psinet

package
v2.0.11+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2020 License: GPL-3.0 Imports: 8 Imported by: 16

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. This package also implements the Psiphon discovery algorithm.

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"`
	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. It's safe for concurrent usage. The Reload function supports hot reloading of Psiphon network data while the server is running.

func NewDatabase

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

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

func (*Database) DiscoverServers

func (db *Database) DiscoverServers(discoveryValue int) []string

DiscoverServers selects new encoded server entries to be "discovered" by the client, using the discoveryValue -- a function of the client's IP address -- as the input into the discovery algorithm.

func (*Database) GetHomepages

func (db *Database) GetHomepages(
	sponsorID, clientRegion, clientASN 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

GetHttpsRequestRegexes returns bytes transferred stats regexes for the specified sponsor.

func (*Database) GetRandomizedHomepages

func (db *Database) GetRandomizedHomepages(
	sponsorID, clientRegion, clientASN 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"`
}

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"`
	HttpsRequestRegexes []HttpsRequestRegex   `json:"https_request_regexes"`
}

Jump to

Keyboard shortcuts

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