public void Run(object state) { try { if (Enclosing_Instance.State == DNSState.ANNOUNCED) { if (count++ < 3 && !info.HasData) { long now = (DateTime.Now.Ticks - 621355968000000000) / 10000; DNSOutgoing out_Renamed = new DNSOutgoing(DNSConstants.FLAGS_QR_QUERY); out_Renamed.AddQuestion(new DNSQuestion(info.QualifiedName, DNSConstants.TYPE_SRV, DNSConstants.CLASS_IN)); out_Renamed.AddQuestion(new DNSQuestion(info.QualifiedName, DNSConstants.TYPE_TXT, DNSConstants.CLASS_IN)); if (info.server != null) { out_Renamed.AddQuestion(new DNSQuestion(info.server, DNSConstants.TYPE_A, DNSConstants.CLASS_IN)); } out_Renamed.AddAnswer((DNSRecord) Enclosing_Instance.Cache.get_Renamed(info.QualifiedName, DNSConstants.TYPE_SRV, DNSConstants.CLASS_IN), now); out_Renamed.AddAnswer((DNSRecord) Enclosing_Instance.Cache.get_Renamed(info.QualifiedName, DNSConstants.TYPE_TXT, DNSConstants.CLASS_IN), now); if (info.server != null) { out_Renamed.AddAnswer((DNSRecord) Enclosing_Instance.Cache.get_Renamed(info.server, DNSConstants.TYPE_A, DNSConstants.CLASS_IN), now); } Enclosing_Instance.Send(out_Renamed); } else { // After three queries, we can quit. // TODO: can omit cancel()? //cancel(); Enclosing_Instance.RemoveListener(info); } ; } else if (Enclosing_Instance.State == DNSState.CANCELED) { // TODO: can omit cancel?? //cancel(); Enclosing_Instance.RemoveListener(info); } } catch (Exception e) { logger.Warn("run() exception ", e); Enclosing_Instance.Recover(); } }
public void Run(object state) { try { if (Enclosing_Instance.State == DNSState.ANNOUNCED) { if (count++ < 3 && !info.HasData) { long now = (DateTime.Now.Ticks - 621355968000000000) / 10000; DNSOutgoing out_Renamed = new DNSOutgoing(DNSConstants.FLAGS_QR_QUERY); out_Renamed.AddQuestion(new DNSQuestion(info.QualifiedName, DNSConstants.TYPE_SRV, DNSConstants.CLASS_IN)); out_Renamed.AddQuestion(new DNSQuestion(info.QualifiedName, DNSConstants.TYPE_TXT, DNSConstants.CLASS_IN)); if (info.server != null) { out_Renamed.AddQuestion(new DNSQuestion(info.server, DNSConstants.TYPE_A, DNSConstants.CLASS_IN)); } out_Renamed.AddAnswer((DNSRecord)Enclosing_Instance.Cache.get_Renamed(info.QualifiedName, DNSConstants.TYPE_SRV, DNSConstants.CLASS_IN), now); out_Renamed.AddAnswer((DNSRecord)Enclosing_Instance.Cache.get_Renamed(info.QualifiedName, DNSConstants.TYPE_TXT, DNSConstants.CLASS_IN), now); if (info.server != null) { out_Renamed.AddAnswer((DNSRecord)Enclosing_Instance.Cache.get_Renamed(info.server, DNSConstants.TYPE_A, DNSConstants.CLASS_IN), now); } Enclosing_Instance.Send(out_Renamed); } else { // After three queries, we can quit. // TODO: can omit cancel()? //cancel(); Enclosing_Instance.RemoveListener(info); } ; } else if (Enclosing_Instance.State == DNSState.CANCELED) { // TODO: can omit cancel?? //cancel(); Enclosing_Instance.RemoveListener(info); } } catch (Exception e) { logger.Warn("run() exception ", e); Enclosing_Instance.Recover(); } }
public void Run(object state) { try { if (++count < 3) { logger.Debug("run() JmDNS canceling service"); // announce the service DNSOutgoing out_Renamed = new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA); for (int i = 0; i < infos.Length; i++) { ServiceInfo info = infos[i]; out_Renamed.AddAnswer(new Pointer(info.type, DNSConstants.TYPE_PTR, DNSConstants.CLASS_IN, ttl, info.QualifiedName), 0); out_Renamed.AddAnswer(new Service(info.QualifiedName, DNSConstants.TYPE_SRV, DNSConstants.CLASS_IN, ttl, info.priority, info.weight, info.port, Enclosing_Instance.localHost.Name), 0); out_Renamed.AddAnswer(new Text(info.QualifiedName, DNSConstants.TYPE_TXT, DNSConstants.CLASS_IN, ttl, info.text), 0); DNSRecord answer = Enclosing_Instance.localHost.DNS4AddressRecord; if (answer != null) { out_Renamed.AddAnswer(answer, 0); } answer = Enclosing_Instance.localHost.DNS6AddressRecord; if (answer != null) { out_Renamed.AddAnswer(answer, 0); } } Enclosing_Instance.Send(out_Renamed); } else { // After three successful announcements, we are finished. lock (lock_Renamed) { Monitor.PulseAll(lock_Renamed); } // TODO: omit cancel? //cancel(); } } catch (Exception e) { logger.Warn("run() exception ", e); Enclosing_Instance.Recover(); } }
public void Run(object state) { try { if (Enclosing_Instance.State == DNSState.ANNOUNCED) { if (count++ < 3) { logger.Debug("run() JmDNS querying service"); long now = (DateTime.Now.Ticks - 621355968000000000) / 10000; DNSOutgoing out_Renamed = new DNSOutgoing(DNSConstants.FLAGS_QR_QUERY); out_Renamed.AddQuestion(new DNSQuestion(type, DNSConstants.TYPE_PTR, DNSConstants.CLASS_IN)); foreach (ServiceInfo info in Enclosing_Instance.services.Values) { try { out_Renamed.AddAnswer(new Pointer(info.type, DNSConstants.TYPE_PTR, DNSConstants.CLASS_IN, DNSConstants.DNS_TTL, info.QualifiedName), now); } catch { break; } } Enclosing_Instance.Send(out_Renamed); } else { // After three queries, we can quit. // TODO: can omit? //cancel(); } ; } else if (Enclosing_Instance.State == DNSState.CANCELED) { // TODO: can omit? //cancel(); } } catch (Exception e) { logger.Warn("run() exception ", e); Enclosing_Instance.Recover(); } }
/// <summary> Add an answer to a question. Deal with the case when the /// outgoing packet overflows /// </summary> internal virtual DNSOutgoing AddAnswer(DNSIncoming in_Renamed, IPAddress addr, int port, DNSOutgoing out_Renamed, DNSRecord rec) { if (out_Renamed == null) { out_Renamed = new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA); } try { out_Renamed.AddAnswer(in_Renamed, rec); } catch { out_Renamed.flags |= DNSConstants.FLAGS_TC; out_Renamed.id = in_Renamed.id; out_Renamed.Finish(); Send(out_Renamed); out_Renamed = new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA); out_Renamed.AddAnswer(in_Renamed, rec); } return(out_Renamed); }
public void Run(object state) { try { if (Enclosing_Instance.State == DNSState.ANNOUNCED) { if (++count < 3) { logger.Debug("run() JmDNS querying type"); DNSOutgoing out_Renamed = new DNSOutgoing(DNSConstants.FLAGS_QR_QUERY); out_Renamed.AddQuestion(new DNSQuestion("_services._mdns._udp.local.", DNSConstants.TYPE_PTR, DNSConstants.CLASS_IN)); foreach (string s in Enclosing_Instance.serviceTypes.Values) { out_Renamed.AddAnswer(new Pointer("_services._mdns._udp.local.", DNSConstants.TYPE_PTR, DNSConstants.CLASS_IN, DNSConstants.DNS_TTL, s), 0); } Enclosing_Instance.Send(out_Renamed); } else { // After three queries, we can quit. // TODO: can we omit this? //cancel(); } ; } else if (Enclosing_Instance.State == DNSState.CANCELED) { // TODO: can omit this? //cancel(); } } catch (Exception e) { logger.Warn("run() exception ", e); Enclosing_Instance.Recover(); } }
/// <summary> Add an answer to a question. Deal with the case when the /// outgoing packet overflows /// </summary> internal virtual DNSOutgoing AddAnswer(DNSIncoming in_Renamed, IPAddress addr, int port, DNSOutgoing out_Renamed, DNSRecord rec) { if (out_Renamed == null) { out_Renamed = new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA); } try { out_Renamed.AddAnswer(in_Renamed, rec); } catch { out_Renamed.flags |= DNSConstants.FLAGS_TC; out_Renamed.id = in_Renamed.id; out_Renamed.Finish(); Send(out_Renamed); out_Renamed = new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA); out_Renamed.AddAnswer(in_Renamed, rec); } return out_Renamed; }
public void Run(object state) { try { if (++count < 3) { logger.Debug("run() JmDNS canceling service"); // announce the service DNSOutgoing out_Renamed = new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA); for (int i = 0; i < infos.Length; i++) { ServiceInfo info = infos[i]; out_Renamed.AddAnswer(new Pointer(info.type, DNSConstants.TYPE_PTR, DNSConstants.CLASS_IN, ttl, info.QualifiedName), 0); out_Renamed.AddAnswer(new Service(info.QualifiedName, DNSConstants.TYPE_SRV, DNSConstants.CLASS_IN, ttl, info.priority, info.weight, info.port, Enclosing_Instance.localHost.Name), 0); out_Renamed.AddAnswer(new Text(info.QualifiedName, DNSConstants.TYPE_TXT, DNSConstants.CLASS_IN, ttl, info.text), 0); DNSRecord answer = Enclosing_Instance.localHost.DNS4AddressRecord; if (answer != null) out_Renamed.AddAnswer(answer, 0); answer = Enclosing_Instance.localHost.DNS6AddressRecord; if (answer != null) out_Renamed.AddAnswer(answer, 0); } Enclosing_Instance.Send(out_Renamed); } else { // After three successful announcements, we are finished. lock (lock_Renamed) { Monitor.PulseAll(lock_Renamed); } // TODO: omit cancel? //cancel(); } } catch (Exception e) { logger.Warn("run() exception ", e); Enclosing_Instance.Recover(); } }