/// <summary> /// Add the given DNS information to the DNS cache. /// </summary> /// <param name="Domainname">The domain name.</param> /// <param name="DNSInformation">The DNS information to add.</param> public DNSCache Add(String Domainname, DNSInfo DNSInformation) { lock (_DNSCache) { DNSCacheEntry CacheEntry = null; if (!_DNSCache.TryGetValue(Domainname, out CacheEntry)) { _DNSCache.Add(Domainname, new DNSCacheEntry( DateTime.Now + TimeSpan.FromSeconds(DNSInformation.Answers.First().TimeToLive.TotalSeconds / 2), DateTime.Now + DNSInformation.Answers.First().TimeToLive, DNSInformation)); } else { // ToDo: Merge of DNS responses! _DNSCache[Domainname] = new DNSCacheEntry( DateTime.Now + TimeSpan.FromSeconds(DNSInformation.Answers.First().TimeToLive.TotalSeconds / 2), DateTime.Now + DNSInformation.Answers.First().TimeToLive, DNSInformation); } return(this); } }
/// <summary> /// Get the cached DNS information from the DNS cache. /// </summary> /// <param name="DomainName">The domain name.</param> public DNSInfo GetDNSInfo(String DomainName) { lock (_DNSCache) { DNSCacheEntry CacheEntry = null; if (_DNSCache.TryGetValue(DomainName, out CacheEntry)) { return(CacheEntry.DNSInfo); } return(null); } }
/// <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 information to the DNS cache. /// </summary> /// <param name="Domainname">The domain name.</param> /// <param name="DNSInformation">The DNS information to add.</param> public DNSCache Add(String Domainname, DNSInfo DNSInformation) { lock (_DNSCache) { DNSCacheEntry CacheEntry = null; if (!_DNSCache.TryGetValue(Domainname, out CacheEntry)) _DNSCache.Add(Domainname, new DNSCacheEntry( DateTime.Now + TimeSpan.FromSeconds(DNSInformation.Answers.First().TimeToLive.TotalSeconds / 2), DateTime.Now + DNSInformation.Answers.First().TimeToLive, DNSInformation)); else { // ToDo: Merge of DNS responses! _DNSCache[Domainname] = new DNSCacheEntry( DateTime.Now + TimeSpan.FromSeconds(DNSInformation.Answers.First().TimeToLive.TotalSeconds / 2), DateTime.Now + DNSInformation.Answers.First().TimeToLive, DNSInformation); } return this; } }