diff --git a/pkg/vpn/bitmask.go b/pkg/vpn/bitmask.go index eb5a9dcfe2d0d9b3cd09e9953f9a804d26e16b5f..617a0b80432e79280cb9119c0e3fecebaf83bb56 100644 --- a/pkg/vpn/bitmask.go +++ b/pkg/vpn/bitmask.go @@ -136,6 +136,25 @@ func Init() (*Bitmask, error) { } */ + if config.ApiVersion == 5 && len(config.STUNServers) != 0 { + /* + Geolocation lookup should be done only once during startup. Changing the country + code during runtime is not supported. The VPN must be turn off for the lookup. + If the lookup succeeds, we save it in the config file and use it as fallback + the next time. + */ + countryCode, err := b.api.DoGeolocationLookup() + if err == nil { + log.Debug(). + Str("countryCode", countryCode). + Msg("Successfully got country code") + } else { + log.Warn(). + Str("err", err.Error()). + Msgf("Could not do geolocation lookup") + } + } + go b.fetchGateways() go b.initOpenVPNManagementHandler() diff --git a/pkg/vpn/bonafide/bonafide.go b/pkg/vpn/bonafide/bonafide.go index b055332b57923f7b38e50612162403ee775d047f..c3cdff709900c9e0229cb565f154a627b123f541 100644 --- a/pkg/vpn/bonafide/bonafide.go +++ b/pkg/vpn/bonafide/bonafide.go @@ -392,3 +392,7 @@ func (b *Bonafide) GetOpenvpnArgs() ([]string, error) { func (b *Bonafide) GetSnowflakeCh() chan *snowflake.StatusEvent { return b.snowflakeCh } + +func (b *Bonafide) DoGeolocationLookup() (string, error) { + return "", errors.New("DoGeolocationLookup is not supported in v3 (only implemented in bitmask-core)") +} diff --git a/pkg/vpn/interface.go b/pkg/vpn/interface.go index e4408b601471b02cee0fa339137e167787ad57ae..fce11fd237b1703081beff04399e2f3a1dcd7068 100644 --- a/pkg/vpn/interface.go +++ b/pkg/vpn/interface.go @@ -21,4 +21,5 @@ type apiInterface interface { GetBestGateways(transport string) ([]bonafide.Gateway, error) FetchAllGateways(transport string) error GetSnowflakeCh() chan *snowflake.StatusEvent + DoGeolocationLookup() (string, error) } diff --git a/pkg/vpn/menshen/init.go b/pkg/vpn/menshen/init.go index dc85574ffe10e85fbaa6dd8b67a73d49a942c538..809aafa38985411bb1f9a88b9ad8cc272dde22e6 100644 --- a/pkg/vpn/menshen/init.go +++ b/pkg/vpn/menshen/init.go @@ -140,3 +140,7 @@ func (m *Menshen) NeedsCredentials() bool { func (m *Menshen) GetSnowflakeCh() chan *snowflake.StatusEvent { return nil } + +func (m *Menshen) DoGeolocationLookup() (string, error) { + return m.api.DoGeolocationLookup() +}