RWMutex may help performance in DNS tracking

This commit is contained in:
Armen Boursalian 2018-08-28 08:21:26 -07:00
parent b95c63f0c0
commit a8a52f8650

View file

@ -12,7 +12,7 @@ import (
var ( var (
responses = make(map[string]string, 0) responses = make(map[string]string, 0)
lock = sync.Mutex{} lock = sync.RWMutex{}
) )
func TrackAnswers(packet gopacket.Packet) bool { func TrackAnswers(packet gopacket.Packet) bool {
@ -63,8 +63,8 @@ func Track(resolved string, hostname string) {
} }
func Host(resolved string) (host string, found bool) { func Host(resolved string) (host string, found bool) {
lock.Lock() lock.RLock()
defer lock.Unlock() defer lock.RUnlock()
host, found = responses[resolved] host, found = responses[resolved]
return return