Struct qp2p::QuicP2p [−][src]
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]
cfg: Option<Config>,
bootstrap_nodes: &[SocketAddr],
use_bootstrap_cache: bool
) -> Result<Self>
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]
&self
) -> Result<(Endpoint, IncomingConnections, IncomingMessages, DisconnectionEvents, SocketAddr)>
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]
&self
) -> Result<(Endpoint, IncomingConnections, IncomingMessages, DisconnectionEvents)>
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
Auto Trait Implementations
impl !RefUnwindSafe for QuicP2p
[src]
impl Send for QuicP2p
[src]
impl Sync for QuicP2p
[src]
impl Unpin for QuicP2p
[src]
impl !UnwindSafe for QuicP2p
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
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]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
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]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,