pub struct P2pEndpoint { /* private fields */ }Expand description
P2P endpoint - the primary API for ant-quic
This struct provides the main interface for P2P communication with NAT traversal, connection management, and secure messaging.
Implementations§
Source§impl P2pEndpoint
impl P2pEndpoint
Sourcepub async fn new(config: P2pConfig) -> Result<Self, EndpointError>
pub async fn new(config: P2pConfig) -> Result<Self, EndpointError>
Create a new P2P endpoint with the given configuration
Sourcepub fn local_addr(&self) -> Option<SocketAddr>
pub fn local_addr(&self) -> Option<SocketAddr>
Get the local bind address
Sourcepub fn external_addr(&self) -> Option<SocketAddr>
pub fn external_addr(&self) -> Option<SocketAddr>
Get observed external address (if discovered)
Sourcepub fn public_key_bytes(&self) -> [u8; 32]
pub fn public_key_bytes(&self) -> [u8; 32]
Get the public key bytes
Sourcepub async fn connect(
&self,
addr: SocketAddr,
) -> Result<PeerConnection, EndpointError>
pub async fn connect( &self, addr: SocketAddr, ) -> Result<PeerConnection, EndpointError>
Connect to a peer by address (direct connection)
Sourcepub async fn connect_to_peer(
&self,
peer_id: PeerId,
coordinator: Option<SocketAddr>,
) -> Result<PeerConnection, EndpointError>
pub async fn connect_to_peer( &self, peer_id: PeerId, coordinator: Option<SocketAddr>, ) -> Result<PeerConnection, EndpointError>
Connect to a peer by ID using NAT traversal
Sourcepub async fn accept(&self) -> Option<PeerConnection>
pub async fn accept(&self) -> Option<PeerConnection>
Accept incoming connections
Sourcepub async fn disconnect(&self, peer_id: &PeerId) -> Result<(), EndpointError>
pub async fn disconnect(&self, peer_id: &PeerId) -> Result<(), EndpointError>
Disconnect from a peer
Sourcepub async fn send(
&self,
peer_id: &PeerId,
data: &[u8],
) -> Result<(), EndpointError>
pub async fn send( &self, peer_id: &PeerId, data: &[u8], ) -> Result<(), EndpointError>
Send data to a peer
Sourcepub async fn recv(
&self,
timeout: Duration,
) -> Result<(PeerId, Vec<u8>), EndpointError>
pub async fn recv( &self, timeout: Duration, ) -> Result<(PeerId, Vec<u8>), EndpointError>
Receive data from any peer (with timeout)
This function first checks the pending data buffer for data that was buffered during authentication, then polls streams from connected peers. The timeout is properly distributed across all peers to avoid O(n*timeout) delays.
Sourcepub async fn stats(&self) -> EndpointStats
pub async fn stats(&self) -> EndpointStats
Get endpoint statistics
Sourcepub async fn connection_metrics(
&self,
peer_id: &PeerId,
) -> Option<ConnectionMetrics>
pub async fn connection_metrics( &self, peer_id: &PeerId, ) -> Option<ConnectionMetrics>
Get metrics for a specific connection
Sourcepub fn nat_stats(&self) -> Result<NatTraversalStatistics, EndpointError>
pub fn nat_stats(&self) -> Result<NatTraversalStatistics, EndpointError>
Get NAT traversal statistics
Sourcepub async fn connect_known_peers(&self) -> Result<usize, EndpointError>
pub async fn connect_known_peers(&self) -> Result<usize, EndpointError>
Connect to configured known peers
Sourcepub async fn add_bootstrap(&self, addr: SocketAddr)
pub async fn add_bootstrap(&self, addr: SocketAddr)
Add a bootstrap node dynamically
Sourcepub async fn connected_peers(&self) -> Vec<PeerConnection>
pub async fn connected_peers(&self) -> Vec<PeerConnection>
Get list of connected peers
Sourcepub async fn is_connected(&self, peer_id: &PeerId) -> bool
pub async fn is_connected(&self, peer_id: &PeerId) -> bool
Check if a peer is connected
Sourcepub async fn is_authenticated(&self, peer_id: &PeerId) -> bool
pub async fn is_authenticated(&self, peer_id: &PeerId) -> bool
Check if a peer is authenticated
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if endpoint is running
Trait Implementations§
Source§impl Clone for P2pEndpoint
impl Clone for P2pEndpoint
Auto Trait Implementations§
impl Freeze for P2pEndpoint
impl !RefUnwindSafe for P2pEndpoint
impl Send for P2pEndpoint
impl Sync for P2pEndpoint
impl Unpin for P2pEndpoint
impl !UnwindSafe for P2pEndpoint
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)