Class NetherNetHTTPSignaling.Builder

java.lang.Object
org.cloudburstmc.netty.channel.nethernet.signaling.NetherNetHTTPSignaling.Builder
Enclosing class:
NetherNetHTTPSignaling

public static class NetherNetHTTPSignaling.Builder extends Object
Builder for NetherNetHTTPSignaling.

The server is backed by one keystore for the TLS listener and another for the server identity used to sign SDP answers. Both must be PKCS12 files, and only the identity keystore is required.

  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • setIdentity

      public NetherNetHTTPSignaling.Builder setIdentity(ServerIdentity identity)
      Sets the identity used to sign SDP answers. Required.

      Load it with ServerIdentity.fromPkcs12(java.io.File, java.lang.String), ServerIdentity.fromPem(java.io.File, java.lang.String) or ServerIdentity.generate(java.lang.String), or build one straight from a keypair.

      Parameters:
      identity - The identity to sign with
      Returns:
      This builder
    • setIdentityKeystore

      public NetherNetHTTPSignaling.Builder setIdentityKeystore(File identityKeystore)
      Sets the identity from an unprotected PKCS12 keystore.
      Parameters:
      identityKeystore - PKCS12 keystore holding the EC P-384 identity key
      Returns:
      This builder
    • setIdentityKeystore

      public NetherNetHTTPSignaling.Builder setIdentityKeystore(File identityKeystore, String identityPassword)
      Sets the identity from a PKCS12 keystore. The key must be EC P-384, and its certificate CN becomes the identity domain, so set it to something recognisable. Generate one with:
      
       keytool -genkeypair -alias identity -keyalg EC -groupname secp384r1 \
               -storetype PKCS12 -keystore identity.p12 -storepass changeit \
               -dname "CN=Your Server" -validity 3650
       
      Parameters:
      identityKeystore - PKCS12 keystore holding the EC P-384 identity key
      identityPassword - Password for identityKeystore, or "" if unprotected
      Returns:
      This builder
      Throws:
      IllegalArgumentException - If the keystore cannot be read
    • setIdentityPem

      public NetherNetHTTPSignaling.Builder setIdentityPem(File identityPem, String domain)
      Sets the identity from an unencrypted PEM private key, which carries no certificate and so no domain of its own.
      Parameters:
      identityPem - PEM file holding the EC P-384 identity key
      domain - The identity domain, surfaced to players in the first use prompt
      Returns:
      This builder
      Throws:
      IllegalArgumentException - If the key cannot be read
    • setSslContext

      public NetherNetHTTPSignaling.Builder setSslContext(io.netty.handler.ssl.SslContext sslContext)
      Sets the TLS context for the listener. If unset the server listens in plaintext.
      Parameters:
      sslContext - The context to serve TLS with
      Returns:
      This builder
    • setHttpsKeystore

      public NetherNetHTTPSignaling.Builder setHttpsKeystore(File httpsKeystore)
      Serves TLS using an unprotected PKCS12 keystore.
      Parameters:
      httpsKeystore - PKCS12 keystore holding the TLS certificate and key
      Returns:
      This builder
    • setHttpsKeystore

      public NetherNetHTTPSignaling.Builder setHttpsKeystore(File httpsKeystore, String httpsPassword)
      Serves TLS using a PKCS12 keystore.
      Parameters:
      httpsKeystore - PKCS12 keystore holding the TLS certificate and key
      httpsPassword - Password for httpsKeystore, or "" if unprotected
      Returns:
      This builder
      Throws:
      IllegalArgumentException - If the keystore cannot be read
    • setHttpsPem

      public NetherNetHTTPSignaling.Builder setHttpsPem(File certificateChain, File privateKey)
      Serves TLS using PEM files, the form most certificate authorities hand out.
      Parameters:
      certificateChain - PEM certificate chain, leaf first
      privateKey - PEM private key for the leaf certificate
      Returns:
      This builder
      Throws:
      IllegalArgumentException - If either file cannot be read
    • setHttpsPem

      public NetherNetHTTPSignaling.Builder setHttpsPem(File certificateChain, File privateKey, @Nullable String keyPassword)
      Serves TLS using PEM files.
      Parameters:
      certificateChain - PEM certificate chain, leaf first
      privateKey - PEM private key for the leaf certificate
      keyPassword - Password for privateKey, or null if unencrypted
      Returns:
      This builder
      Throws:
      IllegalArgumentException - If either file cannot be read
    • setTrustedProxies

      public NetherNetHTTPSignaling.Builder setTrustedProxies(Collection<String> trustedProxies)
      Sets the reverse proxies whose X-Forwarded-For header is honoured, as single addresses or CIDR ranges. Requests from anywhere else keep their peer address.
      Parameters:
      trustedProxies - Addresses or CIDR ranges, such as 10.0.0.0/8
      Returns:
      This builder
    • setIceOnLocalPort

      public NetherNetHTTPSignaling.Builder setIceOnLocalPort(boolean iceOnLocalPort)
      Sets whether ICE may gather on the port signalling binds to. Defaults to true. Set it false when another transport, such as RakNet, already holds the UDP side of that port.
      Parameters:
      iceOnLocalPort - Whether ICE may use the signalling port
      Returns:
      This builder
    • setAdvertisedAddresses

      public NetherNetHTTPSignaling.Builder setAdvertisedAddresses(Collection<String> advertisedAddresses)
      Sets the only local addresses that may be announced as ICE candidates. Empty, the default, announces every address ICE gathers.
      Parameters:
      advertisedAddresses - Addresses reachable by connecting peers
      Returns:
      This builder
      See Also:
    • setTokenTrust

      public NetherNetHTTPSignaling.Builder setTokenTrust(TokenTrust tokenTrust)
      Sets who to trust to have signed the token in a joining peer's identity assertion. Defaults to TokenTrust.MINECRAFT_AUTH, which is what a retail client presents.
      Parameters:
      tokenTrust - The trust policy
      Returns:
      This builder
    • setProxyProtocol

      public NetherNetHTTPSignaling.Builder setProxyProtocol(boolean proxyProtocol)
      Sets whether to read a HAProxy PROXY header, v1 or v2, from connections that arrive from a trusted proxy. Defaults to false.

      Only connections from setTrustedProxies(java.util.Collection<java.lang.String>) are looked at, and a connection that carries no header is served normally, so a listener can take both. The header is read before TLS, which is where a proxy puts it.

      Parameters:
      proxyProtocol - Whether to accept PROXY headers
      Returns:
      This builder
    • setServeHttp

      public NetherNetHTTPSignaling.Builder setServeHttp(boolean serveHttp)
      Sets whether to serve the HTTP join endpoint. Defaults to true. With it off nothing is listened on and offers have to be handed in through NetherNetHTTPSignaling.acceptOffer(java.lang.String, java.lang.String, java.net.InetSocketAddress, java.lang.String), which is how an endpoint outside this process drives signalling.
      Parameters:
      serveHttp - Whether to bind the join endpoint
      Returns:
      This builder
    • setPlayerFilter

      Sets the filter consulted for each join once its identity has been validated. Defaults to allowing everyone.
      Parameters:
      playerFilter - The filter to consult
      Returns:
      This builder
    • setMotdProvider

      Sets the provider called for each status request. Defaults to NetherNetServerSignaling.PongData.DEFAULT.
      Parameters:
      motdProvider - The provider to call
      Returns:
      This builder
    • setMotd

      Sets a fixed MOTD to advertise for every status request.
      Parameters:
      motd - The MOTD to advertise
      Returns:
      This builder
    • build

      public NetherNetHTTPSignaling build()
      Builds the signalling instance.
      Returns:
      A new signalling instance
      Throws:
      IllegalStateException - If no identity was set