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
impl BtPeerInteraction
Sourcepub async fn connect_to_peers(
peer_addrs: &[PeerAddr],
info_hash_raw: &[u8; 20],
num_pieces: u32,
require_crypto: bool,
force_encrypt: bool,
) -> Result<PeerConnectionResult>
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:
- MSE encryption if required or forced
- 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 toinfo_hash_raw- Torrent info hash for handshakenum_pieces- Total number of pieces (for bitfield size)require_crypto- Whether to require encrypted connectionsforce_encrypt- Whether to force encryption (fallback to plain)
§Returns
PeerConnectionResultcontaining connected peers and failure count
Sourcepub async fn broadcast_have(connections: &mut [BtPeerConn], piece_index: u32)
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 connectionspiece_index- Index of the completed piece
Sourcepub fn initialize_peer_tracking(
connections: &[BtPeerConn],
num_pieces: u32,
peer_tracker: &mut PeerBitfieldTracker,
)
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 connectionsnum_pieces- Total number of pieces in the torrentpeer_tracker- Mutable reference to the peer bitfield tracker
Sourcepub fn cleanup_connections(connections: &mut [BtPeerConn])
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§
impl Freeze for BtPeerInteraction
impl RefUnwindSafe for BtPeerInteraction
impl Send for BtPeerInteraction
impl Sync for BtPeerInteraction
impl Unpin for BtPeerInteraction
impl UnsafeUnpin for BtPeerInteraction
impl UnwindSafe for BtPeerInteraction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more