mirror of
https://github.com/gravitl/netmaker.git
synced 2024-09-20 15:26:04 +08:00
b78cc0a8a1
* api to to get host relayed from client * add auto relay to api host * add peer nat type * set pro field on signal * rm net check on relay me handler * return success response * re-establish failover logic * set failOver ctx * failOver with peer pub key * failovered peer updates * failover handlers, reset failovered peer on deletion * rm unused funcs * initialize failover handler on EE * ignore failover node on signal * failover changes * set host id on signal * extend signal model to include node ids * add backwards compatibility * add failover as node api * set json response on failover handers * add failover field to api node * fix signal data check * initialize failover peer map * reset failovered status when relayed or deleted * add failover info to api node * reset network failover * only proceed furtuer if failover exists in the network * set failOver node defaults * cannot set failover node as relayed * debug log * debug log * debug changes * debug changes * debug changes * revert debug changes * don't add peers to idmap when removed * reset failed Over * fix static checks * rm debug log * add check for linux host
102 lines
3.5 KiB
Go
102 lines
3.5 KiB
Go
package models
|
|
|
|
import (
|
|
"net"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// ApiHost - the host struct for API usage
|
|
type ApiHost struct {
|
|
ID string `json:"id"`
|
|
Verbosity int `json:"verbosity"`
|
|
FirewallInUse string `json:"firewallinuse"`
|
|
Version string `json:"version"`
|
|
Name string `json:"name"`
|
|
OS string `json:"os"`
|
|
Debug bool `json:"debug"`
|
|
IsStatic bool `json:"isstatic"`
|
|
ListenPort int `json:"listenport"`
|
|
WgPublicListenPort int `json:"wg_public_listen_port" yaml:"wg_public_listen_port"`
|
|
MTU int `json:"mtu" yaml:"mtu"`
|
|
Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
|
|
DefaultInterface string `json:"defaultinterface" yaml:"defautlinterface"`
|
|
EndpointIP string `json:"endpointip" yaml:"endpointip"`
|
|
PublicKey string `json:"publickey"`
|
|
MacAddress string `json:"macaddress"`
|
|
Nodes []string `json:"nodes"`
|
|
IsDefault bool `json:"isdefault" yaml:"isdefault"`
|
|
NatType string `json:"nat_type" yaml:"nat_type"`
|
|
PersistentKeepalive int `json:"persistentkeepalive" yaml:"persistentkeepalive"`
|
|
AutoUpdate bool `json:"autoupdate" yaml:"autoupdate"`
|
|
}
|
|
|
|
// Host.ConvertNMHostToAPI - converts a Netmaker host to an API editable host
|
|
func (h *Host) ConvertNMHostToAPI() *ApiHost {
|
|
a := ApiHost{}
|
|
a.Debug = h.Debug
|
|
a.EndpointIP = h.EndpointIP.String()
|
|
a.FirewallInUse = h.FirewallInUse
|
|
a.ID = h.ID.String()
|
|
a.Interfaces = h.Interfaces
|
|
for i := range a.Interfaces {
|
|
a.Interfaces[i].AddressString = a.Interfaces[i].Address.String()
|
|
}
|
|
a.DefaultInterface = h.DefaultInterface
|
|
a.IsStatic = h.IsStatic
|
|
a.ListenPort = h.ListenPort
|
|
a.MTU = h.MTU
|
|
a.MacAddress = h.MacAddress.String()
|
|
a.Name = h.Name
|
|
a.OS = h.OS
|
|
a.Nodes = h.Nodes
|
|
a.WgPublicListenPort = h.WgPublicListenPort
|
|
a.PublicKey = h.PublicKey.String()
|
|
a.Verbosity = h.Verbosity
|
|
a.Version = h.Version
|
|
a.IsDefault = h.IsDefault
|
|
a.NatType = h.NatType
|
|
a.PersistentKeepalive = int(h.PersistentKeepalive.Seconds())
|
|
a.AutoUpdate = h.AutoUpdate
|
|
return &a
|
|
}
|
|
|
|
// APIHost.ConvertAPIHostToNMHost - convert's a given apihost struct to
|
|
// a Host struct
|
|
func (a *ApiHost) ConvertAPIHostToNMHost(currentHost *Host) *Host {
|
|
h := Host{}
|
|
h.ID = currentHost.ID
|
|
h.HostPass = currentHost.HostPass
|
|
h.DaemonInstalled = currentHost.DaemonInstalled
|
|
if len(a.EndpointIP) == 0 || strings.Contains(a.EndpointIP, "nil") {
|
|
h.EndpointIP = currentHost.EndpointIP
|
|
} else {
|
|
h.EndpointIP = net.ParseIP(a.EndpointIP)
|
|
}
|
|
h.Debug = a.Debug
|
|
h.FirewallInUse = a.FirewallInUse
|
|
h.IPForwarding = currentHost.IPForwarding
|
|
h.Interface = currentHost.Interface
|
|
h.Interfaces = currentHost.Interfaces
|
|
h.DefaultInterface = currentHost.DefaultInterface
|
|
h.IsDocker = currentHost.IsDocker
|
|
h.IsK8S = currentHost.IsK8S
|
|
h.IsStatic = a.IsStatic
|
|
h.ListenPort = a.ListenPort
|
|
h.MTU = a.MTU
|
|
h.MacAddress = currentHost.MacAddress
|
|
h.PublicKey = currentHost.PublicKey
|
|
h.Name = a.Name
|
|
h.Version = currentHost.Version
|
|
h.Verbosity = a.Verbosity
|
|
h.Nodes = currentHost.Nodes
|
|
h.TrafficKeyPublic = currentHost.TrafficKeyPublic
|
|
h.OS = currentHost.OS
|
|
h.IsDefault = a.IsDefault
|
|
h.NatType = currentHost.NatType
|
|
h.TurnEndpoint = currentHost.TurnEndpoint
|
|
h.PersistentKeepalive = time.Duration(a.PersistentKeepalive) * time.Second
|
|
h.AutoUpdate = a.AutoUpdate
|
|
return &h
|
|
}
|