Class TunnelSetup

java.lang.Object
com.codename1.vpn.tunnel.TunnelSetup

public final class TunnelSetup extends Object

What an application asks the platform to set up before its tunnel runs.

The mirror of TunnelConfiguration: this is what goes DOWN to the platform, that is what comes back up to VpnTunnel.onStart(TunnelConfiguration). They are separate types because they are not the same thing -- a setup is a request, a configuration is what the platform actually established, and a host that runs the tunnel in its own process decides the two apart.

Every field has a usable default, so the smallest tunnel is new TunnelSetup().address("10.0.0.2/32").route("0.0.0.0/0").

  • Field Details

    • DEFAULT_MTU

      public static final int DEFAULT_MTU

      The MTU a link gets when the application does not choose one.

      1400 rather than 1500: a tunnel adds its own encapsulation, and a link sized for the physical MTU fragments every full-size packet.

      See Also:
  • Constructor Details

    • TunnelSetup

      public TunnelSetup()
  • Method Details

    • address

      public TunnelSetup address(String cidr)

      The address this device takes on the tunnel, in CIDR form.

      REQUIRED. A setup without one fails the start with INVALID_CONFIGURATION, because a link with no address is not one a platform can establish -- Android's VpnService.Builder documents that at least one address must be set before establish().

      The prefix may be left off -- /32 for IPv4, /128 for IPv6 -- but one that is written and unreadable FAILS the start the same way; see route(String).

    • server

      public TunnelSetup server(String host)
      The far end, which the platform excludes from the tunnel's own routes so the tunnel's own traffic does not loop back into it.
    • route

      public TunnelSetup route(String cidr)

      A route directed into the tunnel, in CIDR form. Repeatable.

      0.0.0.0/0 and ::/0 are the full tunnel. An unreadable prefix fails the start with INVALID_CONFIGURATION rather than being narrowed to a host route: "0.0.0.0/o" is a typo for the default route, and a tunnel that started and carried one address would let every packet the app believed it was protecting out in the clear. Checked in the simulation as well, so the refusal is not something found first on a device.

    • dnsServer

      public TunnelSetup dnsServer(String address)
      A DNS server the tunnel provides. Repeatable.
    • searchDomain

      public TunnelSetup searchDomain(String domain)

      A DNS search domain. Repeatable.

      Android applies these. A platform that cannot express one ignores it rather than refusing the tunnel, because a search domain is a convenience and losing the tunnel over one is not a trade an app would choose.

    • mtu

      public TunnelSetup mtu(int bytes)
      The link MTU. See DEFAULT_MTU.
    • sessionName

      public TunnelSetup sessionName(String name)
      The name the system shows for this VPN session.
    • data

      public TunnelSetup data(String value)

      Application data handed to VpnTunnel.onStart(TunnelConfiguration) as TunnelConfiguration.getData().

      The one thing that reaches the tunnel from the app WITHOUT relying on the two sharing a process. Android's does, so a static works there; a host that constructed the tunnel elsewhere shares no statics, no singletons and no open connections with the app. A tunnel that takes its token, server list or key from here is the one that does not have to be rewritten.

    • getAddress

      public String getAddress()
      Returns:
      the device's tunnel address in CIDR form
    • getServer

      public String getServer()
      Returns:
      the far end
    • getRoutes

      public String[] getRoutes()
      Returns:
      the routes directed into the tunnel
    • getDnsServers

      public String[] getDnsServers()
      Returns:
      the DNS servers the tunnel provides
    • getSearchDomains

      public String[] getSearchDomains()
      Returns:
      the DNS search domains
    • getMtu

      public int getMtu()
      Returns:
      the link MTU
    • getSessionName

      public String getSessionName()
      Returns:
      the session name the system shows
    • getData

      public String getData()
      Returns:
      the application data, never null