mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-30 16:31:57 +00:00
Change Transport::Dial to be Future and not IntoFuture (#193)
This commit is contained in:
@@ -153,28 +153,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Dial<T: Transport>(RateLimited<T::Dial>);
|
||||
|
||||
impl<T> IntoFuture for Dial<T>
|
||||
where
|
||||
T: Transport + 'static,
|
||||
T::Output: AsyncRead + AsyncWrite,
|
||||
{
|
||||
type Future = Box<Future<Item = Self::Item, Error = Self::Error>>;
|
||||
type Item = (Connection<T::Output>, Multiaddr);
|
||||
type Error = io::Error;
|
||||
|
||||
fn into_future(self) -> Self::Future {
|
||||
let r = self.0.rlimiter;
|
||||
let w = self.0.wlimiter;
|
||||
let future = self.0
|
||||
.value
|
||||
.into_future()
|
||||
.and_then(move |(conn, addr)| Ok((Connection::new(conn, r, w)?, addr)));
|
||||
Box::new(future)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Transport for RateLimited<T>
|
||||
where
|
||||
T: Transport + 'static,
|
||||
@@ -183,7 +161,7 @@ where
|
||||
type Output = Connection<T::Output>;
|
||||
type Listener = Listener<T>;
|
||||
type ListenerUpgrade = ListenerUpgrade<T>;
|
||||
type Dial = Dial<T>;
|
||||
type Dial = Box<Future<Item = (Connection<T::Output>, Multiaddr), Error = io::Error>>;
|
||||
|
||||
fn listen_on(self, addr: Multiaddr) -> Result<(Self::Listener, Multiaddr), (Self, Multiaddr)>
|
||||
where
|
||||
@@ -208,10 +186,17 @@ where
|
||||
{
|
||||
let r = self.rlimiter;
|
||||
let w = self.wlimiter;
|
||||
let r2 = r.clone();
|
||||
let w2 = w.clone();
|
||||
|
||||
self.value
|
||||
.dial(addr)
|
||||
.map(|dial| Dial(RateLimited::from_parts(dial, r.clone(), w.clone())))
|
||||
.map_err(|(transport, a)| (RateLimited::from_parts(transport, r, w), a))
|
||||
.map(move |dial| {
|
||||
let future = dial
|
||||
.and_then(move |(conn, addr)| Ok((Connection::new(conn, r, w)?, addr)));
|
||||
Box::new(future) as Box<_>
|
||||
})
|
||||
.map_err(|(transport, a)| (RateLimited::from_parts(transport, r2, w2), a))
|
||||
}
|
||||
|
||||
fn nat_traversal(&self, server: &Multiaddr, observed: &Multiaddr) -> Option<Multiaddr> {
|
||||
|
Reference in New Issue
Block a user