Skip to content

Commit

Permalink
Allow the QuicConnectionIdGenerator also take the source connection i…
Browse files Browse the repository at this point in the history
…d into account

Motivation:

Sometimes its useful to use the source and destination connection id to generate a connection id

Modifications:

- Add new default method to QuicConnectionIdGenerator that implementations can implement
- Call new method when it makes sense

Result:

More flexible connection id generation on the server
  • Loading branch information
normanmaurer committed Dec 11, 2024
1 parent 4a6ccab commit 18c4b22
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@ public ByteBuffer newId(ByteBuffer input, int length) {
return idGenerator.newId(input, length);
}

@Override
public ByteBuffer newId(ByteBuffer scid, ByteBuffer dcid, int length) {
if (length > Short.BYTES) {
return encodeIdx(idGenerator.newId(scid, dcid, length - Short.BYTES), idx);
}
return idGenerator.newId(scid, dcid, length);
}

@Override
public int maxConnectionIdLength() {
return idGenerator.maxConnectionIdLength();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ public interface QuicConnectionIdGenerator {
*/
ByteBuffer newId(ByteBuffer input, int length);

/**
* Creates a new connection id with the given length. The given source connection id and destionation connection id
* may be used to sign or seed the id, or may be ignored (depending on the implementation).
*
* @param scid the source connection id which may be used to generate the id.
* @param dcid the destination connection id which may be used to generate the id.
* @param length the length of the id.
* @return the id.
*/
default ByteBuffer newId(ByteBuffer scid, ByteBuffer dcid, int length) {
return newId(dcid, length);
}

/**
* Returns the maximum length of a connection id.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ private QuicheQuicChannel handleServer(ChannelHandlerContext ctx, InetSocketAddr
// The remote peer did not send a token.
if (tokenHandler.writeToken(mintTokenBuffer, dcid, sender)) {
ByteBuffer connId = connectionIdAddressGenerator.newId(
dcid.internalNioBuffer(dcid.readerIndex(), dcid.readableBytes()), localConnIdLength);
scid.internalNioBuffer(scid.readerIndex(), scid.readableBytes()),
dcid.internalNioBuffer(dcid.readerIndex(), dcid.readableBytes()),
localConnIdLength);
connIdBuffer.writeBytes(connId);

ByteBuf out = ctx.alloc().directBuffer(Quic.MAX_DATAGRAM_SIZE);
Expand Down

0 comments on commit 18c4b22

Please sign in to comment.