dont start periodic task until necessary

This commit is contained in:
Darien Raymond committed 2018-08-29 23:00:01 +02:00
1 parent 5a0a9aa65e
commit eb05a92592
10 files changed
+81 -162

No files matched your search

+9 -3
View File
@@ -59,13 +59,18 @@ func NewClassicNameServer(address net.Destination, dispatcher core.Dispatcher, c
Execute: s.Cleanup,
}
s.udpServer = udp.NewDispatcher(dispatcher, s.HandleResponse)
common.Must(s.cleanup.Start())
return s
}
func (s *ClassicNameServer) Cleanup() error {
now := time.Now()
s.Lock()
defer s.Unlock()
if len(s.ips) == 0 && len(s.requests) == 0 {
return newError("nothing to do. stopping...")
}
for domain, ips := range s.ips {
newIPs := make([]IPRecord, 0, len(ips))
for _, ip := range ips {
@@ -94,7 +99,6 @@ func (s *ClassicNameServer) Cleanup() error {
s.requests = make(map[uint16]pendingRequest)
}
s.Unlock()
return nil
}
@@ -151,7 +155,6 @@ func (s *ClassicNameServer) HandleResponse(ctx context.Context, payload *buf.Buf
func (s *ClassicNameServer) updateIP(domain string, ips []IPRecord) {
s.Lock()
defer s.Unlock()
newError("updating IP records for domain:", domain).AtDebug().WriteToLog()
now := time.Now()
@@ -163,6 +166,9 @@ func (s *ClassicNameServer) updateIP(domain string, ips []IPRecord) {
}
s.ips[domain] = ips
s.pub.Publish(domain, nil)
s.Unlock()
common.Must(s.cleanup.Start())
}
func (s *ClassicNameServer) getMsgOptions() *dns.OPT {