common

package
v0.0.0-...-b80b294 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ProxiesURL is the URL for fetching the per user proxy config.
	ProxiesURL = "http://config.getiantem.org/proxies.yaml.gz"

	// ProxiesStagingURL is the URL for fetching the per user proxy config in a staging environment.
	ProxiesStagingURL = "http://config-staging.getiantem.org/proxies.yaml.gz"

	// Sentry Configurations
	SentryTimeout         = time.Second * 30
	SentryMaxMessageChars = 8000

	// UpdateServerURL is the URL of the update server. Different applications
	// hit the server on separate paths "/update/<AppName>".
	UpdateServerURL = "https://update.getlantern.org"
)
View Source
const (
	AppHeader                           = "X-Lantern-App"
	LibraryVersionHeader                = "X-Lantern-Version"
	AppVersionHeader                    = "X-Lantern-App-Version"
	DeviceIdHeader                      = "X-Lantern-Device-Id"
	SupportedDataCapsHeader             = "X-Lantern-Supported-Data-Caps"
	TimeZoneHeader                      = "X-Lantern-Time-Zone"
	TokenHeader                         = "X-Lantern-Auth-Token"
	UserIdHeader                        = "X-Lantern-User-Id"
	ProTokenHeader                      = "X-Lantern-Pro-Token"
	CfgSvrAuthTokenHeader               = "X-Lantern-Config-Auth-Token"
	CfgSvrClientIPHeader                = "X-Lantern-Config-Client-IP"
	BBRBytesSentHeader                  = "X-BBR-Sent"
	BBRAvailableBandwidthEstimateHeader = "X-BBR-ABE"
	EtagHeader                          = "X-Lantern-Etag"
	KernelArchHeader                    = "X-Lantern-KernelArch"
	IfNoneMatchHeader                   = "X-Lantern-If-None-Match"
	PingHeader                          = "X-Lantern-Ping"
	PlatformHeader                      = "X-Lantern-Platform"
	PlatformVersionHeader               = "X-Lantern-PlatVer"
	ClientCountryHeader                 = "X-Lantern-Client-Country"
	RandomNoiseHeader                   = "X-Lantern-Rand"
	SleepHeader                         = "X-Lantern-Sleep"
	LocaleHeader                        = "X-Lantern-Locale"
	Referer                             = "Referer"
	XBQHeader                           = "XBQ"
	XBQHeaderv2                         = "XBQv2"
	ContentType                         = "Content-Type"
)
View Source
const (
	// The default name for this app (used if no client-supplied name is passed at initialization)
	DefaultAppName = "Lantern"

	// ProAvailable specifies whether the user can purchase pro with this version.
	ProAvailable = true

	// TrackingID is the Google Analytics tracking ID.
	TrackingID = "UA-21815217-12"

	// SentryDSN is Sentry's project ID thing
	SentryDSN = "https://f65aa492b9524df79b05333a0b0924c5@sentry.io/2222244"

	// SentryDSN is Sentry's for android project
	SentrtAndroidDSN = "https://4753d78f885f4b79a497435907ce4210@o75725.ingest.us.sentry.io/5850353"
)
View Source
const Platform = runtime.GOOS

Variables

View Source
var (
	// EnvMapping is a mapping for the Environment enum
	EnvMapping = map[string]Environment{
		Development.String(): Development,
		Production.String():  Production,
		Staging.String():     Staging,
	}

	// DisablePort is a boolean flag that corresponds with the DISABLE_PORT_RANDOMIZATION env var
	DisablePort bool
)
View Source
var (
	EnvironmentDevelopment = "development"
	EnvironmentProduction  = "production"
)
View Source
var (
	// GlobalURL URL for fetching the global config.
	GlobalURL = "https://globalconfig.flashlightproxy.com/global.yaml.gz"

	// GlobalStagingURL is the URL for fetching the global config in a staging environment.
	GlobalStagingURL = "https://globalconfig.flashlightproxy.com/global.yaml.gz"

	ProAPIHost = "api.getiantem.org"

	DFBaseUrl  = "df.iantem.io/api/v1"
	APIBaseUrl = "iantem.io/api/v1"
)
View Source
var (
	// ApplicationVersion is set at compile-time by application production builds
	ApplicationVersion string = "9999.99.99"

	// LibraryVersion is determined at runtime based on the version of the lantern library that's been included.
	LibraryVersion = ""

	// This gets set at build time
	RevisionDate = ""

	// This gets set at build time
	BuildDate = ""
)

