Class Config


  • public final class Config
    extends java.lang.Object
    Represents the contents of a wg-quick configuration file, made up of one or more "Interface" sections (combined together), and zero or more "Peer" sections (treated individually).

    Instances of this class are immutable.

    • Nested Class Summary

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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      Interface getInterface()
      Returns the interface section of the configuration.
      java.util.List<Peer> getPeers()
      Returns a list of the configuration's peer sections.
      int hashCode()  
      static Config parse​(java.io.BufferedReader reader)
      Parses an series of "Interface" and "Peer" sections into a Config.
      static Config parse​(java.io.InputStream stream)
      Parses an series of "Interface" and "Peer" sections into a Config.
      java.lang.String toString()
      Converts the Config into a string suitable for debugging purposes.
      java.lang.String toWgQuickString()
      Converts the Config into a string suitable for use as a wg-quick configuration file.
      java.lang.String toWgUserspaceString()
      Serializes the Config 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 Config parse​(java.io.InputStream stream)
                            throws java.io.IOException,
                                   BadConfigException
        Parses an series of "Interface" and "Peer" sections into a Config. Throws BadConfigException if the input is not well-formed or contains data that cannot be parsed.
        Parameters:
        stream - a stream of UTF-8 text that is interpreted as a WireGuard configuration
        Returns:
        a Config instance representing the supplied configuration
        Throws:
        java.io.IOException
        BadConfigException
      • parse

        public static Config parse​(java.io.BufferedReader reader)
                            throws java.io.IOException,
                                   BadConfigException
        Parses an series of "Interface" and "Peer" sections into a Config. Throws BadConfigException if the input is not well-formed or contains data that cannot be parsed.
        Parameters:
        reader - a BufferedReader of UTF-8 text that is interpreted as a WireGuard configuration
        Returns:
        a Config instance representing the supplied configuration
        Throws:
        java.io.IOException
        BadConfigException
      • equals

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

        public Interface getInterface()
        Returns the interface section of the configuration.
        Returns:
        the interface configuration
      • getPeers

        public java.util.List<Peer> getPeers()
        Returns a list of the configuration's peer sections.
        Returns:
        a list of Peers
      • hashCode

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

        public java.lang.String toString()
        Converts the Config into a string suitable for debugging purposes. The Config is identified by its interface's public key and the number of peers it has.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a concise single-line identifier for the Config
      • toWgQuickString

        public java.lang.String toWgQuickString()
        Converts the Config into a string suitable for use as a wg-quick configuration file.
        Returns:
        the Config represented as one [Interface] and zero or more [Peer] sections
      • toWgUserspaceString

        public java.lang.String toWgUserspaceString()
        Serializes the Config for use with the WireGuard cross-platform userspace API.
        Returns:
        the Config represented as a series of "key=value" lines