pub struct Network { /* private fields */ }Expand description
The entrypoint to the Mosaic network SDK.
Notes:
-
This type represents a Mosaik network connection and provides methods to access different facilities such as peer discovery and stream management.
-
In most cases one network instance will represent one running process/node.
-
Each network instance has a globally unique identity that is the public key of the secret key used to construct it. If no secret key is provided a new random key will be generated. This is an important property because node identities are globally unique across all Mosaik networks and nodes can be addressed by their public keys alone. The discovery mechanism is responsible for resolving the corresponding network addresses for a given public key. Knowing the physical transport addresses of a peer is not sufficient to identify a node and connect to it.
-
By default a random local port will be chosen for the network instance. This can be overridden by providing a specific port in the builder.
-
Mosaik networks are identified by a
NetworkIdwhich is a unique identifier (a blake3 hash of the network string name). Nodes can only connect to other nodes that are part of the same network (i.e. have the sameNetworkId).
Implementations§
Source§impl Network
Public construction API
impl Network
Public construction API
Sourcepub fn builder(network_id: impl Into<NetworkId>) -> NetworkBuilder
pub fn builder(network_id: impl Into<NetworkId>) -> NetworkBuilder
Creates a new network builder with a given network id.
Source§impl Network
Public API
impl Network
Public API
Sourcepub fn network_id(&self) -> &NetworkId
pub fn network_id(&self) -> &NetworkId
Returns the network identifier of the network that this instance is connected to.
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 UnsafeUnpin 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
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> 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