From ecaedd3deb890c63bae3f995e066a7230ec978dc Mon Sep 17 00:00:00 2001 From: driftluo Date: Tue, 9 Jun 2020 09:53:19 +0800 Subject: [PATCH] fix: fix multiaddr convert to socket unwrap --- network/src/protocols/discovery/substream.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/network/src/protocols/discovery/substream.rs b/network/src/protocols/discovery/substream.rs index 3f7a31463a..ce68d31e9c 100644 --- a/network/src/protocols/discovery/substream.rs +++ b/network/src/protocols/discovery/substream.rs @@ -141,9 +141,9 @@ impl SubstreamValue { count: MAX_ADDR_TO_SEND as u32, listen_port: substream.listen_port, }); - addr_known.insert(RawAddr::from( - multiaddr_to_socketaddr(&substream.remote_addr).unwrap(), - )); + if let Some(addr) = multiaddr_to_socketaddr(&substream.remote_addr) { + addr_known.insert(RawAddr::from(addr)); + } RemoteAddress::Listen(substream.remote_addr) } else { @@ -389,7 +389,11 @@ impl Substream { context .listens() .iter() - .map(|address| multiaddr_to_socketaddr(address).unwrap().port()) + .map(|address| { + multiaddr_to_socketaddr(address) + .map(|addr| addr.port()) + .unwrap_or_default() + }) .next() } else { None