52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package app
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
vpnLocationsCommandTimeout = 7 * time.Second
|
|
vpnLocationsFreshTTL = 10 * time.Minute
|
|
vpnLocationsBackoffMin = 2 * time.Second
|
|
vpnLocationsBackoffMax = 60 * time.Second
|
|
vpnLocationsCachePath = stateDir + "/vpn-locations-cache.json"
|
|
)
|
|
|
|
type vpnLocationItem struct {
|
|
Label string `json:"label"`
|
|
ISO string `json:"iso"`
|
|
Target string `json:"target,omitempty"`
|
|
}
|
|
|
|
type vpnLocationsSnapshot struct {
|
|
Locations []vpnLocationItem `json:"locations"`
|
|
UpdatedAt string `json:"updated_at,omitempty"`
|
|
Stale bool `json:"stale"`
|
|
RefreshInProgress bool `json:"refresh_in_progress"`
|
|
LastError string `json:"last_error,omitempty"`
|
|
NextRetryAt string `json:"next_retry_at,omitempty"`
|
|
}
|
|
|
|
type vpnLocationsCacheDisk struct {
|
|
Locations []vpnLocationItem `json:"locations"`
|
|
UpdatedAt string `json:"updated_at,omitempty"`
|
|
}
|
|
|
|
type vpnLocationsStore struct {
|
|
mu sync.Mutex
|
|
|
|
loaded bool
|
|
|
|
locations []vpnLocationItem
|
|
swr refreshCoordinator
|
|
}
|
|
|
|
var vpnLocationCache = &vpnLocationsStore{
|
|
swr: newRefreshCoordinator(
|
|
vpnLocationsFreshTTL,
|
|
vpnLocationsBackoffMin,
|
|
vpnLocationsBackoffMax,
|
|
),
|
|
}
|