aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/tunneltracker.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-04-26 20:05:24 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-04-27 08:24:22 +0200
commit3e8cf39903775ecb6b8ebe03d43591453fe3c7d8 (patch)
treed62408b62529d0e18a19866d540c1c87cfa957c1 /ui/tunneltracker.go
parentinstaller: new checksums for working msm (diff)
downloadwireguard-windows-3e8cf39903775ecb6b8ebe03d43591453fe3c7d8.tar.xz
wireguard-windows-3e8cf39903775ecb6b8ebe03d43591453fe3c7d8.zip
ui: simplify everything
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--ui/tunneltracker.go99
1 files changed, 0 insertions, 99 deletions
diff --git a/ui/tunneltracker.go b/ui/tunneltracker.go
deleted file mode 100644
index 73d48538..00000000
--- a/ui/tunneltracker.go
+++ /dev/null
@@ -1,99 +0,0 @@
-/* SPDX-License-Identifier: MIT
- *
- * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
- */
-
-package ui
-
-import (
- "fmt"
-
- "github.com/lxn/walk"
- "golang.zx2c4.com/wireguard/windows/service"
-)
-
-type TunnelTracker struct {
- activeTunnel *service.Tunnel
- activeTunnelChanged walk.EventPublisher
- tunnelChangeCB *service.TunnelChangeCallback
- inTransition bool
-}
-
-func (tt *TunnelTracker) ActiveTunnel() *service.Tunnel {
- return tt.activeTunnel
-}
-
-func (tt *TunnelTracker) ActivateTunnel(tunnel *service.Tunnel) error {
- if tunnel == tt.activeTunnel {
- return nil
- }
-
- if err := tt.DeactivateTunnel(); err != nil {
- return fmt.Errorf("ActivateTunnel: Failed to deactivate tunnel '%s': %v", tunnel.Name, err)
- }
-
- if err := tunnel.Start(); err != nil {
- return fmt.Errorf("ActivateTunnel: Failed to start tunnel '%s': %v", tunnel.Name, err)
- }
-
- return nil
-}
-
-func (tt *TunnelTracker) DeactivateTunnel() error {
- if tt.activeTunnel == nil {
- return nil
- }
-
- state, err := tt.activeTunnel.State()
- if err != nil {
- return fmt.Errorf("DeactivateTunnel: Failed to retrieve state for tunnel %s: %v", tt.activeTunnel.Name, err)
- }
-
- if state == service.TunnelStarted {
- if err := tt.activeTunnel.Stop(); err != nil {
- return fmt.Errorf("DeactivateTunnel: Failed to stop tunnel '%s': %v", tt.activeTunnel.Name, err)
- }
- }
-
- if state == service.TunnelStarted || state == service.TunnelStopping {
- if err := tt.activeTunnel.WaitForStop(); err != nil {
- return fmt.Errorf("DeactivateTunnel: Failed to wait for tunnel '%s' to stop: %v", tt.activeTunnel.Name, err)
- }
- }
-
- return nil
-}
-
-func (tt *TunnelTracker) ActiveTunnelChanged() *walk.Event {
- return tt.activeTunnelChanged.Event()
-}
-
-func (tt *TunnelTracker) InTransition() bool {
- return tt.inTransition
-}
-
-func (tt *TunnelTracker) SetTunnelState(tunnel *service.Tunnel, state service.TunnelState, err error) {
- if err != nil {
- tt.inTransition = false
- }
-
- switch state {
- case service.TunnelStarted:
- tt.inTransition = false
- tt.activeTunnel = tunnel
-
- case service.TunnelStarting, service.TunnelStopping:
- tt.inTransition = true
-
- case service.TunnelStopped:
- if tt.activeTunnel != nil && tt.activeTunnel.Name == tunnel.Name {
- tt.inTransition = false
- }
- tt.activeTunnel = nil
-
- default:
- return
- }
-
- tt.activeTunnelChanged.Publish()
-}