Browse Source

refactor + bugs

0xdcarns 3 years ago
parent
commit
cfb0904bd6
2 changed files with 8 additions and 0 deletions
  1. 3 0
      netclient/functions/join.go
  2. 5 0
      netclient/functions/pull.go

+ 3 - 0
netclient/functions/join.go

@@ -144,6 +144,9 @@ func JoinNetwork(cfg *config.ClientConfig, privateKey string) error {
 		return fmt.Errorf("error decoding node from server %w %s", err, string(bodybytes))
 	}
 	node := nodeGET.Node
+	if nodeGET.Peers == nil {
+		nodeGET.Peers = []wgtypes.PeerConfig{}
+	}
 	// safety check. If returned node from server is local, but not currently configured as local, set to local addr
 	if cfg.Node.IsLocal != "yes" && node.IsLocal == "yes" && node.LocalRange != "" {
 		node.LocalAddress, err = ncutils.GetLocalIP(node.LocalRange)

+ 5 - 0
netclient/functions/pull.go

@@ -15,6 +15,7 @@ import (
 	"github.com/gravitl/netmaker/netclient/local"
 	"github.com/gravitl/netmaker/netclient/ncutils"
 	"github.com/gravitl/netmaker/netclient/wireguard"
+	"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
 	//homedir "github.com/mitchellh/go-homedir"
 )
 
@@ -53,6 +54,10 @@ func Pull(network string, iface bool) (*models.Node, error) {
 	resNode := nodeGET.Node
 	// ensure that the OS never changes
 	resNode.OS = runtime.GOOS
+	if nodeGET.Peers == nil {
+		nodeGET.Peers = []wgtypes.PeerConfig{}
+	}
+
 	if iface {
 		if err = config.ModConfig(&resNode); err != nil {
 			return nil, err