joinmarket/scripts/joinmarketd.py
AdamISZ 0c967bca7d
Support payjoin when daemon run separately (joinmarketd)
Prior to this commit, running joinmarketd as an isolated
process only supported serving the Joinmarket protocol;
attempting PayJoin would result in silent failure as the
receiver would reject the !pubkey message.
After this commit, the joinmarketd daemon serves both
protocols with the PayJoin protocol being served at port+1
2019-01-20 15:56:45 +01:00

44 lines
1.5 KiB
Python

from __future__ import (absolute_import, division,
print_function, unicode_literals)
from builtins import * # noqa: F401
import sys
from twisted.internet import reactor
from twisted.python.log import startLogging
import jmdaemon
def startup_joinmarketd(host, port, usessl, factories=None,
finalizer=None, finalizer_args=None):
"""Start event loop for joinmarket daemon here.
Args:
port : port over which to serve the daemon
finalizer: a function which is called after the reactor has shut down.
finalizer_args : arguments to finalizer function.
"""
startLogging(sys.stdout)
if not factories:
factories = [jmdaemon.JMDaemonServerProtocolFactory(),
jmdaemon.P2EPDaemonServerProtocolFactory()]
for factory in factories:
jmdaemon.start_daemon(host, port, factory, usessl,
'./ssl/key.pem', './ssl/cert.pem')
port += 1
if finalizer:
reactor.addSystemEventTrigger("after", "shutdown", finalizer,
finalizer_args)
reactor.run()
if __name__ == "__main__":
if len(sys.argv) < 2:
port = 27183
else:
port = int(sys.argv[1])
usessl = False
if len(sys.argv) > 2:
if int(sys.argv[2]) != 0:
usessl = True
if len(sys.argv) > 3:
host = sys.argv[3]
else:
host = 'localhost'
startup_joinmarketd(host, port, usessl)