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]
impl QuicP2p
[src]pub fn with_config(
cfg: Option<Config>,
bootstrap_nodes: &[SocketAddr],
use_bootstrap_cache: bool
) -> Result<Self>
[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]
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]
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]
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]
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
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> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]fn instrument(self, span: Span) -> Instrumented<Self>
[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]
fn in_current_span(self) -> Instrumented<Self>
[src]impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
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]
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<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,