def main_server(options, wallet, test_data=None):
"""The use_ssl option is only for tests, and flags that case.
"""
if test_data and not test_data['use_ssl']:
cs_single().config.set("SERVER", "use_ssl", "false")
cs_single().bc_interface.start_unspent_monitoring(wallet)
#to allow testing of confirm/unconfirm callback for multiple txs
if isinstance(cs_single().bc_interface, RegtestBitcoinCoreInterface):
cs_single().bc_interface.tick_forward_chain_interval = 2
cs_single().bc_interface.simulating = True
cs_single().config.set("BLOCKCHAIN", "notify_port", "62652")
cs_single().config.set("BLOCKCHAIN", "rpc_host", "127.0.0.2")
#if restart option selected, read state and backout
#(TODO is to attempt restarting normally before backing out)
if options.recover:
session_id = options.recover
carol = CoinSwapCarol(wallet, 'carolstate')
carol.bbmb = wallet.get_balance_by_mixdepth(verbose=False)
carol.load(sessionid=session_id)
carol.backout("Recovering from shutdown")
reactor.run()
return
#TODO currently ignores server setting here and uses localhost
port = cs_single().config.getint("SERVER", "port")
testing_mode = True if test_data else False
carol_class = test_data['alt_c_class'] if test_data and \
test_data['alt_c_class'] else CoinSwapCarol
fcs = test_data["fail_carol_state"] if test_data else None
#Hidden service has first priority
if cs_single().config.get("SERVER", "use_onion") != "false":
s = server.Site(CoinSwapCarolJSONServer(wallet,
testing_mode=testing_mode,
carol_class=carol_class,
fail_carol_state=fcs))
hiddenservice_dir = os.path.join(cs_single().homedir, "hiddenservice")
if not os.path.exists(hiddenservice_dir):
os.makedirs(hiddenservice_dir)
if 'hs_dir' in cs_single().config.options('SERVER'):
hiddenservice_dir = cs_single().config.get("SERVER", "hs_dir")
d = start_tor(s, cs_single().config.getint("SERVER", "onion_port"),
hiddenservice_dir)
#Any callbacks after Tor is inited can be added here with d.addCallback
elif cs_single().config.get("SERVER", "use_ssl") != "false":
reactor.listenSSL(int(port), server.Site(CoinSwapCarolJSONServer(wallet,
testing_mode=testing_mode, carol_class=carol_class,
fail_carol_state=fcs)), contextFactory = get_ssl_context())
else:
cslog.info("WARNING! Serving over HTTP, no TLS used!")
reactor.listenTCP(int(port), server.Site(CoinSwapCarolJSONServer(wallet,
testing_mode=testing_mode,
carol_class=carol_class,
fail_carol_state=fcs)))
if not test_data:
reactor.run()
评论列表
文章目录