Struct iroh_bitswap::message::Entry
source · pub struct Entry {
pub cid: Cid,
pub priority: Priority,
pub want_type: WantType,
pub cancel: bool,
pub send_dont_have: bool,
}Fields§
§cid: Cid§priority: Priority§want_type: WantType§cancel: bool§send_dont_have: boolImplementations§
source§impl Entry
impl Entry
sourcepub fn encoded_len(&self) -> usize
pub fn encoded_len(&self) -> usize
Returns the encoded length of this entry.
Examples found in repository?
src/message.rs (line 344)
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
fn add_full_entry(
&mut self,
cid: Cid,
priority: Priority,
cancel: bool,
want_type: WantType,
send_dont_have: bool,
) -> usize {
if let Some(entry) = self.wantlist.get_mut(&cid) {
// only change priority if want is of the same type
if entry.want_type == want_type {
entry.priority = priority;
}
// only change from dont cancel to cancel
if cancel {
entry.cancel = cancel;
}
// only change from dont send to do send DONT_HAVE
if send_dont_have {
entry.send_dont_have = send_dont_have;
}
// want block overrides existing want have
if want_type == WantType::Block && entry.want_type == WantType::Have {
entry.want_type = want_type;
}
return 0;
}
let entry = Entry {
cid,
priority,
want_type,
send_dont_have,
cancel,
};
let size = entry.encoded_len();
self.wantlist.insert(cid, entry);
size
}
pub fn add_block(&mut self, block: Block) {
self.block_presences.remove(block.cid());
self.blocks.insert(*block.cid(), block);
}
pub fn add_block_presence(&mut self, cid: Cid, typ: BlockPresenceType) {
if self.blocks.contains_key(&cid) {
return;
}
self.block_presences.insert(cid, typ);
}
pub fn add_have(&mut self, cid: Cid) {
self.add_block_presence(cid, BlockPresenceType::Have);
}
pub fn add_dont_have(&mut self, cid: Cid) {
self.add_block_presence(cid, BlockPresenceType::DontHave);
}
pub fn encoded_len(&self) -> usize {
let block_size: usize = self.blocks.values().map(|b| b.data.len()).sum();
let block_presence_size: usize = self.block_presences().map(|bp| bp.encoded_len()).sum();
let wantlist_size: usize = self.wantlist.values().map(|e| e.encoded_len()).sum();
block_size + block_presence_size + wantlist_size
}Trait Implementations§
source§impl PartialEq<Entry> for Entry
impl PartialEq<Entry> for Entry
impl Eq for Entry
impl StructuralEq for Entry
impl StructuralPartialEq for Entry
Auto Trait Implementations§
impl RefUnwindSafe for Entry
impl Send for Entry
impl Sync for Entry
impl Unpin for Entry
impl UnwindSafe for Entry
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request