summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-02-11 13:58:50 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-05 12:26:10 +0200
commit12a0a2700d64f99b8f14d03c8de1c1ea5e922eff (patch)
treedfc59a5d11d407b2ec91bf9e7987835f16e62458
parent03649c96c57e1bc6db026871489c02d4937f0439 (diff)
Begin exposing functions using a map
Signed-off-by: jwijenbergh <jeroenwijenbergh@protonmail.com>
-rw-r--r--exports/Makefile2
-rw-r--r--exports/exports.go13
-rw-r--r--src/server.go30
-rw-r--r--wrappers/python/eduvpncommon/discovery.py1
4 files changed, 39 insertions, 7 deletions
diff --git a/exports/Makefile b/exports/Makefile
index a23f211..86dbec2 100644
--- a/exports/Makefile
+++ b/exports/Makefile
@@ -16,7 +16,7 @@ endif
# Build shared library and remove lib prefix (if any) from header name
# GOOS and GOARCH envvars are set by common.mk
# This extra target prevents unnecessary rebuild
-lib/$(GOOS)/$(GOARCH)/$(LIB_FILE): exports.go ../src/verify.go
+lib/$(GOOS)/$(GOARCH)/$(LIB_FILE): exports.go ../src/*.go
CGO_ENABLED=1 go build -o $@ -buildmode=c-shared $<
mv lib/$(GOOS)/$(GOARCH)/$(LIB_PREFIX)$(LIB_NAME).h lib/$(GOOS)/$(GOARCH)/$(LIB_NAME).h || true # Normalize header name
diff --git a/exports/exports.go b/exports/exports.go
index 9ea8cba..43dfb9e 100644
--- a/exports/exports.go
+++ b/exports/exports.go
@@ -5,6 +5,19 @@ import "C"
import "github.com/jwijenbergh/eduvpn-common/src"
// Functions here should probably not take string parameters, see https://pkg.go.dev/cmd/cgo#hdr-C_references_to_Go
+// GetOrganizationsList gets the list of organizations from the disco server.
+// Returns the unix timestamp of the data. This is used as key for looking up data.
+//export GetOrganizationsList
+func GetOrganizationsList() uint64 {
+ return eduvpn.GetOrganizationsList()
+}
+
+// GetServerList gets the list of servers from the disco server.
+// Returns the unix timestamp of the data. This is used as key for looking up data.
+//export GetServerList
+func GetServerList() uint64 {
+ return eduvpn.GetServerList()
+}
// Verify verifies a signature on a JSON file. See eduvpn.Verify for more details.
// It returns 0 for a valid signature and a nonzero eduvpn.VerifyErrorCode otherwise.
diff --git a/src/server.go b/src/server.go
index 314ceae..87b9672 100644
--- a/src/server.go
+++ b/src/server.go
@@ -10,7 +10,7 @@ import (
// Struct that defines the json format for
// url: "https://disco.eduvpn.org/v2/organization_list.json"
type organizations struct {
- v string `json:"v"`
+ V uint64 `json:"v"`
OrganizationList []struct {
DisplayName struct {
En string `json:"en"`
@@ -26,7 +26,7 @@ type organizations struct {
// Struct that defines the json format for
// url: "https://disco.eduvpn.org/v2/server_list.json"
type servers struct {
- v string `json:"v"`
+ V uint64 `json:"v"`
ServerList []struct {
BaseUrl string `json:"base_url"`
CountryCode string `json:"country_code"`
@@ -101,14 +101,32 @@ func getDiscoJson(jsonFile string, structure interface{}) bool {
return true
}
+// Global maps that are used for storing info
+var organizationsMap = map[uint64]organizations{}
+var serversMap = map[uint64]servers{}
+
// Get the organization list
-func GetOrganizationList() bool {
+// Returns the unix timestamp of the data
+func GetOrganizationsList() uint64 {
organizations := organizations{}
- return getDiscoJson("organization_list.json", &organizations)
+ success := getDiscoJson("organization_list.json", &organizations)
+
+ if success {
+ organizationsMap[organizations.V] = organizations
+ }
+
+ return organizations.V
}
// Get the server list
-func GetServerList() bool {
+// Return the unix timestamp of the data
+func GetServerList() uint64 {
servers := servers{}
- return getDiscoJson("server_list.json", &servers)
+ success := getDiscoJson("server_list.json", &servers)
+
+ if success {
+ serversMap[servers.V] = servers
+ }
+
+ return servers.V
}
diff --git a/wrappers/python/eduvpncommon/discovery.py b/wrappers/python/eduvpncommon/discovery.py
index 371bd71..79a3ee9 100644
--- a/wrappers/python/eduvpncommon/discovery.py
+++ b/wrappers/python/eduvpncommon/discovery.py
@@ -2,6 +2,7 @@ from . import lib, GoSlice
from ctypes import *
from enum import Enum
+lib.GetOrganizationsList.argtypes, lib.GetOrganizationsList.restype = [], c_uint64
lib.Verify.argtypes, lib.Verify.restype = [GoSlice, GoSlice, GoSlice, c_uint64], c_int64
lib.InsecureTestingSetExtraKey.argtypes, lib.InsecureTestingSetExtraKey.restype = [GoSlice], None