pub struct BandwidthProofBuilder { /* private fields */ }Expand description
Builder for BandwidthProof.
Implementations§
Source§impl BandwidthProofBuilder
impl BandwidthProofBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new builder.
§Example
use chie_shared::types::bandwidth::BandwidthProofBuilder;
let proof = BandwidthProofBuilder::new()
.content_cid("bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi")
.chunk_index(0)
.bytes_transferred(262_144)
.provider_peer_id("12D3KooWProviderPeerID")
.requester_peer_id("12D3KooWRequesterPeerID")
.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()
.expect("Failed to build bandwidth proof");
assert_eq!(proof.bytes_transferred, 262_144);
assert_eq!(proof.latency_ms, 100);
assert!(proof.is_valid());
assert_eq!(proof.bandwidth_bps(), 2_621_440.0);Sourcepub fn session_id(self, id: Uuid) -> Self
pub fn session_id(self, id: Uuid) -> Self
Set the session ID (auto-generated if not set).
Sourcepub fn content_cid(self, cid: impl Into<String>) -> Self
pub fn content_cid(self, cid: impl Into<String>) -> Self
Set the content CID.
Sourcepub fn chunk_index(self, index: u64) -> Self
pub fn chunk_index(self, index: u64) -> Self
Set the chunk index.
Sourcepub fn bytes_transferred(self, bytes: Bytes) -> Self
pub fn bytes_transferred(self, bytes: Bytes) -> Self
Set bytes transferred.
Sourcepub fn provider_peer_id(self, peer_id: impl Into<String>) -> Self
pub fn provider_peer_id(self, peer_id: impl Into<String>) -> Self
Set provider peer ID.
Sourcepub fn requester_peer_id(self, peer_id: impl Into<String>) -> Self
pub fn requester_peer_id(self, peer_id: impl Into<String>) -> Self
Set requester peer ID.
Sourcepub fn provider_public_key(self, key: impl Into<Vec<u8>>) -> Self
pub fn provider_public_key(self, key: impl Into<Vec<u8>>) -> Self
Set provider public key.
Sourcepub fn requester_public_key(self, key: impl Into<Vec<u8>>) -> Self
pub fn requester_public_key(self, key: impl Into<Vec<u8>>) -> Self
Set requester public key.
Sourcepub fn provider_signature(self, sig: impl Into<Vec<u8>>) -> Self
pub fn provider_signature(self, sig: impl Into<Vec<u8>>) -> Self
Set provider signature.
Sourcepub fn requester_signature(self, sig: impl Into<Vec<u8>>) -> Self
pub fn requester_signature(self, sig: impl Into<Vec<u8>>) -> Self
Set requester signature.
Sourcepub fn challenge_nonce(self, nonce: impl Into<Vec<u8>>) -> Self
pub fn challenge_nonce(self, nonce: impl Into<Vec<u8>>) -> Self
Set challenge nonce.
Sourcepub fn chunk_hash(self, hash: impl Into<Vec<u8>>) -> Self
pub fn chunk_hash(self, hash: impl Into<Vec<u8>>) -> Self
Set chunk hash.
Sourcepub fn timestamps(self, start_ms: i64, end_ms: i64) -> Self
pub fn timestamps(self, start_ms: i64, end_ms: i64) -> Self
Set timestamps.
Sourcepub fn latency_ms(self, latency: u32) -> Self
pub fn latency_ms(self, latency: u32) -> Self
Set latency directly (overrides calculated from timestamps).
Trait Implementations§
Source§impl Debug for BandwidthProofBuilder
impl Debug for BandwidthProofBuilder
Source§impl Default for BandwidthProofBuilder
impl Default for BandwidthProofBuilder
Source§fn default() -> BandwidthProofBuilder
fn default() -> BandwidthProofBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for BandwidthProofBuilder
impl RefUnwindSafe for BandwidthProofBuilder
impl Send for BandwidthProofBuilder
impl Sync for BandwidthProofBuilder
impl Unpin for BandwidthProofBuilder
impl UnwindSafe for BandwidthProofBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more