2020import io .netty .handler .codec .quic .QuicStreamLimitChangedEvent ;
2121import io .netty .handler .logging .ByteBufFormat ;
2222import io .netty .handler .ssl .SniCompletionEvent ;
23- import io .vertx .core .Handler ;
23+ import io .netty .handler .ssl .SslHandshakeCompletionEvent ;
24+ import io .vertx .core .Completable ;
2425import io .vertx .core .buffer .Buffer ;
2526import io .vertx .core .internal .ContextInternal ;
2627import io .vertx .core .internal .net .SslHandshakeCompletionHandler ;
@@ -51,15 +52,15 @@ private static long timeoutMillis(Duration timeout) {
5152 private final int maxStreamBidiRequests ;
5253 private final int maxStreamUniRequests ;
5354 private final boolean server ;
54- private Handler < QuicConnection > handler ;
55- private QuicChannel channel ;
55+ private final SocketAddress remoteAddress ;
56+ private Completable < QuicConnection > handler ;
5657 private QuicConnectionImpl connection ;
57- private SocketAddress remoteAddress ;
58+ private int maxDatagramLength ;
5859
5960 public QuicConnectionHandler (ContextInternal context , TransportMetrics <?> metrics , Duration idleTimeout ,
6061 Duration readIdleTimeout , Duration writeIdleTimeout , ByteBufFormat activityLogging ,
6162 int maxStreamBidiRequests , int maxStreamUniRequests , SocketAddress remoteAddress ,
62- boolean server , Handler <QuicConnection > handler ) {
63+ boolean server , Completable <QuicConnection > handler ) {
6364 this .context = context ;
6465 this .metrics = metrics ;
6566 this .idleTimeout = timeoutMillis (idleTimeout );
@@ -73,29 +74,24 @@ public QuicConnectionHandler(ContextInternal context, TransportMetrics<?> metric
7374 this .server = server ;
7475 }
7576
76- @ Override
77- public void handlerAdded (ChannelHandlerContext ctx ) {
78- QuicChannel ch = (QuicChannel ) ctx .channel ();
79- channel = ch ;
80- connection = new QuicConnectionImpl (context , metrics , idleTimeout , readIdleTimeout , writeIdleTimeout , activityLogging ,
81- maxStreamBidiRequests , maxStreamUniRequests , ch , remoteAddress , ctx , server );
82- }
83-
8477 @ Override
8578 public void channelActive (ChannelHandlerContext ctx ) throws Exception {
86- super .channelActive (ctx );
87- activate ();
79+ activate (ctx );
8880 }
8981
90- private void activate () {
82+ private void activate (ChannelHandlerContext ctx ) {
83+ QuicChannel ch = (QuicChannel ) ctx .channel ();
84+ QuicConnectionImpl c = new QuicConnectionImpl (context , metrics , idleTimeout , readIdleTimeout , writeIdleTimeout , activityLogging ,
85+ maxStreamBidiRequests , maxStreamUniRequests , maxDatagramLength , ch , remoteAddress , ctx , server );
86+ connection = c ;
9187 if (metrics != null ) {
92- Object metric = metrics .connected (connection .remoteAddress (), connection .remoteName ());
93- connection .metric (metric );
88+ Object metric = metrics .connected (c .remoteAddress (), c .remoteName ());
89+ c .metric (metric );
9490 }
95- Handler <QuicConnection > h = handler ;
91+ Completable <QuicConnection > h = handler ;
9692 if (h != null ) {
9793 handler = null ;
98- context . dispatch ( connection , h );
94+ h . succeed ( c );
9995 }
10096 }
10197
@@ -131,22 +127,29 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
131127 c .shutdown (shutdown .timeout ());
132128 }
133129 } else if (evt instanceof QuicStreamLimitChangedEvent ) {
134- connection .handleQuicStreamLimitChanged ();
130+ QuicConnectionImpl c = connection ;
131+ if (c != null ) {
132+ c .handleQuicStreamLimitChanged ();
133+ }
135134 } else if (evt instanceof QuicDatagramExtensionEvent ) {
136135 QuicDatagramExtensionEvent datagramExtensionEvent = (QuicDatagramExtensionEvent ) evt ;
137- QuicConnectionImpl c = connection ;
138- c .enableDatagramExtension (datagramExtensionEvent .maxLength ());
139-
140- // Activate at this moment, since the handler activation happens before we get relevant information
141- // datagram extension event is last, see QuicheQuicChannel
142- activate ();
136+ this .maxDatagramLength = datagramExtensionEvent .maxLength ();
137+ } else if (evt instanceof SslHandshakeCompletionEvent ) {
138+ SslHandshakeCompletionEvent handshakeEvt = (SslHandshakeCompletionEvent )evt ;
139+ if (!handshakeEvt .isSuccess ()) {
140+ Completable <QuicConnection > h = handler ;
141+ if (h != null ) {
142+ h .fail (handshakeEvt .cause ());
143+ }
144+ }
143145 }
144146 super .userEventTriggered (ctx , evt );
145147 }
146148
147149 @ Override
148150 public void exceptionCaught (ChannelHandlerContext chctx , final Throwable t ) {
149- if (connection .handleException (t )) {
151+ QuicConnectionImpl c = connection ;
152+ if (c != null && c .handleException (t )) {
150153 chctx .close ();
151154 }
152155 }
0 commit comments