Don't use network for sending ACK #2205

Merged
PeterSurda merged 6 commits from gitea-77 into v0.6 2024-04-05 01:15:06 +02:00
2 changed files with 9 additions and 33 deletions
Showing only changes of commit 13d090e344 - Show all commits

View File

@ -31,7 +31,8 @@ from bmconfigparser import config
from fallback import RIPEMD160Hash from fallback import RIPEMD160Hash
from helper_sql import ( from helper_sql import (
sql_ready, sql_timeout, SqlBulkExecute, sqlExecute, sqlQuery) sql_ready, sql_timeout, SqlBulkExecute, sqlExecute, sqlQuery)
from network import bmproto, knownnodes from inventory import Inventory
from network import knownnodes
from network.node import Peer from network.node import Peer
from tr import _translate from tr import _translate
@ -64,7 +65,6 @@ 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()
self.successfullyDecryptMessageTimings = [] self.successfullyDecryptMessageTimings = []
def run(self): def run(self):
@ -733,7 +733,13 @@ class objectProcessor(threading.Thread):
and not config.safeGetBoolean(toAddress, 'dontsendack') and not config.safeGetBoolean(toAddress, 'dontsendack')
and not config.safeGetBoolean(toAddress, 'chan') and not config.safeGetBoolean(toAddress, 'chan')
): ):
self._ack_obj.send_data(ackData[24:]) ackPayload = ackData[24:]
objectType, toStreamNumber, expiresTime = \
protocol.decodeObjectParameters(ackPayload)
inventoryHash = calculateInventoryHash(ackPayload)
Inventory()[inventoryHash] = (
objectType, toStreamNumber, ackPayload, expiresTime, b'')
queues.invQueue.put((toStreamNumber, inventoryHash))
# Display timing data # Display timing data
timeRequiredToAttemptToDecryptMessage = time.time( timeRequiredToAttemptToDecryptMessage = time.time(

View File

@ -9,7 +9,6 @@ import re
import socket import socket
import struct import struct
import time import time
from binascii import hexlify
# magic imports! # magic imports!
import addresses import addresses
@ -678,32 +677,3 @@ 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 = 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)