mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 16:26:38 +00:00
fix convert fullStatus to statusOutput & add logFile
This commit is contained in:
@@ -308,7 +308,7 @@ func getStatusOutput(cmd *cobra.Command, anon bool) string {
|
|||||||
cmd.PrintErrf("Failed to get status: %v\n", err)
|
cmd.PrintErrf("Failed to get status: %v\n", err)
|
||||||
} else {
|
} else {
|
||||||
statusOutputString = nbstatus.ParseToFullDetailSummary(
|
statusOutputString = nbstatus.ParseToFullDetailSummary(
|
||||||
nbstatus.ConvertToStatusOutputOverview(statusResp, anon, "", nil, nil, nil, "", ""),
|
nbstatus.ConvertToStatusOutputOverview(statusResp.GetFullStatus(), anon, statusResp.GetDaemonVersion(), "", nil, nil, nil, "", ""),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return statusOutputString
|
return statusOutputString
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ func statusFunc(cmd *cobra.Command, args []string) error {
|
|||||||
profName = activeProf.Name
|
profName = activeProf.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
var outputInformationHolder = nbstatus.ConvertToStatusOutputOverview(resp, anonymizeFlag, statusFilter, prefixNamesFilter, prefixNamesFilterMap, ipsFilterMap, connectionTypeFilter, profName)
|
var outputInformationHolder = nbstatus.ConvertToStatusOutputOverview(resp.GetFullStatus(), anonymizeFlag, resp.GetDaemonVersion(), statusFilter, prefixNamesFilter, prefixNamesFilterMap, ipsFilterMap, connectionTypeFilter, profName)
|
||||||
var statusOutputString string
|
var statusOutputString string
|
||||||
switch {
|
switch {
|
||||||
case detailFlag:
|
case detailFlag:
|
||||||
|
|||||||
@@ -196,7 +196,8 @@ func runInForegroundMode(ctx context.Context, cmd *cobra.Command, activeProf *pr
|
|||||||
r := peer.NewRecorder(config.ManagementURL.String())
|
r := peer.NewRecorder(config.ManagementURL.String())
|
||||||
r.GetFullStatus()
|
r.GetFullStatus()
|
||||||
|
|
||||||
connectClient := internal.NewConnectClient(ctx, config, r)
|
//todo: do we need to pass logFile here ?
|
||||||
|
connectClient := internal.NewConnectClient(ctx, config, r, "")
|
||||||
SetupDebugHandler(ctx, config, r, connectClient, "")
|
SetupDebugHandler(ctx, config, r, connectClient, "")
|
||||||
|
|
||||||
return connectClient.Run(nil)
|
return connectClient.Run(nil)
|
||||||
|
|||||||
@@ -45,17 +45,19 @@ type ConnectClient struct {
|
|||||||
engineMutex sync.Mutex
|
engineMutex sync.Mutex
|
||||||
|
|
||||||
persistSyncResponse bool
|
persistSyncResponse bool
|
||||||
|
LogFile string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConnectClient(
|
func NewConnectClient(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
config *profilemanager.Config,
|
config *profilemanager.Config,
|
||||||
statusRecorder *peer.Status,
|
statusRecorder *peer.Status,
|
||||||
|
logFile string,
|
||||||
) *ConnectClient {
|
) *ConnectClient {
|
||||||
return &ConnectClient{
|
return &ConnectClient{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
config: config,
|
config: config,
|
||||||
|
LogFile: logFile,
|
||||||
statusRecorder: statusRecorder,
|
statusRecorder: statusRecorder,
|
||||||
engineMutex: sync.Mutex{},
|
engineMutex: sync.Mutex{},
|
||||||
}
|
}
|
||||||
@@ -261,7 +263,7 @@ func (c *ConnectClient) run(mobileDependency MobileDependency, runningChan chan
|
|||||||
|
|
||||||
peerConfig := loginResp.GetPeerConfig()
|
peerConfig := loginResp.GetPeerConfig()
|
||||||
|
|
||||||
engineConfig, err := createEngineConfig(myPrivateKey, c.config, peerConfig)
|
engineConfig, err := createEngineConfig(myPrivateKey, c.config, peerConfig, c.LogFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
return wrapErr(err)
|
return wrapErr(err)
|
||||||
@@ -415,7 +417,7 @@ func (c *ConnectClient) SetSyncResponsePersistence(enabled bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// createEngineConfig converts configuration received from Management Service to EngineConfig
|
// createEngineConfig converts configuration received from Management Service to EngineConfig
|
||||||
func createEngineConfig(key wgtypes.Key, config *profilemanager.Config, peerConfig *mgmProto.PeerConfig) (*EngineConfig, error) {
|
func createEngineConfig(key wgtypes.Key, config *profilemanager.Config, peerConfig *mgmProto.PeerConfig, logFile string) (*EngineConfig, error) {
|
||||||
nm := false
|
nm := false
|
||||||
if config.NetworkMonitor != nil {
|
if config.NetworkMonitor != nil {
|
||||||
nm = *config.NetworkMonitor
|
nm = *config.NetworkMonitor
|
||||||
@@ -444,6 +446,7 @@ func createEngineConfig(key wgtypes.Key, config *profilemanager.Config, peerConf
|
|||||||
BlockInbound: config.BlockInbound,
|
BlockInbound: config.BlockInbound,
|
||||||
|
|
||||||
LazyConnectionEnabled: config.LazyConnectionEnabled,
|
LazyConnectionEnabled: config.LazyConnectionEnabled,
|
||||||
|
LogFile: logFile,
|
||||||
|
|
||||||
ProfileConfig: config,
|
ProfileConfig: config,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ import (
|
|||||||
signal "github.com/netbirdio/netbird/shared/signal/client"
|
signal "github.com/netbirdio/netbird/shared/signal/client"
|
||||||
sProto "github.com/netbirdio/netbird/shared/signal/proto"
|
sProto "github.com/netbirdio/netbird/shared/signal/proto"
|
||||||
"github.com/netbirdio/netbird/util"
|
"github.com/netbirdio/netbird/util"
|
||||||
|
"github.com/netbirdio/netbird/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PeerConnectionTimeoutMax is a timeout of an initial connection attempt to a remote peer.
|
// PeerConnectionTimeoutMax is a timeout of an initial connection attempt to a remote peer.
|
||||||
@@ -128,10 +129,11 @@ type EngineConfig struct {
|
|||||||
BlockInbound bool
|
BlockInbound bool
|
||||||
|
|
||||||
LazyConnectionEnabled bool
|
LazyConnectionEnabled bool
|
||||||
DaemonAddress string
|
|
||||||
|
|
||||||
// for debug bundle generation
|
// for debug bundle generation
|
||||||
ProfileConfig *profilemanager.Config
|
ProfileConfig *profilemanager.Config
|
||||||
|
|
||||||
|
LogFile string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Engine is a mechanism responsible for reacting on Signal and Management stream events and managing connections to the remote peers.
|
// Engine is a mechanism responsible for reacting on Signal and Management stream events and managing connections to the remote peers.
|
||||||
@@ -936,16 +938,18 @@ func (e *Engine) handleBundle(params *mgmProto.BundleParameters) (*mgmProto.JobR
|
|||||||
if syncResponse == nil {
|
if syncResponse == nil {
|
||||||
return nil, errors.New("sync response is not available")
|
return nil, errors.New("sync response is not available")
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert fullStatus to statusOutput
|
// convert fullStatus to statusOutput
|
||||||
fullStatus := e.statusRecorder.GetFullStatus()
|
fullStatus := e.statusRecorder.GetFullStatus()
|
||||||
overview := nbstatus.ConvertFullStatusToOutputOverview(&fullStatus, params.Anonymize, "", "", nil, nil, nil, "", "", nil, nil)
|
protoFullStatus := nbstatus.ToProtoFullStatus(fullStatus)
|
||||||
|
overview := nbstatus.ConvertToStatusOutputOverview(protoFullStatus, params.Anonymize, version.NetbirdVersion(), "", nil, nil, nil, "", "")
|
||||||
statusOutput := nbstatus.ParseToFullDetailSummary(overview)
|
statusOutput := nbstatus.ParseToFullDetailSummary(overview)
|
||||||
|
|
||||||
bundleDeps := debug.GeneratorDependencies{
|
bundleDeps := debug.GeneratorDependencies{
|
||||||
InternalConfig: e.config.ProfileConfig,
|
InternalConfig: e.config.ProfileConfig,
|
||||||
StatusRecorder: e.statusRecorder,
|
StatusRecorder: e.statusRecorder,
|
||||||
SyncResponse: syncResponse,
|
SyncResponse: syncResponse,
|
||||||
LogFile: "", // todo: figure out where come from the log file. I suppose the client who invokes engine creation knows it.
|
LogFile: e.config.LogFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
bundleJobParams := debug.BundleConfig{
|
bundleJobParams := debug.BundleConfig{
|
||||||
|
|||||||
@@ -13,15 +13,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cenkalti/backoff/v4"
|
"github.com/cenkalti/backoff/v4"
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||||
"google.golang.org/protobuf/types/known/durationpb"
|
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
gstatus "google.golang.org/grpc/status"
|
gstatus "google.golang.org/grpc/status"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/client/internal/auth"
|
"github.com/netbirdio/netbird/client/internal/auth"
|
||||||
"github.com/netbirdio/netbird/client/internal/profilemanager"
|
"github.com/netbirdio/netbird/client/internal/profilemanager"
|
||||||
@@ -32,6 +29,7 @@ import (
|
|||||||
"github.com/netbirdio/netbird/client/internal"
|
"github.com/netbirdio/netbird/client/internal"
|
||||||
"github.com/netbirdio/netbird/client/internal/peer"
|
"github.com/netbirdio/netbird/client/internal/peer"
|
||||||
"github.com/netbirdio/netbird/client/proto"
|
"github.com/netbirdio/netbird/client/proto"
|
||||||
|
nbstatus "github.com/netbirdio/netbird/client/status"
|
||||||
"github.com/netbirdio/netbird/version"
|
"github.com/netbirdio/netbird/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -235,7 +233,7 @@ func (s *Server) connectWithRetryRuns(ctx context.Context, config *profilemanage
|
|||||||
|
|
||||||
runOperation := func() error {
|
runOperation := func() error {
|
||||||
log.Tracef("running client connection")
|
log.Tracef("running client connection")
|
||||||
s.connectClient = internal.NewConnectClient(ctx, config, statusRecorder)
|
s.connectClient = internal.NewConnectClient(ctx, config, statusRecorder, s.logFile)
|
||||||
s.connectClient.SetSyncResponsePersistence(s.persistSyncResponse)
|
s.connectClient.SetSyncResponsePersistence(s.persistSyncResponse)
|
||||||
|
|
||||||
err := s.connectClient.Run(runningChan)
|
err := s.connectClient.Run(runningChan)
|
||||||
@@ -1026,7 +1024,7 @@ func (s *Server) Status(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fullStatus := s.statusRecorder.GetFullStatus()
|
fullStatus := s.statusRecorder.GetFullStatus()
|
||||||
pbFullStatus := toProtoFullStatus(fullStatus)
|
pbFullStatus := nbstatus.ToProtoFullStatus(fullStatus)
|
||||||
pbFullStatus.Events = s.statusRecorder.GetEventHistory()
|
pbFullStatus.Events = s.statusRecorder.GetEventHistory()
|
||||||
statusResponse.FullStatus = pbFullStatus
|
statusResponse.FullStatus = pbFullStatus
|
||||||
}
|
}
|
||||||
@@ -1131,93 +1129,6 @@ func (s *Server) onSessionExpire() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func toProtoFullStatus(fullStatus peer.FullStatus) *proto.FullStatus {
|
|
||||||
pbFullStatus := proto.FullStatus{
|
|
||||||
ManagementState: &proto.ManagementState{},
|
|
||||||
SignalState: &proto.SignalState{},
|
|
||||||
LocalPeerState: &proto.LocalPeerState{},
|
|
||||||
Peers: []*proto.PeerState{},
|
|
||||||
}
|
|
||||||
|
|
||||||
pbFullStatus.ManagementState.URL = fullStatus.ManagementState.URL
|
|
||||||
pbFullStatus.ManagementState.Connected = fullStatus.ManagementState.Connected
|
|
||||||
if err := fullStatus.ManagementState.Error; err != nil {
|
|
||||||
pbFullStatus.ManagementState.Error = err.Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
pbFullStatus.SignalState.URL = fullStatus.SignalState.URL
|
|
||||||
pbFullStatus.SignalState.Connected = fullStatus.SignalState.Connected
|
|
||||||
if err := fullStatus.SignalState.Error; err != nil {
|
|
||||||
pbFullStatus.SignalState.Error = err.Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
pbFullStatus.LocalPeerState.IP = fullStatus.LocalPeerState.IP
|
|
||||||
pbFullStatus.LocalPeerState.PubKey = fullStatus.LocalPeerState.PubKey
|
|
||||||
pbFullStatus.LocalPeerState.KernelInterface = fullStatus.LocalPeerState.KernelInterface
|
|
||||||
pbFullStatus.LocalPeerState.Fqdn = fullStatus.LocalPeerState.FQDN
|
|
||||||
pbFullStatus.LocalPeerState.RosenpassPermissive = fullStatus.RosenpassState.Permissive
|
|
||||||
pbFullStatus.LocalPeerState.RosenpassEnabled = fullStatus.RosenpassState.Enabled
|
|
||||||
pbFullStatus.LocalPeerState.Networks = maps.Keys(fullStatus.LocalPeerState.Routes)
|
|
||||||
pbFullStatus.NumberOfForwardingRules = int32(fullStatus.NumOfForwardingRules)
|
|
||||||
pbFullStatus.LazyConnectionEnabled = fullStatus.LazyConnectionEnabled
|
|
||||||
|
|
||||||
for _, peerState := range fullStatus.Peers {
|
|
||||||
pbPeerState := &proto.PeerState{
|
|
||||||
IP: peerState.IP,
|
|
||||||
PubKey: peerState.PubKey,
|
|
||||||
ConnStatus: peerState.ConnStatus.String(),
|
|
||||||
ConnStatusUpdate: timestamppb.New(peerState.ConnStatusUpdate),
|
|
||||||
Relayed: peerState.Relayed,
|
|
||||||
LocalIceCandidateType: peerState.LocalIceCandidateType,
|
|
||||||
RemoteIceCandidateType: peerState.RemoteIceCandidateType,
|
|
||||||
LocalIceCandidateEndpoint: peerState.LocalIceCandidateEndpoint,
|
|
||||||
RemoteIceCandidateEndpoint: peerState.RemoteIceCandidateEndpoint,
|
|
||||||
RelayAddress: peerState.RelayServerAddress,
|
|
||||||
Fqdn: peerState.FQDN,
|
|
||||||
LastWireguardHandshake: timestamppb.New(peerState.LastWireguardHandshake),
|
|
||||||
BytesRx: peerState.BytesRx,
|
|
||||||
BytesTx: peerState.BytesTx,
|
|
||||||
RosenpassEnabled: peerState.RosenpassEnabled,
|
|
||||||
Networks: maps.Keys(peerState.GetRoutes()),
|
|
||||||
Latency: durationpb.New(peerState.Latency),
|
|
||||||
}
|
|
||||||
pbFullStatus.Peers = append(pbFullStatus.Peers, pbPeerState)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, relayState := range fullStatus.Relays {
|
|
||||||
pbRelayState := &proto.RelayState{
|
|
||||||
URI: relayState.URI,
|
|
||||||
Available: relayState.Err == nil,
|
|
||||||
}
|
|
||||||
if err := relayState.Err; err != nil {
|
|
||||||
pbRelayState.Error = err.Error()
|
|
||||||
}
|
|
||||||
pbFullStatus.Relays = append(pbFullStatus.Relays, pbRelayState)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, dnsState := range fullStatus.NSGroupStates {
|
|
||||||
var err string
|
|
||||||
if dnsState.Error != nil {
|
|
||||||
err = dnsState.Error.Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
var servers []string
|
|
||||||
for _, server := range dnsState.Servers {
|
|
||||||
servers = append(servers, server.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
pbDnsState := &proto.NSGroupState{
|
|
||||||
Servers: servers,
|
|
||||||
Domains: dnsState.Domains,
|
|
||||||
Enabled: dnsState.Enabled,
|
|
||||||
Error: err,
|
|
||||||
}
|
|
||||||
pbFullStatus.DnsServers = append(pbFullStatus.DnsServers, pbDnsState)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &pbFullStatus
|
|
||||||
}
|
|
||||||
|
|
||||||
// sendTerminalNotification sends a terminal notification message
|
// sendTerminalNotification sends a terminal notification message
|
||||||
// to inform the user that the NetBird connection session has expired.
|
// to inform the user that the NetBird connection session has expired.
|
||||||
func sendTerminalNotification() error {
|
func sendTerminalNotification() error {
|
||||||
|
|||||||
@@ -11,14 +11,16 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/types/known/durationpb"
|
||||||
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/client/anonymize"
|
"github.com/netbirdio/netbird/client/anonymize"
|
||||||
"github.com/netbirdio/netbird/client/internal/peer"
|
"github.com/netbirdio/netbird/client/internal/peer"
|
||||||
"github.com/netbirdio/netbird/client/internal/relay"
|
|
||||||
"github.com/netbirdio/netbird/client/proto"
|
"github.com/netbirdio/netbird/client/proto"
|
||||||
"github.com/netbirdio/netbird/shared/management/domain"
|
"github.com/netbirdio/netbird/shared/management/domain"
|
||||||
"github.com/netbirdio/netbird/version"
|
"github.com/netbirdio/netbird/version"
|
||||||
|
"golang.org/x/exp/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PeerStateDetailOutput struct {
|
type PeerStateDetailOutput struct {
|
||||||
@@ -102,157 +104,42 @@ type OutputOverview struct {
|
|||||||
ProfileName string `json:"profileName" yaml:"profileName"`
|
ProfileName string `json:"profileName" yaml:"profileName"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConvertToStatusOutputOverview(resp *proto.StatusResponse, anon bool, statusFilter string, prefixNamesFilter []string, prefixNamesFilterMap map[string]struct{}, ipsFilter map[string]struct{}, connectionTypeFilter string, profName string) OutputOverview {
|
func ConvertToStatusOutputOverview(pbFullStatus *proto.FullStatus, anon bool, daemonVersion string, statusFilter string, prefixNamesFilter []string, prefixNamesFilterMap map[string]struct{}, ipsFilter map[string]struct{}, connectionTypeFilter string, profName string) OutputOverview {
|
||||||
pbFullStatus := resp.GetFullStatus()
|
|
||||||
|
|
||||||
managementState := pbFullStatus.GetManagementState()
|
managementState := pbFullStatus.GetManagementState()
|
||||||
signalState := pbFullStatus.GetSignalState()
|
|
||||||
localPeer := pbFullStatus.GetLocalPeerState()
|
|
||||||
protoPeers := pbFullStatus.GetPeers()
|
|
||||||
peers := make([]peer.State, 0, len(protoPeers))
|
|
||||||
for _, p := range protoPeers {
|
|
||||||
//!! todo: this value is not in peer struct !! p.GetNetworks()
|
|
||||||
peers = append(peers, peer.State{
|
|
||||||
IP: p.GetIP(),
|
|
||||||
PubKey: p.GetPubKey(),
|
|
||||||
FQDN: p.GetFqdn(),
|
|
||||||
//!! ConnStatus: peer.ConnStatus(p.GetConnStatus()), // we need way to convert this
|
|
||||||
ConnStatusUpdate: p.GetConnStatusUpdate().AsTime(),
|
|
||||||
Relayed: p.GetRelayed(),
|
|
||||||
LocalIceCandidateType: p.GetLocalIceCandidateType(),
|
|
||||||
RemoteIceCandidateType: p.GetRemoteIceCandidateType(),
|
|
||||||
LocalIceCandidateEndpoint: p.GetLocalIceCandidateEndpoint(),
|
|
||||||
RemoteIceCandidateEndpoint: p.GetRemoteIceCandidateEndpoint(),
|
|
||||||
RelayServerAddress: p.GetRelayAddress(),
|
|
||||||
LastWireguardHandshake: p.GetLastWireguardHandshake().AsTime(),
|
|
||||||
BytesTx: p.GetBytesTx(),
|
|
||||||
BytesRx: p.GetBytesRx(),
|
|
||||||
Latency: p.GetLatency().AsDuration(),
|
|
||||||
RosenpassEnabled: p.GetRosenpassEnabled(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pRelays := pbFullStatus.GetRelays()
|
|
||||||
relays := make([]relay.ProbeResult, 0, len(pRelays))
|
|
||||||
for _, r := range pRelays {
|
|
||||||
//!! todo : this not so good way to do that but it is working
|
|
||||||
available := ""
|
|
||||||
if r.GetAvailable() {
|
|
||||||
available = "available"
|
|
||||||
}
|
|
||||||
|
|
||||||
relays = append(relays, relay.ProbeResult{
|
|
||||||
URI: r.URI,
|
|
||||||
Err: fmt.Errorf(r.GetError()),
|
|
||||||
Addr: available,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pNsGroup := pbFullStatus.GetDnsServers()
|
|
||||||
nsGroup := make([]peer.NSGroupState, 0, len(pNsGroup))
|
|
||||||
for _, n := range nsGroup {
|
|
||||||
nsGroup = append(nsGroup, peer.NSGroupState{
|
|
||||||
ID: n.ID,
|
|
||||||
Enabled: n.Enabled,
|
|
||||||
Error: n.Error,
|
|
||||||
Domains: n.Domains,
|
|
||||||
Servers: n.Servers,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fullStatus := peer.FullStatus{
|
|
||||||
Peers: peers,
|
|
||||||
Relays: relays,
|
|
||||||
NSGroupStates: nsGroup,
|
|
||||||
ManagementState: peer.ManagementState{
|
|
||||||
URL: managementState.GetURL(),
|
|
||||||
Connected: managementState.GetConnected(),
|
|
||||||
Error: fmt.Errorf(managementState.GetError()),
|
|
||||||
},
|
|
||||||
SignalState: peer.SignalState{
|
|
||||||
URL: signalState.GetURL(),
|
|
||||||
Connected: signalState.GetConnected(),
|
|
||||||
Error: fmt.Errorf(signalState.GetError()),
|
|
||||||
},
|
|
||||||
LocalPeerState: peer.LocalPeerState{
|
|
||||||
IP: localPeer.GetIP(),
|
|
||||||
PubKey: localPeer.GetPubKey(),
|
|
||||||
FQDN: localPeer.GetFqdn(),
|
|
||||||
KernelInterface: localPeer.GetKernelInterface(),
|
|
||||||
},
|
|
||||||
RosenpassState: peer.RosenpassState{
|
|
||||||
Enabled: pbFullStatus.LocalPeerState.GetRosenpassEnabled(),
|
|
||||||
Permissive: pbFullStatus.LocalPeerState.GetRosenpassPermissive(),
|
|
||||||
},
|
|
||||||
NumOfForwardingRules: int(pbFullStatus.GetNumberOfForwardingRules()),
|
|
||||||
LazyConnectionEnabled: pbFullStatus.GetLazyConnectionEnabled(),
|
|
||||||
}
|
|
||||||
events := mapEvents(pbFullStatus.GetEvents())
|
|
||||||
|
|
||||||
return ConvertFullStatusToOutputOverview(&fullStatus,
|
|
||||||
anon,
|
|
||||||
resp.GetDaemonVersion(),
|
|
||||||
statusFilter,
|
|
||||||
prefixNamesFilter,
|
|
||||||
prefixNamesFilterMap,
|
|
||||||
ipsFilter,
|
|
||||||
connectionTypeFilter,
|
|
||||||
profName,
|
|
||||||
resp.FullStatus.LocalPeerState.GetNetworks(),
|
|
||||||
events,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ConvertFullStatusToOutputOverview(
|
|
||||||
pbFullStatus *peer.FullStatus,
|
|
||||||
anon bool,
|
|
||||||
daemonVersion string,
|
|
||||||
statusFilter string,
|
|
||||||
prefixNamesFilter []string,
|
|
||||||
prefixNamesFilterMap map[string]struct{},
|
|
||||||
ipsFilter map[string]struct{},
|
|
||||||
connectionTypeFilter string,
|
|
||||||
profName string,
|
|
||||||
networks []string,
|
|
||||||
events []SystemEventOutput,
|
|
||||||
) OutputOverview {
|
|
||||||
managementState := pbFullStatus.ManagementState
|
|
||||||
managementOverview := ManagementStateOutput{
|
managementOverview := ManagementStateOutput{
|
||||||
URL: managementState.URL,
|
URL: managementState.GetURL(),
|
||||||
Connected: managementState.Connected,
|
Connected: managementState.GetConnected(),
|
||||||
Error: managementState.Error.Error(),
|
Error: managementState.Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
signalState := pbFullStatus.SignalState
|
signalState := pbFullStatus.GetSignalState()
|
||||||
signalOverview := SignalStateOutput{
|
signalOverview := SignalStateOutput{
|
||||||
URL: signalState.URL,
|
URL: signalState.GetURL(),
|
||||||
Connected: signalState.Connected,
|
Connected: signalState.GetConnected(),
|
||||||
Error: signalState.Error.Error(),
|
Error: signalState.Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
relayOverview := mapRelays(pbFullStatus.Relays)
|
relayOverview := mapRelays(pbFullStatus.GetRelays())
|
||||||
peersOverview := mapPeers(pbFullStatus.Peers, statusFilter, prefixNamesFilter, prefixNamesFilterMap, ipsFilter, connectionTypeFilter)
|
peersOverview := mapPeers(pbFullStatus.GetPeers(), statusFilter, prefixNamesFilter, prefixNamesFilterMap, ipsFilter, connectionTypeFilter)
|
||||||
nSServerGroups := mapNSGroups(pbFullStatus.NSGroupStates)
|
|
||||||
localPeerState := pbFullStatus.LocalPeerState
|
|
||||||
|
|
||||||
overview := OutputOverview{
|
overview := OutputOverview{
|
||||||
Peers: peersOverview,
|
Peers: peersOverview,
|
||||||
CliVersion: version.NetbirdVersion(),
|
CliVersion: version.NetbirdVersion(),
|
||||||
DaemonVersion: daemonVersion,
|
DaemonVersion: daemonVersion,
|
||||||
ManagementState: managementOverview,
|
ManagementState: managementOverview,
|
||||||
SignalState: signalOverview,
|
SignalState: signalOverview,
|
||||||
Relays: relayOverview,
|
Relays: relayOverview,
|
||||||
IP: localPeerState.IP,
|
IP: pbFullStatus.GetLocalPeerState().GetIP(),
|
||||||
PubKey: localPeerState.PubKey,
|
PubKey: pbFullStatus.GetLocalPeerState().GetPubKey(),
|
||||||
KernelInterface: localPeerState.KernelInterface,
|
KernelInterface: pbFullStatus.GetLocalPeerState().GetKernelInterface(),
|
||||||
FQDN: localPeerState.FQDN,
|
FQDN: pbFullStatus.GetLocalPeerState().GetFqdn(),
|
||||||
RosenpassEnabled: pbFullStatus.LazyConnectionEnabled,
|
RosenpassEnabled: pbFullStatus.GetLocalPeerState().GetRosenpassEnabled(),
|
||||||
RosenpassPermissive: pbFullStatus.RosenpassState.Permissive,
|
RosenpassPermissive: pbFullStatus.GetLocalPeerState().GetRosenpassPermissive(),
|
||||||
Networks: networks,
|
Networks: pbFullStatus.GetLocalPeerState().GetNetworks(),
|
||||||
NumberOfForwardingRules: pbFullStatus.NumOfForwardingRules,
|
NumberOfForwardingRules: int(pbFullStatus.GetNumberOfForwardingRules()),
|
||||||
NSServerGroups: nSServerGroups,
|
NSServerGroups: mapNSGroups(pbFullStatus.GetDnsServers()),
|
||||||
Events: events,
|
Events: mapEvents(pbFullStatus.GetEvents()),
|
||||||
LazyConnectionEnabled: pbFullStatus.LazyConnectionEnabled,
|
LazyConnectionEnabled: pbFullStatus.GetLazyConnectionEnabled(),
|
||||||
ProfileName: profName,
|
ProfileName: profName,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,18 +151,17 @@ func ConvertFullStatusToOutputOverview(
|
|||||||
return overview
|
return overview
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mapRelays(relays []*proto.RelayState) RelayStateOutput {
|
||||||
func mapRelays(relays []relay.ProbeResult) RelayStateOutput {
|
|
||||||
var relayStateDetail []RelayStateOutputDetail
|
var relayStateDetail []RelayStateOutputDetail
|
||||||
|
|
||||||
var relaysAvailable int
|
var relaysAvailable int
|
||||||
for _, relay := range relays {
|
for _, relay := range relays {
|
||||||
available := relay.Addr != ""
|
available := relay.GetAvailable()
|
||||||
relayStateDetail = append(relayStateDetail,
|
relayStateDetail = append(relayStateDetail,
|
||||||
RelayStateOutputDetail{
|
RelayStateOutputDetail{
|
||||||
URI: relay.URI,
|
URI: relay.URI,
|
||||||
Available: available,
|
Available: available,
|
||||||
Error: relay.Err.Error(),
|
Error: relay.GetError(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -291,27 +177,21 @@ func mapRelays(relays []relay.ProbeResult) RelayStateOutput {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapNSGroups(servers []peer.NSGroupState) []NsServerGroupStateOutput {
|
func mapNSGroups(servers []*proto.NSGroupState) []NsServerGroupStateOutput {
|
||||||
mappedNSGroups := make([]NsServerGroupStateOutput, 0, len(servers))
|
mappedNSGroups := make([]NsServerGroupStateOutput, 0, len(servers))
|
||||||
for _, pbNsGroupServer := range servers {
|
for _, pbNsGroupServer := range servers {
|
||||||
var serversAddress []string
|
|
||||||
|
|
||||||
for _, serv := range pbNsGroupServer.Servers {
|
|
||||||
serversAddress = append(serversAddress, serv.Addr().String())
|
|
||||||
}
|
|
||||||
|
|
||||||
mappedNSGroups = append(mappedNSGroups, NsServerGroupStateOutput{
|
mappedNSGroups = append(mappedNSGroups, NsServerGroupStateOutput{
|
||||||
Servers: serversAddress,
|
Servers: pbNsGroupServer.GetServers(),
|
||||||
Domains: pbNsGroupServer.Domains,
|
Domains: pbNsGroupServer.GetDomains(),
|
||||||
Enabled: pbNsGroupServer.Enabled,
|
Enabled: pbNsGroupServer.GetEnabled(),
|
||||||
Error: pbNsGroupServer.Error.Error(),
|
Error: pbNsGroupServer.GetError(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return mappedNSGroups
|
return mappedNSGroups
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapPeers(
|
func mapPeers(
|
||||||
peers []peer.State,
|
peers []*proto.PeerState,
|
||||||
statusFilter string,
|
statusFilter string,
|
||||||
prefixNamesFilter []string,
|
prefixNamesFilter []string,
|
||||||
prefixNamesFilterMap map[string]struct{},
|
prefixNamesFilterMap map[string]struct{},
|
||||||
@@ -331,33 +211,33 @@ func mapPeers(
|
|||||||
transferReceived := int64(0)
|
transferReceived := int64(0)
|
||||||
transferSent := int64(0)
|
transferSent := int64(0)
|
||||||
|
|
||||||
isPeerConnected := pbPeerState.ConnStatus == peer.StatusConnected
|
isPeerConnected := pbPeerState.ConnStatus == peer.StatusConnected.String()
|
||||||
|
|
||||||
if pbPeerState.Relayed {
|
if pbPeerState.Relayed {
|
||||||
connType = "Relayed"
|
connType = "Relayed"
|
||||||
}
|
}
|
||||||
|
|
||||||
if skipDetailByFilters(pbPeerState, pbPeerState.ConnStatus.String(), statusFilter, prefixNamesFilter, prefixNamesFilterMap, ipsFilter, connectionTypeFilter, connType) {
|
if skipDetailByFilters(pbPeerState, pbPeerState.ConnStatus, statusFilter, prefixNamesFilter, prefixNamesFilterMap, ipsFilter, connectionTypeFilter, connType) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if isPeerConnected {
|
if isPeerConnected {
|
||||||
peersConnected++
|
peersConnected++
|
||||||
|
|
||||||
localICE = pbPeerState.LocalIceCandidateType
|
localICE = pbPeerState.GetLocalIceCandidateType()
|
||||||
remoteICE = pbPeerState.RemoteIceCandidateType
|
remoteICE = pbPeerState.GetRemoteIceCandidateType()
|
||||||
localICEEndpoint = pbPeerState.LocalIceCandidateEndpoint
|
localICEEndpoint = pbPeerState.GetLocalIceCandidateEndpoint()
|
||||||
remoteICEEndpoint = pbPeerState.RemoteIceCandidateEndpoint
|
remoteICEEndpoint = pbPeerState.GetRemoteIceCandidateEndpoint()
|
||||||
relayServerAddress = pbPeerState.RelayServerAddress
|
relayServerAddress = pbPeerState.GetRelayAddress()
|
||||||
lastHandshake = pbPeerState.LastWireguardHandshake.Local()
|
lastHandshake = pbPeerState.GetLastWireguardHandshake().AsTime().Local()
|
||||||
transferReceived = pbPeerState.BytesRx
|
transferReceived = pbPeerState.GetBytesRx()
|
||||||
transferSent = pbPeerState.BytesTx
|
transferSent = pbPeerState.GetBytesTx()
|
||||||
}
|
}
|
||||||
|
|
||||||
timeLocal := pbPeerState.ConnStatusUpdate.Local()
|
timeLocal := pbPeerState.GetConnStatusUpdate().AsTime().Local()
|
||||||
peerState := PeerStateDetailOutput{
|
peerState := PeerStateDetailOutput{
|
||||||
IP: pbPeerState.IP,
|
IP: pbPeerState.GetIP(),
|
||||||
PubKey: pbPeerState.PubKey,
|
PubKey: pbPeerState.GetPubKey(),
|
||||||
Status: pbPeerState.ConnStatus.String(),
|
Status: pbPeerState.GetConnStatus(),
|
||||||
LastStatusUpdate: timeLocal,
|
LastStatusUpdate: timeLocal,
|
||||||
ConnType: connType,
|
ConnType: connType,
|
||||||
IceCandidateType: IceCandidateType{
|
IceCandidateType: IceCandidateType{
|
||||||
@@ -369,13 +249,13 @@ func mapPeers(
|
|||||||
Remote: remoteICEEndpoint,
|
Remote: remoteICEEndpoint,
|
||||||
},
|
},
|
||||||
RelayAddress: relayServerAddress,
|
RelayAddress: relayServerAddress,
|
||||||
FQDN: pbPeerState.FQDN,
|
FQDN: pbPeerState.GetFqdn(),
|
||||||
LastWireguardHandshake: lastHandshake,
|
LastWireguardHandshake: lastHandshake,
|
||||||
TransferReceived: transferReceived,
|
TransferReceived: transferReceived,
|
||||||
TransferSent: transferSent,
|
TransferSent: transferSent,
|
||||||
Latency: pbPeerState.Latency,
|
Latency: pbPeerState.GetLatency().AsDuration(),
|
||||||
RosenpassEnabled: pbPeerState.RosenpassEnabled,
|
RosenpassEnabled: pbPeerState.GetRosenpassEnabled(),
|
||||||
Networks: []string{}, // DO WE NEED THIS ?
|
Networks: pbPeerState.GetNetworks(),
|
||||||
}
|
}
|
||||||
|
|
||||||
peersStateDetail = append(peersStateDetail, peerState)
|
peersStateDetail = append(peersStateDetail, peerState)
|
||||||
@@ -579,6 +459,93 @@ func ParseToFullDetailSummary(overview OutputOverview) string {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ToProtoFullStatus(fullStatus peer.FullStatus) *proto.FullStatus {
|
||||||
|
pbFullStatus := proto.FullStatus{
|
||||||
|
ManagementState: &proto.ManagementState{},
|
||||||
|
SignalState: &proto.SignalState{},
|
||||||
|
LocalPeerState: &proto.LocalPeerState{},
|
||||||
|
Peers: []*proto.PeerState{},
|
||||||
|
}
|
||||||
|
|
||||||
|
pbFullStatus.ManagementState.URL = fullStatus.ManagementState.URL
|
||||||
|
pbFullStatus.ManagementState.Connected = fullStatus.ManagementState.Connected
|
||||||
|
if err := fullStatus.ManagementState.Error; err != nil {
|
||||||
|
pbFullStatus.ManagementState.Error = err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
pbFullStatus.SignalState.URL = fullStatus.SignalState.URL
|
||||||
|
pbFullStatus.SignalState.Connected = fullStatus.SignalState.Connected
|
||||||
|
if err := fullStatus.SignalState.Error; err != nil {
|
||||||
|
pbFullStatus.SignalState.Error = err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
pbFullStatus.LocalPeerState.IP = fullStatus.LocalPeerState.IP
|
||||||
|
pbFullStatus.LocalPeerState.PubKey = fullStatus.LocalPeerState.PubKey
|
||||||
|
pbFullStatus.LocalPeerState.KernelInterface = fullStatus.LocalPeerState.KernelInterface
|
||||||
|
pbFullStatus.LocalPeerState.Fqdn = fullStatus.LocalPeerState.FQDN
|
||||||
|
pbFullStatus.LocalPeerState.RosenpassPermissive = fullStatus.RosenpassState.Permissive
|
||||||
|
pbFullStatus.LocalPeerState.RosenpassEnabled = fullStatus.RosenpassState.Enabled
|
||||||
|
pbFullStatus.LocalPeerState.Networks = maps.Keys(fullStatus.LocalPeerState.Routes)
|
||||||
|
pbFullStatus.NumberOfForwardingRules = int32(fullStatus.NumOfForwardingRules)
|
||||||
|
pbFullStatus.LazyConnectionEnabled = fullStatus.LazyConnectionEnabled
|
||||||
|
|
||||||
|
for _, peerState := range fullStatus.Peers {
|
||||||
|
pbPeerState := &proto.PeerState{
|
||||||
|
IP: peerState.IP,
|
||||||
|
PubKey: peerState.PubKey,
|
||||||
|
ConnStatus: peerState.ConnStatus.String(),
|
||||||
|
ConnStatusUpdate: timestamppb.New(peerState.ConnStatusUpdate),
|
||||||
|
Relayed: peerState.Relayed,
|
||||||
|
LocalIceCandidateType: peerState.LocalIceCandidateType,
|
||||||
|
RemoteIceCandidateType: peerState.RemoteIceCandidateType,
|
||||||
|
LocalIceCandidateEndpoint: peerState.LocalIceCandidateEndpoint,
|
||||||
|
RemoteIceCandidateEndpoint: peerState.RemoteIceCandidateEndpoint,
|
||||||
|
RelayAddress: peerState.RelayServerAddress,
|
||||||
|
Fqdn: peerState.FQDN,
|
||||||
|
LastWireguardHandshake: timestamppb.New(peerState.LastWireguardHandshake),
|
||||||
|
BytesRx: peerState.BytesRx,
|
||||||
|
BytesTx: peerState.BytesTx,
|
||||||
|
RosenpassEnabled: peerState.RosenpassEnabled,
|
||||||
|
Networks: maps.Keys(peerState.GetRoutes()),
|
||||||
|
Latency: durationpb.New(peerState.Latency),
|
||||||
|
}
|
||||||
|
pbFullStatus.Peers = append(pbFullStatus.Peers, pbPeerState)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, relayState := range fullStatus.Relays {
|
||||||
|
pbRelayState := &proto.RelayState{
|
||||||
|
URI: relayState.URI,
|
||||||
|
Available: relayState.Err == nil,
|
||||||
|
}
|
||||||
|
if err := relayState.Err; err != nil {
|
||||||
|
pbRelayState.Error = err.Error()
|
||||||
|
}
|
||||||
|
pbFullStatus.Relays = append(pbFullStatus.Relays, pbRelayState)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, dnsState := range fullStatus.NSGroupStates {
|
||||||
|
var err string
|
||||||
|
if dnsState.Error != nil {
|
||||||
|
err = dnsState.Error.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
var servers []string
|
||||||
|
for _, server := range dnsState.Servers {
|
||||||
|
servers = append(servers, server.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
pbDnsState := &proto.NSGroupState{
|
||||||
|
Servers: servers,
|
||||||
|
Domains: dnsState.Domains,
|
||||||
|
Enabled: dnsState.Enabled,
|
||||||
|
Error: err,
|
||||||
|
}
|
||||||
|
pbFullStatus.DnsServers = append(pbFullStatus.DnsServers, pbDnsState)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pbFullStatus
|
||||||
|
}
|
||||||
|
|
||||||
func parsePeers(peers PeersStateOutput, rosenpassEnabled, rosenpassPermissive bool) string {
|
func parsePeers(peers PeersStateOutput, rosenpassEnabled, rosenpassPermissive bool) string {
|
||||||
var (
|
var (
|
||||||
peersString = ""
|
peersString = ""
|
||||||
@@ -669,7 +636,7 @@ func parsePeers(peers PeersStateOutput, rosenpassEnabled, rosenpassPermissive bo
|
|||||||
return peersString
|
return peersString
|
||||||
}
|
}
|
||||||
|
|
||||||
func skipDetailByFilters(peerState peer.State, peerStatus string, statusFilter string, prefixNamesFilter []string, prefixNamesFilterMap map[string]struct{}, ipsFilter map[string]struct{}, connectionTypeFilter, connType string) bool {
|
func skipDetailByFilters(peerState *proto.PeerState, peerStatus string, statusFilter string, prefixNamesFilter []string, prefixNamesFilterMap map[string]struct{}, ipsFilter map[string]struct{}, connectionTypeFilter, connType string) bool {
|
||||||
statusEval := false
|
statusEval := false
|
||||||
ipEval := false
|
ipEval := false
|
||||||
nameEval := true
|
nameEval := true
|
||||||
@@ -690,7 +657,7 @@ func skipDetailByFilters(peerState peer.State, peerStatus string, statusFilter s
|
|||||||
|
|
||||||
if len(prefixNamesFilter) > 0 {
|
if len(prefixNamesFilter) > 0 {
|
||||||
for prefixNameFilter := range prefixNamesFilterMap {
|
for prefixNameFilter := range prefixNamesFilterMap {
|
||||||
if strings.HasPrefix(peerState.FQDN, prefixNameFilter) {
|
if strings.HasPrefix(peerState.Fqdn, prefixNameFilter) {
|
||||||
nameEval = false
|
nameEval = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -858,3 +825,4 @@ func anonymizeOverview(a *anonymize.Anonymizer, overview *OutputOverview) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ var overview = OutputOverview{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestConversionFromFullStatusToOutputOverview(t *testing.T) {
|
func TestConversionFromFullStatusToOutputOverview(t *testing.T) {
|
||||||
convertedResult := ConvertToStatusOutputOverview(resp, false, "", nil, nil, nil, "", "")
|
convertedResult := ConvertToStatusOutputOverview(resp.GetFullStatus(), false, "", "", nil, nil, nil, "", "")
|
||||||
|
|
||||||
assert.Equal(t, overview, convertedResult)
|
assert.Equal(t, overview, convertedResult)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user