From 6044df5adf84b767e559b482ab90aead7eb1c4ab Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Fri, 2 Jun 2017 15:43:35 +0200 Subject: [PATCH] Optional storing of expired and off-stream objects - a new config file option, network/acceptmismatch, allows the inventory to store objects that expired or are from a stream we're not interested in. Having this on will prevent re-requesting objects that other nodes incorrectly advertise. It defaults to false --- src/bmconfigparser.py | 1 + src/network/bmproto.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/bmconfigparser.py b/src/bmconfigparser.py index b727ad65..bfa7e396 100644 --- a/src/bmconfigparser.py +++ b/src/bmconfigparser.py @@ -21,6 +21,7 @@ BMConfigDefaults = { }, "inventory": { "storage": "sqlite", + "acceptmismatch": False, }, "zlib": { 'maxsize': 1048576 diff --git a/src/network/bmproto.py b/src/network/bmproto.py index 8c727f00..722438f5 100644 --- a/src/network/bmproto.py +++ b/src/network/bmproto.py @@ -5,8 +5,6 @@ import math import time import socket import struct -import random -import traceback from addresses import calculateInventoryHash from debug import logger @@ -278,8 +276,16 @@ class BMProto(AdvancedDispatcher, ObjectTracker): raise BMProtoExcessiveDataError() self.object.checkProofOfWorkSufficient() - self.object.checkEOLSanity() - self.object.checkStream() + try: + self.object.checkEOLSanity() + except BMObjectExpiredError: + if not BMConfigParser().get("inventory", "acceptmismatch"): + raise + try: + self.object.checkStream() + except BMObjectUnwantedStreamError: + if not BMConfigParser().get("inventory", "acceptmismatch"): + raise self.object.checkAlreadyHave() if self.object.objectType == protocol.OBJECT_GETPUBKEY: @@ -448,9 +454,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker): def handle_close(self, reason=None): self.set_state("close") if reason is None: - #logger.debug("%s:%i: closing, %s", self.destination.host, self.destination.port, ''.join(traceback.format_stack())) logger.debug("%s:%i: closing", self.destination.host, self.destination.port) - #traceback.print_stack() else: logger.debug("%s:%i: closing, %s", self.destination.host, self.destination.port, reason) AdvancedDispatcher.handle_close(self)