EtherGuard-VPN/mtypes/config.go

244 lines
8.3 KiB
Go
Raw Normal View History

2021-12-02 18:13:48 +01:00
package mtypes
2021-08-20 19:32:50 +02:00
2021-08-23 21:11:01 +02:00
import (
2021-08-25 10:13:53 +02:00
"math"
2021-08-25 13:54:13 +02:00
"strconv"
2021-12-04 03:32:59 +01:00
"sync/atomic"
2021-08-25 10:13:53 +02:00
)
2021-09-20 22:20:00 +02:00
// Nonnegative integer ID of vertex
type Vertex uint16
2021-08-25 10:13:53 +02:00
const (
2021-12-09 23:39:37 +01:00
NodeID_Broadcast Vertex = math.MaxUint16 - iota // Normal boardcast, boardcast with route table
2021-12-12 09:29:05 +01:00
NodeID_Spread Vertex = math.MaxUint16 - iota // p2p mode: boardcast to every know peer and prevent dup. super mode: send to supernode
2021-12-09 08:46:15 +01:00
NodeID_SuperNode Vertex = math.MaxUint16 - iota
2021-12-09 23:39:37 +01:00
NodeID_Invalid Vertex = math.MaxUint16 - iota
NodeID_Special Vertex = NodeID_Invalid
2021-08-23 21:11:01 +02:00
)
2021-08-20 19:32:50 +02:00
type EdgeConfig struct {
2021-12-16 03:56:02 +01:00
Interface InterfaceConf `yaml:"Interface"`
NodeID Vertex `yaml:"NodeID"`
NodeName string `yaml:"NodeName"`
PostScript string `yaml:"PostScript"`
DefaultTTL uint8 `yaml:"DefaultTTL"`
L2FIBTimeout float64 `yaml:"L2FIBTimeout"`
PrivKey string `yaml:"PrivKey"`
ListenPort int `yaml:"ListenPort"`
2021-12-17 08:02:42 +01:00
AfPrefer int `yaml:"AfPrefer"`
2021-12-16 03:56:02 +01:00
LogLevel LoggerInfo `yaml:"LogLevel"`
DynamicRoute DynamicRouteInfo `yaml:"DynamicRoute"`
NextHopTable NextHopTable `yaml:"NextHopTable"`
ResetEndPointInterval float64 `yaml:"ResetEndPointInterval"`
Peers []PeerInfo `yaml:"Peers"`
2021-08-20 19:32:50 +02:00
}
type SuperConfig struct {
2021-12-04 15:46:36 +01:00
NodeName string `yaml:"NodeName"`
PostScript string `yaml:"PostScript"`
PrivKeyV4 string `yaml:"PrivKeyV4"`
PrivKeyV6 string `yaml:"PrivKeyV6"`
ListenPort int `yaml:"ListenPort"`
ListenPort_EdgeAPI string `yaml:"ListenPort_EdgeAPI"`
ListenPort_ManageAPI string `yaml:"ListenPort_ManageAPI"`
API_Prefix string `yaml:"API_Prefix"`
RePushConfigInterval float64 `yaml:"RePushConfigInterval"`
HttpPostInterval float64 `yaml:"HttpPostInterval"`
PeerAliveTimeout float64 `yaml:"PeerAliveTimeout"`
SendPingInterval float64 `yaml:"SendPingInterval"`
2021-12-09 23:39:37 +01:00
DampingResistance float64 `yaml:"DampingResistance"`
2021-12-04 15:46:36 +01:00
LogLevel LoggerInfo `yaml:"LogLevel"`
Passwords Passwords `yaml:"Passwords"`
GraphRecalculateSetting GraphRecalculateSetting `yaml:"GraphRecalculateSetting"`
NextHopTable NextHopTable `yaml:"NextHopTable"`
EdgeTemplate string `yaml:"EdgeTemplate"`
UsePSKForInterEdge bool `yaml:"UsePSKForInterEdge"`
2021-12-16 03:56:02 +01:00
ResetEndPointInterval float64 `yaml:"ResetEndPointInterval"`
2021-12-04 15:46:36 +01:00
Peers []SuperPeerInfo `yaml:"Peers"`
2021-08-20 19:32:50 +02:00
}
2021-09-21 03:15:23 +02:00
type Passwords struct {
2021-12-05 22:36:50 +01:00
ShowState string `yaml:"ShowState"`
AddPeer string `yaml:"AddPeer"`
DelPeer string `yaml:"DelPeer"`
UpdatePeer string `yaml:"UpdatePeer"`
UpdateSuper string `yaml:"UpdateSuper"`
2021-09-21 03:15:23 +02:00
}
2021-08-20 19:32:50 +02:00
type InterfaceConf struct {
2021-12-04 15:46:36 +01:00
IType string `yaml:"IType"`
Name string `yaml:"Name"`
VPPIFaceID uint32 `yaml:"VPPIFaceID"`
VPPBridgeID uint32 `yaml:"VPPBridgeID"`
MacAddrPrefix string `yaml:"MacAddrPrefix"`
IPv4CIDR string `yaml:"IPv4CIDR"`
IPv6CIDR string `yaml:"IPv6CIDR"`
IPv6LLPrefix string `yaml:"IPv6LLPrefix"`
MTU uint16 `yaml:"MTU"`
2021-12-04 15:46:36 +01:00
RecvAddr string `yaml:"RecvAddr"`
SendAddr string `yaml:"SendAddr"`
L2HeaderMode string `yaml:"L2HeaderMode"`
2021-08-20 19:32:50 +02:00
}
type PeerInfo struct {
2021-12-09 08:46:15 +01:00
NodeID Vertex `yaml:"NodeID"`
PubKey string `yaml:"PubKey"`
PSKey string `yaml:"PSKey"`
EndPoint string `yaml:"EndPoint"`
PersistentKeepalive uint32 `yaml:"PersistentKeepalive"`
Static bool `yaml:"Static"`
2021-08-20 19:32:50 +02:00
}
2021-09-20 22:20:00 +02:00
type SuperPeerInfo struct {
2021-12-04 15:46:36 +01:00
NodeID Vertex `yaml:"NodeID"`
Name string `yaml:"Name"`
PubKey string `yaml:"PubKey"`
PSKey string `yaml:"PSKey"`
AdditionalCost float64 `yaml:"AdditionalCost"`
SkipLocalIP bool `yaml:"SkipLocalIP"`
2021-12-15 11:34:49 +01:00
EndPoint string `yaml:"EndPoint"`
2021-12-16 03:56:02 +01:00
ExternalIP string `yaml:"ExternalIP"`
2021-09-20 22:20:00 +02:00
}
2021-08-20 19:32:50 +02:00
type LoggerInfo struct {
2021-12-04 15:46:36 +01:00
LogLevel string `yaml:"LogLevel"`
LogTransit bool `yaml:"LogTransit"`
LogNormal bool `yaml:"LogNormal"`
2021-12-09 21:23:02 +01:00
LogControl bool `yaml:"LogControl"`
2021-12-04 15:46:36 +01:00
LogInternal bool `yaml:"LogInternal"`
LogNTP bool `yaml:"LogNTP"`
2021-08-20 19:32:50 +02:00
}
2021-08-25 10:13:53 +02:00
func (v *Vertex) ToString() string {
2021-08-25 13:54:13 +02:00
switch *v {
2021-12-09 21:23:02 +01:00
case NodeID_Broadcast:
2021-09-21 22:03:11 +02:00
return "Boardcast"
2021-12-12 09:29:05 +01:00
case NodeID_Spread:
return "Spread"
2021-12-09 08:46:15 +01:00
case NodeID_SuperNode:
2021-09-21 22:03:11 +02:00
return "Super"
2021-12-09 23:39:37 +01:00
case NodeID_Invalid:
return "Invalid"
2021-08-25 10:13:53 +02:00
default:
return strconv.Itoa(int(*v))
}
}
2021-08-20 19:32:50 +02:00
type DynamicRouteInfo struct {
2021-12-09 23:39:37 +01:00
SendPingInterval float64 `yaml:"SendPingInterval"`
PeerAliveTimeout float64 `yaml:"PeerAliveTimeout"`
TimeoutCheckInterval float64 `yaml:"TimeoutCheckInterval"`
ConnNextTry float64 `yaml:"ConnNextTry"`
DupCheckTimeout float64 `yaml:"DupCheckTimeout"`
AdditionalCost float64 `yaml:"AdditionalCost"`
DampingResistance float64 `yaml:"DampingResistance"`
SaveNewPeers bool `yaml:"SaveNewPeers"`
SuperNode SuperInfo `yaml:"SuperNode"`
P2P P2PInfo `yaml:"P2P"`
NTPConfig NTPInfo `yaml:"NTPConfig"`
2021-08-20 19:32:50 +02:00
}
2021-12-04 15:46:36 +01:00
type NTPInfo struct {
UseNTP bool `yaml:"UseNTP"`
MaxServerUse int `yaml:"MaxServerUse"`
SyncTimeInterval float64 `yaml:"SyncTimeInterval"`
NTPTimeout float64 `yaml:"NTPTimeout"`
Servers []string `yaml:"Servers"`
2021-08-20 19:32:50 +02:00
}
type SuperInfo struct {
2021-12-15 08:55:28 +01:00
UseSuperNode bool `yaml:"UseSuperNode"`
PSKey string `yaml:"PSKey"`
EndpointV4 string `yaml:"EndpointV4"`
PubKeyV4 string `yaml:"PubKeyV4"`
EndpointV6 string `yaml:"EndpointV6"`
PubKeyV6 string `yaml:"PubKeyV6"`
EndpointEdgeAPIUrl string `yaml:"EndpointEdgeAPIUrl"`
SkipLocalIP bool `yaml:"SkipLocalIP"`
AdditionalLocalIP []string `yaml:"AdditionalLocalIP"`
SuperNodeInfoTimeout float64 `yaml:"SuperNodeInfoTimeout"`
2021-08-20 19:32:50 +02:00
}
2021-12-04 15:46:36 +01:00
type P2PInfo struct {
UseP2P bool `yaml:"UseP2P"`
SendPeerInterval float64 `yaml:"SendPeerInterval"`
GraphRecalculateSetting GraphRecalculateSetting `yaml:"GraphRecalculateSetting"`
2021-08-20 19:32:50 +02:00
}
type GraphRecalculateSetting struct {
2021-12-09 08:46:15 +01:00
StaticMode bool `yaml:"StaticMode"`
ManualLatency DistTable `yaml:"ManualLatency"`
JitterTolerance float64 `yaml:"JitterTolerance"`
JitterToleranceMultiplier float64 `yaml:"JitterToleranceMultiplier"`
TimeoutCheckInterval float64 `yaml:"TimeoutCheckInterval"`
RecalculateCoolDown float64 `yaml:"RecalculateCoolDown"`
2021-08-20 19:32:50 +02:00
}
type DistTable map[Vertex]map[Vertex]float64
2021-12-09 08:46:15 +01:00
type NextHopTable map[Vertex]map[Vertex]Vertex
2021-08-20 19:32:50 +02:00
2021-12-02 18:13:48 +01:00
type API_connurl struct {
ExternalV4 map[string]float64
ExternalV6 map[string]float64
LocalV4 map[string]float64
LocalV6 map[string]float64
}
func (Connurl *API_connurl) IsEmpty() bool {
return len(Connurl.ExternalV4)+len(Connurl.ExternalV6)+len(Connurl.LocalV4)+len(Connurl.LocalV6) == 0
}
func (Connurl *API_connurl) GetList(UseLocal bool) (ret map[string]float64) {
ret = make(map[string]float64)
if UseLocal {
if Connurl.LocalV4 != nil {
for k, v := range Connurl.LocalV4 {
ret[k] = v
}
}
if Connurl.LocalV6 != nil {
for k, v := range Connurl.LocalV6 {
ret[k] = v
}
}
}
if Connurl.ExternalV4 != nil {
for k, v := range Connurl.ExternalV4 {
ret[k] = v
}
}
if Connurl.ExternalV6 != nil {
for k, v := range Connurl.ExternalV6 {
ret[k] = v
}
}
return
}
2021-09-21 22:03:11 +02:00
type API_Peerinfo struct {
2021-08-20 19:32:50 +02:00
NodeID Vertex
PSKey string
2021-12-02 18:13:48 +01:00
Connurl *API_connurl
2021-08-20 19:32:50 +02:00
}
2021-09-20 22:20:00 +02:00
2021-12-04 03:32:59 +01:00
type API_SuperParams struct {
2021-12-09 23:39:37 +01:00
SendPingInterval float64
HttpPostInterval float64
PeerAliveTimeout float64
DampingResistance float64
AdditionalCost float64
2021-12-04 03:32:59 +01:00
}
type StateHash struct {
Peer atomic.Value //[32]byte
SuperParam atomic.Value //[32]byte
NhTable atomic.Value //[32]byte
}
2021-09-21 22:03:11 +02:00
type API_Peers map[string]API_Peerinfo // map[PubKey]API_Peerinfo
2021-08-23 21:11:01 +02:00
2021-12-02 18:13:48 +01:00
type JWTSecret [32]byte
2021-08-23 21:11:01 +02:00
2021-12-02 18:13:48 +01:00
const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"