Struct qp2p::QuicP2p[][src]

pub struct QuicP2p { /* fields omitted */ }

Main QuicP2p instance to communicate with QuicP2p using an async API

Implementations

impl QuicP2p[src]

pub fn with_config(
    cfg: Option<Config>,
    bootstrap_nodes: &[SocketAddr],
    use_bootstrap_cache: bool
) -> Result<Self>
[src]

Construct QuicP2p with supplied parameters, ready to be used. If config is not specified it'll call Config::read_or_construct_default()

bootstrap_nodes: takes bootstrap nodes from the user.

In addition to bootstrap nodes provided, optionally use the nodes found in the bootstrap cache file (if such a file exists) or disable this feature.

Example

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

let mut config = Config::default();
config.local_ip = Some(IpAddr::V4(Ipv4Addr::LOCALHOST));
config.local_port = Some(3000);
let hcc = &["127.0.0.1:8080".parse().unwrap()];
let quic_p2p = QuicP2p::with_config(Some(config), hcc, true).expect("Error initializing QuicP2p");

pub async fn bootstrap(
    &self
) -> Result<(Endpoint, IncomingConnections, IncomingMessages, DisconnectionEvents, SocketAddr)>
[src]

Bootstrap to the network.

Bootstrap concept is different from "connect" in several ways: bootstrap() will try to connect to all peers which are specified in the config (hard_coded_contacts) or were previously cached. Once a connection with a peer succeeds, a Connection for such peer will be returned and all other connections will be dropped.

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.local_ip = Some(IpAddr::V4(Ipv4Addr::LOCALHOST));
    config.local_port = Some(3000);
    let mut quic_p2p = QuicP2p::with_config(Some(config.clone()), Default::default(), true)?;
    let (mut endpoint, _, _, _) = quic_p2p.new_endpoint().await?;
    let peer_addr = endpoint.socket_addr();

    config.local_port = Some(3001);
    let mut quic_p2p = QuicP2p::with_config(Some(config), &[peer_addr], true)?;
    let endpoint = quic_p2p.bootstrap().await?;
    Ok(())
}

pub async fn new_endpoint(
    &self
) -> Result<(Endpoint, IncomingConnections, IncomingMessages, DisconnectionEvents)>
[src]

Create a new Endpoint which can be used to connect to peers and send messages to them, as well as listen to messages incoming from other peers.

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.local_ip = Some(IpAddr::V4(Ipv4Addr::LOCALHOST));
    let mut quic_p2p = QuicP2p::with_config(Some(config.clone()), Default::default(), true)?;
    let (endpoint, incoming_connections, incoming_messages, disconnections) = quic_p2p.new_endpoint().await?;
    Ok(())
}

Trait Implementations

impl Clone for QuicP2p[src]

impl Debug for QuicP2p[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> Instrument for T[src]

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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