list known domains

This commit is contained in:
Vladimir Avtsenov 2024-09-06 06:34:52 +03:00
parent a4354326f5
commit b623c9a9c9

View File

@ -243,6 +243,22 @@ func (r *Records) PutARecord(domainName string, addr net.IP, ttl time.Duration)
record.ARecords = append(record.ARecords, NewARecord(addr, time.Now().Add(ttl))) record.ARecords = append(record.ARecords, NewARecord(addr, time.Now().Add(ttl)))
} }
func (r *Records) ListKnownDomains() []string {
r.mutex.Lock()
defer r.mutex.Unlock()
domains := make([]string, 0)
for name, record := range r.Records {
if record.Cleanup() {
delete(r.Records, name)
continue
}
domains = append(domains, name)
}
return domains
}
func (r *Records) Cleanup() { func (r *Records) Cleanup() {
r.mutex.Lock() r.mutex.Lock()
defer r.mutex.Unlock() defer r.mutex.Unlock()