File tree 5 files changed +25
-4
lines changed
5 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -217,6 +217,10 @@ func (c *Channels) Accept(chid datatransfer.ChannelID) error {
217
217
return c .send (chid , datatransfer .Accept )
218
218
}
219
219
220
+ func (c * Channels ) ChannelOpened (chid datatransfer.ChannelID ) error {
221
+ return c .send (chid , datatransfer .Opened )
222
+ }
223
+
220
224
func (c * Channels ) TransferRequestQueued (chid datatransfer.ChannelID ) error {
221
225
return c .send (chid , datatransfer .TransferRequestQueued )
222
226
}
Original file line number Diff line number Diff line change @@ -50,6 +50,16 @@ var ChannelEvents = fsm.Events{
50
50
chst .AddLog ("" )
51
51
return nil
52
52
}),
53
+
54
+ // When a channel is Opened, clear any previous error message.
55
+ // (eg if the channel is opened after being restarted due to a connection
56
+ // error)
57
+ fsm .Event (datatransfer .Opened ).FromAny ().ToJustRecord ().Action (func (chst * internal.ChannelState ) error {
58
+ chst .Message = ""
59
+ chst .AddLog ("" )
60
+ return nil
61
+ }),
62
+
53
63
fsm .Event (datatransfer .DataReceived ).FromAny ().ToNoChange ().
54
64
Action (func (chst * internal.ChannelState , rcvdBlocksTotal int64 ) error {
55
65
if rcvdBlocksTotal > chst .ReceivedBlocksTotal {
Original file line number Diff line number Diff line change @@ -107,6 +107,9 @@ const (
107
107
108
108
// RequestCancelled indicates that a transport layer request was cancelled by the request opener
109
109
RequestCancelled
110
+
111
+ // Opened is fired when a request for data is sent from this node to a peer
112
+ Opened
110
113
)
111
114
112
115
// Events are human readable names for data transfer events
Original file line number Diff line number Diff line change @@ -15,17 +15,22 @@ import (
15
15
"github.com/filecoin-project/go-data-transfer/registry"
16
16
)
17
17
18
+ // OnChannelOpened is called when we send a request for data to the other
19
+ // peer on the given channel ID
18
20
func (m * manager ) OnChannelOpened (chid datatransfer.ChannelID ) error {
19
21
log .Infof ("channel %s: opened" , chid )
20
22
23
+ // Check if the channel is being tracked
21
24
has , err := m .channels .HasChannel (chid )
22
25
if err != nil {
23
26
return err
24
27
}
25
28
if ! has {
26
29
return datatransfer .ErrChannelNotFound
27
30
}
28
- return nil
31
+
32
+ // Fire an event
33
+ return m .channels .ChannelOpened (chid )
29
34
}
30
35
31
36
// OnDataReceived is called when the transport layer reports that it has
Original file line number Diff line number Diff line change @@ -9,10 +9,9 @@ import (
9
9
10
10
// EventsHandler are semantic data transfer events that happen as a result of graphsync hooks
11
11
type EventsHandler interface {
12
- // OnChannelOpened is called when we ask the other peer to send us data on the
13
- // given channel ID
12
+ // OnChannelOpened is called when we send a request for data to the other
13
+ // peer on the given channel ID
14
14
// return values are:
15
- // - nil = this channel is recognized
16
15
// - error = ignore incoming data for this channel
17
16
OnChannelOpened (chid ChannelID ) error
18
17
// OnResponseReceived is called when we receive a response to a request
You can’t perform that action at this time.
0 commit comments