@Override protected void addCodec(ChannelHandlerContext ctx) throws Exception { ChannelPipeline p = ctx.pipeline(); String name = ctx.name(); Socks5InitialResponseDecoder decoder = new Socks5InitialResponseDecoder(); p.addBefore(name, null, decoder); decoderName = p.context(decoder).name(); encoderName = decoderName + ".encoder"; p.addBefore(name, encoderName, Socks5ClientEncoder.DEFAULT); }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { try { switch (state()) { case INIT: { final byte version = in.readByte(); if (version != SocksVersion.SOCKS5.byteValue()) { throw new DecoderException( "unsupported version: " + version + " (expected: " + SocksVersion.SOCKS5.byteValue() + ')'); } final Socks5AuthMethod authMethod = Socks5AuthMethod.valueOf(in.readByte()); out.add(new DefaultSocks5InitialResponse(authMethod)); 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); } checkpoint(State.FAILURE); Socks5Message m = new DefaultSocks5InitialResponse(Socks5AuthMethod.UNACCEPTED); m.setDecoderResult(DecoderResult.failure(cause)); out.add(m); } }
private void fail(List<Object> out, Exception cause) { if (!(cause instanceof DecoderException)) { cause = new DecoderException(cause); } checkpoint(State.FAILURE); Socks5Message m = new DefaultSocks5InitialResponse(Socks5AuthMethod.UNACCEPTED); m.setDecoderResult(DecoderResult.failure(cause)); out.add(m); } }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { try { switch (state()) { case INIT: { final byte version = in.readByte(); if (version != SocksVersion.SOCKS5.byteValue()) { throw new DecoderException( "unsupported version: " + version + " (expected: " + SocksVersion.SOCKS5.byteValue() + ')'); } final Socks5AuthMethod authMethod = Socks5AuthMethod.valueOf(in.readByte()); out.add(new DefaultSocks5InitialResponse(authMethod)); 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); } }
@Override protected Future<?> execute() { List<Socks5AuthMethod> authMethods = new ArrayList<>(2); authMethods.add(Socks5AuthMethod.NO_AUTH); if ((username != null) || (password != null)) { authMethods.add(Socks5AuthMethod.PASSWORD); } DefaultSocks5InitialRequest initialRequest = new DefaultSocks5InitialRequest(authMethods); addFirstOrReplaceHandler(SOCKS_ENCODER_NAME, Socks5ClientEncoder.DEFAULT); addFirstOrReplaceHandler(SOCKS_DECODER_NAME, new Socks5InitialResponseDecoder()); return writeToChannel(initialRequest); }
private void fail(List<Object> out, Exception cause) { if (!(cause instanceof DecoderException)) { cause = new DecoderException(cause); } checkpoint(State.FAILURE); Socks5Message m = new DefaultSocks5InitialResponse(Socks5AuthMethod.UNACCEPTED); m.setDecoderResult(DecoderResult.failure(cause)); out.add(m); } }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { try { switch (state()) { case INIT: { final byte version = in.readByte(); if (version != SocksVersion.SOCKS5.byteValue()) { throw new DecoderException( "unsupported version: " + version + " (expected: " + SocksVersion.SOCKS5.byteValue() + ')'); } final Socks5AuthMethod authMethod = Socks5AuthMethod.valueOf(in.readByte()); out.add(new DefaultSocks5InitialResponse(authMethod)); 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); } }
@Override protected void addCodec(ChannelHandlerContext ctx) throws Exception { ChannelPipeline p = ctx.pipeline(); String name = ctx.name(); Socks5InitialResponseDecoder decoder = new Socks5InitialResponseDecoder(); p.addBefore(name, null, decoder); decoderName = p.context(decoder).name(); encoderName = decoderName + ".encoder"; p.addBefore(name, encoderName, Socks5ClientEncoder.DEFAULT); }
@Override protected void addCodec(ChannelHandlerContext ctx) throws Exception { ChannelPipeline p = ctx.pipeline(); String name = ctx.name(); Socks5InitialResponseDecoder decoder = new Socks5InitialResponseDecoder(); p.addBefore(name, null, decoder); decoderName = p.context(decoder).name(); encoderName = decoderName + ".encoder"; p.addBefore(name, encoderName, Socks5ClientEncoder.DEFAULT); }