Skip to content

Commit

Permalink
Always initialize status recorder (#383)
Browse files Browse the repository at this point in the history
Always initialize the status recorder

Utilize proto methods to get pbFullStatus values.
  • Loading branch information
mlsmaycon authored Jul 7, 2022
1 parent d4a3ee9 commit 7e1b20d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
35 changes: 19 additions & 16 deletions client/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 7 additions & 1 deletion client/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7e1b20d

Please sign in to comment.