mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-24 07:11:38 +00:00
The Multiaddr of the remote is now a Future (#249)
* The Multiaddr of the remote is now a Future * The multiaddress future in swarm is now a Box
This commit is contained in:
@ -39,7 +39,7 @@ pub fn swarm<T, H, F>(
|
||||
) -> (SwarmController<T>, SwarmFuture<T, H, F::Future>)
|
||||
where
|
||||
T: MuxedTransport + Clone + 'static, // TODO: 'static :-/
|
||||
H: FnMut(T::Output, Multiaddr) -> F,
|
||||
H: FnMut(T::Output, Box<Future<Item = Multiaddr, Error = IoError>>) -> F,
|
||||
F: IntoFuture<Item = (), Error = IoError>,
|
||||
{
|
||||
let (new_dialers_tx, new_dialers_rx) = mpsc::unbounded();
|
||||
@ -76,7 +76,7 @@ where
|
||||
{
|
||||
transport: T,
|
||||
new_listeners: mpsc::UnboundedSender<T::Listener>,
|
||||
new_dialers: mpsc::UnboundedSender<Box<Future<Item = (T::Output, Multiaddr), Error = IoError>>>,
|
||||
new_dialers: mpsc::UnboundedSender<Box<Future<Item = (T::Output, Box<Future<Item = Multiaddr, Error = IoError>>), Error = IoError>>>,
|
||||
new_toprocess: mpsc::UnboundedSender<Box<Future<Item = (), Error = IoError>>>,
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ where
|
||||
match transport.dial(multiaddr.clone()) {
|
||||
Ok(dial) => {
|
||||
let dial = Box::new(
|
||||
dial.map(|(d, client_addr)| (d.into(), client_addr)),
|
||||
dial.map(|(d, client_addr)| (d.into(), Box::new(client_addr) as Box<Future<Item = _, Error = _>>)),
|
||||
) as Box<Future<Item = _, Error = _>>;
|
||||
// Ignoring errors if the receiver has been closed, because in that situation
|
||||
// nothing is going to be processed anyway.
|
||||
@ -163,17 +163,17 @@ where
|
||||
StreamFuture<
|
||||
Box<
|
||||
Stream<
|
||||
Item = Box<Future<Item = (T::Output, Multiaddr), Error = IoError>>,
|
||||
Item = Box<Future<Item = (T::Output, Box<Future<Item = Multiaddr, Error = IoError>>), Error = IoError>>,
|
||||
Error = IoError,
|
||||
>,
|
||||
>,
|
||||
>,
|
||||
>,
|
||||
listeners_upgrade:
|
||||
FuturesUnordered<Box<Future<Item = (T::Output, Multiaddr), Error = IoError>>>,
|
||||
dialers: FuturesUnordered<Box<Future<Item = (T::Output, Multiaddr), Error = IoError>>>,
|
||||
FuturesUnordered<Box<Future<Item = (T::Output, Box<Future<Item = Multiaddr, Error = IoError>>), Error = IoError>>>,
|
||||
dialers: FuturesUnordered<Box<Future<Item = (T::Output, Box<Future<Item = Multiaddr, Error = IoError>>), Error = IoError>>>,
|
||||
new_dialers:
|
||||
mpsc::UnboundedReceiver<Box<Future<Item = (T::Output, Multiaddr), Error = IoError>>>,
|
||||
mpsc::UnboundedReceiver<Box<Future<Item = (T::Output, Box<Future<Item = Multiaddr, Error = IoError>>), Error = IoError>>>,
|
||||
to_process: FuturesUnordered<future::Either<F, Box<Future<Item = (), Error = IoError>>>>,
|
||||
new_toprocess: mpsc::UnboundedReceiver<Box<Future<Item = (), Error = IoError>>>,
|
||||
}
|
||||
@ -181,7 +181,7 @@ where
|
||||
impl<T, H, If, F> Future for SwarmFuture<T, H, F>
|
||||
where
|
||||
T: MuxedTransport + Clone + 'static, // TODO: 'static :-/,
|
||||
H: FnMut(T::Output, Multiaddr) -> If,
|
||||
H: FnMut(T::Output, Box<Future<Item = Multiaddr, Error = IoError>>) -> If,
|
||||
If: IntoFuture<Future = F, Item = (), Error = IoError>,
|
||||
F: Future<Item = (), Error = IoError>,
|
||||
{
|
||||
@ -195,6 +195,9 @@ where
|
||||
Ok(Async::Ready(connec)) => {
|
||||
debug!("Swarm received new multiplexed incoming connection");
|
||||
self.next_incoming = self.transport.clone().next_incoming();
|
||||
let connec = connec.map(|(out, maf)| {
|
||||
(out, Box::new(maf) as Box<Future<Item = Multiaddr, Error = IoError>>)
|
||||
});
|
||||
self.listeners_upgrade.push(Box::new(connec) as Box<_>);
|
||||
}
|
||||
Ok(Async::NotReady) => {}
|
||||
@ -207,7 +210,13 @@ where
|
||||
match self.new_listeners.poll() {
|
||||
Ok(Async::Ready(Some(new_listener))) => {
|
||||
let new_listener = Box::new(
|
||||
new_listener.map(|f| Box::new(f) as Box<Future<Item = _, Error = _>>),
|
||||
new_listener.map(|f| {
|
||||
let f = f.map(|(out, maf)| {
|
||||
(out, Box::new(maf) as Box<Future<Item = Multiaddr, Error = IoError>>)
|
||||
});
|
||||
|
||||
Box::new(f) as Box<Future<Item = _, Error = _>>
|
||||
}),
|
||||
) as Box<Stream<Item = _, Error = _>>;
|
||||
self.listeners.push(new_listener.into_future());
|
||||
}
|
||||
@ -254,10 +263,7 @@ where
|
||||
|
||||
match self.listeners_upgrade.poll() {
|
||||
Ok(Async::Ready(Some((output, client_addr)))) => {
|
||||
debug!(
|
||||
"Successfully upgraded incoming connection with {}",
|
||||
client_addr
|
||||
);
|
||||
debug!("Successfully upgraded incoming connection");
|
||||
self.to_process.push(future::Either::A(
|
||||
handler(output, client_addr).into_future(),
|
||||
));
|
||||
@ -270,7 +276,7 @@ where
|
||||
|
||||
match self.dialers.poll() {
|
||||
Ok(Async::Ready(Some((output, addr)))) => {
|
||||
trace!("Successfully upgraded dialed connection with {}", addr);
|
||||
trace!("Successfully upgraded dialed connection");
|
||||
self.to_process
|
||||
.push(future::Either::A(handler(output, addr).into_future()));
|
||||
}
|
||||
|
Reference in New Issue
Block a user