pub struct Connections { /* private fields */ }
Expand description
TCP connections provides reliable connection to a friend via multiple TCP relays.
Implementations§
Source§impl Connections
impl Connections
Sourcepub fn new(
dht_pk: PublicKey,
dht_sk: SecretKey,
incoming_tx: UnboundedSender<(PublicKey, IncomingPacket)>,
) -> Self
pub fn new( dht_pk: PublicKey, dht_sk: SecretKey, incoming_tx: UnboundedSender<(PublicKey, IncomingPacket)>, ) -> Self
Create new TCP connections object.
Sourcepub async fn add_relay_global(
&self,
relay_addr: SocketAddr,
relay_pk: PublicKey,
) -> Result<(), ConnectionError>
pub async fn add_relay_global( &self, relay_addr: SocketAddr, relay_pk: PublicKey, ) -> Result<(), ConnectionError>
Add relay we are supposed to be connected to. These relays are necessary
for initial connection so that we are able to find friends and to send
them our relays. Later when more relays are received from our friends
they should be added via add_relay_connection
method.
Sourcepub async fn add_relay_connection(
&self,
relay_addr: SocketAddr,
relay_pk: PublicKey,
node_pk: PublicKey,
) -> Result<(), ConnectionError>
pub async fn add_relay_connection( &self, relay_addr: SocketAddr, relay_pk: PublicKey, node_pk: PublicKey, ) -> Result<(), ConnectionError>
Add relay that we received from our friend. This relay can be ignored if
we already connected to this friend via at least
RECOMMENDED_FRIEND_TCP_CONNECTIONS
relays. Connection to our friend
via this relay will be added as well.
Sourcepub async fn add_connection(
&self,
relay_pk: PublicKey,
node_pk: PublicKey,
) -> Result<(), ConnectionError>
pub async fn add_connection( &self, relay_pk: PublicKey, node_pk: PublicKey, ) -> Result<(), ConnectionError>
Add a connection to our friend via relay. It means that we will send
RouteRequest
packet to this relay and wait for the friend to become
connected.
Sourcepub async fn remove_connection(
&self,
node_pk: PublicKey,
) -> Result<(), ConnectionError>
pub async fn remove_connection( &self, node_pk: PublicKey, ) -> Result<(), ConnectionError>
Remove connection to a friend via relays.
Sourcepub async fn send_data(
&self,
node_pk: PublicKey,
data: DataPayload,
) -> Result<(), ConnectionError>
pub async fn send_data( &self, node_pk: PublicKey, data: DataPayload, ) -> Result<(), ConnectionError>
Send Data
packet to a node via one of the relays.
Sourcepub async fn send_oob(
&self,
relay_pk: PublicKey,
node_pk: PublicKey,
data: Vec<u8>,
) -> Result<(), ConnectionError>
pub async fn send_oob( &self, relay_pk: PublicKey, node_pk: PublicKey, data: Vec<u8>, ) -> Result<(), ConnectionError>
Send OobSend
packet to a node via relay with specified PublicKey
.
Sourcepub async fn send_onion(
&self,
relay_pk: PublicKey,
onion_request: OnionRequest,
) -> Result<(), ConnectionError>
pub async fn send_onion( &self, relay_pk: PublicKey, onion_request: OnionRequest, ) -> Result<(), ConnectionError>
Send OnionRequest
packet to relay with specified PublicKey
.
Sourcepub async fn set_connection_status(
&self,
node_pk: PublicKey,
status: NodeConnectionStatus,
) -> Result<(), ConnectionError>
pub async fn set_connection_status( &self, node_pk: PublicKey, status: NodeConnectionStatus, ) -> Result<(), ConnectionError>
Change status of connection to the node. Connections module need to know whether connection is used to be able to put to sleep relay connections.
Sourcepub async fn get_random_relay(&self) -> Option<PackedNode>
pub async fn get_random_relay(&self) -> Option<PackedNode>
Get a random TCP relay we are connected to.
Sourcepub async fn get_random_relays(&self, count: u8) -> Vec<PackedNode>
pub async fn get_random_relays(&self, count: u8) -> Vec<PackedNode>
Get up to count
random TCP relays we are connected to.
Sourcepub async fn run(&self) -> Result<(), ConnectionError>
pub async fn run(&self) -> Result<(), ConnectionError>
Run TCP periodical tasks. Result future will never be completed successfully.
Trait Implementations§
Source§impl Clone for Connections
impl Clone for Connections
Source§fn clone(&self) -> Connections
fn clone(&self) -> Connections
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for Connections
impl !RefUnwindSafe for Connections
impl Send for Connections
impl Sync for Connections
impl Unpin for Connections
impl !UnwindSafe for Connections
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