mirror of
https://github.com/strukturag/nextcloud-spreed-signaling
synced 2024-05-17 21:16:33 +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
|
hostname string
|
||||||
hostIP net.IP
|
hostIP net.IP
|
||||||
|
|
||||||
|
mu sync.Mutex
|
||||||
ips []net.IP
|
ips []net.IP
|
||||||
entries map[*DnsMonitorEntry]bool
|
entries map[*DnsMonitorEntry]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *dnsMonitorEntry) setIPs(ips []net.IP, fromIP bool) {
|
func (e *dnsMonitorEntry) setIPs(ips []net.IP, fromIP bool) {
|
||||||
|
e.mu.Lock()
|
||||||
|
defer e.mu.Unlock()
|
||||||
|
|
||||||
empty := len(e.ips) == 0
|
empty := len(e.ips) == 0
|
||||||
if empty {
|
if empty {
|
||||||
// Simple case: initial lookup.
|
// 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) {
|
func (e *dnsMonitorEntry) runCallbacks(all []net.IP, add []net.IP, keep []net.IP, remove []net.IP) {
|
||||||
for entry := range e.entries {
|
for entry := range e.entries {
|
||||||
entry.callback(entry, all, add, keep, remove)
|
entry.callback(entry, all, add, keep, remove)
|
||||||
|
@ -197,7 +216,7 @@ func (m *DnsMonitor) Add(target string, callback DnsMonitorCallback) (*DnsMonito
|
||||||
m.hostnames[hostname] = entry
|
m.hostnames[hostname] = entry
|
||||||
}
|
}
|
||||||
e.entry = entry
|
e.entry = entry
|
||||||
entry.entries[e] = true
|
entry.addEntry(e)
|
||||||
m.cond.Signal()
|
m.cond.Signal()
|
||||||
return e, nil
|
return e, nil
|
||||||
}
|
}
|
||||||
|
@ -216,8 +235,7 @@ func (m *DnsMonitor) Remove(entry *DnsMonitorEntry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.entry = nil
|
entry.entry = nil
|
||||||
delete(e.entries, entry)
|
if e.removeEntry(entry) {
|
||||||
if len(e.entries) == 0 {
|
|
||||||
delete(m.hostnames, e.hostname)
|
delete(m.hostnames, e.hostname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue