pub struct Libp2pNetwork {
pub swarm: Swarm<ChatBehaviour>,
pub local_peer_id: PeerId,
pub dht_discovery_enabled: bool,
pub bootstrap_peer_ids: Vec<PeerId>,
/* private fields */
}Expand description
Shared libp2p network implementation fields used by both native and WASM builds.
Fields§
§swarm: Swarm<ChatBehaviour>§local_peer_id: PeerId§dht_discovery_enabled: bool§bootstrap_peer_ids: Vec<PeerId>Implementations§
Source§impl Libp2pNetwork
impl Libp2pNetwork
pub fn on_new_listen_addr(&self, address: Multiaddr) -> Option<NetworkEvent>
pub fn on_external_addr_confirmed( &self, address: Multiaddr, ) -> Option<NetworkEvent>
pub fn on_connection_established( &mut self, peer_id: PeerId, endpoint: ConnectedPoint, num_established: u32, ) -> Option<NetworkEvent>
pub fn on_connection_closed( &mut self, peer_id: PeerId, endpoint: ConnectedPoint, num_established: u32, ) -> Option<NetworkEvent>
pub fn on_history_message( &mut self, peer: PeerId, message: Message<Vec<u8>, Vec<u8>>, ) -> Option<NetworkEvent>
pub fn on_identify_received(&mut self, peer_id: PeerId, info: Info)
pub fn on_gossipsub_message( &self, propagation_source: PeerId, message: Message, ) -> Option<NetworkEvent>
Sourcepub fn handle_swarm_event(
&mut self,
event: SwarmEvent<ChatBehaviourEvent>,
) -> Option<NetworkEvent>
pub fn handle_swarm_event( &mut self, event: SwarmEvent<ChatBehaviourEvent>, ) -> Option<NetworkEvent>
Shared swarm event handler. Native and WASM modules call this for all common events, handling only platform-specific arms themselves.
Trait Implementations§
Source§impl NetworkNode for Libp2pNetwork
impl NetworkNode for Libp2pNetwork
Source§fn dial(&mut self, addr: &Multiaddr) -> NetworkResult<()>
fn dial(&mut self, addr: &Multiaddr) -> NetworkResult<()>
Dial a peer by an opaque address string (multiaddr, endpoint ticket, etc.).
Source§fn join_room(&mut self, room: &RoomId) -> NetworkResult<()>
fn join_room(&mut self, room: &RoomId) -> NetworkResult<()>
Join a room/topic. The backend maps the room name to its internal topic mechanism.
Source§fn publish_message(&mut self, data: Vec<u8>) -> NetworkResult<()>
fn publish_message(&mut self, data: Vec<u8>) -> NetworkResult<()>
Publish a message to the room topic (pubsub / gossip).
All room members receive this via BroadcastReceived.
Source§fn send_message(
&mut self,
peer_id: &PeerId,
data: Vec<u8>,
) -> NetworkResult<RequestId>
fn send_message( &mut self, peer_id: &PeerId, data: Vec<u8>, ) -> NetworkResult<RequestId>
Send a message to a specific peer. Returns an opaque request ID.
Source§fn send_response(
&mut self,
request_id: &RequestId,
data: Vec<u8>,
) -> NetworkResult<()>
fn send_response( &mut self, request_id: &RequestId, data: Vec<u8>, ) -> NetworkResult<()>
Respond to a received message/request.
Source§fn connected_peers(&self) -> Vec<PeerId>
fn connected_peers(&self) -> Vec<PeerId>
Return connected peer IDs (excluding self).
Source§fn is_dialing(&self, peer_id: &PeerId) -> bool
fn is_dialing(&self, peer_id: &PeerId) -> bool
Return whether we have an in-flight dial to the given peer.
Source§fn bootstrap(&mut self) -> NetworkResult<()>
fn bootstrap(&mut self) -> NetworkResult<()>
Bootstrap the network (DHT, relay, etc.).
Source§fn dial_addrs(&self) -> Vec<Multiaddr>
fn dial_addrs(&self) -> Vec<Multiaddr>
Get currently known dialable addresses.
Source§async fn next_event(&mut self) -> Option<NetworkEvent>
async fn next_event(&mut self) -> Option<NetworkEvent>
Return the next network event.
Auto Trait Implementations§
impl !Freeze for Libp2pNetwork
impl !RefUnwindSafe for Libp2pNetwork
impl Send for Libp2pNetwork
impl !Sync for Libp2pNetwork
impl Unpin for Libp2pNetwork
impl !UnwindSafe for Libp2pNetwork
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Returns the layout of the type.