Skip to content

Commit

Permalink
Merge pull request #2059 from gravitl/GRA-1242-fix-pull
Browse files Browse the repository at this point in the history
Gra 1242 fix pull
  • Loading branch information
0xdcarns authored Feb 21, 2023
2 parents dd2f99b + 7194f0e commit ce04cfc
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 525 deletions.
26 changes: 5 additions & 21 deletions controllers/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ func getUsersNodes(user models.User) ([]models.Node, error) {
func getNode(w http.ResponseWriter, r *http.Request) {
// set header.
w.Header().Set("Content-Type", "application/json")

nodeRequest := r.Header.Get("requestfrom") == "node"

var params = mux.Vars(r)
Expand All @@ -434,36 +433,21 @@ func getNode(w http.ResponseWriter, r *http.Request) {
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
return
}
peerUpdate, err := logic.GetPeerUpdate(&node, host)
if err != nil && !database.IsEmptyRecord(err) {
logger.Log(0, r.Header.Get("user"),
fmt.Sprintf("error fetching wg peers config for node [ %s ]: %v", nodeid, err))
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
return
}
hostPeerUpdate, err := logic.GetPeerUpdateForHost(host)
hostPeerUpdate, err := logic.GetPeerUpdateForHost(node.Network, host)
if err != nil && !database.IsEmptyRecord(err) {
logger.Log(0, r.Header.Get("user"),
fmt.Sprintf("error fetching wg peers config for host [ %s ]: %v", host.ID.String(), err))
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
return
}
server := servercfg.GetServerInfo()
network, err := logic.GetNetwork(node.Network)
if err != nil {
logger.Log(0, r.Header.Get("user"),
fmt.Sprintf("error fetching network for node [ %s ] info: %v", nodeid, err))
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
return
}
legacy := node.Legacy(host, &server, &network)
response := models.NodeGet{
Node: *legacy,
Node: node,
Host: *host,
Peers: peerUpdate.Peers,
HostPeers: hostPeerUpdate.Peers,
Peers: hostPeerUpdate.NodePeers,
ServerConfig: server,
PeerIDs: peerUpdate.PeerIDs,
PeerIDs: hostPeerUpdate.PeerIDs,
}

if servercfg.Is_EE && nodeRequest {
Expand Down Expand Up @@ -632,7 +616,7 @@ func createNode(w http.ResponseWriter, r *http.Request) {
return
}
}
hostPeerUpdate, err := logic.GetPeerUpdateForHost(&data.Host)
hostPeerUpdate, err := logic.GetPeerUpdateForHost(networkName, &data.Host)
if err != nil && !database.IsEmptyRecord(err) {
logger.Log(0, r.Header.Get("user"),
fmt.Sprintf("error fetching wg peers config for host [ %s ]: %v", data.Host.ID.String(), err))
Expand Down
37 changes: 0 additions & 37 deletions logic/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"time"

"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/logic"
proxy_metrics "github.com/gravitl/netmaker/metrics"
"github.com/gravitl/netmaker/models"
"golang.zx2c4.com/wireguard/wgctrl"
Expand Down Expand Up @@ -71,42 +70,6 @@ func Collect(iface, server, network string, peerMap models.PeerMap) (*models.Met
return &metrics, nil
}

// GetExchangedBytesForNode - get exchanged bytes for current node peers
func GetExchangedBytesForNode(node *models.Node, metrics *models.Metrics) error {
host, err := logic.GetHost(node.HostID.String())
if err != nil {
return err
}
peers, err := logic.GetPeerUpdate(node, host)
if err != nil {
logger.Log(0, "Failed to get peers: ", err.Error())
return err
}
wgclient, err := wgctrl.New()
if err != nil {
return err
}
defer wgclient.Close()
device, err := wgclient.Device(models.WIREGUARD_INTERFACE)
if err != nil {
return err
}
for _, currPeer := range device.Peers {
id := peers.PeerIDs[currPeer.PublicKey.String()].ID
address := peers.PeerIDs[currPeer.PublicKey.String()].Address
if id == "" || address == "" {
logger.Log(0, "attempted to parse metrics for invalid peer from server", id, address)
continue
}
logger.Log(2, "collecting exchanged bytes info for peer: ", address)
peerMetric := metrics.Connectivity[id]
peerMetric.TotalReceived = currPeer.ReceiveBytes
peerMetric.TotalSent = currPeer.TransmitBytes
metrics.Connectivity[id] = peerMetric
}
return nil
}

// == used to fill zero value data for non connected peers ==
func fillUnconnectedData(metrics *models.Metrics, peerMap models.PeerMap) {
for r := range peerMap {
Expand Down
16 changes: 0 additions & 16 deletions logic/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,22 +382,6 @@ func FindRelay(node *models.Node) *models.Node {
return nil
}

func findNode(ip string) (*models.Node, error) {
nodes, err := GetAllNodes()
if err != nil {
return nil, err
}
for _, node := range nodes {
if node.Address.IP.String() == ip {
return &node, nil
}
if node.Address6.IP.String() == ip {
return &node, nil
}
}
return nil, errors.New("node not found")
}

// GetNetworkIngresses - gets the gateways of a network
func GetNetworkIngresses(network string) ([]models.Node, error) {
var ingresses []models.Node
Expand Down
Loading

0 comments on commit ce04cfc

Please sign in to comment.