@Override protected void addCodec(ChannelHandlerContext ctx) throws Exception { ChannelPipeline p = ctx.pipeline(); String name = ctx.name(); Socks4ClientDecoder decoder = new Socks4ClientDecoder(); p.addBefore(name, null, decoder); decoderName = p.context(decoder).name(); encoderName = decoderName + ".encoder"; p.addBefore(name, encoderName, Socks4ClientEncoder.INSTANCE); }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { try { switch (state()) { case START: { final int version = in.readUnsignedByte(); checkpoint(State.SUCCESS); int readableBytes = actualReadableBytes(); if (readableBytes > 0) { out.add(in.readRetainedSlice(readableBytes)); in.skipBytes(actualReadableBytes()); break; fail(out, e);
public Socks4ClientDecoder() { super(State.START); setSingleDecode(true); }
private void fail(List<Object> out, Exception cause) { if (!(cause instanceof DecoderException)) { cause = new DecoderException(cause); } Socks4CommandResponse m = new DefaultSocks4CommandResponse(Socks4CommandStatus.REJECTED_OR_FAILED); 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); } Socks4CommandResponse m = new DefaultSocks4CommandResponse(Socks4CommandStatus.REJECTED_OR_FAILED); 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(); checkpoint(State.SUCCESS); int readableBytes = actualReadableBytes(); if (readableBytes > 0) { out.add(in.readRetainedSlice(readableBytes)); in.skipBytes(actualReadableBytes()); break; fail(out, e);
@Override protected Future<?> execute() { InetSocketAddress destinationAddress; try { destinationAddress = addressFor(serverHostAndPort, proxyServer); } catch (UnknownHostException e) { return channel.newFailedFuture(e); } DefaultSocks4CommandRequest connectRequest = new DefaultSocks4CommandRequest( Socks4CommandType.CONNECT, destinationAddress.getHostString(), destinationAddress.getPort()); addFirstOrReplaceHandler(SOCKS_ENCODER_NAME, Socks4ClientEncoder.INSTANCE); addFirstOrReplaceHandler(SOCKS_DECODER_NAME, new Socks4ClientDecoder()); return writeToChannel(connectRequest); }
private void fail(List<Object> out, Exception cause) { if (!(cause instanceof DecoderException)) { cause = new DecoderException(cause); } Socks4CommandResponse m = new DefaultSocks4CommandResponse(Socks4CommandStatus.REJECTED_OR_FAILED); m.setDecoderResult(DecoderResult.failure(cause)); out.add(m); checkpoint(State.FAILURE); } }
public Socks4ClientDecoder() { 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(); checkpoint(State.SUCCESS); int readableBytes = actualReadableBytes(); if (readableBytes > 0) { out.add(in.readRetainedSlice(readableBytes)); in.skipBytes(actualReadableBytes()); break; fail(out, e);
@Override protected void addCodec(ChannelHandlerContext ctx) throws Exception { ChannelPipeline p = ctx.pipeline(); String name = ctx.name(); Socks4ClientDecoder decoder = new Socks4ClientDecoder(); p.addBefore(name, null, decoder); decoderName = p.context(decoder).name(); encoderName = decoderName + ".encoder"; p.addBefore(name, encoderName, Socks4ClientEncoder.INSTANCE); }
public Socks4ClientDecoder() { super(State.START); setSingleDecode(true); }
@Override protected void addCodec(ChannelHandlerContext ctx) throws Exception { ChannelPipeline p = ctx.pipeline(); String name = ctx.name(); Socks4ClientDecoder decoder = new Socks4ClientDecoder(); p.addBefore(name, null, decoder); decoderName = p.context(decoder).name(); encoderName = decoderName + ".encoder"; p.addBefore(name, encoderName, Socks4ClientEncoder.INSTANCE); }