Просмотр исходного кода

bin/ircd: major bug fix for syncing messages

ghassmo 3 лет назад
Родитель
Сommit
230fd7edfc
3 измененных файлов с 17 добавлено и 7 удалено
  1. 1 1
      bin/ircd/src/buffers.rs
  2. 15 5
      bin/ircd/src/protocol_privmsg.rs
  3. 1 1
      bin/ircd/src/settings.rs

+ 1 - 1
bin/ircd/src/buffers.rs

@@ -309,7 +309,7 @@ impl UMsgs {
 
     pub async fn insert(&self, msg: &Privmsg) -> String {
         let mut hasher = Ripemd160::new();
-        hasher.update(msg.to_string() + &msg.term.to_string());
+        hasher.update(msg.to_string() + &msg.term.to_string() + &msg.timestamp.to_string());
         let key = hex::encode(hasher.finalize());
 
         let msgs = &mut self.msgs.lock().await;

+ 15 - 5
bin/ircd/src/protocol_privmsg.rs

@@ -36,11 +36,12 @@ impl Inv {
 #[derive(SerialDecodable, SerialEncodable, Clone, Debug)]
 struct GetData {
     invs: Vec<InvObject>,
+    term: Option<u64>,
 }
 
 impl GetData {
-    fn new(invs: Vec<InvObject>) -> Self {
-        Self { invs }
+    fn new(invs: Vec<InvObject>, term: Option<u64>) -> Self {
+        Self { invs, term }
     }
 }
 
@@ -118,7 +119,7 @@ impl ProtocolPrivmsg {
             }
 
             if !inv_requested.is_empty() {
-                self.channel.send(GetData::new(inv_requested)).await?;
+                self.channel.send(GetData::new(inv_requested, None)).await?;
             }
 
             self.update_unread_msgs().await?;
@@ -160,12 +161,15 @@ impl ProtocolPrivmsg {
             self.update_unread_msgs().await?;
 
             match self.buffers.privmsgs.last_term().await.cmp(&last_term) {
-                Ordering::Less => {
+                Ordering::Greater => {
                     for msg in self.buffers.privmsgs.fetch_msgs(last_term).await {
                         self.channel.send(msg).await?;
                     }
                 }
-                Ordering::Greater | Ordering::Equal => continue,
+                Ordering::Less => {
+                    self.channel.send(GetData::new(vec![], Some(last_term))).await?;
+                }
+                Ordering::Equal => continue,
             }
         }
     }
@@ -181,6 +185,12 @@ impl ProtocolPrivmsg {
                     self.channel.send(msg.clone()).await?;
                 }
             }
+
+            if let Some(term) = getdata.term {
+                for msg in self.buffers.privmsgs.fetch_msgs(term).await {
+                    self.channel.send(msg).await?;
+                }
+            }
         }
     }
 

+ 1 - 1
bin/ircd/src/settings.rs

@@ -15,7 +15,7 @@ pub const CONFIG_FILE_CONTENTS: &str = include_str!("../ircd_config.toml");
 
 // Buffers and ordering configuration
 pub const SIZE_OF_MSGS_BUFFER: usize = 4095;
-pub const SIZE_OF_IDSS_BUFFER: usize = 16384;
+pub const SIZE_OF_IDSS_BUFFER: usize = 65536;
 pub const LIFETIME_FOR_ORPHAN: i64 = 600;
 pub const TERM_MAX_TIME_DIFFERENCE: i64 = 180;
 pub const BROADCAST_LAST_TERM_MSG: u64 = 4;