ant_quic/api/
mod.rs

1// Copyright 2024 Saorsa Labs Ltd.
2//
3// This Saorsa Network Software is licensed under the General Public License (GPL), version 3.
4// Please see the file LICENSE-GPL, or visit <http://www.gnu.org/licenses/> for the full text.
5//
6// Full details available at https://saorsalabs.com/licenses
7#![allow(missing_docs)]
8
9//! High-Level NAT Traversal API
10//!
11//! This module provides a clean, intuitive API for developers to use the
12//! ant-quic library for NAT traversal and P2P networking.
13
14use std::collections::HashMap;
15use std::time::Duration;
16use thiserror::Error;
17
18use crate::nat_traversal::{NatTraversalEndpoint, NatTraversalError, PeerId};
19
20// Re-export configuration module
21pub mod config;
22pub use config::ConfigError;
23pub use config::P2PConfig;
24pub use config::P2PConfigBuilder;
25
26/// High-level P2P node implementation
27pub struct P2PNode {
28    // Internal NAT traversal endpoint
29    #[allow(dead_code)]
30    endpoint: NatTraversalEndpoint,
31    // Node configuration
32    #[allow(dead_code)]
33    config: P2PConfig,
34    // Active connections
35    #[allow(dead_code)]
36    connections: HashMap<PeerId, P2PConnection>,
37    // Event queue
38    #[allow(dead_code)]
39    events: Vec<P2PEvent>,
40}
41
42/// High-level P2P connection
43pub struct P2PConnection {
44    // Peer ID
45    #[allow(dead_code)]
46    peer_id: PeerId,
47    // Connection state
48    #[allow(dead_code)]
49    state: ConnectionState,
50    // Statistics
51    #[allow(dead_code)]
52    stats: ConnectionStats,
53}
54
55/// Connection state
56enum ConnectionState {
57    #[allow(dead_code)]
58    Connecting,
59    #[allow(dead_code)]
60    Connected,
61    #[allow(dead_code)]
62    Disconnecting,
63    #[allow(dead_code)]
64    Disconnected,
65}
66
67/// Connection statistics
68pub struct ConnectionStats {
69    // Round-trip time
70    #[allow(dead_code)]
71    rtt: Duration,
72    // Bytes sent
73    #[allow(dead_code)]
74    bytes_sent: u64,
75    // Bytes received
76    #[allow(dead_code)]
77    bytes_received: u64,
78    // Packets sent
79    #[allow(dead_code)]
80    packets_sent: u64,
81    // Packets received
82    #[allow(dead_code)]
83    packets_received: u64,
84}
85
86/// High-level P2P events
87pub enum P2PEvent {
88    /// Connected to a peer
89    Connected { peer_id: PeerId },
90    /// Disconnected from a peer
91    Disconnected {
92        peer_id: PeerId,
93        reason: Option<String>,
94    },
95    /// Received data from a peer
96    Data { peer_id: PeerId, data: Vec<u8> },
97    /// Error occurred
98    Error {
99        /// The peer ID if known
100        peer_id: Option<PeerId>,
101        /// The error that occurred
102        error: P2PError,
103    },
104}
105
106/// Errors that can occur in the P2P API
107#[derive(Debug, Error)]
108pub enum P2PError {
109    /// Connection-related error
110    #[error("Connection error: {0}")]
111    Connection(String),
112
113    #[error("Authentication error: {0}")]
114    Authentication(String),
115
116    #[error("NAT traversal error: {0}")]
117    NatTraversal(#[from] NatTraversalError),
118
119    #[error("Configuration error: {0}")]
120    Configuration(String),
121
122    #[error("Timeout: {0}")]
123    Timeout(String),
124}
125
126// Implementation of the P2P API
127// (Placeholder - actual implementation would go here)