Exemplo n.º 1
0
        private void OnARecord(Name name, IPAddress address, uint ttl)
        {
            HostAddresses hostAddresses;
            bool          found = _packetHostAddresses.TryGetValue(name, out hostAddresses);

            if (!found)
            {
                hostAddresses = new HostAddresses();
                _packetHostAddresses.Add(name, hostAddresses);
            }
            List <IPAddress> addresses = null;

            if (address.AddressFamily == AddressFamily.InterNetwork)
            {
                if (hostAddresses.IPv4Addresses == null)
                {
                    hostAddresses.IPv4Addresses = new List <IPAddress>();
                }
                addresses = hostAddresses.IPv4Addresses;
            }
            else if (address.AddressFamily == AddressFamily.InterNetworkV6)
            {
                if (hostAddresses.IPv6Addresses == null)
                {
                    hostAddresses.IPv6Addresses = new List <IPAddress>();
                }
                addresses = hostAddresses.IPv6Addresses;
            }
            if (ttl != 0)
            {
                addresses.Add(address);
            }
        }
Exemplo n.º 2
0
        private void HandlePacketHostAddresses()
        {
            foreach (var hostAddressKV in _packetHostAddresses)
            {
                Name          name          = hostAddressKV.Key;
                HostAddresses hostAddresses = hostAddressKV.Value;

                HostInfo hostInfo;
                _hostInfos.TryGetValue(name, out hostInfo);
                if (hostInfo == null)
                {
                    return;
                }

                List <IPAddress> packetAddresses = new List <IPAddress>();
                if (hostAddresses.IPv4Addresses == null)
                {
                    if (hostInfo.Addresses != null)
                    {
                        packetAddresses.AddRange(hostInfo.Addresses.Where(a => a.AddressFamily == AddressFamily.InterNetwork));
                    }
                }
                else
                {
                    packetAddresses.AddRange(hostAddresses.IPv4Addresses);
                }
                if (hostAddresses.IPv6Addresses == null)
                {
                    if (hostInfo.Addresses != null)
                    {
                        packetAddresses.AddRange(hostInfo.Addresses.Where(a => a.AddressFamily == AddressFamily.InterNetworkV6));
                    }
                }
                else
                {
                    packetAddresses.AddRange(hostAddresses.IPv6Addresses);
                }

                if (packetAddresses.Count == 0)
                {
                    _hostInfos.Remove(name);
                    foreach (var service in hostInfo.ServiceInfos)
                    {
                        PacketRemovesService(service.Name);
                    }
                }
                else
                {
                    var  addresses = hostInfo.Addresses;
                    bool same      = (addresses != null) && (addresses.Count == packetAddresses.Count) && (addresses.TrueForAll(packetAddresses.Contains));
                    if (!same)
                    {
                        foreach (var service in hostInfo.ServiceInfos)
                        {
                            ServiceInfo newService = FindOrCreatePacketService(service.Name);
                            newService.Addresses = packetAddresses;
                        }
                        hostInfo.Addresses = packetAddresses;
                    }
                }
            }
        }
Exemplo n.º 3
0
 private void OnARecord(Name name, IPAddress address, uint ttl)
 {
     HostAddresses hostAddresses;
     bool found = _packetHostAddresses.TryGetValue(name, out hostAddresses);
     if (!found)
     {
         hostAddresses = new HostAddresses();
         _packetHostAddresses.Add(name, hostAddresses);
     }
     List<IPAddress> addresses = null;
     if (address.AddressFamily == AddressFamily.InterNetwork)
     {
         if (hostAddresses.IPv4Addresses == null)
         {
             hostAddresses.IPv4Addresses = new List<IPAddress>();
         }
         addresses = hostAddresses.IPv4Addresses;
     }
     else if (address.AddressFamily == AddressFamily.InterNetworkV6)
     {
         if (hostAddresses.IPv6Addresses == null)
         {
             hostAddresses.IPv6Addresses = new List<IPAddress>();
         }
         addresses = hostAddresses.IPv6Addresses;
     }
     if (ttl != 0)
     {
         addresses.Add(address);
     }
 }