internal

package
v0.0.0-...-e8355e7 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: BSD-3-Clause Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KrakenTickerInterval  = 30 * time.Minute
	MinTransportWords     = 3
	MinFunctionalFraction = 0.5
	MinRatioFraction      = 0.5
	TransportPrefix       = "transport"
	ExtraInfoPrefix       = "extra-info"
	RecordEndPrefix       = "-----END SIGNATURE-----"
)
View Source
const (
	// FarInTheFuture determines a time span that's far enough in the future to
	// practically count as infinity.
	FarInTheFuture = time.Hour * 24 * 365 * 100
	// MaxResources determines the maximum number of resources that we're
	// willing to buffer before sending a request to bridgestrap.
	MaxResources = 25
)
View Source
const (
	PrometheusNamespace = "rdsys_backend"
)

Variables

This section is empty.

Functions

func Deserialise

func Deserialise(filename string, object interface{}) error

func GetRandBase32

func GetRandBase32(numBytes int) (string, error)

GetRandBase32 takes as input the number of desired bytes and returns a Base32-encoded string consisting of the given number of cryptographically secure random bytes. If anything went wrong, an error is returned.

func InitKraken

func InitKraken(cfg *Config, shutdown chan bool, ready chan bool, bCtx *BackendContext)

func Serialise

func Serialise(filename string, object interface{}) error

func UnmarshalResources

func UnmarshalResources(rawResources []json.RawMessage) ([]core.Resource, error)

UnmarshalResources unmarshals a slice of raw JSON messages into the corresponding resources.

Types

type BackendConfig

type BackendConfig struct {
	ExtrainfoFile           string            `json:"extrainfo_file"`
	NetworkstatusFile       string            `json:"networkstatus_file"`
	DescriptorsFile         string            `json:"descriptors_file"`
	BlocklistFile           string            `json:"blocklist_file"`
	AllowlistFile           string            `json:"allowlist_file"`
	ApiTokens               map[string]string `json:"api_tokens"`
	ResourcesEndpoint       string            `json:"api_endpoint_resources"`
	ResourceStreamEndpoint  string            `json:"api_endpoint_resource_stream"`
	TargetsEndpoint         string            `json:"api_endpoint_targets"`
	StatusEndpoint          string            `json:"web_endpoint_status"`
	MetricsEndpoint         string            `json:"web_endpoint_metrics"`
	BridgestrapEndpoint     string            `json:"bridgestrap_endpoint"`
	BridgestrapToken        string            `json:"bridgestrap_token"`
	OnbascaEndpoint         string            `json:"onbasca_endpoint"`
	OnbascaToken            string            `json:"onbasca_token"`
	BandwidthRatioThreshold float64           `json:"bandwidth_ratio_threshold"`
	StorageDir              string            `json:"storage_dir"`
	AssignmentsFile         string            `json:"assignments_file"`
	// DistProportions contains the proportion of resources that each
	// distributor should get.  E.g. if the HTTPS distributor is set to x and
	// the Salmon distributor is set to y, then HTTPS gets x/(x+y) of all
	// resources and Salmon gets y/(x+y).
	DistProportions map[string]int            `json:"distribution_proportions"`
	Resources       map[string]ResourceConfig `json:"resources"`
	WebApi          WebApiConfig              `json:"web_api"`
}

func (BackendConfig) ResourceStreamURL

func (bc BackendConfig) ResourceStreamURL() string

ResourceStreamURL returns the url to connect to the resource stream endpoint

func (BackendConfig) ResourcesURL

func (bc BackendConfig) ResourcesURL() string

ResourceStreamURL returns the url to connect to the resources endpoint

type BackendContext

type BackendContext struct {
	Config    *Config
	Resources core.BackendResources
	// contains filtered or unexported fields
}

BackendContext contains the state that our backend requires.

func (*BackendContext) InitBackend

func (b *BackendContext) InitBackend(cfg *Config)

InitBackend initialises our backend.

type BridgeTest

type BridgeTest struct {
	Functional bool       `json:"functional"`
	LastTested *time.Time `json:"last_tested"`
	Ratio      *float64   `json:"ratio"`
	Error      string     `json:"error,omitempty"`
}

BridgeTest represents the status of a single bridge in bridgestrap's response.

type BridgeTestRequest

