Skip to content

Commit f14cc40

Browse files
authored
Channel monitor watches for errors instead of measuring data rate (#190)
* feat: channel monitor watches for errors instead of measuring data rate * refactor: better method name * feat: add debounce to channel monitor * fix: restart channel size
1 parent dbc57eb commit f14cc40

File tree

16 files changed

+611
-776
lines changed

16 files changed

+611
-776
lines changed

channelmonitor/channelmonitor.go

Lines changed: 202 additions & 299 deletions
Large diffs are not rendered by default.

channelmonitor/channelmonitor_test.go

Lines changed: 267 additions & 458 deletions
Large diffs are not rendered by default.

channels/channels.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ func (c *Channels) SendDataError(chid datatransfer.ChannelID, err error) error {
346346
return c.send(chid, datatransfer.SendDataError, err)
347347
}
348348

349+
// ReceiveDataError indicates that the transport layer had an error receiving
350+
// data from the remote peer
351+
func (c *Channels) ReceiveDataError(chid datatransfer.ChannelID, err error) error {
352+
return c.send(chid, datatransfer.ReceiveDataError, err)
353+
}
354+
349355
// HasChannel returns true if the given channel id is being tracked
350356
func (c *Channels) HasChannel(chid datatransfer.ChannelID) (bool, error) {
351357
return c.stateMachines.Has(chid)

channels/channels_fsm.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ var ChannelEvents = fsm.Events{
8383
chst.AddLog("data transfer send error: %s", chst.Message)
8484
return nil
8585
}),
86+
fsm.Event(datatransfer.ReceiveDataError).FromAny().ToNoChange().Action(func(chst *internal.ChannelState, err error) error {
87+
chst.Message = err.Error()
88+
chst.AddLog("data transfer receive error: %s", chst.Message)
89+
return nil
90+
}),
8691
fsm.Event(datatransfer.RequestTimedOut).FromAny().ToNoChange().Action(func(chst *internal.ChannelState, err error) error {
8792
chst.Message = err.Error()
8893
chst.AddLog("data transfer request timed out: %s", chst.Message)

events.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ const (
9898
// SendDataError indicates that the transport layer had an error trying
9999
// to send data to the remote peer
100100
SendDataError
101+
102+
// ReceiveDataError indicates that the transport layer had an error
103+
// receiving data from the remote peer
104+
ReceiveDataError
101105
)
102106

103107
// Events are human readable names for data transfer events
@@ -127,6 +131,9 @@ var Events = map[EventCode]string{
127131
DataQueuedProgress: "DataQueuedProgress",
128132
DataSentProgress: "DataSentProgress",
129133
DataReceivedProgress: "DataReceivedProgress",
134+
RequestTimedOut: "RequestTimedOut",
135+
SendDataError: "SendDataError",
136+
ReceiveDataError: "ReceiveDataError",
130137
}
131138

132139
// Event is a struct containing information about a data transfer event

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/filecoin-project/go-data-transfer
33
go 1.14
44

55
require (
6+
github.com/bep/debounce v1.2.0
67
github.com/filecoin-project/go-ds-versioning v0.1.0
78
github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe
89
github.com/hannahhoward/cbor-gen-for v0.0.0-20200817222906-ea96cece81f1
@@ -12,7 +13,7 @@ require (
1213
github.com/ipfs/go-cid v0.0.7
1314
github.com/ipfs/go-datastore v0.4.5
1415
github.com/ipfs/go-ds-badger v0.2.3
15-
github.com/ipfs/go-graphsync v0.6.0
16+
github.com/ipfs/go-graphsync v0.6.1
1617
github.com/ipfs/go-ipfs-blockstore v1.0.1
1718
github.com/ipfs/go-ipfs-blocksutil v0.0.1
1819
github.com/ipfs/go-ipfs-chunker v0.0.5

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ github.com/Stebalien/go-bitfield v0.0.1 h1:X3kbSSPUaJK60wV2hjOPZwmpljr6VGCqdq4cB
2828
github.com/Stebalien/go-bitfield v0.0.1/go.mod h1:GNjFpasyUVkHMsfEOk8EFLJ9syQ6SI+XWrX9Wf2XH0s=
2929
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
3030
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
31+
github.com/bep/debounce v1.2.0 h1:wXds8Kq8qRfwAOpAxHrJDbCXgC5aHSzgQb/0gKsHQqo=
32+
github.com/bep/debounce v1.2.0/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
3133
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8=
3234
github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI=
3335
github.com/btcsuite/btcd v0.0.0-20190605094302-a0d1e3e36d50/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI=
@@ -213,8 +215,8 @@ github.com/ipfs/go-ds-badger v0.2.3/go.mod h1:pEYw0rgg3FIrywKKnL+Snr+w/LjJZVMTBR
213215
github.com/ipfs/go-ds-leveldb v0.0.1/go.mod h1:feO8V3kubwsEF22n0YRQCffeb79OOYIykR4L04tMOYc=
214216
github.com/ipfs/go-ds-leveldb v0.4.1/go.mod h1:jpbku/YqBSsBc1qgME8BkWS4AxzF2cEu1Ii2r79Hh9s=
215217
github.com/ipfs/go-ds-leveldb v0.4.2/go.mod h1:jpbku/YqBSsBc1qgME8BkWS4AxzF2cEu1Ii2r79Hh9s=
216-
github.com/ipfs/go-graphsync v0.6.0 h1:x6UvDUGA7wjaKNqx5Vbo7FGT8aJ5ryYA0dMQ5jN3dF0=
217-
github.com/ipfs/go-graphsync v0.6.0/go.mod h1:e2ZxnClqBBYAtd901g9vXMJzS47labjAtOzsWtOzKNk=
218+
github.com/ipfs/go-graphsync v0.6.1 h1:i9wN7YkBXWwIsUjVQeuaDxFB59yWZrG1xL564Nz7aGE=
219+
github.com/ipfs/go-graphsync v0.6.1/go.mod h1:e2ZxnClqBBYAtd901g9vXMJzS47labjAtOzsWtOzKNk=
218220
github.com/ipfs/go-ipfs-blockstore v0.0.1/go.mod h1:d3WClOmRQKFnJ0Jz/jj/zmksX0ma1gROTlovZKBmN08=
219221
github.com/ipfs/go-ipfs-blockstore v0.1.0/go.mod h1:5aD0AvHPi7mZc6Ci1WCAhiBQu2IsfTduLl+422H6Rqw=
220222
github.com/ipfs/go-ipfs-blockstore v0.1.4/go.mod h1:Jxm3XMVjh6R17WvxFEiyKBLUGr86HgIYJW/D/MwqeYQ=

impl/events.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ func (m *manager) OnSendDataError(chid datatransfer.ChannelID, err error) error
227227
return m.channels.SendDataError(chid, err)
228228
}
229229

230+
func (m *manager) OnReceiveDataError(chid datatransfer.ChannelID, err error) error {
231+
log.Warnf("channel %+v had transport receive error: %s", chid, err)
232+
return m.channels.ReceiveDataError(chid, err)
233+
}
234+
230235
// OnChannelCompleted is called
231236
// - by the requester when all data for a transfer has been received
232237
// - by the responder when all data for a transfer has been sent

impl/impl.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,9 @@ func NewDataTransfer(ds datastore.Batching, cidListsDir string, dataTransferNetw
116116
option(m)
117117
}
118118

119-
// Start push / pull channel monitor after applying config options as the config
119+
// Create push / pull channel monitor after applying config options as the config
120120
// options may apply to the monitor
121121
m.channelMonitor = channelmonitor.NewMonitor(m, m.channelMonitorCfg)
122-
m.channelMonitor.Start()
123122

124123
return m, nil
125124
}
@@ -320,6 +319,12 @@ func (m *manager) CloseDataTransferChannel(ctx context.Context, chid datatransfe
320319
return nil
321320
}
322321

322+
// ConnectTo opens a connection to a peer on the data-transfer protocol,
323+
// retrying if necessary
324+
func (m *manager) ConnectTo(ctx context.Context, p peer.ID) error {
325+
return m.dataTransferNetwork.ConnectWithRetry(ctx, p)
326+
}
327+
323328
// close an open channel and fire an error event
324329
func (m *manager) CloseDataTransferChannelWithError(ctx context.Context, chid datatransfer.ChannelID, cherr error) error {
325330
log.Infof("close channel %s with error %s", chid, cherr)
@@ -511,3 +516,7 @@ func (m *manager) channelDataTransferType(channel datatransfer.ChannelState) Cha
511516
// we received a push channel
512517
return ManagerPeerReceivePush
513518
}
519+
520+
func (m *manager) PeerID() peer.ID {
521+
return m.peerID
522+
}

impl/integration_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ func TestManyReceiversAtOnce(t *testing.T) {
495495
}
496496
}
497497

498-
// disconnectCoordinator is used by TestPushRequestAutoRestart to allow
498+
// disconnectCoordinator is used by TestAutoRestart to allow
499499
// test cases to signal when a disconnect should start, and whether
500500
// to wait for the disconnect to take effect before continuing
501501
type disconnectCoordinator struct {
@@ -724,14 +724,10 @@ func TestAutoRestart(t *testing.T) {
724724

725725
// Set up
726726
restartConf := ChannelRestartConfig(channelmonitor.Config{
727-
MonitorPushChannels: tc.isPush,
728-
MonitorPullChannels: !tc.isPush,
729727
AcceptTimeout: 100 * time.Millisecond,
730-
Interval: 100 * time.Millisecond,
731-
MinBytesTransferred: 1,
732-
ChecksPerInterval: 10,
733728
RestartBackoff: 500 * time.Millisecond,
734729
MaxConsecutiveRestarts: 5,
730+
RestartAckTimeout: 100 * time.Millisecond,
735731
CompleteTimeout: 100 * time.Millisecond,
736732
})
737733
initiator, err := NewDataTransfer(gsData.DtDs1, gsData.TempDir1, gsData.DtNet1, initiatorGSTspt, restartConf)

0 commit comments

Comments
 (0)