model

package
v0.0.0-...-7328bb5 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package model contains data structures for the collector.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidMeasurement marks a measurement that does not conform to the minimal sanity checks.
	ErrInvalidMeasurement = errors.New("bad measurement")

	// AllowedClockSkewSeconds is how much the report timestamp can be in the future with regards to server.
	AllowedClockSkewSeconds = 60 * 5

	// AllowedLimitForOldReportsInDays makes server to reject reports with a timestamp older than this.
	AllowedLimitForOldReportsInDays = 7
)

Functions

This section is empty.

Types

type Collector

type Collector interface {
	// Save stores a valid Measurement in the internal store.
	Save(m *Measurement) bool
}

Collector receives measurements and stores them for later processing.

type Failure

type Failure struct {
	Op    string `json:"op"`
	Error string `json:"error"`
}

Failure encapsulates an error reported by clients.

type GeolocatingCollector

type GeolocatingCollector interface {
	Collector
	Geolocator
}

type Geolocator

type Geolocator interface {
	// Geolocate adds geolocation metadata based on the real IP of the client submitting the report.
	Geolocate(m *Measurement, ip string) error
}

Geolocator is able to extract ASN and Country Code (CC) from the Real IP of the client submitting the report.

type Measurement

type Measurement struct {
	Type         string     `json:"report-type"`
	UUID         string     `json:"uuid,omitempty"`
	OOID         string     `json:"ooni-measurement-id,omitempty"`
	OOIDLink     string     `json:"ooni-measurement-link,omitempty"`
	TimeStart    *time.Time `json:"time"`
	DurationMS   int64      `json:"duration_ms,omitempty"`
	TimeReported *time.Time `json:"t_reported,omitempty"`
	TimeRelayed  *time.Time `json:"t_relayed,omitempty"`
	Agent        string     `json:"agent,omitempty"`
	CollectorID  string     `json:"collector_id,omitempty"`
	Endpoint     string     `json:"endpoint,omitempty"`
	EndpointAddr string     `json:"endpoint_addr,omitempty"`
	EndpointPort int        `json:"endpoint_port,omitempty"`
	EndpointASN  string     `json:"endpoint_asn,omitempty"`
	EndpointCC   string     `json:"endpoint_cc,omitempty"`
	Protocol     string     `json:"proto,omitempty"`
	Config       any        `json:"config,omitempty"`
	ClientASN    string     `json:"client_asn"`
	ClientCC     string     `json:"client_cc"`
	Failure      *Failure   `json:"failure,omitempty"`
	SamplingRate float32    `json:"sampling_rate"`
}

Measurement is a single measurement reported by clients.

func NewMeasurement

func NewMeasurement() *Measurement

func (*Measurement) PreSave

func (m *Measurement) PreSave(cfg *config.Config) error

PreSave updates any needed fields before saving in the database. It returns an error if any of the optional fields are set to improper values.

func (*Measurement) Validate

func (m *Measurement) Validate() error

Validate returns an error if the measurement does not pass sanity checks. TODO(ain): pass time object for tests

type Submitter

type Submitter interface {
	// Submit sends a collection of measurements to an upstream collector.
	Submit(mm []*Measurement) bool
}

Submitter sends processed reports or aggregates to an upstream collector.

Jump to

Keyboard shortcuts

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