Skip to main content

ResourceSender

Struct ResourceSender 

Source
pub struct ResourceSender {
Show 25 fields pub status: ResourceStatus, pub resource_hash: [u8; 32], pub truncated_hash: [u8; 16], pub expected_proof: [u8; 32], pub original_hash: [u8; 32], pub random_hash: Vec<u8>, pub sdu: usize, pub part_hashes: Vec<[u8; 4]>, pub sent_parts: usize, pub flags: AdvFlags, pub transfer_size: usize, pub data_size: usize, pub segment_index: u64, pub total_segments: u64, pub request_id: Option<Vec<u8>>, pub retries_left: usize, pub max_retries: usize, pub max_adv_retries: usize, pub rtt: Option<f64>, pub link_rtt: f64, pub timeout_factor: f64, pub last_activity: f64, pub adv_sent: f64, pub last_part_sent: f64, pub sender_grace_time: f64, /* private fields */
}
Expand description

Resource sender state machine.

Creates an advertisement, handles part requests, sends parts, and validates proofs. Returns Vec<ResourceAction> — no I/O, no callbacks.

Fields§

§status: ResourceStatus

Current status

§resource_hash: [u8; 32]

Resource hash (SHA-256 of unencrypted data + random_hash), 32 bytes

§truncated_hash: [u8; 16]

Truncated hash (first 16 bytes of resource_hash)

§expected_proof: [u8; 32]

Expected proof (SHA-256 of unencrypted data + resource_hash)

§original_hash: [u8; 32]

Original hash (for multi-segment, first segment’s hash)

§random_hash: Vec<u8>

Random hash for map hashing (4 bytes)

§sdu: usize

SDU size

§part_hashes: Vec<[u8; 4]>

Part map hashes (4 bytes each)

§sent_parts: usize

Number of unique parts sent

§flags: AdvFlags

Flags

§transfer_size: usize

Transfer size (encrypted data size)

§data_size: usize

Total uncompressed data size

§segment_index: u64

Segment index (1-based)

§total_segments: u64

Total segments

§request_id: Option<Vec<u8>>

Request ID

§retries_left: usize

Retries left

§max_retries: usize

Max retries

§max_adv_retries: usize

Max advertisement retries

§rtt: Option<f64>

RTT estimate (seconds)

§link_rtt: f64

Link RTT estimate (from link establishment)

§timeout_factor: f64

Timeout factor

§last_activity: f64

Last activity timestamp

§adv_sent: f64

Advertisement sent timestamp

§last_part_sent: f64

Last part sent timestamp

§sender_grace_time: f64

Sender grace time

Implementations§

Source§

impl ResourceSender

Source

pub fn new( data: &[u8], metadata: Option<&[u8]>, sdu: usize, encrypt_fn: &dyn Fn(&[u8]) -> Vec<u8>, compressor: &dyn Compressor, rng: &mut dyn Rng, now: f64, auto_compress: bool, is_response: bool, request_id: Option<Vec<u8>>, segment_index: u64, total_segments: u64, original_hash: Option<[u8; 32]>, link_rtt: f64, traffic_timeout_factor: f64, ) -> Result<Self, ResourceError>

Create a new ResourceSender from unencrypted data.

  • data: raw application data (no metadata prefix)
  • metadata: optional pre-serialized metadata bytes
  • sdu: SDU size (usually RESOURCE_SDU = 464)
  • encrypt_fn: closure to encrypt the full data blob
  • compressor: Compressor trait for optional compression
  • rng: random number generator
  • now: current timestamp
  • auto_compress: whether to attempt compression
  • is_response: whether this is a response to a request
  • request_id: optional request ID
  • segment_index: 1-based segment number (1 for single-segment)
  • total_segments: total number of segments
  • original_hash: original hash from first segment (None for first segment)
  • link_rtt: current link RTT estimate
  • traffic_timeout_factor: link traffic timeout factor
Source

pub fn get_advertisement(&self, segment: usize) -> Vec<u8>

Generate the advertisement for the given hashmap segment.

Source

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

Advertise the resource. Returns SendAdvertisement action.

Source

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

Handle a request for parts (RESOURCE_REQ context).

request_data format: [exhausted_flag: u8][last_map_hash: 4 bytes if exhausted][resource_hash: 32 bytes][requested_hashes: N*4 bytes]

Source

pub fn handle_proof( &mut self, proof_data: &[u8], _now: f64, ) -> Vec<ResourceAction>

Handle proof from receiver.

Source

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

Handle rejection from receiver.

Source

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

Cancel the transfer.

Source

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

Periodic tick. Checks for timeouts.

Source

pub fn total_parts(&self) -> usize

Get the total number of parts.

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.