MCPcopy
hub / github.com/AdguardTeam/dnsproxy / setWithSubnet

Method setWithSubnet

proxy/cache.go:349–363  ·  view source on GitHub ↗

setWithSubnet stores response and upstream with subnet in the cache. The given subnet mask and IP address are used to calculate the cache key. u, n, and l must not be nil.

(req, m *dns.Msg, u upstream.Upstream, n *net.IPNet, l *slog.Logger)

Source from the content-addressed store, hash-verified

347// given subnet mask and IP address are used to calculate the cache key. u, n,
348// and l must not be nil.
349func (c *cache) setWithSubnet(req, m *dns.Msg, u upstream.Upstream, n *net.IPNet, l *slog.Logger) {
350 item := c.respToItem(m, u, l)
351 if item == nil {
352 return
353 }
354
355 pref, _ := n.Mask.Size()
356 key := msgToKeyWithSubnet(req, n.IP.Mask(n.Mask), pref)
357 packed := item.pack()
358
359 c.itemsWithSubnetLock.Lock()
360 defer c.itemsWithSubnetLock.Unlock()
361
362 c.itemsWithSubnet.Set(key, packed)
363}
364
365// clearItems empties the simple cache.
366func (c *cache) clearItems() {

Callers 3

cacheRespMethod · 0.80
TestCache_getWithSubnetFunction · 0.80

Calls 4

respToItemMethod · 0.95
msgToKeyWithSubnetFunction · 0.85
packMethod · 0.80
SetMethod · 0.45

Tested by 2

TestCache_getWithSubnetFunction · 0.64