MCPcopy
hub / github.com/Place1/wg-access-server / Lookup

Method Lookup

internal/dnsproxy/server.go:90–112  ·  view source on GitHub ↗
(m *dns.Msg)

Source from the content-addressed store, hash-verified

88}
89
90func (d *DNSServer) Lookup(m *dns.Msg) (*dns.Msg, error) {
91 key := makekey(m)
92
93 // check the cache first
94 if item, found := d.cache.Get(key); found {
95 logrus.Debugf("dns cache hit %s", prettyPrintMsg(m))
96 return item.(*dns.Msg), nil
97 }
98
99 // fallback to upstream exchange
100 response, _, err := d.client.Exchange(m, net.JoinHostPort(d.upstream[0], "53"))
101 if err != nil {
102 return nil, err
103 }
104
105 if len(response.Answer) > 0 {
106 ttl := time.Duration(response.Answer[0].Header().Ttl) * time.Second
107 logrus.Debugf("caching dns response for %s for %v seconds", prettyPrintMsg(m), ttl)
108 d.cache.Set(key, response, ttl)
109 }
110
111 return response, nil
112}
113
114func makekey(m *dns.Msg) string {
115 q := m.Question[0]

Callers 1

ServeDNSMethod · 0.95

Calls 3

makekeyFunction · 0.85
prettyPrintMsgFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected