Expired / Stream mismatch / duplicate object error handling

- cleanup of the code
This commit is contained in:
Peter Šurda 2017-06-24 12:22:41 +02:00
parent 0a79490e2c
commit 0dc0b22974
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
1 changed files with 22 additions and 6 deletions

View File

@ -7,6 +7,7 @@ import socket
import struct import struct
from addresses import calculateInventoryHash from addresses import calculateInventoryHash
from bmconfigparser import BMConfigParser
from debug import logger from debug import logger
from inventory import Inventory from inventory import Inventory
import knownnodes import knownnodes
@ -272,10 +273,10 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
self.object.checkProofOfWorkSufficient() self.object.checkProofOfWorkSufficient()
try: try:
self.object.checkEOLSanity() self.object.checkEOLSanity()
self.object.checkStream()
self.object.checkAlreadyHave() self.object.checkAlreadyHave()
except (BMObjectExpiredError, BMObjectUnwantedStreamError, BMObjectAlreadyHaveError) as e: except (BMObjectExpiredError, BMObjectAlreadyHaveError) as e:
for connection in network.connectionpool.BMConnectionPool().inboundConnections.values() + network.connectionpool.BMConnectionPool().outboundConnections.values(): for connection in network.connectionpool.BMConnectionPool().inboundConnections.values() + \
network.connectionpool.BMConnectionPool().outboundConnections.values():
try: try:
with connection.objectsNewToThemLock: with connection.objectsNewToThemLock:
del connection.objectsNewToThem[self.object.inventoryHash] del connection.objectsNewToThem[self.object.inventoryHash]
@ -286,9 +287,24 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
del connection.objectsNewToMe[self.object.inventoryHash] del connection.objectsNewToMe[self.object.inventoryHash]
except KeyError: except KeyError:
pass pass
if not BMConfigParser().get("inventory", "acceptmismatch") or \ raise e
isinstance(e, BMObjectAlreadyHaveError) or \ try:
isinstance(e, BMObjectExpiredError): self.object.checkStream()
except (BMObjectUnwantedStreamError,) as e:
for connection in network.connectionpool.BMConnectionPool().inboundConnections.values() + \
network.connectionpool.BMConnectionPool().outboundConnections.values():
try:
with connection.objectsNewToMeLock:
del connection.objectsNewToMe[self.object.inventoryHash]
except KeyError:
pass
if not BMConfigParser().get("inventory", "acceptmismatch"):
try:
with connection.objectsNewToThemLock:
del connection.objectsNewToThem[self.object.inventoryHash]
except KeyError:
pass
if not BMConfigParser().get("inventory", "acceptmismatch"):
raise e raise e
self.object.checkObjectByType() self.object.checkObjectByType()