From cb1f1962e8e9e2a9f13fe34d546a1075f1765f6d Mon Sep 17 00:00:00 2001 From: "jai.s" Date: Mon, 2 Mar 2020 18:43:56 +0530 Subject: [PATCH] Solved ackreceived issue --- src/network/bmproto.py | 8 +++----- src/protocol.py | 2 +- src/storage/sqlite.py | 7 +++++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/network/bmproto.py b/src/network/bmproto.py index 3de70120..e98bdf93 100644 --- a/src/network/bmproto.py +++ b/src/network/bmproto.py @@ -141,7 +141,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker): except BMObjectAlreadyHaveError: logger.debug( '%(host)s:%(port)i already got object, skipping', - self.destinaestion._asdict()) + self.destination._asdict()) except struct.error: logger.debug('decoding error, skipping') except ValueError: @@ -409,7 +409,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker): try: self.object.checkObjectByType() objectProcessorQueue.put(( - self.object.objectType, memoryview(self.object.data))) + self.object.objectType, memoryview(self.object.data))) except BMObjectInvalidError: BMProto.stopDownloadingObject(self.object.inventoryHash, True) else: @@ -420,13 +420,11 @@ class BMProto(AdvancedDispatcher, ObjectTracker): if self.object.inventoryHash in Inventory()._realInventory and Dandelion().hasHash(self.object.inventoryHash): Dandelion().removeHash(self.object.inventoryHash, "cycle detection") - [self.object.inventoryHash] = ( - + Inventory()._realInventory[self.object.inventoryHash] = ( self.object.objectType, self.object.streamNumber, memoryview(self.payload[objectOffset:]), self.object.expiresTime, memoryview(self.object.tag) ) - Inventory()[self.object.inventoryHash] self.handleReceivedObject( self.object.streamNumber, self.object.inventoryHash) invQueue.put(( diff --git a/src/protocol.py b/src/protocol.py index 9e2f0865..a213d9ec 100644 --- a/src/protocol.py +++ b/src/protocol.py @@ -289,7 +289,7 @@ def isProofOfWorkSufficient( def CreatePacket(command, payload=''): """Construct and return a number of bytes from a payload""" - payload = payload if type(payload) in [bytes, bytearray] else payload.encode() + payload = payload if type(payload) in [bytes, bytearray,memoryview] else payload.encode() payload_length = len(payload) checksum = hashlib.sha512(payload).digest()[0:4] byte = bytearray(Header.size + payload_length) diff --git a/src/storage/sqlite.py b/src/storage/sqlite.py index d3c8c9e1..71d70488 100644 --- a/src/storage/sqlite.py +++ b/src/storage/sqlite.py @@ -42,8 +42,11 @@ class SqliteInventory(InventoryStorage): # pylint: disable=too-many-ancestors def __getitem__(self, hash_): with self.lock: - if hash_ in self._inventory: - return self._inventory[hash_] + if isinstance(hash_,memoryview) and bytes(hash_) in self._inventory : + return self._inventory[bytes(hash_)] + else: + if hash_ in self._inventory: + return self._inventory[hash_] rows = sqlQuery( 'SELECT objecttype, streamnumber, payload, expirestime, tag' ' FROM inventory WHERE hash=?', sqlite3.Binary(hash_))