update tor warning

This commit is contained in:
callebtc
2022-10-30 12:53:39 +01:00
parent 5f5774e5e0
commit ace3785b15
3 changed files with 16 additions and 11 deletions

View File

@@ -31,7 +31,8 @@ class TorProxy:
logger.debug("Starting")
self.run_daemon()
def check_platform(self):
@classmethod
def check_platform(cls):
if platform.system() == "Linux":
if platform.machine() != "x86_64":
return False
@@ -119,7 +120,7 @@ class TorProxy:
print(".", end="", flush=True)
if "Bootstrapped 100%" in str(line):
if verbose:
print("done.", flush=True)
print("done", flush=True)
break
# tor is ready
self.startup_finished = True

View File

@@ -30,6 +30,7 @@ from cashu.core.settings import (
TOR,
VERSION,
)
from cashu.tor.tor import TorProxy
from cashu.wallet import migrations
from cashu.wallet.crud import (
get_lightning_invoices,
@@ -70,6 +71,13 @@ def cli(ctx, host: str, walletname: str):
ctx.obj["HOST"] = host
ctx.obj["WALLET_NAME"] = walletname
wallet = Wallet(ctx.obj["HOST"], os.path.join(CASHU_DIR, walletname))
if TOR and not TorProxy().check_platform():
print(
"WARNING: Your settings say TOR=true but the built-in Tor bundle is not supported on your system. Your IP will be visible to the mint! Please install Tor manually and set TOR=false and SOCKS_HOST=localhost and SOCKS_PORT=9050 in your Cashu config (recommended) or turn off Tor altogether by setting TOR=false (not recommended)."
)
print("")
ctx.obj["WALLET"] = wallet
asyncio.run(init_wallet(wallet))
pass

View File

@@ -55,6 +55,7 @@ from cashu.wallet.crud import (
class LedgerAPI:
keys: Dict[int, str]
keyset: str
tor: TorProxy
def __init__(self, url):
self.url = url
@@ -63,14 +64,9 @@ class LedgerAPI:
s = requests.Session()
s.headers.update({"Client-version": VERSION})
socks_host, socks_port = None, None
if TOR:
tor = TorProxy(keep_alive=True)
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)
if TOR and TorProxy().check_platform():
self.tor = TorProxy(keep_alive=True)
self.tor.wait_until_startup(verbose=True)
socks_host, socks_port = "localhost", 9050
else:
socks_host, socks_port = SOCKS_HOST, SOCKS_PORT