work on torgossip
This commit is contained in:
parent
630a9b1522
commit
2ffcc2e18e
@ -64,9 +64,10 @@ def client_funcs(shared_state, socket_pool):
|
|||||||
s.set_proxy(
|
s.set_proxy(
|
||||||
socket.SOCKS5, '127.0.0.1', socks_port, rdns=True)
|
socket.SOCKS5, '127.0.0.1', socks_port, rdns=True)
|
||||||
try:
|
try:
|
||||||
socket_pool[peer] = s.connect(
|
s.connect(
|
||||||
(p_encoded, 2021))
|
(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:
|
except socket.GeneralProxyError:
|
||||||
s.close()
|
s.close()
|
||||||
@ -88,6 +89,7 @@ def client_funcs(shared_state, socket_pool):
|
|||||||
SystemRandom().shuffle(peers)
|
SystemRandom().shuffle(peers)
|
||||||
try:
|
try:
|
||||||
peer = peers[0]
|
peer = peers[0]
|
||||||
|
print(peer)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
logger.error(
|
logger.error(
|
||||||
"There are no known TorGossip peers." +
|
"There are no known TorGossip peers." +
|
||||||
@ -95,7 +97,10 @@ def client_funcs(shared_state, socket_pool):
|
|||||||
terminal=True)
|
terminal=True)
|
||||||
sleep(sleep_t)
|
sleep(sleep_t)
|
||||||
continue
|
continue
|
||||||
|
try:
|
||||||
download_blocks(socket_pool[peer], 0, 'txt')
|
download_blocks(socket_pool[peer], 0, 'txt')
|
||||||
|
except BrokenPipeError:
|
||||||
|
del socket_pool[peer]
|
||||||
|
|
||||||
_client_pool(shared_state, socket_pool)
|
_client_pool(shared_state, socket_pool)
|
||||||
client_loop(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"
|
bootstap_peers = path.dirname(path.realpath(__file__)) + "/bootstrap.txt"
|
||||||
with open(bootstap_peers, 'r') as bs_peers:
|
with open(bootstap_peers, 'r') as bs_peers:
|
||||||
peers = bs_peers.read().split(',')
|
peers = bs_peers.read().split(',')
|
||||||
|
try:
|
||||||
peers.remove(our_host)
|
peers.remove(our_host)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
for peer in peers:
|
for peer in peers:
|
||||||
try:
|
try:
|
||||||
peer_db.db.get(peer)
|
peer_db.db.get(peer)
|
||||||
|
@ -14,17 +14,15 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
def download_blocks(sock: 'socket', offset: int, block_type: str):
|
def download_blocks(sock: 'socket', offset: int, block_type: str):
|
||||||
sock.sendall(
|
sock.sendall(
|
||||||
int(GossipCommands.LIST_BLOCKS_BY_TYPE_OFFSET).to_bytes(
|
str(int(GossipCommands.LIST_BLOCKS_BY_TYPE_OFFSET)).encode('utf-8') + str(offset).encode('utf-8') + b',' +
|
||||||
1, 'little') + str(offset).encode('utf-8') +
|
|
||||||
block_type.encode('utf-8'))
|
block_type.encode('utf-8'))
|
||||||
bl_hashs = sock.recv(600000)
|
bl_hashs = sock.recv(600000)
|
||||||
hash = None
|
hash = None
|
||||||
for i in range(len(bl_hashs)//64):
|
for i in range(len(bl_hashs)//64):
|
||||||
hash = bl[:(i*64) + 64]
|
hash = bl_hashs[:(i*64) + 64]
|
||||||
sock.sendall(
|
sock.sendall(
|
||||||
int(GossipCommands.GET_BLOCK).to_bytes(
|
str(int(GossipCommands.GET_BLOCK)).encode('utf-8') + hash)
|
||||||
1, 'little') + hash)
|
|
||||||
bl_content = sock.recv(10**6)
|
bl_content = sock.recv(10**6)
|
||||||
print(bl_content)
|
print('got block', bl_content)
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ def start_server(shared_state):
|
|||||||
|
|
||||||
def read(conn, mask):
|
def read(conn, mask):
|
||||||
data = conn.recv(1000) # Should be ready
|
data = conn.recv(1000) # Should be ready
|
||||||
|
print('recd', data)
|
||||||
cmd = None
|
cmd = None
|
||||||
if data:
|
if data:
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user