Browse Source

merge conflicts resolved

Abhishek Kondur 2 years ago
parent
commit
695e3b1661

+ 2 - 2
models/node.go

@@ -60,7 +60,7 @@ type Node struct {
 	Address6                string               `json:"address6" bson:"address6" yaml:"address6" validate:"omitempty,ipv6"`
 	LocalAddress            string               `json:"localaddress" bson:"localaddress" yaml:"localaddress" validate:"omitempty"`
 	Interfaces              []Iface              `json:"interfaces" yaml:"interfaces"`
-	Name                    string               `json:"name" bson:"name" yaml:"name"`
+	Name                    string               `json:"name" bson:"name" yaml:"name" validate:"omitempty,max=62,in_charset"`
 	NetworkSettings         Network              `json:"networksettings" bson:"networksettings" yaml:"networksettings" validate:"-"`
 	ListenPort              int32                `json:"listenport" bson:"listenport" yaml:"listenport" validate:"omitempty,numeric,min=1024,max=65535"`
 	LocalListenPort         int32                `json:"locallistenport" bson:"locallistenport" yaml:"locallistenport" validate:"numeric,min=0,max=65535"`
@@ -112,11 +112,11 @@ type Node struct {
 	InternetGateway string      `json:"internetgateway" bson:"internetgateway" yaml:"internetgateway"`
 	Connected       string      `json:"connected" bson:"connected" yaml:"connected" validate:"checkyesorno"`
 	PendingDelete   bool        `json:"pendingdelete" bson:"pendingdelete" yaml:"pendingdelete"`
+	Proxy           bool        `json:"proxy" bson:"proxy" yaml:"proxy"`
 	// == PRO ==
 	DefaultACL string `json:"defaultacl,omitempty" bson:"defaultacl,omitempty" yaml:"defaultacl,omitempty" validate:"checkyesornoorunset"`
 	OwnerID    string `json:"ownerid,omitempty" bson:"ownerid,omitempty" yaml:"ownerid,omitempty"`
 	Failover   string `json:"failover" bson:"failover" yaml:"failover" validate:"checkyesorno"`
-	Proxy      bool   `json:"proxy" bson:"proxy" yaml:"proxy"`
 }
 
 // NodesArray - used for node sorting

+ 1 - 1
netclient/cli_options/flags.go

@@ -71,7 +71,7 @@ func GetFlags(hostname string) []cli.Flag {
 			Aliases: []string{"os"},
 			EnvVars: []string{"NETCLIENT_OS"},
 			Value:   "",
-			Usage:   "Identifiable name for machine within Netmaker network.",
+			Usage:   "Operating system of machine (linux, darwin, windows, freebsd).",
 		},
 		&cli.StringFlag{
 			Name:    "publicipservice",

+ 31 - 0
netclient/functions/common.go

@@ -128,6 +128,37 @@ func getPrivateAddrBackup() (string, error) {
 	return local, err
 }
 
+func getInterfaces() (*[]models.Iface, error) {
+	ifaces, err := net.Interfaces()
+	if err != nil {
+		return nil, err
+	}
+	var data []models.Iface
+	var link models.Iface
+	for _, iface := range ifaces {
+		if iface.Flags&net.FlagUp == 0 {
+			continue // interface down
+		}
+		if iface.Flags&net.FlagLoopback != 0 {
+			continue // loopback interface
+		}
+		addrs, err := iface.Addrs()
+		if err != nil {
+			return nil, err
+		}
+		for _, addr := range addrs {
+			link.Name = iface.Name
+			_, cidr, err := net.ParseCIDR(addr.String())
+			if err != nil {
+				continue
+			}
+			link.Address = *cidr
+			data = append(data, link)
+		}
+	}
+	return &data, nil
+}
+
 // GetNode - gets node locally
 func GetNode(network string) models.Node {
 

+ 8 - 0
netclient/functions/join.go

@@ -238,6 +238,14 @@ func JoinNetwork(cfg *config.ClientConfig, privateKey string) error {
 			logger.Log(1, "network:", cfg.Network, "error retrieving private address: ", err.Error())
 		}
 	}
+	if len(cfg.Node.Interfaces) == 0 {
+		ip, err := getInterfaces()
+		if err != nil {
+			logger.Log(0, "failed to retrive local interfaces", err.Error())
+		} else {
+			cfg.Node.Interfaces = *ip
+		}
+	}
 
 	// set endpoint if blank. set to local if local net, retrieve from function if not
 	if cfg.Node.Endpoint == "" {

+ 8 - 0
netclient/functions/mqpublish.go

@@ -140,6 +140,14 @@ func Hello(nodeCfg *config.ClientConfig) {
 	var checkin models.NodeCheckin
 	checkin.Version = ncutils.Version
 	checkin.Connected = nodeCfg.Node.Connected
+	ip, err := getInterfaces()
+	if err != nil {
+		logger.Log(0, "failed to retrieve local interfaces", err.Error())
+	} else {
+		nodeCfg.Node.Interfaces = *ip
+		config.Write(nodeCfg, nodeCfg.Network)
+	}
+	checkin.Ifaces = nodeCfg.Node.Interfaces
 	data, err := json.Marshal(checkin)
 	if err != nil {
 		logger.Log(0, "unable to marshal checkin data", err.Error())