mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-10 07:08:05 -05:00
keep track of privmsg ids to avoid rebroadcasting one we already received.
This commit is contained in:
@@ -153,7 +153,7 @@ async fn start(executor: Arc<Executor<'_>>, options: ProgramOptions) -> Result<(
|
||||
|
||||
let rpc_interface = Arc::new(JsonRpcInterface {});
|
||||
executor.spawn(async move {
|
||||
listen_and_serve(server_config, rpc_interface, executor).await
|
||||
//listen_and_serve(server_config, rpc_interface, executor).await
|
||||
}).detach();
|
||||
|
||||
loop {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use async_std::sync::Mutex;
|
||||
use std::{
|
||||
sync::Arc,
|
||||
collections::HashSet,
|
||||
@@ -14,7 +15,7 @@ pub struct ProtocolPrivMsg {
|
||||
notify_queue_sender: async_channel::Sender<Arc<PrivMsg>>,
|
||||
privmsg_sub: net::MessageSubscription<PrivMsg>,
|
||||
jobsman: net::ProtocolJobsManagerPtr,
|
||||
privmsg_ids: HashSet<PrivMsgId>,
|
||||
privmsg_ids: Mutex<HashSet<PrivMsgId>>,
|
||||
p2p: net::P2pPtr,
|
||||
}
|
||||
|
||||
@@ -36,7 +37,7 @@ impl ProtocolPrivMsg {
|
||||
notify_queue_sender,
|
||||
privmsg_sub,
|
||||
jobsman: net::ProtocolJobsManager::new("PrivMsgProtocol", channel),
|
||||
privmsg_ids: HashSet::new(),
|
||||
privmsg_ids: Mutex::new(HashSet::new()),
|
||||
p2p,
|
||||
})
|
||||
}
|
||||
@@ -60,10 +61,15 @@ impl ProtocolPrivMsg {
|
||||
);
|
||||
|
||||
// Do we already have this message?
|
||||
if self.privmsg_ids.contains(&privmsg.id) {
|
||||
if self.privmsg_ids.lock().await.contains(&privmsg.id) {
|
||||
continue
|
||||
}
|
||||
|
||||
// If not then broadcast to everybody else
|
||||
|
||||
// First update list of privmsg ids
|
||||
self.privmsg_ids.lock().await.insert(privmsg.id);
|
||||
|
||||
let privmsg_copy = (*privmsg).clone();
|
||||
self.p2p.broadcast(privmsg_copy).await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user