class_objectProcessor quality fixes
This commit is contained in:
parent
e534994ee3
commit
059e82e2a2
|
@ -1,7 +1,9 @@
|
||||||
|
"""
|
||||||
|
The objectProcessor thread, of which there is only one, processes the network objects
|
||||||
|
"""
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import random
|
import random
|
||||||
import shared
|
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
|
@ -9,11 +11,13 @@ from subprocess import call # nosec
|
||||||
|
|
||||||
import highlevelcrypto
|
import highlevelcrypto
|
||||||
import knownnodes
|
import knownnodes
|
||||||
|
import shared
|
||||||
from addresses import (
|
from addresses import (
|
||||||
calculateInventoryHash, decodeAddress, decodeVarint, encodeAddress,
|
calculateInventoryHash, decodeAddress, decodeVarint, encodeAddress,
|
||||||
encodeVarint, varintDecodeError
|
encodeVarint, varintDecodeError
|
||||||
)
|
)
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
|
|
||||||
import helper_bitcoin
|
import helper_bitcoin
|
||||||
import helper_inbox
|
import helper_inbox
|
||||||
import helper_msgcoding
|
import helper_msgcoding
|
||||||
|
@ -22,12 +26,15 @@ from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery
|
||||||
from helper_ackPayload import genAckPayload
|
from helper_ackPayload import genAckPayload
|
||||||
from network import bmproto
|
from network import bmproto
|
||||||
from network.node import Peer
|
from network.node import Peer
|
||||||
|
|
||||||
import protocol
|
import protocol
|
||||||
import queues
|
import queues
|
||||||
import state
|
import state
|
||||||
import tr
|
import tr
|
||||||
from fallback import RIPEMD160Hash
|
from fallback import RIPEMD160Hash
|
||||||
|
|
||||||
import l10n
|
import l10n
|
||||||
|
# pylint: disable=too-many-locals, too-many-return-statements, too-many-branches, too-many-statements
|
||||||
|
|
||||||
logger = logging.getLogger('default')
|
logger = logging.getLogger('default')
|
||||||
|
|
||||||
|
@ -122,7 +129,10 @@ class objectProcessor(threading.Thread):
|
||||||
state.shutdown = 2
|
state.shutdown = 2
|
||||||
break
|
break
|
||||||
|
|
||||||
def checkackdata(self, data):
|
@staticmethod
|
||||||
|
def checkackdata(data):
|
||||||
|
"""Checking Acknowledgement of message received or not?"""
|
||||||
|
# pylint: disable=protected-access
|
||||||
# Let's check whether this is a message acknowledgement bound for us.
|
# Let's check whether this is a message acknowledgement bound for us.
|
||||||
if len(data) < 32:
|
if len(data) < 32:
|
||||||
return
|
return
|
||||||
|
@ -272,6 +282,7 @@ class objectProcessor(threading.Thread):
|
||||||
queues.workerQueue.put(('sendOutOrStoreMyV4Pubkey', myAddress))
|
queues.workerQueue.put(('sendOutOrStoreMyV4Pubkey', myAddress))
|
||||||
|
|
||||||
def processpubkey(self, data):
|
def processpubkey(self, data):
|
||||||
|
"""Process a pubkey object"""
|
||||||
pubkeyProcessingStartTime = time.time()
|
pubkeyProcessingStartTime = time.time()
|
||||||
shared.numberOfPubkeysProcessed += 1
|
shared.numberOfPubkeysProcessed += 1
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
|
@ -444,6 +455,7 @@ class objectProcessor(threading.Thread):
|
||||||
timeRequiredToProcessPubkey)
|
timeRequiredToProcessPubkey)
|
||||||
|
|
||||||
def processmsg(self, data):
|
def processmsg(self, data):
|
||||||
|
"""Process a message object"""
|
||||||
messageProcessingStartTime = time.time()
|
messageProcessingStartTime = time.time()
|
||||||
shared.numberOfMessagesProcessed += 1
|
shared.numberOfMessagesProcessed += 1
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
|
@ -739,7 +751,7 @@ class objectProcessor(threading.Thread):
|
||||||
# We really should have a discussion about how to
|
# We really should have a discussion about how to
|
||||||
# set the TTL for mailing list broadcasts. This is obviously
|
# set the TTL for mailing list broadcasts. This is obviously
|
||||||
# hard-coded.
|
# hard-coded.
|
||||||
TTL = 2*7*24*60*60 # 2 weeks
|
TTL = 2 * 7 * 24 * 60 * 60 # 2 weeks
|
||||||
t = ('',
|
t = ('',
|
||||||
toAddress,
|
toAddress,
|
||||||
ripe,
|
ripe,
|
||||||
|
@ -791,6 +803,7 @@ class objectProcessor(threading.Thread):
|
||||||
)
|
)
|
||||||
|
|
||||||
def processbroadcast(self, data):
|
def processbroadcast(self, data):
|
||||||
|
"""Process a broadcast object"""
|
||||||
messageProcessingStartTime = time.time()
|
messageProcessingStartTime = time.time()
|
||||||
shared.numberOfBroadcastsProcessed += 1
|
shared.numberOfBroadcastsProcessed += 1
|
||||||
queues.UISignalQueue.put((
|
queues.UISignalQueue.put((
|
||||||
|
@ -975,7 +988,7 @@ class objectProcessor(threading.Thread):
|
||||||
|
|
||||||
fromAddress = encodeAddress(
|
fromAddress = encodeAddress(
|
||||||
sendersAddressVersion, sendersStream, calculatedRipe)
|
sendersAddressVersion, sendersStream, calculatedRipe)
|
||||||
logger.info('fromAddress: %s' % fromAddress)
|
logger.info('fromAddress: %s', fromAddress)
|
||||||
|
|
||||||
# Let's store the public key in case we want to reply to this person.
|
# Let's store the public key in case we want to reply to this person.
|
||||||
sqlExecute('''INSERT INTO pubkeys VALUES (?,?,?,?,?)''',
|
sqlExecute('''INSERT INTO pubkeys VALUES (?,?,?,?,?)''',
|
||||||
|
@ -992,7 +1005,7 @@ class objectProcessor(threading.Thread):
|
||||||
|
|
||||||
fromAddress = encodeAddress(
|
fromAddress = encodeAddress(
|
||||||
sendersAddressVersion, sendersStream, calculatedRipe)
|
sendersAddressVersion, sendersStream, calculatedRipe)
|
||||||
logger.debug('fromAddress: ' + fromAddress)
|
logger.debug('fromAddress: %s', fromAddress)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
decodedMessage = helper_msgcoding.MsgDecode(
|
decodedMessage = helper_msgcoding.MsgDecode(
|
||||||
|
@ -1060,7 +1073,8 @@ class objectProcessor(threading.Thread):
|
||||||
del state.neededPubkeys[tag]
|
del state.neededPubkeys[tag]
|
||||||
self.sendMessages(address)
|
self.sendMessages(address)
|
||||||
|
|
||||||
def sendMessages(self, address):
|
@staticmethod
|
||||||
|
def sendMessages(address):
|
||||||
"""
|
"""
|
||||||
This method is called by the `possibleNewPubkey` when it sees
|
This method is called by the `possibleNewPubkey` when it sees
|
||||||
that we now have the necessary pubkey to send one or more messages.
|
that we now have the necessary pubkey to send one or more messages.
|
||||||
|
@ -1073,7 +1087,9 @@ class objectProcessor(threading.Thread):
|
||||||
" AND folder='sent'", address)
|
" AND folder='sent'", address)
|
||||||
queues.workerQueue.put(('sendmessage', ''))
|
queues.workerQueue.put(('sendmessage', ''))
|
||||||
|
|
||||||
def ackDataHasAValidHeader(self, ackData):
|
@staticmethod
|
||||||
|
def ackDataHasAValidHeader(ackData):
|
||||||
|
"""Checking ackData with valid Header, not sending ackData when false"""
|
||||||
if len(ackData) < protocol.Header.size:
|
if len(ackData) < protocol.Header.size:
|
||||||
logger.info(
|
logger.info(
|
||||||
'The length of ackData is unreasonably short. Not sending'
|
'The length of ackData is unreasonably short. Not sending'
|
||||||
|
@ -1108,11 +1124,12 @@ class objectProcessor(threading.Thread):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def addMailingListNameToSubject(self, subject, mailingListName):
|
@staticmethod
|
||||||
|
def addMailingListNameToSubject(subject, mailingListName):
|
||||||
|
"""Adding mailingListName to subject"""
|
||||||
subject = subject.strip()
|
subject = subject.strip()
|
||||||
if subject[:3] == 'Re:' or subject[:3] == 'RE:':
|
if subject[:3] == 'Re:' or subject[:3] == 'RE:':
|
||||||
subject = subject[3:].strip()
|
subject = subject[3:].strip()
|
||||||
if '[' + mailingListName + ']' in subject:
|
if '[' + mailingListName + ']' in subject:
|
||||||
return subject
|
return subject
|
||||||
else:
|
|
||||||
return '[' + mailingListName + '] ' + subject
|
return '[' + mailingListName + '] ' + subject
|
||||||
|
|
Loading…
Reference in New Issue
Block a user