Struct Server

Source
pub struct Server { /* private fields */ }
Expand description

A Server is a structure that holds connected clients, manages their links and handles their responses. Notice that there is no actual network code here, the Server accepts packets by value from Server::handle_packet, sends packets back to clients via futures::sync::mpsc::UnboundedSender<Packet> channel, accepts onion responses from Server::handle_udp_onion_response and sends onion requests via futures::sync::mpsc::UnboundedSender<OnionRequest> channel. The outer code should manage how to handshake connections, get packets from clients, pass them into Server::handle_packet, get onion responses from UPD socket and send them to Server::handle_udp_onion_response, create mpsc channels, take packets from futures::sync::mpsc::UnboundedReceiver<Packet> send them back to clients via network.

Implementations§

Source§

impl Server

Source

pub fn new() -> Server

Create a new Server without onion

Source

pub fn set_udp_onion_sink( &mut self, onion_sink: Sender<(OnionRequest, SocketAddr)>, )

Create a new Server with onion

Source

pub async fn insert(&self, client: Client) -> Result<(), Error>

Insert the client into connected_clients. If connected_clients contains a client with the same pk it will be terminated.

Source

pub async fn handle_packet( &self, pk: &PublicKey, packet: Packet, ) -> Result<(), Error>

The main processing function. Call in on each incoming packet from connected and handshaked client.

Source

pub async fn handle_udp_onion_response( &self, ip_addr: IpAddr, port: u16, payload: InnerOnionResponse, ) -> Result<(), Error>

Send OnionResponse packet to the client by it’s std::net::IpAddr.

Source

pub async fn shutdown_client( &self, pk: &PublicKey, ip_addr: IpAddr, port: u16, ) -> Result<(), Error>

Gracefully shutdown client by pk, IP address and port. IP address and port are used to ensure that the right client will be removed. If the client with passed pk has different IP address or port it means that it was recently reconnected and it shouldn’t be removed by the old connection finalization step. If IP address with port are correct remove it from the list of connected clients. If there are any clients mutually linked to current client, we send them corresponding DisconnectNotification.

Source

pub async fn send_pings(&self) -> Result<(), Error>

Send pings to all connected clients and terminate all timed out clients.

Trait Implementations§

Source§

impl Clone for Server

Source§

fn clone(&self) -> Server

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Server

Source§

fn default() -> Server

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Server

§

impl !RefUnwindSafe for Server

§

impl Send for Server

§

impl Sync for Server

§

impl Unpin for Server

§

impl !UnwindSafe for Server

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.