Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 42 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion substrate/network-libp2p/src/network_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ fn parse_and_add_to_node_store(

let mut addr = addr_str.to_multiaddr().map_err(|_| ErrorKind::AddressParse)?;
let who = match addr.pop() {
Some(AddrComponent::P2P(key)) | Some(AddrComponent::IPFS(key)) =>
Some(AddrComponent::P2P(key)) =>
PeerId::from_bytes(key).map_err(|_| ErrorKind::AddressParse)?,
_ => return Err(ErrorKind::AddressParse.into()),
};
Expand Down
34 changes: 22 additions & 12 deletions substrate/network-libp2p/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,17 +767,20 @@ fn handle_custom_connection(
who: NodeIndex,
node_id: PeerstorePeerId,
handler: Arc<NetworkProtocolHandler + Send + Sync>,
protocol: ProtocolId
protocol: ProtocolId,
print_log_message: bool,
}

impl Drop for ProtoDisconnectGuard {
fn drop(&mut self) {
info!(target: "sub-libp2p",
"Node {:?} with peer ID {} through protocol {:?} disconnected",
self.node_id,
self.who,
self.protocol
);
if self.print_log_message {
info!(target: "sub-libp2p",
"Node {:?} with peer ID {} through protocol {:?} disconnected",
self.node_id,
self.who,
self.protocol
);
}
self.handler.disconnected(&NetworkContextImpl {
inner: self.inner.clone(),
protocol: self.protocol,
Expand All @@ -790,12 +793,13 @@ fn handle_custom_connection(
}
}

let dc_guard = ProtoDisconnectGuard {
let mut dc_guard = ProtoDisconnectGuard {
inner: shared.clone(),
who,
node_id: node_id.clone(),
handler: handler.clone(),
protocol: protocol_id,
print_log_message: true,
};

let fut = custom_proto_out.incoming
Expand All @@ -816,10 +820,16 @@ fn handle_custom_connection(

let val = (custom_proto_out.outgoing, custom_proto_out.protocol_version);
let final_fut = unique_connec.tie_or_stop(val, fut)
.then(move |val| {
// Makes sure that `dc_guard` is kept alive until here.
drop(dc_guard);
val
.then({
let node_id = node_id.clone();
move |val| {
info!(target: "sub-libp2p", "Finishing future for proto {:?} with {:?} => {:?}",
protocol_id, node_id, val);
// Makes sure that `dc_guard` is kept alive until here.
dc_guard.print_log_message = false;
drop(dc_guard);
val
}
});

debug!(target: "sub-libp2p",
Expand Down
4 changes: 3 additions & 1 deletion substrate/network-libp2p/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ pub fn build_transport(
upgrade::map(mplex::MplexConfig::new(), either::EitherOutput::First),
upgrade::map(yamux::Config::default(), either::EitherOutput::Second),
))
.into_connection_reuse();
.map(|out, _| ((), out))
.into_connection_reuse()
.map(|((), out), _| out);

TransportTimeout::new(base, Duration::from_secs(20))
}
Expand Down