/// <summary> /// Add the given DNS resource record to the DNS cache. /// </summary> /// <param name="Domainname">The domain name.</param> /// <param name="Origin">The origin of the DNS resource record.</param> /// <param name="ResourceRecord">The DNS resource record to add.</param> public DNSCache Add(String Domainname, IPSocket Origin, ADNSResourceRecord ResourceRecord) { lock (_DNSCache) { DNSCacheEntry CacheEntry = null; //Debug.WriteLine("[" + DateTime.Now + "] Adding '" + Domainname + "' to the DNS cache!"); if (!_DNSCache.TryGetValue(Domainname, out CacheEntry)) { _DNSCache.Add(Domainname, new DNSCacheEntry( DateTime.Now + TimeSpan.FromSeconds(ResourceRecord.TimeToLive.TotalSeconds / 2), DateTime.Now + ResourceRecord.TimeToLive, new DNSInfo(Origin: Origin, QueryId: new Random().Next(), IsAuthorativeAnswer: false, IsTruncated: false, RecursionDesired: false, RecursionAvailable: false, ResponseCode: DNSResponseCodes.NoError, Answers: new ADNSResourceRecord[1] { ResourceRecord }, Authorities: new ADNSResourceRecord[0], AdditionalRecords: new ADNSResourceRecord[0]))); } else { // ToDo: Merge of DNS responses! Debug.WriteLine("[" + DateTime.Now + "] Resource record for '" + Domainname + "' already exists within the DNS cache!"); } return(this); } }
/// <summary> /// Add the given DNS resource record to the DNS cache. /// </summary> /// <param name="Domainname">The domain name.</param> /// <param name="Origin">The origin of the DNS resource record.</param> /// <param name="ResourceRecord">The DNS resource record to add.</param> public DNSCache Add(String Domainname, IPSocket Origin, ADNSResourceRecord ResourceRecord) { lock (_DNSCache) { DNSCacheEntry CacheEntry = null; //Debug.WriteLine("[" + DateTime.Now + "] Adding '" + Domainname + "' to the DNS cache!"); if (!_DNSCache.TryGetValue(Domainname, out CacheEntry)) _DNSCache.Add(Domainname, new DNSCacheEntry( DateTime.Now + TimeSpan.FromSeconds(ResourceRecord.TimeToLive.TotalSeconds / 2), DateTime.Now + ResourceRecord.TimeToLive, new DNSInfo(Origin: Origin, QueryId: new Random().Next(), IsAuthorativeAnswer: false, IsTruncated: false, RecursionDesired: false, RecursionAvailable: false, ResponseCode: DNSResponseCodes.NoError, Answers: new ADNSResourceRecord[1] { ResourceRecord }, Authorities: new ADNSResourceRecord[0], AdditionalRecords: new ADNSResourceRecord[0]))); else { // ToDo: Merge of DNS responses! Debug.WriteLine("[" + DateTime.Now + "] Resource record for '" + Domainname + "' already exists within the DNS cache!"); } return this; } }
internal void AddAnswer(ADNSResourceRecord ResourceRecord) { this._Answers.Add(ResourceRecord); }