コード例 #1
0
ファイル: MiscTests.cs プロジェクト: encodeous/wstream
        public override async Task <int> ReadAsync(ArraySegment <byte> buffer, CancellationToken cancellationToken = new CancellationToken())
        {
            int len = await WrappedSocket.ReadAsync(buffer, cancellationToken);

            _data.BytesRead += len;
            return(len);
        }
コード例 #2
0
            private void Connect()
            {
                try
                {
                    var ipAddress = Global.OSSupportsLocalIPv6 ? IPAddress.IPv6Loopback : IPAddress.Loopback;
                    var remoteEp  = new IPEndPoint(ipAddress, _targetPort);

                    _remote = new WrappedSocket();

                    // Connect to the remote endpoint.
                    _remote.BeginConnect(remoteEp, ConnectCallback, null);
                }
                catch (Exception e)
                {
                    Logging.LogUsefulException(e);
                    Close();
                }
            }
コード例 #3
0
        private async Task ReadBytesAsync(ArraySegment <byte> result, CancellationToken cancellationToken = default(CancellationToken))
        {
            int count = result.Count;

            do
            {
                int num = await WrappedSocket.ReadAsync(result, cancellationToken).ConfigureAwait(false);

                if (num != 0)
                {
                    count -= num;
                }
                else
                {
                    throw new EndOfStreamException("Unexpected end of stream while trying to read crypto packet!");
                }
            } while (count > 0);
        }
コード例 #4
0
ファイル: PortForwarder.cs プロジェクト: Evilrabbit520/Photon
            public void Start(byte[] firstPacket, int length, Socket socket, int targetPort)
            {
                _firstPacket       = firstPacket;
                _firstPacketLength = length;
                _local             = socket;
                try
                {
                    EndPoint remoteEP = SocketUtil.GetEndPoint("127.0.0.1", targetPort);

                    // 连接到远程端点
                    _remote = new WrappedSocket();
                    _remote.BeginConnect(remoteEP, ConnectCallback, null);
                }
                catch (Exception e)
                {
                    Logging.LogUsefulException(e);
                    Close();
                }
            }
コード例 #5
0
ファイル: PortForwarder.cs プロジェクト: whosa/trojan-windows
            public void Start(byte[] firstPacket, int length, Socket socket, int targetPort)
            {
                _firstPacket       = firstPacket;
                _firstPacketLength = length;
                _local             = socket;
                try
                {
                    // Local Port Forward use IP as is
                    EndPoint remoteEP = SocketUtil.GetEndPoint(_local.AddressFamily == AddressFamily.InterNetworkV6 ? "[::1]" : "127.0.0.1", targetPort);

                    // Connect to the remote endpoint.
                    _remote = new WrappedSocket();
                    _remote.BeginConnect(remoteEP, ConnectCallback, null);
                }
                catch (Exception e)
                {
                    logger.LogUsefulException(e);
                    Close();
                }
            }
コード例 #6
0
        public override Task WriteAsync(ArraySegment <byte> buffer, CancellationToken cancellationToken = new CancellationToken())
        {
            var buf = ArrayPool <byte> .Shared.Rent(buffer.Count + 20);

            var ctext = new ArraySegment <byte>(buf, 20, buffer.Count);
            var tag   = new ArraySegment <byte>(buf, 4, 16);

            BitConverter.TryWriteBytes(new ArraySegment <byte>(buf, 0, 4), buffer.Count);
            lock (_writeNonce)
            {
                _aes.Encrypt(_writeNonce, buffer, ctext, tag);
                IncrementNonce(_writeNonce);
            }

            async Task Send()
            {
                await WrappedSocket.WriteAsync(new ArraySegment <byte>(buf, 0, buffer.Count + 20), cancellationToken);

                ArrayPool <byte> .Shared.Return(buf);
            }

            return(Send());
        }
コード例 #7
0
ファイル: MiscTests.cs プロジェクト: encodeous/wstream
 public override Task WriteAsync(ArraySegment <byte> buffer, CancellationToken cancellationToken = new CancellationToken())
 {
     _data.BytesWritten += buffer.Count;
     return(WrappedSocket.WriteAsync(buffer, cancellationToken));
 }
コード例 #8
0
ファイル: MiscTests.cs プロジェクト: encodeous/wstream
 public override Task CloseAsync()
 {
     return(WrappedSocket.CloseAsync());
 }
コード例 #9
0
ファイル: WsWrapSample.cs プロジェクト: encodeous/wstream
 public override Task CloseAsync()
 {
     Console.WriteLine("Socket Closed");
     return(WrappedSocket.CloseAsync());
 }
コード例 #10
0
 public HttpHandler(ShadowsocksController controller, Configuration config, TCPRelay tcprelay, Socket socket) : base(controller, config, tcprelay, socket)
 {
     _localSocket = new WrappedSocket(socket);
 }