Prettify APIviz / Tighten visibility / Move subclasses to top level / Remove unused UnknownSocksMessage

This commit is contained in:
Trustin Lee 2013-02-11 19:42:23 +09:00
parent 6c7bd6d174
commit a2e5cd94be
48 changed files with 552 additions and 396 deletions

View File

@ -54,7 +54,7 @@ import java.util.Map;
* @see QueryStringEncoder * @see QueryStringEncoder
* *
* @apiviz.stereotype utility * @apiviz.stereotype utility
* @apiviz.has io.netty.handler.codec.http.FullHttpRequest oneway - - decodes * @apiviz.has io.netty.handler.codec.http.HttpRequest oneway - - decodes URI
*/ */
public class QueryStringDecoder { public class QueryStringDecoder {

View File

@ -36,7 +36,7 @@ import java.util.List;
* @see QueryStringDecoder * @see QueryStringDecoder
* *
* @apiviz.stereotype utility * @apiviz.stereotype utility
* @apiviz.has io.netty.handler.codec.http.FullHttpRequest oneway - - encodes * @apiviz.has io.netty.handler.codec.http.HttpRequest oneway - - encodes URI
*/ */
public class QueryStringEncoder { public class QueryStringEncoder {
@ -116,7 +116,7 @@ public class QueryStringEncoder {
private static String encodeComponent(String s, Charset charset) { private static String encodeComponent(String s, Charset charset) {
try { try {
return URLEncoder.encode(s, charset.name()).replaceAll("\\+", "%20"); return URLEncoder.encode(s, charset.name()).replace("+", "%20");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
throw new UnsupportedCharsetException(charset.name()); throw new UnsupportedCharsetException(charset.name());
} }

View File

@ -25,9 +25,6 @@ import io.netty.handler.codec.TooLongFrameException;
* <p> * <p>
* For the detailed instruction on adding add Web Socket support to your HTTP server, take a look into the * For the detailed instruction on adding add Web Socket support to your HTTP server, take a look into the
* <tt>WebSocketServer</tt> example located in the {@code io.netty.example.http.websocket} package. * <tt>WebSocketServer</tt> example located in the {@code io.netty.example.http.websocket} package.
*
* @apiviz.landmark
* @apiviz.uses io.netty.handler.codec.http.websocket.WebSocketFrame
*/ */
public class WebSocket00FrameDecoder extends ReplayingDecoder<Void> { public class WebSocket00FrameDecoder extends ReplayingDecoder<Void> {

View File

@ -25,9 +25,6 @@ import io.netty.handler.codec.MessageToByteEncoder;
* <p> * <p>
* For the detailed instruction on adding add Web Socket support to your HTTP server, take a look into the * For the detailed instruction on adding add Web Socket support to your HTTP server, take a look into the
* <tt>WebSocketServer</tt> example located in the {@code io.netty.example.http.websocket} package. * <tt>WebSocketServer</tt> example located in the {@code io.netty.example.http.websocket} package.
*
* @apiviz.landmark
* @apiviz.uses io.netty.handler.codec.http.websocket.WebSocketFrame
*/ */
@Sharable @Sharable
public class WebSocket00FrameEncoder extends MessageToByteEncoder<WebSocketFrame> { public class WebSocket00FrameEncoder extends MessageToByteEncoder<WebSocketFrame> {

View File

@ -93,7 +93,7 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDe
private final boolean maskedPayload; private final boolean maskedPayload;
private boolean receivedClosingHandshake; private boolean receivedClosingHandshake;
public enum State { enum State {
FRAME_START, MASKING_KEY, PAYLOAD, CORRUPT FRAME_START, MASKING_KEY, PAYLOAD, CORRUPT
} }

View File

@ -22,7 +22,10 @@ import java.net.URI;
import static io.netty.handler.codec.http.websocketx.WebSocketVersion.*; import static io.netty.handler.codec.http.websocketx.WebSocketVersion.*;
/** /**
* Instances the appropriate handshake class to use for clients * Creates a new {@link WebSocketClientHandshaker} of desired protocol version.
*
* @apiviz.landmark
* @apiviz.has io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker oneway - - creates
*/ */
public final class WebSocketClientHandshakerFactory { public final class WebSocketClientHandshakerFactory {

View File

@ -24,7 +24,11 @@ import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion; import io.netty.handler.codec.http.HttpVersion;
/** /**
* Instances the appropriate handshake class to use for servers * Auto-detects the version of the Web Socket protocol in use and creates a new proper
* {@link WebSocketServerHandshaker}.
*
* @apiviz.landmark
* @apiviz.has io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker oneway - - creates
*/ */
public class WebSocketServerHandshakerFactory { public class WebSocketServerHandshakerFactory {

View File

@ -33,9 +33,9 @@
* {@code io.netty.example.http.websocket} package. * {@code io.netty.example.http.websocket} package.
* </p> * </p>
* *
* @apiviz.exclude OneToOne(Encoder|Decoder)$ * @apiviz.exclude [0-9][0-9]
* @apiviz.exclude \.codec\.replay\. * @apiviz.exclude Exception$
* @apiviz.exclude \.Default * @apiviz.exclude Version$
*/ */
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;

View File

@ -33,16 +33,17 @@ import javax.net.ssl.SSLEngine;
* {@link ChannelInboundByteHandler} which is responsible to setup the {@link ChannelPipeline} either for * {@link ChannelInboundByteHandler} which is responsible to setup the {@link ChannelPipeline} either for
* HTTP or SPDY. This offers an easy way for users to support both at the same time while not care to * HTTP or SPDY. This offers an easy way for users to support both at the same time while not care to
* much about the low-level details. * much about the low-level details.
*
*/ */
public abstract class SpdyOrHttpChooser extends ChannelDuplexHandler implements ChannelInboundByteHandler { public abstract class SpdyOrHttpChooser extends ChannelDuplexHandler implements ChannelInboundByteHandler {
// TODO: Replace with generic NPN handler
public enum SelectedProtocol { public enum SelectedProtocol {
SpdyVersion2, SPDY_2,
SpdyVersion3, SPDY_3,
HttpVersion1_1, HTTP_1_1,
HttpVersion1_0, HTTP_1_0,
None UNKNOWN
} }
private final int maxSpdyContentLength; private final int maxSpdyContentLength;
@ -55,7 +56,7 @@ public abstract class SpdyOrHttpChooser extends ChannelDuplexHandler implements
/** /**
* Return the {@link SelectedProtocol} for the {@link SSLEngine}. If its not known yet implementations * Return the {@link SelectedProtocol} for the {@link SSLEngine}. If its not known yet implementations
* MUST return {@link SelectedProtocol#None}. * MUST return {@link SelectedProtocol#UNKNOWN}.
* *
*/ */
protected abstract SelectedProtocol getProtocol(SSLEngine engine); protected abstract SelectedProtocol getProtocol(SSLEngine engine);
@ -98,17 +99,17 @@ public abstract class SpdyOrHttpChooser extends ChannelDuplexHandler implements
SelectedProtocol protocol = getProtocol(handler.engine()); SelectedProtocol protocol = getProtocol(handler.engine());
switch (protocol) { switch (protocol) {
case None: case UNKNOWN:
// Not done with choosing the protocol, so just return here for now, // Not done with choosing the protocol, so just return here for now,
return false; return false;
case SpdyVersion2: case SPDY_2:
addSpdyHandlers(ctx, 2); addSpdyHandlers(ctx, 2);
break; break;
case SpdyVersion3: case SPDY_3:
addSpdyHandlers(ctx, 3); addSpdyHandlers(ctx, 3);
break; break;
case HttpVersion1_0: case HTTP_1_0:
case HttpVersion1_1: case HTTP_1_1:
addHttpHandlers(ctx); addHttpHandlers(ctx);
break; break;
default: default:
@ -144,15 +145,15 @@ public abstract class SpdyOrHttpChooser extends ChannelDuplexHandler implements
/** /**
* Create the {@link ChannelInboundMessageHandler} that is responsible for handling the http requests * Create the {@link ChannelInboundMessageHandler} that is responsible for handling the http requests
* when the {@link SelectedProtocol} was {@link SelectedProtocol#HttpVersion1_0} or * when the {@link SelectedProtocol} was {@link SelectedProtocol#HTTP_1_0} or
* {@link SelectedProtocol#HttpVersion1_1} * {@link SelectedProtocol#HTTP_1_1}
*/ */
protected abstract ChannelInboundMessageHandler<?> createHttpRequestHandlerForHttp(); protected abstract ChannelInboundMessageHandler<?> createHttpRequestHandlerForHttp();
/** /**
* Create the {@link ChannelInboundMessageHandler} that is responsible for handling the http responses * Create the {@link ChannelInboundMessageHandler} that is responsible for handling the http responses
* when the {@link SelectedProtocol} was {@link SelectedProtocol#SpdyVersion2} or * when the {@link SelectedProtocol} was {@link SelectedProtocol#SPDY_2} or
* {@link SelectedProtocol#SpdyVersion3}. * {@link SelectedProtocol#SPDY_3}.
* *
* Bye default this getMethod will just delecate to {@link #createHttpRequestHandlerForHttp()}, but * Bye default this getMethod will just delecate to {@link #createHttpRequestHandlerForHttp()}, but
* sub-classes may override this to change the behaviour. * sub-classes may override this to change the behaviour.

View File

@ -0,0 +1,44 @@
/*
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.handler.codec.socks;
public enum SocksAddressType {
IPv4((byte) 0x01),
DOMAIN((byte) 0x03),
IPv6((byte) 0x04),
UNKNOWN((byte) 0xff);
private final byte b;
SocksAddressType(byte b) {
this.b = b;
}
public static SocksAddressType fromByte(byte b) {
for (SocksAddressType code : values()) {
if (code.b == b) {
return code;
}
}
return UNKNOWN;
}
public byte byteValue() {
return b;
}
}

View File

@ -28,7 +28,7 @@ import java.nio.charset.CharsetEncoder;
*/ */
public final class SocksAuthRequest extends SocksRequest { public final class SocksAuthRequest extends SocksRequest {
private static final CharsetEncoder asciiEncoder = CharsetUtil.getEncoder(CharsetUtil.US_ASCII); private static final CharsetEncoder asciiEncoder = CharsetUtil.getEncoder(CharsetUtil.US_ASCII);
private static final SubnegotiationVersion SUBNEGOTIATION_VERSION = SubnegotiationVersion.AUTH_PASSWORD; private static final SocksSubnegotiationVersion SUBNEGOTIATION_VERSION = SocksSubnegotiationVersion.AUTH_PASSWORD;
private final String username; private final String username;
private final String password; private final String password;
@ -74,7 +74,7 @@ public final class SocksAuthRequest extends SocksRequest {
@Override @Override
public void encodeAsByteBuf(ByteBuf byteBuf) { public void encodeAsByteBuf(ByteBuf byteBuf) {
byteBuf.writeByte(SUBNEGOTIATION_VERSION.getByteValue()); byteBuf.writeByte(SUBNEGOTIATION_VERSION.byteValue());
byteBuf.writeByte(username.length()); byteBuf.writeByte(username.length());
byteBuf.writeBytes(username.getBytes(CharsetUtil.US_ASCII)); byteBuf.writeBytes(username.getBytes(CharsetUtil.US_ASCII));
byteBuf.writeByte(password.length()); byteBuf.writeByte(password.length());

View File

@ -31,7 +31,7 @@ public class SocksAuthRequestDecoder extends ReplayingDecoder<SocksAuthRequestDe
return name; return name;
} }
private SocksMessage.SubnegotiationVersion version; private SocksSubnegotiationVersion version;
private int fieldLength; private int fieldLength;
private String username; private String username;
private String password; private String password;
@ -45,8 +45,8 @@ public class SocksAuthRequestDecoder extends ReplayingDecoder<SocksAuthRequestDe
protected Object decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception { protected Object decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
switch (state()) { switch (state()) {
case CHECK_PROTOCOL_VERSION: { case CHECK_PROTOCOL_VERSION: {
version = SocksMessage.SubnegotiationVersion.fromByte(byteBuf.readByte()); version = SocksSubnegotiationVersion.fromByte(byteBuf.readByte());
if (version != SocksMessage.SubnegotiationVersion.AUTH_PASSWORD) { if (version != SocksSubnegotiationVersion.AUTH_PASSWORD) {
break; break;
} }
checkpoint(State.READ_USERNAME); checkpoint(State.READ_USERNAME);

View File

@ -24,10 +24,10 @@ import io.netty.buffer.ByteBuf;
* @see SocksAuthResponseDecoder * @see SocksAuthResponseDecoder
*/ */
public final class SocksAuthResponse extends SocksResponse { public final class SocksAuthResponse extends SocksResponse {
private static final SubnegotiationVersion SUBNEGOTIATION_VERSION = SubnegotiationVersion.AUTH_PASSWORD; private static final SocksSubnegotiationVersion SUBNEGOTIATION_VERSION = SocksSubnegotiationVersion.AUTH_PASSWORD;
private final AuthStatus authStatus; private final SocksAuthStatus authStatus;
public SocksAuthResponse(AuthStatus authStatus) { public SocksAuthResponse(SocksAuthStatus authStatus) {
super(SocksResponseType.AUTH); super(SocksResponseType.AUTH);
if (authStatus == null) { if (authStatus == null) {
throw new NullPointerException("authStatus"); throw new NullPointerException("authStatus");
@ -36,17 +36,17 @@ public final class SocksAuthResponse extends SocksResponse {
} }
/** /**
* Returns the {@link AuthStatus} of this {@link SocksAuthResponse} * Returns the {@link SocksAuthStatus} of this {@link SocksAuthResponse}
* *
* @return The {@link AuthStatus} of this {@link SocksAuthResponse} * @return The {@link SocksAuthStatus} of this {@link SocksAuthResponse}
*/ */
public AuthStatus authStatus() { public SocksAuthStatus authStatus() {
return authStatus; return authStatus;
} }
@Override @Override
public void encodeAsByteBuf(ByteBuf byteBuf) { public void encodeAsByteBuf(ByteBuf byteBuf) {
byteBuf.writeByte(SUBNEGOTIATION_VERSION.getByteValue()); byteBuf.writeByte(SUBNEGOTIATION_VERSION.byteValue());
byteBuf.writeByte(authStatus.getByteValue()); byteBuf.writeByte(authStatus.byteValue());
} }
} }

View File

@ -30,8 +30,8 @@ public class SocksAuthResponseDecoder extends ReplayingDecoder<SocksAuthResponse
return name; return name;
} }
private SocksMessage.SubnegotiationVersion version; private SocksSubnegotiationVersion version;
private SocksMessage.AuthStatus authStatus; private SocksAuthStatus authStatus;
private SocksResponse msg = SocksCommonUtils.UNKNOWN_SOCKS_RESPONSE; private SocksResponse msg = SocksCommonUtils.UNKNOWN_SOCKS_RESPONSE;
public SocksAuthResponseDecoder() { public SocksAuthResponseDecoder() {
@ -42,14 +42,14 @@ public class SocksAuthResponseDecoder extends ReplayingDecoder<SocksAuthResponse
protected Object decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception { protected Object decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception {
switch (state()) { switch (state()) {
case CHECK_PROTOCOL_VERSION: { case CHECK_PROTOCOL_VERSION: {
version = SocksMessage.SubnegotiationVersion.fromByte(byteBuf.readByte()); version = SocksSubnegotiationVersion.fromByte(byteBuf.readByte());
if (version != SocksMessage.SubnegotiationVersion.AUTH_PASSWORD) { if (version != SocksSubnegotiationVersion.AUTH_PASSWORD) {
break; break;
} }
checkpoint(State.READ_AUTH_RESPONSE); checkpoint(State.READ_AUTH_RESPONSE);
} }
case READ_AUTH_RESPONSE: { case READ_AUTH_RESPONSE: {
authStatus = SocksMessage.AuthStatus.fromByte(byteBuf.readByte()); authStatus = SocksAuthStatus.fromByte(byteBuf.readByte());
msg = new SocksAuthResponse(authStatus); msg = new SocksAuthResponse(authStatus);
} }
} }
@ -57,7 +57,7 @@ public class SocksAuthResponseDecoder extends ReplayingDecoder<SocksAuthResponse
return msg; return msg;
} }
public enum State { enum State {
CHECK_PROTOCOL_VERSION, CHECK_PROTOCOL_VERSION,
READ_AUTH_RESPONSE READ_AUTH_RESPONSE
} }

View File

@ -0,0 +1,44 @@
/*
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.handler.codec.socks;
public enum SocksAuthScheme {
NO_AUTH((byte) 0x00),
AUTH_GSSAPI((byte) 0x01),
AUTH_PASSWORD((byte) 0x02),
UNKNOWN((byte) 0xff);
private final byte b;
SocksAuthScheme(byte b) {
this.b = b;
}
public static SocksAuthScheme fromByte(byte b) {
for (SocksAuthScheme code : values()) {
if (code.b == b) {
return code;
}
}
return UNKNOWN;
}
public byte byteValue() {
return b;
}
}

View File

@ -0,0 +1,42 @@
/*
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.handler.codec.socks;
public enum SocksAuthStatus {
SUCCESS((byte) 0x00),
FAILURE((byte) 0xff);
private final byte b;
SocksAuthStatus(byte b) {
this.b = b;
}
public static SocksAuthStatus fromByte(byte b) {
for (SocksAuthStatus code : values()) {
if (code.b == b) {
return code;
}
}
return FAILURE;
}
public byte byteValue() {
return b;
}
}

View File

@ -28,12 +28,12 @@ import java.net.IDN;
* @see SocksCmdRequestDecoder * @see SocksCmdRequestDecoder
*/ */
public final class SocksCmdRequest extends SocksRequest { public final class SocksCmdRequest extends SocksRequest {
private final CmdType cmdType; private final SocksCmdType cmdType;
private final AddressType addressType; private final SocksAddressType addressType;
private final String host; private final String host;
private final int port; private final int port;
public SocksCmdRequest(CmdType cmdType, AddressType addressType, String host, int port) { public SocksCmdRequest(SocksCmdType cmdType, SocksAddressType addressType, String host, int port) {
super(SocksRequestType.CMD); super(SocksRequestType.CMD);
if (cmdType == null) { if (cmdType == null) {
throw new NullPointerException("cmdType"); throw new NullPointerException("cmdType");
@ -73,36 +73,36 @@ public final class SocksCmdRequest extends SocksRequest {
} }
/** /**
* Returns the {@link CmdType} of this {@link SocksCmdRequest} * Returns the {@link SocksCmdType} of this {@link SocksCmdRequest}
* *
* @return The {@link CmdType} of this {@link SocksCmdRequest} * @return The {@link SocksCmdType} of this {@link SocksCmdRequest}
*/ */
public CmdType cmdType() { public SocksCmdType cmdType() {
return cmdType; return cmdType;
} }
/** /**
* Returns the {@link AddressType} of this {@link SocksCmdRequest} * Returns the {@link SocksAddressType} of this {@link SocksCmdRequest}
* *
* @return The {@link AddressType} of this {@link SocksCmdRequest} * @return The {@link SocksAddressType} of this {@link SocksCmdRequest}
*/ */
public AddressType addressType() { public SocksAddressType addressType() {
return addressType; return addressType;
} }
/** /**
* Returns host that is used as a parameter in {@link CmdType} * Returns host that is used as a parameter in {@link SocksCmdType}
* *
* @return host that is used as a parameter in {@link CmdType} * @return host that is used as a parameter in {@link SocksCmdType}
*/ */
public String host() { public String host() {
return IDN.toUnicode(host); return IDN.toUnicode(host);
} }
/** /**
* Returns port that is used as a parameter in {@link CmdType} * Returns port that is used as a parameter in {@link SocksCmdType}
* *
* @return port that is used as a parameter in {@link CmdType} * @return port that is used as a parameter in {@link SocksCmdType}
*/ */
public int port() { public int port() {
return port; return port;
@ -110,10 +110,10 @@ public final class SocksCmdRequest extends SocksRequest {
@Override @Override
public void encodeAsByteBuf(ByteBuf byteBuf) { public void encodeAsByteBuf(ByteBuf byteBuf) {
byteBuf.writeByte(protocolVersion().getByteValue()); byteBuf.writeByte(protocolVersion().byteValue());
byteBuf.writeByte(cmdType.getByteValue()); byteBuf.writeByte(cmdType.byteValue());
byteBuf.writeByte(0x00); byteBuf.writeByte(0x00);
byteBuf.writeByte(addressType.getByteValue()); byteBuf.writeByte(addressType.byteValue());
switch (addressType) { switch (addressType) {
case IPv4: { case IPv4: {
byteBuf.writeBytes(NetUtil.createByteArrayFromIpAddressString(host)); byteBuf.writeBytes(NetUtil.createByteArrayFromIpAddressString(host));

View File

@ -31,10 +31,10 @@ public class SocksCmdRequestDecoder extends ReplayingDecoder<SocksCmdRequestDeco
return name; return name;
} }
private SocksMessage.ProtocolVersion version; private SocksProtocolVersion version;
private int fieldLength; private int fieldLength;
private SocksMessage.CmdType cmdType; private SocksCmdType cmdType;
private SocksMessage.AddressType addressType; private SocksAddressType addressType;
private byte reserved; private byte reserved;
private String host; private String host;
private int port; private int port;
@ -48,16 +48,16 @@ public class SocksCmdRequestDecoder extends ReplayingDecoder<SocksCmdRequestDeco
protected Object decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception { protected Object decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
switch (state()) { switch (state()) {
case CHECK_PROTOCOL_VERSION: { case CHECK_PROTOCOL_VERSION: {
version = SocksMessage.ProtocolVersion.fromByte(byteBuf.readByte()); version = SocksProtocolVersion.fromByte(byteBuf.readByte());
if (version != SocksMessage.ProtocolVersion.SOCKS5) { if (version != SocksProtocolVersion.SOCKS5) {
break; break;
} }
checkpoint(State.READ_CMD_HEADER); checkpoint(State.READ_CMD_HEADER);
} }
case READ_CMD_HEADER: { case READ_CMD_HEADER: {
cmdType = SocksMessage.CmdType.fromByte(byteBuf.readByte()); cmdType = SocksCmdType.fromByte(byteBuf.readByte());
reserved = byteBuf.readByte(); reserved = byteBuf.readByte();
addressType = SocksMessage.AddressType.fromByte(byteBuf.readByte()); addressType = SocksAddressType.fromByte(byteBuf.readByte());
checkpoint(State.READ_CMD_ADDRESS); checkpoint(State.READ_CMD_ADDRESS);
} }
case READ_CMD_ADDRESS: { case READ_CMD_ADDRESS: {

View File

@ -24,9 +24,9 @@ import io.netty.buffer.ByteBuf;
* @see SocksCmdResponseDecoder * @see SocksCmdResponseDecoder
*/ */
public final class SocksCmdResponse extends SocksResponse { public final class SocksCmdResponse extends SocksResponse {
private final CmdStatus cmdStatus; private final SocksCmdStatus cmdStatus;
private final AddressType addressType; private final SocksAddressType addressType;
// All arrays are initialized on construction time to 0/false/null remove array Initialization // All arrays are initialized on construction time to 0/false/null remove array Initialization
private static final byte[] IPv4_HOSTNAME_ZEROED = {0x00, 0x00, 0x00, 0x00}; private static final byte[] IPv4_HOSTNAME_ZEROED = {0x00, 0x00, 0x00, 0x00};
private static final byte[] IPv6_HOSTNAME_ZEROED = {0x00, 0x00, 0x00, 0x00, private static final byte[] IPv6_HOSTNAME_ZEROED = {0x00, 0x00, 0x00, 0x00,
@ -34,7 +34,7 @@ public final class SocksCmdResponse extends SocksResponse {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00}; 0x00, 0x00, 0x00, 0x00};
public SocksCmdResponse(CmdStatus cmdStatus, AddressType addressType) { public SocksCmdResponse(SocksCmdStatus cmdStatus, SocksAddressType addressType) {
super(SocksResponseType.CMD); super(SocksResponseType.CMD);
if (cmdStatus == null) { if (cmdStatus == null) {
throw new NullPointerException("cmdStatus"); throw new NullPointerException("cmdStatus");
@ -47,29 +47,29 @@ public final class SocksCmdResponse extends SocksResponse {
} }
/** /**
* Returns the {@link CmdStatus} of this {@link SocksCmdResponse} * Returns the {@link SocksCmdStatus} of this {@link SocksCmdResponse}
* *
* @return The {@link CmdStatus} of this {@link SocksCmdResponse} * @return The {@link SocksCmdStatus} of this {@link SocksCmdResponse}
*/ */
public CmdStatus cmdStatus() { public SocksCmdStatus cmdStatus() {
return cmdStatus; return cmdStatus;
} }
/** /**
* Returns the {@link AddressType} of this {@link SocksCmdResponse} * Returns the {@link SocksAddressType} of this {@link SocksCmdResponse}
* *
* @return The {@link AddressType} of this {@link SocksCmdResponse} * @return The {@link SocksAddressType} of this {@link SocksCmdResponse}
*/ */
public AddressType addressType() { public SocksAddressType addressType() {
return addressType; return addressType;
} }
@Override @Override
public void encodeAsByteBuf(ByteBuf byteBuf) { public void encodeAsByteBuf(ByteBuf byteBuf) {
byteBuf.writeByte(protocolVersion().getByteValue()); byteBuf.writeByte(protocolVersion().byteValue());
byteBuf.writeByte(cmdStatus.getByteValue()); byteBuf.writeByte(cmdStatus.byteValue());
byteBuf.writeByte(0x00); byteBuf.writeByte(0x00);
byteBuf.writeByte(addressType.getByteValue()); byteBuf.writeByte(addressType.byteValue());
switch (addressType) { switch (addressType) {
case IPv4: { case IPv4: {
byteBuf.writeBytes(IPv4_HOSTNAME_ZEROED); byteBuf.writeBytes(IPv4_HOSTNAME_ZEROED);

View File

@ -31,10 +31,10 @@ public class SocksCmdResponseDecoder extends ReplayingDecoder<SocksCmdResponseDe
return name; return name;
} }
private SocksMessage.ProtocolVersion version; private SocksProtocolVersion version;
private int fieldLength; private int fieldLength;
private SocksMessage.CmdStatus cmdStatus; private SocksCmdStatus cmdStatus;
private SocksMessage.AddressType addressType; private SocksAddressType addressType;
private byte reserved; private byte reserved;
private String host; private String host;
private int port; private int port;
@ -48,16 +48,16 @@ public class SocksCmdResponseDecoder extends ReplayingDecoder<SocksCmdResponseDe
protected Object decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception { protected Object decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
switch (state()) { switch (state()) {
case CHECK_PROTOCOL_VERSION: { case CHECK_PROTOCOL_VERSION: {
version = SocksMessage.ProtocolVersion.fromByte(byteBuf.readByte()); version = SocksProtocolVersion.fromByte(byteBuf.readByte());
if (version != SocksMessage.ProtocolVersion.SOCKS5) { if (version != SocksProtocolVersion.SOCKS5) {
break; break;
} }
checkpoint(State.READ_CMD_HEADER); checkpoint(State.READ_CMD_HEADER);
} }
case READ_CMD_HEADER: { case READ_CMD_HEADER: {
cmdStatus = SocksMessage.CmdStatus.fromByte(byteBuf.readByte()); cmdStatus = SocksCmdStatus.fromByte(byteBuf.readByte());
reserved = byteBuf.readByte(); reserved = byteBuf.readByte();
addressType = SocksMessage.AddressType.fromByte(byteBuf.readByte()); addressType = SocksAddressType.fromByte(byteBuf.readByte());
checkpoint(State.READ_CMD_ADDRESS); checkpoint(State.READ_CMD_ADDRESS);
} }
case READ_CMD_ADDRESS: { case READ_CMD_ADDRESS: {
@ -90,7 +90,7 @@ public class SocksCmdResponseDecoder extends ReplayingDecoder<SocksCmdResponseDe
return msg; return msg;
} }
public enum State { enum State {
CHECK_PROTOCOL_VERSION, CHECK_PROTOCOL_VERSION,
READ_CMD_HEADER, READ_CMD_HEADER,
READ_CMD_ADDRESS READ_CMD_ADDRESS

View File

@ -0,0 +1,49 @@
/*
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.handler.codec.socks;
public enum SocksCmdStatus {
SUCCESS((byte) 0x00),
FAILURE((byte) 0x01),
FORBIDDEN((byte) 0x02),
NETWORK_UNREACHABLE((byte) 0x03),
HOST_UNREACHABLE((byte) 0x04),
REFUSED((byte) 0x05),
TTL_EXPIRED((byte) 0x06),
COMMAND_NOT_SUPPORTED((byte) 0x07),
ADDRESS_NOT_SUPPORTED((byte) 0x08),
UNASSIGNED((byte) 0xff);
private final byte b;
SocksCmdStatus(byte b) {
this.b = b;
}
public static SocksCmdStatus fromByte(byte b) {
for (SocksCmdStatus code : values()) {
if (code.b == b) {
return code;
}
}
return UNASSIGNED;
}
public byte byteValue() {
return b;
}
}

View File

@ -0,0 +1,44 @@
/*
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.handler.codec.socks;
public enum SocksCmdType {
CONNECT((byte) 0x01),
BIND((byte) 0x02),
UDP((byte) 0x03),
UNKNOWN((byte) 0xff);
private final byte b;
SocksCmdType(byte b) {
this.b = b;
}
public static SocksCmdType fromByte(byte b) {
for (SocksCmdType code : values()) {
if (code.b == b) {
return code;
}
}
return UNKNOWN;
}
public byte byteValue() {
return b;
}
}

View File

@ -27,9 +27,9 @@ import java.util.List;
* @see SocksInitRequestDecoder * @see SocksInitRequestDecoder
*/ */
public final class SocksInitRequest extends SocksRequest { public final class SocksInitRequest extends SocksRequest {
private final List<AuthScheme> authSchemes; private final List<SocksAuthScheme> authSchemes;
public SocksInitRequest(List<AuthScheme> authSchemes) { public SocksInitRequest(List<SocksAuthScheme> authSchemes) {
super(SocksRequestType.INIT); super(SocksRequestType.INIT);
if (authSchemes == null) { if (authSchemes == null) {
throw new NullPointerException("authSchemes"); throw new NullPointerException("authSchemes");
@ -38,20 +38,20 @@ public final class SocksInitRequest extends SocksRequest {
} }
/** /**
* Returns the List<{@link AuthScheme}> of this {@link SocksInitRequest} * Returns the List<{@link SocksAuthScheme}> of this {@link SocksInitRequest}
* *
* @return The List<{@link AuthScheme}> of this {@link SocksInitRequest} * @return The List<{@link SocksAuthScheme}> of this {@link SocksInitRequest}
*/ */
public List<AuthScheme> authSchemes() { public List<SocksAuthScheme> authSchemes() {
return Collections.unmodifiableList(authSchemes); return Collections.unmodifiableList(authSchemes);
} }
@Override @Override
public void encodeAsByteBuf(ByteBuf byteBuf) { public void encodeAsByteBuf(ByteBuf byteBuf) {
byteBuf.writeByte(protocolVersion().getByteValue()); byteBuf.writeByte(protocolVersion().byteValue());
byteBuf.writeByte(authSchemes.size()); byteBuf.writeByte(authSchemes.size());
for (AuthScheme authScheme : authSchemes) { for (SocksAuthScheme authScheme : authSchemes) {
byteBuf.writeByte(authScheme.getByteValue()); byteBuf.writeByte(authScheme.byteValue());
} }
} }
} }

View File

@ -33,8 +33,8 @@ public class SocksInitRequestDecoder extends ReplayingDecoder<SocksInitRequestDe
return name; return name;
} }
private final List<SocksMessage.AuthScheme> authSchemes = new ArrayList<SocksMessage.AuthScheme>(); private final List<SocksAuthScheme> authSchemes = new ArrayList<SocksAuthScheme>();
private SocksMessage.ProtocolVersion version; private SocksProtocolVersion version;
private byte authSchemeNum; private byte authSchemeNum;
private SocksRequest msg = SocksCommonUtils.UNKNOWN_SOCKS_REQUEST; private SocksRequest msg = SocksCommonUtils.UNKNOWN_SOCKS_REQUEST;
@ -46,8 +46,8 @@ public class SocksInitRequestDecoder extends ReplayingDecoder<SocksInitRequestDe
protected Object decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception { protected Object decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
switch (state()) { switch (state()) {
case CHECK_PROTOCOL_VERSION: { case CHECK_PROTOCOL_VERSION: {
version = SocksMessage.ProtocolVersion.fromByte(byteBuf.readByte()); version = SocksProtocolVersion.fromByte(byteBuf.readByte());
if (version != SocksMessage.ProtocolVersion.SOCKS5) { if (version != SocksProtocolVersion.SOCKS5) {
break; break;
} }
checkpoint(State.READ_AUTH_SCHEMES); checkpoint(State.READ_AUTH_SCHEMES);
@ -56,7 +56,7 @@ public class SocksInitRequestDecoder extends ReplayingDecoder<SocksInitRequestDe
authSchemes.clear(); authSchemes.clear();
authSchemeNum = byteBuf.readByte(); authSchemeNum = byteBuf.readByte();
for (int i = 0; i < authSchemeNum; i++) { for (int i = 0; i < authSchemeNum; i++) {
authSchemes.add(SocksMessage.AuthScheme.fromByte(byteBuf.readByte())); authSchemes.add(SocksAuthScheme.fromByte(byteBuf.readByte()));
} }
msg = new SocksInitRequest(authSchemes); msg = new SocksInitRequest(authSchemes);
break; break;

View File

@ -24,9 +24,9 @@ import io.netty.buffer.ByteBuf;
* @see SocksInitResponseDecoder * @see SocksInitResponseDecoder
*/ */
public final class SocksInitResponse extends SocksResponse { public final class SocksInitResponse extends SocksResponse {
private final AuthScheme authScheme; private final SocksAuthScheme authScheme;
public SocksInitResponse(AuthScheme authScheme) { public SocksInitResponse(SocksAuthScheme authScheme) {
super(SocksResponseType.INIT); super(SocksResponseType.INIT);
if (authScheme == null) { if (authScheme == null) {
throw new NullPointerException("authScheme"); throw new NullPointerException("authScheme");
@ -35,17 +35,17 @@ public final class SocksInitResponse extends SocksResponse {
} }
/** /**
* Returns the {@link AuthScheme} of this {@link SocksInitResponse} * Returns the {@link SocksAuthScheme} of this {@link SocksInitResponse}
* *
* @return The {@link AuthScheme} of this {@link SocksInitResponse} * @return The {@link SocksAuthScheme} of this {@link SocksInitResponse}
*/ */
public AuthScheme authScheme() { public SocksAuthScheme authScheme() {
return authScheme; return authScheme;
} }
@Override @Override
public void encodeAsByteBuf(ByteBuf byteBuf) { public void encodeAsByteBuf(ByteBuf byteBuf) {
byteBuf.writeByte(protocolVersion().getByteValue()); byteBuf.writeByte(protocolVersion().byteValue());
byteBuf.writeByte(authScheme.getByteValue()); byteBuf.writeByte(authScheme.byteValue());
} }
} }

View File

@ -30,8 +30,8 @@ public class SocksInitResponseDecoder extends ReplayingDecoder<SocksInitResponse
return name; return name;
} }
private SocksMessage.ProtocolVersion version; private SocksProtocolVersion version;
private SocksMessage.AuthScheme authScheme; private SocksAuthScheme authScheme;
private SocksResponse msg = SocksCommonUtils.UNKNOWN_SOCKS_RESPONSE; private SocksResponse msg = SocksCommonUtils.UNKNOWN_SOCKS_RESPONSE;
@ -43,14 +43,14 @@ public class SocksInitResponseDecoder extends ReplayingDecoder<SocksInitResponse
protected SocksResponse decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception { protected SocksResponse decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
switch (state()) { switch (state()) {
case CHECK_PROTOCOL_VERSION: { case CHECK_PROTOCOL_VERSION: {
version = SocksMessage.ProtocolVersion.fromByte(byteBuf.readByte()); version = SocksProtocolVersion.fromByte(byteBuf.readByte());
if (version != SocksMessage.ProtocolVersion.SOCKS5) { if (version != SocksProtocolVersion.SOCKS5) {
break; break;
} }
checkpoint(State.READ_PREFFERED_AUTH_TYPE); checkpoint(State.READ_PREFFERED_AUTH_TYPE);
} }
case READ_PREFFERED_AUTH_TYPE: { case READ_PREFFERED_AUTH_TYPE: {
authScheme = SocksMessage.AuthScheme.fromByte(byteBuf.readByte()); authScheme = SocksAuthScheme.fromByte(byteBuf.readByte());
msg = new SocksInitResponse(authScheme); msg = new SocksInitResponse(authScheme);
break; break;
} }
@ -59,7 +59,7 @@ public class SocksInitResponseDecoder extends ReplayingDecoder<SocksInitResponse
return msg; return msg;
} }
public enum State { enum State {
CHECK_PROTOCOL_VERSION, CHECK_PROTOCOL_VERSION,
READ_PREFFERED_AUTH_TYPE READ_PREFFERED_AUTH_TYPE
} }

View File

@ -26,10 +26,10 @@ import io.netty.buffer.ByteBuf;
*/ */
public abstract class SocksMessage { public abstract class SocksMessage {
private final MessageType type; private final SocksMessageType type;
private final ProtocolVersion protocolVersion = ProtocolVersion.SOCKS5; private final SocksProtocolVersion protocolVersion = SocksProtocolVersion.SOCKS5;
protected SocksMessage(MessageType type) { protected SocksMessage(SocksMessageType type) {
if (type == null) { if (type == null) {
throw new NullPointerException("type"); throw new NullPointerException("type");
} }
@ -37,209 +37,20 @@ public abstract class SocksMessage {
} }
/** /**
* Returns the {@link MessageType} of this {@link SocksMessage} * Returns the {@link SocksMessageType} of this {@link SocksMessage}
* *
* @return The {@link MessageType} of this {@link SocksMessage} * @return The {@link SocksMessageType} of this {@link SocksMessage}
*/ */
public MessageType type() { public SocksMessageType type() {
return type; return type;
} }
public enum MessageType {
REQUEST,
RESPONSE,
UNKNOWN
}
public enum AuthScheme {
NO_AUTH((byte) 0x00),
AUTH_GSSAPI((byte) 0x01),
AUTH_PASSWORD((byte) 0x02),
UNKNOWN((byte) 0xff);
private final byte b;
AuthScheme(byte b) {
this.b = b;
}
public static AuthScheme fromByte(byte b) {
for (AuthScheme code : values()) {
if (code.b == b) {
return code;
}
}
return UNKNOWN;
}
public byte getByteValue() {
return b;
}
}
public enum CmdType {
CONNECT((byte) 0x01),
BIND((byte) 0x02),
UDP((byte) 0x03),
UNKNOWN((byte) 0xff);
private final byte b;
CmdType(byte b) {
this.b = b;
}
public static CmdType fromByte(byte b) {
for (CmdType code : values()) {
if (code.b == b) {
return code;
}
}
return UNKNOWN;
}
public byte getByteValue() {
return b;
}
}
public enum AddressType {
IPv4((byte) 0x01),
DOMAIN((byte) 0x03),
IPv6((byte) 0x04),
UNKNOWN((byte) 0xff);
private final byte b;
AddressType(byte b) {
this.b = b;
}
public static AddressType fromByte(byte b) {
for (AddressType code : values()) {
if (code.b == b) {
return code;
}
}
return UNKNOWN;
}
public byte getByteValue() {
return b;
}
}
public enum AuthStatus {
SUCCESS((byte) 0x00),
FAILURE((byte) 0xff);
private final byte b;
AuthStatus(byte b) {
this.b = b;
}
public static AuthStatus fromByte(byte b) {
for (AuthStatus code : values()) {
if (code.b == b) {
return code;
}
}
return FAILURE;
}
public byte getByteValue() {
return b;
}
}
public enum CmdStatus {
SUCCESS((byte) 0x00),
FAILURE((byte) 0x01),
FORBIDDEN((byte) 0x02),
NETWORK_UNREACHABLE((byte) 0x03),
HOST_UNREACHABLE((byte) 0x04),
REFUSED((byte) 0x05),
TTL_EXPIRED((byte) 0x06),
COMMAND_NOT_SUPPORTED((byte) 0x07),
ADDRESS_NOT_SUPPORTED((byte) 0x08),
UNASSIGNED((byte) 0xff);
private final byte b;
CmdStatus(byte b) {
this.b = b;
}
public static CmdStatus fromByte(byte b) {
for (CmdStatus code : values()) {
if (code.b == b) {
return code;
}
}
return UNASSIGNED;
}
public byte getByteValue() {
return b;
}
}
public enum ProtocolVersion {
SOCKS4a((byte) 0x04),
SOCKS5((byte) 0x05),
UNKNOWN((byte) 0xff);
private final byte b;
ProtocolVersion(byte b) {
this.b = b;
}
public static ProtocolVersion fromByte(byte b) {
for (ProtocolVersion code : values()) {
if (code.b == b) {
return code;
}
}
return UNKNOWN;
}
public byte getByteValue() {
return b;
}
}
public enum SubnegotiationVersion {
AUTH_PASSWORD((byte) 0x01),
UNKNOWN((byte) 0xff);
private final byte b;
SubnegotiationVersion(byte b) {
this.b = b;
}
public static SubnegotiationVersion fromByte(byte b) {
for (SubnegotiationVersion code : values()) {
if (code.b == b) {
return code;
}
}
return UNKNOWN;
}
public byte getByteValue() {
return b;
}
}
/** /**
* Returns the {@link ProtocolVersion} of this {@link SocksMessage} * Returns the {@link SocksProtocolVersion} of this {@link SocksMessage}
* *
* @return The {@link ProtocolVersion} of this {@link SocksMessage} * @return The {@link SocksProtocolVersion} of this {@link SocksMessage}
*/ */
public ProtocolVersion protocolVersion() { public SocksProtocolVersion protocolVersion() {
return protocolVersion; return protocolVersion;
} }

View File

@ -0,0 +1,23 @@
/*
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.handler.codec.socks;
public enum SocksMessageType {
REQUEST,
RESPONSE,
UNKNOWN
}

View File

@ -0,0 +1,42 @@
/*
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.handler.codec.socks;
public enum SocksProtocolVersion {
SOCKS4a((byte) 0x04),
SOCKS5((byte) 0x05),
UNKNOWN((byte) 0xff);
private final byte b;
SocksProtocolVersion(byte b) {
this.b = b;
}
public static SocksProtocolVersion fromByte(byte b) {
for (SocksProtocolVersion code : values()) {
if (code.b == b) {
return code;
}
}
return UNKNOWN;
}
public byte byteValue() {
return b;
}
}

View File

@ -28,7 +28,7 @@ public abstract class SocksRequest extends SocksMessage {
private final SocksRequestType requestType; private final SocksRequestType requestType;
protected SocksRequest(SocksRequestType requestType) { protected SocksRequest(SocksRequestType requestType) {
super(MessageType.REQUEST); super(SocksMessageType.REQUEST);
if (requestType == null) { if (requestType == null) {
throw new NullPointerException("requestType"); throw new NullPointerException("requestType");
} }
@ -43,14 +43,4 @@ public abstract class SocksRequest extends SocksMessage {
public SocksRequestType requestType() { public SocksRequestType requestType() {
return requestType; return requestType;
} }
/**
* Type of socks request
*/
public enum SocksRequestType {
INIT,
AUTH,
CMD,
UNKNOWN
}
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012 The Netty Project * Copyright 2013 The Netty Project
* *
* The Netty Project licenses this file to you under the Apache License, * The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance * version 2.0 (the "License"); you may not use this file except in compliance
@ -13,24 +13,15 @@
* License for the specific language governing permissions and limitations * License for the specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package io.netty.handler.codec.socks; package io.netty.handler.codec.socks;
import io.netty.buffer.ByteBuf;
/** /**
* An unknown socks message. * Type of socks request
*
* @see UnknownSocksRequest
* @see UnknownSocksResponse
*/ */
public final class UnknownSocksMessage extends SocksMessage { public enum SocksRequestType {
INIT,
public UnknownSocksMessage() { AUTH,
super(MessageType.UNKNOWN); CMD,
} UNKNOWN
@Override
public void encodeAsByteBuf(ByteBuf byteBuf) {
// NOOP
}
} }

View File

@ -28,7 +28,7 @@ public abstract class SocksResponse extends SocksMessage {
private final SocksResponseType responseType; private final SocksResponseType responseType;
protected SocksResponse(SocksResponseType responseType) { protected SocksResponse(SocksResponseType responseType) {
super(MessageType.RESPONSE); super(SocksMessageType.RESPONSE);
if (responseType == null) { if (responseType == null) {
throw new NullPointerException("responseType"); throw new NullPointerException("responseType");
} }
@ -43,14 +43,4 @@ public abstract class SocksResponse extends SocksMessage {
public SocksResponseType responseType() { public SocksResponseType responseType() {
return responseType; return responseType;
} }
/**
* Type of socks response
*/
public enum SocksResponseType {
INIT,
AUTH,
CMD,
UNKNOWN
}
} }

View File

@ -0,0 +1,27 @@
/*
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.handler.codec.socks;
/**
* Type of socks response
*/
public enum SocksResponseType {
INIT,
AUTH,
CMD,
UNKNOWN
}

View File

@ -0,0 +1,42 @@
/*
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.handler.codec.socks;
public enum SocksSubnegotiationVersion {
AUTH_PASSWORD((byte) 0x01),
UNKNOWN((byte) 0xff);
private final byte b;
SocksSubnegotiationVersion(byte b) {
this.b = b;
}
public static SocksSubnegotiationVersion fromByte(byte b) {
for (SocksSubnegotiationVersion code : values()) {
if (code.b == b) {
return code;
}
}
return UNKNOWN;
}
public byte byteValue() {
return b;
}
}

View File

@ -16,5 +16,8 @@
/** /**
* Encoder, decoder and their related message types for Socks. * Encoder, decoder and their related message types for Socks.
*
* @apiviz.exclude \.Socks.*(Type|Version|Status|Scheme)$
*/ */
package io.netty.handler.codec.socks; package io.netty.handler.codec.socks;
// TODO: Combine decoders into one.

View File

@ -24,7 +24,7 @@ import static org.junit.Assert.*;
public class SocksAuthResponseDecoderTest { public class SocksAuthResponseDecoderTest {
private static final Logger logger = LoggerFactory.getLogger(SocksAuthResponseDecoderTest.class); private static final Logger logger = LoggerFactory.getLogger(SocksAuthResponseDecoderTest.class);
private static void testSocksAuthResponseDecoderWithDifferentParams(SocksMessage.AuthStatus authStatus){ private static void testSocksAuthResponseDecoderWithDifferentParams(SocksAuthStatus 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();
@ -37,7 +37,7 @@ public class SocksAuthResponseDecoderTest {
@Test @Test
public void testSocksCmdResponseDecoder(){ public void testSocksCmdResponseDecoder(){
for (SocksMessage.AuthStatus authStatus: SocksMessage.AuthStatus.values()){ for (SocksAuthStatus authStatus: SocksAuthStatus.values()){
testSocksAuthResponseDecoderWithDifferentParams(authStatus); testSocksAuthResponseDecoderWithDifferentParams(authStatus);
} }
} }

View File

@ -26,13 +26,13 @@ import static org.junit.Assert.*;
public class SocksCmdRequestDecoderTest { public class SocksCmdRequestDecoderTest {
private static final Logger logger = LoggerFactory.getLogger(SocksCmdRequestDecoderTest.class); private static final Logger logger = LoggerFactory.getLogger(SocksCmdRequestDecoderTest.class);
private static void testSocksCmdRequestDecoderWithDifferentParams(SocksMessage.CmdType cmdType, SocksMessage.AddressType addressType, String host, int port) { private static void testSocksCmdRequestDecoderWithDifferentParams(SocksCmdType cmdType, SocksAddressType 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();
EmbeddedByteChannel embedder = new EmbeddedByteChannel(decoder); EmbeddedByteChannel embedder = new EmbeddedByteChannel(decoder);
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg); SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
if (msg.addressType() == SocksMessage.AddressType.UNKNOWN) { if (msg.addressType() == SocksAddressType.UNKNOWN) {
assertTrue(embedder.readInbound() instanceof UnknownSocksRequest); assertTrue(embedder.readInbound() instanceof UnknownSocksRequest);
} else { } else {
msg = (SocksCmdRequest) embedder.readInbound(); msg = (SocksCmdRequest) embedder.readInbound();
@ -48,10 +48,10 @@ public class SocksCmdRequestDecoderTest {
public void testCmdRequestDecoderIPv4() { public void testCmdRequestDecoderIPv4() {
String[] hosts = {"127.0.0.1",}; String[] hosts = {"127.0.0.1",};
int[] ports = {0, 32769, 65535 }; int[] ports = {0, 32769, 65535 };
for (SocksMessage.CmdType cmdType : SocksMessage.CmdType.values()) { for (SocksCmdType cmdType : SocksCmdType.values()) {
for (String host : hosts) { for (String host : hosts) {
for (int port : ports) { for (int port : ports) {
testSocksCmdRequestDecoderWithDifferentParams(cmdType, SocksMessage.AddressType.IPv4, host, port); testSocksCmdRequestDecoderWithDifferentParams(cmdType, SocksAddressType.IPv4, host, port);
} }
} }
} }
@ -61,10 +61,10 @@ public class SocksCmdRequestDecoderTest {
public void testCmdRequestDecoderIPv6() { public void testCmdRequestDecoderIPv6() {
String[] hosts = {SocksCommonUtils.ipv6toStr(IPAddressUtil.textToNumericFormatV6("::1"))}; String[] hosts = {SocksCommonUtils.ipv6toStr(IPAddressUtil.textToNumericFormatV6("::1"))};
int[] ports = {0, 32769, 65535}; int[] ports = {0, 32769, 65535};
for (SocksMessage.CmdType cmdType : SocksMessage.CmdType.values()) { for (SocksCmdType cmdType : SocksCmdType.values()) {
for (String host : hosts) { for (String host : hosts) {
for (int port : ports) { for (int port : ports) {
testSocksCmdRequestDecoderWithDifferentParams(cmdType, SocksMessage.AddressType.IPv6, host, port); testSocksCmdRequestDecoderWithDifferentParams(cmdType, SocksAddressType.IPv6, host, port);
} }
} }
} }
@ -85,10 +85,10 @@ public class SocksCmdRequestDecoderTest {
"실례.테스트", "실례.테스트",
"உதாரணம்.பரிட்சை"}; "உதாரணம்.பரிட்சை"};
int[] ports = {0, 32769, 65535}; int[] ports = {0, 32769, 65535};
for (SocksMessage.CmdType cmdType : SocksMessage.CmdType.values()) { for (SocksCmdType cmdType : SocksCmdType.values()) {
for (String host : hosts) { for (String host : hosts) {
for (int port : ports) { for (int port : ports) {
testSocksCmdRequestDecoderWithDifferentParams(cmdType, SocksMessage.AddressType.DOMAIN, host, port); testSocksCmdRequestDecoderWithDifferentParams(cmdType, SocksAddressType.DOMAIN, host, port);
} }
} }
} }
@ -98,8 +98,8 @@ public class SocksCmdRequestDecoderTest {
public void testCmdRequestDecoderUnknown() { public void testCmdRequestDecoderUnknown() {
String host = "google.com"; String host = "google.com";
int port = 80; int port = 80;
for (SocksMessage.CmdType cmdType : SocksMessage.CmdType.values()) { for (SocksCmdType cmdType : SocksCmdType.values()) {
testSocksCmdRequestDecoderWithDifferentParams(cmdType, SocksMessage.AddressType.UNKNOWN, host, port); testSocksCmdRequestDecoderWithDifferentParams(cmdType, SocksAddressType.UNKNOWN, host, port);
} }
} }
} }

View File

@ -16,25 +16,26 @@
package io.netty.handler.codec.socks; package io.netty.handler.codec.socks;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
public class SocksCmdRequestTest { public class SocksCmdRequestTest {
@Test @Test
public void testConstructorParamsAreNotNull(){ public void testConstructorParamsAreNotNull(){
try { try {
new SocksCmdRequest(null, SocksMessage.AddressType.UNKNOWN, "", 0); new SocksCmdRequest(null, SocksAddressType.UNKNOWN, "", 0);
} catch (Exception e){ } catch (Exception e){
assertTrue(e instanceof NullPointerException); assertTrue(e instanceof NullPointerException);
} }
try { try {
new SocksCmdRequest(SocksMessage.CmdType.UNKNOWN, null, "", 0); new SocksCmdRequest(SocksCmdType.UNKNOWN, null, "", 0);
} catch (Exception e){ } catch (Exception e){
assertTrue(e instanceof NullPointerException); assertTrue(e instanceof NullPointerException);
} }
try { try {
new SocksCmdRequest(SocksMessage.CmdType.UNKNOWN, SocksMessage.AddressType.UNKNOWN, null, 0); new SocksCmdRequest(SocksCmdType.UNKNOWN, SocksAddressType.UNKNOWN, null, 0);
} catch (Exception e){ } catch (Exception e){
assertTrue(e instanceof NullPointerException); assertTrue(e instanceof NullPointerException);
} }
@ -43,7 +44,7 @@ public class SocksCmdRequestTest {
@Test @Test
public void testIPv4CorrectAddress(){ public void testIPv4CorrectAddress(){
try { try {
new SocksCmdRequest(SocksMessage.CmdType.BIND, SocksMessage.AddressType.IPv4, "54.54.1111.253", 0); new SocksCmdRequest(SocksCmdType.BIND, SocksAddressType.IPv4, "54.54.1111.253", 0);
} catch (Exception e){ } catch (Exception e){
assertTrue(e instanceof IllegalArgumentException); assertTrue(e instanceof IllegalArgumentException);
} }
@ -52,7 +53,7 @@ public class SocksCmdRequestTest {
@Test @Test
public void testIPv6CorrectAddress(){ public void testIPv6CorrectAddress(){
try { try {
new SocksCmdRequest(SocksMessage.CmdType.BIND, SocksMessage.AddressType.IPv6, "xxx:xxx:xxx", 0); new SocksCmdRequest(SocksCmdType.BIND, SocksAddressType.IPv6, "xxx:xxx:xxx", 0);
} catch (Exception e){ } catch (Exception e){
assertTrue(e instanceof IllegalArgumentException); assertTrue(e instanceof IllegalArgumentException);
} }
@ -61,7 +62,7 @@ public class SocksCmdRequestTest {
@Test @Test
public void testIDNNotExceeds255CharsLimit(){ public void testIDNNotExceeds255CharsLimit(){
try { try {
new SocksCmdRequest(SocksMessage.CmdType.BIND, SocksMessage.AddressType.DOMAIN, new SocksCmdRequest(SocksCmdType.BIND, SocksAddressType.DOMAIN,
"παράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμή" + "παράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμή" +
"παράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμή" + "παράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμή" +
"παράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμή" + "παράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμήπαράδειγμα.δοκιμή" +
@ -74,14 +75,14 @@ public class SocksCmdRequestTest {
@Test @Test
public void testValidPortRange(){ public void testValidPortRange(){
try { try {
new SocksCmdRequest(SocksMessage.CmdType.BIND, SocksMessage.AddressType.DOMAIN, new SocksCmdRequest(SocksCmdType.BIND, SocksAddressType.DOMAIN,
"παράδειγμα.δοκιμήπαράδει", -1); "παράδειγμα.δοκιμήπαράδει", -1);
} catch (Exception e){ } catch (Exception e){
assertTrue(e instanceof IllegalArgumentException); assertTrue(e instanceof IllegalArgumentException);
} }
try { try {
new SocksCmdRequest(SocksMessage.CmdType.BIND, SocksMessage.AddressType.DOMAIN, new SocksCmdRequest(SocksCmdType.BIND, SocksAddressType.DOMAIN,
"παράδειγμα.δοκιμήπαράδει", 65536); "παράδειγμα.δοκιμήπαράδει", 65536);
} catch (Exception e){ } catch (Exception e){
assertTrue(e instanceof IllegalArgumentException); assertTrue(e instanceof IllegalArgumentException);

View File

@ -25,13 +25,13 @@ import static org.junit.Assert.*;
public class SocksCmdResponseDecoderTest { public class SocksCmdResponseDecoderTest {
private static final Logger logger = LoggerFactory.getLogger(SocksCmdResponseDecoderTest.class); private static final Logger logger = LoggerFactory.getLogger(SocksCmdResponseDecoderTest.class);
private static void testSocksCmdResponseDecoderWithDifferentParams(SocksMessage.CmdStatus cmdStatus, SocksMessage.AddressType addressType){ private static void testSocksCmdResponseDecoderWithDifferentParams(SocksCmdStatus cmdStatus, SocksAddressType 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();
EmbeddedByteChannel embedder = new EmbeddedByteChannel(decoder); EmbeddedByteChannel embedder = new EmbeddedByteChannel(decoder);
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg); SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
if (addressType == SocksMessage.AddressType.UNKNOWN){ if (addressType == SocksAddressType.UNKNOWN){
assertTrue(embedder.readInbound() instanceof UnknownSocksResponse); assertTrue(embedder.readInbound() instanceof UnknownSocksResponse);
} else { } else {
msg = (SocksResponse) embedder.readInbound(); msg = (SocksResponse) embedder.readInbound();
@ -42,8 +42,8 @@ public class SocksCmdResponseDecoderTest {
@Test @Test
public void testSocksCmdResponseDecoder(){ public void testSocksCmdResponseDecoder(){
for (SocksMessage.CmdStatus cmdStatus: SocksMessage.CmdStatus.values()){ for (SocksCmdStatus cmdStatus: SocksCmdStatus.values()){
for (SocksMessage.AddressType addressType: SocksMessage.AddressType.values()){ for (SocksAddressType addressType: SocksAddressType.values()){
testSocksCmdResponseDecoderWithDifferentParams(cmdStatus, addressType); testSocksCmdResponseDecoderWithDifferentParams(cmdStatus, addressType);
} }
} }

View File

@ -16,18 +16,19 @@
package io.netty.handler.codec.socks; package io.netty.handler.codec.socks;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
public class SocksCmdResponseTest { public class SocksCmdResponseTest {
@Test @Test
public void testConstructorParamsAreNotNull() { public void testConstructorParamsAreNotNull() {
try { try {
new SocksCmdResponse(null, SocksMessage.AddressType.UNKNOWN); new SocksCmdResponse(null, SocksAddressType.UNKNOWN);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e instanceof NullPointerException); assertTrue(e instanceof NullPointerException);
} }
try { try {
new SocksCmdResponse(SocksMessage.CmdStatus.UNASSIGNED, null); new SocksCmdResponse(SocksCmdStatus.UNASSIGNED, null);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e instanceof NullPointerException); assertTrue(e instanceof NullPointerException);
} }

View File

@ -19,6 +19,10 @@ import java.lang.ref.Reference;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/**
*
* @apiviz.has io.netty.handler.codec.serialization.ClassResolver oneway - - creates
*/
public final class ClassResolvers { public final class ClassResolvers {
/** /**

View File

@ -19,7 +19,7 @@ import java.lang.ref.Reference;
import java.lang.ref.SoftReference; import java.lang.ref.SoftReference;
import java.util.Map; import java.util.Map;
public class SoftReferenceMap<K, V> extends ReferenceMap<K, V> { final class SoftReferenceMap<K, V> extends ReferenceMap<K, V> {
public SoftReferenceMap(Map<K, Reference<V>> delegate) { public SoftReferenceMap(Map<K, Reference<V>> delegate) {
super(delegate); super(delegate);

View File

@ -19,7 +19,7 @@ import java.lang.ref.Reference;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.Map; import java.util.Map;
public class WeakReferenceMap<K, V> extends ReferenceMap<K, V> { final class WeakReferenceMap<K, V> extends ReferenceMap<K, V> {
public WeakReferenceMap(Map<K, Reference<V>> delegate) { public WeakReferenceMap(Map<K, Reference<V>> delegate) {
super(delegate); super(delegate);

View File

@ -19,6 +19,8 @@ package io.netty.util;
* Holds {@link Attribute}s which can be accessed via {@link AttributeKey}. * Holds {@link Attribute}s which can be accessed via {@link AttributeKey}.
* *
* Implementations must be Thread-safe. * Implementations must be Thread-safe.
*
* @apiviz.composedOf io.netty.util.Attribute oneway - - creates
*/ */
public interface AttributeMap { public interface AttributeMap {
/** /**

View File

@ -26,6 +26,9 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
/**
* @apiviz.has io.netty.util.ResourceLeak oneway - - creates
*/
public final class ResourceLeakDetector<T> { public final class ResourceLeakDetector<T> {
private static final boolean ENABLED = SystemPropertyUtil.getBoolean("io.netty.resourceLeakDetection", false); private static final boolean ENABLED = SystemPropertyUtil.getBoolean("io.netty.resourceLeakDetection", false);

View File

@ -21,6 +21,6 @@
* @apiviz.exclude ^java\.(lang|util)\. * @apiviz.exclude ^java\.(lang|util)\.
* @apiviz.exclude \.netty\.(?!util)[a-z0-9]+\. * @apiviz.exclude \.netty\.(?!util)[a-z0-9]+\.
* @apiviz.exclude Util$ * @apiviz.exclude Util$
* @apiviz.exclude \.EstimatableObjectWrapper$ * @apiviz.exclude Exception$
*/ */
package io.netty.util; package io.netty.util;

View File

@ -26,8 +26,7 @@ import io.netty.channel.ChannelOption;
import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.socks.SocksCmdRequest; import io.netty.handler.codec.socks.SocksCmdRequest;
import io.netty.handler.codec.socks.SocksCmdResponse; import io.netty.handler.codec.socks.SocksCmdResponse;
import io.netty.handler.codec.socks.SocksMessage; import io.netty.handler.codec.socks.SocksCmdStatus;
@ChannelHandler.Sharable @ChannelHandler.Sharable
public final class SocksServerConnectHandler extends ChannelInboundMessageHandlerAdapter<SocksCmdRequest> { public final class SocksServerConnectHandler extends ChannelInboundMessageHandlerAdapter<SocksCmdRequest> {
@ -44,7 +43,7 @@ public final class SocksServerConnectHandler extends ChannelInboundMessageHandle
CallbackNotifier cb = new CallbackNotifier() { CallbackNotifier cb = new CallbackNotifier() {
@Override @Override
public void onSuccess(final ChannelHandlerContext outboundCtx) { public void onSuccess(final ChannelHandlerContext outboundCtx) {
ctx.channel().write(new SocksCmdResponse(SocksMessage.CmdStatus.SUCCESS, request.addressType())) ctx.channel().write(new SocksCmdResponse(SocksCmdStatus.SUCCESS, request.addressType()))
.addListener(new ChannelFutureListener() { .addListener(new ChannelFutureListener() {
@Override @Override
public void operationComplete(ChannelFuture channelFuture) throws Exception { public void operationComplete(ChannelFuture channelFuture) throws Exception {
@ -57,7 +56,7 @@ public final class SocksServerConnectHandler extends ChannelInboundMessageHandle
@Override @Override
public void onFailure(ChannelHandlerContext outboundCtx, Throwable cause) { public void onFailure(ChannelHandlerContext outboundCtx, Throwable cause) {
ctx.channel().write(new SocksCmdResponse(SocksMessage.CmdStatus.FAILURE, request.addressType())); ctx.channel().write(new SocksCmdResponse(SocksCmdStatus.FAILURE, request.addressType()));
SocksServerUtils.closeOnFlush(ctx.channel()); SocksServerUtils.closeOnFlush(ctx.channel());
} }
}; };

View File

@ -19,10 +19,12 @@ 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.handler.codec.socks.SocksAuthResponse; import io.netty.handler.codec.socks.SocksAuthResponse;
import io.netty.handler.codec.socks.SocksAuthScheme;
import io.netty.handler.codec.socks.SocksAuthStatus;
import io.netty.handler.codec.socks.SocksCmdRequest; import io.netty.handler.codec.socks.SocksCmdRequest;
import io.netty.handler.codec.socks.SocksCmdRequestDecoder; import io.netty.handler.codec.socks.SocksCmdRequestDecoder;
import io.netty.handler.codec.socks.SocksCmdType;
import io.netty.handler.codec.socks.SocksInitResponse; import io.netty.handler.codec.socks.SocksInitResponse;
import io.netty.handler.codec.socks.SocksMessage;
import io.netty.handler.codec.socks.SocksRequest; import io.netty.handler.codec.socks.SocksRequest;
@ -40,18 +42,18 @@ public final class SocksServerHandler extends ChannelInboundMessageHandlerAdapte
case INIT: { case INIT: {
// auth support example // auth support example
// ctx.pipeline().addFirst("socksAuthRequestDecoder",new SocksAuthRequestDecoder()); // ctx.pipeline().addFirst("socksAuthRequestDecoder",new SocksAuthRequestDecoder());
// ctx.write(new SocksInitResponse(SocksMessage.AuthScheme.AUTH_PASSWORD)); // ctx.write(new SocksInitResponse(SocksMessage.SocksAuthScheme.AUTH_PASSWORD));
ctx.pipeline().addFirst(SocksCmdRequestDecoder.getName(), new SocksCmdRequestDecoder()); ctx.pipeline().addFirst(SocksCmdRequestDecoder.getName(), new SocksCmdRequestDecoder());
ctx.write(new SocksInitResponse(SocksMessage.AuthScheme.NO_AUTH)); ctx.write(new SocksInitResponse(SocksAuthScheme.NO_AUTH));
break; break;
} }
case AUTH: case AUTH:
ctx.pipeline().addFirst(SocksCmdRequestDecoder.getName(), new SocksCmdRequestDecoder()); ctx.pipeline().addFirst(SocksCmdRequestDecoder.getName(), new SocksCmdRequestDecoder());
ctx.write(new SocksAuthResponse(SocksMessage.AuthStatus.SUCCESS)); ctx.write(new SocksAuthResponse(SocksAuthStatus.SUCCESS));
break; break;
case CMD: case CMD:
SocksCmdRequest req = (SocksCmdRequest) socksRequest; SocksCmdRequest req = (SocksCmdRequest) socksRequest;
if (req.cmdType() == SocksMessage.CmdType.CONNECT) { if (req.cmdType() == SocksCmdType.CONNECT) {
ctx.pipeline().addLast(SocksServerConnectHandler.getName(), new SocksServerConnectHandler()); ctx.pipeline().addLast(SocksServerConnectHandler.getName(), new SocksServerConnectHandler());
ctx.pipeline().remove(this); ctx.pipeline().remove(this);
ctx.nextInboundMessageBuffer().add(socksRequest); ctx.nextInboundMessageBuffer().add(socksRequest);