mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-08 05:23:41 +08:00
a82935f326
Integrate onroad views, configurable widgets, local settings, steering-profile contracts, Bluetooth and Android Auto with their device and runtime services. Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Daniel Koepping <elkoled@gmail.com> Co-authored-by: Danny <dannyirwin31@yahoo.com> Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com> Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com> Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com> Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu> Co-authored-by: Shane Smiskol <shane@smiskol.com> Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com> Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com> Co-authored-by: stef <19478336+stefpi@users.noreply.github.com> Co-authored-by: whoisdomi <dcantu83@gmail.com> Co-authored-by: Intelli <contact@intelli.software> Co-authored-by: pharmacomaniac <blittle65@gmail.com> Co-authored-by: prabhaavp <prabhaav@msu.edu>
61 lines
2.2 KiB
Python
61 lines
2.2 KiB
Python
"""Supervise the original Galaxy FRPC route only while a private pairing exists."""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
import threading
|
|
|
|
from openpilot.starpilot.galaxy.remote import RemotePairing
|
|
from openpilot.starpilot.galaxy.frpc_asset import bundled_frpc_path
|
|
|
|
|
|
def frpc_binary() -> str | None:
|
|
override = os.environ.get('STARPILOT_FRPC_BIN')
|
|
if override:
|
|
return override if Path(override).is_file() and os.access(override, os.X_OK) else None
|
|
return bundled_frpc_path() or shutil.which('frpc')
|
|
|
|
|
|
def supervise_tunnel(stop: threading.Event, pairing: RemotePairing, *, remote_port: int = 8084, auth_port: int = 8083) -> None:
|
|
process = None
|
|
active_slug = None
|
|
config_path = None
|
|
try:
|
|
while not stop.wait(1):
|
|
record = pairing.read()
|
|
slug = record['slug'] if record else None
|
|
if process is not None and (slug != active_slug or process.poll() is not None):
|
|
if process.poll() is None:
|
|
process.terminate()
|
|
try:
|
|
process.wait(timeout=5)
|
|
except subprocess.TimeoutExpired:
|
|
process.kill()
|
|
process.wait(timeout=2)
|
|
process = None
|
|
active_slug = None
|
|
if config_path is not None:
|
|
Path(config_path).unlink(missing_ok=True)
|
|
config_path = None
|
|
binary = frpc_binary() if slug and process is None else None
|
|
if slug and binary and process is None:
|
|
fd, config_path = tempfile.mkstemp(prefix='.frpc-', suffix='.toml', dir=pairing.root)
|
|
os.fchmod(fd, 0o600)
|
|
with os.fdopen(fd, 'w', encoding='utf-8') as stream:
|
|
stream.write(pairing.frpc_config(slug, remote_port, auth_port))
|
|
process = subprocess.Popen([binary, '-c', config_path], stdin=subprocess.DEVNULL,
|
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
active_slug = slug
|
|
finally:
|
|
if process is not None and process.poll() is None:
|
|
process.terminate()
|
|
try:
|
|
process.wait(timeout=5)
|
|
except subprocess.TimeoutExpired:
|
|
process.kill()
|
|
process.wait(timeout=2)
|
|
if config_path is not None:
|
|
Path(config_path).unlink(missing_ok=True)
|