From 7e1b20da5d1d6a26f6a7715266a4ac955de55772 Mon Sep 17 00:00:00 2001 From: Maycon Santos Date: Thu, 7 Jul 2022 13:54:47 +0200 Subject: [PATCH] Always initialize status recorder (#383) Always initialize the status recorder Utilize proto methods to get pbFullStatus values. --- client/cmd/status.go | 35 +++++++++++++++++++---------------- client/server/server.go | 8 +++++++- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/client/cmd/status.go b/client/cmd/status.go index 6dcd8cae6ac..ead961fd8e4 100644 --- a/client/cmd/status.go +++ b/client/cmd/status.go @@ -106,29 +106,32 @@ func parseFilters() error { func fromProtoFullStatus(pbFullStatus *proto.FullStatus) nbStatus.FullStatus { var fullStatus nbStatus.FullStatus - fullStatus.ManagementState.URL = pbFullStatus.ManagementState.URL - fullStatus.ManagementState.Connected = pbFullStatus.ManagementState.Connected + managementState := pbFullStatus.GetManagementState() + fullStatus.ManagementState.URL = managementState.GetURL() + fullStatus.ManagementState.Connected = managementState.GetConnected() - fullStatus.SignalState.URL = pbFullStatus.SignalState.URL - fullStatus.SignalState.Connected = pbFullStatus.SignalState.Connected + signalState := pbFullStatus.GetSignalState() + fullStatus.SignalState.URL = signalState.GetURL() + fullStatus.SignalState.Connected = signalState.GetConnected() - fullStatus.LocalPeerState.IP = pbFullStatus.LocalPeerState.IP - fullStatus.LocalPeerState.PubKey = pbFullStatus.LocalPeerState.PubKey - fullStatus.LocalPeerState.KernelInterface = pbFullStatus.LocalPeerState.KernelInterface + localPeerState := pbFullStatus.GetLocalPeerState() + fullStatus.LocalPeerState.IP = localPeerState.GetIP() + fullStatus.LocalPeerState.PubKey = localPeerState.GetPubKey() + fullStatus.LocalPeerState.KernelInterface = localPeerState.GetKernelInterface() var peersState []nbStatus.PeerState - for _, pbPeerState := range pbFullStatus.Peers { - timeLocal := pbPeerState.ConnStatusUpdate.AsTime().Local() + for _, pbPeerState := range pbFullStatus.GetPeers() { + timeLocal := pbPeerState.GetConnStatusUpdate().AsTime().Local() peerState := nbStatus.PeerState{ - IP: pbPeerState.IP, - PubKey: pbPeerState.PubKey, - ConnStatus: pbPeerState.ConnStatus, + IP: pbPeerState.GetIP(), + PubKey: pbPeerState.GetPubKey(), + ConnStatus: pbPeerState.GetConnStatus(), ConnStatusUpdate: timeLocal, - Relayed: pbPeerState.Relayed, - Direct: pbPeerState.Direct, - LocalIceCandidateType: pbPeerState.LocalIceCandidateType, - RemoteIceCandidateType: pbPeerState.RemoteIceCandidateType, + Relayed: pbPeerState.GetRelayed(), + Direct: pbPeerState.GetDirect(), + LocalIceCandidateType: pbPeerState.GetLocalIceCandidateType(), + RemoteIceCandidateType: pbPeerState.GetRemoteIceCandidateType(), } peersState = append(peersState, peerState) } diff --git a/client/server/server.go b/client/server/server.go index 3358ad66911..6116bfca612 100644 --- a/client/server/server.go +++ b/client/server/server.go @@ -95,7 +95,9 @@ func (s *Server) Start() error { s.config = config - s.statusRecorder = nbStatus.NewRecorder() + if s.statusRecorder == nil { + s.statusRecorder = nbStatus.NewRecorder() + } go func() { if err := internal.RunClient(ctx, config, s.statusRecorder); err != nil { @@ -400,6 +402,10 @@ func (s *Server) Status( statusResponse := proto.StatusResponse{Status: string(status)} + if s.statusRecorder == nil { + s.statusRecorder = nbStatus.NewRecorder() + } + if msg.GetFullPeerStatus { fullStatus := s.statusRecorder.GetFullStatus() pbFullStatus := toProtoFullStatus(fullStatus)