Skip to main content

Network

Struct Network 

Source
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

Source

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.

Source

pub const fn port(&self) -> Option<u16>

The IPv4 port it takes connections on.

Source

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.

Source

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.

Source

pub fn endpoint(&self) -> [u8; 32]

This endpoint’s ID: the public half of its key.

Source

pub fn local_addresses(&self) -> Vec<SocketAddr>

The addresses this endpoint takes connections on, as this computer reaches them, for connecting without discovery.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn connect_at( &self, peer: [u8; 32], addresses: &[SocketAddr], protocol: Protocol, timeout: Duration, ) -> Result<Connection, NetError>

Connects to an endpoint at these addresses.

§Errors

As Network::connect.

Source

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.

Trait Implementations§

Source§

impl Drop for Network

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more