コード例 #1
0
        public override ClientFilterResult AfterReading(ClientFilterContext ctx)
        {
            _logger?.LogInformation($"TestPipeFilter AfterReading data={ctx.Memory.ToArray().ToHexString()}");
            var newBuff = SmartBuffer.Rent(ctx.Memory.Length - 4);

            ctx.Memory.Slice(4).CopyTo(newBuff.Memory);
            newBuff.SignificantLength = ctx.Memory.Length - 4;
            return(new ClientFilterResult(ctx.Client, newBuff, true));
        }
コード例 #2
0
        public override ClientFilterResult BeforeWriting(ClientFilterContext ctx)
        {
            if (!ctx.Memory.IsEmpty)
            {
                var bufferCipher = _cipher.EncryptUdp(ctx.Memory);
                return(new ClientFilterResult(this.Client, bufferCipher, true));
            }
            else
            {
                _logger?.LogError($"CipherUdpFilter BeforeWriting filterContext.Memory.IsEmpty");
            }

            return(new ClientFilterResult(this.Client, null, false));
        }
コード例 #3
0
        public override ClientFilterResult BeforeWriting(ClientFilterContext ctx)
        {
            _logger?.LogInformation($"TestPipeFilter BeforeWriting data={ctx.Memory.ToArray().ToHexString()}");
            var newBuff = SmartBuffer.Rent(ctx.Memory.Length + 4);
            var p       = newBuff.Memory.Span;

            p[0] = 0x12;
            p[1] = 0x34;
            p[2] = 0xAB;
            p[3] = 0xCD;
            ctx.Memory.CopyTo(newBuff.Memory.Slice(4));
            newBuff.SignificantLength = ctx.Memory.Length + 4;
            return(new ClientFilterResult(ctx.Client, newBuff, true));
        }
コード例 #4
0
        public override ClientFilterResult BeforeWriting(ClientFilterContext ctx)
        {
            SmartBuffer toTarget = SmartBuffer.Rent(ctx.Memory.Length);

            if (ShadowsocksAddress.TryResolveLength(ctx.Memory, out int targetAddrLen))
            {
                ctx.Memory.Slice(targetAddrLen).CopyTo(toTarget.Memory);
                toTarget.SignificantLength = ctx.Memory.Length - targetAddrLen;
                return(new ClientFilterResult(ctx.Client, toTarget, true));
            }
            else
            {
                return(new ClientFilterResult(ctx.Client, toTarget, false));
            }
        }
コード例 #5
0
        public override ClientFilterResult BeforeWriting(ClientFilterContext ctx)
        {
            if (!ctx.Memory.IsEmpty)
            {
                SmartBuffer toRemote = SmartBuffer.Rent(1500);
                ctx.Memory.Slice(3).CopyTo(toRemote.Memory);
                toRemote.SignificantLength = ctx.Memory.Length - 3;
                return(new ClientFilterResult(ctx.Client, toRemote, true));
            }
            else
            {
                _logger?.LogError($"LocalUdpRelayPackingFilter BeforeWriting filterContext.Memory.IsEmpty");
            }

            return(new ClientFilterResult(this.Client, null, false));
        }
コード例 #6
0
        public override ClientFilterResult OnReading(ClientFilterContext ctx)
        {
            SmartBuffer bufferPlain = null;

            if (null != _cipher)
            {
                if (!ctx.Memory.IsEmpty)//TODO 1
                {
                    bufferPlain = _cipher.DecryptTcp(ctx.Memory);
                }
                else
                {
                    _logger?.LogError($"AeadCipherTcpFilter OnReading filterContext.Memory.IsEmpty");
                }
            }
            return(new ClientFilterResult(this.Client, bufferPlain, true));//TODO 2
        }
コード例 #7
0
        public override ClientFilterResult AfterReading(ClientFilterContext ctx)
        {
            if (!ctx.Memory.IsEmpty)
            {
                SmartBuffer toApplication = SmartBuffer.Rent(1500);
                ctx.Memory.CopyTo(toApplication.Memory.Slice(2 + 1));
                var p = toApplication.Memory.Span;
                p.Slice(0, 3).Fill(0x0);
                toApplication.SignificantLength = ctx.Memory.Length + 2 + 1;
                return(new ClientFilterResult(ctx.Client, toApplication, true));
            }
            else
            {
                _logger?.LogError($"LocalUdpRelayPackingFilter AfterReading filterContext.Memory.IsEmpty");
            }

            return(new ClientFilterResult(this.Client, null, false));
        }
コード例 #8
0
        public override ClientFilterResult OnWriting(ClientFilterContext ctx)
        {
            ClientFilterResult r = new ClientFilterResult(this.Client, null, false);

            if (null != _cipher)
            {
                if (!ctx.Memory.IsEmpty)
                {
                    var bufferCipher = _cipher.EncryptTcp(ctx.Memory);
                    r = new ClientFilterResult(this.Client, bufferCipher, true);
                }
                else
                {
                    _logger?.LogError($"AeadCipherTcpFilter OnWriting filterContext.Memory.IsEmpty");
                }
            }
            return(r);
        }
コード例 #9
0
        public override ClientFilterResult AfterReading(ClientFilterContext ctx)
        {
            SmartBuffer toSsLocal = SmartBuffer.Rent(1500);//TODO what if exceeds 1500? fragments or not?

            if (ShadowsocksAddress.TrySerailizeTo(
                    (byte)(AddressFamily.InterNetworkV6 == ctx.Client.EndPoint.AddressFamily ? 0x4 : 0x1),
                    ctx.Client.EndPoint.Address.GetAddressBytes(),
                    (ushort)ctx.Client.EndPoint.Port,
                    toSsLocal.Memory,
                    out int written))
            {
                toSsLocal.SignificantLength = written;
                int payloadToCopy = Math.Min(toSsLocal.FreeSpace, ctx.Memory.Length);
                ctx.Memory.Slice(0, payloadToCopy).CopyTo(toSsLocal.FreeMemory);
                toSsLocal.SignificantLength += payloadToCopy;

                return(new ClientFilterResult(ctx.Client, toSsLocal, true));;
            }

            return(new ClientFilterResult(ctx.Client, null, false));;
        }
コード例 #10
0
        public override ClientFilterResult AfterReading(ClientFilterContext ctx)
        {
            if (!ctx.Memory.IsEmpty)
            {
                var bufferPlain = _cipher.DecryptUdp(ctx.Memory);
                if (null != bufferPlain && bufferPlain.SignificantLength > 0)
                {
                    return(new ClientFilterResult(this.Client, bufferPlain, true));
                }
                else
                {
                    _logger?.LogError($"CipherUdpFilter AfterReading no plain data.");
                }
            }
            else
            {
                _logger?.LogError($"CipherUdpFilter AfterReading filterContext.Memory.IsEmpty");
            }

            return(new ClientFilterResult(this.Client, null, false));
        }
コード例 #11
0
 public override ClientFilterResult BeforeWriting(ClientFilterContext filterContext)
 {
     throw new NotImplementedException();
 }
コード例 #12
0
 public override ClientFilterResult AfterReading(ClientFilterContext filterContext)
 {
     throw new NotImplementedException();
 }
コード例 #13
0
 public abstract ClientFilterResult OnWriting(ClientFilterContext filterContext);
コード例 #14
0
 public abstract ClientFilterResult AfterReading(ClientFilterContext filterContext);