Esempio n. 1
0
        public bool MatchFilter(byte[] packet, out PacketFilterInfo pfi)
        {
            pfi = null;

            if (_filters == null)
            {
                return(false);
            }

            bool result = false;

            for (int i = 0; i < _filters.Count; i++)
            {
                if (packet[0] == _filters[i].PacketID)
                {
                    if (_filters[i].GetConditions() == null)
                    {
                        // No condition so just match packetid
                        result = true;
                        pfi    = _filters[i];
                    }
                    else
                    {
                        foreach (PacketFilterCondition fc in _filters[i].GetConditions())
                        {
                            if (fc.Position + fc.Length > packet.Length)
                            {
                                result = false;
                                continue;
                            }

                            byte[] tmp = new byte[fc.Length];
                            Buffer.BlockCopy(packet, fc.Position, tmp, 0, fc.Length);

                            if (!tmp.SequenceEqual(fc.GetBytes()))
                            {
                                result = false;
                                break;
                            }

                            result = true;
                            pfi    = _filters?[i] ?? null;
                        }
                    }
                }

                if (result)
                {
                    break;
                }
            }

            if (!result)
            {
                pfi = null;
            }

            return(result);
        }
Esempio n. 2
0
        public void Add(PacketFilterInfo pfi)
        {
            if (_filters == null)
            {
                _filters = new List <PacketFilterInfo>();
            }

            _filters.Add(pfi);
        }
Esempio n. 3
0
        public void Remove(PacketFilterInfo pfi)
        {
            if (_filters == null)
            {
                _filters = new List <PacketFilterInfo>();
            }

            if (_filters.Contains(pfi))
            {
                _filters.Remove(pfi);
            }
        }
        public PacketWaitEntry Add(PacketFilterInfo pfi, PacketDirection direction, bool autoRemove = false)
        {
            PacketWaitEntry we = new PacketWaitEntry
            {
                PFI = pfi, Lock = new AutoResetEvent(false), PacketDirection = direction, AutoRemove = autoRemove
            };

            lock ( _waitEntryLock )
            {
                _waitEntries.Add(we);
                WaitEntryAddedEvent?.Invoke(we);
            }

            return(we);
        }
Esempio n. 5
0
 public bool Contains(PacketFilterInfo pfi)
 {
     return(_filters != null && _filters.Contains(pfi));
 }