Make tuples from sets before taking random samples
This commit is contained in:
parent
4e77342d4d
commit
740654b563
|
@ -266,11 +266,11 @@ class Connection(threading.Thread):
|
||||||
if len(shared.node_pool) > 10:
|
if len(shared.node_pool) > 10:
|
||||||
addr.update({
|
addr.update({
|
||||||
structure.NetAddr(1, a[0], a[1])
|
structure.NetAddr(1, a[0], a[1])
|
||||||
for a in random.sample(shared.node_pool, 10)})
|
for a in random.sample(tuple(shared.node_pool), 10)})
|
||||||
if len(shared.unchecked_node_pool) > 10:
|
if len(shared.unchecked_node_pool) > 10:
|
||||||
addr.update({
|
addr.update({
|
||||||
structure.NetAddr(1, a[0], a[1])
|
structure.NetAddr(1, a[0], a[1])
|
||||||
for a in random.sample(shared.unchecked_node_pool, 10)})
|
for a in random.sample(tuple(shared.unchecked_node_pool), 10)})
|
||||||
if len(addr) != 0:
|
if len(addr) != 0:
|
||||||
self.send_queue.put(message.Addr(addr))
|
self.send_queue.put(message.Addr(addr))
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ class Connection(threading.Thread):
|
||||||
# We limit size of inv messaged to 10000 entries
|
# We limit size of inv messaged to 10000 entries
|
||||||
# because they might time out
|
# because they might time out
|
||||||
# in very slow networks (I2P)
|
# in very slow networks (I2P)
|
||||||
pack = random.sample(to_send, 10000)
|
pack = random.sample(tuple(to_send), 10000)
|
||||||
self.send_queue.put(message.Inv(pack))
|
self.send_queue.put(message.Inv(pack))
|
||||||
to_send.difference_update(pack)
|
to_send.difference_update(pack)
|
||||||
else:
|
else:
|
||||||
|
@ -456,7 +456,7 @@ class Connection(threading.Thread):
|
||||||
logging.info(
|
logging.info(
|
||||||
'Queued %s vectors to get', len(self.vectors_to_get))
|
'Queued %s vectors to get', len(self.vectors_to_get))
|
||||||
if len(self.vectors_to_get) > 64:
|
if len(self.vectors_to_get) > 64:
|
||||||
pack = random.sample(self.vectors_to_get, 64)
|
pack = random.sample(tuple(self.vectors_to_get), 64)
|
||||||
self.send_queue.put(message.GetData(pack))
|
self.send_queue.put(message.GetData(pack))
|
||||||
self.vectors_requested.update({
|
self.vectors_requested.update({
|
||||||
vector: time.time() for vector in pack
|
vector: time.time() for vector in pack
|
||||||
|
@ -486,7 +486,7 @@ class Connection(threading.Thread):
|
||||||
logging.info(
|
logging.info(
|
||||||
'Preparing to send %s objects', len(self.vectors_to_send))
|
'Preparing to send %s objects', len(self.vectors_to_send))
|
||||||
if len(self.vectors_to_send) > 16:
|
if len(self.vectors_to_send) > 16:
|
||||||
to_send = random.sample(self.vectors_to_send, 16)
|
to_send = random.sample(tuple(self.vectors_to_send), 16)
|
||||||
self.vectors_to_send.difference_update(to_send)
|
self.vectors_to_send.difference_update(to_send)
|
||||||
else:
|
else:
|
||||||
to_send = self.vectors_to_send.copy()
|
to_send = self.vectors_to_send.copy()
|
||||||
|
|
|
@ -98,24 +98,26 @@ class Manager(threading.Thread):
|
||||||
if shared.ip_enabled:
|
if shared.ip_enabled:
|
||||||
if len(shared.unchecked_node_pool) > 16:
|
if len(shared.unchecked_node_pool) > 16:
|
||||||
to_connect.update(random.sample(
|
to_connect.update(random.sample(
|
||||||
shared.unchecked_node_pool, 16))
|
tuple(shared.unchecked_node_pool), 16))
|
||||||
else:
|
else:
|
||||||
to_connect.update(shared.unchecked_node_pool)
|
to_connect.update(shared.unchecked_node_pool)
|
||||||
shared.unchecked_node_pool.difference_update(to_connect)
|
shared.unchecked_node_pool.difference_update(to_connect)
|
||||||
if len(shared.node_pool) > 8:
|
if len(shared.node_pool) > 8:
|
||||||
to_connect.update(random.sample(shared.node_pool, 8))
|
to_connect.update(random.sample(
|
||||||
|
tuple(shared.node_pool), 8))
|
||||||
else:
|
else:
|
||||||
to_connect.update(shared.node_pool)
|
to_connect.update(shared.node_pool)
|
||||||
|
|
||||||
if shared.i2p_enabled:
|
if shared.i2p_enabled:
|
||||||
if len(shared.i2p_unchecked_node_pool) > 16:
|
if len(shared.i2p_unchecked_node_pool) > 16:
|
||||||
to_connect.update(
|
to_connect.update(random.sample(
|
||||||
random.sample(shared.i2p_unchecked_node_pool, 16))
|
tuple(shared.i2p_unchecked_node_pool), 16))
|
||||||
else:
|
else:
|
||||||
to_connect.update(shared.i2p_unchecked_node_pool)
|
to_connect.update(shared.i2p_unchecked_node_pool)
|
||||||
shared.i2p_unchecked_node_pool.difference_update(to_connect)
|
shared.i2p_unchecked_node_pool.difference_update(to_connect)
|
||||||
if len(shared.i2p_node_pool) > 8:
|
if len(shared.i2p_node_pool) > 8:
|
||||||
to_connect.update(random.sample(shared.i2p_node_pool, 8))
|
to_connect.update(random.sample(
|
||||||
|
tuple(shared.i2p_node_pool), 8))
|
||||||
else:
|
else:
|
||||||
to_connect.update(shared.i2p_node_pool)
|
to_connect.update(shared.i2p_node_pool)
|
||||||
|
|
||||||
|
@ -214,17 +216,18 @@ class Manager(threading.Thread):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def pickle_nodes():
|
def pickle_nodes():
|
||||||
if len(shared.node_pool) > 10000:
|
if len(shared.node_pool) > 10000:
|
||||||
shared.node_pool = set(random.sample(shared.node_pool, 10000))
|
shared.node_pool = set(random.sample(
|
||||||
|
tuple(shared.node_pool), 10000))
|
||||||
if len(shared.unchecked_node_pool) > 1000:
|
if len(shared.unchecked_node_pool) > 1000:
|
||||||
shared.unchecked_node_pool = set(
|
shared.unchecked_node_pool = set(random.sample(
|
||||||
random.sample(shared.unchecked_node_pool, 1000))
|
tuple(shared.unchecked_node_pool), 1000))
|
||||||
|
|
||||||
if len(shared.i2p_node_pool) > 1000:
|
if len(shared.i2p_node_pool) > 1000:
|
||||||
shared.i2p_node_pool = set(
|
shared.i2p_node_pool = set(random.sample(
|
||||||
random.sample(shared.i2p_node_pool, 1000))
|
tuple(shared.i2p_node_pool), 1000))
|
||||||
if len(shared.i2p_unchecked_node_pool) > 100:
|
if len(shared.i2p_unchecked_node_pool) > 100:
|
||||||
shared.i2p_unchecked_node_pool = set(
|
shared.i2p_unchecked_node_pool = set(random.sample(
|
||||||
random.sample(shared.i2p_unchecked_node_pool, 100))
|
tuple(shared.i2p_unchecked_node_pool), 100))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(
|
with open(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user