2
0
Эх сурвалжийг харах

seperate static port and static endpoint

Max Ma 1 жил өмнө
parent
commit
81a6c9cf8a

+ 14 - 11
cli/cmd/host/update.go

@@ -12,15 +12,16 @@ import (
 )
 
 var (
-	apiHostFilePath string
-	endpoint        string
-	endpoint6       string
-	name            string
-	listenPort      int
-	mtu             int
-	isStatic        bool
-	isDefault       bool
-	keepAlive       int
+	apiHostFilePath  string
+	endpoint         string
+	endpoint6        string
+	name             string
+	listenPort       int
+	mtu              int
+	isStaticPort     bool
+	isStaticEndpoint bool
+	isDefault        bool
+	keepAlive        int
 )
 
 var hostUpdateCmd = &cobra.Command{
@@ -45,7 +46,8 @@ var hostUpdateCmd = &cobra.Command{
 			apiHost.Name = name
 			apiHost.ListenPort = listenPort
 			apiHost.MTU = mtu
-			apiHost.IsStatic = isStatic
+			apiHost.IsStaticPort = isStaticPort
+			apiHost.IsStaticEndpoint = isStaticEndpoint
 			apiHost.IsDefault = isDefault
 			apiHost.PersistentKeepalive = keepAlive
 		}
@@ -61,7 +63,8 @@ func init() {
 	hostUpdateCmd.Flags().IntVar(&listenPort, "listen_port", 0, "Listen port of the host")
 	hostUpdateCmd.Flags().IntVar(&mtu, "mtu", 0, "Host MTU size")
 	hostUpdateCmd.Flags().IntVar(&keepAlive, "keep_alive", 0, "Interval (seconds) in which packets are sent to keep connections open with peers")
-	hostUpdateCmd.Flags().BoolVar(&isStatic, "static", false, "Make Host Static ?")
+	hostUpdateCmd.Flags().BoolVar(&isStaticPort, "static_port", false, "Make Host Static Port?")
+	hostUpdateCmd.Flags().BoolVar(&isStaticEndpoint, "static_endpoint", false, "Make Host Static Endpoint?")
 	hostUpdateCmd.Flags().BoolVar(&isDefault, "default", false, "Make Host Default ?")
 	rootCmd.AddCommand(hostUpdateCmd)
 }

+ 2 - 1
controllers/migrate.go

@@ -150,7 +150,8 @@ func convertLegacyHostNode(legacy models.LegacyNode) (models.Host, models.Node)
 	host.EndpointIP = net.ParseIP(legacy.Endpoint)
 	host.IsDocker = models.ParseBool(legacy.IsDocker)
 	host.IsK8S = models.ParseBool(legacy.IsK8S)
-	host.IsStatic = models.ParseBool(legacy.IsStatic)
+	host.IsStaticPort = models.ParseBool(legacy.IsStatic)
+	host.IsStaticEndpoint = models.ParseBool(legacy.IsStatic)
 	host.PersistentKeepalive = time.Duration(legacy.PersistentKeepalive) * time.Second
 	if host.PersistentKeepalive == 0 {
 		host.PersistentKeepalive = models.DefaultPersistentKeepAlive

+ 2 - 1
logic/hosts.go

@@ -266,7 +266,8 @@ func UpdateHostFromClient(newHost, currHost *models.Host) (sendPeerUpdate bool)
 	currHost.Debug = newHost.Debug
 	currHost.Verbosity = newHost.Verbosity
 	currHost.Version = newHost.Version
-	currHost.IsStatic = newHost.IsStatic
+	currHost.IsStaticPort = newHost.IsStaticPort
+	currHost.IsStaticEndpoint = newHost.IsStaticEndpoint
 	currHost.MTU = newHost.MTU
 	currHost.Name = newHost.Name
 	if len(newHost.NatType) > 0 && newHost.NatType != currHost.NatType {

+ 8 - 6
logic/peers.go

@@ -249,9 +249,10 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
 				hostPeerUpdate.Peers = append(hostPeerUpdate.Peers, peerConfig)
 				peerIndexMap[peerHost.PublicKey.String()] = len(hostPeerUpdate.Peers) - 1
 				hostPeerUpdate.HostNetworkInfo[peerHost.PublicKey.String()] = models.HostNetworkInfo{
-					Interfaces: peerHost.Interfaces,
-					ListenPort: peerHost.ListenPort,
-					IsStatic:   peerHost.IsStatic,
+					Interfaces:       peerHost.Interfaces,
+					ListenPort:       peerHost.ListenPort,
+					IsStaticPort:     peerHost.IsStaticPort,
+					IsStaticEndpoint: peerHost.IsStaticEndpoint,
 				}
 				nodePeer = peerConfig
 			} else {
@@ -260,9 +261,10 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
 				hostPeerUpdate.Peers[peerIndexMap[peerHost.PublicKey.String()]].AllowedIPs = peerAllowedIPs
 				hostPeerUpdate.Peers[peerIndexMap[peerHost.PublicKey.String()]].Remove = false
 				hostPeerUpdate.HostNetworkInfo[peerHost.PublicKey.String()] = models.HostNetworkInfo{
-					Interfaces: peerHost.Interfaces,
-					ListenPort: peerHost.ListenPort,
-					IsStatic:   peerHost.IsStatic,
+					Interfaces:       peerHost.Interfaces,
+					ListenPort:       peerHost.ListenPort,
+					IsStaticPort:     peerHost.IsStaticPort,
+					IsStaticEndpoint: peerHost.IsStaticEndpoint,
 				}
 				nodePeer = hostPeerUpdate.Peers[peerIndexMap[peerHost.PublicKey.String()]]
 			}

+ 6 - 3
models/api_host.go

@@ -15,7 +15,8 @@ type ApiHost struct {
 	Name                string     `json:"name"`
 	OS                  string     `json:"os"`
 	Debug               bool       `json:"debug"`
-	IsStatic            bool       `json:"isstatic"`
+	IsStaticPort        bool       `json:"isstaticport"`
+	IsStaticEndpoint    bool       `json:"isstaticendpoint"`
 	ListenPort          int        `json:"listenport"`
 	WgPublicListenPort  int        `json:"wg_public_listen_port" yaml:"wg_public_listen_port"`
 	MTU                 int        `json:"mtu"                   yaml:"mtu"`
@@ -61,7 +62,8 @@ func (h *Host) ConvertNMHostToAPI() *ApiHost {
 		}
 	}
 	a.DefaultInterface = h.DefaultInterface
-	a.IsStatic = h.IsStatic
+	a.IsStaticPort = h.IsStaticPort
+	a.IsStaticEndpoint = h.IsStaticEndpoint
 	a.ListenPort = h.ListenPort
 	a.MTU = h.MTU
 	a.MacAddress = h.MacAddress.String()
@@ -104,7 +106,8 @@ func (a *ApiHost) ConvertAPIHostToNMHost(currentHost *Host) *Host {
 	h.DefaultInterface = currentHost.DefaultInterface
 	h.IsDocker = currentHost.IsDocker
 	h.IsK8S = currentHost.IsK8S
-	h.IsStatic = a.IsStatic
+	h.IsStaticPort = a.IsStaticPort
+	h.IsStaticEndpoint = a.IsStaticEndpoint
 	h.ListenPort = a.ListenPort
 	h.MTU = a.MTU
 	h.MacAddress = currentHost.MacAddress

+ 2 - 1
models/host.go

@@ -66,7 +66,8 @@ type Host struct {
 	EndpointIPv6        net.IP           `json:"endpointipv6"            yaml:"endpointipv6"`
 	IsDocker            bool             `json:"isdocker"                yaml:"isdocker"`
 	IsK8S               bool             `json:"isk8s"                   yaml:"isk8s"`
-	IsStatic            bool             `json:"isstatic"                yaml:"isstatic"`
+	IsStaticPort        bool             `json:"isstaticport"            yaml:"isstaticport"`
+	IsStaticEndpoint    bool             `json:"isstaticendpoint"        yaml:"isstaticendpoint"`
 	IsDefault           bool             `json:"isdefault"               yaml:"isdefault"`
 	NatType             string           `json:"nat_type,omitempty"      yaml:"nat_type,omitempty"`
 	TurnEndpoint        *netip.AddrPort  `json:"turn_endpoint,omitempty" yaml:"turn_endpoint,omitempty"`

+ 4 - 3
models/metrics.go

@@ -42,9 +42,10 @@ type HostInfoMap map[string]HostNetworkInfo
 
 // HostNetworkInfo - holds info related to host networking (used for client side peer calculations)
 type HostNetworkInfo struct {
-	Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
-	ListenPort int     `json:"listen_port" yaml:"listen_port"`
-	IsStatic   bool    `json:"is_static"`
+	Interfaces       []Iface `json:"interfaces" yaml:"interfaces"`
+	ListenPort       int     `json:"listen_port" yaml:"listen_port"`
+	IsStaticPort     bool    `json:"is_static_port"`
+	IsStaticEndpoint bool    `json:"is_static_endpoint"`
 }
 
 // PeerMap - peer map for ids and addresses in metrics

+ 1 - 1
models/node.go

@@ -569,7 +569,7 @@ func (n *Node) Legacy(h *Host, s *ServerConfig, net *Network) *LegacyNode {
 	//l.FailoverNode = n.FailoverNode
 	//l.IngressGatewayRange = n.IngressGatewayRange
 	//l.IngressGatewayRange6 = n.IngressGatewayRange6
-	l.IsStatic = formatBool(h.IsStatic)
+	l.IsStatic = formatBool(h.IsStaticPort)
 	l.UDPHolePunch = formatBool(true)
 	l.DNSOn = formatBool(n.DNSOn)
 	l.Action = n.Action