Home / Class/ Socks5ClientEncoder Class — netty Architecture

Socks5ClientEncoder Class — netty Architecture

Architecture documentation for the Socks5ClientEncoder class in Socks5ClientEncoder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  38438508_6164_1fbb_2974_832cc944b4c7["Socks5ClientEncoder"]
  1368d861_567e_b168_99aa_252ea10ae8ef["Socks5ClientEncoder.java"]
  38438508_6164_1fbb_2974_832cc944b4c7 -->|defined in| 1368d861_567e_b168_99aa_252ea10ae8ef
  0cc1cc9c_9c66_0c34_5c14_7af5c9f67e26["Socks5ClientEncoder()"]
  38438508_6164_1fbb_2974_832cc944b4c7 -->|method| 0cc1cc9c_9c66_0c34_5c14_7af5c9f67e26
  03be0ac8_0f38_70a0_b69f_c80227b0b8c3["Socks5AddressEncoder()"]
  38438508_6164_1fbb_2974_832cc944b4c7 -->|method| 03be0ac8_0f38_70a0_b69f_c80227b0b8c3
  7cc5b5cc_17e1_f6ca_091c_89fabe99b164["encode()"]
  38438508_6164_1fbb_2974_832cc944b4c7 -->|method| 7cc5b5cc_17e1_f6ca_091c_89fabe99b164
  8f9720bd_8235_eaf6_7b80_f05f0cb5a76f["encodeAuthMethodRequest()"]
  38438508_6164_1fbb_2974_832cc944b4c7 -->|method| 8f9720bd_8235_eaf6_7b80_f05f0cb5a76f
  34b7b878_7aca_f110_2f0d_ffa8fb361e0a["encodePasswordAuthRequest()"]
  38438508_6164_1fbb_2974_832cc944b4c7 -->|method| 34b7b878_7aca_f110_2f0d_ffa8fb361e0a
  0e35a09a_4872_130d_303e_d9660780c1cf["encodePrivateAuthRequest()"]
  38438508_6164_1fbb_2974_832cc944b4c7 -->|method| 0e35a09a_4872_130d_303e_d9660780c1cf
  cc71ef6b_55b2_f57d_0a92_7f59249ed52b["encodeCommandRequest()"]
  38438508_6164_1fbb_2974_832cc944b4c7 -->|method| cc71ef6b_55b2_f57d_0a92_7f59249ed52b

Relationship Graph

Source Code

codec-socks/src/main/java/io/netty/handler/codec/socksx/v5/Socks5ClientEncoder.java lines 34–125

@Sharable
public class Socks5ClientEncoder extends MessageToByteEncoder<Socks5Message> {

    public static final Socks5ClientEncoder DEFAULT = new Socks5ClientEncoder();

    private final Socks5AddressEncoder addressEncoder;

    /**
     * Creates a new instance with the default {@link Socks5AddressEncoder}.
     */
    protected Socks5ClientEncoder() {
        this(Socks5AddressEncoder.DEFAULT);
    }

    /**
     * Creates a new instance with the specified {@link Socks5AddressEncoder}.
     */
    public Socks5ClientEncoder(Socks5AddressEncoder addressEncoder) {
        super(Socks5Message.class);
        this.addressEncoder = ObjectUtil.checkNotNull(addressEncoder, "addressEncoder");
    }

    /**
     * Returns the {@link Socks5AddressEncoder} of this encoder.
     */
    protected final Socks5AddressEncoder addressEncoder() {
        return addressEncoder;
    }

    @Override
    protected void encode(ChannelHandlerContext ctx, Socks5Message msg, ByteBuf out) throws Exception {
        if (msg instanceof Socks5InitialRequest) {
            encodeAuthMethodRequest((Socks5InitialRequest) msg, out);
        } else if (msg instanceof Socks5PasswordAuthRequest) {
            encodePasswordAuthRequest((Socks5PasswordAuthRequest) msg, out);
        } else if (msg instanceof Socks5PrivateAuthRequest) {
            encodePrivateAuthRequest((Socks5PrivateAuthRequest) msg, out);
        } else if (msg instanceof Socks5CommandRequest) {
            encodeCommandRequest((Socks5CommandRequest) msg, out);
        } else {
            throw new EncoderException("unsupported message type: " + StringUtil.simpleClassName(msg));
        }
    }

    private static void encodeAuthMethodRequest(Socks5InitialRequest msg, ByteBuf out) {
        out.writeByte(msg.version().byteValue());

        final List<Socks5AuthMethod> authMethods = msg.authMethods();
        final int numAuthMethods = authMethods.size();
        out.writeByte(numAuthMethods);

        if (authMethods instanceof RandomAccess) {
            for (int i = 0; i < numAuthMethods; i ++) {
                out.writeByte(authMethods.get(i).byteValue());
            }
        } else {
            for (Socks5AuthMethod a: authMethods) {
                out.writeByte(a.byteValue());
            }
        }
    }

    private static void encodePasswordAuthRequest(Socks5PasswordAuthRequest msg, ByteBuf out) {
        out.writeByte(0x01);

        final String username = msg.username();
        out.writeByte(username.length());
        ByteBufUtil.writeAscii(out, username);

        final String password = msg.password();
        out.writeByte(password.length());
        ByteBufUtil.writeAscii(out, password);
    }

    private static void encodePrivateAuthRequest(Socks5PrivateAuthRequest msg, ByteBuf out) {
        byte[] bytes = msg.privateToken();
        out.writeByte(0x01);
        out.writeByte(bytes.length);
        out.writeBytes(bytes);
    }

Frequently Asked Questions

What is the Socks5ClientEncoder class?
Socks5ClientEncoder is a class in the netty codebase, defined in codec-socks/src/main/java/io/netty/handler/codec/socksx/v5/Socks5ClientEncoder.java.
Where is Socks5ClientEncoder defined?
Socks5ClientEncoder is defined in codec-socks/src/main/java/io/netty/handler/codec/socksx/v5/Socks5ClientEncoder.java at line 34.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free