Fix inspector warnings introduced by recent mergences
This commit is contained in:
parent
818a7b42a3
commit
6208c62888
|
@ -54,14 +54,17 @@ public abstract class AbstractByteBufAllocator implements ByteBufAllocator {
|
||||||
return heapBuffer(initialCapacity, maxCapacity);
|
return heapBuffer(initialCapacity, maxCapacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ByteBuf heapBuffer() {
|
public ByteBuf heapBuffer() {
|
||||||
return heapBuffer(256, Integer.MAX_VALUE);
|
return heapBuffer(256, Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ByteBuf heapBuffer(int initialCapacity) {
|
public ByteBuf heapBuffer(int initialCapacity) {
|
||||||
return buffer(initialCapacity, Integer.MAX_VALUE);
|
return buffer(initialCapacity, Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ByteBuf heapBuffer(int initialCapacity, int maxCapacity) {
|
public ByteBuf heapBuffer(int initialCapacity, int maxCapacity) {
|
||||||
if (initialCapacity == 0 && maxCapacity == 0) {
|
if (initialCapacity == 0 && maxCapacity == 0) {
|
||||||
return emptyBuf;
|
return emptyBuf;
|
||||||
|
@ -69,14 +72,17 @@ public abstract class AbstractByteBufAllocator implements ByteBufAllocator {
|
||||||
return newHeapBuffer(initialCapacity, maxCapacity);
|
return newHeapBuffer(initialCapacity, maxCapacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ByteBuf directBuffer() {
|
public ByteBuf directBuffer() {
|
||||||
return directBuffer(256, Integer.MAX_VALUE);
|
return directBuffer(256, Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ByteBuf directBuffer(int initialCapacity) {
|
public ByteBuf directBuffer(int initialCapacity) {
|
||||||
return directBuffer(initialCapacity, Integer.MAX_VALUE);
|
return directBuffer(initialCapacity, Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ByteBuf directBuffer(int initialCapacity, int maxCapacity) {
|
public ByteBuf directBuffer(int initialCapacity, int maxCapacity) {
|
||||||
if (initialCapacity == 0 && maxCapacity == 0) {
|
if (initialCapacity == 0 && maxCapacity == 0) {
|
||||||
return emptyBuf;
|
return emptyBuf;
|
||||||
|
|
|
@ -31,13 +31,6 @@ public final class SocksAuthRequest extends SocksRequest {
|
||||||
private final String username;
|
private final String username;
|
||||||
private final String password;
|
private final String password;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param username
|
|
||||||
* @param password
|
|
||||||
* @throws NullPointerException
|
|
||||||
* @throws IllegalArgumentException
|
|
||||||
*/
|
|
||||||
public SocksAuthRequest(String username, String password) {
|
public SocksAuthRequest(String username, String password) {
|
||||||
super(SocksRequestType.AUTH);
|
super(SocksRequestType.AUTH);
|
||||||
if (username == null) {
|
if (username == null) {
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class SocksAuthRequestDecoder extends ReplayingDecoder<SocksRequest, Sock
|
||||||
public SocksRequest decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
|
public SocksRequest decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
|
||||||
switch (state()) {
|
switch (state()) {
|
||||||
case CHECK_PROTOCOL_VERSION: {
|
case CHECK_PROTOCOL_VERSION: {
|
||||||
version = SocksMessage.ProtocolVersion.fromByte((byte) byteBuf.readByte());
|
version = SocksMessage.ProtocolVersion.fromByte(byteBuf.readByte());
|
||||||
if (version != SocksMessage.ProtocolVersion.SOCKS5) {
|
if (version != SocksMessage.ProtocolVersion.SOCKS5) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,15 +33,6 @@ public final class SocksCmdRequest extends SocksRequest {
|
||||||
private final String host;
|
private final String host;
|
||||||
private final int port;
|
private final int port;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param cmdType
|
|
||||||
* @param addressType
|
|
||||||
* @param host
|
|
||||||
* @param port
|
|
||||||
* @throws NullPointerException
|
|
||||||
* @throws IllegalArgumentException
|
|
||||||
*/
|
|
||||||
public SocksCmdRequest(CmdType cmdType, AddressType addressType, String host, int port) {
|
public SocksCmdRequest(CmdType cmdType, AddressType addressType, String host, int port) {
|
||||||
super(SocksRequestType.CMD);
|
super(SocksRequestType.CMD);
|
||||||
if (cmdType == null) {
|
if (cmdType == null) {
|
||||||
|
@ -72,7 +63,7 @@ public final class SocksCmdRequest extends SocksRequest {
|
||||||
case UNKNOWN:
|
case UNKNOWN:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((port < 0) && (port >= 65535)) {
|
if (port < 0 && port >= 65535) {
|
||||||
throw new IllegalArgumentException(port + " is not in bounds 0 < x < 65536");
|
throw new IllegalArgumentException(port + " is not in bounds 0 < x < 65536");
|
||||||
}
|
}
|
||||||
this.cmdType = cmdType;
|
this.cmdType = cmdType;
|
||||||
|
|
|
@ -34,12 +34,6 @@ public final class SocksCmdResponse extends SocksResponse {
|
||||||
0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00};
|
0x00, 0x00, 0x00, 0x00};
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param cmdStatus
|
|
||||||
* @param addressType
|
|
||||||
* @throws NullPointerException
|
|
||||||
*/
|
|
||||||
public SocksCmdResponse(CmdStatus cmdStatus, AddressType addressType) {
|
public SocksCmdResponse(CmdStatus cmdStatus, AddressType addressType) {
|
||||||
super(SocksResponseType.CMD);
|
super(SocksResponseType.CMD);
|
||||||
if (cmdStatus == null) {
|
if (cmdStatus == null) {
|
||||||
|
|
|
@ -32,10 +32,10 @@ final class SocksCommonUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String intToIp(int i) {
|
public static String intToIp(int i) {
|
||||||
return new StringBuilder().append((i >> FIRST_ADDRESS_OCTET_SHIFT) & XOR_DEFAULT_VALUE).append(".")
|
return String.valueOf(i >> FIRST_ADDRESS_OCTET_SHIFT & XOR_DEFAULT_VALUE) + '.' +
|
||||||
.append((i >> SECOND_ADDRESS_OCTET_SHIFT) & XOR_DEFAULT_VALUE).append(".")
|
(i >> SECOND_ADDRESS_OCTET_SHIFT & XOR_DEFAULT_VALUE) + '.' +
|
||||||
.append((i >> THIRD_ADDRESS_OCTET_SHIFT) & XOR_DEFAULT_VALUE).append(".")
|
(i >> THIRD_ADDRESS_OCTET_SHIFT & XOR_DEFAULT_VALUE) + '.' +
|
||||||
.append(i & XOR_DEFAULT_VALUE).toString();
|
(i & XOR_DEFAULT_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final char[] ipv6conseqZeroFiller = {':', ':'};
|
private static final char[] ipv6conseqZeroFiller = {':', ':'};
|
||||||
|
@ -64,7 +64,7 @@ final class SocksCommonUtils {
|
||||||
cmprHextet = hextet;
|
cmprHextet = hextet;
|
||||||
cmprSize = size;
|
cmprSize = size;
|
||||||
}
|
}
|
||||||
hextet = (curByte / 2) + 1;
|
hextet = curByte / 2 + 1;
|
||||||
}
|
}
|
||||||
if (cmprHextet == -1 || cmprSize < 2) {
|
if (cmprHextet == -1 || cmprSize < 2) {
|
||||||
//No compression can be applied
|
//No compression can be applied
|
||||||
|
@ -93,8 +93,8 @@ final class SocksCommonUtils {
|
||||||
private static void ipv6toStr(StringBuilder sb, byte[] src,
|
private static void ipv6toStr(StringBuilder sb, byte[] src,
|
||||||
int fromHextet, int toHextet) {
|
int fromHextet, int toHextet) {
|
||||||
for (int i = fromHextet; i < toHextet; i++) {
|
for (int i = fromHextet; i < toHextet; i++) {
|
||||||
sb.append(Integer.toHexString(((src[i << 1] << 8) & 0xff00)
|
sb.append(Integer.toHexString(src[i << 1] << 8 & 0xff00
|
||||||
| (src[(i << 1) + 1] & 0xff)));
|
| src[(i << 1) + 1] & 0xff));
|
||||||
if (i < toHextet - 1) {
|
if (i < toHextet - 1) {
|
||||||
sb.append(ipv6hextetSeparator);
|
sb.append(ipv6hextetSeparator);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,11 +26,6 @@ import io.netty.buffer.ByteBuf;
|
||||||
public final class SocksInitResponse extends SocksResponse {
|
public final class SocksInitResponse extends SocksResponse {
|
||||||
private final AuthScheme authScheme;
|
private final AuthScheme authScheme;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param authScheme
|
|
||||||
* @throws NullPointerException
|
|
||||||
*/
|
|
||||||
public SocksInitResponse(AuthScheme authScheme) {
|
public SocksInitResponse(AuthScheme authScheme) {
|
||||||
super(SocksResponseType.INIT);
|
super(SocksResponseType.INIT);
|
||||||
if (authScheme == null) {
|
if (authScheme == null) {
|
||||||
|
|
|
@ -29,12 +29,7 @@ public abstract class SocksMessage {
|
||||||
private final MessageType messageType;
|
private final MessageType messageType;
|
||||||
private final ProtocolVersion protocolVersion = ProtocolVersion.SOCKS5;
|
private final ProtocolVersion protocolVersion = ProtocolVersion.SOCKS5;
|
||||||
|
|
||||||
/**
|
protected SocksMessage(MessageType messageType) {
|
||||||
*
|
|
||||||
* @param messageType
|
|
||||||
* @throws NullPointerException
|
|
||||||
*/
|
|
||||||
public SocksMessage(MessageType messageType) {
|
|
||||||
if (messageType == null) {
|
if (messageType == null) {
|
||||||
throw new NullPointerException("messageType");
|
throw new NullPointerException("messageType");
|
||||||
}
|
}
|
||||||
|
@ -64,7 +59,7 @@ public abstract class SocksMessage {
|
||||||
|
|
||||||
private final byte b;
|
private final byte b;
|
||||||
|
|
||||||
private AuthScheme(byte b) {
|
AuthScheme(byte b) {
|
||||||
this.b = b;
|
this.b = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +85,7 @@ public abstract class SocksMessage {
|
||||||
|
|
||||||
private final byte b;
|
private final byte b;
|
||||||
|
|
||||||
private CmdType(byte b) {
|
CmdType(byte b) {
|
||||||
this.b = b;
|
this.b = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +111,7 @@ public abstract class SocksMessage {
|
||||||
|
|
||||||
private final byte b;
|
private final byte b;
|
||||||
|
|
||||||
private AddressType(byte b) {
|
AddressType(byte b) {
|
||||||
this.b = b;
|
this.b = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +135,7 @@ public abstract class SocksMessage {
|
||||||
|
|
||||||
private final byte b;
|
private final byte b;
|
||||||
|
|
||||||
private AuthStatus(byte b) {
|
AuthStatus(byte b) {
|
||||||
this.b = b;
|
this.b = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +167,7 @@ public abstract class SocksMessage {
|
||||||
|
|
||||||
private final byte b;
|
private final byte b;
|
||||||
|
|
||||||
private CmdStatus(byte b) {
|
CmdStatus(byte b) {
|
||||||
this.b = b;
|
this.b = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +192,7 @@ public abstract class SocksMessage {
|
||||||
|
|
||||||
private final byte b;
|
private final byte b;
|
||||||
|
|
||||||
private ProtocolVersion(byte b) {
|
ProtocolVersion(byte b) {
|
||||||
this.b = b;
|
this.b = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,7 @@ package io.netty.codec.socks;
|
||||||
public abstract class SocksRequest extends SocksMessage {
|
public abstract class SocksRequest extends SocksMessage {
|
||||||
private final SocksRequestType socksRequestType;
|
private final SocksRequestType socksRequestType;
|
||||||
|
|
||||||
/**
|
protected SocksRequest(SocksRequestType socksRequestType) {
|
||||||
*
|
|
||||||
* @param socksRequestType
|
|
||||||
* @throws NullPointerException
|
|
||||||
*/
|
|
||||||
public SocksRequest(SocksRequestType socksRequestType) {
|
|
||||||
super(MessageType.REQUEST);
|
super(MessageType.REQUEST);
|
||||||
if (socksRequestType == null) {
|
if (socksRequestType == null) {
|
||||||
throw new NullPointerException("socksRequestType");
|
throw new NullPointerException("socksRequestType");
|
||||||
|
|
|
@ -27,12 +27,7 @@ package io.netty.codec.socks;
|
||||||
public abstract class SocksResponse extends SocksMessage {
|
public abstract class SocksResponse extends SocksMessage {
|
||||||
private final SocksResponseType socksResponseType;
|
private final SocksResponseType socksResponseType;
|
||||||
|
|
||||||
/**
|
protected SocksResponse(SocksResponseType socksResponseType) {
|
||||||
*
|
|
||||||
* @param socksResponseType
|
|
||||||
* @throws NullPointerException
|
|
||||||
*/
|
|
||||||
public SocksResponse(SocksResponseType socksResponseType) {
|
|
||||||
super(MessageType.RESPONSE);
|
super(MessageType.RESPONSE);
|
||||||
if (socksResponseType == null) {
|
if (socksResponseType == null) {
|
||||||
throw new NullPointerException("socksResponseType");
|
throw new NullPointerException("socksResponseType");
|
||||||
|
|
|
@ -18,8 +18,8 @@ package io.netty.codec.socks;
|
||||||
import io.netty.channel.embedded.EmbeddedByteChannel;
|
import io.netty.channel.embedded.EmbeddedByteChannel;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class SocksAuthRequestDecoderTest {
|
public class SocksAuthRequestDecoderTest {
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SocksAuthRequestDecoderTest.class);
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SocksAuthRequestDecoderTest.class);
|
||||||
|
@ -32,8 +32,8 @@ public class SocksAuthRequestDecoderTest {
|
||||||
EmbeddedByteChannel embedder = new EmbeddedByteChannel(decoder);
|
EmbeddedByteChannel embedder = new EmbeddedByteChannel(decoder);
|
||||||
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
|
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
|
||||||
msg = (SocksAuthRequest) embedder.readInbound();
|
msg = (SocksAuthRequest) embedder.readInbound();
|
||||||
assertTrue(msg.getUsername().equals(username));
|
assertEquals(msg.getUsername(), username);
|
||||||
assertTrue(msg.getUsername().equals(password));
|
assertEquals(msg.getUsername(), password);
|
||||||
assertNull(embedder.readInbound());
|
assertNull(embedder.readInbound());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,19 +18,19 @@ package io.netty.codec.socks;
|
||||||
import io.netty.channel.embedded.EmbeddedByteChannel;
|
import io.netty.channel.embedded.EmbeddedByteChannel;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class SocksAuthResponseDecoderTest {
|
public class SocksAuthResponseDecoderTest {
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SocksAuthResponseDecoderTest.class);
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SocksAuthResponseDecoderTest.class);
|
||||||
private void testSocksAuthResponseDecoderWithDifferentParams(SocksMessage.AuthStatus authStatus){
|
private static void testSocksAuthResponseDecoderWithDifferentParams(SocksMessage.AuthStatus authStatus){
|
||||||
logger.debug("Testing SocksAuthResponseDecoder with authStatus: "+ authStatus);
|
logger.debug("Testing SocksAuthResponseDecoder with authStatus: "+ authStatus);
|
||||||
SocksAuthResponse msg = new SocksAuthResponse(authStatus);
|
SocksAuthResponse msg = new SocksAuthResponse(authStatus);
|
||||||
SocksAuthResponseDecoder decoder = new SocksAuthResponseDecoder();
|
SocksAuthResponseDecoder decoder = new SocksAuthResponseDecoder();
|
||||||
EmbeddedByteChannel embedder = new EmbeddedByteChannel(decoder);
|
EmbeddedByteChannel embedder = new EmbeddedByteChannel(decoder);
|
||||||
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
|
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
|
||||||
msg = (SocksAuthResponse) embedder.readInbound();
|
msg = (SocksAuthResponse) embedder.readInbound();
|
||||||
assertTrue(msg.getAuthStatus().equals(authStatus));
|
assertSame(msg.getAuthStatus(), authStatus);
|
||||||
assertNull(embedder.readInbound());
|
assertNull(embedder.readInbound());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,13 @@ import io.netty.channel.embedded.EmbeddedByteChannel;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import sun.net.util.IPAddressUtil;
|
import sun.net.util.IPAddressUtil;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class SocksCmdRequestDecoderTest {
|
public class SocksCmdRequestDecoderTest {
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SocksCmdRequestDecoderTest.class);
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SocksCmdRequestDecoderTest.class);
|
||||||
|
|
||||||
private void testSocksCmdRequestDecoderWithDifferentParams(SocksMessage.CmdType cmdType, SocksMessage.AddressType addressType, String host, int port) {
|
private static void testSocksCmdRequestDecoderWithDifferentParams(SocksMessage.CmdType cmdType, SocksMessage.AddressType addressType, String host, int port) {
|
||||||
logger.debug("Testing cmdType: " + cmdType + " addressType: " + addressType + " host: " + host + " port: " + port);
|
logger.debug("Testing cmdType: " + cmdType + " addressType: " + addressType + " host: " + host + " port: " + port);
|
||||||
SocksCmdRequest msg = new SocksCmdRequest(cmdType, addressType, host, port);
|
SocksCmdRequest msg = new SocksCmdRequest(cmdType, addressType, host, port);
|
||||||
SocksCmdRequestDecoder decoder = new SocksCmdRequestDecoder();
|
SocksCmdRequestDecoder decoder = new SocksCmdRequestDecoder();
|
||||||
|
@ -35,10 +35,10 @@ public class SocksCmdRequestDecoderTest {
|
||||||
assertTrue(embedder.readInbound() instanceof UnknownSocksRequest);
|
assertTrue(embedder.readInbound() instanceof UnknownSocksRequest);
|
||||||
} else {
|
} else {
|
||||||
msg = (SocksCmdRequest) embedder.readInbound();
|
msg = (SocksCmdRequest) embedder.readInbound();
|
||||||
assertTrue(msg.getCmdType().equals(cmdType));
|
assertSame(msg.getCmdType(), cmdType);
|
||||||
assertTrue(msg.getAddressType().equals(addressType));
|
assertSame(msg.getAddressType(), addressType);
|
||||||
assertTrue(msg.getHost().equals(host));
|
assertEquals(msg.getHost(), host);
|
||||||
assertTrue(msg.getPort() == port);
|
assertEquals(msg.getPort(), port);
|
||||||
}
|
}
|
||||||
assertNull(embedder.readInbound());
|
assertNull(embedder.readInbound());
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,13 @@ package io.netty.codec.socks;
|
||||||
import io.netty.channel.embedded.EmbeddedByteChannel;
|
import io.netty.channel.embedded.EmbeddedByteChannel;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class SocksCmdResponseDecoderTest {
|
public class SocksCmdResponseDecoderTest {
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SocksCmdResponseDecoderTest.class);
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SocksCmdResponseDecoderTest.class);
|
||||||
|
|
||||||
private void testSocksCmdResponseDecoderWithDifferentParams(SocksMessage.CmdStatus cmdStatus, SocksMessage.AddressType addressType){
|
private static void testSocksCmdResponseDecoderWithDifferentParams(SocksMessage.CmdStatus cmdStatus, SocksMessage.AddressType addressType){
|
||||||
logger.debug("Testing cmdStatus: " + cmdStatus + " addressType: " + addressType);
|
logger.debug("Testing cmdStatus: " + cmdStatus + " addressType: " + addressType);
|
||||||
SocksResponse msg = new SocksCmdResponse(cmdStatus, addressType);
|
SocksResponse msg = new SocksCmdResponse(cmdStatus, addressType);
|
||||||
SocksCmdResponseDecoder decoder = new SocksCmdResponseDecoder();
|
SocksCmdResponseDecoder decoder = new SocksCmdResponseDecoder();
|
||||||
|
@ -33,8 +33,8 @@ public class SocksCmdResponseDecoderTest {
|
||||||
if (addressType == SocksMessage.AddressType.UNKNOWN){
|
if (addressType == SocksMessage.AddressType.UNKNOWN){
|
||||||
assertTrue(embedder.readInbound() instanceof UnknownSocksResponse);
|
assertTrue(embedder.readInbound() instanceof UnknownSocksResponse);
|
||||||
} else {
|
} else {
|
||||||
msg = (SocksCmdResponse) embedder.readInbound();
|
msg = (SocksResponse) embedder.readInbound();
|
||||||
assertTrue(((SocksCmdResponse) msg).getCmdStatus().equals(cmdStatus));
|
assertEquals(((SocksCmdResponse) msg).getCmdStatus(), cmdStatus);
|
||||||
}
|
}
|
||||||
assertNull(embedder.readInbound());
|
assertNull(embedder.readInbound());
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,9 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||||
}
|
}
|
||||||
if (delimiters.length == 0) {
|
if (delimiters.length == 0) {
|
||||||
throw new IllegalArgumentException("empty delimiters");
|
throw new IllegalArgumentException("empty delimiters");
|
||||||
} else if (isLineBased(delimiters) && !isSubclass()) {
|
}
|
||||||
|
|
||||||
|
if (isLineBased(delimiters) && !isSubclass()) {
|
||||||
lineBasedDecoder = new LineBasedFrameDecoder(maxFrameLength, stripDelimiter, failFast);
|
lineBasedDecoder = new LineBasedFrameDecoder(maxFrameLength, stripDelimiter, failFast);
|
||||||
this.delimiters = null;
|
this.delimiters = null;
|
||||||
} else {
|
} else {
|
||||||
|
@ -203,7 +205,7 @@ public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder<Object> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return <code>true</code> if the current instance is a subclass of DelimiterBasedFrameDecoder
|
* Return {@code true} if the current instance is a subclass of DelimiterBasedFrameDecoder
|
||||||
*/
|
*/
|
||||||
private boolean isSubclass() {
|
private boolean isSubclass() {
|
||||||
return this.getClass() != DelimiterBasedFrameDecoder.class;
|
return this.getClass() != DelimiterBasedFrameDecoder.class;
|
||||||
|
|
|
@ -18,7 +18,6 @@ package io.netty.example.socksproxy;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
|
||||||
public interface CallbackNotifier {
|
public interface CallbackNotifier {
|
||||||
void onSuccess(final ChannelHandlerContext outboundCtx);
|
void onSuccess(ChannelHandlerContext outboundCtx);
|
||||||
|
void onFailure(ChannelHandlerContext outboundCtx, Throwable cause);
|
||||||
void onFailure(final ChannelHandlerContext outboundCtx, final Throwable cause);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,14 +16,13 @@
|
||||||
package io.netty.example.socksproxy;
|
package io.netty.example.socksproxy;
|
||||||
|
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.channel.ChannelFutureListener;
|
|
||||||
import io.netty.channel.ChannelFuture;
|
|
||||||
import io.netty.channel.ChannelHandler;
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelHandler.Sharable;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
||||||
|
import io.netty.channel.ChannelOption;
|
||||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
import io.netty.codec.socks.SocksCmdRequest;
|
import io.netty.codec.socks.SocksCmdRequest;
|
||||||
import io.netty.codec.socks.SocksCmdResponse;
|
import io.netty.codec.socks.SocksCmdResponse;
|
||||||
|
@ -48,17 +47,20 @@ public final class SocksServerConnectHandler extends ChannelInboundMessageHandle
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(final ChannelHandlerContext ctx, final SocksCmdRequest request) throws Exception {
|
public void messageReceived(final ChannelHandlerContext ctx, final SocksCmdRequest request) throws Exception {
|
||||||
CallbackNotifier cb = new CallbackNotifier() {
|
CallbackNotifier cb = new CallbackNotifier() {
|
||||||
|
@Override
|
||||||
public void onSuccess(final ChannelHandlerContext outboundCtx) {
|
public void onSuccess(final ChannelHandlerContext outboundCtx) {
|
||||||
ctx.channel().write(new SocksCmdResponse(SocksMessage.CmdStatus.SUCCESS, request.getAddressType()))
|
ctx.channel().write(new SocksCmdResponse(SocksMessage.CmdStatus.SUCCESS, request.getAddressType()))
|
||||||
.addListener(new ChannelFutureListener() {
|
.addListener(new ChannelFutureListener() {
|
||||||
|
@Override
|
||||||
public void operationComplete(ChannelFuture channelFuture) throws Exception {
|
public void operationComplete(ChannelFuture channelFuture) throws Exception {
|
||||||
ctx.pipeline().remove(SocksServerConnectHandler.getName());
|
ctx.pipeline().remove(getName());
|
||||||
outboundCtx.channel().pipeline().addLast(new RelayHandler(ctx.channel()));
|
outboundCtx.channel().pipeline().addLast(new RelayHandler(ctx.channel()));
|
||||||
ctx.channel().pipeline().addLast(new RelayHandler(outboundCtx.channel()));
|
ctx.channel().pipeline().addLast(new RelayHandler(outboundCtx.channel()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onFailure(ChannelHandlerContext outboundCtx, Throwable cause) {
|
public void onFailure(ChannelHandlerContext outboundCtx, Throwable cause) {
|
||||||
ctx.channel().write(new SocksCmdResponse(SocksMessage.CmdStatus.FAILURE, request.getAddressType()));
|
ctx.channel().write(new SocksCmdResponse(SocksMessage.CmdStatus.FAILURE, request.getAddressType()));
|
||||||
SocksServerUtils.closeOnFlush(ctx.channel());
|
SocksServerUtils.closeOnFlush(ctx.channel());
|
||||||
|
@ -72,7 +74,7 @@ public final class SocksServerConnectHandler extends ChannelInboundMessageHandle
|
||||||
.option(ChannelOption.SO_KEEPALIVE, true)
|
.option(ChannelOption.SO_KEEPALIVE, true)
|
||||||
.handler(new DirectClientInitializer(cb))
|
.handler(new DirectClientInitializer(cb))
|
||||||
.remoteAddress(request.getHost(), request.getPort());
|
.remoteAddress(request.getHost(), request.getPort());
|
||||||
ChannelFuture f = b.connect();
|
b.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,8 +24,6 @@ import io.netty.codec.socks.SocksMessage;
|
||||||
import io.netty.codec.socks.SocksRequest;
|
import io.netty.codec.socks.SocksRequest;
|
||||||
import io.netty.codec.socks.SocksAuthResponse;
|
import io.netty.codec.socks.SocksAuthResponse;
|
||||||
import io.netty.codec.socks.SocksCmdRequest;
|
import io.netty.codec.socks.SocksCmdRequest;
|
||||||
import io.netty.codec.socks.SocksCmdResponse;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ChannelHandler.Sharable
|
@ChannelHandler.Sharable
|
||||||
|
|
|
@ -22,12 +22,8 @@ import io.netty.codec.socks.SocksInitRequestDecoder;
|
||||||
import io.netty.codec.socks.SocksMessageEncoder;
|
import io.netty.codec.socks.SocksMessageEncoder;
|
||||||
|
|
||||||
public final class SocksServerInitializer extends ChannelInitializer<SocketChannel> {
|
public final class SocksServerInitializer extends ChannelInitializer<SocketChannel> {
|
||||||
private SocksMessageEncoder socksMessageEncoder = new SocksMessageEncoder();
|
private final SocksMessageEncoder socksMessageEncoder = new SocksMessageEncoder();
|
||||||
private SocksServerHandler socksServerHandler = new SocksServerHandler();
|
private final SocksServerHandler socksServerHandler = new SocksServerHandler();
|
||||||
|
|
||||||
public SocksServerInitializer() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initChannel(SocketChannel socketChannel) throws Exception {
|
public void initChannel(SocketChannel socketChannel) throws Exception {
|
||||||
|
|
|
@ -32,7 +32,6 @@ import java.io.IOException;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ChunkedWriteHandlerTest {
|
public class ChunkedWriteHandlerTest {
|
||||||
|
|
|
@ -70,17 +70,19 @@ public class DefaultChannelPipelineTest {
|
||||||
|
|
||||||
final String prefixX = "x";
|
final String prefixX = "x";
|
||||||
for (int i = 0; i < handlerNum; i++) {
|
for (int i = 0; i < handlerNum; i++) {
|
||||||
if (i % 2 == 0)
|
if (i % 2 == 0) {
|
||||||
pipeline.addFirst(prefixX + String.valueOf(i), handlers1[i]);
|
pipeline.addFirst(prefixX + String.valueOf(i), handlers1[i]);
|
||||||
else
|
} else {
|
||||||
pipeline.addLast(prefixX + String.valueOf(i), handlers1[i]);
|
pipeline.addLast(prefixX + String.valueOf(i), handlers1[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < handlerNum; i++) {
|
for (int i = 0; i < handlerNum; i++) {
|
||||||
if (i % 2 != 0)
|
if (i % 2 != 0) {
|
||||||
pipeline.addBefore(prefixX + String.valueOf(i), String.valueOf(i), handlers2[i]);
|
pipeline.addBefore(prefixX + String.valueOf(i), String.valueOf(i), handlers2[i]);
|
||||||
else
|
} else {
|
||||||
pipeline.addAfter(prefixX + String.valueOf(i), String.valueOf(i), handlers2[i]);
|
pipeline.addAfter(prefixX + String.valueOf(i), String.valueOf(i), handlers2[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
verifyContextNumber(pipeline, handlerNum * 2);
|
verifyContextNumber(pipeline, handlerNum * 2);
|
||||||
|
@ -115,17 +117,18 @@ public class DefaultChannelPipelineTest {
|
||||||
|
|
||||||
private int next(DefaultChannelHandlerContext ctx) {
|
private int next(DefaultChannelHandlerContext ctx) {
|
||||||
DefaultChannelHandlerContext next = ctx.next;
|
DefaultChannelHandlerContext next = ctx.next;
|
||||||
if (next == null)
|
if (next == null) {
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
return toInt(next.name());
|
return toInt(next.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
private int toInt(String name) {
|
private static int toInt(String name) {
|
||||||
return Integer.parseInt(name);
|
return Integer.parseInt(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyContextNumber(DefaultChannelPipeline pipeline, int expectedNumber) {
|
private static void verifyContextNumber(DefaultChannelPipeline pipeline, int expectedNumber) {
|
||||||
DefaultChannelHandlerContext ctx = (DefaultChannelHandlerContext) pipeline.firstContext();
|
DefaultChannelHandlerContext ctx = (DefaultChannelHandlerContext) pipeline.firstContext();
|
||||||
int handlerNumber = 0;
|
int handlerNumber = 0;
|
||||||
while (ctx != null) {
|
while (ctx != null) {
|
||||||
|
@ -139,8 +142,9 @@ public class DefaultChannelPipelineTest {
|
||||||
assert num > 0;
|
assert num > 0;
|
||||||
|
|
||||||
ChannelHandler[] handlers = new ChannelHandler[num];
|
ChannelHandler[] handlers = new ChannelHandler[num];
|
||||||
for (int i = 0; i < num; i++)
|
for (int i = 0; i < num; i++) {
|
||||||
handlers[i] = newHandler();
|
handlers[i] = newHandler();
|
||||||
|
}
|
||||||
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user