Browse Source

started get new peers test

newtransport
Kevin F 2 weeks ago
parent
commit
2be0175326
  1. 8
      src/gossip/client/__init__.py
  2. 4
      src/gossip/client/peerexchange.py
  3. 10
      tests/gossip-unittests/test_client_get_new_peers.py

8
src/gossip/client/__init__.py

@ -94,13 +94,19 @@ def start_gossip_client(): @@ -94,13 +94,19 @@ def start_gossip_client():
# transport plugin handles the new peer
add_onionr_thread(
get_new_peers,
120, initial_sleep=5)
60, initial_sleep=120)
# Start a new thread to stream blocks from peers
# These blocks are being diffused and are stored in
# the peer's block database
add_onionr_thread(
stream_from_peers,
3, initial_sleep=10
)
# Blocks we receive or create through all means except
# Diffusal are put into block queues, we decide to either
# stem or diffuse a block from the queue based on the current
# dandelion++ phase
while True:
block_queue_processing()

4
src/gossip/client/peerexchange.py

@ -36,8 +36,8 @@ def _ask_peer(peer): @@ -36,8 +36,8 @@ def _ask_peer(peer):
def get_new_peers():
while not len(gossip_peer_set):
sleep(0.5)
if not len(gossip_peer_set):
raise ValueError("Peer set empty")
# Deep copy the peer list
peer_list: Peer = list(gossip_peer_set)

10
tests/gossip-unittests/test_client_get_new_peers.py

@ -23,8 +23,7 @@ import onionrblocks @@ -23,8 +23,7 @@ import onionrblocks
from filepaths import gossip_server_socket_file
from gossip.client import block_queue_processing
from gossip import client
from gossip.blockqueues import gossip_block_queues
from gossip.client import get_new_peers
from gossip.peerset import gossip_peer_set
@ -53,9 +52,14 @@ class MockPeer: @@ -53,9 +52,14 @@ class MockPeer:
class OnionrGossipClientGetNewPeers(unittest.TestCase):
def test_get_new_peers_no_peers(self):
gossip_peer_set.clear()
self.assertRaises(ValueError, get_new_peers)
def test_get_new_peers(self):
return
p = MockPeer()
gossip_peer_set.add(p)
get_new_peers()
unittest.main()

Loading…
Cancel
Save