Skip to content

Commit

Permalink
Max known nodes configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterSurda committed Jun 24, 2017
1 parent 26eb54a commit b9d60f8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/bmconfigparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"storage": "sqlite",
"acceptmismatch": False,
},
"knownnodes": {
"maxnodes": 20000,
},
"zlib": {
'maxsize': 1048576
}
Expand Down
4 changes: 2 additions & 2 deletions src/knownnodes.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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]
Expand Down

0 comments on commit b9d60f8

Please sign in to comment.