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 untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
2 changed files with 5 additions and 2 deletions

View File

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

View File

@ -1,12 +1,12 @@
import pickle import pickle
import threading import threading
from bmconfigparser import BMConfigParser
import state import state
knownNodesLock = threading.Lock() knownNodesLock = threading.Lock()
knownNodes = {} knownNodes = {}
knownNodesMax = 20000
knownNodesTrimAmount = 2000 knownNodesTrimAmount = 2000
def saveKnownNodes(dirName = None): def saveKnownNodes(dirName = None):
@ -17,7 +17,7 @@ def saveKnownNodes(dirName = None):
pickle.dump(knownNodes, output) pickle.dump(knownNodes, output)
def trimKnownNodes(recAddrStream = 1): def trimKnownNodes(recAddrStream = 1):
if len(knownNodes[recAddrStream]) < knownNodesMax: if len(knownNodes[recAddrStream]) < BMConfigParser().get("knownnodes", "maxnodes"):
return return
with knownNodesLock: with knownNodesLock:
oldestList = sorted(knownNodes[recAddrStream], key=knownNodes[recAddrStream].get)[:knownNodesTrimAmount] oldestList = sorted(knownNodes[recAddrStream], key=knownNodes[recAddrStream].get)[:knownNodesTrimAmount]