summaryrefslogtreecommitdiff
path: root/pkg/vpn/bonafide
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2021-12-23 00:43:29 +0100
committerkali kaneko (leap communications) <kali@leap.se>2021-12-23 00:43:40 +0100
commitbddadc7323d6467f5233f26b97652fe671d77eed (patch)
tree7f5aba2a33e852a2be04ff3e6bbd0383376d91f1 /pkg/vpn/bonafide
parentd83fd91d6293386867cc908f05b5f3f4d95a7053 (diff)
[ui] expose bonafide+snowflake bootstrap events
Diffstat (limited to 'pkg/vpn/bonafide')
-rw-r--r--pkg/vpn/bonafide/bonafide.go24
-rw-r--r--pkg/vpn/bonafide/eip_service.go12
-rw-r--r--pkg/vpn/bonafide/gateways.go13
3 files changed, 38 insertions, 11 deletions
diff --git a/pkg/vpn/bonafide/bonafide.go b/pkg/vpn/bonafide/bonafide.go
index 024a7e1..129845f 100644
--- a/pkg/vpn/bonafide/bonafide.go
+++ b/pkg/vpn/bonafide/bonafide.go
@@ -54,6 +54,8 @@ type Bonafide struct {
maxGateways int
auth authentication
token []byte
+ SnowflakeCh chan *snowflake.StatusEvent
+ snowflake bool
}
type openvpnConfig map[string]interface{}
@@ -206,7 +208,6 @@ func (b *Bonafide) GetPemCertificateNoDNS() ([]byte, error) {
return nil, err
}
defer resp.Body.Close()
-
return ioutil.ReadAll(resp.Body)
}
@@ -241,8 +242,18 @@ func (b *Bonafide) getURLNoDNS(object string) string {
}
func (b *Bonafide) maybeInitializeEIP() error {
+ // FIXME - use config/bitmask flag
if os.Getenv("SNOWFLAKE") == "1" {
- snowflake.BootstrapWithSnowflakeProxies()
+ p := strings.ToLower(config.Provider)
+ // FIXME only if progress != 100 %, then just pick files.
+ // we probably need another status watcher internally, to keep track
+ // of whether we need to cancel, or just wait.
+ snowflake.BootstrapWithSnowflakeProxies(p, getAPIAddr(p), b.SnowflakeCh)
+ err := b.parseEipJSONFromFile()
+ if err != nil {
+ return err
+ }
+ b.gateways = newGatewayPool(b.eip)
} else {
if b.eip == nil {
err := b.fetchEipJSON()
@@ -272,11 +283,11 @@ func (b *Bonafide) GetGateways(transport string) ([]Gateway, error) {
if err != nil {
return nil, err
}
+
max := maxGateways
if b.maxGateways != 0 {
max = b.maxGateways
}
-
gws, err := b.gateways.getBest(transport, b.tzOffsetHours, max)
return gws, err
}
@@ -285,6 +296,7 @@ func (b *Bonafide) GetGateways(transport string) ([]Gateway, error) {
// if "any" is provided it will return all gateways for all transports
func (b *Bonafide) GetAllGateways(transport string) ([]Gateway, error) {
err := b.maybeInitializeEIP()
+ // XXX needs to wait for bonafide too
if err != nil {
return nil, err
}
@@ -327,8 +339,10 @@ func (b *Bonafide) GetGatewayByIP(ip string) (Gateway, error) {
}
func (b *Bonafide) fetchGatewaysFromMenshen() error {
- /* FIXME in float deployments, geolocation is served on gemyip.domain/json, with a LE certificate, but in riseup is served behind the api certificate.
- So this is a workaround until we streamline that behavior */
+ /* FIXME in float deployments, geolocation is served on
+ * gemyip.domain/json, with a LE certificate, but in riseup is served
+ * behind the api certificate. So this is a workaround until we
+ * streamline that behavior */
resp, err := b.client.Post(config.GeolocationAPI, "", nil)
if err != nil {
client := &http.Client{}
diff --git a/pkg/vpn/bonafide/eip_service.go b/pkg/vpn/bonafide/eip_service.go
index 1b8dc01..5b4c3df 100644
--- a/pkg/vpn/bonafide/eip_service.go
+++ b/pkg/vpn/bonafide/eip_service.go
@@ -6,6 +6,7 @@ import (
"io"
"log"
"os"
+ "path/filepath"
"strings"
"time"
@@ -148,6 +149,17 @@ func (b *Bonafide) fetchEipJSON() error {
return nil
}
+func (b *Bonafide) parseEipJSONFromFile() error {
+ provider := strings.ToLower(config.Provider)
+ eipFile := filepath.Join(config.Path, provider+"-eip.json")
+ f, err := os.Open(eipFile)
+ if err != nil {
+ return err
+ }
+ b.eip, err = decodeEIP3(f)
+ return err
+}
+
func decodeEIP3(body io.Reader) (*eipService, error) {
var eip eipService
decoder := json.NewDecoder(body)
diff --git a/pkg/vpn/bonafide/gateways.go b/pkg/vpn/bonafide/gateways.go
index c442e72..25ab027 100644
--- a/pkg/vpn/bonafide/gateways.go
+++ b/pkg/vpn/bonafide/gateways.go
@@ -306,16 +306,17 @@ func (p *gatewayPool) getBestLocation(transport string, tz int) string {
}
func (p *gatewayPool) getAll(transport string, tz int) ([]Gateway, error) {
- /*
- if (&gatewayPool{} == p) {
- log.Println("getAll tried to access uninitialized struct")
- return []Gateway{}, nil
- }
- */
+ if (&gatewayPool{} == p) {
+ log.Println("getAll tried to access uninitialized struct")
+ return []Gateway{}, nil
+ }
+ log.Println(">>> in getAll")
+ log.Println("seems to be initialized...")
if p.recommended == nil || len(p.recommended) == 0 {
return p.getGatewaysFromMenshen(transport, 999)
}
+ log.Println(">>> by timezone")
return p.getGatewaysByTimezone(transport, tz, 999)
}