pub struct Network { /* private fields */ }Implementations§
Source§impl Network
impl Network
Sourcepub fn builder() -> NetworkBuilder
pub fn builder() -> NetworkBuilder
Returns builder to create Network with custom options.
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) -> u64
pub fn highest_seen_protocol_version(&self) -> u64
Sourcepub fn subscribe(&self) -> NetworkEventReceiver
pub fn subscribe(&self) -> NetworkEventReceiver
Subscribe to network events.
Sourcepub fn register(&self, handle: RepositoryHandle) -> Registration
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.
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.
Sourcepub fn set_request_timeout(&self, timeout: Duration)
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.
Sourcepub fn open_udp_side_channel_v4(&self) -> Option<SideChannel>
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.
Sourcepub fn open_udp_side_channel_v6(&self) -> Option<SideChannel>
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.
Sourcepub fn open_stream(
&self,
addr: PeerAddr,
topic_id: TopicId,
) -> Option<(SendStream, RecvStream)>
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.
Sourcepub fn set_dht_routers(&self, routers: HashSet<String>)
pub fn set_dht_routers(&self, routers: HashSet<String>)
Changes the DHT routers (boostrap nodes), rebootstraps the DHTs and restarts any ongoing lookups.
Sourcepub fn dht_routers(&self) -> HashSet<String>
pub fn dht_routers(&self) -> HashSet<String>
Returns the current DHT routers (bootstrap nodes).
Sourcepub fn dht_lookup(&self, info_hash: InfoHash, announce: bool) -> DhtLookupStream
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.
Sourcepub fn set_local_dht_enabled(&self, enabled: bool)
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.
pub fn is_local_dht_enabled(&self) -> bool
Sourcepub async fn pin_dht(&self) -> DhtPin
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§
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