Add a Rust Android mesh client with shared tray views
Run one agent for all joined networks behind Android's VPN service. Share transport registration and reporting with the CLI, and move the tray's egui forms into a Rust UI crate. Phones use compact device rows and a full-width exit picker with RTT and data path. All four transports retain their per-network selection and priority. The phone consumes remote IPv4 exits and keeps the existing desktop identity and wire protocols. Send discovery and transport traffic over the physical network and bind VIP TCP health checks to the mesh. Build local DNS zones from the same signed membership and VIP records on desktop and Android. Answer UDP and TCP queries on the VPN, keep unknown mesh names local, and resolve public names through Android's underlying resolver, including with an exit. Show an ongoing notification for the selected exit. Guard its disconnect action against a stale selection and keep mesh routing and DNS alive when it removes the default route. Remove the app notification in mesh-only mode. Document Android 14's unlocked-device swipe behavior. Checked formatting and ran locked all-target workspace Clippy with warnings denied and tests on macOS (547 passed, 2 ignored). Built the arm64 debug APK. A physical Pixel resolved a mesh member and a Kubernetes VIP, answered UDP and TCP DNS, and reached the API over TLS (HTTP 401 without credentials). On a separate Android emulator the notification action removed the default route and notice while mesh DNS still worked.
This commit is contained in:
1 parent
9dec056349
commit
ef67e1c0ae
70 files changed
+6199
-1181
No files matched your search
@@ -35,6 +35,8 @@ pub struct ExitHostPlan {
|
||||
pub offer: Vec<Ipv4Range>,
|
||||
/// Whether this device sends its internet traffic through a member.
|
||||
pub client: bool,
|
||||
/// Local address in the selected exit network, for hosts that choose a primary address.
|
||||
pub client_source: Option<std::net::Ipv4Addr>,
|
||||
/// The range of every network on the interface. Only the using side
|
||||
/// reads it, to keep this agent's own traffic *to* the overlay inside it
|
||||
/// where the host has no per-user routing (macOS).
|
||||
|
||||
@@ -407,6 +407,7 @@ mod tests {
|
||||
overlay: vec![range()],
|
||||
bypass: vec![Ipv4Addr::new(138, 201, 61, 182)],
|
||||
bypass_hosts: vec!["relay.example".into()],
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -231,6 +231,7 @@ impl Interface {
|
||||
let tally = Arc::new(Tally::default());
|
||||
|
||||
let vip_task = {
|
||||
let factory = Arc::clone(&factory);
|
||||
let routes = Arc::clone(&routes);
|
||||
let carrier = Arc::clone(&carrier);
|
||||
tokio::spawn(async move {
|
||||
@@ -242,7 +243,10 @@ impl Interface {
|
||||
_=interval.tick()=>{
|
||||
let (probes,jobs)=routes.vips.tick(routes.vips.check_capacity().saturating_sub(checks.len()));
|
||||
for (route,packet) in probes {carrier.carry(route,packet);}
|
||||
for job in jobs {checks.spawn(job.run());}
|
||||
for job in jobs {
|
||||
let factory = Arc::clone(&factory);
|
||||
checks.spawn(job.run(move |socket, source| factory.bind_overlay_socket(socket, source)));
|
||||
}
|
||||
},
|
||||
Some(result)=checks.join_next(),if !checks.is_empty()=>{
|
||||
if let Ok((job,ok))=result {routes.vips.checked(job,ok);}
|
||||
@@ -415,7 +419,7 @@ impl Interface {
|
||||
.collect();
|
||||
ranges.sort_by_key(|range| (range.base, range.prefix_len));
|
||||
ranges.dedup();
|
||||
let client = self.routes.exit_via().is_some();
|
||||
let (client, client_source) = self.routes.exit_client();
|
||||
let overlay = self.routes.overlay_ranges();
|
||||
let (bypass, bypass_hosts) = if client && exit.needs_bypass() {
|
||||
self.underlay_targets(&overlay)
|
||||
@@ -426,6 +430,7 @@ impl Interface {
|
||||
interface: self.name.clone(),
|
||||
offer: ranges,
|
||||
client,
|
||||
client_source,
|
||||
overlay,
|
||||
bypass,
|
||||
bypass_hosts,
|
||||
|
||||
@@ -281,6 +281,15 @@ impl RoutingTable {
|
||||
exit_via(&self.read())
|
||||
}
|
||||
|
||||
/// Whether a default route is selected and the local source valid in that network.
|
||||
pub(crate) fn exit_client(&self) -> (bool, Option<Ipv4Addr>) {
|
||||
let networks = self.read();
|
||||
match exit_via(&networks) {
|
||||
Some((id, _)) => (true, networks.get(&id).and_then(|routes| routes.local)),
|
||||
None => (false, None),
|
||||
}
|
||||
}
|
||||
|
||||
/// Networks that offer this agent as an exit node, with the range each
|
||||
/// agreed. A network that has not agreed one yet has nothing to
|
||||
/// masquerade and is left out.
|
||||
|
||||
@@ -90,6 +90,21 @@ pub trait TunFactory: Send + Sync + std::fmt::Debug + 'static {
|
||||
/// land on the second.
|
||||
fn on_host(&self) -> bool;
|
||||
|
||||
/// Bind a socket carrying a VIP health check to this overlay on platforms
|
||||
/// that explicitly route mesh transport sockets outside the VPN.
|
||||
fn bind_overlay_socket(
|
||||
&self,
|
||||
_socket: &tokio::net::TcpSocket,
|
||||
_source: std::net::Ipv4Addr,
|
||||
) -> std::io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Assigned overlay addresses when the OS chooses a new interface name on reconfiguration.
|
||||
fn assigned_addresses(&self) -> Vec<std::net::IpAddr> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
/// Creates a device.
|
||||
fn create<'a>(
|
||||
&'a self,
|
||||
@@ -229,37 +244,34 @@ impl TunDevice for MemoryTun {
|
||||
/// enough here: the agent chose the address, so anything else holding it is a
|
||||
/// problem in its own right.
|
||||
pub fn address_is_local(address: std::net::IpAddr) -> bool {
|
||||
if std::net::UdpSocket::bind((address, 0)).is_ok() {
|
||||
return true;
|
||||
}
|
||||
let bound = std::net::UdpSocket::bind((address, 0)).is_ok();
|
||||
#[cfg(all(feature = "tun-device", target_os = "windows"))]
|
||||
{
|
||||
if let Ok(interfaces) = std::panic::catch_unwind(netdev::get_interfaces) {
|
||||
for iface in interfaces {
|
||||
if iface.is_up() {
|
||||
match address {
|
||||
std::net::IpAddr::V4(v4) => {
|
||||
if iface.ipv4.iter().any(|ip| ip.addr() == v4) {
|
||||
return true;
|
||||
}
|
||||
if !bound && let Ok(interfaces) = std::panic::catch_unwind(netdev::get_interfaces) {
|
||||
for iface in interfaces {
|
||||
if iface.is_up() {
|
||||
match address {
|
||||
std::net::IpAddr::V4(v4) => {
|
||||
if iface.ipv4.iter().any(|ip| ip.addr() == v4) {
|
||||
return true;
|
||||
}
|
||||
std::net::IpAddr::V6(v6) => {
|
||||
if iface.ipv6.iter().any(|ip| ip.addr() == v6) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
std::net::IpAddr::V6(v6) => {
|
||||
if iface.ipv6.iter().any(|ip| ip.addr() == v6) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
bound
|
||||
}
|
||||
|
||||
/// Creates [`MemoryTun`] devices.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct MemoryTunFactory {
|
||||
created: Arc<std::sync::Mutex<Vec<Arc<MemoryTun>>>>,
|
||||
rules: Option<Arc<dyn super::hostrules::BroadcastHostRules>>,
|
||||
}
|
||||
|
||||
impl MemoryTunFactory {
|
||||
@@ -268,6 +280,12 @@ impl MemoryTunFactory {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Simulate host rule outcomes alongside this in-memory interface.
|
||||
pub fn with_host_rules(mut self, rules: Arc<dyn super::hostrules::BroadcastHostRules>) -> Self {
|
||||
self.rules = Some(rules);
|
||||
self
|
||||
}
|
||||
|
||||
/// The device created for an interface name, if any.
|
||||
pub fn device(&self, name: &str) -> Option<Arc<MemoryTun>> {
|
||||
let guard = match self.created.lock() {
|
||||
@@ -291,6 +309,9 @@ impl MemoryTunFactory {
|
||||
}
|
||||
|
||||
impl TunFactory for MemoryTunFactory {
|
||||
fn host_rules(&self) -> Option<Arc<dyn super::hostrules::BroadcastHostRules>> {
|
||||
self.rules.clone()
|
||||
}
|
||||
fn name(&self) -> &str {
|
||||
"memory"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user