Special class BMStringParser for sending ACK (resolves #1374)
This commit is contained in:
parent
7c7d6781a2
commit
49985a435f
|
@ -19,6 +19,7 @@ import helper_msgcoding
|
||||||
import helper_sent
|
import helper_sent
|
||||||
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery
|
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery
|
||||||
from helper_ackPayload import genAckPayload
|
from helper_ackPayload import genAckPayload
|
||||||
|
from network import bmproto
|
||||||
import protocol
|
import protocol
|
||||||
import queues
|
import queues
|
||||||
import state
|
import state
|
||||||
|
@ -50,6 +51,7 @@ class objectProcessor(threading.Thread):
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'Loaded %s objects from disk into the objectProcessorQueue.',
|
'Loaded %s objects from disk into the objectProcessorQueue.',
|
||||||
len(queryreturn))
|
len(queryreturn))
|
||||||
|
self._ack_obj = bmproto.BMStringParser()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while True:
|
while True:
|
||||||
|
@ -743,12 +745,13 @@ class objectProcessor(threading.Thread):
|
||||||
|
|
||||||
# Don't send ACK if invalid, blacklisted senders, invisible
|
# Don't send ACK if invalid, blacklisted senders, invisible
|
||||||
# messages, disabled or chan
|
# messages, disabled or chan
|
||||||
# if (self.ackDataHasAValidHeader(ackData) and not blockMessage
|
if (
|
||||||
# and messageEncodingType != 0 and
|
self.ackDataHasAValidHeader(ackData) and not blockMessage and
|
||||||
# not BMConfigParser().safeGetBoolean(toAddress, 'dontsendack')
|
messageEncodingType != 0 and
|
||||||
# and not BMConfigParser().safeGetBoolean(toAddress, 'chan')
|
not BMConfigParser().safeGetBoolean(toAddress, 'dontsendack') and
|
||||||
# ):
|
not BMConfigParser().safeGetBoolean(toAddress, 'chan')
|
||||||
# shared.checkAndShareObjectWithPeers(ackData[24:])
|
):
|
||||||
|
self._ack_obj.send_data(ackData[24:])
|
||||||
|
|
||||||
# Display timing data
|
# Display timing data
|
||||||
timeRequiredToAttemptToDecryptMessage = time.time(
|
timeRequiredToAttemptToDecryptMessage = time.time(
|
||||||
|
|
|
@ -4,6 +4,7 @@ import random
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
import time
|
import time
|
||||||
|
from binascii import hexlify
|
||||||
|
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
from debug import logger
|
from debug import logger
|
||||||
|
@ -575,3 +576,32 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
logger.debug("Disconnected socket closing")
|
logger.debug("Disconnected socket closing")
|
||||||
AdvancedDispatcher.handle_close(self)
|
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)
|
||||||
|
|
Reference in New Issue
Block a user