浏览代码

add migration logic for ManageDNS

abhishek9686 3 月之前
父节点
当前提交
40e4a0c1a5
共有 6 个文件被更改,包括 19 次插入3 次删除
  1. 6 0
      logic/hosts.go
  2. 3 0
      logic/peers.go
  3. 7 0
      migrate/migrate.go
  4. 1 1
      models/api_host.go
  5. 1 1
      models/host.go
  6. 1 1
      servercfg/serverconf.go

+ 6 - 0
logic/hosts.go

@@ -229,6 +229,12 @@ func CreateHost(h *models.Host) error {
 	}
 	h.HostPass = string(hash)
 	h.AutoUpdate = AutoUpdateEnabled()
+
+	if GetServerSettings().ManageDNS {
+		h.DNS = "on"
+	} else {
+		h.DNS = "off"
+	}
 	checkForZombieHosts(h)
 	return UpsertHost(h)
 }

+ 3 - 0
logic/peers.go

@@ -141,6 +141,9 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
 		HostNetworkInfo: models.HostInfoMap{},
 		ServerConfig:    GetServerInfo(),
 	}
+	if host.DNS == "off" {
+		hostPeerUpdate.ManageDNS = false
+	}
 	defer func() {
 		if !hostPeerUpdate.FwUpdate.AllowAll {
 

+ 7 - 0
migrate/migrate.go

@@ -196,6 +196,13 @@ func updateHosts() {
 				continue
 			}
 		}
+		if host.DNS == "" {
+			if logic.GetServerSettings().ManageDNS {
+				host.DNS = "on"
+			} else {
+				host.DNS = "off"
+			}
+		}
 	}
 }
 

+ 1 - 1
models/api_host.go

@@ -31,7 +31,7 @@ type ApiHost struct {
 	NatType             string     `json:"nat_type"              yaml:"nat_type"`
 	PersistentKeepalive int        `json:"persistentkeepalive"   yaml:"persistentkeepalive"`
 	AutoUpdate          bool       `json:"autoupdate"              yaml:"autoupdate"`
-	DNS                 bool       `json:"dns"               yaml:"dns"`
+	DNS                 string     `json:"dns"               yaml:"dns"`
 }
 
 // ApiIface - the interface struct for API usage

+ 1 - 1
models/host.go

@@ -69,7 +69,7 @@ type Host struct {
 	IsStaticPort        bool             `json:"isstaticport"            yaml:"isstaticport"`
 	IsStatic            bool             `json:"isstatic"        yaml:"isstatic"`
 	IsDefault           bool             `json:"isdefault"               yaml:"isdefault"`
-	DNS                 bool             `json:"dns"               yaml:"dns"`
+	DNS                 string           `json:"dns"               yaml:"dns"`
 	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" swaggertype:"primitive,integer" format:"int64" yaml:"persistentkeepalive"`

+ 1 - 1
servercfg/serverconf.go

@@ -685,7 +685,7 @@ func GetMetricInterval() string {
 
 // GetManageDNS - if manage DNS enabled or not
 func GetManageDNS() bool {
-	enabled := false
+	enabled := true
 	if os.Getenv("MANAGE_DNS") != "" {
 		enabled = os.Getenv("MANAGE_DNS") == "true"
 	}