Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the QuicConnectionIdGenerator also take the source connection i… #766

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Expand Up @@ -205,7 +207,9 @@ private QuicheQuicChannel handleServer(ChannelHandlerContext ctx, InetSocketAddr
if (noToken) {
connIdBuffer.clear();
key = connectionIdAddressGenerator.newId(
dcid.internalNioBuffer(dcid.readerIndex(), dcid.readableBytes()), localConnIdLength);
scid.internalNioBuffer(scid.readerIndex(), scid.readableBytes()),
dcid.internalNioBuffer(dcid.readerIndex(), dcid.readableBytes()),
localConnIdLength);
connIdBuffer.writeBytes(key.duplicate());
scidAddr = Quiche.readerMemoryAddress(connIdBuffer);
scidLen = localConnIdLength;
Expand Down
Loading