psinet

package
v0.0.0-...-9e90a31 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package psinet implements psinet database services. The psinet database is a JSON-format file containing information about the Psiphon network, including sponsors, home pages, stats regexes, available upgrades, and other servers for discovery.

Index

Constants

View Source
const (
	MAX_DATABASE_AGE_FOR_SERVER_ENTRY_VALIDITY = 48 * time.Hour
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientVersion

type ClientVersion struct {
	Version string `json:"version"`
}

type Database

type Database struct {
	common.ReloadableFile

	Sponsors               map[string]*Sponsor        `json:"sponsors"`
	Versions               map[string][]ClientVersion `json:"client_versions"`
	DefaultSponsorID       string                     `json:"default_sponsor_id"`
	DefaultAlertActionURLs map[string][]string        `json:"default_alert_action_urls"`
	ValidServerEntryTags   map[string]bool            `json:"valid_server_entry_tags"`
	DiscoveryServers       []*DiscoveryServer         `json:"discovery_servers"`
	// contains filtered or unexported fields
}

Database serves Psiphon API data requests. The Reload function supports hot reloading of Psiphon network data while the server is running.

All of the methods on Database are thread-safe, but callers must not mutate any returned data. The struct may be safely shared across goroutines.

func NewDatabase

func NewDatabase(filename string) (*Database, error)

NewDatabase initializes a Database, calling Reload on the specified filename.

func (*Database) GetAlertActionURLs

func (db *Database) GetAlertActionURLs(
	alertReason, sponsorID, clientRegion, clientASN, deviceRegion string) []string

GetAlertActionURLs returns a list of alert action URLs for the specified alert reason and sponsor.

func (*Database) GetDiscoveryServers

func (db *Database) GetDiscoveryServers() []*DiscoveryServer

func (*Database) GetDomainBytesChecksum

func (db *Database) GetDomainBytesChecksum(sponsorID string) []byte

GetDomainBytesChecksum returns the bytes transferred stats regexes checksum for the specified sponsor. The checksum may be nil.

func (*Database) GetHomepages

func (db *Database) GetHomepages(
	sponsorID, clientRegion, clientASN, deviceRegion string, isMobilePlatform bool) []string

GetHomepages returns a list of home pages for the specified sponsor, region, and platform.

func (*Database) GetHttpsRequestRegexes

func (db *Database) GetHttpsRequestRegexes(sponsorID string) ([]map[string]string, []byte)

GetHttpsRequestRegexes returns bytes transferred stats regexes and the associated checksum for the specified sponsor. The checksum may be nil.

func (*Database) GetRandomizedHomepages

func (db *Database) GetRandomizedHomepages(
	sponsorID, clientRegion, clientASN, deviceRegion string, isMobilePlatform bool) []string

GetRandomizedHomepages returns a randomly ordered list of home pages for the specified sponsor, region, and platform.

func (*Database) GetUpgradeClientVersion

func (db *Database) GetUpgradeClientVersion(clientVersion, clientPlatform string) string

GetUpgradeClientVersion returns a new client version when an upgrade is indicated for the specified client current version. The result is "" when no upgrade is available. Caller should normalize clientPlatform.

func (*Database) IsValidServerEntryTag

func (db *Database) IsValidServerEntryTag(serverEntryTag string) bool

IsValidServerEntryTag checks if the specified server entry tag is valid.

type DiscoveryServer

type DiscoveryServer struct {
	DiscoveryDateRange []time.Time `json:"discovery_date_range"`
	EncodedServerEntry string      `json:"encoded_server_entry"`

	IPAddress string `json:"-"`
}

func (*DiscoveryServer) String

func (s *DiscoveryServer) String() string

consistent.Member implementation. TODO: move to discovery package. Requires bridging to a new type.

type HomePage

type HomePage struct {
	Region string `json:"region"`
	URL    string `json:"url"`
}

type HttpsRequestRegex

type HttpsRequestRegex struct {
	Regex   string `json:"regex"`
	Replace string `json:"replace"`
}
type Sponsor struct {
	ID                  string                `json:"id"`
	HomePages           map[string][]HomePage `json:"home_pages"`
	MobileHomePages     map[string][]HomePage `json:"mobile_home_pages"`
	AlertActionURLs     map[string][]string   `json:"alert_action_urls"`
	HttpsRequestRegexes []HttpsRequestRegex   `json:"https_request_regexes"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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