Functions

func AddCommonHeaders

func AddCommonHeaders(uc UserConfig, req *http.Request)

AddCommonHeaders sets standard http headers on a request bound for an internal service, representing auth and other configuration metadata.

func AddCommonHeadersWithOptions

func AddCommonHeadersWithOptions(uc UserConfig, req *http.Request, overwriteAuth bool)

AddCommonHeadersWithOptions sets standard http headers on a request bound for an internal service, representing auth and other configuration metadata. The caller may specify overwriteAuth=false to prevent overwriting any of the common 'auth' headers (DeviceIdHeader, ProTokenHeader, UserIdHeader) that are already present in the given request.

func AddCommonNonUserHeaders

func AddCommonNonUserHeaders(uc UserConfig, req *http.Request)

AddCommonNonUserHeaders adds all common headers that are not user or device specific.

func CORSMiddleware

func CORSMiddleware(next http.Handler) http.Handler

CORSMiddleware is HTTP middleware used to process CORS requests on localhost

func ForceAds

func ForceAds() bool

ForceAds indicates whether adswapping should be forced to 100%

func ForceStaging

func ForceStaging()

ForceStaging forces staging mode.

func IsDevEnvironment

func IsDevEnvironment() bool

IsDevEnvironment checks if flashlight is currently being run in development mode

func IsStagingEnvironment

func IsStagingEnvironment() bool

IsDevEnvironment checks if flashlight is currently being run in staging mode

func ProcessCORS

func ProcessCORS(responseHeaders http.Header, r *http.Request) bool

ProcessCORS processes CORS requests on localhost. It returns true if the request is a valid CORS request from an allowed origin and false otherwise.

Types

type AuthConfig

type AuthConfig interface {
	GetAppName() string
	GetDeviceID() string
	GetUserID() int64
	GetToken() string
	Locale() string
}

AuthConfig retrieves any custom info for interacting with internal services.

type Environment

type Environment int

Environment represents different environments Lantern may be running in

const (
	Development Environment = iota
	Production
	Staging
)

func (Environment) IsDevelopment

func (e Environment) IsDevelopment() bool

IsDevelopment checks if flashlight is currently being run in dev mode

func (Environment) IsStaging

func (e Environment) IsStaging() bool

IsStaging checks if flashlight is currently being run in staging mode

func (Environment) String

func (e Environment) String() string

type UserConfig

type UserConfig interface {
	AuthConfig
	GetLanguage() string
	GetTimeZone() (string, error)
	GetInternalHeaders() map[string]string
	GetEnabledExperiments() []string
}

type UserConfigData

type UserConfigData struct {
	AppName  string
	DeviceID string
	UserID   int64
	Token    string
	Language string
	Headers  map[string]string
}

an implementation of UserConfig

func NewUserConfig

func NewUserConfig(appName string, deviceID string, userID int64, token string, headers map[string]string,
	lang string) *UserConfigData

NewUserConfig constucts a new UserConfigData with the given options.

func (*UserConfigData) GetAppName

func (uc *UserConfigData) GetAppName() string

func (*UserConfigData) GetDeviceID

func (uc *UserConfigData) GetDeviceID() string

func (*UserConfigData) GetEnabledExperiments

func (uc *UserConfigData) GetEnabledExperiments() []string

func (*UserConfigData) GetInternalHeaders

func (uc *UserConfigData) GetInternalHeaders() map[string]string

func (*UserConfigData) GetLanguage

func (uc *UserConfigData) GetLanguage() string

func (*UserConfigData) GetTimeZone

func (uc *UserConfigData) GetTimeZone() (string, error)

func (*UserConfigData) GetToken

func (uc *UserConfigData) GetToken() string

func (*UserConfigData) GetUserID

func (uc *UserConfigData) GetUserID() int64

func (*UserConfigData) Locale

func (uc *UserConfigData) Locale() string

Jump to

Keyboard shortcuts

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