ignore duplicate messages

This commit is contained in:
Jonathan Warren 2014-07-26 13:15:28 -04:00
parent a303c8d878
commit b41fb616ae
2 changed files with 90 additions and 72 deletions

View File

@ -595,7 +595,7 @@ class objectProcessor(threading.Thread):
if queryreturn == []: if queryreturn == []:
logger.info('Message ignored because address not in whitelist.') logger.info('Message ignored because address not in whitelist.')
blockMessage = True blockMessage = True
if not blockMessage:
toLabel = shared.config.get(toAddress, 'label') toLabel = shared.config.get(toAddress, 'label')
if toLabel == '': if toLabel == '':
toLabel = toAddress toLabel = toAddress
@ -608,9 +608,16 @@ class objectProcessor(threading.Thread):
subject = '' subject = ''
elif messageEncodingType == 0: elif messageEncodingType == 0:
logger.info('messageEncodingType == 0. Doing nothing with the message. They probably just sent it so that we would store their public key or send their ack data for them.') logger.info('messageEncodingType == 0. Doing nothing with the message. They probably just sent it so that we would store their public key or send their ack data for them.')
subject = ''
body = ''
else: else:
body = 'Unknown encoding type.\n\n' + repr(message) body = 'Unknown encoding type.\n\n' + repr(message)
subject = '' subject = ''
# Let us make sure that we haven't already received this message
if helper_inbox.isMessageAlreadyInInbox(toAddress, fromAddress, subject, body, messageEncodingType):
logger.info('This msg is already in our inbox. Ignoring it.')
blockMessage = True
if not blockMessage:
if messageEncodingType != 0: if messageEncodingType != 0:
t = (inventoryHash, toAddress, fromAddress, subject, int( t = (inventoryHash, toAddress, fromAddress, subject, int(
time.time()), body, 'inbox', messageEncodingType, 0) time.time()), body, 'inbox', messageEncodingType, 0)
@ -808,7 +815,10 @@ class objectProcessor(threading.Thread):
toAddress = '[Broadcast subscribers]' toAddress = '[Broadcast subscribers]'
if messageEncodingType != 0: if messageEncodingType != 0:
# Let us make sure that we haven't already received this message
if helper_inbox.isMessageAlreadyInInbox(toAddress, fromAddress, subject, body, messageEncodingType):
logger.info('This broadcast is already in our inbox. Ignoring it.')
else:
t = (inventoryHash, toAddress, fromAddress, subject, int( t = (inventoryHash, toAddress, fromAddress, subject, int(
time.time()), body, 'inbox', messageEncodingType, 0) time.time()), body, 'inbox', messageEncodingType, 0)
helper_inbox.insert(t) helper_inbox.insert(t)
@ -953,7 +963,9 @@ class objectProcessor(threading.Thread):
toAddress = '[Broadcast subscribers]' toAddress = '[Broadcast subscribers]'
if messageEncodingType != 0: if messageEncodingType != 0:
if helper_inbox.isMessageAlreadyInInbox(toAddress, fromAddress, subject, body, messageEncodingType):
logger.info('This broadcast is already in our inbox. Ignoring it.')
else:
t = (inventoryHash, toAddress, fromAddress, subject, int( t = (inventoryHash, toAddress, fromAddress, subject, int(
time.time()), body, 'inbox', messageEncodingType, 0) time.time()), body, 'inbox', messageEncodingType, 0)
helper_inbox.insert(t) helper_inbox.insert(t)
@ -1096,7 +1108,9 @@ class objectProcessor(threading.Thread):
toAddress = '[Broadcast subscribers]' toAddress = '[Broadcast subscribers]'
if messageEncodingType != 0: if messageEncodingType != 0:
if helper_inbox.isMessageAlreadyInInbox(toAddress, fromAddress, subject, body, messageEncodingType):
logger.info('This broadcast is already in our inbox. Ignoring it.')
else:
t = (inventoryHash, toAddress, fromAddress, subject, int( t = (inventoryHash, toAddress, fromAddress, subject, int(
time.time()), body, 'inbox', messageEncodingType, 0) time.time()), body, 'inbox', messageEncodingType, 0)
helper_inbox.insert(t) helper_inbox.insert(t)

View File

@ -9,3 +9,7 @@ def trash(msgid):
sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', msgid) sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', msgid)
shared.UISignalQueue.put(('removeInboxRowByMsgid',msgid)) shared.UISignalQueue.put(('removeInboxRowByMsgid',msgid))
def isMessageAlreadyInInbox(toAddress, fromAddress, subject, body, encodingType):
queryReturn = sqlQuery(
'''SELECT COUNT(*) FROM inbox WHERE toaddress=? AND fromaddress=? AND subject=? AND message=? AND encodingtype=? ''', toAddress, fromAddress, subject, body, encodingType)
return queryReturn[0][0] != 0