billstat

package
v0.0.0-...-b6e3791 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package billstat implements the AdGuard DNS billing statistics database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmptyRecorder

type EmptyRecorder struct{}

EmptyRecorder is a billing statistics recorder that does nothing.

func (EmptyRecorder) Record

Record implements the Recorder interface for EmptyRecorder.

type Record

type Record struct {
	// Time is the time of the most recent query from the device.
	Time time.Time

	// Country is the detected country of the client's IP address, if any.
	Country geoip.Country

	// ASN is the detected ASN of the client's IP address, if any.
	ASN geoip.ASN

	// Queries is the total number of Queries the device has performed since the
	// most recent sync.  This value is an int32 to be in sync with the business
	// logic backend which uses this type.  Change it if it is changed there.
	Queries int32

	// Proto is the DNS protocol of the most recent query from the device.
	Proto agd.Protocol
}

Record is a single billing statistics Record.

type Recorder

type Recorder interface {
	Record(
		ctx context.Context,
		id agd.DeviceID,
		ctry geoip.Country,
		asn geoip.ASN,
		start time.Time,
		proto agd.Protocol,
	)
}

Recorder is the billing statistics recorder interface.

type Records

type Records = map[agd.DeviceID]*Record

Records is a helpful alias for a mapping of devices to their billing statistics records.

type RuntimeRecorder

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

RuntimeRecorder is the runtime billing statistics recorder. The records kept here are not persistent.

func NewRuntimeRecorder

func NewRuntimeRecorder(c *RuntimeRecorderConfig) (r *RuntimeRecorder)

NewRuntimeRecorder creates a new runtime billing statistics database. c must be non-nil.

func (*RuntimeRecorder) Record

func (r *RuntimeRecorder) Record(
	ctx context.Context,
	id agd.DeviceID,
	ctry geoip.Country,
	asn geoip.ASN,
	start time.Time,
	proto agd.Protocol,
)

Record implements the Recorder interface for *RuntimeRecorder.

func (*RuntimeRecorder) Refresh

func (r *RuntimeRecorder) Refresh(ctx context.Context) (err error)

Refresh implements the [agdserivce.Refresher] interface for *RuntimeRecorder. It uploads the currently available data and resets it.

type RuntimeRecorderConfig

type RuntimeRecorderConfig struct {
	// Uploader is used to upload the billing statistics records to.
	Uploader Uploader
}

RuntimeRecorderConfig is the configuration structure for a runtime billing statistics recorder. All fields must be non-empty.

type Uploader

type Uploader interface {
	Upload(ctx context.Context, records Records) (err error)
}

Uploader is the interface for a backend that accepts the billing statistics records.

Jump to

Keyboard shortcuts

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