keep track of privmsg ids to avoid rebroadcasting one we already received.

This commit is contained in:
narodnik
2022-01-04 16:57:10 +01:00
parent 6c7f563786
commit fe9fdc55c6
2 changed files with 10 additions and 4 deletions

View File

@@ -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 {

View File

@@ -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?;