-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
accelerated-dht: cleanup peer from message sender on disconnection #1009
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -15,12 +15,14 @@ | |||||||
"github.com/multiformats/go-multihash" | ||||||||
|
||||||||
"github.com/libp2p/go-libp2p-routing-helpers/tracing" | ||||||||
"github.com/libp2p/go-libp2p/core/event" | ||||||||
"github.com/libp2p/go-libp2p/core/host" | ||||||||
"github.com/libp2p/go-libp2p/core/network" | ||||||||
"github.com/libp2p/go-libp2p/core/peer" | ||||||||
"github.com/libp2p/go-libp2p/core/peerstore" | ||||||||
"github.com/libp2p/go-libp2p/core/protocol" | ||||||||
"github.com/libp2p/go-libp2p/core/routing" | ||||||||
"github.com/libp2p/go-libp2p/p2p/host/eventbus" | ||||||||
swarm "github.com/libp2p/go-libp2p/p2p/net/swarm" | ||||||||
|
||||||||
"github.com/gogo/protobuf/proto" | ||||||||
|
@@ -98,6 +100,8 @@ | |||||||
bulkSendParallelism int | ||||||||
|
||||||||
self peer.ID | ||||||||
|
||||||||
peerConnectednessSubscriber event.Subscription | ||||||||
} | ||||||||
|
||||||||
// NewFullRT creates a DHT client that tracks the full network. It takes a protocol prefix for the given network, | ||||||||
|
@@ -151,6 +155,11 @@ | |||||||
} | ||||||||
} | ||||||||
|
||||||||
sub, err := h.EventBus().Subscribe(new(event.EvtPeerConnectednessChanged), eventbus.Name("fullrt-dht")) | ||||||||
if err != nil { | ||||||||
return nil, fmt.Errorf("peer connectedness subscription failed: %w", err) | ||||||||
} | ||||||||
|
||||||||
ctx, cancel := context.WithCancel(context.Background()) | ||||||||
|
||||||||
self := h.ID() | ||||||||
|
@@ -195,14 +204,14 @@ | |||||||
|
||||||||
crawlerInterval: fullrtcfg.crawlInterval, | ||||||||
|
||||||||
bulkSendParallelism: fullrtcfg.bulkSendParallelism, | ||||||||
|
||||||||
self: self, | ||||||||
bulkSendParallelism: fullrtcfg.bulkSendParallelism, | ||||||||
self: self, | ||||||||
peerConnectednessSubscriber: sub, | ||||||||
} | ||||||||
|
||||||||
rt.wg.Add(1) | ||||||||
rt.wg.Add(2) | ||||||||
go rt.runCrawler(ctx) | ||||||||
|
||||||||
go rt.runSubscriber() | ||||||||
return rt, nil | ||||||||
} | ||||||||
|
||||||||
|
@@ -211,6 +220,29 @@ | |||||||
key kadkey.Key | ||||||||
} | ||||||||
|
||||||||
func (dht *FullRT) runSubscriber() { | ||||||||
defer dht.wg.Done() | ||||||||
ms, ok := dht.messageSender.(dht_pb.MessageSenderWithDisconnect) | ||||||||
if !ok { | ||||||||
return | ||||||||
} | ||||||||
defer dht.peerConnectednessSubscriber.Close() | ||||||||
for { | ||||||||
select { | ||||||||
case e := <-dht.peerConnectednessSubscriber.Out(): | ||||||||
pc, ok := e.(event.EvtPeerConnectednessChanged) | ||||||||
if !ok { | ||||||||
logger.Errorf("invalid event message type: %T", e) | ||||||||
} | ||||||||
if pc.Connectedness != network.Connected { | ||||||||
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.
Suggested change
gammazero marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
ms.OnDisconnect(dht.ctx, pc.Peer) | ||||||||
} | ||||||||
case <-dht.ctx.Done(): | ||||||||
return | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
func (dht *FullRT) TriggerRefresh(ctx context.Context) error { | ||||||||
select { | ||||||||
case <-ctx.Done(): | ||||||||
|
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.
Should this be moved up so that
dht.peerConnectednessSubscriber.Close()
gets called even if the type assertion returns false?