mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-24 23:31:33 +00:00
Implement Send everywhere (#458)
This commit is contained in:
@ -48,7 +48,7 @@ impl<Trans> Clone for IdentifyTransport<Trans>
|
||||
}
|
||||
}
|
||||
|
||||
type CacheEntry = future::Shared<Box<Future<Item = IdentifyTransportOutcome, Error = IoError>>>;
|
||||
type CacheEntry = future::Shared<Box<Future<Item = IdentifyTransportOutcome, Error = IoError> + Send>>;
|
||||
|
||||
impl<Trans> IdentifyTransport<Trans> {
|
||||
/// Creates an `IdentifyTransport` that wraps around the given transport and peerstore.
|
||||
@ -63,14 +63,18 @@ impl<Trans> IdentifyTransport<Trans> {
|
||||
|
||||
impl<Trans> Transport for IdentifyTransport<Trans>
|
||||
where
|
||||
Trans: Transport + Clone + 'static, // TODO: 'static :(
|
||||
Trans::Output: AsyncRead + AsyncWrite,
|
||||
Trans: Transport + Clone + Send + 'static, // TODO: 'static :(
|
||||
Trans::Dial: Send,
|
||||
Trans::Listener: Send,
|
||||
Trans::ListenerUpgrade: Send,
|
||||
Trans::MultiaddrFuture: Send,
|
||||
Trans::Output: AsyncRead + AsyncWrite + Send,
|
||||
{
|
||||
type Output = IdentifyTransportOutput<Trans::Output>;
|
||||
type MultiaddrFuture = future::FutureResult<Multiaddr, IoError>;
|
||||
type Listener = Box<Stream<Item = Self::ListenerUpgrade, Error = IoError>>;
|
||||
type ListenerUpgrade = Box<Future<Item = (Self::Output, Self::MultiaddrFuture), Error = IoError>>;
|
||||
type Dial = Box<Future<Item = (Self::Output, Self::MultiaddrFuture), Error = IoError>>;
|
||||
type Listener = Box<Stream<Item = Self::ListenerUpgrade, Error = IoError> + Send>;
|
||||
type ListenerUpgrade = Box<Future<Item = (Self::Output, Self::MultiaddrFuture), Error = IoError> + Send>;
|
||||
type Dial = Box<Future<Item = (Self::Output, Self::MultiaddrFuture), Error = IoError> + Send>;
|
||||
|
||||
#[inline]
|
||||
fn listen_on(self, addr: Multiaddr) -> Result<(Self::Listener, Multiaddr), (Self, Multiaddr)> {
|
||||
@ -139,7 +143,7 @@ where
|
||||
Ok((out, future::ok(client_addr)))
|
||||
});
|
||||
|
||||
Box::new(fut) as Box<Future<Item = _, Error = _>>
|
||||
Box::new(fut) as Box<Future<Item = _, Error = _> + Send>
|
||||
});
|
||||
|
||||
Ok((Box::new(listener) as Box<_>, new_addr))
|
||||
@ -213,11 +217,17 @@ where
|
||||
|
||||
impl<Trans> MuxedTransport for IdentifyTransport<Trans>
|
||||
where
|
||||
Trans: MuxedTransport + Clone + 'static,
|
||||
Trans::Output: AsyncRead + AsyncWrite,
|
||||
Trans: MuxedTransport + Clone + Send + 'static,
|
||||
Trans::Dial: Send,
|
||||
Trans::Listener: Send,
|
||||
Trans::ListenerUpgrade: Send,
|
||||
Trans::MultiaddrFuture: Send,
|
||||
Trans::Output: AsyncRead + AsyncWrite + Send,
|
||||
Trans::Incoming: Send,
|
||||
Trans::IncomingUpgrade: Send,
|
||||
{
|
||||
type Incoming = Box<Future<Item = Self::IncomingUpgrade, Error = IoError>>;
|
||||
type IncomingUpgrade = Box<Future<Item = (Self::Output, Self::MultiaddrFuture), Error = IoError>>;
|
||||
type Incoming = Box<Future<Item = Self::IncomingUpgrade, Error = IoError> + Send>;
|
||||
type IncomingUpgrade = Box<Future<Item = (Self::Output, Self::MultiaddrFuture), Error = IoError> + Send>;
|
||||
|
||||
#[inline]
|
||||
fn next_incoming(self) -> Self::Incoming {
|
||||
@ -274,7 +284,7 @@ where
|
||||
Ok((out, future::ok(client_addr)))
|
||||
});
|
||||
|
||||
Box::new(future) as Box<Future<Item = _, Error = _>>
|
||||
Box::new(future) as Box<Future<Item = _, Error = _> + Send>
|
||||
});
|
||||
|
||||
Box::new(future) as Box<_>
|
||||
@ -286,7 +296,7 @@ pub struct IdentifyTransportOutput<S> {
|
||||
/// The socket to communicate with the remote.
|
||||
pub socket: S,
|
||||
/// Outcome of the identification of the remote.
|
||||
pub info: Box<Future<Item = IdentifyTransportOutcome, Error = IoError>>,
|
||||
pub info: Box<Future<Item = IdentifyTransportOutcome, Error = IoError> + Send>,
|
||||
}
|
||||
|
||||
/// Outcome of the identification of the remote.
|
||||
@ -301,7 +311,7 @@ pub struct IdentifyTransportOutcome {
|
||||
fn cache_entry<F, Fut>(cache: &Mutex<FnvHashMap<Multiaddr, CacheEntry>>, addr: Multiaddr, if_no_entry: F)
|
||||
-> impl Future<Item = IdentifyTransportOutcome, Error = IoError>
|
||||
where F: FnOnce() -> Fut,
|
||||
Fut: Future<Item = IdentifyTransportOutcome, Error = IoError> + 'static,
|
||||
Fut: Future<Item = IdentifyTransportOutcome, Error = IoError> + Send + 'static,
|
||||
{
|
||||
trace!("Looking up cache entry for {}", addr);
|
||||
let mut cache = cache.lock();
|
||||
@ -313,7 +323,7 @@ where F: FnOnce() -> Fut,
|
||||
|
||||
Entry::Vacant(entry) => {
|
||||
trace!("No cache entry available");
|
||||
let future = (Box::new(if_no_entry()) as Box<Future<Item = _, Error = _>>).shared();
|
||||
let future = (Box::new(if_no_entry()) as Box<Future<Item = _, Error = _> + Send>).shared();
|
||||
entry.insert(future.clone());
|
||||
future::Either::B(future)
|
||||
},
|
||||
|
@ -45,16 +45,21 @@ impl<Trans, AddrRes> PeerIdTransport<Trans, AddrRes> {
|
||||
|
||||
impl<Trans, AddrRes, AddrResOut> Transport for PeerIdTransport<Trans, AddrRes>
|
||||
where
|
||||
Trans: Transport + Clone + 'static, // TODO: 'static :(
|
||||
Trans::Output: AsyncRead + AsyncWrite,
|
||||
Trans: Transport + Clone + Send + 'static, // TODO: 'static :(
|
||||
Trans::Dial: Send,
|
||||
Trans::Listener: Send,
|
||||
Trans::ListenerUpgrade: Send,
|
||||
Trans::MultiaddrFuture: Send,
|
||||
Trans::Output: AsyncRead + AsyncWrite + Send,
|
||||
AddrRes: Fn(PeerId) -> AddrResOut + 'static, // TODO: 'static :(
|
||||
AddrResOut: IntoIterator<Item = Multiaddr> + 'static, // TODO: 'static :(
|
||||
AddrResOut::IntoIter: Send,
|
||||
{
|
||||
type Output = PeerIdTransportOutput<Trans::Output>;
|
||||
type MultiaddrFuture = Box<Future<Item = Multiaddr, Error = IoError>>;
|
||||
type Listener = Box<Stream<Item = Self::ListenerUpgrade, Error = IoError>>;
|
||||
type ListenerUpgrade = Box<Future<Item = (Self::Output, Self::MultiaddrFuture), Error = IoError>>;
|
||||
type Dial = Box<Future<Item = (Self::Output, Self::MultiaddrFuture), Error = IoError>>;
|
||||
type MultiaddrFuture = Box<Future<Item = Multiaddr, Error = IoError> + Send>;
|
||||
type Listener = Box<Stream<Item = Self::ListenerUpgrade, Error = IoError> + Send>;
|
||||
type ListenerUpgrade = Box<Future<Item = (Self::Output, Self::MultiaddrFuture), Error = IoError> + Send>;
|
||||
type Dial = Box<Future<Item = (Self::Output, Self::MultiaddrFuture), Error = IoError> + Send>;
|
||||
|
||||
#[inline]
|
||||
fn listen_on(self, addr: Multiaddr) -> Result<(Self::Listener, Multiaddr), (Self, Multiaddr)> {
|
||||
@ -94,11 +99,11 @@ where
|
||||
let peer_id = info.info.public_key.clone().into_peer_id();
|
||||
debug!("Identified {} as {:?}", original_addr, peer_id);
|
||||
AddrComponent::P2P(peer_id.into()).into()
|
||||
})) as Box<Future<Item = _, Error = _>>;
|
||||
})) as Box<Future<Item = _, Error = _> + Send>;
|
||||
(out, real_addr)
|
||||
});
|
||||
|
||||
Box::new(fut) as Box<Future<Item = _, Error = _>>
|
||||
Box::new(fut) as Box<Future<Item = _, Error = _> + Send>
|
||||
});
|
||||
|
||||
Ok((Box::new(listener) as Box<_>, listened_addr))
|
||||
@ -155,7 +160,7 @@ where
|
||||
original_addr: original_addr,
|
||||
};
|
||||
// Replace the multiaddress with the one of the form `/p2p/...` or `/ipfs/...`.
|
||||
Ok((out, Box::new(future::ok(addr)) as Box<Future<Item = _, Error = _>>))
|
||||
Ok((out, Box::new(future::ok(addr)) as Box<Future<Item = _, Error = _> + Send>))
|
||||
});
|
||||
|
||||
Ok(Box::new(future) as Box<_>)
|
||||
@ -195,7 +200,7 @@ where
|
||||
let peer_id = info.info.public_key.clone().into_peer_id();
|
||||
debug!("Identified {} as {:?}", original_addr, peer_id);
|
||||
AddrComponent::P2P(peer_id.into()).into()
|
||||
})) as Box<Future<Item = _, Error = _>>;
|
||||
})) as Box<Future<Item = _, Error = _> + Send>;
|
||||
(out, real_addr)
|
||||
});
|
||||
|
||||
@ -212,13 +217,20 @@ where
|
||||
|
||||
impl<Trans, AddrRes, AddrResOut> MuxedTransport for PeerIdTransport<Trans, AddrRes>
|
||||
where
|
||||
Trans: MuxedTransport + Clone + 'static,
|
||||
Trans::Output: AsyncRead + AsyncWrite,
|
||||
Trans: MuxedTransport + Clone + Send + 'static,
|
||||
Trans::Dial: Send,
|
||||
Trans::Listener: Send,
|
||||
Trans::ListenerUpgrade: Send,
|
||||
Trans::MultiaddrFuture: Send,
|
||||
Trans::Output: AsyncRead + AsyncWrite + Send,
|
||||
Trans::Incoming: Send,
|
||||
Trans::IncomingUpgrade: Send,
|
||||
AddrRes: Fn(PeerId) -> AddrResOut + 'static, // TODO: 'static :(
|
||||
AddrResOut: IntoIterator<Item = Multiaddr> + 'static, // TODO: 'static :(
|
||||
AddrResOut::IntoIter: Send,
|
||||
{
|
||||
type Incoming = Box<Future<Item = Self::IncomingUpgrade, Error = IoError>>;
|
||||
type IncomingUpgrade = Box<Future<Item = (Self::Output, Self::MultiaddrFuture), Error = IoError>>;
|
||||
type Incoming = Box<Future<Item = Self::IncomingUpgrade, Error = IoError> + Send>;
|
||||
type IncomingUpgrade = Box<Future<Item = (Self::Output, Self::MultiaddrFuture), Error = IoError> + Send>;
|
||||
|
||||
#[inline]
|
||||
fn next_incoming(self) -> Self::Incoming {
|
||||
@ -243,11 +255,11 @@ where
|
||||
let peer_id = info.info.public_key.clone().into_peer_id();
|
||||
debug!("Identified {} as {:?}", original_addr, peer_id);
|
||||
AddrComponent::P2P(peer_id.into()).into()
|
||||
})) as Box<Future<Item = _, Error = _>>;
|
||||
})) as Box<Future<Item = _, Error = _> + Send>;
|
||||
(out, real_addr)
|
||||
});
|
||||
|
||||
Box::new(future) as Box<Future<Item = _, Error = _>>
|
||||
Box::new(future) as Box<Future<Item = _, Error = _> + Send>
|
||||
});
|
||||
|
||||
Box::new(future) as Box<_>
|
||||
@ -261,7 +273,7 @@ pub struct PeerIdTransportOutput<S> {
|
||||
|
||||
/// Identification of the remote.
|
||||
/// This may not be known immediately, hence why we use a future.
|
||||
pub info: Box<Future<Item = IdentifyTransportOutcome, Error = IoError>>,
|
||||
pub info: Box<Future<Item = IdentifyTransportOutcome, Error = IoError> + Send>,
|
||||
|
||||
/// Original address of the remote.
|
||||
/// This layer turns the address of the remote into the `/p2p/...` form, but stores the
|
||||
@ -313,8 +325,8 @@ mod tests {
|
||||
impl Transport for UnderlyingTrans {
|
||||
type Output = <TcpConfig as Transport>::Output;
|
||||
type MultiaddrFuture = <TcpConfig as Transport>::MultiaddrFuture;
|
||||
type Listener = Box<Stream<Item = Self::ListenerUpgrade, Error = IoError>>;
|
||||
type ListenerUpgrade = Box<Future<Item = (Self::Output, Self::MultiaddrFuture), Error = IoError>>;
|
||||
type Listener = Box<Stream<Item = Self::ListenerUpgrade, Error = IoError> + Send>;
|
||||
type ListenerUpgrade = Box<Future<Item = (Self::Output, Self::MultiaddrFuture), Error = IoError> + Send>;
|
||||
type Dial = <TcpConfig as Transport>::Dial;
|
||||
#[inline]
|
||||
fn listen_on(
|
||||
|
@ -61,7 +61,7 @@ pub struct IdentifySender<T> {
|
||||
|
||||
impl<'a, T> IdentifySender<T>
|
||||
where
|
||||
T: AsyncWrite + 'a,
|
||||
T: AsyncWrite + Send + 'a,
|
||||
{
|
||||
/// Sends back information to the client. Returns a future that is signalled whenever the
|
||||
/// info have been sent.
|
||||
@ -69,7 +69,7 @@ where
|
||||
self,
|
||||
info: IdentifyInfo,
|
||||
observed_addr: &Multiaddr,
|
||||
) -> Box<Future<Item = (), Error = IoError> + 'a> {
|
||||
) -> Box<Future<Item = (), Error = IoError> + Send + 'a> {
|
||||
debug!("Sending identify info to client");
|
||||
trace!("Sending: {:?}", info);
|
||||
|
||||
@ -113,14 +113,14 @@ pub struct IdentifyInfo {
|
||||
|
||||
impl<C, Maf> ConnectionUpgrade<C, Maf> for IdentifyProtocolConfig
|
||||
where
|
||||
C: AsyncRead + AsyncWrite + 'static,
|
||||
Maf: Future<Item = Multiaddr, Error = IoError> + 'static,
|
||||
C: AsyncRead + AsyncWrite + Send + 'static,
|
||||
Maf: Future<Item = Multiaddr, Error = IoError> + Send + 'static,
|
||||
{
|
||||
type NamesIter = iter::Once<(Bytes, Self::UpgradeIdentifier)>;
|
||||
type UpgradeIdentifier = ();
|
||||
type Output = IdentifyOutput<C>;
|
||||
type MultiaddrFuture = future::Either<future::FutureResult<Multiaddr, IoError>, Maf>;
|
||||
type Future = Box<Future<Item = (Self::Output, Self::MultiaddrFuture), Error = IoError>>;
|
||||
type Future = Box<Future<Item = (Self::Output, Self::MultiaddrFuture), Error = IoError> + Send>;
|
||||
|
||||
#[inline]
|
||||
fn protocol_names(&self) -> Self::NamesIter {
|
||||
|
Reference in New Issue
Block a user