Class Interface


  • public final class Interface
    extends java.lang.Object
    Represents the configuration for a WireGuard interface (an [Interface] block). Interfaces must have a private key (used to initialize a KeyPair), and may optionally have several other attributes.

    Instances of this class are immutable.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Interface.Builder  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      java.util.Set<InetNetwork> getAddresses()
      Returns the set of IP addresses assigned to the interface.
      java.util.Set<java.lang.String> getDnsSearchDomains()
      Returns the set of DNS search domains associated with the interface.
      java.util.Set<java.net.InetAddress> getDnsServers()
      Returns the set of DNS servers associated with the interface.
      java.util.Set<java.lang.String> getExcludedApplications()
      Returns the set of applications excluded from using the interface.
      java.util.Set<java.lang.String> getIncludedApplications()
      Returns the set of applications included exclusively for using the interface.
      KeyPair getKeyPair()
      Returns the public/private key pair used by the interface.
      java.util.Optional<java.lang.Integer> getListenPort()
      Returns the UDP port number that the WireGuard interface will listen on.
      java.util.Optional<java.lang.Integer> getMtu()
      Returns the MTU used for the WireGuard interface.
      int hashCode()  
      static Interface parse​(java.lang.Iterable<? extends java.lang.CharSequence> lines)
      Parses an series of "KEY = VALUE" lines into an Interface.
      java.lang.String toString()
      Converts the Interface into a string suitable for debugging purposes.
      java.lang.String toWgQuickString()
      Converts the Interface into a string suitable for inclusion in a wg-quick configuration file.
      java.lang.String toWgUserspaceString()
      Serializes the Interface for use with the WireGuard cross-platform userspace API.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • parse

        public static Interface parse​(java.lang.Iterable<? extends java.lang.CharSequence> lines)
                               throws BadConfigException
        Parses an series of "KEY = VALUE" lines into an Interface. Throws ParseException if the input is not well-formed or contains unknown attributes.
        Parameters:
        lines - An iterable sequence of lines, containing at least a private key attribute
        Returns:
        An Interface with all of the attributes from lines set
        Throws:
        BadConfigException
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • getAddresses

        public java.util.Set<InetNetwork> getAddresses()
        Returns the set of IP addresses assigned to the interface.
        Returns:
        a set of InetNetworks
      • getDnsServers

        public java.util.Set<java.net.InetAddress> getDnsServers()
        Returns the set of DNS servers associated with the interface.
        Returns:
        a set of InetAddresses
      • getDnsSearchDomains

        public java.util.Set<java.lang.String> getDnsSearchDomains()
        Returns the set of DNS search domains associated with the interface.
        Returns:
        a set of strings
      • getExcludedApplications

        public java.util.Set<java.lang.String> getExcludedApplications()
        Returns the set of applications excluded from using the interface.
        Returns:
        a set of package names
      • getIncludedApplications

        public java.util.Set<java.lang.String> getIncludedApplications()
        Returns the set of applications included exclusively for using the interface.
        Returns:
        a set of package names
      • getKeyPair

        public KeyPair getKeyPair()
        Returns the public/private key pair used by the interface.
        Returns:
        a key pair
      • getListenPort

        public java.util.Optional<java.lang.Integer> getListenPort()
        Returns the UDP port number that the WireGuard interface will listen on.
        Returns:
        a UDP port number, or Optional.empty() if none is configured
      • getMtu

        public java.util.Optional<java.lang.Integer> getMtu()
        Returns the MTU used for the WireGuard interface.
        Returns:
        the MTU, or Optional.empty() if none is configured
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Converts the Interface into a string suitable for debugging purposes. The Interface is identified by its public key and (if set) the port used for its UDP socket.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A concise single-line identifier for the Interface
      • toWgQuickString

        public java.lang.String toWgQuickString()
        Converts the Interface into a string suitable for inclusion in a wg-quick configuration file.
        Returns:
        The Interface represented as a series of "Key = Value" lines
      • toWgUserspaceString

        public java.lang.String toWgUserspaceString()
        Serializes the Interface for use with the WireGuard cross-platform userspace API. Note that not all attributes are included in this representation.
        Returns:
        the Interface represented as a series of "KEY=VALUE" lines