Solved inventory issue
This commit is contained in:
parent
0cdfdfbcd0
commit
be178f23ae
|
@ -455,7 +455,7 @@ class singleWorker(StoppableThread):
|
||||||
|
|
||||||
inventoryHash = calculateInventoryHash(payload)
|
inventoryHash = calculateInventoryHash(payload)
|
||||||
objectType = 1
|
objectType = 1
|
||||||
Inventory()._realInventory[inventoryHash] = (
|
Inventory()[inventoryHash] = (
|
||||||
objectType, streamNumber, payload, embeddedTime,
|
objectType, streamNumber, payload, embeddedTime,
|
||||||
doubleHashOfAddressData[32:]
|
doubleHashOfAddressData[32:]
|
||||||
)
|
)
|
||||||
|
@ -1239,7 +1239,7 @@ class singleWorker(StoppableThread):
|
||||||
objectType = 2
|
objectType = 2
|
||||||
inventoryHashlist = (
|
inventoryHashlist = (
|
||||||
objectType, toStreamNumber,encryptedPayload, embeddedTime, '')
|
objectType, toStreamNumber,encryptedPayload, embeddedTime, '')
|
||||||
Inventory()._realInventory[inventoryHash] = (
|
Inventory()[inventoryHash] = (
|
||||||
objectType, toStreamNumber, encryptedPayload, embeddedTime, '')
|
objectType, toStreamNumber, encryptedPayload, embeddedTime, '')
|
||||||
if BMConfigParser().has_section(toaddress) or \
|
if BMConfigParser().has_section(toaddress) or \
|
||||||
not protocol.checkBitfield(behaviorBitfield, protocol.BITFIELD_DOESACK):
|
not protocol.checkBitfield(behaviorBitfield, protocol.BITFIELD_DOESACK):
|
||||||
|
@ -1393,9 +1393,8 @@ class singleWorker(StoppableThread):
|
||||||
payload = self._doPOWDefaults(payload, TTL)
|
payload = self._doPOWDefaults(payload, TTL)
|
||||||
inventoryHash = calculateInventoryHash(payload)
|
inventoryHash = calculateInventoryHash(payload)
|
||||||
objectType = 1
|
objectType = 1
|
||||||
Inventory()._realInventory[inventoryHash] = (
|
Inventory()[inventoryHash] = (
|
||||||
objectType, streamNumber, payload, embeddedTime, '')
|
objectType, streamNumber, payload, embeddedTime, '')
|
||||||
# Inventory()._realInventory[inventoryHashlist]
|
|
||||||
self.logger.info('sending inv (for the getpubkey message)')
|
self.logger.info('sending inv (for the getpubkey message)')
|
||||||
queues.invQueue.put((streamNumber, inventoryHash))
|
queues.invQueue.put((streamNumber, inventoryHash))
|
||||||
# wait 10% past expiration
|
# wait 10% past expiration
|
||||||
|
|
|
@ -24,8 +24,8 @@ class Inventory():
|
||||||
|
|
||||||
# cheap inheritance copied from asyncore
|
# cheap inheritance copied from asyncore
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
if attr == "__contains__":
|
# if attr == "__contains__":
|
||||||
self.numberOfInventoryLookupsPerformed += 1
|
# self.numberOfInventoryLookupsPerformed += 1
|
||||||
try:
|
try:
|
||||||
realRet = getattr(self._realInventory, attr)
|
realRet = getattr(self._realInventory, attr)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
@ -36,6 +36,15 @@ class Inventory():
|
||||||
else:
|
else:
|
||||||
return realRet
|
return realRet
|
||||||
|
|
||||||
|
# on python3 we have separately added __contains__ method
|
||||||
|
def __contains__(self, attr):
|
||||||
|
self.numberOfInventoryLookupsPerformed += 1
|
||||||
|
return getattr(self._realInventory, '__contains__')(attr)
|
||||||
|
|
||||||
|
# on python3 we have separately added __setitem__ method
|
||||||
|
def __setitem__(self, hash_, value):
|
||||||
|
return getattr(self._realInventory,'__setitem__')(hash_,value)
|
||||||
|
|
||||||
# hint for pylint: this is dictionary like object
|
# hint for pylint: this is dictionary like object
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
return self._realInventory[key]
|
return self._realInventory[key]
|
|
@ -116,7 +116,7 @@ class BMObject(object): # pylint: disable=too-many-instance-attributes
|
||||||
# if it's a stem duplicate, pretend we don't have it
|
# if it's a stem duplicate, pretend we don't have it
|
||||||
if Dandelion().hasHash(self.inventoryHash):
|
if Dandelion().hasHash(self.inventoryHash):
|
||||||
return
|
return
|
||||||
if self.inventoryHash in Inventory()._realInventory:
|
if self.inventoryHash in Inventory():
|
||||||
raise BMObjectAlreadyHaveError()
|
raise BMObjectAlreadyHaveError()
|
||||||
|
|
||||||
def checkObjectByType(self):
|
def checkObjectByType(self):
|
||||||
|
|
|
@ -357,7 +357,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
if dandelion and not state.dandelion:
|
if dandelion and not state.dandelion:
|
||||||
return True
|
return True
|
||||||
for i in map(bytes, items):
|
for i in map(bytes, items):
|
||||||
if i in Inventory()._realInventory and not Dandelion().hasHash(i):
|
if i in Inventory() and not Dandelion().hasHash(i):
|
||||||
continue
|
continue
|
||||||
if dandelion and not Dandelion().hasHash(i):
|
if dandelion and not Dandelion().hasHash(i):
|
||||||
Dandelion().addHash(i, self)
|
Dandelion().addHash(i, self)
|
||||||
|
@ -417,10 +417,9 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
|
||||||
del missingObjects[self.object.inventoryHash]
|
del missingObjects[self.object.inventoryHash]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
if self.object.inventoryHash in Inventory() and Dandelion().hasHash(self.object.inventoryHash):
|
||||||
if self.object.inventoryHash in Inventory()._realInventory and Dandelion().hasHash(self.object.inventoryHash):
|
|
||||||
Dandelion().removeHash(self.object.inventoryHash, "cycle detection")
|
Dandelion().removeHash(self.object.inventoryHash, "cycle detection")
|
||||||
Inventory()._realInventory[self.object.inventoryHash] = (
|
Inventory()[self.object.inventoryHash] = (
|
||||||
self.object.objectType, self.object.streamNumber,
|
self.object.objectType, self.object.streamNumber,
|
||||||
memoryview(self.payload[objectOffset:]), self.object.expiresTime,
|
memoryview(self.payload[objectOffset:]), self.object.expiresTime,
|
||||||
memoryview(self.object.tag)
|
memoryview(self.object.tag)
|
||||||
|
|
|
@ -61,7 +61,7 @@ class DownloadThread(StoppableThread):
|
||||||
payload = bytearray()
|
payload = bytearray()
|
||||||
chunkCount = 0
|
chunkCount = 0
|
||||||
for chunk in request:
|
for chunk in request:
|
||||||
if chunk in Inventory()._realInventory and not Dandelion().hasHash(chunk):
|
if chunk in Inventory() and not Dandelion().hasHash(chunk):
|
||||||
try:
|
try:
|
||||||
del i.objectsNewToMe[chunk]
|
del i.objectsNewToMe[chunk]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
|
@ -211,7 +211,7 @@ class TCPConnection(BMProto, TLSDispatcher):
|
||||||
# may lock for a long time, but I think it's better than
|
# may lock for a long time, but I think it's better than
|
||||||
# thousands of small locks
|
# thousands of small locks
|
||||||
with self.objectsNewToThemLock:
|
with self.objectsNewToThemLock:
|
||||||
for objHash in Inventory()._realInventory.unexpired_hashes_by_stream(stream):
|
for objHash in Inventory().unexpired_hashes_by_stream(stream):
|
||||||
# don't advertise stem objects on bigInv
|
# don't advertise stem objects on bigInv
|
||||||
if Dandelion().hasHash(objHash):
|
if Dandelion().hasHash(objHash):
|
||||||
continue
|
continue
|
||||||
|
|
Reference in New Issue
Block a user