pub trait NetworkInterface {
    type Sender;
    type AppData;

    // Required methods
    fn peer_metadata_storage(&self) -> &PeerMetadataStorage;
    fn sender(&self) -> Self::Sender;
    fn insert_app_data(&self, peer_id: PeerId, data: Self::AppData);
    fn remove_app_data(&self, peer_id: &PeerId);
    fn read_app_data(&self, peer_id: &PeerId) -> Option<Self::AppData>;
    fn write_app_data<F: FnOnce(&mut Entry<'_, PeerId, Self::AppData>) -> Result<(), PeerError>>(
        &self,
        peer_id: PeerId,
        modifier: F
    ) -> Result<(), PeerError>;

    // Provided methods
    fn connected_peers(&self) -> HashMap<PeerId, PeerInfo> { ... }
    fn filtered_peers<F: FnMut(&(&PeerId, &PeerInfo)) -> bool>(
        &self,
        filter: F
    ) -> HashMap<PeerId, PeerInfo> { ... }
    fn peers(&self) -> HashMap<PeerId, PeerInfo> { ... }
}
Expand description

A generic NetworkInterface for applications to connect to networking

Each application would implement their own NetworkInterface. This would hold AppData specific to the application as well as a specific Sender for cloning across threads and sending requests.

Required Associated Types§

Required Methods§

source

fn peer_metadata_storage(&self) -> &PeerMetadataStorage

Provides the PeerMetadataStorage for other functions. Not expected to be used externally.

source

fn sender(&self) -> Self::Sender

Give a copy of the sender for the network

source

fn insert_app_data(&self, peer_id: PeerId, data: Self::AppData)

Insert application specific data

source

fn remove_app_data(&self, peer_id: &PeerId)

Removes application specific data

source

fn read_app_data(&self, peer_id: &PeerId) -> Option<Self::AppData>

Read application specific data

source

fn write_app_data<F: FnOnce(&mut Entry<'_, PeerId, Self::AppData>) -> Result<(), PeerError>>( &self, peer_id: PeerId, modifier: F ) -> Result<(), PeerError>

Write application specific data, allows for read before write operations

Provided Methods§

source

fn connected_peers(&self) -> HashMap<PeerId, PeerInfo>

Retrieve only connected peers

source

fn filtered_peers<F: FnMut(&(&PeerId, &PeerInfo)) -> bool>( &self, filter: F ) -> HashMap<PeerId, PeerInfo>

Filter peers with according filter

source

fn peers(&self) -> HashMap<PeerId, PeerInfo>

Retrieve PeerInfo for the node

Implementors§