common

package
v7.6.75 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: GPL-3.0 Imports: 13 Imported by: 8

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"
	XBQHeader                           = "XBQ"
	XBQHeaderv2                         = "XBQv2"
)
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"
)
View Source
const Platform = runtime.GOOS

Variables

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"

	// StagingMode if true, run Lantern against our staging infrastructure.
	// This is set by the linker using -ldflags
	StagingMode = "false"

	Staging = false

	ProAPIHost = "api.getiantem.org"

	// Set by the linker using -ldflags in the project's Makefile.
	// Defaults to 'production' so as not to mistakingly push development work
	// to a production environment
	Environment = "production"
)
View Source
var (
	// CompileTimeApplicationVersion is set at compile-time by application production builds
	CompileTimeApplicationVersion string = ""

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

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 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
}

AuthConfig retrieves any custom info for interacting with internal services.

type NullAuthConfig

type NullAuthConfig struct{}

NullAuthConfig is useful for testing

func (NullAuthConfig) GetAppName

func (a NullAuthConfig) GetAppName() string

func (NullAuthConfig) GetDeviceID

func (a NullAuthConfig) GetDeviceID() string

func (NullAuthConfig) GetEnabledExperiments

func (a NullAuthConfig) GetEnabledExperiments() []string

func (NullAuthConfig) GetToken

func (a NullAuthConfig) GetToken() string

func (NullAuthConfig) GetUserID

func (a NullAuthConfig) GetUserID() int64

type NullUserConfig

type NullUserConfig struct{ NullAuthConfig }

NullUserConfig is useful for testing

func (NullUserConfig) GetInternalHeaders

func (s NullUserConfig) GetInternalHeaders() map[string]string

func (NullUserConfig) GetLanguage

func (s NullUserConfig) GetLanguage() string

func (NullUserConfig) GetTimeZone

func (s NullUserConfig) GetTimeZone() (string, error)

type UserConfig

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

UserConfig retrieves auth and other metadata passed to internal services.

type UserConfigData

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

an implementation of common.UserConfig

func NewUserConfigData

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

NewUserConfigData constucts a new UserConfigData (common.UserConfig) 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

Jump to

Keyboard shortcuts

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