Skip to content

Commit

Permalink
Expired / Stream mismatch / duplicate object error handling
Browse files Browse the repository at this point in the history
- cleanup of the code
  • Loading branch information
PeterSurda committed Jun 24, 2017
1 parent 0a79490 commit 0dc0b22
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/network/bmproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import struct

from addresses import calculateInventoryHash
from bmconfigparser import BMConfigParser
from debug import logger
from inventory import Inventory
import knownnodes
Expand Down Expand Up @@ -272,10 +273,10 @@ def bm_command_object(self):
self.object.checkProofOfWorkSufficient()
try:
self.object.checkEOLSanity()
self.object.checkStream()
self.object.checkAlreadyHave()
except (BMObjectExpiredError, BMObjectUnwantedStreamError, BMObjectAlreadyHaveError) as e:
for connection in network.connectionpool.BMConnectionPool().inboundConnections.values() + network.connectionpool.BMConnectionPool().outboundConnections.values():
except (BMObjectExpiredError, BMObjectAlreadyHaveError) as e:
for connection in network.connectionpool.BMConnectionPool().inboundConnections.values() + \
network.connectionpool.BMConnectionPool().outboundConnections.values():
try:
with connection.objectsNewToThemLock:
del connection.objectsNewToThem[self.object.inventoryHash]
Expand All @@ -286,9 +287,24 @@ def bm_command_object(self):
del connection.objectsNewToMe[self.object.inventoryHash]
except KeyError:
pass
if not BMConfigParser().get("inventory", "acceptmismatch") or \
isinstance(e, BMObjectAlreadyHaveError) or \
isinstance(e, BMObjectExpiredError):
raise e
try:
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

self.object.checkObjectByType()
Expand Down

0 comments on commit 0dc0b22

Please sign in to comment.