Struct Connections

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

TCP connections provides reliable connection to a friend via multiple TCP relays.

Implementations§

Source§

impl Connections

Source

pub fn new( dht_pk: PublicKey, dht_sk: SecretKey, incoming_tx: UnboundedSender<(PublicKey, IncomingPacket)>, ) -> Self

Create new TCP connections object.

Source

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.

Source

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.

Source

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.

Source

pub async fn remove_connection( &self, node_pk: PublicKey, ) -> Result<(), ConnectionError>

Remove connection to a friend via relays.

Source

pub async fn send_data( &self, node_pk: PublicKey, data: DataPayload, ) -> Result<(), ConnectionError>

Send Data packet to a node via one of the relays.

Source

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.

Source

pub async fn send_onion( &self, relay_pk: PublicKey, onion_request: OnionRequest, ) -> Result<(), ConnectionError>

Send OnionRequest packet to relay with specified PublicKey.

Source

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.

Source

pub async fn get_random_relay(&self) -> Option<PackedNode>

Get a random TCP relay we are connected to.

Source

pub async fn get_random_relays(&self, count: u8) -> Vec<PackedNode>

Get up to count random TCP relays we are connected to.

Source

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

Source§

fn clone(&self) -> Connections

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

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