From 63bad9196b922fe9bd2884b4772dff1086888bdf Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 14 Sep 2024 16:42:30 +0530 Subject: [PATCH] GenericRecordInfo: added last modified and expiry TTL parameters. --- .../Dns/ResourceRecords/GenericRecordInfo.cs | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/DnsServerCore/Dns/ResourceRecords/GenericRecordInfo.cs b/DnsServerCore/Dns/ResourceRecords/GenericRecordInfo.cs index e2f0d6bb..82713334 100644 --- a/DnsServerCore/Dns/ResourceRecords/GenericRecordInfo.cs +++ b/DnsServerCore/Dns/ResourceRecords/GenericRecordInfo.cs @@ -29,6 +29,8 @@ namespace DnsServerCore.Dns.ResourceRecords bool _disabled; string _comments; + DateTime _lastModified; + uint _expiryTtl; DateTime _lastUsedOn; //not serialized @@ -59,6 +61,16 @@ namespace DnsServerCore.Dns.ResourceRecords ReadExtendedRecordInfoFrom(bR); break; + case 2: + _disabled = bR.ReadBoolean(); + _comments = bR.ReadShortString(); + + _lastModified = bR.ReadDateTime(); + _expiryTtl = bR.ReadUInt32(); + + ReadExtendedRecordInfoFrom(bR); + break; + default: throw new InvalidDataException("GenericRecordInfo format version not supported."); } @@ -66,7 +78,7 @@ namespace DnsServerCore.Dns.ResourceRecords protected sealed override void WriteRecordInfoTo(BinaryWriter bW) { - bW.Write((byte)1); //version + bW.Write((byte)2); //version bW.Write(_disabled); @@ -75,6 +87,9 @@ namespace DnsServerCore.Dns.ResourceRecords else bW.WriteShortString(_comments); + bW.Write(_lastModified); + bW.Write(_expiryTtl); + WriteExtendedRecordInfoTo(bW); } @@ -90,9 +105,22 @@ namespace DnsServerCore.Dns.ResourceRecords #endregion + #region public + + public uint GetPendingExpiryTtl() + { + uint elapsedSeconds = Convert.ToUInt32((DateTime.UtcNow - _lastModified).TotalSeconds); + if (elapsedSeconds < _expiryTtl) + return _expiryTtl - elapsedSeconds; + + return 0u; + } + + #endregion + #region properties - public bool Disabled + public virtual bool Disabled { get { return _disabled; } set { _disabled = value; } @@ -110,6 +138,18 @@ namespace DnsServerCore.Dns.ResourceRecords } } + public DateTime LastModified + { + get { return _lastModified; } + set { _lastModified = value; } + } + + public virtual uint ExpiryTtl + { + get { return _expiryTtl; } + set { _expiryTtl = value; } + } + public DateTime LastUsedOn { get { return _lastUsedOn; }