From 2f3587ef6d611f4b8f0c0d5430146e19ebf4b927 Mon Sep 17 00:00:00 2001 From: Ludovic Orban Date: Wed, 31 Mar 2021 16:06:00 +0200 Subject: [PATCH] refactor session creation Signed-off-by: Ludovic Orban --- .../http3/client/ClientQuicConnection.java | 7 +++++-- .../jetty/http3/common/QuicConnection.java | 20 ++++++------------- .../jetty/http3/common/QuicSession.java | 2 +- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/jetty-http3/http3-client/src/main/java/org/eclipse/jetty/http3/client/ClientQuicConnection.java b/jetty-http3/http3-client/src/main/java/org/eclipse/jetty/http3/client/ClientQuicConnection.java index ef07240afa1..f0783e85539 100644 --- a/jetty-http3/http3-client/src/main/java/org/eclipse/jetty/http3/client/ClientQuicConnection.java +++ b/jetty-http3/http3-client/src/main/java/org/eclipse/jetty/http3/client/ClientQuicConnection.java @@ -103,9 +103,12 @@ public class ClientQuicConnection extends QuicConnection } @Override - protected QuicSession createSession(InetSocketAddress remoteAddress, ByteBuffer cipherBuffer) + protected QuicSession createSession(InetSocketAddress remoteAddress, ByteBuffer cipherBuffer) throws IOException { - return pendingSessions.get(remoteAddress); + QuicSession session = pendingSessions.get(remoteAddress); + if (session != null) + session.process(remoteAddress, cipherBuffer); + return session; } @Override diff --git a/jetty-http3/http3-common/src/main/java/org/eclipse/jetty/http3/common/QuicConnection.java b/jetty-http3/http3-common/src/main/java/org/eclipse/jetty/http3/common/QuicConnection.java index d84fdcbfa48..1fcc6054e86 100644 --- a/jetty-http3/http3-common/src/main/java/org/eclipse/jetty/http3/common/QuicConnection.java +++ b/jetty-http3/http3-common/src/main/java/org/eclipse/jetty/http3/common/QuicConnection.java @@ -118,26 +118,18 @@ public abstract class QuicConnection extends AbstractConnection if (LOG.isDebugEnabled()) LOG.debug("packet contains connection ID {}", quicheConnectionId); - boolean created = false; QuicSession session = sessions.get(quicheConnectionId); if (session == null) { session = createSession(remoteAddress, cipherBuffer); - if (session == null) - continue; - created = true; + if (session != null && promoteSession(quicheConnectionId, session)) + sessions.put(quicheConnectionId, session); + continue; } - // createSession() may have consumed the cipherBuffer - if (cipherBuffer.hasRemaining()) - { - if (LOG.isDebugEnabled()) - LOG.debug("packet is for existing session with connection ID {}, processing it ({} byte(s))", quicheConnectionId, cipherBuffer.remaining()); - session.process(remoteAddress, cipherBuffer); - } - - if (created && promoteSession(quicheConnectionId, session)) - sessions.put(quicheConnectionId, session); + if (LOG.isDebugEnabled()) + LOG.debug("packet is for existing session with connection ID {}, processing it ({} byte(s))", quicheConnectionId, cipherBuffer.remaining()); + session.process(remoteAddress, cipherBuffer); } } catch (Throwable x) diff --git a/jetty-http3/http3-common/src/main/java/org/eclipse/jetty/http3/common/QuicSession.java b/jetty-http3/http3-common/src/main/java/org/eclipse/jetty/http3/common/QuicSession.java index 148e956c6ae..c00cb595e02 100644 --- a/jetty-http3/http3-common/src/main/java/org/eclipse/jetty/http3/common/QuicSession.java +++ b/jetty-http3/http3-common/src/main/java/org/eclipse/jetty/http3/common/QuicSession.java @@ -147,7 +147,7 @@ public abstract class QuicSession this.quicheConnectionId = quicheConnectionId; } - void process(InetSocketAddress remoteAddress, ByteBuffer cipherBufferIn) throws IOException + public void process(InetSocketAddress remoteAddress, ByteBuffer cipherBufferIn) throws IOException { this.remoteAddress = remoteAddress; quicheConnection.feedCipherText(cipherBufferIn);