-
Notifications
You must be signed in to change notification settings - Fork 949
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
feat: report changes in supported protocols to ConnectionHandler
#3651
Conversation
@mxinden made me aware that we also need to learn a remote's protocols for client-mode. Working on that next. |
f0170b9
to
f9cf33f
Compare
@mxinden @MarcoPolo This PR now contains a PoC for Kademlia's client-mode based on the new infrastructure for reporting protocols to the connection. Please take a look :) I've split it into distinct commits, that should make the review fairly easy. It needs some more polishing before we can merge it though! |
This comment was marked as resolved.
This comment was marked as resolved.
Great to see this in place. Thanks @thomaseizinger! I wonder how sophisticated we should make this new mechanism. A couple of possible extensions: Full vs partial viewIn this pull request a single What if a single How would two partial-view In- and outbound protocolsIn this pull request the list of protocols is the list of supported inbound protocols. Do we need to design for outbound protocols as well. E.g. should a I can not think of a use-case for this. Successful upgrades as source of inputShould we include the information attained from successful upgrades or even Replacement of
|
Yes. I talked to them and they will push what they have some time this week. I'll take over from there. |
I am working on my own version of #2831 now. It is actually a bit more invasive than I thought but looking nice already. Stay tuned. |
No, I was thinking of calling
Hmm, I am not sure this is useful. Upgrades can fail for a variety of ways. Although in general, I'd like this mechanism to be as transparent as possible for the The question however is, which protocol would benefit from knowing that another protocol successfully upraded / is supported? Why would the relay protocol care that the kademlia is supported by the other node? On the other hand, if we already build a mechanism like this, we might as well enrich it with as much information as we have. I'll keep thinking about it. |
self.listen_addresses | ||
.iter() | ||
.chain(self.external_addresses.iter()) | ||
.cloned() | ||
.collect() |
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.
Just a note for sometime in the future, ideally we would prioritize the addresses we send to a remote, e.g. we should prioritize (in terms of order in the list) external addresses over listening addresses. Again, not for this pull request.
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.
That is an easy enough change!
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.
It actually isn't because we are collecting in a HashSet
and thus lose any ordering.
) -> Option<Self> { | ||
let mut actually_removed_protocols = existing_protocols.intersection(to_remove).peekable(); | ||
|
||
actually_removed_protocols.peek()?; |
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.
Neat!
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.
Are you referring to intersection
?
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 am referring to the concise early return via peek()?
.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Added a changelog entry now, good to go into |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
🎉 great to see this merged. |
Currently, the kademlia behaviour can only learn that the remote node supports kademlia on a particular connection if we successfully negotiate a stream to them. Using the newly introduced abstractions from #3651, we don't have to attempt to establish a stream to the remote to learn whether they support kademlia on a connection but we can directly learn it from the `ConnectionEvent::RemoteProtocolsChange` event. This happens directly once a connection is established which should overall benefit the DHT. Clients do not advertise the kademlia protocol and thus we will immediately learn that a given connection is not suitable for kadmelia requests. We may receive inbound messages from it but this does not affect the routing table. Resolves: #2032. Pull-Request: #3877.
Description
With this patch, implementations of
ConnectionHandler
(which are typically composed in a tree) can exchange information about the supported protocols of a remote with each other viaConnectionHandlerEvent::ReportRemoteProtocols
. The providedProtocolSupport
enum can describe either additions or removals of the remote peer's protocols.This information is aggregated in the connection and passed down to the
ConnectionHandler
viaConnectionEvent::RemoteProtocolsChange
.Similarly, if the listen protocols of a connection change, all
ConnectionHandler
s on the connection will be notified viaConnectionEvent::LocalProtocolsChange
. This will allow us to eventually removePollParameters
fromNetworkBehaviour
.This pattern allows protocols on a connection to communicate with each other. For example, protocols like identify can share the list of (supposedly) supported protocols by the remote with all other handlers. A protocol like kademlia can accurately add and remove a remote from its routing table as a result.
Resolves: #2680.
Related: #3124.
Notes & open questions
String
insideswarm::Connection
?PollParameters::supported_protocols
as part of thisExtract 586394b as separate PR once we can make breaking changes: feat(swarm): report outcome of handlingSwarmEvent
#3865Dependencies
ProtocolName
withAsRef<str>
#3746SwarmEvent
#3865Dependents
The following PRs depend on this / are enabled by this:
Change checklist