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
impl Server
Sourcepub fn set_udp_onion_sink(
&mut self,
onion_sink: Sender<(OnionRequest, SocketAddr)>,
)
pub fn set_udp_onion_sink( &mut self, onion_sink: Sender<(OnionRequest, SocketAddr)>, )
Create a new Server
with onion
Sourcepub async fn insert(&self, client: Client) -> Result<(), Error>
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.
Sourcepub async fn handle_packet(
&self,
pk: &PublicKey,
packet: Packet,
) -> Result<(), Error>
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.
Sourcepub async fn handle_udp_onion_response(
&self,
ip_addr: IpAddr,
port: u16,
payload: InnerOnionResponse,
) -> Result<(), Error>
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
.
Sourcepub async fn shutdown_client(
&self,
pk: &PublicKey,
ip_addr: IpAddr,
port: u16,
) -> Result<(), Error>
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
.
Sourcepub async fn send_pings(&self) -> Result<(), Error>
pub async fn send_pings(&self) -> Result<(), Error>
Send pings to all connected clients and terminate all timed out clients.
Trait Implementations§
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> 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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