[][src]Struct qp2p::Connection

pub struct Connection { /* fields omitted */ }

Connection instance to a node which can be used to send messages to it

Implementations

impl Connection[src]

pub fn remote_address(&self) -> SocketAddr[src]

Returns the address of the connected peer.

Example

use qp2p::{QuicP2p, Config, Error};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};

#[tokio::main]
async fn main() -> Result<(), Error> {

    let mut config = Config::default();
    config.ip = Some(IpAddr::V4(Ipv4Addr::LOCALHOST));
    let mut quic_p2p = QuicP2p::with_config(Some(config.clone()), Default::default(), true)?;
    let peer_1 = quic_p2p.new_endpoint()?;
    let peer1_addr = peer_1.our_endpoint()?;

    let (peer_2, connection) = quic_p2p.connect_to(&peer1_addr).await?;
    assert_eq!(connection.remote_address(), peer1_addr);
    Ok(())
}

pub async fn open_bi_stream<'_>(&'_ self) -> Result<(SendStream, RecvStream)>[src]

Get connection streams for reading/writing

Example

use qp2p::{QuicP2p, Config, Error};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};

#[tokio::main]
async fn main() -> Result<(), Error> {

    let mut config = Config::default();
    config.ip = Some(IpAddr::V4(Ipv4Addr::LOCALHOST));
    let mut quic_p2p = QuicP2p::with_config(Some(config.clone()), Default::default(), true)?;
    let peer_1 = quic_p2p.new_endpoint()?;
    let peer1_addr = peer_1.our_endpoint()?;

    let (peer_2, connection) = quic_p2p.connect_to(&peer1_addr).await?;
    let (send_stream, recv_stream) = connection.open_bi_stream().await?;
    Ok(())
}

pub async fn send<'_>(&'_ self, msg: Bytes) -> Result<(SendStream, RecvStream)>[src]

Send message to the connected peer via a bi-directional stream. This returns the streams to send additional messages / read responses sent using the same stream.

pub async fn send_uni<'_>(&'_ self, msg: Bytes) -> Result<()>[src]

Send message to peer using a uni-directional stream.

pub fn close(&self)[src]

Gracefully close connection immediatelly

Trait Implementations

impl Drop for Connection[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,