Class ServerConfig.Builder

java.lang.Object
io.github.mahmoudimus.quic.connection.ServerConfig.Builder
Enclosing class:
ServerConfig

public static final class ServerConfig.Builder extends Object
Builds a ServerConfig. Not thread-safe.
  • Method Details

    • transport

      public ServerConfig.Builder transport(TransportConfig transport)
      The transport settings.
      Parameters:
      transport - the settings
      Returns:
      this builder
    • retry

      public ServerConfig.Builder retry(boolean retry)
      Turns Retry-based address validation on or off (off by default).
      Parameters:
      retry - whether to send Retry to clients without a valid token
      Returns:
      this builder
    • tokenKey

      public ServerConfig.Builder tokenKey(TokenKey key)
      The key Retry tokens are sealed with; servers behind one address share it.
      Parameters:
      key - the key, or null for a random one
      Returns:
      this builder
    • retryTokenLifetime

      public ServerConfig.Builder retryTokenLifetime(Duration lifetime)
      How long a Retry token stays valid.
      Parameters:
      lifetime - the lifetime, 15 seconds by default
      Returns:
      this builder
    • newTokens

      public ServerConfig.Builder newTokens(int count)
      How many NEW_TOKEN tokens to send each client after its handshake (RFC 9000 section 8.1.3). A client presents one in its next connection's first Initial, which validates its address so that Retry is skipped; each token is accepted once.
      Parameters:
      count - 0 to send none; 2 by default, as quinn sends
      Returns:
      this builder
    • validationTokenLifetime

      public ServerConfig.Builder validationTokenLifetime(Duration lifetime)
      How long a NEW_TOKEN token stays valid.
      Parameters:
      lifetime - the lifetime, two weeks by default
      Returns:
      this builder
    • migration

      public ServerConfig.Builder migration(boolean migration)
      Whether clients may migrate (RFC 9000 section 9): on by default, as in quinn. A connection then follows a client to a new address once a non-probing packet arrives from it, validates the new path, and goes back to the old one if validation fails. Off, the server sends disable_active_migration and drops packets from any address but the one the handshake used; a client may still move to the preferred address.
      Parameters:
      migration - whether to allow migration
      Returns:
      this builder
    • preferredAddress

      public ServerConfig.Builder preferredAddress(InetSocketAddress ipv4, InetSocketAddress ipv6)
      Advertises a preferred address (RFC 9000 section 9.6) in the preferred_address transport parameter, with a connection ID of its own: a client may validate it after the handshake and move there. The server must receive datagrams at the address; QuicServer binds a socket to each address given (port 0 takes an ephemeral port, which is then advertised).
      Parameters:
      ipv4 - the IPv4 address, or null
      ipv6 - the IPv6 address, or null
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if an address is of the other family
    • maxConnections

      public ServerConfig.Builder maxConnections(int max)
      The most connections held at once.
      Parameters:
      max - at least 1; 4096 by default
      Returns:
      this builder
    • clock

      public ServerConfig.Builder clock(InstantSource clock)
      The wall clock token expiry is checked against.
      Parameters:
      clock - the clock
      Returns:
      this builder
    • build

      public ServerConfig build()
      Builds the configuration.
      Returns:
      the configuration