vpn: require an active WireGuard handshake before downloading (refuse a dead tunnel)
This commit is contained in:
+10
-1
@@ -11,6 +11,7 @@ from pathlib import Path
|
||||
from . import __version__, vpn
|
||||
from .config import Config, QUALITY_PRESETS, default_config_path, load_config, write_default_config
|
||||
from .downloader import cookie_opts, download_video
|
||||
from .progress import DownloadProgress
|
||||
|
||||
|
||||
def log_setup(verbose: bool) -> None:
|
||||
@@ -74,7 +75,8 @@ def cmd_download(args: argparse.Namespace) -> int:
|
||||
extra = cookie_opts(cfg)
|
||||
|
||||
print(f"downloading: {args.url} (quality={quality}, out={out_dir.expanduser()})")
|
||||
path = download_video(args.url, out_dir, quality, format_override, extra)
|
||||
bar = DownloadProgress()
|
||||
path = download_video(args.url, out_dir, quality, format_override, extra, progress=bar)
|
||||
if not path:
|
||||
logging.error("download failed: %s", args.url)
|
||||
return 1
|
||||
@@ -91,6 +93,13 @@ def cmd_vpn(args: argparse.Namespace) -> int:
|
||||
else:
|
||||
vpn.up(cfg)
|
||||
print("tunnel up")
|
||||
if not vpn.wait_for_handshake(cfg):
|
||||
logging.error(
|
||||
"tunnel is up but no WireGuard handshake was established — "
|
||||
"downloads will be refused until the tunnel is active"
|
||||
)
|
||||
return 1
|
||||
print("handshake established")
|
||||
elif args.vpn_command == "down":
|
||||
vpn.down(cfg)
|
||||
print("tunnel down")
|
||||
|
||||
Reference in New Issue
Block a user