public void Add(BlackListEntryHolder beh) { Dictionary <string, List <BlackListEntryHolder> > value; lock (fastmap) { if (!fastmap.TryGetValue(beh.MaskIndex, out value)) { value = new Dictionary <string, List <BlackListEntryHolder> >(); fastmap[beh.MaskIndex] = value; } List <BlackListEntryHolder> value2; if (!value.TryGetValue(beh.Index, out value2)) { value2 = new List <BlackListEntryHolder>(); value[beh.Index] = value2; } if (beh.BlockType == 1) { value2.Insert(0, beh); } else { value2.Add(beh); } } }
public override bool Equals(object obj) { BlackListEntryHolder a = obj as BlackListEntryHolder; if (a != null) { return((_hashCode != 0) && (_hashCode == a._hashCode)); } return(false); }
private System.Collections.Generic.Dictionary <BlackListEntry, BlackListEntryHolder> BuildNewBlackList() { var retval = new System.Collections.Generic.Dictionary <BlackListEntry, BlackListEntryHolder>(); BlackListEntry[] thearr = PhoneSystem.Root.GetBlackListEntries(); foreach (var a in thearr) { try { BlackListEntryHolder tmp = new BlackListEntryHolder(a); retval[a] = tmp; blc_.Add(tmp); } catch { //just ignore } } return(retval); }
public List <BlackListEntryHolder> BlockedBy(byte[] theAddress, byte[] theMask) { lock (fastmap) { int maskIndex = BlackListEntryHolder.GetMaskIndex(theMask); for (int i = 0; i < theAddress.Length; i++) { theAddress[i] &= theMask[i]; } Dictionary <string, List <BlackListEntryHolder> > value; List <BlackListEntryHolder> theList; if (fastmap.TryGetValue(maskIndex, out value) && value.TryGetValue(String.Format("{0}.{1}.{2}.{3}", theAddress[0], theAddress[1], theAddress[2], theAddress[3]), out theList)) { return(theList); } } return(null); }
public void Remove(BlackListEntryHolder beh) { lock (fastmap) { Dictionary <string, List <BlackListEntryHolder> > value; List <BlackListEntryHolder> value2; if (fastmap.TryGetValue(beh.MaskIndex, out value) && value.TryGetValue(beh.Index, out value2)) { value2.Remove(beh); if (value2.Count == 0) { value.Remove(beh.Index); if (value.Count == 0) { fastmap.Remove(beh.MaskIndex); } } } } }
public void ps_Updated(object sender, NotificationEventArgs e) { if (e.EntityName == "BLACKLIST") { BlackListEntry entry = e.ConfObject as BlackListEntry; if (entry != null) { lock (this) { } //Console.WriteLine("Updated: {0}[{1}]. expires at {2}", entry.IPAddr, entry.IPMask, entry.ExpiresAt.ToLocalTime()); BlackListEntryHolder val; if (the_set.TryGetValue(entry, out val)) { blc_.Remove(val); the_set.Remove(entry); } BlackListEntryHolder tmp = new BlackListEntryHolder(entry); blc_.Add(tmp); the_set[entry] = tmp; } } }
public BlackListEntry InsertOrUpdateEntry(string theaddr, string themask, TimeSpan blockingtime, string description) { DateTime newDate = DateTime.UtcNow + blockingtime; BlackListEntryHolder theObj = null; byte[] theMask = IPAddress.Parse(themask).GetAddressBytes(); byte[] theAddress = IPAddress.Parse(theaddr).GetAddressBytes(); for (int i = 0; i < theAddress.Length; i++) { theAddress[i] &= theMask[i]; } int maskIndex = BlackListEntryHolder.GetMaskIndex(theMask); lock (fastmap) { Dictionary <string, List <BlackListEntryHolder> > value; List <BlackListEntryHolder> objList; if (fastmap.TryGetValue(maskIndex, out value) && value.TryGetValue(String.Format("{0}.{1}.{2}.{3}", theAddress[0], theAddress[1], theAddress[2], theAddress[3]), out objList)) { if (objList != null && objList.Count > 0) { foreach (var be in objList) { if ((theObj == null || theObj.Expires < be.Expires) && be.Obj.IPAddr == theaddr && be.Obj.IPMask == themask && be.Obj.BlockType == 0) { theObj = be; } } if (theObj != null && theObj.Expires >= newDate) { return(null); } } } } BlackListEntry theEntry; if (theObj == null) { theEntry = PhoneSystem.Root.CreateBlackListEntry(); theEntry.IPAddr = theaddr; theEntry.IPMask = themask; theEntry.Description = description; } else { theEntry = theObj.Obj.Clone() as BlackListEntry; } theEntry.ExpiresAt = newDate; try { theEntry.Save(); } catch { theEntry = PhoneSystem.Root.CreateBlackListEntry(); theEntry.IPAddr = theaddr; theEntry.IPMask = themask; theEntry.Description = description; theEntry.ExpiresAt = newDate; theEntry.Save(); } return(theEntry); }