dnscache

package
v0.30.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package dnscache maps remote IP addresses back to the hostnames the local machine resolved them from. netscope can only see IPs on the wire; by sniffing DNS responses it recovers the human-meaningful domain for each flow.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is a bounded, TTL'd IP -> hostname map. Safe for concurrent use.

Entries are kept in a list ordered by when they were last seen, oldest at the front, so eviction is a pop rather than a scan. That matters on the packet path: a laptop that has been up for a few days runs this cache full, and full is where every DNS answer and every SNI hit used to pay an O(n) walk over 20 000 entries to find the one to drop.

func New

func New(ttl time.Duration, max int) *Cache

New returns a Cache. ttl bounds how long a mapping is trusted after it was last observed; max bounds the number of retained entries.

func (*Cache) Len

func (c *Cache) Len() int

Len reports the number of cached mappings.

func (*Cache) LoadFrom added in v0.6.0

func (c *Cache) LoadFrom(path string) error

LoadFrom merges mappings from a file written by SaveTo, preserving each entry's original "seen" time (so the TTL still applies) and dropping any that have already expired. A missing file is not an error.

func (*Cache) Lookup

func (c *Cache) Lookup(ip string) string

Lookup returns the hostname for ip, or "" if unknown or expired.

func (*Cache) Put

func (c *Cache) Put(ip, host string)

Put records that ip resolves to host. The most recent mapping wins.

func (*Cache) SaveTo added in v0.6.0

func (c *Cache) SaveTo(path string) error

SaveTo writes the cache to path as JSON (atomically via a temp file + rename), so learned IP→host mappings survive a daemon restart.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL