knownnodes quality fixes
This commit is contained in:
parent
ee5be28179
commit
afce500085
|
@ -82,6 +82,7 @@ def pickle_deserialize_old_knownnodes(source):
|
||||||
|
|
||||||
|
|
||||||
def saveKnownNodes(dirName=None):
|
def saveKnownNodes(dirName=None):
|
||||||
|
"""Save knownnodes to filesystem"""
|
||||||
if dirName is None:
|
if dirName is None:
|
||||||
dirName = state.appdata
|
dirName = state.appdata
|
||||||
with knownNodesLock:
|
with knownNodesLock:
|
||||||
|
@ -90,6 +91,7 @@ def saveKnownNodes(dirName=None):
|
||||||
|
|
||||||
|
|
||||||
def addKnownNode(stream, peer, lastseen=None, is_self=False):
|
def addKnownNode(stream, peer, lastseen=None, is_self=False):
|
||||||
|
"""Add a new node to the dict"""
|
||||||
knownNodes[stream][peer] = {
|
knownNodes[stream][peer] = {
|
||||||
"lastseen": lastseen or time.time(),
|
"lastseen": lastseen or time.time(),
|
||||||
"rating": 1 if is_self else 0,
|
"rating": 1 if is_self else 0,
|
||||||
|
@ -98,6 +100,7 @@ def addKnownNode(stream, peer, lastseen=None, is_self=False):
|
||||||
|
|
||||||
|
|
||||||
def createDefaultKnownNodes():
|
def createDefaultKnownNodes():
|
||||||
|
"""Creating default Knownnodes"""
|
||||||
past = time.time() - 2418600 # 28 days - 10 min
|
past = time.time() - 2418600 # 28 days - 10 min
|
||||||
for peer in DEFAULT_NODES:
|
for peer in DEFAULT_NODES:
|
||||||
addKnownNode(1, peer, past)
|
addKnownNode(1, peer, past)
|
||||||
|
@ -105,6 +108,7 @@ def createDefaultKnownNodes():
|
||||||
|
|
||||||
|
|
||||||
def readKnownNodes():
|
def readKnownNodes():
|
||||||
|
"""Load knownnodes from filesystem"""
|
||||||
try:
|
try:
|
||||||
with open(state.appdata + 'knownnodes.dat', 'rb') as source:
|
with open(state.appdata + 'knownnodes.dat', 'rb') as source:
|
||||||
with knownNodesLock:
|
with knownNodesLock:
|
||||||
|
@ -131,6 +135,7 @@ def readKnownNodes():
|
||||||
|
|
||||||
|
|
||||||
def increaseRating(peer):
|
def increaseRating(peer):
|
||||||
|
"""Increase rating of a peer node"""
|
||||||
increaseAmount = 0.1
|
increaseAmount = 0.1
|
||||||
maxRating = 1
|
maxRating = 1
|
||||||
with knownNodesLock:
|
with knownNodesLock:
|
||||||
|
@ -145,6 +150,7 @@ def increaseRating(peer):
|
||||||
|
|
||||||
|
|
||||||
def decreaseRating(peer):
|
def decreaseRating(peer):
|
||||||
|
"""Decrease rating of a peer node"""
|
||||||
decreaseAmount = 0.1
|
decreaseAmount = 0.1
|
||||||
minRating = -1
|
minRating = -1
|
||||||
with knownNodesLock:
|
with knownNodesLock:
|
||||||
|
@ -159,6 +165,7 @@ def decreaseRating(peer):
|
||||||
|
|
||||||
|
|
||||||
def trimKnownNodes(recAddrStream=1):
|
def trimKnownNodes(recAddrStream=1):
|
||||||
|
"""Triming Knownnodes"""
|
||||||
if len(knownNodes[recAddrStream]) < \
|
if len(knownNodes[recAddrStream]) < \
|
||||||
BMConfigParser().safeGetInt("knownnodes", "maxnodes"):
|
BMConfigParser().safeGetInt("knownnodes", "maxnodes"):
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user