work on torgossip

This commit is contained in:
Kevin Froman 2021-02-15 09:11:16 +00:00
parent 630a9b1522
commit 2ffcc2e18e
3 changed files with 17 additions and 10 deletions

View File

@ -64,9 +64,10 @@ def client_funcs(shared_state, socket_pool):
s.set_proxy(
socket.SOCKS5, '127.0.0.1', socks_port, rdns=True)
try:
socket_pool[peer] = s.connect(
s.connect(
(p_encoded, 2021))
logger.info(f"Connected to {p_encoded}", terminal=True)
socket_pool[peer] = s
logger.info(f"[TorGossip] Connected to {p_encoded}", terminal=True)
except socket.GeneralProxyError:
s.close()
@ -88,6 +89,7 @@ def client_funcs(shared_state, socket_pool):
SystemRandom().shuffle(peers)
try:
peer = peers[0]
print(peer)
except IndexError:
logger.error(
"There are no known TorGossip peers." +
@ -95,7 +97,10 @@ def client_funcs(shared_state, socket_pool):
terminal=True)
sleep(sleep_t)
continue
download_blocks(socket_pool[peer], 0, 'txt')
try:
download_blocks(socket_pool[peer], 0, 'txt')
except BrokenPipeError:
del socket_pool[peer]
_client_pool(shared_state, socket_pool)
client_loop(shared_state, socket_pool)
@ -110,7 +115,10 @@ def _add_bootstrap_peers(peer_db: 'TorGossipPeers'):
bootstap_peers = path.dirname(path.realpath(__file__)) + "/bootstrap.txt"
with open(bootstap_peers, 'r') as bs_peers:
peers = bs_peers.read().split(',')
peers.remove(our_host)
try:
peers.remove(our_host)
except ValueError:
pass
for peer in peers:
try:
peer_db.db.get(peer)

View File

@ -14,17 +14,15 @@ if TYPE_CHECKING:
def download_blocks(sock: 'socket', offset: int, block_type: str):
sock.sendall(
int(GossipCommands.LIST_BLOCKS_BY_TYPE_OFFSET).to_bytes(
1, 'little') + str(offset).encode('utf-8') +
str(int(GossipCommands.LIST_BLOCKS_BY_TYPE_OFFSET)).encode('utf-8') + str(offset).encode('utf-8') + b',' +
block_type.encode('utf-8'))
bl_hashs = sock.recv(600000)
hash = None
for i in range(len(bl_hashs)//64):
hash = bl[:(i*64) + 64]
hash = bl_hashs[:(i*64) + 64]
sock.sendall(
int(GossipCommands.GET_BLOCK).to_bytes(
1, 'little') + hash)
str(int(GossipCommands.GET_BLOCK)).encode('utf-8') + hash)
bl_content = sock.recv(10**6)
print(bl_content)
print('got block', bl_content)

View File

@ -58,6 +58,7 @@ def start_server(shared_state):
def read(conn, mask):
data = conn.recv(1000) # Should be ready
print('recd', data)
cmd = None
if data:
try: