private void enableSocks4(ChannelHandlerContext ctx, ByteBuf msg) { enableSocks(ctx, msg, new Socks4ProxyHandler(server, mockServerLogger), Socks4ServerEncoder.INSTANCE, new Socks4ServerDecoder()); }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { try { switch (state()) { case START: { final int version = in.readUnsignedByte(); dstPort = in.readUnsignedShort(); dstAddr = NetUtil.intToIpAddress(in.readInt()); checkpoint(State.READ_USERID); userId = readString("userid", in); checkpoint(State.READ_DOMAIN); dstAddr = readString("dstAddr", in); checkpoint(State.SUCCESS); int readableBytes = actualReadableBytes(); if (readableBytes > 0) { out.add(in.readRetainedSlice(readableBytes)); in.skipBytes(actualReadableBytes()); break; fail(out, e);
public Socks4ServerDecoder() { super(State.START); setSingleDecode(true); }
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); checkpoint(State.FAILURE); }
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); checkpoint(State.FAILURE); }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { try { switch (state()) { case START: { final int version = in.readUnsignedByte(); dstPort = in.readUnsignedShort(); dstAddr = NetUtil.intToIpAddress(in.readInt()); checkpoint(State.READ_USERID); userId = readString("userid", in); checkpoint(State.READ_DOMAIN); dstAddr = readString("dstAddr", in); checkpoint(State.SUCCESS); int readableBytes = actualReadableBytes(); if (readableBytes > 0) { out.add(in.readRetainedSlice(readableBytes)); in.skipBytes(actualReadableBytes()); break; fail(out, e);
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { final int readerIndex = in.readerIndex(); if (in.writerIndex() == readerIndex) { return; } ChannelPipeline p = ctx.pipeline(); final byte versionVal = in.getByte(readerIndex); SocksVersion version = SocksVersion.valueOf(versionVal); switch (version) { case SOCKS4a: logKnownVersion(ctx, version); p.addAfter(ctx.name(), null, Socks4ServerEncoder.INSTANCE); p.addAfter(ctx.name(), null, new Socks4ServerDecoder()); break; case SOCKS5: logKnownVersion(ctx, version); p.addAfter(ctx.name(), null, socks5encoder); p.addAfter(ctx.name(), null, new Socks5InitialRequestDecoder()); break; default: logUnknownVersion(ctx, versionVal); in.skipBytes(in.readableBytes()); ctx.close(); return; } p.remove(this); }
public Socks4ServerDecoder() { super(State.START); setSingleDecode(true); }
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); checkpoint(State.FAILURE); }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { try { switch (state()) { case START: { final int version = in.readUnsignedByte(); dstPort = in.readUnsignedShort(); dstAddr = NetUtil.intToIpAddress(in.readInt()); checkpoint(State.READ_USERID); userId = readString("userid", in); checkpoint(State.READ_DOMAIN); dstAddr = readString("dstAddr", in); checkpoint(State.SUCCESS); int readableBytes = actualReadableBytes(); if (readableBytes > 0) { out.add(in.readRetainedSlice(readableBytes)); in.skipBytes(actualReadableBytes()); break; fail(out, e);
private void enableSocks4(ChannelHandlerContext ctx, ByteBuf msg) { enableSocks(ctx, msg, new Socks4ProxyHandler(server, mockServerLogger), Socks4ServerEncoder.INSTANCE, new Socks4ServerDecoder()); }
public Socks4ServerDecoder() { super(State.START); setSingleDecode(true); }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { final int readerIndex = in.readerIndex(); if (in.writerIndex() == readerIndex) { return; } ChannelPipeline p = ctx.pipeline(); final byte versionVal = in.getByte(readerIndex); SocksVersion version = SocksVersion.valueOf(versionVal); switch (version) { case SOCKS4a: logKnownVersion(ctx, version); p.addAfter(ctx.name(), null, Socks4ServerEncoder.INSTANCE); p.addAfter(ctx.name(), null, new Socks4ServerDecoder()); break; case SOCKS5: logKnownVersion(ctx, version); p.addAfter(ctx.name(), null, socks5encoder); p.addAfter(ctx.name(), null, new Socks5InitialRequestDecoder()); break; default: logUnknownVersion(ctx, versionVal); in.skipBytes(in.readableBytes()); ctx.close(); return; } p.remove(this); }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { final int readerIndex = in.readerIndex(); if (in.writerIndex() == readerIndex) { return; } ChannelPipeline p = ctx.pipeline(); final byte versionVal = in.getByte(readerIndex); SocksVersion version = SocksVersion.valueOf(versionVal); switch (version) { case SOCKS4a: logKnownVersion(ctx, version); p.addAfter(ctx.name(), null, Socks4ServerEncoder.INSTANCE); p.addAfter(ctx.name(), null, new Socks4ServerDecoder()); break; case SOCKS5: logKnownVersion(ctx, version); p.addAfter(ctx.name(), null, socks5encoder); p.addAfter(ctx.name(), null, new Socks5InitialRequestDecoder()); break; default: logUnknownVersion(ctx, versionVal); in.skipBytes(in.readableBytes()); ctx.close(); return; } p.remove(this); }