add support for providing a custom Connection ID generator via Config (#3452)

* Add support for providing a custom ConnectionID generator via Config

This work makes it possible for servers or clients to control how
ConnectionIDs are generated, which in turn will force peers in the
connection to use those ConnectionIDs as destination connection IDs  when sending packets.

This is useful for scenarios where we want to perform some kind
selection on the QUIC packets at the L4 level.

* add more doc

* refactor populate config to not use provided config

* add an integration test for custom connection ID generators

* fix linter warnings

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
This commit is contained in:
João Oliveirinha
2022-08-24 12:06:16 +01:00
committed by GitHub
parent 034fc4e09a
commit 66f6fe0b71
11 changed files with 124 additions and 38 deletions

View File

@@ -42,11 +42,8 @@ type client struct {
logger utils.Logger
}
var (
// make it possible to mock connection ID generation in the tests
generateConnectionID = protocol.GenerateConnectionID
generateConnectionIDForInitial = protocol.GenerateConnectionIDForInitial
)
// make it possible to mock connection ID for initial generation in the tests
var generateConnectionIDForInitial = protocol.GenerateConnectionIDForInitial
// DialAddr establishes a new QUIC connection to a server.
// It uses a new UDP connection and closes this connection when the QUIC connection is closed.
@@ -193,7 +190,7 @@ func dialContext(
return nil, err
}
config = populateClientConfig(config, createdPacketConn)
packetHandlers, err := getMultiplexer().AddConn(pconn, config.ConnectionIDLength, config.StatelessResetKey, config.Tracer)
packetHandlers, err := getMultiplexer().AddConn(pconn, config.ConnectionIDGenerator.ConnectionIDLen(), config.StatelessResetKey, config.Tracer)
if err != nil {
return nil, err
}
@@ -256,7 +253,7 @@ func newClient(
}
}
srcConnID, err := generateConnectionID(config.ConnectionIDLength)
srcConnID, err := config.ConnectionIDGenerator.GenerateConnectionID()
if err != nil {
return nil, err
}