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: ResourceStatusCurrent 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: usizeSDU size
part_hashes: Vec<[u8; 4]>Part map hashes (4 bytes each)
sent_parts: usizeNumber of unique parts sent
flags: AdvFlagsFlags
transfer_size: usizeTransfer size (encrypted data size)
data_size: usizeTotal uncompressed data size
segment_index: u64Segment index (1-based)
total_segments: u64Total segments
request_id: Option<Vec<u8>>Request ID
retries_left: usizeRetries left
max_retries: usizeMax retries
max_adv_retries: usizeMax advertisement retries
rtt: Option<f64>RTT estimate (seconds)
link_rtt: f64Link RTT estimate (from link establishment)
timeout_factor: f64Timeout factor
last_activity: f64Last activity timestamp
adv_sent: f64Advertisement sent timestamp
last_part_sent: f64Last part sent timestamp
sender_grace_time: f64Sender grace time
Implementations§
Source§impl ResourceSender
impl ResourceSender
Sourcepub 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>
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 bytessdu: SDU size (usually RESOURCE_SDU = 464)encrypt_fn: closure to encrypt the full data blobcompressor: Compressor trait for optional compressionrng: random number generatornow: current timestampauto_compress: whether to attempt compressionis_response: whether this is a response to a requestrequest_id: optional request IDsegment_index: 1-based segment number (1 for single-segment)total_segments: total number of segmentsoriginal_hash: original hash from first segment (None for first segment)link_rtt: current link RTT estimatetraffic_timeout_factor: link traffic timeout factor
Sourcepub fn get_advertisement(&self, segment: usize) -> Vec<u8> ⓘ
pub fn get_advertisement(&self, segment: usize) -> Vec<u8> ⓘ
Generate the advertisement for the given hashmap segment.
Sourcepub fn advertise(&mut self, now: f64) -> Vec<ResourceAction>
pub fn advertise(&mut self, now: f64) -> Vec<ResourceAction>
Advertise the resource. Returns SendAdvertisement action.
Sourcepub fn handle_request(
&mut self,
request_data: &[u8],
now: f64,
) -> Vec<ResourceAction>
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]
Sourcepub fn handle_proof(
&mut self,
proof_data: &[u8],
_now: f64,
) -> Vec<ResourceAction>
pub fn handle_proof( &mut self, proof_data: &[u8], _now: f64, ) -> Vec<ResourceAction>
Handle proof from receiver.
Sourcepub fn handle_reject(&mut self) -> Vec<ResourceAction>
pub fn handle_reject(&mut self) -> Vec<ResourceAction>
Handle rejection from receiver.
Sourcepub fn cancel(&mut self) -> Vec<ResourceAction>
pub fn cancel(&mut self) -> Vec<ResourceAction>
Cancel the transfer.
Sourcepub fn tick(&mut self, now: f64) -> Vec<ResourceAction>
pub fn tick(&mut self, now: f64) -> Vec<ResourceAction>
Periodic tick. Checks for timeouts.
Sourcepub fn total_parts(&self) -> usize
pub fn total_parts(&self) -> usize
Get the total number of parts.