mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-13 01:51:23 +00:00
Change Multiaddr
representation to Bytes
. (#1041)
* Change `Multiaddr` representation to `Bytes`. * Mark several `Multiaddr` methods as deprecated.
This commit is contained in:
@ -64,7 +64,7 @@ impl<T> IdentifySender<T> where T: AsyncWrite {
|
||||
|
||||
let listen_addrs = info.listen_addrs
|
||||
.into_iter()
|
||||
.map(|addr| addr.into_bytes())
|
||||
.map(|addr| addr.to_vec())
|
||||
.collect();
|
||||
|
||||
let pubkey_bytes = info.public_key.into_protobuf_encoding();
|
||||
@ -74,7 +74,7 @@ impl<T> IdentifySender<T> where T: AsyncWrite {
|
||||
message.set_protocolVersion(info.protocol_version);
|
||||
message.set_publicKey(pubkey_bytes);
|
||||
message.set_listenAddrs(listen_addrs);
|
||||
message.set_observedAddr(observed_addr.to_bytes());
|
||||
message.set_observedAddr(observed_addr.to_vec());
|
||||
message.set_protocols(RepeatedField::from_vec(info.protocols));
|
||||
|
||||
let bytes = message
|
||||
@ -234,7 +234,7 @@ fn parse_proto_msg(msg: BytesMut) -> Result<(IdentifyInfo, Multiaddr), IoError>
|
||||
// Turn a `Vec<u8>` into a `Multiaddr`. If something bad happens, turn it into
|
||||
// an `IoError`.
|
||||
fn bytes_to_multiaddr(bytes: Vec<u8>) -> Result<Multiaddr, IoError> {
|
||||
Multiaddr::from_bytes(bytes)
|
||||
Multiaddr::try_from_vec(bytes)
|
||||
.map_err(|err| IoError::new(IoErrorKind::InvalidData, err))
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ impl KadPeer {
|
||||
|
||||
let mut addrs = Vec::with_capacity(peer.get_addrs().len());
|
||||
for addr in peer.take_addrs().into_iter() {
|
||||
let as_ma = Multiaddr::from_bytes(addr)
|
||||
let as_ma = Multiaddr::try_from_vec(addr)
|
||||
.map_err(|err| IoError::new(IoErrorKind::InvalidData, err))?;
|
||||
addrs.push(as_ma);
|
||||
}
|
||||
@ -124,7 +124,7 @@ impl Into<protobuf_structs::dht::Message_Peer> for KadPeer {
|
||||
let mut out = protobuf_structs::dht::Message_Peer::new();
|
||||
out.set_id(self.node_id.into_bytes());
|
||||
for addr in self.multiaddrs {
|
||||
out.mut_addrs().push(addr.into_bytes());
|
||||
out.mut_addrs().push(addr.to_vec());
|
||||
}
|
||||
out.set_connection(self.connection_ty.into());
|
||||
out
|
||||
|
@ -75,7 +75,7 @@ where
|
||||
.map_err(|(e, _): (io::Error, FramedRead<Negotiated<C>, UviBytes>)| e)
|
||||
.and_then(move |(bytes, _)| {
|
||||
if let Some(b) = bytes {
|
||||
let ma = Multiaddr::from_bytes(b.to_vec())
|
||||
let ma = Multiaddr::try_from_vec(b.to_vec())
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
|
||||
Ok(ma)
|
||||
} else {
|
||||
@ -94,7 +94,7 @@ pub struct Sender<C> {
|
||||
impl<C: AsyncWrite> Sender<C> {
|
||||
/// Send address `a` to remote as the observed address.
|
||||
pub fn send_address(self, a: Multiaddr) -> impl Future<Item=(), Error=io::Error> {
|
||||
self.io.send(Bytes::from(a.into_bytes())).map(|_io| ())
|
||||
self.io.send(Bytes::from(a.to_vec())).map(|_io| ())
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user