@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_REQUEST); break; } checkpoint(State.READ_AUTH_SCHEMES); } case READ_AUTH_SCHEMES: { final byte authSchemeNum = byteBuf.readByte(); final List<SocksAuthScheme> authSchemes; if (authSchemeNum > 0) { authSchemes = new ArrayList<SocksAuthScheme>(authSchemeNum); for (int i = 0; i < authSchemeNum; i++) { authSchemes.add(SocksAuthScheme.valueOf(byteBuf.readByte())); } } else { authSchemes = Collections.emptyList(); } out.add(new SocksInitRequest(authSchemes)); break; } default: { throw new Error(); } } ctx.pipeline().remove(this); }
@Override public void initChannel(SocketChannel socketChannel) throws Exception { ChannelPipeline p = socketChannel.pipeline(); p.addLast(new SocksInitRequestDecoder()); p.addLast(socksMessageEncoder); p.addLast(socksServerHandler); p.addLast(trafficHandler); } }
@Override protected void initChannel(SocketChannel socketChannel) throws Exception { socketChannel.pipeline() .addLast("logging", new LoggingHandler(LogLevel.DEBUG)) .addLast(new SocksInitRequestDecoder()) .addLast(new SocksMessageEncoder()) .addLast(new Socks5Handler()) .addLast(Status.TRAFFIC_HANDLER); } });
@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_REQUEST); break; } checkpoint(State.READ_AUTH_SCHEMES); } case READ_AUTH_SCHEMES: { final byte authSchemeNum = byteBuf.readByte(); final List<SocksAuthScheme> authSchemes; if (authSchemeNum > 0) { authSchemes = new ArrayList<SocksAuthScheme>(authSchemeNum); for (int i = 0; i < authSchemeNum; i++) { authSchemes.add(SocksAuthScheme.valueOf(byteBuf.readByte())); } } else { authSchemes = Collections.emptyList(); } out.add(new SocksInitRequest(authSchemes)); break; } default: { throw new Error(); } } ctx.pipeline().remove(this); }
@Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new SocksInitRequestDecoder()).addLast(new SocksCmdRequestDecoder()).addLast(new IdleStateHandler(this.idleRead, this.idleWrite, this.idleAll)).addLast(this.channelHandlerBuilder.build()); } }
@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_REQUEST); break; } checkpoint(State.READ_AUTH_SCHEMES); } case READ_AUTH_SCHEMES: { final byte authSchemeNum = byteBuf.readByte(); final List<SocksAuthScheme> authSchemes; if (authSchemeNum > 0) { authSchemes = new ArrayList<SocksAuthScheme>(authSchemeNum); for (int i = 0; i < authSchemeNum; i++) { authSchemes.add(SocksAuthScheme.valueOf(byteBuf.readByte())); } } else { authSchemes = Collections.emptyList(); } out.add(new SocksInitRequest(authSchemes)); break; } default: { throw new Error(); } } ctx.pipeline().remove(this); }