SatSale

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 31033e7c332085556154021bd6d47e10ae391795
parent 879fb4d85fb581b328d5441ce074040bf82b7aa6
Author: NicholasFarrow <nicholas.w.farrow@gmail.com>
Date:   Thu,  4 Feb 2021 23:18:27 +1100

Handle concurrent lnd and btcd tunnels

Diffstat:
Mssh_tunnel.py | 51++++++++++++++++++++++++++++++++-------------------
1 file changed, 32 insertions(+), 19 deletions(-)

diff --git a/ssh_tunnel.py b/ssh_tunnel.py @@ -4,30 +4,43 @@ import config import invoice from pay import bitcoind +def open_tunnel(host, port): + # If tunnel is required (might make things easier) + try: + if host is not None: + command = [ + "ssh", + config.tunnel_host, + "-q", + "-N", + "-L", + "{}:localhost:{}".format(port, port), + ] + print("Opening tunnel to {}.".format(" ".join(command))) + tunnel_proc = subprocess.Popen(command) + return tunnel_proc -# If tunnel is required (might make things easier) -try: - if config.tunnel_host is not None: - command = [ - "ssh", - config.tunnel_host, - "-q", - "-N", - "-L", - "{}:localhost:{}".format(config.rpcport, config.rpcport), - ] - print("Opening tunnel to {}.".format(" ".join(command))) - tunnel_proc = subprocess.Popen(command) - else: + else: + tunnel_proc = None + except Exception as e: + print("FAILED TO OPEN TUNNEL. Exception: {}".format(e)) tunnel_proc = None -except Exception as e: - print("FAILED TO OPEN TUNNEL. Exception: {}".format(e)) - tunnel_proc = None - pass - + pass + return def close_tunnel(): if tunnel_proc is not None: tunnel_proc.kill() print("Tunnel closed.") return + +# Open tunnel +if config.tunnel_host is not None: + tunnel_proc = open_tunnel(config.tunnel_host, config.rpcport) + + # Also for lnd if enabled + if 'lnd_rpcport' in config.__dict__.keys(): + open_tunnel(config.tunnel_host, config.lnd_rpcport) + +else: + tunnel_proc = None