Interface TunnelTransport


public interface TunnelTransport

How packets reach the tunnel, which is where the two platforms differ.

This interface EXPOSES that difference rather than hiding it, because hiding it would mean pretending one of the platforms works like the other:

  • On Android a VpnService runs in the app's own process and hands over a file descriptor. Reading it blocks, and the read loop owns a thread.
  • A host that delivers packets through a completion handler instead -- an NEPacketTunnelProvider is the example, though iOS does not run these tunnels -- has nothing to block on, and a loop that tried to would deadlock it. The simulation takes this shape so the case is exercised.

isBlocking() is the discriminator, and the host reads it rather than guessing from the platform. A tunnel written against VpnTunnel never sees any of this; it is here for the ports and for the simulation.

  • Method Summary

    Modifier and Type
    Method
    Description
    The buffers this transport reads into, sized for the link.
    void
    Releases whatever the platform gave the tunnel.
    boolean
    Whether read(PacketBuffer[]) blocks until packets arrive.
    int
    Takes the next packets, filling into and answering how many.
    void
    Sends one packet back out.
  • Method Details

    • isBlocking

      boolean isBlocking()

      Whether read(PacketBuffer[]) blocks until packets arrive.

      True on Android, where the host gives the loop a thread. False for a host that arms a callback and returns, which is the simulation.

    • read

      int read(PacketBuffer[] into)

      Takes the next packets, filling into and answering how many.

      Answers 0 when the tunnel is going down, which is how a blocking loop learns to stop.

    • write

      void write(PacketBuffer packet)
      Sends one packet back out.
    • buffers

      PacketBuffer[] buffers()

      The buffers this transport reads into, sized for the link.

      Owned by the transport and reused; see PacketBuffer.

    • close

      void close()
      Releases whatever the platform gave the tunnel.