mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-15 11:01:21 +00:00
fix(autonat): Skip unparsable multiaddr (#3363)
With this commit `libp2p-autonat` no longer discards the whole remote payload in case an addr is unparsable, but instead logs the failure and skips the unparsable multiaddr. See libp2p#3244 for details.
This commit is contained in:
@ -10,6 +10,13 @@
|
|||||||
|
|
||||||
[PR 3153]: https://github.com/libp2p/rust-libp2p/pull/3153
|
[PR 3153]: https://github.com/libp2p/rust-libp2p/pull/3153
|
||||||
|
|
||||||
|
# 0.9.1
|
||||||
|
|
||||||
|
- Skip unparsable multiaddr in `DialRequest::from_bytes`. See [PR 3351].
|
||||||
|
|
||||||
|
[PR 3351]: https://github.com/libp2p/rust-libp2p/pull/3351
|
||||||
|
|
||||||
|
|
||||||
# 0.9.0
|
# 0.9.0
|
||||||
|
|
||||||
- Update to `libp2p-core` `v0.38.0`.
|
- Update to `libp2p-core` `v0.38.0`.
|
||||||
|
@ -134,15 +134,16 @@ impl DialRequest {
|
|||||||
PeerId::try_from(peer_id)
|
PeerId::try_from(peer_id)
|
||||||
.map_err(|_| io::Error::new(io::ErrorKind::InvalidData, "invalid peer id"))?
|
.map_err(|_| io::Error::new(io::ErrorKind::InvalidData, "invalid peer id"))?
|
||||||
};
|
};
|
||||||
let addrs = {
|
let addrs = addrs
|
||||||
let mut maddrs = vec![];
|
.into_iter()
|
||||||
for addr in addrs.into_iter() {
|
.filter_map(|a| match Multiaddr::try_from(a) {
|
||||||
let maddr = Multiaddr::try_from(addr)
|
Ok(a) => Some(a),
|
||||||
.map_err(|err| io::Error::new(io::ErrorKind::InvalidData, err))?;
|
Err(e) => {
|
||||||
maddrs.push(maddr);
|
log::debug!("Unable to parse multiaddr: {e}");
|
||||||
}
|
None
|
||||||
maddrs
|
}
|
||||||
};
|
})
|
||||||
|
.collect();
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
peer_id,
|
peer_id,
|
||||||
addresses: addrs,
|
addresses: addrs,
|
||||||
@ -333,4 +334,35 @@ mod tests {
|
|||||||
let response2 = DialResponse::from_bytes(&bytes).unwrap();
|
let response2 = DialResponse::from_bytes(&bytes).unwrap();
|
||||||
assert_eq!(response, response2);
|
assert_eq!(response, response2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_skip_unparsable_multiaddr() {
|
||||||
|
let valid_multiaddr: Multiaddr = "/ip6/2001:db8::/tcp/1234".parse().unwrap();
|
||||||
|
let valid_multiaddr_bytes = valid_multiaddr.to_vec();
|
||||||
|
|
||||||
|
let invalid_multiaddr = {
|
||||||
|
let a = vec![255; 8];
|
||||||
|
assert!(Multiaddr::try_from(a.clone()).is_err());
|
||||||
|
a
|
||||||
|
};
|
||||||
|
|
||||||
|
let msg = structs_proto::Message {
|
||||||
|
r#type: Some(structs_proto::message::MessageType::Dial.into()),
|
||||||
|
dial: Some(structs_proto::message::Dial {
|
||||||
|
peer: Some(structs_proto::message::PeerInfo {
|
||||||
|
id: Some(PeerId::random().to_bytes()),
|
||||||
|
addrs: vec![valid_multiaddr_bytes, invalid_multiaddr],
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
dial_response: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut bytes = Vec::with_capacity(msg.encoded_len());
|
||||||
|
msg.encode(&mut bytes)
|
||||||
|
.expect("Vec<u8> provides capacity as needed");
|
||||||
|
|
||||||
|
let request = DialRequest::from_bytes(&bytes).expect("not to fail");
|
||||||
|
|
||||||
|
assert_eq!(request.addresses, vec![valid_multiaddr])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user