From b9d60f8b41ea5ba28ed3bc958953c7ac27fff9dd Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sat, 24 Jun 2017 12:17:01 +0200 Subject: [PATCH] Max known nodes configurable --- src/bmconfigparser.py | 3 +++ src/knownnodes.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bmconfigparser.py b/src/bmconfigparser.py index 0db58103..6725a4d8 100644 --- a/src/bmconfigparser.py +++ b/src/bmconfigparser.py @@ -23,6 +23,9 @@ BMConfigDefaults = { "storage": "sqlite", "acceptmismatch": False, }, + "knownnodes": { + "maxnodes": 20000, + }, "zlib": { 'maxsize': 1048576 } diff --git a/src/knownnodes.py b/src/knownnodes.py index ffb14edc..8f566d43 100644 --- a/src/knownnodes.py +++ b/src/knownnodes.py @@ -1,12 +1,12 @@ import pickle import threading +from bmconfigparser import BMConfigParser import state knownNodesLock = threading.Lock() knownNodes = {} -knownNodesMax = 20000 knownNodesTrimAmount = 2000 def saveKnownNodes(dirName = None): @@ -17,7 +17,7 @@ def saveKnownNodes(dirName = None): pickle.dump(knownNodes, output) def trimKnownNodes(recAddrStream = 1): - if len(knownNodes[recAddrStream]) < knownNodesMax: + if len(knownNodes[recAddrStream]) < BMConfigParser().get("knownnodes", "maxnodes"): return with knownNodesLock: oldestList = sorted(knownNodes[recAddrStream], key=knownNodes[recAddrStream].get)[:knownNodesTrimAmount]