objectracker pylint fixes

This commit is contained in:
lakshyacis 2019-09-06 15:58:06 +05:30
parent db1593f428
commit fa6ef4f933
No known key found for this signature in database
GPG Key ID: D2C539C8EC63E9EB
1 changed files with 16 additions and 19 deletions

View File

@ -1,3 +1,7 @@
import time
from threading import RLock
@ -27,6 +31,7 @@ missingObjects = {}
class ObjectTracker(object):
"""Object tracker mixin"""
invCleanPeriod = 300
invInitialCapacity = 50000
invErrorRate = 0.03
@ -42,21 +47,24 @@ class ObjectTracker(object):
self.lastCleaned = time.time()
def initInvBloom(self):
"""Init bloom filter for tracking. WIP."""
if haveBloom:
# lock?
self.invBloom = BloomFilter(capacity=ObjectTracker.invInitialCapacity,
def initAddrBloom(self):
"""Init bloom filter for tracking addrs, WIP. This either needs to be moved to addrthread.py or removed."""
if haveBloom:
# lock?
self.addrBloom = BloomFilter(capacity=ObjectTracker.invInitialCapacity,
def clean(self):
"""Clean up tracking to prevent memory bloat"""
if self.lastCleaned < time.time() - ObjectTracker.invCleanPeriod:
if haveBloom:
if len(missingObjects) == 0:
if missingObjects == 0:
@ -67,12 +75,13 @@ class ObjectTracker(object):
self.lastCleaned = time.time()
def hasObj(self, hashid):
"""Do we already have object?"""
if haveBloom:
return hashid in self.invBloom
return hashid in self.objectsNewToMe
return hashid in self.objectsNewToMe
def handleReceivedInventory(self, hashId):
"""Handling received inventory"""
if haveBloom:
@ -85,6 +94,7 @@ class ObjectTracker(object):
self.objectsNewToMe[hashId] = True
def handleReceivedObject(self, streamNumber, hashid):
"""Handling received object"""
for i in network.connectionpool.BMConnectionPool().inboundConnections.values(
) + network.connectionpool.BMConnectionPool().outboundConnections.values():
if not i.fullyEstablished:
@ -109,25 +119,12 @@ class ObjectTracker(object):
def hasAddr(self, addr):
"""WIP, should be moved to addrthread.py or removed"""
if haveBloom:
return addr in self.invBloom
return None
def addAddr(self, hashid):
"""WIP, should be moved to addrthread.py or removed"""
if haveBloom:
addr sending -> per node upload queue, and flush every minute or so
inv sending -> if not in bloom, inv immediately, otherwise put into a per node upload queue
and flush every minute or so
data sending -> a simple queue
no bloom
- if inv arrives
- if we don't have it, add tracking and download queue
- if we do have it, remove from tracking
tracking downloads
- per node hash of items the node has but we don't
tracking inv
- per node hash of items that neither the remote node nor we have