From 7325911793504e5ffed0cb6f54d690af511a1dc7 Mon Sep 17 00:00:00 2001 From: eduard6 Date: Tue, 2 May 2017 21:57:35 -0400 Subject: [PATCH] Increment daemon_port and try again if listen fails Undo joinmarketd.py changes --- jmclient/jmclient/client_protocol.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/jmclient/jmclient/client_protocol.py b/jmclient/jmclient/client_protocol.py index 30219e8..86945d4 100644 --- a/jmclient/jmclient/client_protocol.py +++ b/jmclient/jmclient/client_protocol.py @@ -23,6 +23,7 @@ import string import time import hashlib import os +import sys from jmclient import (Taker, Wallet, jm_single, get_irc_mchannels, load_program_config, get_log) @@ -309,12 +310,23 @@ def start_reactor(host, port, factory, ish=True, daemon=False): #pragma: no cove "section of the config. Quitting.") return dfactory = JMDaemonServerProtocolFactory() - if usessl: - reactor.listenSSL(port, dfactory, - ssl.DefaultOpenSSLContextFactory( - "./ssl/key.pem", "./ssl/cert.pem")) - else: - reactor.listenTCP(port, dfactory) + orgport = port + while True: + try: + if usessl: + reactor.listenSSL(port, dfactory, + ssl.DefaultOpenSSLContextFactory( + "./ssl/key.pem", "./ssl/cert.pem")) + else: + reactor.listenTCP(port, dfactory) + jlog.info("Listening on port " + str(port)) + break + except Exception: + jlog.warn("Cannot listen on port " + str(port) + ", trying next port") + if port >= (orgport + 100): + jlog.error("Tried 100 ports but cannot listen on any of them. Quitting.") + sys.exit(1) + port += 1 if usessl: ctx = ClientContextFactory()