Struct qp2p::QuicP2p[][src]

pub struct QuicP2p { /* fields omitted */ }
Expand description

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(())
}

pub async fn rebootstrap(
    &mut self,
    endpoint: &Endpoint,
    bootstrap_nodes: &[SocketAddr]
) -> Result<SocketAddr>
[src]

Rebootstrap

pub fn update_bootstrap_contacts(&mut self, bootstrap_nodes: &[SocketAddr])[src]

Clears the current bootstrap cache and replaces the peer list with the provided bootstrap nodes.

Trait Implementations

impl Clone for QuicP2p[src]

fn clone(&self) -> QuicP2p[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for QuicP2p[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl !RefUnwindSafe for QuicP2p

impl Send for QuicP2p

impl Sync for QuicP2p

impl Unpin for QuicP2p

impl !UnwindSafe for QuicP2p

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[src]

fn instrument(self, span: Span) -> Instrumented<Self>[src]

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

fn in_current_span(self) -> Instrumented<Self>[src]

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

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

pub fn into(self) -> U[src]

Performs the conversion.

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

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

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

pub fn vzip(self) -> V