internal override bool HandleResponse(mDNS dns) { ServiceInfo info = (ServiceInfo)dns.services[name.ToLower()]; if (info != null && (port != info.port || !server.ToUpper().Equals(dns.LocalHost.Name.ToUpper()))) { logger.Debug("handleResponse() Denial detected"); if (info.State.Probing) { string oldName = info.QualifiedName.ToLower(); info.SetName(dns.IncrementName(info.getName())); dns.services.Remove(oldName); dns.services[info.QualifiedName.ToLower()] = info; logger.Debug("handleResponse() New unique name chose:" + info.getName()); } info.RevertState(); return(true); } return(false); }
/// <summary> Generate a possibly unique name for a service using the information we /// have in the cache. /// /// </summary> /// <returns> returns true, if the name of the service info had to be changed. /// </returns> private bool makeServiceNameUnique(ServiceInfo info) { string originalQualifiedName = info.QualifiedName; long now = (DateTime.Now.Ticks - 621355968000000000) / 10000; bool collision; do { collision = false; // Check for collision in cache for (DNSCache.CacheNode j = cache.find(info.QualifiedName.ToLower()); j != null; j = j.Next) { DNSRecord a = (DNSRecord)j.Value; if ((a.type == DNSConstants.TYPE_SRV) && !a.IsExpired(now)) { Service s = (Service)a; if (s.port != info.port || !s.server.Equals(localHost.Name)) { logger.Debug("makeServiceNameUnique() JmDNS.makeServiceNameUnique srv collision:" + a + " s.server=" + s.server + " " + localHost.Name + " equals:" + (s.server.Equals(localHost.Name))); info.SetName(IncrementName(info.getName())); collision = true; break; } } } // Check for collision with other service infos published by JmDNS object selfService = services[info.QualifiedName.ToLower()]; if (selfService != null && selfService != info) { info.SetName(IncrementName(info.getName())); collision = true; } }while (collision); return(!(originalQualifiedName.Equals(info.QualifiedName))); }
internal virtual void HandleServiceResolved(ServiceInfo info) { IList list = (IList)serviceListeners[info.type.ToLower()]; if (list != null) { ServiceEvent event_Renamed = new ServiceEvent(this, info.type, info.getName(), info); // Iterate on a copy in case listeners will modify it ArrayList listCopy = new ArrayList(list); foreach (IServiceListener listener in listCopy) { listener.ServiceResolved(this, event_Renamed); } } }
internal override bool HandleQuery(mDNS dns, long expirationTime) { ServiceInfo info = (ServiceInfo)dns.services[name.ToLower()]; if (info != null && (port != info.port || !server.ToUpper().Equals(dns.LocalHost.Name.ToUpper()))) { logger.Debug("handleQuery() Conflicting probe detected"); // Tie breaker test if (info.State.Probing && lexCompare(new Service(info.QualifiedName, DNSConstants.TYPE_SRV, DNSConstants.CLASS_IN | DNSConstants.CLASS_UNIQUE, DNSConstants.DNS_TTL, info.priority, info.weight, info.port, dns.LocalHost.Name)) >= 0) { // We lost the tie break string oldName = info.QualifiedName.ToLower(); info.SetName(dns.IncrementName(info.getName())); dns.services.Remove(oldName); dns.services[info.QualifiedName.ToLower()] = info; logger.Debug("handleQuery() Lost tie break: new unique name chosen:" + info.getName()); } info.RevertState(); return(true); } return(false); }
/// <summary> Generate a possibly unique name for a service using the information we /// have in the cache. /// /// </summary> /// <returns> returns true, if the name of the service info had to be changed. /// </returns> private bool makeServiceNameUnique(ServiceInfo info) { string originalQualifiedName = info.QualifiedName; long now = (DateTime.Now.Ticks - 621355968000000000) / 10000; bool collision; do { collision = false; // Check for collision in cache for (DNSCache.CacheNode j = cache.find(info.QualifiedName.ToLower()); j != null; j = j.Next) { DNSRecord a = (DNSRecord) j.Value; if ((a.type == DNSConstants.TYPE_SRV) && !a.IsExpired(now)) { Service s = (Service) a; if (s.port != info.port || !s.server.Equals(localHost.Name)) { logger.Debug("makeServiceNameUnique() JmDNS.makeServiceNameUnique srv collision:" + a + " s.server=" + s.server + " " + localHost.Name + " equals:" + (s.server.Equals(localHost.Name))); info.SetName(IncrementName(info.getName())); collision = true; break; } } } // Check for collision with other service infos published by JmDNS object selfService = services[info.QualifiedName.ToLower()]; if (selfService != null && selfService != info) { info.SetName(IncrementName(info.getName())); collision = true; } } while (collision); return !(originalQualifiedName.Equals(info.QualifiedName)); }
internal virtual void HandleServiceResolved(ServiceInfo info) { IList list = (IList) serviceListeners[info.type.ToLower()]; if (list != null) { ServiceEvent event_Renamed = new ServiceEvent(this, info.type, info.getName(), info); // Iterate on a copy in case listeners will modify it ArrayList listCopy = new ArrayList(list); foreach (IServiceListener listener in listCopy) { listener.ServiceResolved(this, event_Renamed); } } }