Package com.wireguard.config
Class Interface
- java.lang.Object
-
- com.wireguard.config.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 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 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 anInterface
.java.lang.String
toString()
Converts theInterface
into a string suitable for debugging purposes.java.lang.String
toWgQuickString()
Converts theInterface
into a string suitable for inclusion in awg-quick
configuration file.java.lang.String
toWgUserspaceString()
Serializes theInterface
for 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
. ThrowsParseException
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 fromlines
set - Throws:
BadConfigException
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
getAddresses
public java.util.Set<InetNetwork> getAddresses()
Returns the set of IP addresses assigned to the interface.- Returns:
- a set of
InetNetwork
s
-
getDnsServers
public java.util.Set<java.net.InetAddress> getDnsServers()
Returns the set of DNS servers associated with the interface.- Returns:
- a set of
InetAddress
es
-
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 classjava.lang.Object
-
toString
public java.lang.String toString()
Converts theInterface
into a string suitable for debugging purposes. TheInterface
is identified by its public key and (if set) the port used for its UDP socket.- Overrides:
toString
in classjava.lang.Object
- Returns:
- A concise single-line identifier for the
Interface
-
toWgQuickString
public java.lang.String toWgQuickString()
Converts theInterface
into a string suitable for inclusion in awg-quick
configuration file.- Returns:
- The
Interface
represented as a series of "Key = Value" lines
-
toWgUserspaceString
public java.lang.String toWgUserspaceString()
Serializes theInterface
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
-
-