diff --git a/models/node.go b/models/node.go index 37a78282..99cf31c4 100644 --- a/models/node.go +++ b/models/node.go @@ -37,7 +37,7 @@ type Node struct { Address string `json:"address" bson:"address" yaml:"address" validate:"omitempty,ipv4"` Address6 string `json:"address6" bson:"address6" yaml:"address6" validate:"omitempty,ipv6"` LocalAddress string `json:"localaddress" bson:"localaddress" yaml:"localaddress" validate:"omitempty,ip"` - LocalListenPort int32 `json:"locallistenport" bson:"locallistenport" yaml:"locallistenport" validate:"numeric,min=1024,max=65535"` + LocalListenPort int32 `json:"locallistenport" bson:"locallistenport" yaml:"locallistenport" validate:"numeric,min=0,max=65535"` 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"` @@ -272,9 +272,6 @@ func (newNode *Node) Fill(currentNode *Node) { if newNode.LocalListenPort == 0 && newNode.IsStatic != "yes" { newNode.LocalListenPort = currentNode.LocalListenPort } - if newNode.LocalListenPort == 0 { - newNode.LocalListenPort = currentNode.ListenPort - } if newNode.PublicKey == "" && newNode.IsStatic != "yes" { newNode.PublicKey = currentNode.PublicKey } diff --git a/netclient/config/config.go b/netclient/config/config.go index 4e8348a6..c8b4ef60 100644 --- a/netclient/config/config.go +++ b/netclient/config/config.go @@ -241,7 +241,6 @@ func GetCLIConfig(c *cli.Context) (ClientConfig, string, error) { cfg.Node.PostUp = c.String("postup") cfg.Node.PostDown = c.String("postdown") cfg.Node.ListenPort = int32(c.Int("port")) - cfg.Node.LocalListenPort = int32(c.Int("localport")) cfg.Node.PersistentKeepalive = int32(c.Int("keepalive")) cfg.Node.PublicKey = c.String("publickey") privateKey := c.String("privatekey") diff --git a/netclient/functions/mqpublish.go b/netclient/functions/mqpublish.go index 911ee1ac..82ef6b2b 100644 --- a/netclient/functions/mqpublish.go +++ b/netclient/functions/mqpublish.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "os" + "strconv" "sync" "time" @@ -68,12 +69,11 @@ func Checkin(ctx context.Context, wg *sync.WaitGroup) { deviceiface = nodeCfg.Node.Interface } } - localPort, err := local.GetLocalListenPort(deviceiface) - if err != nil { - logger.Log(1, "error encountered checking private ip addresses: ", err.Error()) - } - if nodeCfg.Node.LocalListenPort != localPort && localPort != 0 { - logger.Log(1, "local port has changed from ", string(nodeCfg.Node.LocalListenPort), " to ", string(localPort)) + localPort, errN := local.GetLocalListenPort(deviceiface) + if errN != nil { + logger.Log(1, "error encountered checking local listen port: ", err.Error()) + } else if nodeCfg.Node.LocalListenPort != localPort && localPort != 0 { + logger.Log(1, "local port has changed from ", strconv.Itoa(int(nodeCfg.Node.LocalListenPort)), " to ", strconv.Itoa(int(localPort))) nodeCfg.Node.LocalListenPort = localPort if err := PublishNodeUpdate(&nodeCfg); err != nil { logger.Log(0, "could not publish local port change") diff --git a/netclient/local/local.go b/netclient/local/local.go index 90c4a27e..b158ca22 100644 --- a/netclient/local/local.go +++ b/netclient/local/local.go @@ -129,6 +129,7 @@ func GetLocalListenPort(ifacename string) (int32, error) { if err != nil { return 0, err } + portstring = strings.TrimSuffix(portstring, "\n") i, err := strconv.ParseInt(portstring, 10, 32) if err != nil { return 0, err