internalsdk

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: 67 Imported by: 0

Documentation

Overview

package internalsdk implements the mobile application functionality of flashlight

Index

Constants

This section is empty.

Variables

This section is empty.

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 BytesToInt64Slice

func BytesToInt64Slice(b []byte) []int

func CheckForUpdates

func CheckForUpdates(deviceInfo DeviceInfo) (string, error)

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

func ConvertToUserDetailsResponse

func ConvertToUserDetailsResponse(userResponse *protos.LoginResponse) *protos.User

func CreateBinaryFile

func CreateBinaryFile(name string, data protoreflect.ProtoMessage) error

create binary data from proto

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 GenerateEncryptedKey

func GenerateEncryptedKey(password string, email string, salt []byte) *big.Int

Takes password and email, salt and returns encrypted key

func GenerateRandomString

func GenerateRandomString(length int) string

func GenerateSalt

func GenerateSalt() ([]byte, error)

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 Int64SliceToBytes

func Int64SliceToBytes(int64Slice []int) []byte

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 StopTun2Socks

func StopTun2Socks()

StopTun2Socks stops the current tun device.

func StringToIntSlice

func StringToIntSlice(str string) ([]int, error)

func ToString

func ToString(value int64) string

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 AppInfo

type AppInfo struct {
	PackageName string `json:"packageName"`
	Name        string `json:"name"`
	Icon        []int  `json:"icon"`
}

Define the struct to match the JSON structure

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 ClientSession

type ClientSession interface {
	GetDeviceID() (string, error)
	GetUserID() (int64, error)
	GetToken() (string, error)
	Locale() (string, error)
	SetUserIdAndToken(int64, string) error
}

ClientSession includes information needed to create a new client session

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

type PanickingSession interface {
	common.AuthConfig
	SetCountry(string)
	UpdateAdSettings(AdSettings)
	UpdateStats(string, string, string, int, int, bool)
	SetStaging(bool)
	BandwidthUpdate(int, int, int, int)
	Locale() string
	GetTimeZone() string
	Code() string
	GetCountryCode() string
	GetForcedCountryCode() string
	GetDNSServer() string
	Provider() string
	IsStoreVersion() bool
	Email() string
	Currency() string
	DeviceOS() string
	IsProUser() bool
	SetAuthEnabled(bool)
	SetChatEnabled(bool)
	SetIP(string)
	SplitTunnelingEnabled() bool
	SetShowGoogleAds(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
	SetHasConfigFetched(bool)
	SetHasProxyFetched(bool)
	SetUserIdAndToken(int64, string)
	SetOnSuccess(bool)
	ChatEnable() bool

	Wrapped() Session
}

PanickingSession wraps the Session interface but panics instead of returning errors

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 {
	ClientSession
	GetAppName() string
	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
	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
	SetAuthEnabled(bool)
	SetChatEnabled(bool)
	SplitTunnelingEnabled() (bool, error)
	SetShowGoogleAds(bool)
	SetHasConfigFetched(bool)
	SetHasProxyFetched(bool)
	SetUserIdAndToken(int64, string) error
	SetOnSuccess(bool)
	ChatEnable() 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..... percent: Long, remaining: Long, allowed: Long, ttlSeconds: Long Name become part of Objective c so this is important

func (*SessionModel) ChatEnable

func (m *SessionModel) ChatEnable() bool

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) IpAddress

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

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) SetAuthEnabled

func (m *SessionModel) SetAuthEnabled(authEnabled bool)

func (*SessionModel) SetChatEnabled

func (m *SessionModel) SetChatEnabled(chatEnabled bool)

func (*SessionModel) SetCountry

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

func (*SessionModel) SetHasConfigFetched

func (m *SessionModel) SetHasConfigFetched(fetached bool)

func (*SessionModel) SetHasProxyFetched

func (m *SessionModel) SetHasProxyFetched(fetached bool)

func (*SessionModel) SetIP

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

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

func (*SessionModel) SetOnSuccess

func (m *SessionModel) SetOnSuccess(fetached bool)

func (*SessionModel) SetReplicaAddr

func (m *SessionModel) SetReplicaAddr(replicaAddr string)

func (*SessionModel) SetShowGoogleAds

func (m *SessionModel) SetShowGoogleAds(adsEnable bool)

func (*SessionModel) SetStaging

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

func (*SessionModel) SetUserIdAndToken

func (m *SessionModel) SetUserIdAndToken(p1 int64, p2 string) error

Keep name as p1,p2 somehow is conflicting with objective c p1 is userid and p2 is token

func (*SessionModel) SplitTunnelingEnabled

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

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
	DeviceID        string
	Device          string
	Model           string
	OsVersion       string
	PlayVersion     bool
	Lang            string
	TimeZone        string
	Platform        string
	ConfigPath      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 Survey

type Survey 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"`
	ShowPlansScreen *bool   `json:"showPlansScreen,omitempty"`
}

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 SurveyModel

type SurveyModel struct {
	*SessionModel
}

func NewSurveyModel

func NewSurveyModel(session SessionModel) (*SurveyModel, error)

SurveyModel is a custom model derived from the baseModel.

func (SurveyModel) InvokeMethod

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

InvokeMethod handles method invocations on the model.

func (*SurveyModel) IsSurveyAvalible

func (s *SurveyModel) IsSurveyAvalible() (*Survey, error)

IsSurveyAvalible checks if the survey is available for the user.

func (SurveyModel) Name

func (m SurveyModel) Name() string

func (SurveyModel) Subscribe

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

Subscribe subscribes to database changes based on the provided request.

func (SurveyModel) Unsubscribe

func (m SurveyModel) Unsubscribe(path string)

Unsubscribe unsubscribes from database changes using the provided ID.

type SurveyResponse

type SurveyResponse struct {
	DefaultLocale *string           `json:"defaultLocale,omitempty"`
	Surveys       map[string]Survey `json:"surveys,omitempty"`
}

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
ios

Jump to

Keyboard shortcuts

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