-
Notifications
You must be signed in to change notification settings - Fork 60
/
billstat.go
71 lines (57 loc) · 1.78 KB
/
billstat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Package billstat implements the AdGuard DNS billing statistics database.
package billstat
import (
"context"
"time"
"github.com/AdguardTeam/AdGuardDNS/internal/agd"
"github.com/AdguardTeam/AdGuardDNS/internal/geoip"
)
// Common Constants, Types, And Utilities
// Recorder is the billing statistics recorder interface.
type Recorder interface {
Record(
ctx context.Context,
id agd.DeviceID,
ctry geoip.Country,
asn geoip.ASN,
start time.Time,
proto agd.Protocol,
)
}
// type check
var _ Recorder = EmptyRecorder{}
// EmptyRecorder is a billing statistics recorder that does nothing.
type EmptyRecorder struct{}
// Record implements the Recorder interface for EmptyRecorder.
func (EmptyRecorder) Record(
_ context.Context,
_ agd.DeviceID,
_ geoip.Country,
_ geoip.ASN,
_ time.Time,
_ agd.Protocol,
) {
}
// Uploader is the interface for a backend that accepts the billing statistics
// records.
type Uploader interface {
Upload(ctx context.Context, records Records) (err error)
}
// Record is a single billing statistics 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
}
// Records is a helpful alias for a mapping of devices to their billing
// statistics records.
type Records = map[agd.DeviceID]*Record