pub struct NetCrypto { /* private fields */ }
Expand description
Struct that manages crypto connections to friends and handles net crypto packets from both UDP and TCP connections.
Implementations§
Source§impl NetCrypto
impl NetCrypto
Sourcepub fn new(args: NetCryptoNewArgs) -> NetCrypto
pub fn new(args: NetCryptoNewArgs) -> NetCrypto
Create new NetCrypto
object
Sourcepub async fn add_friend(&self, real_pk: PublicKey)
pub async fn add_friend(&self, real_pk: PublicKey)
Add a friend to accept incoming connections from him.
Sourcepub async fn remove_friend(&self, real_pk: PublicKey)
pub async fn remove_friend(&self, real_pk: PublicKey)
Remove a friend to stop accepting incoming connections from him.
Sourcepub async fn add_connection(
&self,
peer_real_pk: PublicKey,
peer_dht_pk: PublicKey,
)
pub async fn add_connection( &self, peer_real_pk: PublicKey, peer_dht_pk: PublicKey, )
Add connection to a friend when its DHT PublicKey
is known.
Sourcepub async fn kill_connection(
&self,
real_pk: PublicKey,
) -> Result<(), KillConnectionError>
pub async fn kill_connection( &self, real_pk: PublicKey, ) -> Result<(), KillConnectionError>
Kill a connection sending PACKET_ID_KILL
packet and removing it from
the connections list.
Sourcepub async fn set_friend_udp_addr(&self, real_pk: PublicKey, saddr: SocketAddr)
pub async fn set_friend_udp_addr(&self, real_pk: PublicKey, saddr: SocketAddr)
Set friend’s UDP IP address when it gets known.
Sourcepub async fn send_lossless(
&self,
real_pk: PublicKey,
packet: Vec<u8>,
) -> Result<(), SendLosslessPacketError>
pub async fn send_lossless( &self, real_pk: PublicKey, packet: Vec<u8>, ) -> Result<(), SendLosslessPacketError>
Send lossless packet to a friend via established connection.
Handle CookieRequest
packet received from UDP socket
Handle CookieRequest
packet received from TCP socket
Handle CookieResponse
and if it’s correct change connection status to HandshakeSending
.
Handle CookieResponse
packet received from UDP socket
Handle CookieResponse
packet received from TCP socket
Sourcepub async fn handle_crypto_handshake(
&self,
connection: &mut CryptoConnection,
packet: &CryptoHandshake,
) -> Result<(), HandlePacketError>
pub async fn handle_crypto_handshake( &self, connection: &mut CryptoConnection, packet: &CryptoHandshake, ) -> Result<(), HandlePacketError>
Handle CryptoHandshake
and if it’s correct change connection status to NotConfirmed
.
Sourcepub async fn handle_udp_crypto_handshake(
&self,
packet: &CryptoHandshake,
addr: SocketAddr,
) -> Result<(), HandlePacketError>
pub async fn handle_udp_crypto_handshake( &self, packet: &CryptoHandshake, addr: SocketAddr, ) -> Result<(), HandlePacketError>
Handle CryptoHandshake
packet received from UDP socket
Sourcepub async fn handle_tcp_crypto_handshake(
&self,
packet: &CryptoHandshake,
sender_pk: PublicKey,
) -> Result<(), HandlePacketError>
pub async fn handle_tcp_crypto_handshake( &self, packet: &CryptoHandshake, sender_pk: PublicKey, ) -> Result<(), HandlePacketError>
Handle CryptoHandshake
packet received from TCP socket
Sourcepub async fn handle_udp_crypto_data(
&self,
packet: &CryptoData,
addr: SocketAddr,
) -> Result<(), HandlePacketError>
pub async fn handle_udp_crypto_data( &self, packet: &CryptoData, addr: SocketAddr, ) -> Result<(), HandlePacketError>
Handle CryptoData
packet received from UDP socket
Sourcepub async fn handle_tcp_crypto_data(
&self,
packet: &CryptoData,
sender_pk: PublicKey,
) -> Result<(), HandlePacketError>
pub async fn handle_tcp_crypto_data( &self, packet: &CryptoData, sender_pk: PublicKey, ) -> Result<(), HandlePacketError>
Handle CryptoData
packet received from TCP socket
Sourcepub async fn run(&self) -> Result<(), RunError>
pub async fn run(&self) -> Result<(), RunError>
Run net_crypto
periodical tasks. Result future will never be completed
successfully.
Sourcepub async fn set_dht_pk_sink(
&self,
dht_pk_tx: UnboundedSender<(PublicKey, PublicKey)>,
)
pub async fn set_dht_pk_sink( &self, dht_pk_tx: UnboundedSender<(PublicKey, PublicKey)>, )
Set sink to send DHT PublicKey
when it gets known.
Sourcepub async fn set_connection_status_sink(
&self,
connection_status_tx: UnboundedSender<(PublicKey, bool)>,
)
pub async fn set_connection_status_sink( &self, connection_status_tx: UnboundedSender<(PublicKey, bool)>, )
Set sink to send a connection status when it becomes connected or disconnected.
Sourcepub async fn set_tcp_sink(&self, tcp_tx: Sender<(DataPayload, PublicKey)>)
pub async fn set_tcp_sink(&self, tcp_tx: Sender<(DataPayload, PublicKey)>)
Set sink for sending TCP packets via relays.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NetCrypto
impl !RefUnwindSafe for NetCrypto
impl Send for NetCrypto
impl Sync for NetCrypto
impl Unpin for NetCrypto
impl !UnwindSafe for NetCrypto
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