mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-14 19:00:50 +01:00
a4826cfb5f
Get static system info once for Windows, Darwin, and Linux nodes This should improve startup and peer authentication times
47 lines
903 B
Go
47 lines
903 B
Go
//go:build (linux && !android) || windows || (darwin && !ios)
|
|
|
|
package system
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/netbirdio/netbird/client/system/detect_cloud"
|
|
"github.com/netbirdio/netbird/client/system/detect_platform"
|
|
)
|
|
|
|
var (
|
|
staticInfo StaticInfo
|
|
once sync.Once
|
|
)
|
|
|
|
func init() {
|
|
go func() {
|
|
_ = updateStaticInfo()
|
|
}()
|
|
}
|
|
|
|
func updateStaticInfo() StaticInfo {
|
|
once.Do(func() {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
wg := sync.WaitGroup{}
|
|
wg.Add(3)
|
|
go func() {
|
|
staticInfo.SystemSerialNumber, staticInfo.SystemProductName, staticInfo.SystemManufacturer = sysInfo()
|
|
wg.Done()
|
|
}()
|
|
go func() {
|
|
staticInfo.Environment.Cloud = detect_cloud.Detect(ctx)
|
|
wg.Done()
|
|
}()
|
|
go func() {
|
|
staticInfo.Environment.Platform = detect_platform.Detect(ctx)
|
|
wg.Done()
|
|
}()
|
|
wg.Wait()
|
|
})
|
|
return staticInfo
|
|
}
|