Network

Struct Network 

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

Implementations§

Source§

impl Network

Source

pub fn builder() -> NetworkBuilder

Returns builder to create Network with custom options.

Source

pub fn new() -> Self

Create network with default options. Equal to Self::builder().build().

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) -> u64

Source

pub fn highest_seen_protocol_version(&self) -> u64

Source

pub fn subscribe(&self) -> NetworkEventReceiver

Subscribe to network events.

Source

pub 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.

Source

pub fn set_request_timeout(&self, timeout: Duration)

Change the sync protocol request timeout. Useful mostly for testing and benchmarking as the default value should be sufficient for most use cases.

Source

pub fn open_udp_side_channel_v4(&self) -> Option<SideChannel>

Opens a side channel for the underlying IPv4 UDP socket, or None if IPv4 QUIC stack isn’t configured.

The side channel is used to send/receive raw UDP datagrams on the same socket that the sync protocol uses.

Source

pub fn open_udp_side_channel_v6(&self) -> Option<SideChannel>

Opens a side channel for the underlying IPv6 UDP socket, or None if IPv6 QUIC stack isn’t configured.

The side channel is used to send/receive raw UDP datagrams on the same socket that the sync protocol uses.

Source

pub fn open_stream( &self, addr: PeerAddr, topic_id: TopicId, ) -> Option<(SendStream, RecvStream)>

Opens raw byte stream to the given peer, bound to the given topic. This can be used to send/recv arbitrary data to the peer, outside of the ouisync protocol.

Returns None if no active connection to the peer exists.

Source

pub fn set_dht_routers(&self, routers: HashSet<String>)

Changes the DHT routers (boostrap nodes), rebootstraps the DHTs and restarts any ongoing lookups.

Source

pub fn dht_routers(&self) -> HashSet<String>

Returns the current DHT routers (bootstrap nodes).

Source

pub fn dht_lookup(&self, info_hash: InfoHash, announce: bool) -> DhtLookupStream

Performs explicit DHT lookup or announce for the given infohash and returns a stream of the discovered peer addresses. It will not automatically connect to them.

Source

pub fn set_local_dht_enabled(&self, enabled: bool)

Set whether DHT on the local network (or localhost) is enabled. By default this is false because DHT is a global discovery mechanism and finding a local peer on it is unexpected (and could indicate malice). However, is some situations it’s still useful to enable it (typically for testing).

Note: this option is currently experimental and unstable (semver extempt). It’s possible it will be removed in the future.

Source

pub fn is_local_dht_enabled(&self) -> bool

Source

pub async fn pin_dht(&self) -> DhtPin

Creates a “pin” which starts the DHT instances and keeps them running. This prevents the DHTs to shut down even when there are no more ongoing lookups. This is useful if one wants to avoid having to rebootstrap the DHT when doing another lookup in the future.

Note that DHT is automatically started and kept running when there is at least one repository with DHT enabled. Thus, pinning the DHT while having DHT-enabled repos is unnecessary (but harmless).

Trait Implementations§

Source§

impl Default for Network

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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