Refactor multiaddr crate. (#498)

Refactor multiaddr crate.

- Remove `AddrComponent`. Instead `Protocol` directly contains its
associated data.

- Various smaller changes around conversions to Multiaddr from other
types, e.g. socket addresses.

- Expand tests to include property tests which test encoding/decoding
identity.
This commit is contained in:
Toralf Wittner
2018-09-20 19:51:00 +02:00
committed by GitHub
parent 1969bde4fe
commit 84b089cacc
18 changed files with 669 additions and 748 deletions

View File

@@ -253,7 +253,7 @@ pub mod transport;
pub mod upgrade;
pub use self::connection_reuse::ConnectionReuse;
pub use self::multiaddr::{AddrComponent, Multiaddr};
pub use self::multiaddr::Multiaddr;
pub use self::muxing::StreamMuxer;
pub use self::peer_id::PeerId;
pub use self::public_key::PublicKey;

View File

@@ -20,7 +20,7 @@
use bytes::{Bytes, IntoBuf};
use futures::{future::{self, FutureResult}, prelude::*, stream, sync::mpsc};
use multiaddr::{AddrComponent, Multiaddr};
use multiaddr::{Protocol, Multiaddr};
use parking_lot::Mutex;
use rw_stream_sink::RwStreamSink;
use std::{io, sync::Arc};
@@ -132,7 +132,7 @@ impl<T: IntoBuf + Send + 'static> Transport for Listener<T> {
/// Returns `true` if and only if the address is `/memory`.
fn is_memory_addr(a: &Multiaddr) -> bool {
let mut iter = a.iter();
if iter.next() != Some(AddrComponent::Memory) {
if iter.next() != Some(Protocol::Memory) {
return false;
}
if iter.next().is_some() {