Package com.wireguard.config
Class Interface
- java.lang.Object
-
- com.wireguard.config.Interface
-
public final class Interface extends java.lang.ObjectRepresents the configuration for a WireGuard interface (an [Interface] block). Interfaces must have a private key (used to initialize aKeyPair), and may optionally have several other attributes.Instances of this class are immutable.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classInterface.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(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.KeyPairgetKeyPair()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.inthashCode()static Interfaceparse(java.lang.Iterable<? extends java.lang.CharSequence> lines)Parses an series of "KEY = VALUE" lines into anInterface.java.lang.StringtoString()Converts theInterfaceinto a string suitable for debugging purposes.java.lang.StringtoWgQuickString()Converts theInterfaceinto a string suitable for inclusion in awg-quickconfiguration file.java.lang.StringtoWgUserspaceString()Serializes theInterfacefor use with the WireGuard cross-platform userspace API.
-
-
-
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 anInterface. ThrowsParseExceptionif 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
Interfacewith all of the attributes fromlinesset - Throws:
BadConfigException
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.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:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
Converts theInterfaceinto a string suitable for debugging purposes. TheInterfaceis identified by its public key and (if set) the port used for its UDP socket.- Overrides:
toStringin classjava.lang.Object- Returns:
- A concise single-line identifier for the
Interface
-
toWgQuickString
public java.lang.String toWgQuickString()
Converts theInterfaceinto a string suitable for inclusion in awg-quickconfiguration file.- Returns:
- The
Interfacerepresented as a series of "Key = Value" lines
-
toWgUserspaceString
public java.lang.String toWgUserspaceString()
Serializes theInterfacefor use with the WireGuard cross-platform userspace API. Note that not all attributes are included in this representation.- Returns:
- the
Interfacerepresented as a series of "KEY=VALUE" lines
-
-