mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-28 01:01:34 +00:00
feat: upgrade multihash (#1792)
* feat: upgrade to multihash 0.13 `multihash` changes a lot internally, it is using stack allocation instead of heap allocation. This leads to a few limitations in regards on how `Multihash` can be used. Therefore `PeerId` is now using a `Bytes` internally so that only minimal changes are needed. * Update versions and changelogs. Co-authored-by: Roman Borschel <romanb@users.noreply.github.com> Co-authored-by: Roman S. Borschel <roman@parity.io>
This commit is contained in:
@ -51,8 +51,8 @@ impl From<io::Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<multihash::DecodeOwnedError> for Error {
|
||||
fn from(err: multihash::DecodeOwnedError) -> Error {
|
||||
impl From<multihash::Error> for Error {
|
||||
fn from(err: multihash::Error) -> Error {
|
||||
Error::ParsingError(err.into())
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ impl<'a> Protocol<'a> {
|
||||
"p2p" => {
|
||||
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
|
||||
let decoded = bs58::decode(s).into_vec()?;
|
||||
Ok(Protocol::P2p(Multihash::from_bytes(decoded)?))
|
||||
Ok(Protocol::P2p(Multihash::from_bytes(&decoded)?))
|
||||
}
|
||||
"http" => Ok(Protocol::Http),
|
||||
"https" => Ok(Protocol::Https),
|
||||
@ -280,7 +280,7 @@ impl<'a> Protocol<'a> {
|
||||
P2P => {
|
||||
let (n, input) = decode::usize(input)?;
|
||||
let (data, rest) = split_at(n, input)?;
|
||||
Ok((Protocol::P2p(Multihash::from_bytes(data.to_owned())?), rest))
|
||||
Ok((Protocol::P2p(Multihash::from_bytes(data)?), rest))
|
||||
}
|
||||
P2P_CIRCUIT => Ok((Protocol::P2pCircuit, input)),
|
||||
QUIC => Ok((Protocol::Quic, input)),
|
||||
@ -388,7 +388,7 @@ impl<'a> Protocol<'a> {
|
||||
}
|
||||
Protocol::P2p(multihash) => {
|
||||
w.write_all(encode::u32(P2P, &mut buf))?;
|
||||
let bytes = multihash.as_bytes();
|
||||
let bytes = multihash.to_bytes();
|
||||
w.write_all(encode::usize(bytes.len(), &mut encode::usize_buffer()))?;
|
||||
w.write_all(&bytes)?
|
||||
}
|
||||
@ -492,7 +492,7 @@ impl<'a> fmt::Display for Protocol<'a> {
|
||||
let s = BASE32.encode(addr.hash());
|
||||
write!(f, "/onion3/{}:{}", s.to_lowercase(), addr.port())
|
||||
}
|
||||
P2p(c) => write!(f, "/p2p/{}", bs58::encode(c.as_bytes()).into_string()),
|
||||
P2p(c) => write!(f, "/p2p/{}", bs58::encode(c.to_bytes()).into_string()),
|
||||
P2pCircuit => f.write_str("/p2p-circuit"),
|
||||
Quic => f.write_str("/quic"),
|
||||
Sctp(port) => write!(f, "/sctp/{}", port),
|
||||
@ -584,4 +584,4 @@ read_onion_impl!(read_onion, 10, 16);
|
||||
// Parse a version 3 onion address and return its binary representation.
|
||||
//
|
||||
// Format: <base-32 address> ":" <port number>
|
||||
read_onion_impl!(read_onion3, 35, 56);
|
||||
read_onion_impl!(read_onion3, 35, 56);
|
||||
|
Reference in New Issue
Block a user