Max known nodes configurable
This commit is contained in:
parent
26eb54a82e
commit
b9d60f8b41
|
@ -23,6 +23,9 @@ BMConfigDefaults = {
|
||||||
"storage": "sqlite",
|
"storage": "sqlite",
|
||||||
"acceptmismatch": False,
|
"acceptmismatch": False,
|
||||||
},
|
},
|
||||||
|
"knownnodes": {
|
||||||
|
"maxnodes": 20000,
|
||||||
|
},
|
||||||
"zlib": {
|
"zlib": {
|
||||||
'maxsize': 1048576
|
'maxsize': 1048576
|
||||||
}
|
}
|
||||||
|
|
|
@ -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]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user