mirror of
https://github.com/strukturag/nextcloud-spreed-signaling
synced 2024-05-01 21:42:45 +02:00
Add lock to entries to prevent concurrent modifications.
This commit is contained in:
parent
2c4cdedcae
commit
c4fce20678
|
@ -55,11 +55,15 @@ type dnsMonitorEntry struct {
|
|||
hostname string
|
||||
hostIP net.IP
|
||||
|
||||
mu sync.Mutex
|
||||
ips []net.IP
|
||||
entries map[*DnsMonitorEntry]bool
|
||||
}
|
||||
|
||||
func (e *dnsMonitorEntry) setIPs(ips []net.IP, fromIP bool) {
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
|
||||
empty := len(e.ips) == 0
|
||||
if empty {
|
||||
// Simple case: initial lookup.
|
||||
|
@ -113,6 +117,21 @@ func (e *dnsMonitorEntry) setIPs(ips []net.IP, fromIP bool) {
|
|||
}
|
||||
}
|
||||
|
||||
func (e *dnsMonitorEntry) addEntry(entry *DnsMonitorEntry) {
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
|
||||
e.entries[entry] = true
|
||||
}
|
||||
|
||||
func (e *dnsMonitorEntry) removeEntry(entry *DnsMonitorEntry) bool {
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
|
||||
delete(e.entries, entry)
|
||||
return len(e.entries) == 0
|
||||
}
|
||||
|
||||
func (e *dnsMonitorEntry) runCallbacks(all []net.IP, add []net.IP, keep []net.IP, remove []net.IP) {
|
||||
for entry := range e.entries {
|
||||
entry.callback(entry, all, add, keep, remove)
|
||||
|
@ -197,7 +216,7 @@ func (m *DnsMonitor) Add(target string, callback DnsMonitorCallback) (*DnsMonito
|
|||
m.hostnames[hostname] = entry
|
||||
}
|
||||
e.entry = entry
|
||||
entry.entries[e] = true
|
||||
entry.addEntry(e)
|
||||
m.cond.Signal()
|
||||
return e, nil
|
||||
}
|
||||
|
@ -216,8 +235,7 @@ func (m *DnsMonitor) Remove(entry *DnsMonitorEntry) {
|
|||
}
|
||||
|
||||
entry.entry = nil
|
||||
delete(e.entries, entry)
|
||||
if len(e.entries) == 0 {
|
||||
if e.removeEntry(entry) {
|
||||
delete(m.hostnames, e.hostname)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue