Class Peer


  • public final class Peer
    extends java.lang.Object
    Represents 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 class  Peer.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> 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.
      Key getPublicKey()
      Returns the peer's public key.
      int hashCode()  
      static Peer parse​(java.lang.Iterable<? extends java.lang.CharSequence> lines)
      Parses an series of "KEY = VALUE" lines into a Peer.
      java.lang.String toString()
      Converts the Peer into a string suitable for debugging purposes.
      java.lang.String toWgQuickString()
      Converts the Peer into a string suitable for inclusion in a wg-quick configuration file.
      java.lang.String toWgUserspaceString()
      Serializes the Peer 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 Peer parse​(java.lang.Iterable<? extends java.lang.CharSequence> lines)
                          throws BadConfigException
        Parses an series of "KEY = VALUE" lines into a Peer. Throws ParseException if 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 Peer with all of its attributes set from lines
        Throws:
        BadConfigException
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.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:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Converts the Peer into a string suitable for debugging purposes. The Peer is identified by its public key and (if known) its endpoint.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a concise single-line identifier for the Peer
      • toWgQuickString

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

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