Remove Transport::nat_traversal and refactor multiaddr. (#1052)

The functionality is available through `Multiaddr::replace`.
What we currently call "nat_traversal" is merley a replacement of an IP
address prefix in a `Multiaddr`, hence it can be done directly on
`Multiaddr` values instead of having to go through a `Transport`.

In addition this PR consolidates changes made to `Multiaddr` in
previous commits which resulted in lots of deprecations. It adds some
more (see below for the complete list of API changes) and removes all
deprecated functionality, requiring a minor version bump.

Here are the changes to `multiaddr` compared to the currently published
version:

1.  Removed `into_bytes` (use `to_vec` instead).
2.  Renamed `to_bytes` to `to_vec`.
3.  Removed `from_bytes` (use the `TryFrom` impl instead).
4.  Added `with_capacity`.
5.  Added `len`.
6.  Removed `as_slice` (use `AsRef` impl instead).
7.  Removed `encapsulate` (use `push` or `with` instead).
8.  Removed `decapsulate` (use `pop` instead).
9.  Renamed `append` to `push`.
10. Added `with`.
11. Added `replace`.
12. Removed `ToMultiaddr` trait (use `TryFrom` instead).
This commit is contained in:
Toralf Wittner
2019-04-17 20:12:31 +02:00
committed by GitHub
parent a4173705db
commit ca58f8029c
33 changed files with 494 additions and 803 deletions

View File

@ -222,7 +222,6 @@ use std::{error, time::Duration};
///
/// > **Note**: This `Transport` is not suitable for production usage, as its implementation
/// > reserves the right to support additional protocols or remove deprecated protocols.
#[inline]
pub fn build_development_transport(keypair: identity::Keypair)
-> impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone
{
@ -280,7 +279,6 @@ struct CommonTransportInner {
impl CommonTransport {
/// Initializes the `CommonTransport`.
#[inline]
#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))]
pub fn new() -> CommonTransport {
let tcp = tcp::TcpConfig::new().nodelay(true);
@ -297,7 +295,6 @@ impl CommonTransport {
}
/// Initializes the `CommonTransport`.
#[inline]
#[cfg(all(any(target_os = "emscripten", target_os = "unknown"), feature = "libp2p-websocket"))]
pub fn new() -> CommonTransport {
let inner = websocket::BrowserWsConfig::new();
@ -307,7 +304,6 @@ impl CommonTransport {
}
/// Initializes the `CommonTransport`.
#[inline]
#[cfg(all(any(target_os = "emscripten", target_os = "unknown"), not(feature = "libp2p-websocket")))]
pub fn new() -> CommonTransport {
let inner = core::transport::dummy::DummyTransport::new();
@ -324,18 +320,11 @@ impl Transport for CommonTransport {
type ListenerUpgrade = <InnerImplementation as Transport>::ListenerUpgrade;
type Dial = <InnerImplementation as Transport>::Dial;
#[inline]
fn listen_on(self, addr: Multiaddr) -> Result<Self::Listener, TransportError<Self::Error>> {
self.inner.inner.listen_on(addr)
}
#[inline]
fn dial(self, addr: Multiaddr) -> Result<Self::Dial, TransportError<Self::Error>> {
self.inner.inner.dial(addr)
}
#[inline]
fn nat_traversal(&self, server: &Multiaddr, observed: &Multiaddr) -> Option<Multiaddr> {
self.inner.inner.nat_traversal(server, observed)
}
}