Explorar o código

added netmaker check on checkin

afeiszli %!s(int64=4) %!d(string=hai) anos
pai
achega
4385131bc6
Modificáronse 3 ficheiros con 7 adicións e 13 borrados
  1. 1 1
      controllers/common.go
  2. 5 0
      functions/helpers.go
  3. 1 12
      serverctl/wireguard.go

+ 1 - 1
controllers/common.go

@@ -45,7 +45,7 @@ func GetPeersList(networkName string) ([]models.PeersResponse, error) {
 			peer.EgressGatewayRanges = strings.Join(node.EgressGatewayRanges, ",")
 		}
 		if node.Network == networkName && node.IsPending != "yes" {
-			if node.UDPHolePunch == "yes" && errN == nil {
+			if node.UDPHolePunch == "yes" && errN == nil && functions.IsBase64(peer.PublicKey) && functions.CheckEndpoint(peer.Endpoint) {
 				endpointstring := udppeers[peer.PublicKey]
 				endpointarr := strings.Split(endpointstring, ":")
 				log.Println("got values:",endpointstring,endpointarr)

+ 5 - 0
functions/helpers.go

@@ -20,6 +20,11 @@ import (
 	"github.com/gravitl/netmaker/servercfg"
 )
 
+func CheckEndpoint(endpoint string) bool {
+    endpointarr := strings.Split(endpoint,":")
+	return net.ParseIP(endpointarr[0]) == nil
+}
+
 func PrintUserLog(username string, message string, loglevel int) {
 	log.SetFlags(log.Flags() &^ (log.Llongfile | log.Lshortfile))
 	if int32(loglevel) <= servercfg.GetVerbose() && servercfg.GetVerbose() != 0 {

+ 1 - 12
serverctl/wireguard.go

@@ -9,8 +9,6 @@ import (
 	"net"
 	"os"
 	"strconv"
-	"strings"
-	"encoding/base64"
 	"github.com/gravitl/netmaker/database"
 	"github.com/gravitl/netmaker/functions"
 	"github.com/gravitl/netmaker/models"
@@ -202,19 +200,10 @@ func GetPeers(networkName string) (map[string]string, error) {
 		return nil, err
 	}
 	for _, peer := range device.Peers {
-		if isBase64(peer.PublicKey.String()) && checkEndpoint(peer.Endpoint.String()) {
+		if functions.IsBase64(peer.PublicKey.String()) && functions.CheckEndpoint(peer.Endpoint.String()) {
 			peers[peer.PublicKey.String()] = peer.Endpoint.String()
 		}
 	}
 	return peers, nil
 }
 
-func checkEndpoint(endpoint string) bool {
-    endpointarr := strings.Split(endpoint,":")
-	return net.ParseIP(endpointarr[0]) == nil
-}
-
-func isBase64(s string) bool {
-	_, err := base64.StdEncoding.DecodeString(s)
-	return err == nil
-}