Slightly reduced TCPConnection.sendAddr() and changed
in order to send only nodes with non-negative rating
This commit is contained in:
parent
2d702e9647
commit
e25fb857cb
|
@ -130,36 +130,30 @@ class TCPConnection(BMProto, TLSDispatcher): # pylint: disable=too-many-instanc
|
||||||
# We are going to share a maximum number of 1000 addrs (per overlapping
|
# We are going to share a maximum number of 1000 addrs (per overlapping
|
||||||
# stream) with our peer. 500 from overlapping streams, 250 from the
|
# stream) with our peer. 500 from overlapping streams, 250 from the
|
||||||
# left child stream, and 250 from the right child stream.
|
# left child stream, and 250 from the right child stream.
|
||||||
maxAddrCount = BMConfigParser().safeGetInt("bitmessagesettings", "maxaddrperstreamsend", 500)
|
maxAddrCount = BMConfigParser().safeGetInt(
|
||||||
|
"bitmessagesettings", "maxaddrperstreamsend", 500)
|
||||||
|
|
||||||
# init
|
|
||||||
templist = []
|
templist = []
|
||||||
addrs = {}
|
addrs = {}
|
||||||
for stream in self.streams:
|
for stream in self.streams:
|
||||||
with knownnodes.knownNodesLock:
|
with knownnodes.knownNodesLock:
|
||||||
if knownnodes.knownNodes[stream]:
|
for n, s in enumerate((stream, stream * 2, stream * 2 + 1)):
|
||||||
filtered = {k: v for k, v in knownnodes.knownNodes[stream].items()
|
nodes = knownnodes.knownNodes.get(s)
|
||||||
if v["lastseen"] > (int(time.time()) - shared.maximumAgeOfNodesThatIAdvertiseToOthers)}
|
if not nodes:
|
||||||
elemCount = len(filtered)
|
continue
|
||||||
if elemCount > maxAddrCount:
|
|
||||||
elemCount = maxAddrCount
|
|
||||||
# only if more recent than 3 hours
|
# only if more recent than 3 hours
|
||||||
addrs[stream] = helper_random.randomsample(filtered.items(), elemCount)
|
# and having positive or neutral rating
|
||||||
|
filtered = [
|
||||||
|
(k, v) for k, v in nodes.iteritems()
|
||||||
|
if v["lastseen"] > int(time.time()) -
|
||||||
|
shared.maximumAgeOfNodesThatIAdvertiseToOthers and
|
||||||
|
v["rating"] >= 0
|
||||||
|
]
|
||||||
# sent 250 only if the remote isn't interested in it
|
# sent 250 only if the remote isn't interested in it
|
||||||
if knownnodes.knownNodes[stream * 2] and stream not in self.streams:
|
elemCount = min(
|
||||||
filtered = {k: v for k, v in knownnodes.knownNodes[stream * 2].items()
|
len(filtered),
|
||||||
if v["lastseen"] > (int(time.time()) - shared.maximumAgeOfNodesThatIAdvertiseToOthers)}
|
maxAddrCount / 2 if n else maxAddrCount)
|
||||||
elemCount = len(filtered)
|
addrs[s] = helper_random.randomsample(filtered, elemCount)
|
||||||
if elemCount > maxAddrCount / 2:
|
|
||||||
elemCount = int(maxAddrCount / 2)
|
|
||||||
addrs[stream * 2] = helper_random.randomsample(filtered.items(), elemCount)
|
|
||||||
if knownnodes.knownNodes[(stream * 2) + 1] and stream not in self.streams:
|
|
||||||
filtered = {k: v for k, v in knownnodes.knownNodes[stream * 2 + 1].items()
|
|
||||||
if v["lastseen"] > (int(time.time()) - shared.maximumAgeOfNodesThatIAdvertiseToOthers)}
|
|
||||||
elemCount = len(filtered)
|
|
||||||
if elemCount > maxAddrCount / 2:
|
|
||||||
elemCount = int(maxAddrCount / 2)
|
|
||||||
addrs[stream * 2 + 1] = helper_random.randomsample(filtered.items(), elemCount)
|
|
||||||
for substream in addrs:
|
for substream in addrs:
|
||||||
for peer, params in addrs[substream]:
|
for peer, params in addrs[substream]:
|
||||||
templist.append((substream, peer, params["lastseen"]))
|
templist.append((substream, peer, params["lastseen"]))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user