feat(mesh): integrate MeshPort/EasyTier P2P mesh network with NetworkManager auto-connect
Offline project checks / check (push) Canceled after 0s

- Add platina-mesh CLI (scripts/phone-mesh.py) for status inspection, control, and JSON telemetry.
- Add OpenRC service (scripts/phone-mesh.openrc) for managing easytier-core daemon.
- Add NetworkManager dispatcher hook (scripts/phone-mesh-dispatcher.sh) to automatically start mesh when external default route is active and stop when disconnected.
- Add default mesh configuration (scripts/easytier.conf) with node identity Platina (192.168.20.10).
- Integrate mesh runtime into image overlay builder (scripts/image-runtime.py).
- Add unit tests for mesh control and image runtime integration (142 tests passing).
This commit is contained in:
shenlei
2026-11-10 09:50:00 +09:00
parent 2a9ec1e1d6
commit 139bb1fc21
7 changed files with 375 additions and 1 deletions
+19
View File
@@ -0,0 +1,19 @@
# Platina Linux EasyTier P2P Mesh Network Configuration
hostname = "Platina"
instance_name = "platina-phone"
ipv4 = "192.168.20.10/24"
dhcp = false
listeners = [
"tcp://0.0.0.0:52015",
"udp://0.0.0.0:52015",
]
[network_identity]
network_name = "UzeaThJooQn1ylehvb5"
network_secret = "2NWf05N815cL1zKp09%"
[[peer]]
uri = "tcp://easytier.slcydia.fun:52015"
[flags]
latency_first = true
+11 -1
View File
@@ -27,9 +27,13 @@ HELPERS = {
'scripts/phone-usb-power.py': 'usr/local/sbin/platina-usb-power',
'scripts/phone-usb-power-dispatcher.sh': 'etc/NetworkManager/dispatcher.d/90-platina-usb-power',
'scripts/phone-cellular-setup.py': 'usr/local/sbin/platina-cellular',
'scripts/phone-mesh.py': 'usr/local/sbin/platina-mesh',
'scripts/phone-mesh.openrc': 'etc/init.d/easytier',
'scripts/phone-mesh-dispatcher.sh': 'etc/NetworkManager/dispatcher.d/95-platina-mesh',
'scripts/image-runtime.py': 'usr/local/libexec/platina-image-runtime',
}
CONFIG = 'etc/conf.d/platina-power-chord'
MESH_CONFIG = 'etc/easytier/easytier.conf'
def layout(version):
@@ -38,18 +42,21 @@ def layout(version):
base = 'usr/local/share/platina/releases/' + version
modes = {name: 0o755 for name in HELPERS.values()}
modes[CONFIG] = 0o644
modes[MESH_CONFIG] = 0o644
for sub in ('', 'poweroff/'):
for name in ('release.json', 'version', 'frame.bgrx.gz'):
modes[base + '/' + sub + name] = 0o644
links = {'usr/local/share/platina/current': 'releases/' + version,
'etc/platina-release': '../usr/local/share/platina/current/version',
'etc/runlevels/default/platina-power-chord': '../../init.d/platina-power-chord',
'etc/runlevels/default/platina-battery-guard': '../../init.d/platina-battery-guard'}
'etc/runlevels/default/platina-battery-guard': '../../init.d/platina-battery-guard',
'etc/runlevels/default/easytier': '../../init.d/easytier'}
return base, modes, links
def source_inputs():
names = list(HELPERS) + ['scripts/phone-power-chord.conf',
'scripts/easytier.conf',
'scripts/platina-release.py', 'project/release.json',
'project/branding/platina-linux-logo.png',
'project/branding/provenance.json']
@@ -138,6 +145,9 @@ def prepare(output):
dest = stage / CONFIG
dest.parent.mkdir(parents=True, exist_ok=True)
dest.write_bytes(conf.replace(b'dry_run=yes\n', b'dry_run=no\n'))
dest_mesh = stage / MESH_CONFIG
dest_mesh.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(ROOT / 'scripts/easytier.conf', dest_mesh)
for sub in ('', 'poweroff/'):
for name in ('release.json', 'version', 'frame.bgrx.gz'):
dest = stage / base / sub / name
+32
View File
@@ -0,0 +1,32 @@
#!/bin/sh
# Platina Linux MeshPort / EasyTier auto-connect dispatcher
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PATH
interface="${1:-}"
action="${2:-}"
# Ignore virtual tun/tap/dummy devices created by mesh networking
case "$interface" in
lo|tun*|tap*|dummy*) exit 0 ;;
esac
case "$action" in
up|dhcp4-change|reapply)
# Check if an active default route to the external network exists
if ip route show default 2>/dev/null | grep -q 'default via'; then
if [ -x /usr/local/sbin/platina-mesh ]; then
/usr/local/sbin/platina-mesh --auto-up >/dev/null 2>&1 || true
fi
fi
;;
down)
# If no default route remains, stop mesh service to conserve battery
if ! ip route show default 2>/dev/null | grep -q 'default via'; then
if [ -x /usr/local/sbin/platina-mesh ]; then
/usr/local/sbin/platina-mesh --auto-down >/dev/null 2>&1 || true
fi
fi
;;
esac
exit 0
+24
View File
@@ -0,0 +1,24 @@
#!/sbin/openrc-run
description="EasyTier P2P Mesh Network Service"
command="/usr/local/bin/easytier-core"
command_args="-c /etc/easytier/easytier.conf"
command_background="yes"
pidfile="/run/easytier.pid"
output_log="/var/log/easytier.log"
error_log="/var/log/easytier.log"
depend() {
need localmount
after net
}
start_pre() {
if [ ! -c /dev/net/tun ]; then
modprobe tun >/dev/null 2>&1 || true
fi
if [ ! -r /etc/easytier/easytier.conf ]; then
eerror "EasyTier configuration file /etc/easytier/easytier.conf not found"
return 1
fi
}
+148
View File
@@ -0,0 +1,148 @@
#!/usr/bin/env python3
"""Platina Linux EasyTier P2P Mesh Network Management."""
import argparse
import json
from pathlib import Path
import shutil
import subprocess
import sys
CONFIG_FILE = '/etc/easytier/easytier.conf'
SERVICE_NAME = 'easytier'
def is_service_running(executor=subprocess.run):
"""Check if easytier service is currently running."""
try:
proc = executor(['rc-service', SERVICE_NAME, 'status'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
return proc.returncode == 0
except Exception:
return False
def get_mesh_status(executor=subprocess.run, config_file=CONFIG_FILE, cli_path=None):
"""Retrieve full status of mesh node and peers via easytier-cli."""
running = is_service_running(executor=executor)
status = {
'service_running': running,
'config_present': Path(config_file).is_file(),
'node': None,
'peers': [],
'error': None
}
if not running:
return status
resolved_cli = cli_path or shutil.which('easytier-cli') or '/usr/local/bin/easytier-cli'
if executor is subprocess.run and not Path(resolved_cli).is_file():
status['error'] = 'easytier-cli binary not found'
return status
# Query node details
try:
proc_node = executor([resolved_cli, '-o', 'json', 'node'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, timeout=5)
if proc_node.returncode == 0:
status['node'] = json.loads(proc_node.stdout)
except Exception as exc:
status['error'] = f'Failed to query node info: {exc}'
# Query peers list
try:
proc_peer = executor([resolved_cli, '-o', 'json', 'peer'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, timeout=5)
if proc_peer.returncode == 0:
status['peers'] = json.loads(proc_peer.stdout)
except Exception:
pass
return status
def toggle_service(action, executor=subprocess.run):
"""Execute rc-service action (start/stop/restart)."""
cmd = ['rc-service', SERVICE_NAME, action]
proc = executor(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
return proc.returncode == 0
def auto_up(executor=subprocess.run, checker=is_service_running, config_file=CONFIG_FILE):
"""Invoked on network interface up with default route: start if not running."""
if not checker(executor=executor):
if Path(config_file).is_file():
return toggle_service('start', executor=executor)
return True
def auto_down(executor=subprocess.run, checker=is_service_running):
"""Invoked on network interface down when no default route: stop service."""
if checker(executor=executor):
return toggle_service('stop', executor=executor)
return True
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--status', action='store_true', help='Show mesh network status')
parser.add_argument('--up', action='store_true', help='Start mesh networking service')
parser.add_argument('--down', action='store_true', help='Stop mesh networking service')
parser.add_argument('--restart', action='store_true', help='Restart mesh networking service')
parser.add_argument('--auto-up', action='store_true', help='Auto-start when default network is up')
parser.add_argument('--auto-down', action='store_true', help='Auto-stop when default network is down')
parser.add_argument('--json', action='store_true', help='Output in JSON format')
args = parser.parse_args()
if args.auto_up:
success = auto_up()
sys.exit(0 if success else 1)
if args.auto_down:
success = auto_down()
sys.exit(0 if success else 1)
if args.up:
success = toggle_service('start')
print("Mesh service started" if success else "Failed to start mesh service")
sys.exit(0 if success else 1)
if args.down:
success = toggle_service('stop')
print("Mesh service stopped" if success else "Failed to stop mesh service")
sys.exit(0 if success else 1)
if args.restart:
success = toggle_service('restart')
print("Mesh service restarted" if success else "Failed to restart mesh service")
sys.exit(0 if success else 1)
# Default to status if no other action
status = get_mesh_status()
if args.json:
print(json.dumps(status, indent=2))
else:
if not status['service_running']:
print("Mesh Status: Service is STOPPED")
else:
node = status.get('node') or {}
vip = node.get('ipv4_addr', 'N/A')
hostname = node.get('hostname', 'N/A')
peer_id = node.get('peer_id', 'N/A')
print("Mesh Status: RUNNING")
print(f"Hostname: {hostname}")
print(f"Virtual IP: {vip}")
print(f"Peer ID: {peer_id}")
peers = status.get('peers') or []
print(f"Peers Count: {len(peers)}")
for p in peers:
p_host = p.get('hostname', 'unknown')
p_ip = p.get('ipv4', 'unknown')
p_tun = p.get('tunnel', 'unknown')
p_cost = p.get('cost', 'unknown')
print(f" * {p_host:<12} {p_ip:<18} [{p_tun}, {p_cost}]")
sys.exit(0)
if __name__ == '__main__':
main()