From 38318150bdf6bd9a943c761dd92048ef0d24024d Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Mon, 10 Dec 2018 14:33:07 +0200 Subject: [PATCH] Moved missingObjects dict from state to network.objectracker --- src/network/bmproto.py | 8 ++++---- src/network/downloadthread.py | 8 ++++---- src/network/objectracker.py | 6 ++++-- src/network/stats.py | 4 ++-- src/state.py | 3 --- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/network/bmproto.py b/src/network/bmproto.py index ccb22ef5..ec86290b 100644 --- a/src/network/bmproto.py +++ b/src/network/bmproto.py @@ -1,6 +1,5 @@ import base64 import hashlib -import random import socket import struct import time @@ -17,7 +16,8 @@ from network.bmobject import BMObject, BMObjectInsufficientPOWError, BMObjectInv import network.connectionpool from network.node import Node from network.objectracker import ObjectTracker -from network.proxy import Proxy, ProxyError, GeneralProxyError +from network.proxy import ProxyError +from objectracker import missingObjects import addresses from queues import objectProcessorQueue, portCheckerQueue, invQueue, addrQueue @@ -359,7 +359,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker): BMProto.stopDownloadingObject(self.object.inventoryHash, True) else: try: - del state.missingObjects[self.object.inventoryHash] + del missingObjects[self.object.inventoryHash] except KeyError: pass @@ -559,7 +559,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker): except KeyError: pass try: - del state.missingObjects[hashId] + del missingObjects[hashId] except KeyError: pass diff --git a/src/network/downloadthread.py b/src/network/downloadthread.py index ee0b0289..babce5da 100644 --- a/src/network/downloadthread.py +++ b/src/network/downloadthread.py @@ -1,16 +1,16 @@ -import random import threading import time import addresses +import helper_random +import protocol from dandelion import Dandelion from debug import logger from helper_threading import StoppableThread from inventory import Inventory from network.connectionpool import BMConnectionPool -import protocol -from state import missingObjects -import helper_random +from objectracker import missingObjects + class DownloadThread(threading.Thread, StoppableThread): minPending = 200 diff --git a/src/network/objectracker.py b/src/network/objectracker.py index b5110212..f119b2d8 100644 --- a/src/network/objectracker.py +++ b/src/network/objectracker.py @@ -1,11 +1,9 @@ import time from threading import RLock -from inventory import Inventory import network.connectionpool from network.dandelion import Dandelion from randomtrackingdict import RandomTrackingDict -from state import missingObjects haveBloom = False @@ -24,6 +22,10 @@ except ImportError: # it isn't actually implemented yet so no point in turning it on haveBloom = False +# tracking pending downloads globally, for stats +missingObjects = {} + + class ObjectTracker(object): invCleanPeriod = 300 invInitialCapacity = 50000 diff --git a/src/network/stats.py b/src/network/stats.py index 80925f7c..5a0f8064 100644 --- a/src/network/stats.py +++ b/src/network/stats.py @@ -1,8 +1,8 @@ import time -from network.connectionpool import BMConnectionPool import asyncore_pollchoose as asyncore -from state import missingObjects +from network.connectionpool import BMConnectionPool +from objectracker import missingObjects lastReceivedTimestamp = time.time() lastReceivedBytes = 0 diff --git a/src/state.py b/src/state.py index e8d6a27d..87022d9c 100644 --- a/src/state.py +++ b/src/state.py @@ -51,9 +51,6 @@ trustedPeer = None discoveredPeers = {} -# tracking pending downloads globally, for stats -missingObjects = {} - Peer = collections.namedtuple('Peer', ['host', 'port'])