Always initialize status recorder (#383)

Always initialize the status recorder

Utilize proto methods to get pbFullStatus values.
This commit is contained in:
Maycon Santos 2022-07-07 13:54:47 +02:00 committed by GitHub
parent d4a3ee9d87
commit 7e1b20da5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 17 deletions

View File

@ -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)
}

View File

@ -95,7 +95,9 @@ func (s *Server) Start() error {
s.config = config
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)