netmaker/models/host.go

107 lines
3.8 KiB
Go
Raw Normal View History

2022-12-19 23:41:55 +08:00
package models
import (
"net"
"github.com/google/uuid"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
2023-03-14 22:46:12 +08:00
// OS_Types - list of OS types Netmaker cares about
var OS_Types = struct {
Linux string
Windows string
Mac string
FreeBSD string
IoT string
}{
Linux: "linux",
Windows: "windows",
Mac: "darwin",
FreeBSD: "freebsd",
IoT: "iot",
}
// WIREGUARD_INTERFACE name of wireguard interface
const WIREGUARD_INTERFACE = "netmaker"
2022-12-20 00:03:14 +08:00
// Host - represents a host on the network
2022-12-19 23:41:55 +08:00
type Host struct {
2023-01-05 18:47:09 +08:00
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"`
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"`
2023-01-18 17:36:37 +08:00
PublicListenPort int `json:"public_listen_port" yaml:"public_listen_port"`
2023-01-05 18:47:09 +08:00
ProxyListenPort int `json:"proxy_listen_port" yaml:"proxy_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"`
2023-01-05 18:47:09 +08:00
InternetGateway net.UDPAddr `json:"internetgateway" yaml:"internetgateway"`
Nodes []string `json:"nodes" yaml:"nodes"`
2023-01-11 09:59:33 +08:00
IsRelayed bool `json:"isrelayed" yaml:"isrelayed"`
RelayedBy string `json:"relayed_by" yaml:"relayed_by"`
IsRelay bool `json:"isrelay" yaml:"isrelay"`
RelayedHosts []string `json:"relay_hosts" yaml:"relay_hosts"`
2023-01-05 18:47:09 +08:00
Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
DefaultInterface string `json:"defaultinterface" yaml:"defaultinterface"`
2023-01-05 18:47:09 +08:00
EndpointIP net.IP `json:"endpointip" yaml:"endpointip"`
ProxyEnabled bool `json:"proxy_enabled" yaml:"proxy_enabled"`
2023-03-14 02:39:13 +08:00
ProxyEnabledSet bool `json:"proxy_enabled_updated" yaml:"proxy_enabled_updated"`
2023-01-05 18:47:09 +08:00
IsDocker bool `json:"isdocker" yaml:"isdocker"`
IsK8S bool `json:"isk8s" yaml:"isk8s"`
IsStatic bool `json:"isstatic" yaml:"isstatic"`
IsDefault bool `json:"isdefault" yaml:"isdefault"`
2022-12-19 23:41:55 +08:00
}
2022-12-22 19:42:33 +08:00
// FormatBool converts a boolean to a [yes|no] string
func FormatBool(b bool) string {
s := "no"
if b {
s = "yes"
}
return s
}
// ParseBool parses a [yes|no] string to boolean value
func ParseBool(s string) bool {
b := false
if s == "yes" {
b = true
}
return b
}
2023-01-17 12:57:23 +08:00
// HostMqAction - type for host update action
2023-01-17 12:57:23 +08:00
type HostMqAction string
const (
// UpdateHost - constant for host update action
UpdateHost = "UPDATE_HOST"
// DeleteHost - constant for host delete action
DeleteHost = "DELETE_HOST"
// JoinHostToNetwork - constant for host network join action
2023-01-17 12:57:23 +08:00
JoinHostToNetwork = "JOIN_HOST_TO_NETWORK"
// Acknowledgement - ACK response for hosts
Acknowledgement = "ACK"
2023-02-18 00:39:30 +08:00
// RequestAck - request an ACK
RequestAck = "REQ_ACK"
2023-03-18 03:58:06 +08:00
// CheckIn - update last check in times and public address and interfaces
CheckIn = "CHECK_IN"
2023-01-17 12:57:23 +08:00
)
// HostUpdate - struct for host update
2023-01-17 12:57:23 +08:00
type HostUpdate struct {
Action HostMqAction
Host Host
Node Node
}