Skip to content

Commit

Permalink
Merge pull request #1396 from getlantern/feat/154
Browse files Browse the repository at this point in the history
Adding SNI config support
  • Loading branch information
WendelHime authored Aug 5, 2024
2 parents a082d34 + 6d1f124 commit 45fabba
Show file tree
Hide file tree
Showing 6 changed files with 7,244 additions and 2 deletions.
17 changes: 16 additions & 1 deletion config/client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"errors"

"github.com/getlantern/flashlight/v7/geolookup"
"github.com/getlantern/fronted"
)

Expand Down Expand Up @@ -40,6 +41,7 @@ type ProviderConfig struct {
Masquerades []*fronted.Masquerade
Validator *ValidatorConfig
PassthroughPatterns []string
FrontingSNIs map[string]*fronted.SNIConfig
}

// returns a fronted.ResponseValidator specified by the
Expand Down Expand Up @@ -80,15 +82,28 @@ func NewClientConfig() *ClientConfig {

// Builds a list of fronted.Providers to use based on the configuration
func (c *ClientConfig) FrontedProviders() map[string]*fronted.Provider {

sniRegion := geolookup.GetCountry(0)
providers := make(map[string]*fronted.Provider)
for pid, p := range c.Fronted.Providers {
var sniConfig *fronted.SNIConfig
if p.FrontingSNIs != nil {
sniConfig, ok := p.FrontingSNIs[sniRegion]
if !ok {
sniConfig = p.FrontingSNIs["default"]
}

if sniConfig != nil && sniConfig.UseArbitrarySNIs && len(sniConfig.ArbitrarySNIs) == 0 {
sniConfig.ArbitrarySNIs = p.FrontingSNIs["default"].ArbitrarySNIs
}
}

providers[pid] = fronted.NewProvider(
p.HostAliases,
p.TestURL,
p.Masquerades,
p.GetResponseValidator(pid),
p.PassthroughPatterns,
sniConfig,
)
}
return providers
Expand Down
2 changes: 2 additions & 0 deletions config/embedded_global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func TestEmbeddedGlobal(t *testing.T) {
assert.NoError(t, err)

gl := global.(*Global)
assert.False(t, gl.Client.Fronted.Providers["akamai"].FrontingSNIs["default"].UseArbitrarySNIs)
assert.NotEmpty(t, gl.Client.Fronted.Providers["akamai"].FrontingSNIs["default"].ArbitrarySNIs)
assert.True(t, len(gl.Client.Fronted.Providers["akamai"].Masquerades) > 20)
assert.True(t, len(gl.Client.Fronted.Providers["cloudfront"].Masquerades) > 20)
assert.Containsf(t, gl.Client.Fronted.Providers["cloudfront"].HostAliases, "replica-search.lantern.io", "embedded global config does not contain replica-search cloudfront fronted provider")
Expand Down
Loading

0 comments on commit 45fabba

Please sign in to comment.