Compare commits

...

3 Commits

Author SHA1 Message Date
Kevin F
6b6d357a13 Small gossip fixes 2022-06-14 11:01:07 -05:00
Kevin F
ac88e0a1da Stem out even if we only have 1 peer 2022-06-14 11:00:08 -05:00
Kevin F
cdccde2d9d Don't write python bytecode 2022-06-14 10:55:38 -05:00
7 changed files with 15 additions and 11 deletions

View File

@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
ORIG_ONIONR_RUN_DIR=`pwd` ORIG_ONIONR_RUN_DIR=`pwd`
export ORIG_ONIONR_RUN_DIR export ORIG_ONIONR_RUN_DIR
export PYTHONDONTWRITEBYTECODE=1
cd "$(dirname "$0")" cd "$(dirname "$0")"
cd src cd src
./__init__.py "$@" ./__init__.py "$@"

View File

@ -8,7 +8,6 @@ app_root = os.path.dirname(os.path.realpath(__file__)) + '/../../'
gossip_server_socket_file = home + 'gossip-server.sock' gossip_server_socket_file = home + 'gossip-server.sock'
usage_file = home + 'disk-usage.txt' usage_file = home + 'disk-usage.txt'
block_data_location = home + 'blocks/'
contacts_location = home + 'contacts/' contacts_location = home + 'contacts/'
public_API_host_file = home + 'public-host.txt' public_API_host_file = home + 'public-host.txt'
private_API_host_file = home + 'private-host.txt' private_API_host_file = home + 'private-host.txt'

View File

@ -81,6 +81,7 @@ async def stem_out(d_phase: 'DandelionPhase'):
if not len(gossip_peer_set): if not len(gossip_peer_set):
sleep(1) sleep(1)
return return
not_enough_edges = False
# Spawn threads with deep copied block queue to add to db after time # Spawn threads with deep copied block queue to add to db after time
# for black hole attack # for black hole attack
@ -96,15 +97,17 @@ async def stem_out(d_phase: 'DandelionPhase'):
# Using orderedset for the tried edges to ensure random pairing with queue # Using orderedset for the tried edges to ensure random pairing with queue
tried_edges: "OrderedSet[Peer]" = OrderedSet() tried_edges: "OrderedSet[Peer]" = OrderedSet()
while len(peer_sockets) < OUTBOUND_DANDELION_EDGES: while len(peer_sockets) < OUTBOUND_DANDELION_EDGES or not_enough_edges:
try: try:
# Get a socket for stem out (makes sure they accept) # Get a socket for stem out (makes sure they accept)
peer_sockets.append(await _setup_edge(gossip_peer_set, tried_edges)) peer_sockets.append(await _setup_edge(gossip_peer_set, tried_edges))
except NotEnoughEdges: except NotEnoughEdges:
# No possible edges at this point (edges < OUTBOUND_DANDELION_EDGE) # No possible edges at this point (edges < OUTBOUND_DANDELION_EDGE)
logger.warn("Not able to build enough tunnels for stemout.", logger.warn(
terminal=True) "Making too few edges for stemout " +
break "this is bad for anonymity if frequent."
terminal=True)
not_enough_edges = True
else: else:
# Ran out of time for stem phase # Ran out of time for stem phase
if not d_phase.is_stem_phase() or d_phase.remaining_time() < 5: if not d_phase.is_stem_phase() or d_phase.remaining_time() < 5:

View File

@ -33,7 +33,7 @@ def store_blocks(dandelion_phase: 'DandelionPhase'):
and dandelion_phase.remaining_time() > 1: and dandelion_phase.remaining_time() > 1:
try: try:
blockdb.add_block_to_db( blockdb.add_block_to_db(
new_queue.get(timeout=dandelion_phase.remaining_time()) new_queue.get(timeout=dandelion_phase.remaining_time() + 1)
) )
except Empty: except Empty:
pass pass

View File

@ -31,7 +31,7 @@ def create_dirs():
"""Create onionr data-related directories in """Create onionr data-related directories in
order of the hardcoded list below, order of the hardcoded list below,
then trigger creation of DBs""" then trigger creation of DBs"""
gen_dirs = [home, filepaths.block_data_location, gen_dirs = [home,
filepaths.contacts_location, filepaths.contacts_location,
filepaths.export_location] filepaths.export_location]
for path in gen_dirs: for path in gen_dirs:

View File

@ -8,18 +8,19 @@ from torpeer import TorPeer
def on_announce_rec(api, data=None): def on_announce_rec(api, data=None):
socks_address, socks_port = get_socks()[0] socks_address, socks_port = get_socks()[0]
announced = data['address'] announced: str = data['address']
try: try:
announced = announced.decode('utf-8') announced = announced.decode('utf-8')
except AttributeError: except AttributeError:
pass pass
announced = announced.strip()
if announced == config.get('tor.transport_address'): if announced.removesuffix('.onion') == config.get(
'tor.transport_address', '').removesuffix('.onion'):
logger.warn( logger.warn(
"Received announcement for our own node, which shouldn't happen") "Received announcement for our own node, which shouldn't happen")
return return
announced = announced.strip()
if not announced.endswith('.onion'): if not announced.endswith('.onion'):
announced += '.onion' announced += '.onion'

View File

@ -71,7 +71,7 @@ class OnionrGossipClientGetNewPeers(unittest.TestCase):
def test_get_new_peers_no_peers(self): def test_get_new_peers_no_peers(self):
gossip_peer_set.clear() gossip_peer_set.clear()
self.assertRaises(ValueError, get_new_peers) get_new_peers()
self.assertFalse(len(gossip_peer_set)) self.assertFalse(len(gossip_peer_set))