Skip to main content

ExtHandshake

Struct ExtHandshake 

Source
pub struct ExtHandshake {
    pub m: BTreeMap<String, u8>,
    pub v: Option<String>,
    pub p: Option<u16>,
    pub reqq: Option<u32>,
    pub metadata_size: Option<u64>,
    pub upload_only: Option<u8>,
}
Expand description

Extension handshake (BEP 10, ext_id=0).

Exchanged after the standard handshake to negotiate extension IDs.

Fields§

§m: BTreeMap<String, u8>

Map of extension name → assigned message ID.

§v: Option<String>

Client name.

§p: Option<u16>

TCP listen port for incoming connections.

§reqq: Option<u32>

Number of outstanding request queue size.

§metadata_size: Option<u64>

Total size of metadata (for ut_metadata).

§upload_only: Option<u8>

BEP 21: upload-only flag (1 = seeder, 0 or absent = leecher).

Implementations§

Source§

impl ExtHandshake

Source

pub fn new() -> Self

Create a handshake advertising our supported extensions.

Source

pub fn new_with_plugins(plugin_names: &[&str]) -> Self

Create a handshake advertising built-in + plugin extensions.

Built-in extensions are assigned IDs 1–4. Plugin names are assigned IDs starting at 10, in the order provided.

Source

pub fn new_upload_only() -> Self

Create a handshake advertising upload-only (BEP 21 seeder) status.

Source

pub fn is_upload_only(&self) -> bool

Returns true if the peer declared BEP 21 upload-only status.

Source

pub fn to_bytes(&self) -> Result<Bytes>

Encode to bencode bytes.

§Errors

Returns an error if serialization fails.

Source

pub fn from_bytes(data: &[u8]) -> Result<Self>

Decode from bencode bytes.

Uses lenient parsing to accept unsorted dictionary keys, which many real-world clients send in their extension handshakes.

§Errors

Returns an error if the data is not valid bencode.

Source

pub fn ext_id(&self, name: &str) -> Option<u8>

Look up the message ID for an extension by name.

Trait Implementations§

Source§

impl Clone for ExtHandshake

Source§

fn clone(&self) -> ExtHandshake

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ExtHandshake

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ExtHandshake

Source§

fn default() -> ExtHandshake

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ExtHandshake

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ExtHandshake

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,