BandwidthProof

Struct BandwidthProof 

Source
pub struct BandwidthProof {
Show 15 fields pub session_id: Uuid, pub content_cid: ContentCid, pub chunk_index: u64, pub bytes_transferred: Bytes, pub provider_peer_id: PeerIdString, pub requester_peer_id: PeerIdString, pub provider_public_key: Vec<u8>, pub requester_public_key: Vec<u8>, pub provider_signature: Vec<u8>, pub requester_signature: Vec<u8>, pub challenge_nonce: Vec<u8>, pub chunk_hash: Vec<u8>, pub start_timestamp_ms: i64, pub end_timestamp_ms: i64, pub latency_ms: u32,
}
Expand description

Bandwidth proof submitted to the coordinator.

Fields§

§session_id: Uuid

Unique session identifier.

§content_cid: ContentCid

Content CID.

§chunk_index: u64

Chunk index transferred.

§bytes_transferred: Bytes

Bytes transferred.

§provider_peer_id: PeerIdString

Provider’s peer ID.

§requester_peer_id: PeerIdString

Requester’s peer ID.

§provider_public_key: Vec<u8>

Provider’s public key.

§requester_public_key: Vec<u8>

Requester’s public key.

§provider_signature: Vec<u8>

Provider’s signature over the transfer data.

§requester_signature: Vec<u8>

Requester’s signature confirming receipt.

§challenge_nonce: Vec<u8>

Challenge nonce used.

§chunk_hash: Vec<u8>

Chunk hash for verification.

§start_timestamp_ms: i64

Transfer start timestamp (ms).

§end_timestamp_ms: i64

Transfer end timestamp (ms).

§latency_ms: u32

Transfer latency in milliseconds.

Implementations§

Source§

impl BandwidthProof

Source

pub fn provider_sign_message(&self) -> Vec<u8>

Get the message that was signed by the provider.

Source

pub fn requester_sign_message(&self) -> Vec<u8>

Get the message that was signed by the requester.

Source

pub fn validate(&self) -> Result<(), Vec<ValidationError>>

Validate the proof structure (not cryptographic verification).

§Errors

Returns validation errors if:

  • Public key lengths are not 32 bytes
  • Signature lengths are not 64 bytes
  • Nonce or hash lengths are not 32 bytes
  • Timestamps are invalid or out of range
§Example
use chie_shared::types::bandwidth::BandwidthProofBuilder;

// Valid proof
let valid_proof = BandwidthProofBuilder::new()
    .content_cid("bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi")
    .provider_peer_id("12D3KooWProvider")
    .requester_peer_id("12D3KooWRequester")
    .provider_public_key(vec![1u8; 32])
    .requester_public_key(vec![2u8; 32])
    .provider_signature(vec![3u8; 64])
    .requester_signature(vec![4u8; 64])
    .challenge_nonce(vec![5u8; 32])
    .chunk_hash(vec![6u8; 32])
    .timestamps(1000, 1100)
    .build()
    .unwrap();

assert!(valid_proof.validate().is_ok());

// Invalid proof (wrong signature length)
let invalid_proof = BandwidthProofBuilder::new()
    .content_cid("bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi")
    .provider_peer_id("12D3KooWProvider")
    .requester_peer_id("12D3KooWRequester")
    .provider_public_key(vec![1u8; 32])
    .requester_public_key(vec![2u8; 32])
    .provider_signature(vec![3u8; 32])  // Wrong length!
    .requester_signature(vec![4u8; 64])
    .challenge_nonce(vec![5u8; 32])
    .chunk_hash(vec![6u8; 32])
    .timestamps(1000, 1100)
    .build()
    .unwrap();

assert!(invalid_proof.validate().is_err());
Source

pub fn validate_timestamp(&self, now_ms: i64) -> Result<(), ValidationError>

Validate timestamp against current time.

§Errors

Returns ValidationError if:

  • Timestamp is in the future
  • Timestamp is too old (beyond tolerance window)
Source

pub fn is_valid(&self) -> bool

Check if this proof is valid (basic structural validation).

Source

pub fn bandwidth_bps(&self) -> f64

Calculate the effective bandwidth in bytes per second.

Source

pub fn meets_quality_threshold(&self) -> bool

Check if this transfer meets the minimum quality threshold. Latency should be under 500ms for full reward.

Source

pub fn quality_multiplier(&self) -> f64

Get a penalty multiplier based on latency (0.5x for high latency).

§Example
use chie_shared::types::bandwidth::BandwidthProofBuilder;

// Good quality transfer (low latency)
let fast_proof = BandwidthProofBuilder::new()
    .content_cid("bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi")
    .provider_peer_id("12D3KooWProvider")
    .requester_peer_id("12D3KooWRequester")
    .provider_public_key(vec![1u8; 32])
    .requester_public_key(vec![2u8; 32])
    .provider_signature(vec![3u8; 64])
    .requester_signature(vec![4u8; 64])
    .challenge_nonce(vec![5u8; 32])
    .chunk_hash(vec![6u8; 32])
    .timestamps(1000, 1200)  // 200ms latency
    .build()
    .unwrap();

assert_eq!(fast_proof.quality_multiplier(), 1.0);
assert!(fast_proof.meets_quality_threshold());

// Poor quality transfer (high latency)
let slow_proof = BandwidthProofBuilder::new()
    .content_cid("bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi")
    .provider_peer_id("12D3KooWProvider")
    .requester_peer_id("12D3KooWRequester")
    .provider_public_key(vec![1u8; 32])
    .requester_public_key(vec![2u8; 32])
    .provider_signature(vec![3u8; 64])
    .requester_signature(vec![4u8; 64])
    .challenge_nonce(vec![5u8; 32])
    .chunk_hash(vec![6u8; 32])
    .timestamps(1000, 1800)  // 800ms latency
    .build()
    .unwrap();

assert_eq!(slow_proof.quality_multiplier(), 0.5);
assert!(!slow_proof.meets_quality_threshold());

Trait Implementations§

Source§

impl Clone for BandwidthProof

Source§

fn clone(&self) -> BandwidthProof

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BandwidthProof

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for BandwidthProof

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&BandwidthProof> for CreateProofInput

Source§

fn from(proof: &BandwidthProof) -> Self

Converts to this type from the input type.
Source§

impl Serialize for BandwidthProof

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,