diff --git a/jmdaemon/jmdaemon/onionmc.py b/jmdaemon/jmdaemon/onionmc.py index 776da9163..9d743eb31 100644 --- a/jmdaemon/jmdaemon/onionmc.py +++ b/jmdaemon/jmdaemon/onionmc.py @@ -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 @@ -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 @@ -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: @@ -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)