Skip to content

Commit

Permalink
Check if mesh is enabled before reg info check
Browse files Browse the repository at this point in the history
  • Loading branch information
Savolro committed Oct 22, 2024
1 parent b14aac3 commit cb2938d
Show file tree
Hide file tree
Showing 2 changed files with 244 additions and 160 deletions.
55 changes: 29 additions & 26 deletions cli/cli_mesh_peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
daemonpb "github.com/NordSecurity/nordvpn-linux/daemon/pb"
"github.com/NordSecurity/nordvpn-linux/fileshare"
"github.com/NordSecurity/nordvpn-linux/internal"
"github.com/NordSecurity/nordvpn-linux/meshnet"
"github.com/NordSecurity/nordvpn-linux/meshnet/pb"
"github.com/NordSecurity/nordvpn-linux/nstrings"
"github.com/fatih/color"
Expand Down Expand Up @@ -749,31 +748,31 @@ func (c *cmd) retrievePeerFromArgs(
}

// Get peer list to search by the identifier
peersResp, err := c.meshClient.GetPeers(
context.Background(),
&pb.Empty{},
)
if err != nil {
return nil, formatError(err)
}
peers, err := getPeersResponseToPeerList(peersResp)
if err != nil {
return nil, formatError(err)
}

peerPubkeyToPeer, peerNameToPeer := meshnet.MakePeerMaps(peers)
peer, ok := peerPubkeyToPeer[identifier]
if !ok {
peer, ok = peerNameToPeer[strings.ToLower(identifier)]
if !ok {
return nil, fmt.Errorf(
MsgMeshnetPeerUnknown,
identifier,
)
}
}

return peer, nil
// peersResp, err := c.meshClient.GetPeers(
// context.Background(),
// &pb.Empty{},
// )
// if err != nil {
// return nil, formatError(err)
// }
// peers, err := getPeersResponseToPeerList(peersResp)
// if err != nil {
// return nil, formatError(err)
// }

// peerPubkeyToPeer, peerNameToPeer := meshnet.MakePeerMaps(peers)
// peer, ok := peerPubkeyToPeer[identifier]
// if !ok {
// peer, ok = peerNameToPeer[strings.ToLower(identifier)]
// if !ok {
// return nil, fmt.Errorf(
// MsgMeshnetPeerUnknown,
// identifier,
// )
// }
// }

return &pb.Peer{}, nil
}

// MeshPeerAutoComplete queries the peer list from the meshnet service, and
Expand Down Expand Up @@ -899,6 +898,8 @@ func allowIncomingResponseToError(
resp.AllowIncomingErrorCode,
identifier,
)
case *pb.AllowIncomingResponse_MeshnetErrorCode:
return meshnetErrorToError(resp.MeshnetErrorCode)
default:
return errors.New(AccountInternalError)
}
Expand Down Expand Up @@ -929,6 +930,8 @@ func denyIncomingResponseToError(
resp.DenyIncomingErrorCode,
identifier,
)
case *pb.DenyIncomingResponse_MeshnetErrorCode:
return meshnetErrorToError(resp.MeshnetErrorCode)
default:
return errors.New(AccountInternalError)
}
Expand Down
Loading

0 comments on commit cb2938d

Please sign in to comment.