-
Notifications
You must be signed in to change notification settings - Fork 996
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
swarm: Remove PollParameters
#3124
Comments
I am in favor of removing
I suggest similar to how we would communicate supported protocols of remote peers via #2680, we can do the same for supported protocols of the local peer. As an aside, the set of supported protocols can change at runtime. E.g. |
In theory, it could be that one connection of a node is behind firewall or NAT and the other one isn't. For example, lets say I am listening on TCP and WebRTC connections but only the WebRTC one is port-forwarded. This thought experiment suggests that we'd have to tell our behaviour the supported protocols PER connection. In a way, this would fit in well with #3099 where we only learn our supported protocols after we established the connection to another peer. Thoughts? |
While I am sure we will find this case in the wild, I would assume that it is rare. Thus I suggest not designing for it. |
My only (but important!) use-case for |
Yes. I think that is the right way to think about it. Because At the moment, a This makes it difficult to accurately cache this information. We'd almost have to tell the Instead of that, we could also build a mechanism where a |
Yes, that sounds good (if my understanding is correct): |
I wouldn't make the supported protocols available to the other handlers but report it back to the behaviour via a (newly introduced) enum FromConnection {
Event(E),
ProtocolsChanged(Vec<String>) // Note: Simplified type here.
} Protocols are specific to a connection so I don't think other connections need to know about them. A behaviour can always forward it though if really needed. The only thing I don't really like about this design is that a
Maybe we could make handlers produce an update to begin with and until then, they don't support any protocols? |
My question was not about other connections, it was specifically about Regarding the Update mechanism: changes will be much less frequent (as witnessed by currently known protocols) than connections, so I’d find it quite reasonable to have a nice and easy (i.e. non-foot-gun) normal case (providing protocols via a method is type-checked) and a documented special case (forgetting to emit that event in some cases will lead to some head scratching when connections “half work”). |
On start-up the |
But yes, Perhaps instead of producing an update, the handler could produce an event that just invalidates the "cache" for the supported protocols. A connection would then inquire again about the supported protocols via |
Instead of treating it as a cache, we could also call We would need some kind of diffing strategy to not emit updates about unchanged protocols to the behaviour. Ideally, before we do that, we already got rid of the "upgrade" notation to have |
This patch deprecates 3 out of 4 functions on `PollParameters`: - `local_peer_id` - `listened_addresses` - `external_addresses` The addresses can be obtained by inspecting the `FromSwarm` event. To make this easier, we introduce two utility structs in `libp2p-swarm`: - `ExternalAddresses` - `ListenAddresses` A node's `PeerId` is always known to the caller, thus we can require them to pass it in. Related: #3124.
) This patch deprecates 3 out of 4 functions on `PollParameters`: - `local_peer_id` - `listened_addresses` - `external_addresses` The addresses can be obtained by inspecting the `FromSwarm` event. To make this easier, we introduce two utility structs in `libp2p-swarm`: - `ExternalAddresses` - `ListenAddresses` A node's `PeerId` is always known to the caller, thus we can require them to pass it in. Related: libp2p#3124.
Given that we merged #3153, I am assuming we have agreed that this is a good idea. |
With #3651, |
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 via `ConnectionHandlerEvent::ReportRemoteProtocols`. The provided `ProtocolSupport` 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` via `ConnectionEvent::RemoteProtocolsChange`. Similarly, if the listen protocols of a connection change, all `ConnectionHandler`s on the connection will be notified via `ConnectionEvent::LocalProtocolsChange`. This will allow us to eventually remove `PollParameters` from `NetworkBehaviour`. 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. Pull-Request: #3651.
) This patch deprecates 3 out of 4 functions on `PollParameters`: - `local_peer_id` - `listened_addresses` - `external_addresses` The addresses can be obtained by inspecting the `FromSwarm` event. To make this easier, we introduce two utility structs in `libp2p-swarm`: - `ExternalAddresses` - `ListenAddresses` A node's `PeerId` is always known to the caller, thus we can require them to pass it in. Related: libp2p#3124.
Resolves: libp2p#3124. Pull-Request: libp2p#4490.
Description
Remove the
PollParameters
trait.local_peer_id
can be removed in favor of users having to pass it into their behaviour in the constructor.external_addresses
can be built up from theinject_new_external_addr
andinject_expired_external_addr
callbacks.listened_addresses
can be built up from theinject_new_listen_addr
andinject_expired_listen_addr
callbacksThe only function that does not have a replacement at the moment is
supported_protocols
.Any ideas for how we could model that one differently?
As per usual, we should first deprecate the existing functions, give users a release or two to upgrade and then remove the deprecated code.
Motivation
rust-libp2p
is primarily designed around an async message-passing system. Accessing information synchronously as part of thepoll
function is not inline with this philosophy.Current Implementation
Are you planning to do it yourself in a pull request?
Maybe.
The text was updated successfully, but these errors were encountered: