Class Endpoint

java.lang.Object
io.github.mahmoudimus.quic.connection.Endpoint

public final class Endpoint extends Object
The connections of one UDP socket, as a sans-I/O state machine after quinn-proto's Endpoint: it routes incoming datagrams to connections by Destination Connection ID, whatever address they come from, so that a connection follows a peer that migrates (or by the peer's address when local IDs are zero-length, which rules migration out), creates server connections from Initial packets, and answers what no connection should see: Version Negotiation for unknown versions, Retry for address validation, stateless resets for unknown connection IDs, and CONNECTION_CLOSE for refused attempts.

The I/O layer passes every datagram to handle(long, java.net.InetSocketAddress, int, java.nio.ByteBuffer), delivers the datagram to the connection it names, sends any response, and passes each connection's endpoint events back through handleEvent(io.github.mahmoudimus.quic.connection.Connection, io.github.mahmoudimus.quic.connection.EndpointEvent), which keeps the routes current as connection IDs are issued and retired.

Threads. Not thread-safe and takes no locks; the I/O layer serializes access.

  • Constructor Details

    • Endpoint

      public Endpoint(EndpointConfig config, ServerConfig serverConfig, boolean allowMtud)
      An endpoint.
      Parameters:
      config - the endpoint's settings
      serverConfig - how to accept connections, or null for a client-only endpoint
      allowMtud - whether the socket never fragments datagrams, which path MTU discovery needs
  • Method Details

    • handle

      public Endpoint.DatagramEvent handle(long now, InetSocketAddress remote, int ecn, ByteBuffer datagram)
      Routes a datagram.
      Parameters:
      now - the current time
      remote - the sender
      ecn - the ECN codepoint
      datagram - the datagram, between its position and limit; not modified
      Returns:
      what to do with it, or null to drop it
    • handle

      public Endpoint.DatagramEvent handle(long now, InetSocketAddress remote, int ecn, ByteBuffer datagram, ServerConfig accept)
      Routes a datagram, accepting a connection it starts with accept instead of the endpoint's server configuration: for a server whose connections differ, such as a proxy that offers each client the protocols and transport parameters of the server it reaches.
      Parameters:
      now - the current time
      remote - the sender
      ecn - the ECN codepoint
      datagram - the datagram, between its position and limit; not modified
      accept - how to accept a connection the datagram starts, or null for the endpoint's own configuration
      Returns:
      what to do with it, or null to drop it
    • knows

      public boolean knows(InetSocketAddress remote, ByteBuffer datagram)
      Whether a datagram belongs to one of the endpoint's connections, by its first packet's Destination Connection ID (or the sender's address, for zero-length IDs): what handle(long, java.net.InetSocketAddress, int, java.nio.ByteBuffer) would deliver, short of stateless resets. Nothing changes.
      Parameters:
      remote - the sender
      datagram - the datagram, between its position and limit; not modified
      Returns:
      whether a connection would get it
    • versionNegotiationsSent

      public long versionNegotiationsSent()
      Version Negotiation packets sent, to clients that offered no version this endpoint supports.
      Returns:
      the count
    • retriesSent

      public long retriesSent()
      Retry packets sent, to validate clients' addresses.
      Returns:
      the count
    • statelessResetsSent

      public long statelessResetsSent()
      Stateless resets sent, for packets of connections this endpoint does not know.
      Returns:
      the count
    • connectionsRefused

      public long connectionsRefused()
      Connections refused before they started, with CONNECTION_CLOSE in an Initial packet (server busy, an invalid token or connection ID).
      Returns:
      the count
    • connect

      public Connection connect(long now, ClientConfig clientConfig, InetSocketAddress remote, String serverName)
      Starts a client connection.
      Parameters:
      now - the current time
      clientConfig - how to connect
      remote - the server's address
      serverName - the server name for SNI and certificate checks, or null for the TLS configuration's
      Returns:
      the connection, with its first Initial ready in Connection.pollTransmit(long, int)
      Throws:
      IllegalArgumentException - if the address is unusable or the version is not enabled
    • connect

      public Connection connect(long now, ClientConfig clientConfig, InetSocketAddress remote, String serverName, SessionCache cache)
      Starts a client connection with a cache of session tickets and tokens: it resumes with a ticket from the cache (and sends 0-RTT data if the ticket and the TLS configuration allow it), presents a token from the cache, and keeps the tickets and tokens it receives.
      Parameters:
      now - the current time
      clientConfig - how to connect
      remote - the server's address
      serverName - the server name for SNI and certificate checks, or null for the TLS configuration's
      cache - the cache, or null for none
      Returns:
      the connection, with its first Initial (and any 0-RTT data) ready in Connection.pollTransmit(long, int)
      Throws:
      IllegalArgumentException - if the address is unusable or the version is not enabled
    • handleEvent

      public void handleEvent(Connection conn, EndpointEvent event)
      Applies a connection's endpoint event to the routes.
      Parameters:
      conn - the connection
      event - the event from Connection.pollEndpointEvent()
    • connections

      public List<Connection> connections()
      The connections the endpoint routes to, until each is drained.
      Returns:
      a snapshot
    • openConnections

      public int openConnections()
      The number of connections.
      Returns:
      the count
    • knownCids

      public int knownCids()
      The number of local connection IDs routed, for tests and monitoring.
      Returns:
      the count
    • config

      public EndpointConfig config()
      The endpoint's settings.
      Returns:
      the settings
    • isServer

      public boolean isServer()
      Whether this endpoint accepts connections.
      Returns:
      true for a server