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

Cleanup connect implementation #659

Merged
merged 1 commit into from
Feb 4, 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 @@ -317,9 +317,9 @@ void attachQuicheConnection(QuicheQuicConnection connection) {
}
}

private void connect(Function<QuicChannel, ? extends QuicSslEngine> engineProvider, Executor sslTaskExecutor,
long configAddr, int localConnIdLength,
boolean supportsDatagram, ByteBuffer fromSockaddrMemory, ByteBuffer toSockaddrMemory)
void connectNow(Function<QuicChannel, ? extends QuicSslEngine> engineProvider, Executor sslTaskExecutor,
long configAddr, int localConnIdLength,
boolean supportsDatagram, ByteBuffer fromSockaddrMemory, ByteBuffer toSockaddrMemory)
throws Exception {
assert this.connection == null;
assert this.traceId == null;
Expand Down Expand Up @@ -1854,34 +1854,6 @@ private void notifyEarlyDataReadyIfNeeded() {
}
}

// TODO: Come up with something better.
static QuicheQuicChannel handleConnect(Function<QuicChannel, ? extends QuicSslEngine> sslEngineProvider,
Executor sslTaskExecutor,
SocketAddress address, long config, int localConnIdLength,
boolean supportsDatagram, ByteBuffer fromSockaddrMemory,
ByteBuffer toSockaddrMemory) throws Exception {
if (address instanceof QuicheQuicChannel.QuicheQuicChannelAddress) {
QuicheQuicChannel.QuicheQuicChannelAddress addr = (QuicheQuicChannel.QuicheQuicChannelAddress) address;
QuicheQuicChannel channel = addr.channel;
channel.connect(sslEngineProvider, sslTaskExecutor, config, localConnIdLength, supportsDatagram,
fromSockaddrMemory, toSockaddrMemory);
return channel;
}
return null;
}

/**
* Just a container to pass the {@link QuicheQuicChannel} to {@link QuicheQuicClientCodec}.
*/
private static final class QuicheQuicChannelAddress extends SocketAddress {

final QuicheQuicChannel channel;

QuicheQuicChannelAddress(QuicheQuicChannel channel) {
this.channel = channel;
}
}

private final class TimeoutHandler implements Runnable {
private ScheduledFuture<?> timeoutFuture;
private final Consumer<QuicheQuicChannel> timeoutTask;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.incubator.codec.quic;

import java.net.SocketAddress;

/**
* Just a container to pass the {@link QuicheQuicChannel} to {@link QuicheQuicClientCodec}.
*/
final class QuicheQuicChannelAddress extends SocketAddress {

final QuicheQuicChannel channel;

QuicheQuicChannelAddress(QuicheQuicChannel channel) {
this.channel = channel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,25 @@ protected QuicheQuicChannel quicPacketRead(
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress,
SocketAddress localAddress, ChannelPromise promise) {
final QuicheQuicChannel channel;
try {
channel = QuicheQuicChannel.handleConnect(sslEngineProvider, sslTaskExecutor, remoteAddress, config.nativeAddress(),
localConnIdLength, config.isDatagramSupported(),
senderSockaddrMemory.internalNioBuffer(0, senderSockaddrMemory.capacity()),
recipientSockaddrMemory.internalNioBuffer(0, recipientSockaddrMemory.capacity()));
} catch (Exception e) {
promise.setFailure(e);
return;
}
if (channel != null) {
addChannel(channel);
if (remoteAddress instanceof QuicheQuicChannelAddress) {
QuicheQuicChannelAddress addr = (QuicheQuicChannelAddress) remoteAddress;
QuicheQuicChannel channel = addr.channel;
try {
channel.connectNow(sslEngineProvider, sslTaskExecutor, config.nativeAddress(),
localConnIdLength, config.isDatagramSupported(),
senderSockaddrMemory.internalNioBuffer(0, senderSockaddrMemory.capacity()),
recipientSockaddrMemory.internalNioBuffer(0, recipientSockaddrMemory.capacity()));
} catch (Throwable cause) {
promise.setFailure(cause);
return;
}

addChannel(channel);
channel.finishConnect();
promise.setSuccess();
return;
}

ctx.connect(remoteAddress, localAddress, promise);
}
}
Loading