cuprate_p2p_core

Trait NetworkZone

Source
pub trait NetworkZone:
    Clone
    + Copy
    + Send
    + 'static {
    type Addr: NetZoneAddress;
    type Stream: Stream<Item = Result<Message, BucketError>> + Unpin + Send + 'static;
    type Sink: Sink<LevinMessage<Message>, Error = BucketError> + Unpin + Send + 'static;
    type Listener: Stream<Item = Result<(Option<Self::Addr>, Self::Stream, Self::Sink), Error>> + Send + 'static;
    type ServerCfg: Clone + Debug + Send + 'static;

    const NAME: &'static str;
    const CHECK_NODE_ID: bool;

    // Required methods
    fn connect_to_peer<'async_trait>(
        addr: Self::Addr,
    ) -> Pin<Box<dyn Future<Output = Result<(Self::Stream, Self::Sink), Error>> + Send + 'async_trait>>
       where Self: 'async_trait;
    fn incoming_connection_listener<'async_trait>(
        config: Self::ServerCfg,
        port: u16,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Listener, Error>> + Send + 'async_trait>>
       where Self: 'async_trait;
}
Expand description

An abstraction over a network zone (tor/i2p/clear)

Required Associated Constants§

Source

const NAME: &'static str

The network name.

Source

const CHECK_NODE_ID: bool

Check if our node ID matches the incoming peers node ID for this network.

This has privacy implications on an anonymity network if true so should be set to false.

Required Associated Types§

Source

type Addr: NetZoneAddress

The address type of this network.

Source

type Stream: Stream<Item = Result<Message, BucketError>> + Unpin + Send + 'static

The stream (incoming data) type for this network.

Source

type Sink: Sink<LevinMessage<Message>, Error = BucketError> + Unpin + Send + 'static

The sink (outgoing data) type for this network.

Source

type Listener: Stream<Item = Result<(Option<Self::Addr>, Self::Stream, Self::Sink), Error>> + Send + 'static

The inbound connection listener for this network.

Source

type ServerCfg: Clone + Debug + Send + 'static

Config used to start a server which listens for incoming connections.

Required Methods§

Source

fn connect_to_peer<'async_trait>( addr: Self::Addr, ) -> Pin<Box<dyn Future<Output = Result<(Self::Stream, Self::Sink), Error>> + Send + 'async_trait>>
where Self: 'async_trait,

Connects to a peer with the given address.

This does not complete a handshake with the peer, to do that see the crate docs.

Returns the Self::Stream and Self::Sink to send messages to the peer.

Source

fn incoming_connection_listener<'async_trait>( config: Self::ServerCfg, port: u16, ) -> Pin<Box<dyn Future<Output = Result<Self::Listener, Error>> + Send + 'async_trait>>
where Self: 'async_trait,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§