internalsdk

package
v0.0.0-...-22f0dc9 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: GPL-3.0 Imports: 52 Imported by: 0

Documentation

Overview

package internalsdk implements the mobile application functionality of flashlight

Index

Constants

This section is empty.

Variables

View Source
var (
	// This gets set at build time
	ApplicationVersion = "9999.99.99"

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

Functions

func AllocateRelayAddress

func AllocateRelayAddress(localAddr string) (string, error)

AllocateRelay allocates a relay location at which peers can relay WebRTC traffic to us. If successful, it starts relaying traffic to/from the localAddr and returns the URL at which peers should connect in order to start relaying.

func BytesToFloat64LittleEndian

func BytesToFloat64LittleEndian(b []byte) (float64, error)

func CheckForUpdates

func CheckForUpdates(deviceInfo DeviceInfo) (string, error)

CheckForUpdates checks to see if a new version of Lantern is available

func Debug

func Debug(tag, msg string)

func DownloadUpdate

func DownloadUpdate(deviceInfo DeviceInfo, url, apkPath string, updater Updater) bool

DownloadUpdate downloads the latest APK from the given url to the apkPath file destination.

func Error

func Error(tag, msg string)

func InstallFinished

func InstallFinished(deviceInfo DeviceInfo, success bool)

InstallFinished is called after an update successfully installs or fails to and records ops related to it

func NewReplicaServer

func NewReplicaServer(handler *replicaServer.HttpHandler) (net.Listener, *http.Server, error)

NewReplicaServer uses 'handler' to setup a new net.Listener for Replica on localhost over the next available TCP port.

Returns an http.Server configured with a Replica http.Handler and a TCP listener bound to a random port

func NewStatsTracker

func NewStatsTracker(session panickingSession) *statsTracker

func RelayTo

func RelayTo(relayAddr string) (string, error)

func SDKVersion

func SDKVersion() string

Get the version number of the Go library.

func SendIssueReport

func SendIssueReport(
	session Session,
	issueType string,
	description string,
	subscriptionLevel string,
	userEmail string,
	device string,
	model string,
	osVersion string,
) error

func SetGeoInfo

func SetGeoInfo(cb GeoCallback)

SetGetGeoInfo set's the client's current geo info on the given GeoCallback (if available).

func StopTun2Socks

func StopTun2Socks()

StopTun2Socks stops the current tun device.

func Tun2Socks

func Tun2Socks(fd int, socksAddr, dnsGrabAddr string, mtu int, wrappedSession Session) error

Tun2Socks wraps the TUN device identified by fd with an ipproxy server that does the following:

1. dns packets (any UDP packets to port 53) are routed to dnsGrabAddr 2. All other udp packets are routed directly to their destination 3. All TCP traffic is routed through the Lantern proxy at the given socksAddr.

Types

type AdProvider

type AdProvider interface {
	GetNativeBannerZoneID() string
	GetStandardBannerZoneID() string
	GetInterstitialZoneID() string
	ShouldShowAd() bool
}

AdProvider provides information for displaying an ad and makes decisions on whether or not to display it.

type AdSettings

type AdSettings interface {
	// GetAdProvider gets an ad provider if and only if ads are enabled based on the passed parameters.
	GetAdProvider(isPro bool, countryCode string, daysSinceInstalled int) (AdProvider, error)
}

AdSettings is an interface for retrieving mobile ad settings from the global config

type Arguments

type Arguments interface {
	Scalar() *minisql.Value
	Get(name string) *minisql.Value
}

type ChangeSet

type ChangeSet struct {
	// contains filtered or unexported fields
}

ChangeSet represents changes in a database.

func (*ChangeSet) HasDelete

func (cs *ChangeSet) HasDelete() bool

func (*ChangeSet) HasUpdate

func (cs *ChangeSet) HasUpdate() bool

func (*ChangeSet) PopDelete

func (cs *ChangeSet) PopDelete() string

func (*ChangeSet) PopUpdate

func (cs *ChangeSet) PopUpdate() (*Update, error)

type DeviceInfo

type DeviceInfo interface {
	DeviceID() string
	Model() string
	Hardware() string
	SdkVersion() int
	UserID() string
}

DeviceInfo provides information about a device for sending with ops when downloading and installing auto-updates

type EmailMessage

type EmailMessage email.Message

EmailMessage exposes the type email.Message as part of this package.

func (*EmailMessage) PutInt

func (msg *EmailMessage) PutInt(key string, val int)

PutInt sets an integer variable

func (*EmailMessage) PutString

func (msg *EmailMessage) PutString(key string, val string)

PutString sets a string variable

func (*EmailMessage) Send

func (msg *EmailMessage) Send(handler EmailResponseHandler)

Send sends this EmailMessage using the email package.

type EmailResponseHandler

type EmailResponseHandler interface {
	OnError(errMsg string)
	OnSuccess()
}

EmailResponseHandler is used to return a response to the client in the event there's an error sending an email

type GeoCallback

type GeoCallback interface {
	SetIP(string)
	SetCountry(string)
	SetRegion(string)
	SetCity(string)
	SetLatitude(float64)
	SetLongitude(float64)
}

type MessagingModel

type MessagingModel struct {
	// contains filtered or unexported fields
}

Messing Model

func NewMessagingModel

func NewMessagingModel(mdb minisql.DB) (*MessagingModel, error)

func (MessagingModel) InvokeMethod

func (m MessagingModel) InvokeMethod(method string, arguments Arguments) (*minisql.Value, error)

InvokeMethod handles method invocations on the model.

func (MessagingModel) Name

func (m MessagingModel) Name() string

func (MessagingModel) Subscribe

func (m MessagingModel) Subscribe(req *SubscriptionRequest) error

Subscribe subscribes to database changes based on the provided request.

func (MessagingModel) Unsubscribe

func (m MessagingModel) Unsubscribe(path string)

Unsubscribe unsubscribes from database changes using the provided ID.

type Model

type Model interface {
	Name() string
	InvokeMethod(method string, arguments Arguments) (*minisql.Value, error)
	Subscribe(req *SubscriptionRequest) error
	Unsubscribe(id string)
}

Model defines the methods that any model should implement

type ReplicaServer

type ReplicaServer struct {
	ConfigDir  string
	Flashlight *flashlight.Flashlight
	Session    Session
	UserConfig common.UserConfig
	// contains filtered or unexported fields
}

Replica HTTP Server that handles Replica API requests on localhost at a random port.

func (*ReplicaServer) CheckEnabled

func (s *ReplicaServer) CheckEnabled()

Checks whether Replica should be enabled and lazily starts the server if necessary.

If enabled, the server is started lazily and the server's random address is reported to Session.SetReplicaAddr. If disabled after having been enabled, the server keeps running and ReplicaAddr remains set to its old value.

type Session

type Session interface {
	GetAppName() string
	GetDeviceID() (string, error)
	GetUserID() (int64, error)
	GetToken() (string, error)
	SetCountry(string) error
	SetIP(string) error
	UpdateAdSettings(AdSettings) error
	UpdateStats(serverCity string, serverCountry string, serverCountryCode string, p3 int, p4 int, hasSucceedingProxy bool) error
	SetStaging(bool) error
	BandwidthUpdate(int, int, int, int) error
	Locale() (string, error)
	GetTimeZone() (string, error)
	Code() (string, error)
	GetCountryCode() (string, error)
	GetForcedCountryCode() (string, error)
	GetDNSServer() (string, error)
	Provider() (string, error)
	IsStoreVersion() (bool, error)
	Email() (string, error)
	Currency() (string, error)
	DeviceOS() (string, error)
	IsProUser() (bool, error)
	SetReplicaAddr(string)
	ForceReplica() bool
	SetChatEnabled(bool)
	SplitTunnelingEnabled() (bool, error)
	SetShowInterstitialAdsEnabled(bool)
	// workaround for lack of any sequence types in gomobile bind... ;_;
	// used to implement GetInternalHeaders() map[string]string
	// Should return a JSON encoded map[string]string {"key":"val","key2":"val", ...}
	SerializedInternalHeaders() (string, error)
}

Session provides an interface for interacting with the Android Java/Kotlin code. Note - all methods return an error so that Go has the opportunity to inspect any exceptions thrown from the Java code. If a method interface doesn't include an error, exceptions on the Java side immediately result in a panic from which Go cannot recover.

type SessionModel

type SessionModel struct {
	// contains filtered or unexported fields
}

Custom Model implemnation SessionModel is a custom model derived from the baseModel.

func NewSessionModel

func NewSessionModel(mdb minisql.DB, opts *SessionModelOpts) (*SessionModel, error)

NewSessionModel initializes a new SessionModel instance.

func (*SessionModel) BandwidthUpdate

func (m *SessionModel) BandwidthUpdate(p1 int, p2 int, p3 int, p4 int) error

Keep name as p1,p2,p3..... Name become part of Objective c so this is important

func (*SessionModel) Code

func (m *SessionModel) Code() (string, error)

Todo change method name to referral code

func (*SessionModel) Currency

func (m *SessionModel) Currency() (string, error)

func (*SessionModel) DeviceOS

func (m *SessionModel) DeviceOS() (string, error)

func (*SessionModel) Email

func (m *SessionModel) Email() (string, error)

func (*SessionModel) ForceReplica

func (m *SessionModel) ForceReplica() bool

func (*SessionModel) GetAppName

func (m *SessionModel) GetAppName() string

func (*SessionModel) GetCountryCode

func (m *SessionModel) GetCountryCode() (string, error)

Todo need to make chanegs for Force country setup

func (*SessionModel) GetDNSServer

func (m *SessionModel) GetDNSServer() (string, error)

func (*SessionModel) GetDeviceID

func (m *SessionModel) GetDeviceID() (string, error)

func (*SessionModel) GetForcedCountryCode

func (m *SessionModel) GetForcedCountryCode() (string, error)

func (*SessionModel) GetTimeZone

func (m *SessionModel) GetTimeZone() (string, error)

func (*SessionModel) GetToken

func (m *SessionModel) GetToken() (string, error)

func (*SessionModel) GetUserID

func (m *SessionModel) GetUserID() (int64, error)

Todo There is some issue with user id changeing it value When Coverting from bytes to Float

func (SessionModel) InvokeMethod

func (m SessionModel) InvokeMethod(method string, arguments Arguments) (*minisql.Value, error)

InvokeMethod handles method invocations on the model.

func (*SessionModel) IsProUser

func (m *SessionModel) IsProUser() (bool, error)

func (*SessionModel) IsStoreVersion

func (m *SessionModel) IsStoreVersion() (bool, error)

func (*SessionModel) Locale

func (m *SessionModel) Locale() (string, error)

func (SessionModel) Name

func (m SessionModel) Name() string

func (*SessionModel) Provider

func (m *SessionModel) Provider() (string, error)

func (*SessionModel) SerializedInternalHeaders

func (m *SessionModel) SerializedInternalHeaders() (string, error)

func (*SessionModel) SetChatEnabled

func (m *SessionModel) SetChatEnabled(chatEnable bool)

func (*SessionModel) SetCountry

func (m *SessionModel) SetCountry(country string) error

func (*SessionModel) SetIP

func (m *SessionModel) SetIP(ipAddress string) error

SetIP stores the IP address of the client after a successful geolookup

func (*SessionModel) SetReplicaAddr

func (m *SessionModel) SetReplicaAddr(replicaAddr string)

func (*SessionModel) SetShowInterstitialAdsEnabled

func (m *SessionModel) SetShowInterstitialAdsEnabled(adsEnable bool)

func (*SessionModel) SetStaging

func (m *SessionModel) SetStaging(staging bool) error

func (*SessionModel) SplitTunnelingEnabled

func (m *SessionModel) SplitTunnelingEnabled() (bool, error)

func (*SessionModel) StartService

func (m *SessionModel) StartService(configDir string,
	locale string,
	settings Settings)

Internal functions that manage method

func (SessionModel) Subscribe

func (m SessionModel) Subscribe(req *SubscriptionRequest) error

Subscribe subscribes to database changes based on the provided request.

func (SessionModel) Unsubscribe

func (m SessionModel) Unsubscribe(path string)

Unsubscribe unsubscribes from database changes using the provided ID.

func (*SessionModel) UpdateAdSettings

func (m *SessionModel) UpdateAdSettings(adsetting AdSettings) error

func (*SessionModel) UpdateStats

func (m *SessionModel) UpdateStats(serverCity string, serverCountry string, serverCountryCode string, p3 int, p4 int, hasSucceedingProxy bool) error

Note - the names of these parameters have to match what's defined on the `Session` interface

type SessionModelOpts

type SessionModelOpts struct {
	DevelopmentMode bool
	ProUser         bool
	DeviceID        string
	Device          string
	Model           string
	OsVersion       string
	PlayVersion     bool
	Lang            string
	TimeZone        string
	PaymentTestMode bool
	Platform        string
}

type Settings

type Settings interface {
	StickyConfig() bool
	GetHttpProxyHost() string
	GetHttpProxyPort() int
	TimeoutMillis() int
}

type StartResult

type StartResult struct {
	HTTPAddr    string
	SOCKS5Addr  string
	DNSGrabAddr string
}

StartResult provides information about the started Lantern

func Start

func Start(configDir string,
	locale string,
	settings Settings,
	wrappedSession Session) (*StartResult, error)

Start starts a HTTP and SOCKS proxies at random addresses. It blocks up till the given timeout waiting for the proxy to listen, and returns the addresses at which it is listening (HTTP, SOCKS). If the proxy doesn't start within the given timeout, this method returns an error.

If a Lantern proxy is already running within this process, that proxy is reused.

Note - this does not wait for the entire initialization sequence to finish, just for the proxy to be listening. Once the proxy is listening, one can start to use it, even as it finishes its initialization sequence. However, initial activity may be slow, so clients with low read timeouts may time out.

type SubscriptionRequest

type SubscriptionRequest struct {
	ID             string
	PathPrefixes   string
	JoinDetails    bool
	ReceiveInitial bool
	Updater        UpdaterModel
}

SubscriptionRequest defines the structure of a subscription request.

type SurveyInfo

type SurveyInfo struct {
	Enabled     bool    `json:"enabled"`
	Probability float64 `json:"probability"`
	Campaign    string  `json:"campaign"`
	Url         string  `json:"url"`
	Message     string  `json:"message"`
	Thanks      string  `json:"thanks"`
	Button      string  `json:"button"`
}

type Update

type Update struct {
	Path  string
	Value *minisql.Value
}

type Updater

type Updater autoupdate.Updater

type UpdaterModel

type UpdaterModel interface {
	OnChanges(cs *ChangeSet) error
}

UpdaterModel defines an interface to handle database changes.

type VPNManager

type VPNManager interface {
	StartVPN()
	StopVPN()
}

type VPNModel

type VPNModel struct {
	// contains filtered or unexported fields
}

Custom Model implemnation VPNModel is a custom model derived from the baseModel.

func NewVPNModel

func NewVPNModel(mdb minisql.DB) (*VPNModel, error)

func (*VPNModel) GetVPNStatus

func (m *VPNModel) GetVPNStatus() (string, error)

func (VPNModel) InvokeMethod

func (m VPNModel) InvokeMethod(method string, arguments Arguments) (*minisql.Value, error)

InvokeMethod handles method invocations on the model.

func (VPNModel) Name

func (m VPNModel) Name() string

func (*VPNModel) SaveVPNStatus

func (m *VPNModel) SaveVPNStatus(status string) error

func (*VPNModel) SetManager

func (s *VPNModel) SetManager(manager VPNManager)

func (VPNModel) Subscribe

func (m VPNModel) Subscribe(req *SubscriptionRequest) error

Subscribe subscribes to database changes based on the provided request.

func (*VPNModel) SwitchVPN

func (m *VPNModel) SwitchVPN(on bool) error

func (VPNModel) Unsubscribe

func (m VPNModel) Unsubscribe(path string)

Unsubscribe unsubscribes from database changes using the provided ID.

func (*VPNModel) UpdateBandwidth

func (m *VPNModel) UpdateBandwidth(percent int64, remaining int64, allowedint int64, ttlSeconds int64) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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