Example #1
0
        protected ArrayList InitRemoteIPs()
        {
            NatHistory.Filter f = delegate(NatDataPoint p) {
                TransportAddress ta = p.PeerViewOfLocalTA;
                IPAddress        a  = null;
                if (ta != null)
                {
                    try {
                        a = ((IPTransportAddress)ta).GetIPAddress();
                    } catch (Exception x) {
                        BU.ProtocolLog.WriteIf(BU.ProtocolLog.Exceptions, String.Format(
                                                   "{0}", x));
                    }
                }
                return(a);
            };
            IEnumerable all_ips = _hist.FilteredEnumerator(f);
            Hashtable   ht      = new Hashtable();

            foreach (IPAddress a in all_ips)
            {
                if (false == ht.Contains(a))
                {
                    IPAddressRecord r = new IPAddressRecord();
                    r.IP    = a;
                    r.Count = 1;
                    ht[a]   = r;
                }
                else
                {
                    IPAddressRecord r = (IPAddressRecord)ht[a];
                    r.Count++;
                }
            }

            ArrayList             rips = new ArrayList();
            IDictionaryEnumerator de   = ht.GetEnumerator();

            while (de.MoveNext())
            {
                IPAddressRecord r = (IPAddressRecord)de.Value;
                rips.Add(r);
            }
            //Now we have a list of the most used to least used IPs
            rips.Sort();
            return(rips);
        }
Example #2
0
        protected IList MakeTargets(IEnumerable h, out bool success)
        {
            bool             there_is_a_match = false;
            int              matched_port     = 0;
            TransportAddress matched_ta       = null;

            foreach (NatDataPoint p in h)
            {
                TransportAddress l  = p.LocalTA;
                TransportAddress pv = p.PeerViewOfLocalTA;
                if (l != null && pv != null)
                {
                    there_is_a_match = (((IPTransportAddress)l).Port == ((IPTransportAddress)pv).Port);
                    if (there_is_a_match)
                    {
                        //Move on.
                        matched_port = ((IPTransportAddress)l).Port;
                        matched_ta   = pv;
                        break;
                    }
                }
            }
            if (there_is_a_match)
            {
                //Now we filter to look at only the unmatched ports:
                NatHistory.Filter f = delegate(NatDataPoint p) {
                    TransportAddress pv = p.PeerViewOfLocalTA;
                    if ((pv != null) && (((IPTransportAddress)pv).Port != matched_port))
                    {
                        return(p);
                    }
                    return(null);
                };
                //This is all the non-matching data points:
                IEnumerable non_matched = new NatHistory.FilteredNDP(h, f);
                ArrayList   l           = PredictPorts(non_matched);
                //Put in the matched port at the top of the list:
                l.Insert(0, matched_ta);
                success = true;
                return(l);
            }
            else
            {
                success = false;
                return(null);
            }
        }