Special class BMStringParser for sending ACK (resolves #1374)

This commit is contained in:
Dmitri Bogomolov 2018-10-13 00:12:00 +03:00
parent 7c7d6781a2
commit 49985a435f
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
2 changed files with 39 additions and 6 deletions

View File

@ -19,6 +19,7 @@ import helper_msgcoding
import helper_sent
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery
from helper_ackPayload import genAckPayload
from network import bmproto
import protocol
import queues
import state
@ -50,6 +51,7 @@ class objectProcessor(threading.Thread):
logger.debug(
'Loaded %s objects from disk into the objectProcessorQueue.',
len(queryreturn))
self._ack_obj = bmproto.BMStringParser()
def run(self):
while True:
@ -743,12 +745,13 @@ class objectProcessor(threading.Thread):
# Don't send ACK if invalid, blacklisted senders, invisible
# messages, disabled or chan
# if (self.ackDataHasAValidHeader(ackData) and not blockMessage
# and messageEncodingType != 0 and
# not BMConfigParser().safeGetBoolean(toAddress, 'dontsendack')
# and not BMConfigParser().safeGetBoolean(toAddress, 'chan')
# ):
# shared.checkAndShareObjectWithPeers(ackData[24:])
if (
self.ackDataHasAValidHeader(ackData) and not blockMessage and
messageEncodingType != 0 and
not BMConfigParser().safeGetBoolean(toAddress, 'dontsendack') and
not BMConfigParser().safeGetBoolean(toAddress, 'chan')
):
self._ack_obj.send_data(ackData[24:])
# Display timing data
timeRequiredToAttemptToDecryptMessage = time.time(

View File

@ -4,6 +4,7 @@ import random
import socket
import struct
import time
from binascii import hexlify
from bmconfigparser import BMConfigParser
from debug import logger
@ -575,3 +576,32 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
except AttributeError:
logger.debug("Disconnected socket closing")
AdvancedDispatcher.handle_close(self)
class BMStringParser(BMProto):
"""
A special case of BMProto used by objectProcessor to send ACK
"""
def __init__(self):
super(BMStringParser, self).__init__()
self.destination = state.Peer('127.0.0.1', 8444)
self.payload = None
ObjectTracker.__init__(self)
def send_data(self, data):
"""Send object given by the data string"""
# This class is introduced specially for ACK sending, please
# change log strings if you are going to use it for something else
self.bm_proto_reset()
self.payload = data
try:
self.bm_command_object()
except BMObjectAlreadyHaveError:
pass # maybe the same msg received on different nodes
except BMObjectExpiredError:
logger.debug(
'Sending ACK failure (expired): %s', hexlify(data))
except Exception as e:
logger.debug(
'Exception of type %s while sending ACK',
type(e), exc_info=True)