Skip to content
New issue

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

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

Already on GitHub? # to your account

Use new Lantern Cloud domain for domain fronting, ensure appropriate requests are fronted #1191

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 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
3 changes: 1 addition & 2 deletions desktop/app/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package app
import (
"context"
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
"net/url"
Expand Down Expand Up @@ -200,7 +199,7 @@ func startApp(t *testing.T, helper *integrationtest.Helper) (*App, error) {
return settings.UserConfig(ss)
},
}
proClient := pro.NewClient(fmt.Sprintf("https://%s", common.ProAPIHost), webclientOpts)
proClient := pro.NewClient(ProAPIBaseURL, webclientOpts)

a := NewApp(flags, helper.ConfigDir, proClient, ss)
id := ss.GetUserID()
Expand Down
7 changes: 4 additions & 3 deletions desktop/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"strings"
"time"

"github.com/joho/godotenv"

"github.com/getlantern/appdir"
"github.com/getlantern/errors"
"github.com/getlantern/flashlight/v7"
Expand All @@ -31,7 +33,6 @@ import (
"github.com/getlantern/lantern-client/internalsdk/protos"
"github.com/getlantern/lantern-client/internalsdk/webclient"
"github.com/getlantern/osversion"
"github.com/joho/godotenv"
)

import "C"
Expand Down Expand Up @@ -67,10 +68,10 @@ func init() {
userConfig := func() common.UserConfig {
return settings.UserConfig(ss)
}
proClient = proclient.NewClient(fmt.Sprintf("https://%s", common.ProAPIHost), &webclient.Opts{
proClient = proclient.NewClient(common.ProAPIBaseURL, &webclient.Opts{
UserConfig: userConfig,
})
authClient = auth.NewClient(fmt.Sprintf("https://%s", common.DFBaseUrl), userConfig)
authClient = auth.NewClient(fmt.Sprintf("https://%s", common.APIBaseURL), userConfig)

a = app.NewApp(flags, cdir, proClient, ss)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require (
github.com/getlantern/eventual v1.0.0
github.com/getlantern/eventual/v2 v2.0.2
github.com/getlantern/filepersist v0.0.0-20210901195658-ed29a1cb0b7c
github.com/getlantern/flashlight/v7 v7.6.111
github.com/getlantern/flashlight/v7 v7.6.112-0.20240929144745-72a54c5a4e73
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This includes changes from the unmerged flashlight counterpart: getlantern/flashlight#1416

When I've tested these changes thoroughly, I will merge the flashlight PR in and update this reference.

github.com/getlantern/fronted v0.0.0-20240822220559-6e97652d23cc
github.com/getlantern/golog v0.0.0-20230503153817-8e72de7e0a65
github.com/getlantern/hidden v0.0.0-20220104173330-f221c5a24770
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ github.com/getlantern/fdcount v0.0.0-20210503151800-5decd65b3731/go.mod h1:XZwE+
github.com/getlantern/filepersist v0.0.0-20160317154340-c5f0cd24e799/go.mod h1:8DGAx0LNUfXNnEH+fXI0s3OCBA/351kZCiz/8YSK3i8=
github.com/getlantern/filepersist v0.0.0-20210901195658-ed29a1cb0b7c h1:mcz27xtAkb1OuOLBct/uFfL1p3XxAIcFct82GbT+UZM=
github.com/getlantern/filepersist v0.0.0-20210901195658-ed29a1cb0b7c/go.mod h1:8DGAx0LNUfXNnEH+fXI0s3OCBA/351kZCiz/8YSK3i8=
github.com/getlantern/flashlight/v7 v7.6.111 h1:v+HPV34U5OrCYe7K+iKln2eTXo4MjyQOp0M5+Exfev8=
github.com/getlantern/flashlight/v7 v7.6.111/go.mod h1:M7KG4/LELzZkk6FiFxucmk0rirlQwD785Y0ee5RyiOM=
github.com/getlantern/flashlight/v7 v7.6.112-0.20240929144745-72a54c5a4e73 h1:esX0xv38MqWiHc5oHo4Nc49jHM0PEfiPwSoqw3H0BPY=
github.com/getlantern/flashlight/v7 v7.6.112-0.20240929144745-72a54c5a4e73/go.mod h1:M7KG4/LELzZkk6FiFxucmk0rirlQwD785Y0ee5RyiOM=
github.com/getlantern/framed v0.0.0-20190601192238-ceb6431eeede h1:yrU6Px3ZkvCsDLPryPGi6FN+2iqFPq+JeCb7EFoDBhw=
github.com/getlantern/framed v0.0.0-20190601192238-ceb6431eeede/go.mod h1:nhnoiS6DE6zfe+BaCMU4YI01UpsuiXnDqM5S8jxHuuI=
github.com/getlantern/fronted v0.0.0-20240822220559-6e97652d23cc h1:rVEoCLKM16Pfnz8CguT4U75m6o0QDN7stP+MBFUkmNk=
Expand Down
22 changes: 4 additions & 18 deletions internalsdk/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ package auth

import (
"context"
"time"

"fmt"
"net/http"
"strings"
"time"

"github.com/getlantern/flashlight/v7/proxied"
"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 @@ -52,21 +50,9 @@ 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(30 * time.Second),
}
} else {
log.Debug("using proxied.ChainedNonPersistent")
rt, _ := proxied.ChainedNonPersistent("")
httpClient = pro.NewHTTPClient(rt, 30*time.Second)
httpClient := &http.Client{
Transport: proxied.ChainedThenFronted(),
Timeout: 30 * time.Second,
}

rc := webclient.NewRESTClient(&webclient.Opts{
Expand Down
14 changes: 8 additions & 6 deletions internalsdk/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ var (
// 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"
// ProAPIBaseURL is the URL for all requests to the back-end pro server. Paths at this URL can
// be hit directly (not recommended due to censorship), through proxies, or through domain
// fronting.
ProAPIBaseURL = "df.iantem.io/api/pro-server"

DFBaseUrl = "df.iantem.io/api/v1"
APIBaseUrl = "iantem.io/api/v1"
// APIBaseURL is the URL for all requests to the back-end "API service". Paths at this URL can
// be hit directly (not recommended due to censorship), through proxies, or through domain
// fronting.
APIBaseURL = "df.iantem.io/api/v1"

log = golog.LoggerFor("flashlight.common")

Expand All @@ -63,9 +68,6 @@ func ForceStaging() {
func initInternal() {
isStaging := IsStagingEnvironment()
log.Debugf("****************************** stagingMode: %v", isStaging)
if isStaging {
ProAPIHost = "api-staging.getiantem.org"
}
forceAds, _ = strconv.ParseBool(os.Getenv("FORCEADS"))
}

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

This file was deleted.

26 changes: 18 additions & 8 deletions internalsdk/pro/pro.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import (
"fmt"
"net/http"
"strings"
"time"

"github.com/go-resty/resty/v2"

"github.com/getlantern/errors"
"github.com/getlantern/flashlight/v7/proxied"
"github.com/getlantern/golog"
"github.com/getlantern/lantern-client/internalsdk/common"
"github.com/getlantern/lantern-client/internalsdk/protos"
"github.com/getlantern/lantern-client/internalsdk/webclient"
"github.com/go-resty/resty/v2"

"github.com/leekchan/accounting"
"github.com/shopspring/decimal"
Expand Down Expand Up @@ -57,29 +59,37 @@ 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)
opts.HttpClient = &http.Client{
// 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.
Transport: proxied.ParallelForIdempotent(),
Timeout: 30 * time.Second,
}
}

if opts.OnBeforeRequest == nil {
opts.OnBeforeRequest = func(client *resty.Client, req *http.Request) error {
prepareProRequest(req, common.ProAPIHost, opts.UserConfig())
prepareProRequest(req, opts.UserConfig())
return nil
}
}

if opts.BaseURL == "" {
opts.BaseURL = baseURL
}

return &proClient{
userConfig: opts.UserConfig,
RESTClient: webclient.NewRESTClient(opts),
}
}

// prepareProRequest normalizes requests to the pro server with device ID, user ID, etc set.
func prepareProRequest(r *http.Request, proAPIHost string, userConfig common.UserConfig) {
func prepareProRequest(r *http.Request, userConfig common.UserConfig) {
if r.URL.Scheme == "" {
r.URL.Scheme = "http"
}
r.URL.Host = proAPIHost
r.RequestURI = "" // http: Request.RequestURI can't be set in client requests.
r.Header.Set("Access-Control-Allow-Headers", strings.Join([]string{
common.DeviceIdHeader,
Expand Down
2 changes: 1 addition & 1 deletion internalsdk/pro/pro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ package pro
// },
// }

// proClient := NewClient(fmt.Sprintf("https://%s", common.ProAPIHost), webclientOpts)
// proClient := NewClient(common.ProAPIBaseURL, webclientOpts)

// puchaseData := map[string]interface{}{
// "idempotencyKey": strconv.FormatInt(time.Now().UnixNano(), 10),
Expand Down
115 changes: 0 additions & 115 deletions internalsdk/pro/proxy.go

This file was deleted.

Loading
Loading