protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List <object> output) { try { switch (State) { case Socks5InitialRequestDecoderState.Init: var version = input.ReadByte(); if (version != (byte)SocksVersion.Socks5) { throw new DecoderException( "unsupported version: " + version + " (expected: " + SocksVersion.Socks5 + ')'); } int authMethodCnt = input.ReadByte(); if (ActualReadableBytes < authMethodCnt) { break; } var authMethods = new Socks5AuthMethod[authMethodCnt]; for (var i = 0; i < authMethodCnt; i++) { authMethods[i] = Socks5AuthMethod.ValueOf(input.ReadByte()); } output.Add(new DefaultSocks5InitialRequest(authMethods)); Checkpoint(Socks5InitialRequestDecoderState.Success); break; case Socks5InitialRequestDecoderState.Success: var readableBytes = ActualReadableBytes; if (readableBytes > 0) { output.Add(input.ReadRetainedSlice(readableBytes)); } break; case Socks5InitialRequestDecoderState.Failure: input.SkipBytes(ActualReadableBytes); break; } } catch (Exception e) { Fail(output, e); } }
public DefaultSocks5InitialResponse(Socks5AuthMethod authMethod) { AuthMethod = authMethod; }