chore(all): memory and thread safe storage

- settings: get filter choices from storage for settings validation
- updater: update servers to the storage
- storage: minimal deep copying and data duplication
- storage: add merged servers mutex for thread safety
- connection: filter servers in storage
- formatter: format servers to Markdown in storage
- PIA: get server by name from storage directly
- Updater: get servers count from storage directly
- Updater: equality check done in storage, fix #882
This commit is contained in:
Quentin McGaw
2022-06-05 14:58:46 +00:00
parent 1e6b4ed5eb
commit 36b504609b
84 changed files with 1267 additions and 877 deletions

View File

@@ -27,12 +27,12 @@ type Looper interface {
loopstate.Getter
loopstate.Applier
SettingsGetSetter
ServersGetterSetter
}
type Loop struct {
statusManager loopstate.Manager
state state.Manager
storage Storage
// Fixed parameters
buildInfo models.BuildInformation
versionInfo bool
@@ -64,12 +64,17 @@ type firewallConfigurer interface {
firewall.PortAllower
}
type Storage interface {
FilterServers(provider string, selection settings.ServerSelection) (servers []models.Server, err error)
GetServerByName(provider, name string) (server models.Server, ok bool)
}
const (
defaultBackoffTime = 15 * time.Second
)
func NewLoop(vpnSettings settings.VPN, vpnInputPorts []uint16,
allServers models.AllServers, openvpnConf openvpn.Interface,
storage Storage, openvpnConf openvpn.Interface,
netLinker netlink.NetLinker, fw firewallConfigurer, routing routing.VPNGetter,
portForward portforward.StartStopper, starter command.Starter,
publicip publicip.Looper, dnsLooper dns.Looper,
@@ -81,11 +86,12 @@ func NewLoop(vpnSettings settings.VPN, vpnInputPorts []uint16,
stopped := make(chan struct{})
statusManager := loopstate.New(constants.Stopped, start, running, stop, stopped)
state := state.New(statusManager, vpnSettings, allServers)
state := state.New(statusManager, vpnSettings)
return &Loop{
statusManager: statusManager,
state: state,
storage: storage,
buildInfo: buildInfo,
versionInfo: versionInfo,
vpnInputPorts: vpnInputPorts,