Socks4ServerDecoder Class — netty Architecture
Architecture documentation for the Socks4ServerDecoder class in Socks4ServerDecoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD f3549c11_8ef1_fde3_7585_cf97abbfa145["Socks4ServerDecoder"] 9ac2fa15_2188_3792_0204_78688c8c6e41["Socks4ServerDecoder.java"] f3549c11_8ef1_fde3_7585_cf97abbfa145 -->|defined in| 9ac2fa15_2188_3792_0204_78688c8c6e41 25cd278a_ead0_e47a_151d_d0270919c941["Socks4ServerDecoder()"] f3549c11_8ef1_fde3_7585_cf97abbfa145 -->|method| 25cd278a_ead0_e47a_151d_d0270919c941 1df22ec8_3801_784f_704d_e3f44d44002d["decode()"] f3549c11_8ef1_fde3_7585_cf97abbfa145 -->|method| 1df22ec8_3801_784f_704d_e3f44d44002d 08d49857_8bf5_9ac9_75e1_2f034739ebb2["fail()"] f3549c11_8ef1_fde3_7585_cf97abbfa145 -->|method| 08d49857_8bf5_9ac9_75e1_2f034739ebb2 08ec021e_0e3c_00ce_ac29_756e293dcda8["String()"] f3549c11_8ef1_fde3_7585_cf97abbfa145 -->|method| 08ec021e_0e3c_00ce_ac29_756e293dcda8
Relationship Graph
Source Code
codec-socks/src/main/java/io/netty/handler/codec/socksx/v4/Socks4ServerDecoder.java lines 38–136
public class Socks4ServerDecoder extends ReplayingDecoder<State> {
private static final int MAX_FIELD_LENGTH = 255;
@UnstableApi
public enum State {
START,
READ_USERID,
READ_DOMAIN,
SUCCESS,
FAILURE
}
private Socks4CommandType type;
private String dstAddr;
private int dstPort;
private String userId;
public Socks4ServerDecoder() {
super(State.START);
setSingleDecode(true);
}
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
try {
switch (state()) {
case START: {
final int version = in.readUnsignedByte();
if (version != SocksVersion.SOCKS4a.byteValue()) {
throw new DecoderException("unsupported protocol version: " + version);
}
type = Socks4CommandType.valueOf(in.readByte());
dstPort = ByteBufUtil.readUnsignedShortBE(in);
dstAddr = NetUtil.intToIpAddress(ByteBufUtil.readIntBE(in));
checkpoint(State.READ_USERID);
}
case READ_USERID: {
userId = readString("userid", in);
checkpoint(State.READ_DOMAIN);
}
case READ_DOMAIN: {
// Check for Socks4a protocol marker 0.0.0.x
if (!"0.0.0.0".equals(dstAddr) && dstAddr.startsWith("0.0.0.")) {
dstAddr = readString("dstAddr", in);
}
out.add(new DefaultSocks4CommandRequest(type, dstAddr, dstPort, userId));
checkpoint(State.SUCCESS);
}
case SUCCESS: {
int readableBytes = actualReadableBytes();
if (readableBytes > 0) {
out.add(in.readRetainedSlice(readableBytes));
}
break;
}
case FAILURE: {
in.skipBytes(actualReadableBytes());
break;
}
}
} catch (Exception e) {
fail(out, e);
}
}
private void fail(List<Object> out, Exception cause) {
if (!(cause instanceof DecoderException)) {
cause = new DecoderException(cause);
}
Socks4CommandRequest m = new DefaultSocks4CommandRequest(
type != null? type : Socks4CommandType.CONNECT,
dstAddr != null? dstAddr : "",
dstPort != 0? dstPort : 65535,
userId != null? userId : "");
m.setDecoderResult(DecoderResult.failure(cause));
out.add(m);
Source
Frequently Asked Questions
What is the Socks4ServerDecoder class?
Socks4ServerDecoder is a class in the netty codebase, defined in codec-socks/src/main/java/io/netty/handler/codec/socksx/v4/Socks4ServerDecoder.java.
Where is Socks4ServerDecoder defined?
Socks4ServerDecoder is defined in codec-socks/src/main/java/io/netty/handler/codec/socksx/v4/Socks4ServerDecoder.java at line 38.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free