implemented peer announce in torgossip

This commit is contained in:
Kevin Froman 2021-02-05 04:57:35 +00:00
parent 227472d4dc
commit bae7f745ee

View File

@ -72,7 +72,8 @@ def torgossip_runtest(test_manager):
assert s.recv(64) == bl_new.get_packed() assert s.recv(64) == bl_new.get_packed()
s.sendall(b'40,tbt') s.sendall(b'40,tbt')
assert len(s.recv(100000)) == len(shared_state.get_by_string("SafeDB").get('bl-tbt')) assert len(s.recv(100000)) == len(
shared_state.get_by_string("SafeDB").get('bl-tbt'))
s.sendall(b'41,tbt') s.sendall(b'41,tbt')
assert len(s.recv(100000)) == len( assert len(s.recv(100000)) == len(
@ -86,10 +87,11 @@ def torgossip_runtest(test_manager):
fakes.append(fake) fakes.append(fake)
shared_state.get_by_string('TorGossipPeers').add_peer(fake) shared_state.get_by_string('TorGossipPeers').add_peer(fake)
shared_state.get_by_string('TorGossipPeers').add_peer(fake_peer) shared_state.get_by_string('TorGossipPeers').add_peer(fake_peer)
shared_state.get_by_string('TorGossipPeers').add_score(fake_peer, 100000) shared_state.get_by_string(
'TorGossipPeers').add_score(fake_peer, 100000)
s.sendall(b'71') s.sendall(b'71')
stored = s.recv(1000) stored = s.recv(1000)
expected = _shrink_peer_address(fake_peer)#b32decode(fake_peer.replace('.onion', '')).replace(b'.onion', b'') expected = _shrink_peer_address(fake_peer)
try: try:
assert stored == expected assert stored == expected
except AssertionError: except AssertionError:
@ -102,11 +104,12 @@ def torgossip_runtest(test_manager):
announce_raw = _shrink_peer_address(announce_peer) announce_raw = _shrink_peer_address(announce_peer)
s.sendall(b'8' + announce_raw) s.sendall(b'8' + announce_raw)
assert s.recv(1) == b'1' assert s.recv(1) == b'1'
print(type(announce_raw), type(shared_state.get_by_string('TorGossipPeers').get_highest_score_peers(100)[0][0])) print(type(announce_raw), type(shared_state.get_by_string(
assert announce_raw == shared_state.get_by_string('TorGossipPeers').get_highest_score_peers(100)[0][0] 'TorGossipPeers').get_highest_score_peers(100)[0][0]))
assert announce_raw == shared_state.get_by_string(
'TorGossipPeers').get_highest_score_peers(100)[0][0]
shared_state.get_by_string('TorGossipPeers').remove_peer(announce_raw) shared_state.get_by_string('TorGossipPeers').remove_peer(announce_raw)
s.sendall(b'9') s.sendall(b'9')
assert s.recv(64) == b"BYE" assert s.recv(64) == b"BYE"