pub struct Network { /* private fields */ }Expand description
This replica’s endpoint on the network, which connects to others and takes their connections.
Implementations§
Source§impl Network
impl Network
Sourcepub fn start(secret: &[u8; 32], options: Options) -> Result<Network, NetError>
pub fn start(secret: &[u8; 32], options: Options) -> Result<Network, NetError>
Starts the endpoint with the 32-byte secret of its key, as options say.
§Errors
Returns an error if the runtime or the endpoint cannot start.
Sourcepub fn port_refused(&self) -> Option<(u16, &str)>
pub fn port_refused(&self) -> Option<(u16, &str)>
The port it asked for, and why it could not have it, if it took another: as when
another program of NibKeep has it. A firewall that lets only the ports from that one
through, PORTS of them, lets this endpoint’s connections through only if it took
one of them.
Sourcepub fn remember(
&self,
peer: [u8; 32],
addresses: &[SocketAddr],
announced: Option<&str>,
)
pub fn remember( &self, peer: [u8; 32], addresses: &[SocketAddr], announced: Option<&str>, )
Tells the endpoint where another is, and what it announces, as if it had found it on the network: for tests, and for networks where discovery does not work.
Sourcepub fn local_addresses(&self) -> Vec<SocketAddr>
pub fn local_addresses(&self) -> Vec<SocketAddr>
The addresses this endpoint takes connections on, as this computer reaches them, for connecting without discovery.
Sourcepub fn announce(&self, text: Option<&str>) -> Result<(), NetError>
pub fn announce(&self, text: Option<&str>) -> Result<(), NetError>
Adds text to what the endpoint announces on the network, or stops announcing any.
§Errors
Returns an error if the text is too long to announce.
Sourcepub fn find_announcing(
&self,
text: &str,
except: &BTreeSet<[u8; 32]>,
timeout: Duration,
) -> Result<[u8; 32], NetError>
pub fn find_announcing( &self, text: &str, except: &BTreeSet<[u8; 32]>, timeout: Duration, ) -> Result<[u8; 32], NetError>
Waits up to timeout for an endpoint that announces text, other than those in
except, and returns the one with the lowest ID among those found, so that one that
tries them in turn tries each once.
§Errors
Returns NetError::Timeout if none appears in time.
Sourcepub fn find(
&self,
endpoints: &BTreeSet<[u8; 32]>,
timeout: Duration,
) -> BTreeSet<[u8; 32]>
pub fn find( &self, endpoints: &BTreeSet<[u8; 32]>, timeout: Duration, ) -> BTreeSet<[u8; 32]>
Waits up to timeout until every one of endpoints is seen on the network, and
returns those seen by then.
Sourcepub fn connect(
&self,
peer: [u8; 32],
protocol: Protocol,
timeout: Duration,
) -> Result<Connection, NetError>
pub fn connect( &self, peer: [u8; 32], protocol: Protocol, timeout: Duration, ) -> Result<Connection, NetError>
Connects to an endpoint found on the network.
§Errors
Returns an error if the endpoint cannot be reached, or refuses, within timeout.
Sourcepub fn connect_at(
&self,
peer: [u8; 32],
addresses: &[SocketAddr],
protocol: Protocol,
timeout: Duration,
) -> Result<Connection, NetError>
pub fn connect_at( &self, peer: [u8; 32], addresses: &[SocketAddr], protocol: Protocol, timeout: Duration, ) -> Result<Connection, NetError>
Sourcepub fn accept(
&self,
timeout: Option<Duration>,
) -> Result<Option<Connection>, NetError>
pub fn accept( &self, timeout: Option<Duration>, ) -> Result<Option<Connection>, NetError>
Waits for another endpoint to connect, for up to timeout, or for as long as it
takes; None if none did in time. Connections that fail before they speak a
protocol of NibKeep are passed by.
§Errors
Returns an error if the endpoint was closed, or takes no connections.