From 46926e71d1720b4f37d77ba6fad324a900e15092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sun, 22 Oct 2017 22:33:54 +0200 Subject: [PATCH] Remove old message duplicate code - Calculating so many hashes for each Message is quite expensive - It hides our own implementation bugs, like when we retrieve history from a MUC with wrong timestamps, or on rejoin. We never know about it because the Messages are dropped. - It should not be necessary anymore. The original problem was a bug in nbxmpp which triggered mass resending of old messages. --- gajim/common/connection_handlers.py | 4 ---- gajim/common/connection_handlers_events.py | 16 ---------------- 2 files changed, 20 deletions(-) diff --git a/gajim/common/connection_handlers.py b/gajim/common/connection_handlers.py index 175905511..7322aa7ec 100644 --- a/gajim/common/connection_handlers.py +++ b/gajim/common/connection_handlers.py @@ -725,8 +725,6 @@ class ConnectionHandlersBase: # IDs of sent messages (https://trac.gajim.org/ticket/8222) self.sent_message_ids = [] - self.received_message_hashes = [] - # We decrypt GPG messages one after the other. Keep queue in mem self.gpg_messages_to_decrypt = [] @@ -2048,8 +2046,6 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream): app.nec.push_incoming_event(SignedInEvent(None, conn=self)) self.send_awaiting_pep() self.continue_connect_info = None - # hashes of already received messages - self.received_message_hashes = [] def _SearchCB(self, con, iq_obj): log.debug('SearchCB') diff --git a/gajim/common/connection_handlers_events.py b/gajim/common/connection_handlers_events.py index bed46c6cf..761a236dd 100644 --- a/gajim/common/connection_handlers_events.py +++ b/gajim/common/connection_handlers_events.py @@ -1472,22 +1472,6 @@ class DecryptedMessageReceivedEvent(nec.NetworkIncomingEvent, HelperEvent): if replace: self.correct_id = replace.getAttr('id') - # ignore message duplicates - if self.msgtxt and self.id_ and self.jid: - self.msghash = hashlib.sha256(("%s|%s|%s" % ( - hashlib.sha256(self.msgtxt.encode('utf-8')).hexdigest(), - hashlib.sha256(self.id_.encode('utf-8')).hexdigest(), - hashlib.sha256(self.jid.encode('utf-8')).hexdigest())).encode( - 'utf-8')).digest() - if self.msghash in self.conn.received_message_hashes: - log.info("Ignoring duplicated message from '%s' with id '%s'" % (self.jid, self.id_)) - return False - else: - log.debug("subhashes: msgtxt, id_, jid = ('%s', '%s', '%s')" % (hashlib.sha256(self.msgtxt.encode('utf-8')).hexdigest(), hashlib.sha256(self.id_.encode('utf-8')).hexdigest(), hashlib.sha256(self.jid.encode('utf-8')).hexdigest())) - self.conn.received_message_hashes.append(self.msghash) - # only record the last 20000 hashes (should be about 1MB [32 bytes per hash] - # and about 24 hours if you receive a message every 5 seconds) - self.conn.received_message_hashes = self.conn.received_message_hashes[-20000:] return True class ChatstateReceivedEvent(nec.NetworkIncomingEvent):