pub struct NetworkBuilder<T> { /* private fields */ }Expand description
Builds an overlay network for peers grouped under the same network identifier.
All peers can subscribe to multiple topics in this overlay and hook into a data stream per topic where they’ll send and receive data.
Implementations§
Source§impl<T> NetworkBuilder<T>where
T: TopicQuery,
impl<T> NetworkBuilder<T>where
T: TopicQuery,
Sourcepub fn new(network_id: NetworkId) -> Self
pub fn new(network_id: NetworkId) -> Self
Returns a new instance of NetworkBuilder using the given network identifier.
Networks must use the same identifier if they wish to successfully connect and share data.
Sourcepub fn from_config(config: Config) -> Self
pub fn from_config(config: Config) -> Self
Returns a new instance of NetworkBuilder using the given configuration.
Sourcepub fn bind_ip_v4(self, ip: Ipv4Addr) -> Self
pub fn bind_ip_v4(self, ip: Ipv4Addr) -> Self
Sets or overwrites the local IP for IPv4 sockets.
Default is 0.0.0.0 (UNSPECIFIED).
Sourcepub fn bind_port_v4(self, port: u16) -> Self
pub fn bind_port_v4(self, port: u16) -> Self
Sets or overwrites the local bind port for IPv4 sockets.
Default is 2022.
Sourcepub fn bind_ip_v6(self, ip: Ipv6Addr) -> Self
pub fn bind_ip_v6(self, ip: Ipv6Addr) -> Self
Sets or overwrites the local IP for IPv6 sockets.
Default is :: (UNSPECIFIED).
Sourcepub fn bind_port_v6(self, port: u16) -> Self
pub fn bind_port_v6(self, port: u16) -> Self
Sets or overwrites the local bind port for IPv6 sockets.
Default is 2023.
Sourcepub fn private_key(self, private_key: PrivateKey) -> Self
pub fn private_key(self, private_key: PrivateKey) -> Self
Sets or overwrites the private key.
If this value is not set, the NetworkBuilder will generate a new, random key when
building the network.
Sourcepub fn relay(self, url: RelayUrl, stun_only: bool, stun_port: u16) -> Self
pub fn relay(self, url: RelayUrl, stun_only: bool, stun_port: u16) -> Self
Sets the relay used by the local network to facilitate the establishment of direct connections.
Relay nodes are STUN servers which help in establishing a peer-to-peer connection if one or both of the peers are behind a NAT. The relay node might offer proxy functionality on top (via the Tailscale DERP protocol which is very similar to TURN) if the connection attempt fails, which will serve to relay the data in that case.
Sourcepub fn direct_address(
self,
node_id: PublicKey,
addresses: Vec<SocketAddr>,
relay_addr: Option<RelayUrl>,
) -> Self
pub fn direct_address( self, node_id: PublicKey, addresses: Vec<SocketAddr>, relay_addr: Option<RelayUrl>, ) -> Self
Sets the direct address of a peer, identified by their public key (node id).
The direct address should be reachable without the aid of a STUN or TURN-based relay node. However, if the direct connection attempt might fail (for example, because of a NAT or Firewall), the relay node of that peer can be supplied to allow connecting to it via a fallback connection.
If no relay address is given but turns out to be required, we optimistically try to use our own relay node instead (if specified). This might still fail, as we can’t know if the peer is using the same relay node.
Sourcepub fn discovery(self, handler: impl Discovery + 'static) -> Self
pub fn discovery(self, handler: impl Discovery + 'static) -> Self
Adds one or more discovery strategy, such as mDNS.
Sourcepub fn sync(self, config: SyncConfiguration<T>) -> Self
pub fn sync(self, config: SyncConfiguration<T>) -> Self
Sets the sync protocol and configuration.
Sync sessions will be automatically initiated with any known peers with whom we share topics of interest.
Sourcepub fn gossip(self, config: GossipConfig) -> Self
pub fn gossip(self, config: GossipConfig) -> Self
Sets the gossip configuration.
Configuration parameters define the behavior of the swarm membership (HyParView) and gossip broadcast (Plumtree) layers, as well as the maximum message size.
Sourcepub fn protocol(
self,
protocol_name: &'static [u8],
handler: impl ProtocolHandler + 'static,
) -> Self
pub fn protocol( self, protocol_name: &'static [u8], handler: impl ProtocolHandler + 'static, ) -> Self
Adds additional, custom protocols for communication between two peers.
Sourcepub async fn build(self) -> Result<Network<T>>where
T: TopicQuery + TopicId + 'static,
pub async fn build(self) -> Result<Network<T>>where
T: TopicQuery + TopicId + 'static,
Returns a handle to a newly-spawned instance of Network.
A peer-to-peer endpoint is created and bound to a QUIC socket, after which the gossip, engine and connection handlers are instantiated. A sync handler is also instantiated if a sync protocol is provided. Direct addresses for network peers are added to the engine from the address book and core protocols are registered.
After configuration and registration processes are complete, the network is spawned and an attempt is made to retrieve a direct address for a network peer so that a connection may be made. If no address is retrieved within the timeout limit, the network is shut down and an error is returned.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for NetworkBuilder<T>
impl<T> !RefUnwindSafe for NetworkBuilder<T>
impl<T> Send for NetworkBuilder<T>
impl<T> Sync for NetworkBuilder<T>
impl<T> Unpin for NetworkBuilder<T>
impl<T> !UnwindSafe for NetworkBuilder<T>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§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
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.