Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update http.RoundTripper used by Auth client #1251

Merged
merged 8 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions desktop/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
"github.com/getlantern/lantern-client/internalsdk/common"
proclient "github.com/getlantern/lantern-client/internalsdk/pro"
"github.com/getlantern/lantern-client/internalsdk/protos"
"github.com/getlantern/lantern-client/internalsdk/webclient"
)

var (
Expand Down Expand Up @@ -164,9 +163,7 @@ func (app *App) Run(ctx context.Context) {
userConfig := func() common.UserConfig {
return settings.UserConfig(app.Settings())
}
proClient := proclient.NewClient(fmt.Sprintf("https://%s", common.ProAPIHost), &webclient.Opts{
UserConfig: userConfig,
})
proClient := proclient.NewClient(fmt.Sprintf("https://%s", common.ProAPIHost), userConfig)
authClient := auth.NewClient(fmt.Sprintf("https://%s", common.DFBaseUrl), userConfig)

app.mu.Lock()
Expand Down
27 changes: 6 additions & 21 deletions internalsdk/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package auth
import (
"context"

"fmt"
"net/http"
"strings"
"time"
Expand All @@ -12,7 +11,6 @@ import (
"github.com/getlantern/golog"

"github.com/getlantern/lantern-client/internalsdk/common"
"github.com/getlantern/lantern-client/internalsdk/pro"
"github.com/getlantern/lantern-client/internalsdk/protos"
"github.com/getlantern/lantern-client/internalsdk/webclient"

Expand Down Expand Up @@ -53,33 +51,20 @@ type AuthClient interface {

// NewClient creates a new instance of AuthClient
func NewClient(baseURL string, userConfig func() common.UserConfig) AuthClient {
// The default http.RoundTripper is ChainedNonPersistent which proxies requests through chained servers
// and does not use keep alive connections. Since no root CA is specified, we do not need to check for an error.

var httpClient *http.Client

if baseURL == fmt.Sprintf("https://%s", common.APIBaseUrl) {
log.Debug("using proxied.Fronted")
//this is ios version
httpClient = &http.Client{
Transport: proxied.Fronted("auth_fronted_roundtrip", 30*time.Second),
}
} else {
log.Debug("using proxied.ChainedNonPersistent")
rt, _ := proxied.ChainedNonPersistent("")
httpClient = pro.NewHTTPClient(rt, 30*time.Second)
}

rc := webclient.NewRESTClient(&webclient.Opts{
BaseURL: baseURL,
OnBeforeRequest: func(client *resty.Client, req *http.Request) error {
prepareUserRequest(req, userConfig())
return nil
},
HttpClient: httpClient,
// The Auth client uses an http.Client that first attempts to connect via chained proxies
// and then falls back to using domain fronting with the custom op name above
HttpClient: &http.Client{
Transport: proxied.ChainedThenFronted(),
Timeout: 30 * time.Second,
},
UserConfig: userConfig,
})

return &authClient{rc}
}

Expand Down
25 changes: 0 additions & 25 deletions internalsdk/pro/http.go

This file was deleted.

31 changes: 15 additions & 16 deletions internalsdk/pro/pro.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,23 @@ type ProClient interface {
}

// NewClient creates a new instance of ProClient
func NewClient(baseURL string, opts *webclient.Opts) ProClient {
if opts.HttpClient == nil {
// The default http.RoundTripper used by the ProClient is ParallelForIdempotent which
// attempts to send requests through both chained and direct fronted routes in parallel
// for HEAD and GET requests and ChainedThenFronted for all others.
opts.HttpClient = NewHTTPClient(proxied.ParallelForIdempotent(), opts.Timeout)
}
if opts.OnBeforeRequest == nil {
opts.OnBeforeRequest = func(client *resty.Client, req *http.Request) error {
prepareProRequest(req, common.ProAPIHost, opts.UserConfig())
return nil
}
}

func NewClient(baseURL string, userConfig func() common.UserConfig) ProClient {
return &proClient{
userConfig: opts.UserConfig,
userConfig: userConfig,
backoffRunner: &backoffRunner{},
RESTClient: webclient.NewRESTClient(opts),
RESTClient: webclient.NewRESTClient(&webclient.Opts{
// The default http.RoundTripper used by the ProClient is ParallelForIdempotent which
// attempts to send requests through both chained and direct fronted routes in parallel
// for HEAD and GET requests and ChainedThenFronted for all others.
HttpClient: &http.Client{
Transport: proxied.ParallelForIdempotent(),
Timeout: 30 * time.Second,
},
OnBeforeRequest: func(client *resty.Client, req *http.Request) error {
prepareProRequest(req, common.ProAPIHost, userConfig())
return nil
},
}),
}
}

Expand Down
115 changes: 0 additions & 115 deletions internalsdk/pro/proxy.go

This file was deleted.

64 changes: 0 additions & 64 deletions internalsdk/pro/proxy_test.go

This file was deleted.

45 changes: 18 additions & 27 deletions internalsdk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/getlantern/lantern-client/internalsdk/common"
"github.com/getlantern/lantern-client/internalsdk/pro"
"github.com/getlantern/lantern-client/internalsdk/protos"
"github.com/getlantern/lantern-client/internalsdk/webclient"
"github.com/getlantern/pathdb"
"golang.org/x/crypto/pbkdf2"
"google.golang.org/protobuf/proto"
Expand All @@ -27,32 +26,24 @@ import (

// createProClient creates a new instance of ProClient with the given client session information
func createProClient(session Session, platform string) pro.ProClient {
dialTimeout := 30 * time.Second
if platform == "ios" {
dialTimeout = 20 * time.Second
}
webclientOpts := &webclient.Opts{
Timeout: dialTimeout,
UserConfig: func() common.UserConfig {
internalHeaders := map[string]string{
common.PlatformHeader: platform,
common.AppVersionHeader: common.ApplicationVersion,
}
deviceID, _ := session.GetDeviceID()
userID, _ := session.GetUserID()
token, _ := session.GetToken()
lang, _ := session.Locale()
return common.NewUserConfig(
common.DefaultAppName,
deviceID,
userID,
token,
internalHeaders,
lang,
)
},
}
return pro.NewClient(fmt.Sprintf("https://%s", common.ProAPIHost), webclientOpts)
return pro.NewClient(fmt.Sprintf("https://%s", common.ProAPIHost), func() common.UserConfig {
internalHeaders := map[string]string{
common.PlatformHeader: platform,
common.AppVersionHeader: common.ApplicationVersion,
}
deviceID, _ := session.GetDeviceID()
userID, _ := session.GetUserID()
token, _ := session.GetToken()
lang, _ := session.Locale()
return common.NewUserConfig(
common.DefaultAppName,
deviceID,
userID,
token,
internalHeaders,
lang,
)
})
}

func BytesToFloat64LittleEndian(b []byte) (float64, error) {
Expand Down
Loading