Compare commits
No commits in common. "5337b0aba48377a8d7882f7f32afc42e6fbc0c48" and "8d394c76a7127f59ea053429badb8227c6bba280" have entirely different histories.
5337b0aba4
...
8d394c76a7
@ -11,7 +11,6 @@ if TYPE_CHECKING:
|
||||
from onionrthreads import add_onionr_thread
|
||||
import onionrplugins
|
||||
|
||||
from .connectpeer import connect_peer
|
||||
from .client import gossip_client
|
||||
from .server import gossip_server
|
||||
from .commands import GossipCommands
|
||||
@ -47,5 +46,5 @@ def start_gossip_threads(
|
||||
add_onionr_thread(
|
||||
gossip_client, 1, peer_set, block_queue, seed, initial_sleep=0)
|
||||
onionrplugins.events.event('gossip_start', data=peer_set, threaded=True)
|
||||
onionrplugins.events.event(
|
||||
'bootstrap', data={'peer_set': peer_set, 'callback': connect_peer})
|
||||
sleep(4)
|
||||
onionrplugins.events.event('bootstrap', data=peer_set)
|
||||
|
@ -20,7 +20,7 @@ from gossip.phase import DandelionPhase
|
||||
from onionrthreads import add_onionr_thread
|
||||
|
||||
from .announce import do_announce
|
||||
#from .peerexchange import get_new_peers
|
||||
from .peerexchange import get_new_peers
|
||||
"""
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@ -54,11 +54,9 @@ def gossip_client(
|
||||
data={'peers': peer_set, 'new_peers': new_peer_set})
|
||||
|
||||
add_onionr_thread(do_announce, 3600, peer_set, initial_sleep=10)
|
||||
"""
|
||||
add_onionr_thread(
|
||||
get_new_peers,
|
||||
1200, peer_set, _trigger_new_peers_event, initial_sleep=5)
|
||||
"""
|
||||
|
||||
|
||||
dandelion_phase = DandelionPhase(dandelion_seed, 30)
|
||||
|
@ -1,11 +0,0 @@
|
||||
import logger
|
||||
|
||||
|
||||
def connect_peer(peer_set, peer):
|
||||
try:
|
||||
peer.get_socket()
|
||||
except Exception:
|
||||
logger.warn(f"Could not connect to {peer.transport_address}")
|
||||
else:
|
||||
peer_set.add(peer)
|
||||
logger.info(f"connected to {peer.transport_address}")
|
@ -4,7 +4,10 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
class Peer(Protocol):
|
||||
transport_address = ""
|
||||
stats = {}
|
||||
sock = None
|
||||
id = ""
|
||||
node_address = ""
|
||||
|
||||
def __init__(self):
|
||||
return
|
||||
@ -13,10 +16,3 @@ class Peer(Protocol):
|
||||
|
||||
def disconnect(self):
|
||||
return
|
||||
|
||||
def __eq__(self, other):
|
||||
return
|
||||
|
||||
def __hash__(self):
|
||||
"""Use the transport address"""
|
||||
return
|
@ -3,7 +3,6 @@ from typing import TYPE_CHECKING
|
||||
from typing import Set
|
||||
|
||||
from queue import Queue
|
||||
from .connectpeer import connect_peer
|
||||
|
||||
from onionrplugins import onionrevents
|
||||
|
||||
@ -54,10 +53,8 @@ def gossip_server(
|
||||
address = await reader.read(56)
|
||||
onionrevents.event(
|
||||
'announce_rec',
|
||||
data={'peer_set': peer_set,
|
||||
'address': address,
|
||||
'callback': connect_peer},
|
||||
threaded=True)
|
||||
data={'peer_set': peer_set, 'address': address},
|
||||
threaded=False)
|
||||
writer.write(int(1).to_bytes(1, 'big'))
|
||||
await asyncio.wait_for(_read_announce(), 10)
|
||||
|
||||
|
@ -1,25 +0,0 @@
|
||||
import config
|
||||
import logger
|
||||
|
||||
from getsocks import get_socks
|
||||
from torpeer import TorPeer
|
||||
|
||||
|
||||
def on_announce_rec(api, data=None):
|
||||
socks_address, socks_port = get_socks()[0]
|
||||
|
||||
announced = data['address']
|
||||
try:
|
||||
announced = announced.decode('utf-8')
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
if announced == config.get('tor.transport_address'):
|
||||
logger.warn("Recieved announcement for our own node, which shouldnt happen")
|
||||
return
|
||||
|
||||
announced += '.onion'
|
||||
|
||||
data['callback'](
|
||||
data['peer_set'],
|
||||
TorPeer(socks_address, socks_port, announced))
|
@ -1,44 +0,0 @@
|
||||
from threading import Thread
|
||||
from time import sleep
|
||||
import os
|
||||
|
||||
from gossip.peer import Peer
|
||||
import logger
|
||||
import config
|
||||
from getsocks import get_socks
|
||||
|
||||
from torpeer import TorPeer
|
||||
from torfilepaths import control_socket
|
||||
|
||||
bootstrap_file = f'{os.path.dirname(os.path.realpath(__file__))}/bootstrap.txt'
|
||||
|
||||
def on_bootstrap(api, data):
|
||||
|
||||
try:
|
||||
with open(bootstrap_file, 'r') as bootstrap_file_obj:
|
||||
bootstrap_nodes = set(bootstrap_file_obj.read().split(','))
|
||||
except FileNotFoundError:
|
||||
bootstrap_nodes = set()
|
||||
|
||||
while not os.path.exists(control_socket):
|
||||
sleep(0.1)
|
||||
|
||||
while not config.get('tor.transport_address'):
|
||||
sleep(1)
|
||||
config.reload()
|
||||
|
||||
socks_address, socks_port = get_socks()[0]
|
||||
|
||||
for address in bootstrap_nodes:
|
||||
if address == config.get('tor.transport_address'):
|
||||
continue
|
||||
if not address.endswith('.onion'):
|
||||
address += '.onion'
|
||||
# Tell the gossip logic that this peer is ready to connect
|
||||
# it will add it to data['peer_set'] if it responds to ping
|
||||
Thread(
|
||||
target=data['callback'],
|
||||
args=[data['peer_set'], TorPeer(socks_address, socks_port, address)],
|
||||
daemon=True).start()
|
||||
|
||||
|
@ -28,9 +28,7 @@ sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||
import starttor
|
||||
from torpeer import TorPeer
|
||||
from torfilepaths import control_socket
|
||||
|
||||
from bootstrap import on_bootstrap
|
||||
from announce import on_announce_rec
|
||||
from getsocks import get_socks
|
||||
|
||||
"""
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
@ -52,6 +50,9 @@ plugin_name = 'tor'
|
||||
PLUGIN_VERSION = '0.0.0'
|
||||
|
||||
|
||||
bootstrap_file = f'{os.path.dirname(os.path.realpath(__file__))}/bootstrap.txt'
|
||||
|
||||
|
||||
class OnionrTor:
|
||||
def __init__(self):
|
||||
return
|
||||
@ -69,6 +70,47 @@ def on_get_our_transport(api, data=None):
|
||||
callback_func(for_peer, config.get('tor.transport_address'))
|
||||
|
||||
|
||||
def on_announce_rec(api, data=None):
|
||||
print("got announce rec event")
|
||||
|
||||
|
||||
def on_bootstrap(api, data: Set[Peer] = None):
|
||||
bootstrap_nodes: Set[str]
|
||||
peers = data
|
||||
|
||||
try:
|
||||
with open(bootstrap_file, 'r') as bootstrap_file_obj:
|
||||
bootstrap_nodes = set(bootstrap_file_obj.read().split(','))
|
||||
except FileNotFoundError:
|
||||
bootstrap_nodes = set()
|
||||
|
||||
while not os.path.exists(control_socket):
|
||||
sleep(0.1)
|
||||
|
||||
socks_address, socks_port = get_socks()[0]
|
||||
sleep(5)
|
||||
|
||||
for transport_address in bootstrap_nodes:
|
||||
config.reload()
|
||||
if config.get('tor.transport_address') == transport_address:
|
||||
# ignore if its our own
|
||||
continue
|
||||
if not transport_address.endswith('.onion'):
|
||||
transport_address += '.onion'
|
||||
tor_peer = TorPeer(socks_address, socks_port, transport_address)
|
||||
try:
|
||||
tor_peer.get_socket()
|
||||
except Exception:
|
||||
logger.warn(
|
||||
f"Could not connnect to Tor peer {transport_address} " +
|
||||
"see logs for more info",
|
||||
terminal=True)
|
||||
logger.warn(traceback.format_exc())
|
||||
continue
|
||||
peers.add(tor_peer)
|
||||
logger.info(f"Connected to {len(peers)} Tor peers", terminal=True)
|
||||
|
||||
|
||||
def on_gossip_start(api, data: Set[Peer] = None):
|
||||
# We don't do gossip logic
|
||||
|
||||
|
@ -13,12 +13,3 @@ class TorPeer:
|
||||
s.set_proxy(socks.SOCKS4, self.socks_host, self.socks_port, rdns=True)
|
||||
s.connect((self.onion_address, 80))
|
||||
return s
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.transport_address)
|
||||
|
||||
def __eq__(self, other):
|
||||
try:
|
||||
return self.transport_address == other.transport_address
|
||||
except AttributeError:
|
||||
return False
|
||||
|
Loading…
Reference in New Issue
Block a user