Max known nodes configurable

This commit is contained in:
Peter Šurda 2017-06-24 12:17:01 +02:00
parent 26eb54a82e
commit b9d60f8b41
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
2 changed files with 5 additions and 2 deletions

View File

@ -23,6 +23,9 @@ BMConfigDefaults = {
"storage": "sqlite",
"acceptmismatch": False,
},
"knownnodes": {
"maxnodes": 20000,
},
"zlib": {
'maxsize': 1048576
}

View File

@ -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]