This commit is contained in:
callebtc
2022-10-30 01:10:20 +02:00
parent 45bd624555
commit 5ef4165937
2 changed files with 18 additions and 2 deletions

View File

@@ -31,7 +31,15 @@ class TorProxy:
logger.debug("Starting")
self.run_daemon()
def check_platform(self):
if platform.system() == "Linux":
if platform.machine() != "x86_64":
return False
return True
def run_daemon(self):
if not self.check_platform():
return
cmd = [
f"{self.tor_path()}",
"--defaults-torrc",
@@ -92,6 +100,8 @@ class TorProxy:
return self.tor_proc and self.tor_proc.poll() is None
def wait_until_startup(self, verbose=False):
if not self.check_platform():
return
if self.is_port_open():
return
if self.tor_proc is None:

View File

@@ -62,10 +62,16 @@ class LedgerAPI:
def _set_requests(self):
s = requests.Session()
s.headers.update({"Client-version": VERSION})
socks_host, socks_port = None, None
if TOR:
tor = TorProxy(keep_alive=True)
tor.wait_until_startup(verbose=True)
socks_host, socks_port = "localhost", 9050
if not tor.check_platform():
print(
"WARNING: The built-in Tor bundle is not supported on your System. Please install Tor and set the SOCKS_HOST and SOCKS_PORT variables in your Cashu configuration .env file (recommended) or turn off tor by setting TOR=false (not recommended)."
)
else:
tor.wait_until_startup(verbose=True)
socks_host, socks_port = "localhost", 9050
else:
socks_host, socks_port = SOCKS_HOST, SOCKS_PORT