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: ResourceStatusCurrent 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: AdvFlagsFlags
transfer_size: u64Transfer size (encrypted)
data_size: u64Total uncompressed data size
total_parts: usizeTotal parts
waiting_for_hmu: boolWhether we’re waiting for a hashmap update
received_count: usizeNumber of parts received
outstanding_parts: usizeOutstanding parts in current window request
retries_left: usizeRetries left
rtt: Option<f64>RTT estimate
last_activity: f64Last activity timestamp
req_sent: f64Request sent timestamp
eifr: Option<f64>EIFR
segment_index: u64Segment index
total_segments: u64Total segments
has_metadata: boolHas metadata
request_id: Option<Vec<u8>>Request ID
window: WindowStateWindow state
advertisement_packet: Vec<u8>Original advertisement bytes for this incoming transfer.
max_decompressed_size: usizeMaximum allowed decompressed size for compressed resource payloads.
Implementations§
Source§impl ResourceReceiver
impl ResourceReceiver
Sourcepub fn from_advertisement(
adv_data: &[u8],
sdu: usize,
link_rtt: f64,
now: f64,
previous_window: Option<usize>,
previous_eifr: Option<f64>,
) -> Result<Self, ResourceError>
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.
Sourcepub fn accept(&mut self, now: f64) -> Vec<ResourceAction>
pub fn accept(&mut self, now: f64) -> Vec<ResourceAction>
Accept the advertised resource. Begins transfer.
Sourcepub fn reject(&mut self) -> Vec<ResourceAction>
pub fn reject(&mut self) -> Vec<ResourceAction>
Reject the advertised resource.
Sourcepub fn cancel(&mut self) -> Vec<ResourceAction>
pub fn cancel(&mut self) -> Vec<ResourceAction>
Cancel an accepted incoming transfer.
Sourcepub fn continue_from(&mut self, window: WindowState, eifr: Option<f64>)
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.
Sourcepub fn has_parts_to_decrypt(&self) -> bool
pub fn has_parts_to_decrypt(&self) -> bool
Whether held parts wait for Self::decrypt_next_part.
Sourcepub fn decrypt_next_part(
&mut self,
start: impl FnOnce() -> Option<TokenDecryptStream>,
) -> bool
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.
Sourcepub fn decrypts(&self) -> bool
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.
Sourcepub fn prepare_decrypt_stream(&self, stream: &mut TokenDecryptStream)
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.
Sourcepub fn parts_in_order_from(
&self,
from: usize,
) -> impl Iterator<Item = &[u8]> + '_
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.
Sourcepub fn resume_decrypt(&mut self, stream: Box<TokenDecryptStream>, parts: usize)
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.
Sourcepub fn decrypt_held_parts(
&mut self,
start: impl FnOnce() -> Option<TokenDecryptStream>,
budget: usize,
) -> bool
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.
Sourcepub fn receive_part(
&mut self,
part_data: &[u8],
now: f64,
) -> Vec<ResourceAction>
pub fn receive_part( &mut self, part_data: &[u8], now: f64, ) -> Vec<ResourceAction>
Receive a part. Matches by map hash and stores it.
Sourcepub fn receive_part_into(
&mut self,
part_data: &[u8],
now: f64,
out: &mut Vec<ResourceAction>,
)
pub fn receive_part_into( &mut self, part_data: &[u8], now: f64, out: &mut Vec<ResourceAction>, )
Self::receive_part, appending the actions to out.
Sourcepub fn handle_hashmap_update(
&mut self,
hmu_data: &[u8],
now: f64,
) -> Vec<ResourceAction>
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])]
Sourcepub fn request_next(&mut self, now: f64) -> Vec<ResourceAction>
pub fn request_next(&mut self, now: f64) -> Vec<ResourceAction>
Build and return request for next window of parts.
Sourcepub fn request_next_into(&mut self, now: f64, out: &mut Vec<ResourceAction>)
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.
Sourcepub fn assemble(
&mut self,
decrypt_fn: &PartsDecryptFn<'_>,
compressor: &dyn Compressor,
) -> Vec<ResourceAction>
pub fn assemble( &mut self, decrypt_fn: &PartsDecryptFn<'_>, compressor: &dyn Compressor, ) -> Vec<ResourceAction>
Assemble received parts, decrypt, decompress, verify hash.
Sourcepub fn prepare_assembly(
&mut self,
decrypt_fn: &PartsDecryptFn<'_>,
) -> Result<ResourceAssembly, Vec<ResourceAction>>
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.
pub fn assembly_id(&self) -> Option<&AssemblyId>
Sourcepub fn complete_assembly(
&mut self,
result: AssemblyResult,
) -> Vec<ResourceAction>
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.
Sourcepub fn fail_assembly(&mut self, id: &AssemblyId) -> Vec<ResourceAction>
pub fn fail_assembly(&mut self, id: &AssemblyId) -> Vec<ResourceAction>
Fail a pending worker attempt without blaming the peer for a local failure.
Sourcepub fn handle_cancel(&mut self) -> Vec<ResourceAction>
pub fn handle_cancel(&mut self) -> Vec<ResourceAction>
Handle cancel from sender (RESOURCE_ICL).
Sourcepub fn tick(
&mut self,
now: f64,
decrypt_fn: &PartsDecryptFn<'_>,
compressor: &dyn Compressor,
) -> Vec<ResourceAction>
pub fn tick( &mut self, now: f64, decrypt_fn: &PartsDecryptFn<'_>, compressor: &dyn Compressor, ) -> Vec<ResourceAction>
Periodic tick. Checks for timeouts.
Sourcepub fn get_transfer_state(&self) -> (usize, Option<f64>)
pub fn get_transfer_state(&self) -> (usize, Option<f64>)
Get window and EIFR for passing to next transfer.