Skip to main content

BtPeerInteraction

Struct BtPeerInteraction 

Source
pub struct BtPeerInteraction;
Expand description

BT Peer Interaction Manager

Handles the lifecycle of peer connections from initial connection through the handshake phase until they’re ready for data transfer.

Implementations§

Source§

impl BtPeerInteraction

Source

pub async fn connect_to_peers( peer_addrs: &[PeerAddr], info_hash_raw: &[u8; 20], num_pieces: u32, require_crypto: bool, force_encrypt: bool, ) -> Result<PeerConnectionResult>

Connect to multiple peers with automatic fallback strategies

Attempts to connect to all provided peer addresses using:

  1. MSE encryption if required or forced
  2. Plain connection as fallback

For each successful connection:

  • Sends initial unchoke and interested messages
  • Exchanges bitfields
  • Waits for unchoke from the peer
§Arguments
  • peer_addrs - List of peer addresses to connect to
  • info_hash_raw - Torrent info hash for handshake
  • num_pieces - Total number of pieces (for bitfield size)
  • require_crypto - Whether to require encrypted connections
  • force_encrypt - Whether to force encryption (fallback to plain)
§Returns
  • PeerConnectionResult containing connected peers and failure count
Source

pub async fn broadcast_have(connections: &mut [BtPeerConn], piece_index: u32)

Broadcast a HAVE message to all connected peers

Notifies all peers that we have completed downloading a piece.

§Arguments
  • connections - Mutable slice of active peer connections
  • piece_index - Index of the completed piece
Source

pub fn initialize_peer_tracking( connections: &[BtPeerConn], num_pieces: u32, peer_tracker: &mut PeerBitfieldTracker, )

Initialize peer bitfield tracker for all connections

Sets up tracking of which pieces each peer claims to have.

§Arguments
  • connections - Slice of active peer connections
  • num_pieces - Total number of pieces in the torrent
  • peer_tracker - Mutable reference to the peer bitfield tracker
Source

pub fn cleanup_connections(connections: &mut [BtPeerConn])

Clean up peer connections (drop them properly)

Ensures all connections are properly closed.

§Arguments
  • connections - Mutable slice of peer connections to close

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