Package com.wireguard.config
Class Peer
- java.lang.Object
-
- com.wireguard.config.Peer
-
public final class Peer extends java.lang.ObjectRepresents the configuration for a WireGuard peer (a [Peer] block). Peers must have a public key, and may optionally have several other attributes.Instances of this class are immutable.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPeer.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>getAllowedIps()Returns the peer's set of allowed IPs.java.util.Optional<InetEndpoint>getEndpoint()Returns the peer's endpoint.java.util.Optional<java.lang.Integer>getPersistentKeepalive()Returns the peer's persistent keepalive.java.util.Optional<Key>getPreSharedKey()Returns the peer's pre-shared key.KeygetPublicKey()Returns the peer's public key.inthashCode()static Peerparse(java.lang.Iterable<? extends java.lang.CharSequence> lines)Parses an series of "KEY = VALUE" lines into aPeer.java.lang.StringtoString()Converts thePeerinto a string suitable for debugging purposes.java.lang.StringtoWgQuickString()Converts thePeerinto a string suitable for inclusion in awg-quickconfiguration file.java.lang.StringtoWgUserspaceString()Serializes thePeerfor use with the WireGuard cross-platform userspace API.
-
-
-
Method Detail
-
parse
public static Peer parse(java.lang.Iterable<? extends java.lang.CharSequence> lines) throws BadConfigException
Parses an series of "KEY = VALUE" lines into aPeer. ThrowsParseExceptionif the input is not well-formed or contains unknown attributes.- Parameters:
lines- an iterable sequence of lines, containing at least a public key attribute- Returns:
- a
Peerwith all of its attributes set fromlines - Throws:
BadConfigException
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
getAllowedIps
public java.util.Set<InetNetwork> getAllowedIps()
Returns the peer's set of allowed IPs.- Returns:
- the set of allowed IPs
-
getEndpoint
public java.util.Optional<InetEndpoint> getEndpoint()
Returns the peer's endpoint.- Returns:
- the endpoint, or
Optional.empty()if none is configured
-
getPersistentKeepalive
public java.util.Optional<java.lang.Integer> getPersistentKeepalive()
Returns the peer's persistent keepalive.- Returns:
- the persistent keepalive, or
Optional.empty()if none is configured
-
getPreSharedKey
public java.util.Optional<Key> getPreSharedKey()
Returns the peer's pre-shared key.- Returns:
- the pre-shared key, or
Optional.empty()if none is configured
-
getPublicKey
public Key getPublicKey()
Returns the peer's public key.- Returns:
- the public key
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
Converts thePeerinto a string suitable for debugging purposes. ThePeeris identified by its public key and (if known) its endpoint.- Overrides:
toStringin classjava.lang.Object- Returns:
- a concise single-line identifier for the
Peer
-
toWgQuickString
public java.lang.String toWgQuickString()
Converts thePeerinto a string suitable for inclusion in awg-quickconfiguration file.- Returns:
- the
Peerrepresented as a series of "Key = Value" lines
-
toWgUserspaceString
public java.lang.String toWgUserspaceString()
Serializes thePeerfor use with the WireGuard cross-platform userspace API. Note that not all attributes are included in this representation.- Returns:
- the
Peerrepresented as a series of "key=value" lines
-
-