mirror of
https://github.com/netbirdio/netbird.git
synced 2026-07-16 19:49:56 +00:00
- **Wails v3 application** (`client/ui`) with a React + TypeScript + Tailwind frontend replacing the Fyne UI: main connection view, exit-node switcher, networks/peers browser with detail panels, profile management, settings (general, network, SSH, security, troubleshooting, appearance), debug-bundle creation, and a first-run welcome flow. - **Internationalization**: go-i18n bundle with 9 locales (en, de, es, fr, hu, it, pt, ru, zh-CN) shared between the tray and the frontend. - **New system tray** implementation with per-platform theme-aware icons, including a native XEmbed host for Linux (`xembed_tray_linux.c`) and a Linux theme watcher. - **Session handling**: auth session watcher (`client/internal/auth/sessionwatch`), pending login flow, session-expiration dialog and tray notifications, and `netbird login` improvements. - **Daemon API extensions** (`daemon.proto`): status stream subscription, event stream, networks/exit-node selection endpoints, and richer full status — with probe throttling on the daemon side to protect against UI-driven request storms. - **UI preferences store** persisted per profile, autostart management via the daemon (single source of truth in HKCU on Windows). - **Build system**: Taskfile-based builds per platform (macOS, Linux, Windows), Docker cross-compilation images, MSIX/NSIS/nfpm/AppImage packaging, and a new `frontend-ui` CI workflow. Co-authored-by: Zoltan Papp <zoltan.pmail@gmail.com> Co-authored-by: Eduard Gert <kontakt@eduardgert.de> Co-authored-by: braginini <bangvalo@gmail.com> Co-authored-by: Pascal Fischer <32096965+pascal-fischer@users.noreply.github.com> Co-authored-by: riccardom <riccardomanfrin@gmail.com>
89 lines
3.5 KiB
Go
89 lines
3.5 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
"time"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// healthProbeRunner runs the full, expensive probe (network round-trips to
|
|
// management, signal and the relays) and reports whether every component was
|
|
// healthy. ctx cancels the probe when the caller gives up. Satisfied by
|
|
// *internal.Engine.
|
|
type healthProbeRunner interface {
|
|
RunHealthProbes(ctx context.Context, waitForResult bool) bool
|
|
}
|
|
|
|
// statsRefresher does the cheap WireGuard-stats refresh callers fall back to
|
|
// when a fresh probe isn't warranted. Satisfied by *peer.Status.
|
|
type statsRefresher interface {
|
|
RefreshWireGuardStats() error
|
|
}
|
|
|
|
// probeThrottle rate-limits and single-flights the daemon's health probes.
|
|
//
|
|
// Health probes are expensive (network round-trips to management, signal and
|
|
// the relays), while Status(GetFullPeerStatus=true) RPCs can arrive frequently
|
|
// and concurrently — the desktop UI alone issues one per connect/disconnect.
|
|
// probeThrottle keeps that load bounded with two rules:
|
|
//
|
|
// - Single-flight: only one probe runs at a time. Callers that pile up while
|
|
// a probe is in flight share its result instead of each launching another,
|
|
// even when that probe failed. A failed probe therefore does not make every
|
|
// waiter re-probe in turn; the next, non-overlapping caller can try again.
|
|
// - Throttle: after a fully successful probe the result is cached for
|
|
// interval. While any component is unhealthy the cache is not advanced, so
|
|
// later callers keep probing frequently and notice recovery quickly — the
|
|
// intentional "probe often while unhealthy" behaviour from the original
|
|
// design.
|
|
type probeThrottle struct {
|
|
interval time.Duration
|
|
|
|
mu sync.Mutex
|
|
lastOK time.Time // last fully-successful probe; drives the throttle window
|
|
completedAt time.Time // when the most recent probe finished; drives single-flight sharing
|
|
}
|
|
|
|
func newProbeThrottle(interval time.Duration) *probeThrottle {
|
|
return &probeThrottle{interval: interval}
|
|
}
|
|
|
|
// Run decides whether to run a fresh health probe or serve the most recent
|
|
// result. It serialises concurrent callers: at most one runner.RunHealthProbes
|
|
// executes at a time and the rest call refresher.RefreshWireGuardStats and read
|
|
// the snapshot it produced.
|
|
//
|
|
// Both calls run while the throttle's lock is held, so a slow probe blocks
|
|
// other callers until it completes — that blocking is the single-flight
|
|
// guarantee. ctx is forwarded to RunHealthProbes so a caller that gives up
|
|
// cancels the in-flight probe (and any caller still queued on the lock falls
|
|
// through quickly once it acquires it, since the probe ctx is already done).
|
|
func (t *probeThrottle) Run(ctx context.Context, runner healthProbeRunner, refresher statsRefresher, waitForResult bool) {
|
|
entered := time.Now()
|
|
|
|
t.mu.Lock()
|
|
defer t.mu.Unlock()
|
|
|
|
// A probe that finished after we entered ran while we were waiting on the
|
|
// lock — i.e. a peer in the same burst already probed for us, so share its
|
|
// result rather than launch another. This holds even when that probe
|
|
// failed, so a failed probe doesn't make every waiter re-probe in turn.
|
|
sharedRecentProbe := t.completedAt.After(entered)
|
|
throttled := time.Since(t.lastOK) <= t.interval
|
|
|
|
if sharedRecentProbe || throttled {
|
|
if err := refresher.RefreshWireGuardStats(); err != nil {
|
|
log.Debugf("failed to refresh WireGuard stats: %v", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
healthy := runner.RunHealthProbes(ctx, waitForResult)
|
|
t.completedAt = time.Now()
|
|
if healthy {
|
|
t.lastOK = t.completedAt
|
|
}
|
|
}
|