Minor changes

Fix typos
This commit is contained in:
Miroslav Kovar 2019-11-13 19:14:43 +01:00 committed by Jack Robison
parent 7191042bb8
commit 5951186463
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
4 changed files with 13 additions and 14 deletions

View file

@ -162,7 +162,7 @@ class Node:
for address, udp_port in known_node_urls or [] for address, udp_port in known_node_urls or []
])) ]))
except socket.gaierror: except socket.gaierror:
await asyncio.sleep(30) await asyncio.sleep(30, loop=self.loop)
continue continue
self.protocol.peer_manager.reset() self.protocol.peer_manager.reset()

View file

@ -823,10 +823,7 @@ class SQLiteStorage(SQLiteMixin):
def _save_kademlia_peers(transaction: sqlite3.Connection): def _save_kademlia_peers(transaction: sqlite3.Connection):
transaction.execute('delete from peer').fetchall() transaction.execute('delete from peer').fetchall()
transaction.executemany( transaction.executemany(
'insert into peer(node_id, address, udp_port, tcp_port) values (?, ?, ?, ?)', ( 'insert into peer(node_id, address, udp_port, tcp_port) values (?, ?, ?, ?)',
tuple( tuple([(binascii.hexlify(p.node_id), p.address, p.udp_port, p.tcp_port) for p in peers])
[(binascii.hexlify(p.node_id), p.address, p.udp_port, p.tcp_port) for p in peers]
)
)
).fetchall() ).fetchall()
return await self.db.run(_save_kademlia_peers) return await self.db.run(_save_kademlia_peers)

View file

@ -31,7 +31,6 @@ class DHTIntegrationTest(AsyncioTestCase):
self.addCleanup(node.stop) self.addCleanup(node.stop)
node.protocol.rpc_timeout = .5 node.protocol.rpc_timeout = .5
node.protocol.ping_queue._default_delay = .5 node.protocol.ping_queue._default_delay = .5
node._peer_search_timeout = .5
return node return node
async def setup_network(self, size: int, start_port=40000, seed_nodes=1, external_ip='127.0.0.1'): async def setup_network(self, size: int, start_port=40000, seed_nodes=1, external_ip='127.0.0.1'):

View file

@ -88,14 +88,14 @@ class TestNodePingQueueDiscover(AsyncioTestCase):
n.stop() n.stop()
class TestTemporarilyLosingConnetction(AsyncioTestCase): class TestTemporarilyLosingConnection(AsyncioTestCase):
async def test_losing_connection(self): async def test_losing_connection(self):
loop = asyncio.get_event_loop() loop = self.loop
loop.set_debug(False) loop.set_debug(False)
peer_addresses = [ peer_addresses = [
(f'127.0.0.1', 40000+i) for i in range(10) ('127.0.0.1', 40000+i) for i in range(10)
] ]
node_ids = [constants.generate_id(i) for i in range(10)] node_ids = [constants.generate_id(i) for i in range(10)]
@ -112,17 +112,20 @@ class TestTemporarilyLosingConnetction(AsyncioTestCase):
with dht_mocks.mock_network_loop(loop, dht_network): with dht_mocks.mock_network_loop(loop, dht_network):
for i, n in enumerate(nodes): for i, n in enumerate(nodes):
await n._storage.open() await n._storage.open()
self.addCleanup(n.stop)
n.start(peer_addresses[i][0], peer_addresses[:num_seeds]) n.start(peer_addresses[i][0], peer_addresses[:num_seeds])
await asyncio.gather(*[n.joined.wait() for n in nodes])
node = nodes[-1] node = nodes[-1]
advance = dht_mocks.get_time_accelerator(loop, loop.time()) advance = dht_mocks.get_time_accelerator(loop, loop.time())
await advance(1000) await advance(500)
# Join the network, assert that at least the known peers are in RT # Join the network, assert that at least the known peers are in RT
self.assertTrue(node.joined.is_set()) self.assertTrue(node.joined.is_set())
self.assertTrue(len(node.protocol.routing_table.get_peers()) >= num_seeds) self.assertTrue(len(node.protocol.routing_table.get_peers()) >= num_seeds)
# Refresh, so that the peers are persisted # Refresh, so that the peers are persisted
self.assertFalse(len(await node._storage.get_persisted_kademlia_peers()) > num_seeds)
await advance(4000) await advance(4000)
self.assertTrue(len(await node._storage.get_persisted_kademlia_peers()) > num_seeds) self.assertTrue(len(await node._storage.get_persisted_kademlia_peers()) > num_seeds)
@ -133,14 +136,14 @@ class TestTemporarilyLosingConnetction(AsyncioTestCase):
# The peers are cleared on refresh from RT and storage # The peers are cleared on refresh from RT and storage
await advance(4000) await advance(4000)
self.assertFalse(node.protocol.routing_table.get_peers()) self.assertListEqual([], node.protocol.routing_table.get_peers())
self.assertFalse(await node._storage.get_persisted_kademlia_peers()) self.assertListEqual([], await node._storage.get_persisted_kademlia_peers())
# Reconnect some of the previously stored - node shouldn't connect # Reconnect some of the previously stored - node shouldn't connect
for peer_address, protocol in zip(peer_addresses[num_seeds+1:-2], popped_protocols[num_seeds+1:-2]): for peer_address, protocol in zip(peer_addresses[num_seeds+1:-2], popped_protocols[num_seeds+1:-2]):
dht_network[peer_address] = protocol dht_network[peer_address] = protocol
await advance(1000) await advance(1000)
self.assertEqual(0, len(node.protocol.routing_table.get_peers())) self.assertListEqual([], node.protocol.routing_table.get_peers())
# Reconnect some of the seed nodes # Reconnect some of the seed nodes
for peer_address, protocol in zip(peer_addresses[:num_seeds], popped_protocols[:num_seeds]): for peer_address, protocol in zip(peer_addresses[:num_seeds], popped_protocols[:num_seeds]):