ouisync

Struct Network

Source
pub struct Network { /* private fields */ }

Implementations§

Source§

impl Network

Source

pub fn new( monitor: StateMonitor, dht_contacts: Option<Arc<dyn DhtContactsStoreTrait>>, this_runtime_id: Option<SecretRuntimeId>, ) -> Self

Source

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.

Source

pub fn listener_local_addrs(&self) -> Vec<PeerAddr>

Source

pub fn set_port_forwarding_enabled(&self, enabled: bool)

Source

pub fn is_port_forwarding_enabled(&self) -> bool

Source

pub fn set_local_discovery_enabled(&self, enabled: bool)

Source

pub fn is_local_discovery_enabled(&self) -> bool

Source

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.

Source

pub fn is_pex_send_enabled(&self) -> bool

Source

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.

Source

pub fn is_pex_recv_enabled(&self) -> bool

Source

pub async fn external_addr_v4(&self) -> Option<SocketAddrV4>

Find out external address using the STUN protocol. Currently QUIC only.

Source

pub async fn external_addr_v6(&self) -> Option<SocketAddrV6>

Find out external address using the STUN protocol. Currently QUIC only.

Source

pub async fn nat_behavior(&self) -> Option<NatBehavior>

Determine the behaviour of the NAT we are behind. Returns None on unknown. Currently IPv4 only.

Source

pub fn stats(&self) -> Stats

Get the network traffic stats.

Source

pub fn add_user_provided_peer(&self, peer: &PeerAddr)

Source

pub fn remove_user_provided_peer(&self, peer: &PeerAddr)

Source

pub fn this_runtime_id(&self) -> PublicRuntimeId

Source

pub fn peer_info_collector(&self) -> PeerInfoCollector

Source

pub fn peer_info(&self, addr: PeerAddr) -> Option<PeerInfo>

Source

pub fn current_protocol_version(&self) -> u32

Source

pub fn highest_seen_protocol_version(&self) -> u32

Source

pub fn on_protocol_mismatch(&self) -> Receiver<()>

Subscribe to network protocol mismatch events.

Source

pub fn on_peer_set_change(&self) -> ConnectionSetSubscription

Subscribe change in connected peers events.

Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T