Skip to main content

ResourceReceiver

Struct ResourceReceiver 

Source
pub struct ResourceReceiver {
Show 23 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, pub advertisement_packet: Vec<u8>, pub max_decompressed_size: usize, /* 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

§advertisement_packet: Vec<u8>

Original advertisement bytes for this incoming transfer.

§max_decompressed_size: usize

Maximum allowed decompressed size for compressed resource payloads.

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 cancel(&mut self) -> Vec<ResourceAction>

Cancel an accepted incoming transfer.

Source

pub fn continue_from(&mut self, window: WindowState, eifr: Option<f64>)

Continue the window and rate estimate the previous segment of the same split transfer ended with, instead of starting slow again.

Source

pub fn has_parts_to_decrypt(&self) -> bool

Whether held parts wait for Self::decrypt_next_part.

Source

pub fn decrypt_next_part( &mut self, start: impl FnOnce() -> Option<TokenDecryptStream>, ) -> bool

Authenticate and decrypt the next held part ahead of assembly, so that assembly only has the parts after it left to do. Parts are taken in order from the first; start begins the decryption at the first call. Returns whether more held parts wait. Nothing decrypted here is used before assembly has checked the tag.

Source

pub fn decrypts(&self) -> bool

Whether this receiver’s parts are decrypted at assembly, and so could be fed to a decryption elsewhere ahead of it.

Source

pub fn prepare_decrypt_stream(&self, stream: &mut TokenDecryptStream)

Set up a fresh decryption as Self::decrypt_next_part would, for parts fed to it elsewhere, in order from the first.

Source

pub fn parts_in_order_from( &self, from: usize, ) -> impl Iterator<Item = &[u8]> + '_

The held parts from index from up to the first one missing: what a decryption fed elsewhere takes next, in order.

Source

pub fn resume_decrypt(&mut self, stream: Box<TokenDecryptStream>, parts: usize)

Hand back a decryption fed the first parts held parts elsewhere (Self::prepare_decrypt_stream, Self::parts_in_order_from): assembly feeds it only the rest. Ignored if this receiver already decrypted ahead itself.

Source

pub fn decrypt_held_parts( &mut self, start: impl FnOnce() -> Option<TokenDecryptStream>, budget: usize, ) -> bool

Self::decrypt_next_part for held parts until about budget bytes are done; at least one part is. Returns whether more held parts wait.

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 receive_part_into( &mut self, part_data: &[u8], now: f64, out: &mut Vec<ResourceAction>, )

Self::receive_part, appending the actions to out.

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 request_next_into(&mut self, now: f64, out: &mut Vec<ResourceAction>)

Self::request_next, appending the request to out. The request is written into one buffer sized for the window.

Source

pub fn assemble( &mut self, decrypt_fn: &PartsDecryptFn<'_>, compressor: &dyn Compressor, ) -> Vec<ResourceAction>

Assemble received parts, decrypt, decompress, verify hash.

Source

pub fn prepare_assembly( &mut self, decrypt_fn: &PartsDecryptFn<'_>, ) -> Result<ResourceAssembly, Vec<ResourceAction>>

Authenticate and decrypt the parts, then transfer owned plaintext to an assembly job. Keep this receiver alive until completion or cancellation. A pending attempt ignores duplicate parts and ordinary part-receive timeouts.

Source

pub fn assembly_id(&self) -> Option<&AssemblyId>

Source

pub fn complete_assembly( &mut self, result: AssemblyResult, ) -> Vec<ResourceAction>

Publish a result only for the still-pending attempt that produced it. Results from another receiver or a cancelled attempt are discarded.

Source

pub fn fail_assembly(&mut self, id: &AssemblyId) -> Vec<ResourceAction>

Fail a pending worker attempt without blaming the peer for a local failure.

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: &PartsDecryptFn<'_>, 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.