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

Move PKA field from models node to host level

gabrielseibel1 2 жил өмнө
parent
commit
eca1064090
2 өөрчлөгдсөн 53 нэмэгдсэн , 56 устгасан
  1. 32 31
      models/host.go
  2. 21 25
      models/node.go

+ 32 - 31
models/host.go

@@ -1,11 +1,11 @@
 package models
 
 import (
-	"net"
-	"net/netip"
-
 	"github.com/google/uuid"
 	"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
+	"net"
+	"net/netip"
+	"time"
 )
 
 // OS_Types - list of OS types Netmaker cares about
@@ -37,34 +37,35 @@ const WIREGUARD_INTERFACE = "netmaker"
 
 // Host - represents a host on the network
 type Host struct {
-	ID                 uuid.UUID        `json:"id" yaml:"id"`
-	Verbosity          int              `json:"verbosity" yaml:"verbosity"`
-	FirewallInUse      string           `json:"firewallinuse" yaml:"firewallinuse"`
-	Version            string           `json:"version" yaml:"version"`
-	IPForwarding       bool             `json:"ipforwarding" yaml:"ipforwarding"`
-	DaemonInstalled    bool             `json:"daemoninstalled" yaml:"daemoninstalled"`
-	AutoUpdate         bool             `json:"autoupdate" yaml:"autoupdate"`
-	HostPass           string           `json:"hostpass" yaml:"hostpass"`
-	Name               string           `json:"name" yaml:"name"`
-	OS                 string           `json:"os" yaml:"os"`
-	Interface          string           `json:"interface" yaml:"interface"`
-	Debug              bool             `json:"debug" yaml:"debug"`
-	ListenPort         int              `json:"listenport" yaml:"listenport"`
-	WgPublicListenPort int              `json:"wg_public_listen_port" yaml:"wg_public_listen_port"`
-	MTU                int              `json:"mtu" yaml:"mtu"`
-	PublicKey          wgtypes.Key      `json:"publickey" yaml:"publickey"`
-	MacAddress         net.HardwareAddr `json:"macaddress" yaml:"macaddress"`
-	TrafficKeyPublic   []byte           `json:"traffickeypublic" yaml:"traffickeypublic"`
-	Nodes              []string         `json:"nodes" yaml:"nodes"`
-	Interfaces         []Iface          `json:"interfaces" yaml:"interfaces"`
-	DefaultInterface   string           `json:"defaultinterface" yaml:"defaultinterface"`
-	EndpointIP         net.IP           `json:"endpointip" yaml:"endpointip"`
-	IsDocker           bool             `json:"isdocker" yaml:"isdocker"`
-	IsK8S              bool             `json:"isk8s" yaml:"isk8s"`
-	IsStatic           bool             `json:"isstatic" yaml:"isstatic"`
-	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"`
+	ID                  uuid.UUID        `json:"id" yaml:"id"`
+	Verbosity           int              `json:"verbosity" yaml:"verbosity"`
+	FirewallInUse       string           `json:"firewallinuse" yaml:"firewallinuse"`
+	Version             string           `json:"version" yaml:"version"`
+	IPForwarding        bool             `json:"ipforwarding" yaml:"ipforwarding"`
+	DaemonInstalled     bool             `json:"daemoninstalled" yaml:"daemoninstalled"`
+	AutoUpdate          bool             `json:"autoupdate" yaml:"autoupdate"`
+	HostPass            string           `json:"hostpass" yaml:"hostpass"`
+	Name                string           `json:"name" yaml:"name"`
+	OS                  string           `json:"os" yaml:"os"`
+	Interface           string           `json:"interface" yaml:"interface"`
+	Debug               bool             `json:"debug" yaml:"debug"`
+	ListenPort          int              `json:"listenport" yaml:"listenport"`
+	WgPublicListenPort  int              `json:"wg_public_listen_port" yaml:"wg_public_listen_port"`
+	MTU                 int              `json:"mtu" yaml:"mtu"`
+	PublicKey           wgtypes.Key      `json:"publickey" yaml:"publickey"`
+	MacAddress          net.HardwareAddr `json:"macaddress" yaml:"macaddress"`
+	TrafficKeyPublic    []byte           `json:"traffickeypublic" yaml:"traffickeypublic"`
+	Nodes               []string         `json:"nodes" yaml:"nodes"`
+	Interfaces          []Iface          `json:"interfaces" yaml:"interfaces"`
+	DefaultInterface    string           `json:"defaultinterface" yaml:"defaultinterface"`
+	EndpointIP          net.IP           `json:"endpointip" yaml:"endpointip"`
+	IsDocker            bool             `json:"isdocker" yaml:"isdocker"`
+	IsK8S               bool             `json:"isk8s" yaml:"isk8s"`
+	IsStatic            bool             `json:"isstatic" yaml:"isstatic"`
+	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"`
+	PersistentKeepalive time.Duration    `json:"persistentkeepalive" yaml:"persistentkeepalive"`
 }
 
 // FormatBool converts a boolean to a [yes|no] string

