SocksCmdResponseDecoder Class — netty Architecture
Architecture documentation for the SocksCmdResponseDecoder class in SocksCmdResponseDecoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD fc217319_ea26_738e_cb17_c96d845bfede["SocksCmdResponseDecoder"] ed9bccd9_06d6_85c5_2b79_4f8bcb41d8f3["SocksCmdResponseDecoder.java"] fc217319_ea26_738e_cb17_c96d845bfede -->|defined in| ed9bccd9_06d6_85c5_2b79_4f8bcb41d8f3 10148219_e77a_1031_759e_d26d9328c529["SocksCmdResponseDecoder()"] fc217319_ea26_738e_cb17_c96d845bfede -->|method| 10148219_e77a_1031_759e_d26d9328c529 7f156ba5_0a17_3c8d_259d_a318222f13f3["decode()"] fc217319_ea26_738e_cb17_c96d845bfede -->|method| 7f156ba5_0a17_3c8d_259d_a318222f13f3
Relationship Graph
Source Code
codec-socks/src/main/java/io/netty/handler/codec/socks/SocksCmdResponseDecoder.java lines 33–104
public class SocksCmdResponseDecoder extends ReplayingDecoder<State> {
private SocksCmdStatus cmdStatus;
private SocksAddressType addressType;
public SocksCmdResponseDecoder() {
super(State.CHECK_PROTOCOL_VERSION);
}
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List<Object> out) throws Exception {
switch (state()) {
case CHECK_PROTOCOL_VERSION: {
if (byteBuf.readByte() != SocksProtocolVersion.SOCKS5.byteValue()) {
out.add(SocksCommonUtils.UNKNOWN_SOCKS_RESPONSE);
break;
}
checkpoint(State.READ_CMD_HEADER);
}
case READ_CMD_HEADER: {
cmdStatus = SocksCmdStatus.valueOf(byteBuf.readByte());
byteBuf.skipBytes(1); // reserved
addressType = SocksAddressType.valueOf(byteBuf.readByte());
checkpoint(State.READ_CMD_ADDRESS);
}
case READ_CMD_ADDRESS: {
switch (addressType) {
case IPv4: {
String host = NetUtil.intToIpAddress(ByteBufUtil.readIntBE(byteBuf));
int port = ByteBufUtil.readUnsignedShortBE(byteBuf);
out.add(new SocksCmdResponse(cmdStatus, addressType, host, port));
break;
}
case DOMAIN: {
int fieldLength = byteBuf.readByte();
String host = byteBuf.readString(fieldLength, CharsetUtil.US_ASCII);
int port = ByteBufUtil.readUnsignedShortBE(byteBuf);
out.add(new SocksCmdResponse(cmdStatus, addressType, host, port));
break;
}
case IPv6: {
byte[] bytes = new byte[16];
byteBuf.readBytes(bytes);
String host = SocksCommonUtils.ipv6toStr(bytes);
int port = ByteBufUtil.readUnsignedShortBE(byteBuf);
out.add(new SocksCmdResponse(cmdStatus, addressType, host, port));
break;
}
case UNKNOWN: {
out.add(SocksCommonUtils.UNKNOWN_SOCKS_RESPONSE);
break;
}
default: {
throw new Error("Unexpected address type: " + addressType);
}
}
break;
}
default: {
throw new Error("Unexpected response decoder type: " + state());
}
}
ctx.pipeline().remove(this);
}
@UnstableApi
public enum State {
CHECK_PROTOCOL_VERSION,
READ_CMD_HEADER,
READ_CMD_ADDRESS
}
}
Source
Frequently Asked Questions
What is the SocksCmdResponseDecoder class?
SocksCmdResponseDecoder is a class in the netty codebase, defined in codec-socks/src/main/java/io/netty/handler/codec/socks/SocksCmdResponseDecoder.java.
Where is SocksCmdResponseDecoder defined?
SocksCmdResponseDecoder is defined in codec-socks/src/main/java/io/netty/handler/codec/socks/SocksCmdResponseDecoder.java at line 33.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free