sql

package
v0.0.0-...-fbfc268 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LogDiscard disables logging of DNS requests.
	LogDiscard = iota
	// LogAll logs all DNS requests.
	LogAll
	// LogHijacked only logs hijacked DNS requests.
	LogHijacked
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is a persistent DNS cache. Values added to the cache are written to a SQL database.

func NewCache

func NewCache(client *Client) *Cache

NewCache creates a new cache using client for persistence.

func (*Cache) Close

func (c *Cache) Close() error

Close consumes any outstanding writes and closes the cache.

func (*Cache) Evict

func (c *Cache) Evict(key uint32)

Evict queues a removal of key. As Set, Evict is non-blocking.

func (*Cache) Read

func (c *Cache) Read() []cache.Value

Read returns all entries in the cache.

func (*Cache) Reset

func (c *Cache) Reset()

Reset queues removal of all entries. As Set, Reset is non-blocking.

func (*Cache) Set

func (c *Cache) Set(key uint32, value cache.Value)

Set queues a write associating value with key. Set is non-blocking, but read operations wait for any pending writes to complete before reading.

func (*Cache) Stats

func (c *Cache) Stats() CacheStats

Stats returns cache statistics.

type CacheStats

type CacheStats struct {
	PendingTasks int
}

CacheStats containts cache statistics.

type Client

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

Client implements a client for a SQLite database.

func New

func New(filename string) (*Client, error)

New creates a new database client for given filename.

func (*Client) Close

func (c *Client) Close() error

Close waits for all queries to complete and then closes the database.

type LogEntry

type LogEntry struct {
	Time       time.Time
	RemoteAddr net.IP
	Hijacked   bool
	Qtype      uint16
	Question   string
	Answers    []string
}

LogEntry represents a log entry for a DNS request.

type LogEvent

type LogEvent struct {
	Time  time.Time
	Count int64
}

LogEvent contains the number of requests at a point in time.

type LogStats

type LogStats struct {
	Since        time.Time
	Total        int64
	Hijacked     int64
	PendingTasks int
	Events       []LogEvent
}

LogStats contains log statistics.

type Logger

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

Logger is a logger that logs DNS requests to a SQL database.

func NewLogger

func NewLogger(client *Client, mode int, ttl time.Duration) *Logger

NewLogger creates a new logger. Persisted entries are kept according to ttl.

func (*Logger) Close

func (l *Logger) Close() error

Close consumes any outstanding log requests and closes the logger.

func (*Logger) Read

func (l *Logger) Read(n int) ([]LogEntry, error)

Read returns the n most recent log entries.

func (*Logger) Record

func (l *Logger) Record(remoteAddr net.IP, hijacked bool, qtype uint16, question string, answers ...string)

Record records the given DNS request to the log database.

func (*Logger) Stats

func (l *Logger) Stats(resolution time.Duration) (LogStats, error)

Stats returns logger statistics. Events will be merged together according to resolution. A zero duration disables merging.

Jump to

Keyboard shortcuts

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