-
Notifications
You must be signed in to change notification settings - Fork 225
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
Enable switching DHT between client and server modes #469
Conversation
28fea97
to
a80f6c1
Compare
0930def
to
0aa4675
Compare
22b3963
to
5d313b1
Compare
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.
Next draft is up, let me know what you think so we can get this 🚢
@@ -31,7 +31,7 @@ func TestGetFailures(t *testing.T) { | |||
host1 := bhost.New(swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport)) | |||
host2 := bhost.New(swarmt.GenSwarm(t, ctx, swarmt.OptDisableReuseport)) | |||
|
|||
d, err := New(ctx, host1, opts.DisableAutoRefresh()) | |||
d, err := New(ctx, host1, opts.DisableAutoRefresh(), opts.Mode(opts.ModeServer)) |
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.
Yep, so your tests break here too.
subscriber_notifee.go
Outdated
&event.EvtLocalRoutabilityPublic{}, | ||
&event.EvtLocalRoutabilityPrivate{}, | ||
&event.EvtLocalRoutabilityUnknown{}, |
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.
See #469 (comment)
ac9abda
to
c649402
Compare
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.
@aschmahmann Great stuff ! :)
c649402
to
9138a92
Compare
74ca902
to
d7523e1
Compare
defer dht.plk.Unlock() | ||
if dht.host.Network().Connectedness(e.Peer) != network.Connected { | ||
return | ||
} |
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.
Note: I believe both this check and this lock can go away once we switch to the new routing table logic. At that point, it's actually perfectly fine to add disconnected peers to our routing table.
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.
@aarshkshah1992 can you confirm, I haven't had time to look through the routing table PR yet.
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.
I talked with him about this and I was wrong. We can make this possible with a small tweak to the routing table, but we'll handle that later.
(small tweak == get rid of live/dead states, just call a "checkPeer" function on all peers every tick)
subscriber_notifee.go
Outdated
case event.EvtPeerProtocolsUpdated: | ||
handlePeerProtocolsUpdatedEvent(dht, evt) | ||
case event.EvtLocalReachabilityChanged: | ||
handleLocalReachabilityChangedEvent(dht, evt) |
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.
default: log error?
defer dht.plk.Unlock() | ||
if dht.host.Network().Connectedness(e.Peer) != network.Connected { | ||
return | ||
} |
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.
I talked with him about this and I was wrong. We can make this possible with a small tweak to the routing table, but we'll handle that later.
(small tweak == get rid of live/dead states, just call a "checkPeer" function on all peers every tick)
…EvtLocalRoutability event on the libp2p eventbus
…not simply rely on the eventbus, instead use the eventbus to trigger checking the peerstore for which protocols the peer currently supports
…nes into a single goroutine. made forced updates when we have small numbers of peers in the routing table more consistent
…ng through a subscription
5577ec7
to
a65ba4e
Compare
* created Mode(ModeOpt) option for choosing between auto/client/server modes * Auto mode internally switches the DHT between client and server modes based on the EvtLocalReachabilityChanged event emitted on the event bus (e.g. by AutoNAT) * routing table management of peers that switch between client and server mode while we are connected to them (i.e. are in auto mode) * removed Client(bool) option, becoming a DHT client is specified using Mode(ModeClient) instead
This is needed to support libp2p peers that want to switch between client and server DHT modes while the peers are operational.
SetMode(DHTMode)
that allows manually setting the modeRoutabilityBasedModeSwitching(*dht)
that will use the libp2p eventbus to automatically trigger mode switches (e.g. based on AutoNat emitting LocalRoutability events)There are other ways we could expose this functionality such as:
RoutabilityBasedModeSwitching
to be called on a DHT instanceDHTMode
to be declared outside of the dht package (e.g. options or a new one) and then define an interface with enough of the DHT functionality supported to make this workDHTMode
DHTMode
to another packageAll of these options could potentially run into issues if events get dropped off the eventbus, so following recommendations from the
stabilize
branch I've set the eventbus subscription buffer size to 256. Depending on the risk associated with dropping eventbus messages we may either want a way to define a stateful event channel (e.g. when a new event comes in throw away existing events and add the new one), or have some way of detecting dropped messages and then checking the relevant service.