From ee5ef3d2f68739ceb3c82de9999d9c5d74a66650 Mon Sep 17 00:00:00 2001 From: Dirk McCormick Date: Tue, 10 Mar 2020 16:06:51 -0400 Subject: [PATCH 1/2] feat: timeout when peer doesnt respond to want-block This commit was moved from ipfs/go-bitswap@bdd4629db462166cf811c284e5a75e124282a7a9 --- bitswap/bitswap.go | 2 +- .../messagequeue/donthavetimeoutmgr.go | 5 +++-- bitswap/internal/messagequeue/messagequeue.go | 18 ++++++------------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/bitswap/bitswap.go b/bitswap/bitswap.go index 1b59dcd01..a2bd56ca2 100644 --- a/bitswap/bitswap.go +++ b/bitswap/bitswap.go @@ -125,7 +125,7 @@ func New(parent context.Context, network bsnet.BitSwapNetwork, var wm *bswm.WantManager // onDontHaveTimeout is called when a want-block is sent to a peer that // has an old version of Bitswap that doesn't support DONT_HAVE messages, - // and no response is received within a timeout. + // or when no response is received within a timeout. onDontHaveTimeout := func(p peer.ID, dontHaves []cid.Cid) { // Simulate a DONT_HAVE message arriving to the WantManager wm.ReceiveFrom(ctx, p, nil, nil, dontHaves) diff --git a/bitswap/internal/messagequeue/donthavetimeoutmgr.go b/bitswap/internal/messagequeue/donthavetimeoutmgr.go index ee7941b6d..d1c6be58f 100644 --- a/bitswap/internal/messagequeue/donthavetimeoutmgr.go +++ b/bitswap/internal/messagequeue/donthavetimeoutmgr.go @@ -11,7 +11,8 @@ import ( const ( // dontHaveTimeout is used to simulate a DONT_HAVE when communicating with - // a peer whose Bitswap client doesn't support the DONT_HAVE response. + // a peer whose Bitswap client doesn't support the DONT_HAVE response, + // or when the peer takes too long to respond. // If the peer doesn't respond to a want-block within the timeout, the // local node assumes that the peer doesn't have the block. dontHaveTimeout = 5 * time.Second @@ -45,7 +46,7 @@ type pendingWant struct { // dontHaveTimeoutMgr pings the peer to measure latency. It uses the latency to // set a reasonable timeout for simulating a DONT_HAVE message for peers that -// don't support DONT_HAVE +// don't support DONT_HAVE or that take to long to respond. type dontHaveTimeoutMgr struct { ctx context.Context shutdown func() diff --git a/bitswap/internal/messagequeue/messagequeue.go b/bitswap/internal/messagequeue/messagequeue.go index 8e2518899..922ab6339 100644 --- a/bitswap/internal/messagequeue/messagequeue.go +++ b/bitswap/internal/messagequeue/messagequeue.go @@ -392,10 +392,8 @@ func (mq *MessageQueue) sendMessage() { } // Make sure the DONT_HAVE timeout manager has started - if !mq.sender.SupportsHave() { - // Note: Start is idempotent - mq.dhTimeoutMgr.Start() - } + // Note: Start is idempotent + mq.dhTimeoutMgr.Start() // Convert want lists to a Bitswap Message message, onSent := mq.extractOutgoingMessage(mq.sender.SupportsHave()) @@ -425,15 +423,11 @@ func (mq *MessageQueue) sendMessage() { } } -// If the peer is running an older version of Bitswap that doesn't support the -// DONT_HAVE response, watch for timeouts on any want-blocks we sent the peer, -// and if there is a timeout simulate a DONT_HAVE response. +// If want-block times out, simulate a DONT_HAVE reponse. +// This is necessary when making requests to peers running an older version of +// Bitswap that doesn't support the DONT_HAVE response, and is also useful to +// mitigate getting blocked by a peer that takes a long time to respond. func (mq *MessageQueue) simulateDontHaveWithTimeout(msg bsmsg.BitSwapMessage) { - // If the peer supports DONT_HAVE responses, we don't need to simulate - if mq.sender.SupportsHave() { - return - } - mq.wllock.Lock() // Get the CID of each want-block that expects a DONT_HAVE response From c8636142ab8ef808695161afe3737528c44f40b9 Mon Sep 17 00:00:00 2001 From: Dirk McCormick Date: Tue, 10 Mar 2020 16:50:08 -0400 Subject: [PATCH 2/2] docs: fix find peers log level This commit was moved from ipfs/go-bitswap@dbb73a68706ab0ea3ce24bea0fb304be3eeb55b8 --- bitswap/internal/session/session.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitswap/internal/session/session.go b/bitswap/internal/session/session.go index 45cd825fa..a1f88e825 100644 --- a/bitswap/internal/session/session.go +++ b/bitswap/internal/session/session.go @@ -340,7 +340,7 @@ func (s *Session) broadcastWantHaves(ctx context.Context, wants []cid.Cid) { // Search for providers who have the first want in the list. // Typically if the provider has the first block they will have // the rest of the blocks also. - log.Warnf("Ses%d: FindMorePeers with want %s (1st of %d wants)", s.id, lu.C(wants[0]), len(wants)) + log.Infof("Ses%d: FindMorePeers with want %s (1st of %d wants)", s.id, lu.C(wants[0]), len(wants)) s.findMorePeers(ctx, wants[0]) } s.resetIdleTick()