pub struct BtPeerConn {
pub allowed_fast: HashSet<u32>,
pub connection_type: ConnectionType,
/* private fields */
}Expand description
Peer connection abstraction that supports both plain and encrypted (MSE) connections.
This mirrors the original aria2 C++ architecture where connection management is separated from the download command logic (see BtRuntime in original). Now also supports uTP (UDP-based) connections per BEP 29.
Fields§
§allowed_fast: HashSet<u32>Set of piece indices for which the peer has sent an AllowedFast message. Pieces in this set can be requested even when the peer is choked.
connection_type: ConnectionTypeConnection type (TCP or uTP)
Implementations§
Source§impl BtPeerConn
impl BtPeerConn
Sourcepub async fn connect_mse(
addr: &PeerAddr,
info_hash: &[u8; 20],
require_encryption: bool,
) -> Result<Self>
pub async fn connect_mse( addr: &PeerAddr, info_hash: &[u8; 20], require_encryption: bool, ) -> Result<Self>
Connect via MSE (Message Stream Encryption) over TCP
Sourcepub async fn connect_plain(
addr: &PeerAddr,
info_hash: &[u8; 20],
) -> Result<Self>
pub async fn connect_plain( addr: &PeerAddr, info_hash: &[u8; 20], ) -> Result<Self>
Connect via plain TCP
Sourcepub async fn connect_utp(addr: SocketAddr, info_hash: &[u8; 20]) -> Result<Self>
pub async fn connect_utp(addr: SocketAddr, info_hash: &[u8; 20]) -> Result<Self>
Connect via uTP (Micro Transport Protocol)
uTP is a UDP-based transport protocol that provides:
- Reliable, ordered delivery
- LEDBAT congestion control (low priority, background traffic)
- Better performance on congested networks
- NAT traversal benefits
Sourcepub fn from_utp_socket(
socket: Arc<Mutex<UtpSocket>>,
conn_id: u16,
info_hash: &[u8; 20],
) -> Self
pub fn from_utp_socket( socket: Arc<Mutex<UtpSocket>>, conn_id: u16, info_hash: &[u8; 20], ) -> Self
Create a uTP connection from an existing socket
Used when accepting incoming uTP connections
Sourcepub fn connection_type(&self) -> ConnectionType
pub fn connection_type(&self) -> ConnectionType
Get the connection type
Sourcepub fn add_allowed_fast(&mut self, index: u32)
pub fn add_allowed_fast(&mut self, index: u32)
Add a piece index to the AllowedFast set.
Called when an AllowedFast message is received from this peer. Pieces in the allowed_fast set can be requested even when the peer is choked (BEP 6 / Fast Extension).
Sourcepub fn is_allowed_fast(&self, index: u32) -> bool
pub fn is_allowed_fast(&self, index: u32) -> bool
Check whether a piece index is in the AllowedFast set.
Returns true if the peer has granted fast access to this piece, meaning a Request can be sent even while the peer is choked.
Sourcepub fn allowed_fast_set(&self) -> &HashSet<u32>
pub fn allowed_fast_set(&self) -> &HashSet<u32>
Get a reference to the full AllowedFast set
Returns all piece indices that this peer has allowed us to request via BEP 6 Fast Extension, even when choked.