Class Endpoint
java.lang.Object
io.github.mahmoudimus.quic.connection.Endpoint
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceWhat to do with a datagram. -
Constructor Summary
ConstructorsConstructorDescriptionEndpoint(EndpointConfig config, ServerConfig serverConfig, boolean allowMtud) An endpoint. -
Method Summary
Modifier and TypeMethodDescriptionconfig()The endpoint's settings.connect(long now, ClientConfig clientConfig, InetSocketAddress remote, String serverName) Starts a client 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.The connections the endpoint routes to, until each is drained.longConnections refused before they started, with CONNECTION_CLOSE in an Initial packet (server busy, an invalid token or connection ID).handle(long now, InetSocketAddress remote, int ecn, ByteBuffer datagram) Routes a datagram.handle(long now, InetSocketAddress remote, int ecn, ByteBuffer datagram, ServerConfig accept) Routes a datagram, accepting a connection it starts withacceptinstead 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.voidhandleEvent(Connection conn, EndpointEvent event) Applies a connection's endpoint event to the routes.booleanisServer()Whether this endpoint accepts connections.intThe number of local connection IDs routed, for tests and monitoring.booleanknows(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): whathandle(long, java.net.InetSocketAddress, int, java.nio.ByteBuffer)would deliver, short of stateless resets.intThe number of connections.longRetry packets sent, to validate clients' addresses.longStateless resets sent, for packets of connections this endpoint does not know.longVersion Negotiation packets sent, to clients that offered no version this endpoint supports.
-
Constructor Details
-
Endpoint
An endpoint.- Parameters:
config- the endpoint's settingsserverConfig- how to accept connections, or null for a client-only endpointallowMtud- 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 timeremote- the senderecn- the ECN codepointdatagram- 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 withacceptinstead 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 timeremote- the senderecn- the ECN codepointdatagram- the datagram, between its position and limit; not modifiedaccept- 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
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): whathandle(long, java.net.InetSocketAddress, int, java.nio.ByteBuffer)would deliver, short of stateless resets. Nothing changes.- Parameters:
remote- the senderdatagram- 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 timeclientConfig- how to connectremote- the server's addressserverName- 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 timeclientConfig- how to connectremote- the server's addressserverName- the server name for SNI and certificate checks, or null for the TLS configuration'scache- 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
Applies a connection's endpoint event to the routes.- Parameters:
conn- the connectionevent- the event fromConnection.pollEndpointEvent()
-
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
The endpoint's settings.- Returns:
- the settings
-
isServer
public boolean isServer()Whether this endpoint accepts connections.- Returns:
- true for a server
-