summaryrefslogtreecommitdiff
path: root/internal/discovery/manager.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/discovery/manager.go')
-rw-r--r--internal/discovery/manager.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/internal/discovery/manager.go b/internal/discovery/manager.go
index e71f13a..6a78486 100644
--- a/internal/discovery/manager.go
+++ b/internal/discovery/manager.go
@@ -7,6 +7,8 @@ import (
"codeberg.org/eduVPN/eduvpn-common/internal/log"
)
+// Manager is the discovery struct that is cached
+// with some bookkeeping to avoid race conditions
type Manager struct {
disco *Discovery
@@ -15,6 +17,7 @@ type Manager struct {
wait sync.WaitGroup
}
+// NewManager creates a new Discovery manager
func NewManager(disco *Discovery) *Manager {
return &Manager{disco: disco}
}
@@ -35,6 +38,8 @@ func (m *Manager) unlock(write bool) {
m.mu.RUnlock()
}
+// Discovery gets the cached discovery
+// `write` is true if discovery will be written to
func (m *Manager) Discovery(write bool) (*Discovery, func()) {
if write {
m.wait.Wait()
@@ -45,6 +50,7 @@ func (m *Manager) Discovery(write bool) (*Discovery, func()) {
}
}
+// Cancel aborts the running discovery startup process
func (m *Manager) Cancel() {
if m.cancel != nil {
m.cancel()
@@ -52,6 +58,8 @@ func (m *Manager) Cancel() {
m.wait.Wait()
}
+// Startup handles the discovery process in the background
+// It's called Startup because it's called when the lib is initialised
func (m *Manager) Startup(ctx context.Context, cb func()) {
ctx, cancel := context.WithCancel(ctx)
m.cancel = cancel