Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 740902b

Browse files
tomakagavofyork
authored andcommitted
Update libp2p and some log (#532)
* Update libp2p and some log and yamux * Replace trace! with info! * Only have one log message on disconnect
1 parent 6d50e5d commit 740902b

File tree

4 files changed

+68
-43
lines changed

4 files changed

+68
-43
lines changed

Cargo.lock

Lines changed: 42 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

substrate/network-libp2p/src/network_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ fn parse_and_add_to_node_store(
838838

839839
let mut addr = addr_str.to_multiaddr().map_err(|_| ErrorKind::AddressParse)?;
840840
let who = match addr.pop() {
841-
Some(AddrComponent::P2P(key)) | Some(AddrComponent::IPFS(key)) =>
841+
Some(AddrComponent::P2P(key)) =>
842842
PeerId::from_bytes(key).map_err(|_| ErrorKind::AddressParse)?,
843843
_ => return Err(ErrorKind::AddressParse.into()),
844844
};

substrate/network-libp2p/src/service.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -777,17 +777,20 @@ fn handle_custom_connection(
777777
who: NodeIndex,
778778
node_id: PeerstorePeerId,
779779
handler: Arc<NetworkProtocolHandler + Send + Sync>,
780-
protocol: ProtocolId
780+
protocol: ProtocolId,
781+
print_log_message: bool,
781782
}
782783

783784
impl Drop for ProtoDisconnectGuard {
784785
fn drop(&mut self) {
785-
info!(target: "sub-libp2p",
786-
"Node {:?} with peer ID {} through protocol {:?} disconnected",
787-
self.node_id,
788-
self.who,
789-
self.protocol
790-
);
786+
if self.print_log_message {
787+
info!(target: "sub-libp2p",
788+
"Node {:?} with peer ID {} through protocol {:?} disconnected",
789+
self.node_id,
790+
self.who,
791+
self.protocol
792+
);
793+
}
791794
self.handler.disconnected(&NetworkContextImpl {
792795
inner: self.inner.clone(),
793796
protocol: self.protocol,
@@ -800,12 +803,13 @@ fn handle_custom_connection(
800803
}
801804
}
802805

803-
let dc_guard = ProtoDisconnectGuard {
806+
let mut dc_guard = ProtoDisconnectGuard {
804807
inner: shared.clone(),
805808
who,
806809
node_id: node_id.clone(),
807810
handler: handler.clone(),
808811
protocol: protocol_id,
812+
print_log_message: true,
809813
};
810814

811815
let fut = custom_proto_out.incoming
@@ -826,10 +830,16 @@ fn handle_custom_connection(
826830

827831
let val = (custom_proto_out.outgoing, custom_proto_out.protocol_version);
828832
let final_fut = unique_connec.tie_or_stop(val, fut)
829-
.then(move |val| {
830-
// Makes sure that `dc_guard` is kept alive until here.
831-
drop(dc_guard);
832-
val
833+
.then({
834+
let node_id = node_id.clone();
835+
move |val| {
836+
info!(target: "sub-libp2p", "Finishing future for proto {:?} with {:?} => {:?}",
837+
protocol_id, node_id, val);
838+
// Makes sure that `dc_guard` is kept alive until here.
839+
dc_guard.print_log_message = false;
840+
drop(dc_guard);
841+
val
842+
}
833843
});
834844

835845
debug!(target: "sub-libp2p",

substrate/network-libp2p/src/transport.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ pub fn build_transport(
5555
upgrade::map(mplex::MplexConfig::new(), either::EitherOutput::First),
5656
upgrade::map(yamux::Config::default(), either::EitherOutput::Second),
5757
))
58-
.into_connection_reuse();
58+
.map(|out, _| ((), out))
59+
.into_connection_reuse()
60+
.map(|((), out), _| out);
5961

6062
TransportTimeout::new(base, Duration::from_secs(20))
6163
}

0 commit comments

Comments
 (0)