pub struct Network { /* private fields */ }
Implementations§
Source§impl Network
impl Network
pub fn new( monitor: StateMonitor, dht_contacts: Option<Arc<dyn DhtContactsStoreTrait>>, this_runtime_id: Option<SecretRuntimeId>, ) -> Self
Sourcepub async fn bind(&self, addrs: &[PeerAddr])
pub async fn bind(&self, addrs: &[PeerAddr])
Binds the network to the specified addresses.
Rebinds if already bound. Unbinds and disables the network if addrs
is empty.
NOTE: currently at most one address per protocol (QUIC/TCP) and family (IPv4/IPv6) is used and the rest are ignored, but this might change in the future.
pub fn listener_local_addrs(&self) -> Vec<PeerAddr>
pub fn set_port_forwarding_enabled(&self, enabled: bool)
pub fn is_port_forwarding_enabled(&self) -> bool
pub fn set_local_discovery_enabled(&self, enabled: bool)
pub fn is_local_discovery_enabled(&self) -> bool
Sourcepub fn set_pex_send_enabled(&self, enabled: bool)
pub fn set_pex_send_enabled(&self, enabled: bool)
Sets whether sending contacts to other peer over peer exchange is enabled.
Note: PEX sending for a given repo is enabled only if it’s enabled globally using this function and also for the repo using Registration::set_pex_enabled.
pub fn is_pex_send_enabled(&self) -> bool
Sourcepub fn set_pex_recv_enabled(&self, enabled: bool)
pub fn set_pex_recv_enabled(&self, enabled: bool)
Sets whether receiving contacts over peer exchange is enabled.
Note: PEX receiving for a given repo is enabled only if it’s enabled globally using this function and also for the repo using Registration::set_pex_enabled.
pub fn is_pex_recv_enabled(&self) -> bool
Sourcepub async fn external_addr_v4(&self) -> Option<SocketAddrV4>
pub async fn external_addr_v4(&self) -> Option<SocketAddrV4>
Find out external address using the STUN protocol. Currently QUIC only.
Sourcepub async fn external_addr_v6(&self) -> Option<SocketAddrV6>
pub async fn external_addr_v6(&self) -> Option<SocketAddrV6>
Find out external address using the STUN protocol. Currently QUIC only.
Sourcepub async fn nat_behavior(&self) -> Option<NatBehavior>
pub async fn nat_behavior(&self) -> Option<NatBehavior>
Determine the behaviour of the NAT we are behind. Returns None
on unknown.
Currently IPv4 only.
pub fn add_user_provided_peer(&self, peer: &PeerAddr)
pub fn remove_user_provided_peer(&self, peer: &PeerAddr)
pub fn this_runtime_id(&self) -> PublicRuntimeId
pub fn peer_info_collector(&self) -> PeerInfoCollector
pub fn peer_info(&self, addr: PeerAddr) -> Option<PeerInfo>
pub fn current_protocol_version(&self) -> u32
pub fn highest_seen_protocol_version(&self) -> u32
Sourcepub fn on_protocol_mismatch(&self) -> Receiver<()>
pub fn on_protocol_mismatch(&self) -> Receiver<()>
Subscribe to network protocol mismatch events.
Sourcepub fn on_peer_set_change(&self) -> ConnectionSetSubscription
pub fn on_peer_set_change(&self) -> ConnectionSetSubscription
Subscribe change in connected peers events.
Sourcepub async fn register(&self, handle: RepositoryHandle) -> Registration
pub async fn register(&self, handle: RepositoryHandle) -> Registration
Register a local repository into the network. This links the repository with all matching repositories of currently connected remote replicas as well as any replicas connected in the future. The repository is automatically deregistered when the returned handle is dropped.
Note: A repository should have at most one registration - creating more than one has undesired effects. This is currently not enforced and so it’s a responsibility of the caller.
Sourcepub async fn shutdown(&self)
pub async fn shutdown(&self)
Gracefully disconnect from peers. Failing to call this function on app termination will cause the peers to not learn that we disconnected just now. They will still find out later once the keep-alive mechanism kicks in, but in the mean time we will not be able to reconnect (by starting the app again) because the remote peer will keep dropping new connections from us.
Auto Trait Implementations§
impl Freeze for Network
impl !RefUnwindSafe for Network
impl Send for Network
impl Sync for Network
impl Unpin for Network
impl !UnwindSafe for Network
Blanket Implementations§
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
§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>
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>
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