mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-12-01 15:39:44 +00:00
dont start periodic task until necessary
This commit is contained in:
10 files changed
+81
-162
No files matched your search
+9
-3
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user