diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2024-07-10 14:39:34 +0200 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2024-07-17 14:00:03 +0000 |
| commit | a1879195a727d7b90347ed11f86d85fac6541df7 (patch) | |
| tree | ef19423671009552181f759b4a9162e7d91bf82a /exports/exports.go | |
| parent | 7f8af5845ddec1816f93a2cb013f0818c19caab3 (diff) | |
Client + Discovery: Fetch dscovery at startup using DiscoveryStartup
With a manager that locks and copies such that no race conditions happen
Diffstat (limited to 'exports/exports.go')
| -rw-r--r-- | exports/exports.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/exports/exports.go b/exports/exports.go index 1e496f8..36372b4 100644 --- a/exports/exports.go +++ b/exports/exports.go @@ -21,6 +21,7 @@ typedef long long int (*ReadRxBytes)(); typedef int (*StateCB)(int oldstate, int newstate, void* data); +typedef void (*RefreshList)(); typedef void (*TokenGetter)(const char* server_id, int server_type, char* out, size_t len); typedef void (*TokenSetter)(const char* server_id, int server_type, const char* tokens); typedef void (*ProxySetup)(int fd, const char* peer_ips); @@ -34,6 +35,10 @@ static int call_callback(StateCB callback, int oldstate, int newstate, void* dat { return callback(oldstate, newstate, data); } +static void call_refresh_list(RefreshList refresh) +{ + refresh(); +} static void call_token_getter(TokenGetter getter, const char* server_id, int server_type, char* out, size_t len) { getter(server_id, server_type, out, len); @@ -1024,6 +1029,28 @@ func getCookie(c C.uintptr_t) (*cookie.Cookie, error) { return v, nil } + +// DiscoveryStartup does a discovery request in the background +// +// The `refresh` argument is a callback that is called when the refreshing is done +// When this callback is thus called, the app SHOULD refresh the server list of the already configured servers +// This DiscoveryStartup function MUST be called after calling `Register` +// +//export DiscoveryStartup +func DiscoveryStartup(refresh C.RefreshList) *C.char { + state, stateErr := getVPNState() + if stateErr != nil { + return getCError(stateErr) + } + state.DiscoveryStartup(func() { + if refresh == nil { + return + } + C.call_refresh_list(refresh) + }) + return nil +} + // SetTokenHandler sets the token getters and token setters for OAuth // // Because the data that is saved does not contain OAuth tokens for server, the common lib asks and sets the tokens using these callback functions. |
