/// <summary> /// Updates service information from a DNS record /// </summary> /// <param name="zc">Zc.</param> /// <param name="now">Now.</param> /// <param name="record">Record.</param> public void UpdateRecord(Zeroconf zc, long now, DNSRecord record) { if (record != null && !record.IsExpired(now)) { if (record.Type == DNSType.A && record.Name == this.Server) { this.Address = ((DNSAddress)record).Address.ToString(); } else if (record.Type == DNSType.SRV && record.Name == this.Name) { this.Server = ((DNSService)record).Server.ToString(); this.Port = ((DNSService)record).Port; this.Weight = ((DNSService)record).Weight; this.Priority = ((DNSService)record).Priority; UpdateRecord(zc, now, (DNSAddress)zc.Cache.GetByDetails( this.Server, DNSType.A, DNSClass.IN)); } else if (record.Type == DNSType.TXT && record.Name == this.Name) { SetText(((DNSText)record).Text); } } }
public void AddAnswerAtTime(DNSRecord record, long now) { if (now == 0 || !record.IsExpired(now)) { this.Answers.Add(new Tuple <DNSRecord, long>(record, now)); } }
/// <summary> /// Callback invoked by Zeroconf when new information arrives. /// Updates information required by browser in the Zeroconf cache. /// </summary> /// <param name="zc">Zc.</param> /// <param name="now">Now.</param> /// <param name="record">Record.</param> public void UpdateRecord(Zeroconf zc, long now, DNSRecord record) { if (record.Type == DNSType.PTR && record.Name == this.type) { bool expired = record.IsExpired(now); string alias = ((DNSPointer)record).Alias; string serviceKey = alias.ToLower(); DNSRecord oldRecord; bool success = this.services.TryGetValue(serviceKey, out oldRecord); if (!success && !expired) { this.services[serviceKey] = record; this.eventArgs.Enqueue( new Delegates.OnChangeEventArgs(this.type, alias, ServiceStateChange.Added) ); } else if (!expired) { oldRecord.ResetTTL(record); } else { this.services.Remove(serviceKey); this.eventArgs.Enqueue( new Delegates.OnChangeEventArgs(this.type, alias, ServiceStateChange.Removed) ); return; } long expires = record.GetExpirationTime(75); if (expires < this.nextTime) { this.nextTime = expires; } } }