EtherGuard-VPN/mtypes/config.go

209 lines
4.5 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-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 (
Broadcast Vertex = math.MaxUint16 - iota // Normal boardcast, boardcast with route table
ControlMessage Vertex = math.MaxUint16 - iota // p2p mode: boardcast to every know peer and prevent dup. super mode: send to supernode
2021-09-20 22:20:00 +02:00
SuperNodeMessage Vertex = math.MaxUint16 - iota
2021-12-02 18:13:48 +01:00
BrokenMessage Vertex = math.MaxUint16 - iota
Special_NodeID Vertex = BrokenMessage
2021-08-23 21:11:01 +02:00
)
2021-08-20 19:32:50 +02:00
type EdgeConfig struct {
2021-08-24 10:43:55 +02:00
Interface InterfaceConf
NodeID Vertex
NodeName string
2021-11-06 10:47:06 +01:00
PostScript string
2021-09-20 22:20:00 +02:00
DefaultTTL uint8
2021-10-01 10:56:42 +02:00
L2FIBTimeout float64
2021-08-24 10:43:55 +02:00
PrivKey string
ListenPort int
LogLevel LoggerInfo
DynamicRoute DynamicRouteInfo
NextHopTable NextHopTable
ResetConnInterval float64
Peers []PeerInfo
2021-08-20 19:32:50 +02:00
}
type SuperConfig struct {
NodeName string
2021-11-06 10:47:06 +01:00
PostScript string
2021-08-20 19:32:50 +02:00
PrivKeyV4 string
PrivKeyV6 string
ListenPort int
LogLevel LoggerInfo
2021-08-21 16:54:24 +02:00
RePushConfigInterval float64
2021-09-21 03:15:23 +02:00
Passwords Passwords
2021-08-20 19:32:50 +02:00
GraphRecalculateSetting GraphRecalculateSetting
NextHopTable NextHopTable
2021-09-21 03:15:23 +02:00
EdgeTemplate string
UsePSKForInterEdge bool
2021-09-20 22:20:00 +02:00
Peers []SuperPeerInfo
2021-08-20 19:32:50 +02:00
}
2021-09-21 03:15:23 +02:00
type Passwords struct {
ShowState string
AddPeer string
DelPeer string
}
2021-08-20 19:32:50 +02:00
type InterfaceConf struct {
2021-08-24 10:43:55 +02:00
Itype string
Name string
VPPIfaceID uint32
VPPBridgeID uint32
MacAddrPrefix string
MTU int
RecvAddr string
SendAddr string
L2HeaderMode string
2021-08-20 19:32:50 +02:00
}
type PeerInfo struct {
NodeID Vertex
PubKey string
2021-08-21 16:54:24 +02:00
PSKey string
2021-08-20 19:32:50 +02:00
EndPoint string
Static bool
}
2021-09-20 22:20:00 +02:00
type SuperPeerInfo struct {
2021-10-27 03:02:44 +02:00
NodeID Vertex
Name string
PubKey string
PSKey string
AdditionalCost float64
2021-12-03 23:46:58 +01:00
SkipLocalIP bool
2021-09-20 22:20:00 +02:00
}
2021-08-20 19:32:50 +02:00
type LoggerInfo struct {
2021-10-09 12:22:27 +02:00
LogLevel string
LogTransit bool
LogControl bool
LogNormal bool
LogInternal bool
LogNTP bool
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 {
case Broadcast:
2021-09-21 22:03:11 +02:00
return "Boardcast"
2021-08-25 10:13:53 +02:00
case ControlMessage:
2021-09-21 22:03:11 +02:00
return "Control"
2021-08-25 10:13:53 +02:00
case SuperNodeMessage:
2021-09-21 22:03:11 +02:00
return "Super"
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 {
SendPingInterval float64
PeerAliveTimeout float64
2021-08-20 19:32:50 +02:00
DupCheckTimeout float64
ConnTimeOut float64
ConnNextTry float64
2021-12-03 23:46:58 +01:00
AdditionalCost float64
2021-08-20 19:32:50 +02:00
SaveNewPeers bool
SuperNode SuperInfo
P2P P2Pinfo
NTPconfig NTPinfo
}
type NTPinfo struct {
2021-08-25 13:54:13 +02:00
UseNTP bool
MaxServerUse int
SyncTimeInterval float64
NTPTimeout float64
Servers []string
2021-08-20 19:32:50 +02:00
}
type SuperInfo struct {
UseSuperNode bool
PSKey string
2021-08-20 19:32:50 +02:00
ConnURLV4 string
PubKeyV4 string
ConnURLV6 string
PubKeyV6 string
APIUrl string
2021-12-02 18:13:48 +01:00
SkipLocalIP bool
HttpPostInterval float64
2021-08-20 19:32:50 +02:00
SuperNodeInfoTimeout float64
}
type P2Pinfo struct {
UseP2P bool
SendPeerInterval float64
GraphRecalculateSetting GraphRecalculateSetting
}
type GraphRecalculateSetting struct {
StaticMode bool
2021-08-20 19:32:50 +02:00
JitterTolerance float64
JitterToleranceMultiplier float64
NodeReportTimeout float64
2021-10-12 10:05:23 +02:00
TimeoutCheckInterval float64
2021-08-20 19:32:50 +02:00
RecalculateCoolDown float64
}
type DistTable map[Vertex]map[Vertex]float64
type NextHopTable map[Vertex]map[Vertex]*Vertex
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-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"