Exemplo n.º 1
0
        private static int CalculateBandwidth(TcpFlow flow, TimeSpan interval)
        {
            int bandwidth = 0;

            if (!TcpPackets.ContainsKey(flow))
            {
                return(bandwidth);
            }

            var now        = DateTime.UtcNow;
            var entryArray = TcpPackets[flow];

            bandwidth = (from entry in entryArray
                         where ((now - entry.Timeval.Date) < interval)
                         select entry.Packet.Bytes.Length).Sum();
            return(bandwidth);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="timeval">
        /// A <see cref="PosixTimeval"/>
        /// </param>
        /// <param name="connection">
        /// A <see cref="TcpConnection"/>
        /// </param>
        /// <param name="flow">
        /// A <see cref="TcpFlow"/>
        /// </param>
        /// <param name="tcp">
        /// A <see cref="TcpPacket"/>
        /// </param>
        protected void HandleCOnPacketReceived(PosixTimeval timeval, TcpConnection connection, TcpFlow flow, TcpPacket tcp)
        {
            // look up the ConnectionStatistics
            var connectionStatistics = connectionDictionary[connection];

            if (tcp.Synchronize && !tcp.Acknowledgment)
            {
                if (connectionStatistics.clientFlow != null)
                {
                    OnMeasurementEvent(this, connection, EventTypes.DuplicateSynFound);
                    return;
                }

                connectionStatistics.clientFlow = flow;
                connectionStatistics.synTime    = timeval;
            }
            else if (tcp.Synchronize && tcp.Acknowledgment)
            {
                if (connectionStatistics.serverFlow != null)
                {
                    OnMeasurementEvent(this, connection, EventTypes.DuplicateSynAckFound);
                    return;
                }

                connectionStatistics.serverFlow = flow;
                connectionStatistics.synAckTime = timeval;
            }

            // if we have both a syn and a syn-ack time then report that
            // we have a valid measurement
            if ((connectionStatistics.synTime != null) &&
                (connectionStatistics.synAckTime != null))
            {
                OnMeasurementFound(this, connection, connectionStatistics);

                // unregister the handler since we found our syn-syn/ack time
                connection.OnPacketReceived -= HandleCOnPacketReceived;
            }
        }
Exemplo n.º 3
0
        private void Connection_OnPacketReceived(SharpPcap.PosixTimeval timeval, TcpConnection connection, TcpFlow flow, TcpPacket tcpPacket)
        {
            if (tcpPacket.PayloadData.Length == 0)
            {
                return;
            }
            var data      = (byte[])tcpPacket.PayloadData.Clone();
            var direction = tcpPacket.SourcePort == Constants.GAME_PORT ? PacketDirection.ServerToClient : PacketDirection.ClientToServer;

            if (gameCrypt != null)
            {
                gameCrypt.Decrypt(data, direction);
            }

            var parsedPacket = ParsePacket(data, direction);

            if (parsedPacket == null)
            {
                return;
            }

            if (parsedPacket.GetType() == typeof(KeyPacket))
            {
                gameCrypt = new GameCrypt(parsedPacket as KeyPacket);
                return;
            }
        }
Exemplo n.º 4
0
        private void Connection_OnPacketReceived(SharpPcap.PosixTimeval timeval, TcpConnection connection, TcpFlow flow, TcpPacket tcp)
        {
            //incoming packets, first one is Init always
            if (tcp.SourcePort == Constants.LOGIN_PORT && Crypt.IsInitial)
            {
                TryInit(tcp);
                return;
            }

            // only after inited we can parse
            if (!Crypt.IsInitial)
            {
                ParsePacket(tcp);
            }
        }
Exemplo n.º 5
0
        static void HandleOnPacketReceived(PosixTimeval timeval, PacketDotNet.TcpPacket tcp, TcpConnection connection, TcpFlow flow)
        {
            lock (DictionaryLock)
            {
                if (!TcpPackets.ContainsKey(flow))
                {
                    TcpPackets[flow] = new List <Entry>();
                }

                var entry = new Entry(timeval, tcp);
                TcpPackets[flow].Add(entry);
            }
        }
Exemplo n.º 6
0
 static void HandleOnFlowClosed(PosixTimeval timeval, PacketDotNet.TcpPacket tcp, TcpConnection connection, TcpFlow flow)
 {
     // unhook the received handler
     flow.OnPacketReceived -= HandleOnPacketReceived;
 }