diff --git a/jmclient/jmclient/client_protocol.py b/jmclient/jmclient/client_protocol.py index d916e37..a8e5aa8 100644 --- a/jmclient/jmclient/client_protocol.py +++ b/jmclient/jmclient/client_protocol.py @@ -246,7 +246,19 @@ class JMTakerClientProtocolFactory(protocol.ClientFactory): return JMTakerClientProtocol(self, self.taker) -def start_reactor(host, port, factory, ish=True): #pragma: no cover +def start_reactor(host, port, factory, ish=True, daemon=False): #pragma: no cover #(Cannot start the reactor in tests) + if daemon: + try: + from jmdaemon import JMDaemonServerProtocolFactory + except ImportError: + jlog.error("Cannot start daemon without jmdaemon package; " + "either install it, and restart, or, if you want " + "to run the daemon separately, edit the DAEMON " + "section of the config. Quitting.") + return + dfactory = JMDaemonServerProtocolFactory() + reactor.listenTCP(port, dfactory) + reactor.connectTCP(host, port, factory) reactor.run(installSignalHandlers=ish) diff --git a/jmclient/jmclient/configure.py b/jmclient/jmclient/configure.py index 7b6ed15..fa6e814 100644 --- a/jmclient/jmclient/configure.py +++ b/jmclient/jmclient/configure.py @@ -89,6 +89,17 @@ required_options = {'BLOCKCHAIN': ['blockchain_source', 'network'], defaultconfig = \ """ +[DAEMON] +#set to 1 to run the daemon service within this process; +#set to 0 if the daemon is run separately (using script joinmarketd.py) +no_daemon = 1 +#port on which daemon serves; note that communication still +#occurs over this port even if no_daemon = 1 +daemon_port = 27183 +#currently, running the daemon on a remote host is +#*NOT* supported, so don't change this variable +daemon_host = localhost + [BLOCKCHAIN] blockchain_source = blockr #options: blockr, bitcoin-rpc, regtest diff --git a/jmdaemon/jmdaemon/irc.py b/jmdaemon/jmdaemon/irc.py index 4a530af..3918604 100644 --- a/jmdaemon/jmdaemon/irc.py +++ b/jmdaemon/jmdaemon/irc.py @@ -56,9 +56,10 @@ class TxIRCFactory(protocol.ClientFactory): def clientConnectionLost(self, connector, reason): log.info('IRC connection lost: ' + str(reason)) if not self.wrapper.give_up: - log.info('Attempting to reconnect...') - reactor.callLater(self.wrapper.reconnect_interval, - connector.connect()) + if reactor.running: + log.info('Attempting to reconnect...') + reactor.callLater(self.wrapper.reconnect_interval, + connector.connect()) def clientConnectionFailed(self, connector, reason): log.info('IRC connection failed: ' + reason) diff --git a/scripts/sendpayment.py b/scripts/sendpayment.py index 47adec4..6813a3a 100644 --- a/scripts/sendpayment.py +++ b/scripts/sendpayment.py @@ -122,12 +122,6 @@ def main(): dest='makercount', help='how many makers to coinjoin with, default random from 4 to 6', default=random.randint(4, 6)) - parser.add_option('-p', - '--port', - type='int', - dest='daemonport', - help='port on which joinmarketd is running', - default='27183') parser.add_option('-S', '--schedule-file', type='str', @@ -316,7 +310,11 @@ def main(): order_chooser=chooseOrdersFunc, callbacks=(filter_orders_callback, None, taker_finished)) clientfactory = JMTakerClientProtocolFactory(taker) - start_reactor("localhost", options.daemonport, clientfactory) + nodaemon = jm_single().config.getint("DAEMON", "no_daemon") + daemon = True if nodaemon == 1 else False + start_reactor(jm_single().config.get("DAEMON", "daemon_host"), + jm_single().config.getint("DAEMON", "daemon_port"), + clientfactory, daemon=daemon) if __name__ == "__main__": main()