type BridgeTestRequest struct {
	BridgeLines []string `json:"bridge_lines"`
}

BridgeTestRequest represents requests for bridgestrap and onbasca. Here's what its API look like: https://gitlab.torproject.org/phw/bridgestrap#input

type BridgeTestResponse

type BridgeTestResponse struct {
	Bridges map[string]*BridgeTest `json:"bridge_results"`
	Time    float64                `json:"time"`
	Error   string                 `json:"error,omitempty"`
}

BridgesTestResponse represents bridgestrap and onbasca's responses.

type Config

type Config struct {
	Backend      BackendConfig `json:"backend"`
	Distributors Distributors  `json:"distributors"`
	Updaters     Updaters      `json:"updaters"`
	// contains filtered or unexported fields
}

Config represents our central configuration file.

func LoadConfig

func LoadConfig(filename string) (*Config, error)

LoadConfig loads the given JSON configuration file and returns the resulting Config configuration object.

func ParseFlags

func ParseFlags() (*Config, func() error, error)

ParseFlags to load config file and configure the log it returns a Config struct and a close function meant to be called once the program finishes

func (*Config) Set

func (config *Config) Set(filename string) error

Set loads the given JSON configuration file rewritting the existing config

func (*Config) String

func (config *Config) String() string

type Distributors

type Distributors struct {
	Https    HttpsDistConfig    `json:"https"`
	Salmon   SalmonDistConfig   `json:"salmon"`
	Stub     StubDistConfig     `json:"stub"`
	Gettor   GettorDistConfig   `json:"gettor"`
	Moat     MoatDistConfig     `json:"moat"`
	Telegram TelegramDistConfig `json:"telegram"`
	Whatsapp WhatsAppConfig     `json:"whatsapp"`
}

type EmailConfig

type EmailConfig struct {
	Address      string `json:"address"`
	SmtpServer   string `json:"smtp_server"`
	SmtpUsername string `json:"smtp_username"`
	SmtpPassword string `json:"smtp_password"`
	ImapServer   string `json:"imap_server"`
	ImapUsername string `json:"imap_username"`
	ImapPassword string `json:"imap_password"`
}

type GettorDistConfig

type GettorDistConfig struct {
	Resources      []string    `json:"resources"`
	Email          EmailConfig `json:"email"`
	MetricsAddress string      `json:"metrics_address"`
}

type GettorUpdater

type GettorUpdater struct {
	Github             Github             `json:"github"`
	Gitlab             Gitlab             `json:"gitlab"`
	S3Updaters         []S3Updater        `json:"s3"`
	GoogleDriveUpdater GoogleDriveUpdater `json:"gdrive"`
	MetricsAddress     string             `json:"metrics_address"`
}

type Github

type Github struct {
	AuthToken string `json:"auth_token"`
	Owner     string `json:"owner"`
	Repo      string `json:"repo"`
}

type Gitlab

type Gitlab struct {
	AuthToken string `json:"auth_token"`
	Owner     string `json:"owner"`
}

type GoogleDriveUpdater

type GoogleDriveUpdater struct {
	AppCredentialPath  string `json:"app_credential_path"`
	UserCredentialPath string `json:"user_credential_path"`
	ParentFolderID     string `json:"parent_folder_id"`
}

type HttpsDistConfig

type HttpsDistConfig struct {
	Resources        []string               `json:"resources"`
	WebApi           WebApiConfig           `json:"web_api"`
	TimeDistribution TimeDistributionConfig `json:"time_distribution"`
	TrustProxy       bool                   `json:"trust_proxy"`
}

type Metrics

type Metrics struct {
	DistributingNonFunctional prometheus.Gauge
	IgnoringBandwidthRatio    prometheus.Gauge
	FlickeringBandwidth       *prometheus.CounterVec
	RatiosSeen                prometheus.Histogram
	Resources                 *prometheus.GaugeVec
	DistributorResources      *prometheus.GaugeVec
	Requests                  *prometheus.CounterVec
}

func InitMetrics

func InitMetrics() *Metrics

InitMetrics initialises our Prometheus metrics.

type MoatDistConfig

