Skip to main content

BtPeerConn

Struct BtPeerConn 

Source
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: ConnectionType

Connection type (TCP or uTP)

Implementations§

Source§

impl BtPeerConn

Source

pub async fn connect_mse( addr: &PeerAddr, info_hash: &[u8; 20], require_encryption: bool, ) -> Result<Self>

Connect via MSE (Message Stream Encryption) over TCP

Source

pub async fn connect_plain( addr: &PeerAddr, info_hash: &[u8; 20], ) -> Result<Self>

Connect via plain TCP

Source

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
Source

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

Source

pub fn connection_type(&self) -> ConnectionType

Get the connection type

Source

pub fn is_utp(&self) -> bool

Check if this is a uTP connection

Source

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).

Source

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.

Source

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.

Source

pub async fn send_unchoke(&mut self) -> Result<()>

Source

pub async fn send_choke(&mut self) -> Result<()>

Source

pub async fn send_interested(&mut self) -> Result<()>

Source

pub async fn send_not_interested(&mut self) -> Result<()>

Source

pub async fn send_have(&mut self, piece_index: u32) -> Result<()>

Source

pub async fn send_request(&mut self, req: PieceBlockRequest) -> Result<()>

Source

pub async fn send_cancel(&mut self, req: &PieceBlockRequest) -> Result<()>

Source

pub async fn send_bitfield(&mut self, bitfield: Vec<u8>) -> Result<()>

Source

pub async fn read_message(&mut self) -> Result<Option<BtMessage>>

Source

pub fn is_connected(&self) -> bool

Source

pub fn is_encrypted(&self) -> bool

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more