Trait network::application::interface::NetworkInterface
source · 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§
sourcefn peer_metadata_storage(&self) -> &PeerMetadataStorage
fn peer_metadata_storage(&self) -> &PeerMetadataStorage
Provides the PeerMetadataStorage
for other functions. Not expected to be used externally.
sourcefn insert_app_data(&self, peer_id: PeerId, data: Self::AppData)
fn insert_app_data(&self, peer_id: PeerId, data: Self::AppData)
Insert application specific data
sourcefn remove_app_data(&self, peer_id: &PeerId)
fn remove_app_data(&self, peer_id: &PeerId)
Removes application specific data
sourcefn read_app_data(&self, peer_id: &PeerId) -> Option<Self::AppData>
fn read_app_data(&self, peer_id: &PeerId) -> Option<Self::AppData>
Read application specific data
Provided Methods§
sourcefn connected_peers(&self) -> HashMap<PeerId, PeerInfo>
fn connected_peers(&self) -> HashMap<PeerId, PeerInfo>
Retrieve only connected peers