type MoatDistConfig struct {
	Resources             []string               `json:"resources"`
	GeoipDB               string                 `json:"geoipdb"`
	Geoip6DB              string                 `json:"geoip6db"`
	CircumventionMap      string                 `json:"circumvention_map"`
	CircumventionDefaults string                 `json:"circumvention_defaults"`
	BuiltInBridgesURL     string                 `json:"builtin_bridges_url"`
	ShimTokens            map[string]string      `json:"shim_tokens"`
	DummyBridgesFile      string                 `json:"dummy_bridges_file"`
	TimeDistribution      TimeDistributionConfig `json:"time_distribution"`
	WebApi                WebApiConfig           `json:"web_api"`
	TrustProxy            bool                   `json:"trust_proxy"`
}

type ResourceConfig

type ResourceConfig struct {
	Unpartitioned bool     `json:"unpartitioned"`
	Stored        bool     `json:"stored"`
	Distributors  []string `json:"distributors"`
}

type ResourceTestPool

type ResourceTestPool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ResourceTestPool implements a pool to which we add resources until it's time to send them to bridgestrap for testing.

func NewResourceTestPool

func NewResourceTestPool(bridgestrapEndpoint string, bridgestrapToken string, onbascaEndpoint string, onbascaToken string, bandwidthRatioThreshold float64) *ResourceTestPool

NewResourceTestPool returns a new resource test pool.

func (*ResourceTestPool) GetTestFunc

func (p *ResourceTestPool) GetTestFunc() func(r core.Resource)

GetTestFunc returns a function that's executed when a new resource is added to rdsys's backend. The function takes as input a resource and submits it to our testing pool.

func (*ResourceTestPool) Stop

func (p *ResourceTestPool) Stop()

Stop stops the test pool by signalling to the dispatcher that it's time to shut down.

type S3Updater

type S3Updater struct {
	AccessKey                    string `json:"access_key"`
	AccessSecret                 string `json:"access_secret"`
	SigningMethod                string `json:"signing_method"`
	EndpointUrl                  string `json:"endpoint_url"`
	EndpointRegion               string `json:"endpoint_region"`
	Name                         string `json:"name"`
	Bucket                       string `json:"bucket"`
	NameProceduralGenerationSeed string `json:"name_procedural_generation_seed"`
}

type SalmonDistConfig

type SalmonDistConfig struct {
	Resources  []string     `json:"resources"`
	WebApi     WebApiConfig `json:"web_api"`
	WorkingDir string       `json:"working_dir"` // This is where Salmon stores its state.
}

type Set

type Set struct {
	Set map[interface{}]struct{}
	// contains filtered or unexported fields
}

func NewSet

func NewSet() *Set

func (*Set) Add

func (s *Set) Add(item interface{})

func (*Set) Contains

func (s *Set) Contains(item interface{}) bool

func (*Set) Length

func (s *Set) Length() int

func (*Set) Remove

func (s *Set) Remove(item interface{}) error

type Stringer

type Stringer interface {
	String() string
}

type StubDistConfig

type StubDistConfig struct {
	Resources []string     `json:"resources"`
	WebApi    WebApiConfig `json:"web_api"`
}

type TelegramDistConfig

type TelegramDistConfig struct {
	Resource             string            `json:"resource"`
	NumBridgesPerRequest int               `json:"num_bridges_per_request"`
	RotationPeriodHours  int               `json:"rotation_period_hours"`
	Token                string            `json:"token"`
	MinUserID            int64             `json:"min_user_id"`
	UpdaterTokens        map[string]string `json:"updater_tokens"`
	StorageDir           string            `json:"storage_dir"`
	ApiAddress           string            `json:"api_address"`
	LoxServerAddress     string            `json:"lox_server_address"`
}

type TimeDistributionConfig

type TimeDistributionConfig struct {
	NumBridgesPerRequest int    `json:"num_bridges_per_request"`
	RotationPeriodHours  int    `json:"rotation_period_hours"`
	NumPeriods           int    `json:"num_periods"`
	StorageDir           string `json:"storage_dir"`
}

type Updaters

type Updaters struct {
	Gettor GettorUpdater `json:"gettor"`
}

type WebApiConfig

type WebApiConfig struct {
	ApiAddress string `json:"api_address"`
	CertFile   string `json:"cert_file"`
	KeyFile    string `json:"key_file"`
}

type WhatsAppConfig

type WhatsAppConfig struct {
	SessionFile    string `json:"session_file"`
	MetricsAddress string `json:"metrics_address"`
}

Jump to

Keyboard shortcuts

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