mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-29 17:51:35 +00:00
protocols/gossipsub: Do not overwrite msg's peers if put again into mcache (#2493)
Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
@ -8,14 +8,17 @@
|
|||||||
|
|
||||||
- Emit gossip of all non empty topics (see [PR 2481]).
|
- Emit gossip of all non empty topics (see [PR 2481]).
|
||||||
|
|
||||||
- Merge NetworkBehaviour's inject_\* paired methods (see PR 2445).
|
- Merge NetworkBehaviour's inject_\* paired methods (see [PR 2445]).
|
||||||
|
|
||||||
- Revert to wasm-timer (see [PR 2506]).
|
- Revert to wasm-timer (see [PR 2506]).
|
||||||
|
|
||||||
|
- Do not overwrite msg's peers if put again into mcache (see [PR 2493]).
|
||||||
|
|
||||||
[PR 2442]: https://github.com/libp2p/rust-libp2p/pull/2442
|
[PR 2442]: https://github.com/libp2p/rust-libp2p/pull/2442
|
||||||
[PR 2481]: https://github.com/libp2p/rust-libp2p/pull/2481
|
[PR 2481]: https://github.com/libp2p/rust-libp2p/pull/2481
|
||||||
[PR 2445]: https://github.com/libp2p/rust-libp2p/pull/2445
|
[PR 2445]: https://github.com/libp2p/rust-libp2p/pull/2445
|
||||||
[PR 2506]: https://github.com/libp2p/rust-libp2p/pull/2506
|
[PR 2506]: https://github.com/libp2p/rust-libp2p/pull/2506
|
||||||
|
[PR 2493]: https://github.com/libp2p/rust-libp2p/pull/2493
|
||||||
|
|
||||||
# 0.35.0 [2022-01-27]
|
# 0.35.0 [2022-01-27]
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ use crate::topic::TopicHash;
|
|||||||
use crate::types::{MessageId, RawGossipsubMessage};
|
use crate::types::{MessageId, RawGossipsubMessage};
|
||||||
use libp2p_core::PeerId;
|
use libp2p_core::PeerId;
|
||||||
use log::{debug, trace};
|
use log::{debug, trace};
|
||||||
|
use std::collections::hash_map::Entry;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
@ -73,22 +74,22 @@ impl MessageCache {
|
|||||||
///
|
///
|
||||||
/// Returns true if the message didn't already exist in the cache.
|
/// Returns true if the message didn't already exist in the cache.
|
||||||
pub fn put(&mut self, message_id: &MessageId, msg: RawGossipsubMessage) -> bool {
|
pub fn put(&mut self, message_id: &MessageId, msg: RawGossipsubMessage) -> bool {
|
||||||
trace!("Put message {:?} in mcache", message_id);
|
match self.msgs.entry(message_id.clone()) {
|
||||||
let cache_entry = CacheEntry {
|
Entry::Occupied(_) => {
|
||||||
mid: message_id.clone(),
|
// Don't add duplicate entries to the cache.
|
||||||
topic: msg.topic.clone(),
|
false
|
||||||
};
|
}
|
||||||
|
Entry::Vacant(entry) => {
|
||||||
|
let cache_entry = CacheEntry {
|
||||||
|
mid: message_id.clone(),
|
||||||
|
topic: msg.topic.clone(),
|
||||||
|
};
|
||||||
|
entry.insert((msg, HashSet::default()));
|
||||||
|
self.history[0].push(cache_entry);
|
||||||
|
|
||||||
if self
|
trace!("Put message {:?} in mcache", message_id);
|
||||||
.msgs
|
true
|
||||||
.insert(message_id.clone(), (msg, HashSet::new()))
|
}
|
||||||
.is_none()
|
|
||||||
{
|
|
||||||
// Don't add duplicate entries to the cache.
|
|
||||||
self.history[0].push(cache_entry);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user