Beispiel #1
0
        /// <summary>
        /// Checks whether the passed packet is a duplicate.
        /// A packet is duplicate if another packet with the same identifier
        /// has been sent from the same host in the last time.
        /// @param packet packet in question
        /// @param address client address
        /// @return true if it is duplicate
        /// </summary>
        protected bool IsPacketDuplicate(RadiusPacket packet, IPEndPoint address)
        {
            //long now = System.currentTimeMillis();
            DateTime now = DateTime.Now;

            DateTime intervalStart = now - (new TimeSpan(0, 0, 0, 0, DuplicateInterval));

            byte[] authenticator = packet.Authenticator;

            lock (_receivedPackets)
            {
                for (int i = _receivedPackets.Count - 1; i >= 0; i--)
                {
                    ReceivedPacket p = _receivedPackets[i];
                    if (p.ReceiveTime < intervalStart)
                    {
                        _receivedPackets.RemoveAt(i);
                    }
                    else
                    {
                        if (p.Address.Equals(address) && p.PacketIdentifier == packet.Identifier)
                        {
                            return(authenticator == null || p.Authenticator == null ||
                                   Equals(p.Authenticator, authenticator));
                        }
                    }
                }
            }

            // add packet to receive list
            var rp = new ReceivedPacket
            {
                Address          = address,
                PacketIdentifier = packet.Identifier,
                ReceiveTime      = now,
                Authenticator    = authenticator
            };

            _receivedPackets.Add(rp);
            return(false);
        }
        /// <summary>
        /// Checks whether the passed packet is a duplicate.
        /// A packet is duplicate if another packet with the same identifier
        /// has been sent from the same host in the last time. 
        /// @param packet packet in question
        /// @param address client address
        /// @return true if it is duplicate
        /// </summary>
        protected bool IsPacketDuplicate(RadiusPacket packet, IPEndPoint address)
        {
            //long now = System.currentTimeMillis();
            DateTime now = DateTime.Now;

            DateTime intervalStart = now - (new TimeSpan(0, 0, 0, 0, DuplicateInterval));

            byte[] authenticator = packet.Authenticator;

            lock (_receivedPackets)
            {
                for (int i = _receivedPackets.Count - 1; i >= 0; i--)
                {
                    ReceivedPacket p = _receivedPackets[i];
                    if (p.ReceiveTime < intervalStart)
                    {
                        _receivedPackets.RemoveAt(i);
                    }
                    else
                    {
                        if (p.Address.Equals(address) && p.PacketIdentifier == packet.Identifier)
                        {
                            return authenticator == null || p.Authenticator == null ||
                                   Equals(p.Authenticator, authenticator);
                        }
                    }
                }
            }

            // add packet to receive list
            var rp = new ReceivedPacket
                         {
                             Address = address,
                             PacketIdentifier = packet.Identifier,
                             ReceiveTime = now,
                             Authenticator = authenticator
                         };
            _receivedPackets.Add(rp);
            return false;
        }