From c7148d9559dab0e1cdbc6dd5306a3c852615560e Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Mon, 29 Nov 2021 18:09:24 +0100 Subject: [feat] hook snowflake on bootstrap --- pkg/vpn/bonafide/bonafide.go | 26 ++++++++++++++++---------- pkg/vpn/bonafide/gateways.go | 9 ++++++++- 2 files changed, 24 insertions(+), 11 deletions(-) (limited to 'pkg/vpn') diff --git a/pkg/vpn/bonafide/bonafide.go b/pkg/vpn/bonafide/bonafide.go index b4e6af0..907bba5 100644 --- a/pkg/vpn/bonafide/bonafide.go +++ b/pkg/vpn/bonafide/bonafide.go @@ -25,10 +25,12 @@ import ( "io/ioutil" "log" "net/http" + "os" "strings" "time" "0xacab.org/leap/bitmask-vpn/pkg/config" + "0xacab.org/leap/bitmask-vpn/pkg/snowflake" ) const ( @@ -234,18 +236,22 @@ func (b *Bonafide) getURLNoDNS(object string) string { } func (b *Bonafide) maybeInitializeEIP() error { - if b.eip == nil { - err := b.fetchEipJSON() - if err != nil { - return err + if os.Getenv("SNOWFLAKE") == "1" { + snowflake.BootstrapWithSnowflakeProxies() + } else { + if b.eip == nil { + err := b.fetchEipJSON() + if err != nil { + return err + } + b.gateways = newGatewayPool(b.eip) } - b.gateways = newGatewayPool(b.eip) - } - // FIXME: let's update the menshen gateways every time we 'maybe initilize EIP' - // in a future we might want to be more clever on when to do that - // (when opening the locations tab in the UI, only on reconnects, ...) - b.fetchGatewaysFromMenshen() + // FIXME: let's update the menshen gateways every time we 'maybe initilize EIP' + // in a future we might want to be more clever on when to do that + // (when opening the locations tab in the UI, only on reconnects, ...) + b.fetchGatewaysFromMenshen() + } return nil } diff --git a/pkg/vpn/bonafide/gateways.go b/pkg/vpn/bonafide/gateways.go index 633493e..c442e72 100644 --- a/pkg/vpn/bonafide/gateways.go +++ b/pkg/vpn/bonafide/gateways.go @@ -306,7 +306,14 @@ func (p *gatewayPool) getBestLocation(transport string, tz int) string { } func (p *gatewayPool) getAll(transport string, tz int) ([]Gateway, error) { - if len(p.recommended) != 0 { + /* + if (&gatewayPool{} == p) { + log.Println("getAll tried to access uninitialized struct") + return []Gateway{}, nil + } + */ + + if p.recommended == nil || len(p.recommended) == 0 { return p.getGatewaysFromMenshen(transport, 999) } return p.getGatewaysByTimezone(transport, tz, 999) -- cgit v1.2.3