+ 21 - 25
models/node.go

@@ -54,28 +54,27 @@ type Iface struct {
 
 // CommonNode - represents a commonn node data elements shared by netmaker and netclient
 type CommonNode struct {
-	ID                  uuid.UUID     `json:"id" yaml:"id"`
-	HostID              uuid.UUID     `json:"hostid" yaml:"hostid"`
-	Network             string        `json:"network" yaml:"network"`
-	NetworkRange        net.IPNet     `json:"networkrange" yaml:"networkrange"`
-	NetworkRange6       net.IPNet     `json:"networkrange6" yaml:"networkrange6"`
-	InternetGateway     *net.UDPAddr  `json:"internetgateway" yaml:"internetgateway"`
-	Server              string        `json:"server" yaml:"server"`
-	Connected           bool          `json:"connected" yaml:"connected"`
-	Address             net.IPNet     `json:"address" yaml:"address"`
-	Address6            net.IPNet     `json:"address6" yaml:"address6"`
-	Action              string        `json:"action" yaml:"action"`
-	LocalAddress        net.IPNet     `json:"localaddress" yaml:"localaddress"`
-	IsEgressGateway     bool          `json:"isegressgateway" yaml:"isegressgateway"`
-	EgressGatewayRanges []string      `json:"egressgatewayranges" bson:"egressgatewayranges" yaml:"egressgatewayranges"`
-	IsIngressGateway    bool          `json:"isingressgateway" yaml:"isingressgateway"`
-	IsRelayed           bool          `json:"isrelayed" bson:"isrelayed" yaml:"isrelayed"`
-	RelayedBy           string        `json:"relayedby" bson:"relayedby" yaml:"relayedby"`
-	IsRelay             bool          `json:"isrelay" bson:"isrelay" yaml:"isrelay"`
-	RelayedNodes        []string      `json:"relaynodes" yaml:"relayedNodes"`
-	IngressDNS          string        `json:"ingressdns" yaml:"ingressdns"`
-	DNSOn               bool          `json:"dnson" yaml:"dnson"`
-	PersistentKeepalive time.Duration `json:"persistentkeepalive" yaml:"persistentkeepalive"`
+	ID                  uuid.UUID    `json:"id" yaml:"id"`
+	HostID              uuid.UUID    `json:"hostid" yaml:"hostid"`
+	Network             string       `json:"network" yaml:"network"`
+	NetworkRange        net.IPNet    `json:"networkrange" yaml:"networkrange"`
+	NetworkRange6       net.IPNet    `json:"networkrange6" yaml:"networkrange6"`
+	InternetGateway     *net.UDPAddr `json:"internetgateway" yaml:"internetgateway"`
+	Server              string       `json:"server" yaml:"server"`
+	Connected           bool         `json:"connected" yaml:"connected"`
+	Address             net.IPNet    `json:"address" yaml:"address"`
+	Address6            net.IPNet    `json:"address6" yaml:"address6"`
+	Action              string       `json:"action" yaml:"action"`
+	LocalAddress        net.IPNet    `json:"localaddress" yaml:"localaddress"`
+	IsEgressGateway     bool         `json:"isegressgateway" yaml:"isegressgateway"`
+	EgressGatewayRanges []string     `json:"egressgatewayranges" bson:"egressgatewayranges" yaml:"egressgatewayranges"`
+	IsIngressGateway    bool         `json:"isingressgateway" yaml:"isingressgateway"`
+	IsRelayed           bool         `json:"isrelayed" bson:"isrelayed" yaml:"isrelayed"`
+	RelayedBy           string       `json:"relayedby" bson:"relayedby" yaml:"relayedby"`
+	IsRelay             bool         `json:"isrelay" bson:"isrelay" yaml:"isrelay"`
+	RelayedNodes        []string     `json:"relaynodes" yaml:"relayedNodes"`
+	IngressDNS          string       `json:"ingressdns" yaml:"ingressdns"`
+	DNSOn               bool         `json:"dnson" yaml:"dnson"`
 }
 
 // Node - a model of a network node
@@ -369,9 +368,6 @@ func (newNode *Node) Fill(currentNode *Node, isPro bool) { // TODO add new field
 	if newNode.Address6.String() == "" {
 		newNode.Address6 = currentNode.Address6
 	}
-	if newNode.PersistentKeepalive < 0 {
-		newNode.PersistentKeepalive = currentNode.PersistentKeepalive
-	}
 	if newNode.LastModified != currentNode.LastModified {
 		newNode.LastModified = currentNode.LastModified
 	}