Only parse packet length once per packet. See #382
This commit is contained in:
parent
f759d30538
commit
a56ea06e58
@ -166,7 +166,6 @@ public class SslHandler extends StreamToStreamCodec {
|
|||||||
private final SslBufferPool bufferPool;
|
private final SslBufferPool bufferPool;
|
||||||
private final Executor delegatedTaskExecutor;
|
private final Executor delegatedTaskExecutor;
|
||||||
|
|
||||||
// TODO: Fix STARTTLS
|
|
||||||
private final boolean startTls;
|
private final boolean startTls;
|
||||||
private boolean sentFirstMessage;
|
private boolean sentFirstMessage;
|
||||||
|
|
||||||
@ -184,6 +183,8 @@ public class SslHandler extends StreamToStreamCodec {
|
|||||||
|
|
||||||
private final SSLEngineInboundCloseFuture sslEngineCloseFuture = new SSLEngineInboundCloseFuture();
|
private final SSLEngineInboundCloseFuture sslEngineCloseFuture = new SSLEngineInboundCloseFuture();
|
||||||
|
|
||||||
|
private int packetLength = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance.
|
* Creates a new instance.
|
||||||
*
|
*
|
||||||
@ -610,14 +611,12 @@ public class SslHandler extends StreamToStreamCodec {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(ChannelInboundHandlerContext<Byte> ctx, ChannelBuffer in, ChannelBuffer out) throws Exception {
|
public void decode(ChannelInboundHandlerContext<Byte> ctx, ChannelBuffer in, ChannelBuffer out) throws Exception {
|
||||||
|
|
||||||
|
// check if the packet lenght was read before
|
||||||
|
if (packetLength == -1) {
|
||||||
if (in.readableBytes() < 5) {
|
if (in.readableBytes() < 5) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
in.markReaderIndex();
|
|
||||||
|
|
||||||
|
|
||||||
int packetLength = 0;
|
|
||||||
|
|
||||||
// SSLv3 or TLS - Check ContentType
|
// SSLv3 or TLS - Check ContentType
|
||||||
boolean tls;
|
boolean tls;
|
||||||
switch (in.getUnsignedByte(in.readerIndex())) {
|
switch (in.getUnsignedByte(in.readerIndex())) {
|
||||||
@ -679,13 +678,12 @@ public class SslHandler extends StreamToStreamCodec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert packetLength > 0;
|
assert packetLength > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (in.readableBytes() < packetLength) {
|
if (in.readableBytes() < packetLength) {
|
||||||
// not enough bytes so reset the reader index and return
|
// not enough bytes left to read the packet
|
||||||
//
|
// so return here for now
|
||||||
// TODO: store the parsed packetlength and reuse it. This will safe us from re-parse it
|
|
||||||
in.resetReaderIndex();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -705,7 +703,12 @@ public class SslHandler extends StreamToStreamCodec {
|
|||||||
// before calling the user code.
|
// before calling the user code.
|
||||||
final int packetOffset = in.readerIndex();
|
final int packetOffset = in.readerIndex();
|
||||||
in.skipBytes(packetLength);
|
in.skipBytes(packetLength);
|
||||||
|
try {
|
||||||
unwrap(ctx, ctx.channel(), in, packetOffset, packetLength, out);
|
unwrap(ctx, ctx.channel(), in, packetOffset, packetLength, out);
|
||||||
|
} finally {
|
||||||
|
// reset packet length
|
||||||
|
packetLength = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user