Skip to main content

ResourceReceiver

Struct ResourceReceiver 

Source
pub struct ResourceReceiver {
Show 21 fields pub status: ResourceStatus, pub resource_hash: Vec<u8>, pub random_hash: Vec<u8>, pub original_hash: Vec<u8>, pub flags: AdvFlags, pub transfer_size: u64, pub data_size: u64, pub total_parts: usize, pub waiting_for_hmu: bool, pub received_count: usize, pub outstanding_parts: usize, pub retries_left: usize, pub rtt: Option<f64>, pub last_activity: f64, pub req_sent: f64, pub eifr: Option<f64>, pub segment_index: u64, pub total_segments: u64, pub has_metadata: bool, pub request_id: Option<Vec<u8>>, pub window: WindowState, /* private fields */
}
Expand description

Resource receiver state machine.

Unpacks advertisements, requests parts, receives parts, assembles data. Returns Vec<ResourceAction> — no I/O, no callbacks.

Fields§

§status: ResourceStatus

Current status

§resource_hash: Vec<u8>

Resource hash (from advertisement, 32 bytes)

§random_hash: Vec<u8>

Random hash (from advertisement)

§original_hash: Vec<u8>

Original hash

§flags: AdvFlags

Flags

§transfer_size: u64

Transfer size (encrypted)

§data_size: u64

Total uncompressed data size

§total_parts: usize

Total parts

§waiting_for_hmu: bool

Whether we’re waiting for a hashmap update

§received_count: usize

Number of parts received

§outstanding_parts: usize

Outstanding parts in current window request

§retries_left: usize

Retries left

§rtt: Option<f64>

RTT estimate

§last_activity: f64

Last activity timestamp

§req_sent: f64

Request sent timestamp

§eifr: Option<f64>

EIFR

§segment_index: u64

Segment index

§total_segments: u64

Total segments

§has_metadata: bool

Has metadata

§request_id: Option<Vec<u8>>

Request ID

§window: WindowState

Window state

Implementations§

Source§

impl ResourceReceiver

Source

pub fn from_advertisement( adv_data: &[u8], sdu: usize, link_rtt: f64, now: f64, previous_window: Option<usize>, previous_eifr: Option<f64>, ) -> Result<Self, ResourceError>

Create a receiver from an advertisement packet.

Source

pub fn accept(&mut self, now: f64) -> Vec<ResourceAction>

Accept the advertised resource. Begins transfer.

Source

pub fn reject(&mut self) -> Vec<ResourceAction>

Reject the advertised resource.

Source

pub fn receive_part( &mut self, part_data: &[u8], now: f64, ) -> Vec<ResourceAction>

Receive a part. Matches by map hash and stores it.

Source

pub fn handle_hashmap_update( &mut self, hmu_data: &[u8], now: f64, ) -> Vec<ResourceAction>

Handle a hashmap update packet.

HMU format: [resource_hash: 32 bytes][msgpack([segment, hashmap])]

Source

pub fn request_next(&mut self, now: f64) -> Vec<ResourceAction>

Build and return request for next window of parts.

Source

pub fn assemble( &mut self, decrypt_fn: &dyn Fn(&[u8]) -> Result<Vec<u8>, ()>, compressor: &dyn Compressor, ) -> Vec<ResourceAction>

Assemble received parts, decrypt, decompress, verify hash.

Source

pub fn handle_cancel(&mut self) -> Vec<ResourceAction>

Handle cancel from sender (RESOURCE_ICL).

Source

pub fn tick( &mut self, now: f64, decrypt_fn: &dyn Fn(&[u8]) -> Result<Vec<u8>, ()>, compressor: &dyn Compressor, ) -> Vec<ResourceAction>

Periodic tick. Checks for timeouts.

Source

pub fn progress(&self) -> (usize, usize)

Get current progress as (received, total).

Source

pub fn get_transfer_state(&self) -> (usize, Option<f64>)

Get window and EIFR for passing to next transfer.

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