Skip to content

Commit

Permalink
Merge branch 'apache-3.1' into apache-3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ committed Mar 6, 2023
2 parents 516c61b + 7277c15 commit d711300
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public class TelnetDetector implements ProtocolDetector {

private FrameworkModel frameworkModel;
private final FrameworkModel frameworkModel;
private final int MaxSize = 2048;
private final ChannelBuffer AytPreface = new HeapChannelBuffer(new byte[]{(byte) 0xff, (byte) 0xf6});

Expand All @@ -46,7 +46,7 @@ public Result detect(ChannelBuffer in) {
return Result.UNRECOGNIZED;
}
Result resCommand = commandDetect(in);
if (resCommand.equals(Result.RECOGNIZED)){
if (resCommand.equals(Result.RECOGNIZED)) {
return resCommand;
}
Result resAyt = telnetAytDetect(in);
Expand All @@ -62,14 +62,19 @@ public Result detect(ChannelBuffer in) {
private Result commandDetect(ChannelBuffer in) {
// detect if remote channel send a qos command to server
ChannelBuffer back = in.copy();
byte[] backBytes = new byte[back.readableBytes()];
back.getBytes(back.readerIndex(), backBytes);
byte[] backBytes;
try {
backBytes = new byte[back.readableBytes()];
back.getBytes(back.readerIndex(), backBytes);
} finally {
back.release();
}

String s = new String(backBytes, CharsetUtil.UTF_8);
// trim /r/n to let parser work for input
s = s.trim();
CommandContext commandContext = TelnetCommandDecoder.decode(s);
if(frameworkModel.getExtensionLoader(BaseCommand.class).hasExtension(commandContext.getCommandName())){
if (frameworkModel.getExtensionLoader(BaseCommand.class).hasExtension(commandContext.getCommandName())) {
return Result.RECOGNIZED;
}
return Result.UNRECOGNIZED;
Expand All @@ -79,10 +84,10 @@ private Result telnetAytDetect(ChannelBuffer in) {
// detect if remote channel send a telnet ayt command to server
int prefaceLen = AytPreface.readableBytes();
int bytesRead = min(in.readableBytes(), prefaceLen);
if(bytesRead == 0 || !ChannelBuffers.prefixEquals(in, AytPreface, bytesRead)) {
if (bytesRead == 0 || !ChannelBuffers.prefixEquals(in, AytPreface, bytesRead)) {
return Result.UNRECOGNIZED;
}
if(bytesRead == prefaceLen) {
if (bytesRead == prefaceLen) {
// we need to consume preface because it's not a qos command
// consume and remember to mark, pu server handler reset reader index
in.readBytes(AytPreface.readableBytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -948,4 +948,12 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
* array
*/
int arrayOffset();

/**
* If this buffer is backed by an NIO direct buffer,
* in some scenarios it may be necessary to manually release.
*/
default void release() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,9 @@ public boolean hasArray() {
public int arrayOffset() {
return buffer.arrayOffset();
}

@Override
public void release() {
buffer.release();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.dubbo.remoting.buffer.ChannelBuffers;

import io.netty.buffer.ByteBuf;
import io.netty.util.ReferenceCountUtil;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -448,4 +449,9 @@ public void writerIndex(int writerIndex) {
public int compareTo(ChannelBuffer o) {
return ChannelBuffers.compare(this, o);
}

@Override
public void release() {
ReferenceCountUtil.safeRelease(buffer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,12 @@ public byte[] pack(Object obj) throws IOException {
for (String type : argumentsType) {
builder.addArgTypes(type);
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
for (int i = 0; i < arguments.length; i++) {
Object argument = arguments[i];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
multipleSerialization.serialize(url, serialize, actualRequestTypes[i], argument, bos);
builder.addArgs(bos.toByteArray());
bos.reset();
}
return builder.build().toByteArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public Builder setSerializeType(String serializeType) {
}

public Builder addArgTypes(String argsType) {
Assert.notEmptyString(argsType, "argsType不能为空");
Assert.notEmptyString(argsType, "argsType cannot be empty.");
argTypes.add(argsType);
return this;
}
Expand Down

0 comments on commit d711300

Please sign in to comment.