Skip to content

Commit 10c4092

Browse files
authored
fix: clear error message on channel open after restart (#273)
1 parent 14b7f03 commit 10c4092

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

channels/channels.go

+4
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ func (c *Channels) Accept(chid datatransfer.ChannelID) error {
217217
return c.send(chid, datatransfer.Accept)
218218
}
219219

220+
func (c *Channels) ChannelOpened(chid datatransfer.ChannelID) error {
221+
return c.send(chid, datatransfer.Opened)
222+
}
223+
220224
func (c *Channels) TransferRequestQueued(chid datatransfer.ChannelID) error {
221225
return c.send(chid, datatransfer.TransferRequestQueued)
222226
}

channels/channels_fsm.go

+10
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ var ChannelEvents = fsm.Events{
5050
chst.AddLog("")
5151
return nil
5252
}),
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+
5363
fsm.Event(datatransfer.DataReceived).FromAny().ToNoChange().
5464
Action(func(chst *internal.ChannelState, rcvdBlocksTotal int64) error {
5565
if rcvdBlocksTotal > chst.ReceivedBlocksTotal {

events.go

+3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ const (
107107

108108
// RequestCancelled indicates that a transport layer request was cancelled by the request opener
109109
RequestCancelled
110+
111+
// Opened is fired when a request for data is sent from this node to a peer
112+
Opened
110113
)
111114

112115
// Events are human readable names for data transfer events

impl/events.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@ import (
1515
"github.com/filecoin-project/go-data-transfer/registry"
1616
)
1717

18+
// OnChannelOpened is called when we send a request for data to the other
19+
// peer on the given channel ID
1820
func (m *manager) OnChannelOpened(chid datatransfer.ChannelID) error {
1921
log.Infof("channel %s: opened", chid)
2022

23+
// Check if the channel is being tracked
2124
has, err := m.channels.HasChannel(chid)
2225
if err != nil {
2326
return err
2427
}
2528
if !has {
2629
return datatransfer.ErrChannelNotFound
2730
}
28-
return nil
31+
32+
// Fire an event
33+
return m.channels.ChannelOpened(chid)
2934
}
3035

3136
// OnDataReceived is called when the transport layer reports that it has

transport.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ import (
99

1010
// EventsHandler are semantic data transfer events that happen as a result of graphsync hooks
1111
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
1414
// return values are:
15-
// - nil = this channel is recognized
1615
// - error = ignore incoming data for this channel
1716
OnChannelOpened(chid ChannelID) error
1817
// OnResponseReceived is called when we receive a response to a request

0 commit comments

Comments
 (0)