mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-10 23:24:32 +08:00
added turn ep + nat type to host model
This commit is contained in:
parent
b1b4fb821e
commit
fa40a5929d
4 changed files with 39 additions and 9 deletions
|
@ -178,6 +178,11 @@ func UpdateHostFromClient(newHost, currHost *models.Host) (sendPeerUpdate bool)
|
|||
if newHost.Name != "" {
|
||||
currHost.Name = newHost.Name
|
||||
}
|
||||
if len(newHost.NatType) > 0 && newHost.NatType != currHost.NatType {
|
||||
currHost.NatType = newHost.NatType
|
||||
logger.Log(0, "updated host nat type", newHost.Name, newHost.NatType)
|
||||
sendPeerUpdate = true
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ type ApiHost struct {
|
|||
RelayedBy string `json:"relayed_by" bson:"relayed_by" yaml:"relayed_by"`
|
||||
IsRelay bool `json:"isrelay" bson:"isrelay" yaml:"isrelay"`
|
||||
RelayedHosts []string `json:"relay_hosts" bson:"relay_hosts" yaml:"relay_hosts"`
|
||||
NatType string `json:"nat_type" bson:"nat_type" yaml:"nat_type"`
|
||||
}
|
||||
|
||||
// Host.ConvertNMHostToAPI - converts a Netmaker host to an API editable host
|
||||
|
@ -112,6 +113,8 @@ func (a *ApiHost) ConvertAPIHostToNMHost(currentHost *Host) *Host {
|
|||
h.IsRelayed = a.IsRelayed
|
||||
h.ProxyEnabled = a.ProxyEnabled
|
||||
h.IsDefault = a.IsDefault
|
||||
h.NatType = currentHost.NatType
|
||||
h.TurnEndpoint = currentHost.TurnEndpoint
|
||||
|
||||
return &h
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package models
|
|||
|
||||
import (
|
||||
"net"
|
||||
"net/netip"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
|
@ -22,6 +23,19 @@ var OS_Types = struct {
|
|||
IoT: "iot",
|
||||
}
|
||||
|
||||
// NAT_Types - the type of NAT in which a HOST currently resides (simplified)
|
||||
var NAT_Types = struct {
|
||||
Public string
|
||||
Symmetric string
|
||||
Asymmetric string
|
||||
Double string
|
||||
}{
|
||||
Public: "public",
|
||||
Symmetric: "symmetric",
|
||||
Asymmetric: "asymmetric",
|
||||
Double: "double",
|
||||
}
|
||||
|
||||
// WIREGUARD_INTERFACE name of wireguard interface
|
||||
const WIREGUARD_INTERFACE = "netmaker"
|
||||
|
||||
|
@ -60,6 +74,8 @@ type Host struct {
|
|||
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"`
|
||||
}
|
||||
|
||||
// FormatBool converts a boolean to a [yes|no] string
|
||||
|
|
|
@ -396,16 +396,22 @@ func handleHostCheckin(h, currentHost *models.Host) bool {
|
|||
for i := range h.Interfaces {
|
||||
h.Interfaces[i].AddressString = h.Interfaces[i].Address.String()
|
||||
}
|
||||
ifaceDelta := len(h.Interfaces) != len(currentHost.Interfaces) || !h.EndpointIP.Equal(currentHost.EndpointIP)
|
||||
currentHost.EndpointIP = h.EndpointIP
|
||||
currentHost.Interfaces = h.Interfaces
|
||||
currentHost.DefaultInterface = h.DefaultInterface
|
||||
if err := logic.UpsertHost(currentHost); err != nil {
|
||||
logger.Log(0, "failed to update host after check-in", h.Name, h.ID.String(), err.Error())
|
||||
return false
|
||||
ifaceDelta := len(h.Interfaces) != len(currentHost.Interfaces) ||
|
||||
!h.EndpointIP.Equal(currentHost.EndpointIP) ||
|
||||
(len(h.NatType) > 0 && h.NatType != currentHost.NatType) ||
|
||||
h.DefaultInterface != currentHost.DefaultInterface
|
||||
if ifaceDelta { // only save if something changes
|
||||
currentHost.EndpointIP = h.EndpointIP
|
||||
currentHost.Interfaces = h.Interfaces
|
||||
currentHost.DefaultInterface = h.DefaultInterface
|
||||
currentHost.NatType = h.NatType
|
||||
if err := logic.UpsertHost(currentHost); err != nil {
|
||||
logger.Log(0, "failed to update host after check-in", h.Name, h.ID.String(), err.Error())
|
||||
return false
|
||||
}
|
||||
logger.Log(1, "updated host after check-in", currentHost.Name, currentHost.ID.String())
|
||||
}
|
||||
|
||||
logger.Log(0, "ping processed for host", h.Name, h.ID.String())
|
||||
logger.Log(2, "check-in processed for host", h.Name, h.ID.String())
|
||||
return ifaceDelta
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue