MobDev.Tunnel (mob_dev v0.3.28)

Copy Markdown View Source

Manages port tunnels for Android and physical iOS devices.

Android (adb): adb reverse tcp:4369 tcp:4369 — Android BEAM registers in Mac's EPMD adb forward tcp:<dist> tcp:9100 — Mac reaches device's dist port

Physical iOS (direct networking — USB preferred, WiFi/LAN fallback): mob_beam.m finds the device's own IP via getifaddrs() and starts the BEAM as mob_qa_ios@<device-ip>. The in-process EPMD binds 0.0.0.0:4369 so Mac can query it at <device-ip>:4369. The dist port is directly reachable.

Connection priority (mirrors mob_beam.m priority):

1. USB link-local (169.254.x.x)  detected from Mac ARP table
2. WiFi/LAN (10.x, 172.16-31.x, 192.168.x)  EPMD scan of ARP table
3. Tailscale (100.64-127.x)  EPMD scan of ARP table

iOS simulator: Shares Mac network stack — no tunnels needed.

Summary

Functions

Returns the dist port for a given device index (same formula used in setup/2).

Assigns a dist port and sets up tunnels for a device. Returns {:ok, %Device{}} with dist_port and host_ip filled in, or {:error, reason}.

Tears down tunnels for a device.

Functions

dist_port(index)

@spec dist_port(non_neg_integer()) :: non_neg_integer()

Returns the dist port for a given device index (same formula used in setup/2).

setup(device, index \\ 0)

@spec setup(MobDev.Device.t(), non_neg_integer()) ::
  {:ok, MobDev.Device.t()} | {:error, String.t()}

Assigns a dist port and sets up tunnels for a device. Returns {:ok, %Device{}} with dist_port and host_ip filled in, or {:error, reason}.

teardown(device)

@spec teardown(MobDev.Device.t()) :: :ok

Tears down tunnels for a device.