This repository has been archived by the owner on Feb 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 112
Track timeouts per peer #274
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ca205c7
feat: track timeouts per peer
dirkmc ad97437
docs: add warning about StopTimer()
dirkmc a388fed
fix: log from warn to info
dirkmc 565164c
fix: races in tests
dirkmc 805ea89
fix: flaky test timing
dirkmc eec41b7
fix: test race
dirkmc e53420b
fix: TestPeerTimeoutManagerWithTimeout
dirkmc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"sync" | ||
"time" | ||
|
||
bstimer "github.com/ipfs/go-bitswap/internal/timer" | ||
bsmsg "github.com/ipfs/go-bitswap/message" | ||
pb "github.com/ipfs/go-bitswap/message/pb" | ||
bsnet "github.com/ipfs/go-bitswap/network" | ||
|
@@ -57,6 +58,7 @@ type MessageQueue struct { | |
dhTimeoutMgr DontHaveTimeoutManager | ||
maxMessageSize int | ||
sendErrorBackoff time.Duration | ||
onRequestSent OnRequestSent | ||
|
||
outgoingWork chan time.Time | ||
done chan struct{} | ||
|
@@ -131,6 +133,8 @@ func (pc *peerConn) Latency() time.Duration { | |
// older version of Bitswap that doesn't support DONT_HAVE messages. | ||
type OnDontHaveTimeout func(peer.ID, []cid.Cid) | ||
|
||
type OnRequestSent func(peer.ID) | ||
|
||
// DontHaveTimeoutManager pings a peer to estimate latency so it can set a reasonable | ||
// upper bound on when to consider a DONT_HAVE request as timed out (when connected to | ||
// a peer that doesn't support DONT_HAVE messages) | ||
|
@@ -147,17 +151,18 @@ type DontHaveTimeoutManager interface { | |
} | ||
|
||
// New creates a new MessageQueue. | ||
func New(ctx context.Context, p peer.ID, network MessageNetwork, onDontHaveTimeout OnDontHaveTimeout) *MessageQueue { | ||
func New(ctx context.Context, p peer.ID, network MessageNetwork, onDontHaveTimeout OnDontHaveTimeout, onRequestSent OnRequestSent) *MessageQueue { | ||
onTimeout := func(ks []cid.Cid) { | ||
onDontHaveTimeout(p, ks) | ||
} | ||
dhTimeoutMgr := newDontHaveTimeoutMgr(ctx, newPeerConnection(p, network), onTimeout) | ||
return newMessageQueue(ctx, p, network, maxMessageSize, sendErrorBackoff, dhTimeoutMgr) | ||
return newMessageQueue(ctx, p, network, maxMessageSize, sendErrorBackoff, dhTimeoutMgr, onRequestSent) | ||
} | ||
|
||
// This constructor is used by the tests | ||
func newMessageQueue(ctx context.Context, p peer.ID, network MessageNetwork, | ||
maxMsgSize int, sendErrorBackoff time.Duration, dhTimeoutMgr DontHaveTimeoutManager) *MessageQueue { | ||
maxMsgSize int, sendErrorBackoff time.Duration, dhTimeoutMgr DontHaveTimeoutManager, | ||
onRequestSent OnRequestSent) *MessageQueue { | ||
|
||
mq := &MessageQueue{ | ||
ctx: ctx, | ||
|
@@ -172,6 +177,7 @@ func newMessageQueue(ctx context.Context, p peer.ID, network MessageNetwork, | |
done: make(chan struct{}), | ||
rebroadcastInterval: defaultRebroadcastInterval, | ||
sendErrorBackoff: sendErrorBackoff, | ||
onRequestSent: onRequestSent, | ||
priority: maxPriority, | ||
} | ||
|
||
|
@@ -286,11 +292,8 @@ func (mq *MessageQueue) runQueue() { | |
|
||
// Create a timer for debouncing scheduled work. | ||
scheduleWork := time.NewTimer(0) | ||
if !scheduleWork.Stop() { | ||
// Need to drain the timer if Stop() returns false | ||
// See: https://golang.org/pkg/time/#Timer.Stop | ||
<-scheduleWork.C | ||
} | ||
defer scheduleWork.Stop() | ||
bstimer.StopTimer(scheduleWork) | ||
|
||
var workScheduled time.Time | ||
for { | ||
|
@@ -304,9 +307,8 @@ func (mq *MessageQueue) runQueue() { | |
// track delay. | ||
if workScheduled.IsZero() { | ||
workScheduled = when | ||
} else if !scheduleWork.Stop() { | ||
// Need to drain the timer if Stop() returns false | ||
<-scheduleWork.C | ||
} else { | ||
bstimer.StopTimer(scheduleWork) | ||
} | ||
|
||
// If we have too many updates and/or we've waited too | ||
|
@@ -413,6 +415,9 @@ func (mq *MessageQueue) sendMessage() { | |
|
||
mq.simulateDontHaveWithTimeout(message) | ||
|
||
// Signal that a request was sent | ||
mq.onRequestSent(mq.p) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Concerned that doing this after sending the request could cause us to handle this after receiving the response. |
||
|
||
// If the message was too big and only a subset of wants could be | ||
// sent, schedule sending the rest of the wants in the next | ||
// iteration of the event loop. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just pass
pm.OnTimeout
(without the function)