-
Notifications
You must be signed in to change notification settings - Fork 2.6k
NetworkBehaviour trait is not fully implemented #10370
Comments
That's what I came up with: diff --git a/client/network/src/discovery.rs b/client/network/src/discovery.rs
index dc08ab57ed..93ea14ef56 100644
--- a/client/network/src/discovery.rs
+++ b/client/network/src/discovery.rs
@@ -589,13 +589,16 @@ impl NetworkBehaviour for DiscoveryBehaviour {
fn inject_connection_closed(
&mut self,
- _peer_id: &PeerId,
- _conn: &ConnectionId,
- _endpoint: &ConnectedPoint,
+ peer_id: &PeerId,
+ conn: &ConnectionId,
+ endpoint: &ConnectedPoint,
_handler: <Self::ProtocolsHandler as IntoProtocolsHandler>::Handler,
) {
self.num_connections -= 1;
- // NetworkBehaviour::inject_connection_closed on Kademlia<MemoryStore> does nothing.
+ for k in self.kademlias.values_mut() {
+ let handler = k.new_handler().into_handler(peer_id, endpoint);
+ NetworkBehaviour::inject_connection_closed(k, peer_id, conn, endpoint, handler);
+ }
}
fn inject_disconnected(&mut self, peer_id: &PeerId) {
@@ -689,8 +692,11 @@ impl NetworkBehaviour for DiscoveryBehaviour {
}
}
- fn inject_listen_failure(&mut self, _: &Multiaddr, _: &Multiaddr, _: Self::ProtocolsHandler) {
- // NetworkBehaviour::inject_listen_failure on Kademlia<MemoryStore> does nothing.
+ fn inject_listen_failure(&mut self, local_addr: &Multiaddr, send_back_addr: &Multiaddr, _: Self::ProtocolsHandler) {
+ for k in self.kademlias.values_mut() {
+ let handler = k.new_handler();
+ NetworkBehaviour::inject_listen_failure(k, local_addr, send_back_addr, handler);
+ }
}
fn inject_listener_error(&mut self, id: ListenerId, err: &(dyn std::error::Error + 'static)) { @mxinden Max, is it enough or do I need to deconstruct |
Yes, that is the way to go @kpp. Can you prepare a patch for https://github.com/libp2p/rust-libp2p/? |
Sorry, would you please elaborate? |
@kpp you would need to add a method to |
Why should it differ from inject_listen_failure? |
I don't understand your questions. If you try to compile the code of your diff you will get compilation errors because of a type mismatch. When the behavior in The content of |
It compiles.
Do we have to split |
Ahh, I misread your diff. Yeah, you definitely shouldn't be calling
All of them. It's part of the API contract of the |
Thanks for clarification! Will do |
See the review comment #10035 (comment) (and the other comment right below)
The
NetworkBehaviour
trait implementations presently don't always redirect the method calls to their underlyingNetworkBehaviour
s because rust-libp2p doesn't give the possibility to deconstruct aMultiHandler
.This means that a
cargo update
that updates libp2p could potentially break our code.This should be solved in a short time frame.
The text was updated successfully, but these errors were encountered: