Skip to content

Commit

Permalink
Quit at startup if directory_nodes can't be parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamISZ committed Mar 28, 2022
1 parent e601dd7 commit b0e908f
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions jmdaemon/jmdaemon/onionmc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from jmdaemon.message_channel import MessageChannel
from jmdaemon.protocol import COMMAND_PREFIX, JM_VERSION
from jmbase import get_log, JM_APP_NAME, JMHiddenService
from jmbase import get_log, JM_APP_NAME, JMHiddenService, stop_reactor
import json
import copy
from typing import Callable, Union, Tuple, List
Expand Down Expand Up @@ -103,6 +103,9 @@ class OnionPeerConnectionError(OnionPeerError):
class OnionCustomMessageDecodingError(Exception):
pass

class InvalidLocationStringError(Exception):
pass

class OnionCustomMessage(object):
""" Encapsulates the messages passed over the wire
to and from other onion peers
Expand Down Expand Up @@ -367,9 +370,13 @@ def from_location_string(cls, mc: 'OnionMessageChannel',
connection information given by the network interface.
TODO: special handling for inbound is needed.
"""
host, port = location.split(":")
try:
host, port = location.split(":")
portint = int(port)
except:
raise InvalidLocationStringError(location)
return cls(mc, socks5_host, socks5_port,
(host, int(port)), directory=directory,
(host, portint), directory=directory,
handshake_callback=handshake_callback)

def set_location(self, location_string: str) -> bool:
Expand Down Expand Up @@ -547,9 +554,14 @@ def __init__(self,
self.peers = set()
for dn in configdata["directory_nodes"].split(","):
# note we don't use a nick for directories:
self.peers.add(OnionDirectoryPeer.from_location_string(
self, dn, self.socks5_host, self.socks5_port,
directory=True, handshake_callback=self.handshake_as_client))
try:
self.peers.add(OnionDirectoryPeer.from_location_string(
self, dn, self.socks5_host, self.socks5_port,
directory=True, handshake_callback=self.handshake_as_client))
except InvalidLocationStringError as e:
log.error("Failed to load directory nodes: {}".format(repr(e)))
stop_reactor()
return
# we can direct messages via the protocol factory, which
# will index protocol connections by peer location:
self.proto_factory = OnionLineProtocolFactory(self)
Expand Down

0 comments on commit b0e908f

Please sign in to comment.