EtherGuard-VPN/config/config.go

156 lines
3.3 KiB
Go
Raw Normal View History

2021-08-20 19:32:50 +02:00
package config
2021-08-23 21:11:01 +02:00
import (
"crypto/rand"
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
)
const (
Boardcast Vertex = math.MaxUint32 - iota // Normal boardcast, boardcast with route table
ControlMessage Vertex = math.MaxUint32 - iota // p2p mode: boardcast to every know keer and prevent dup/ super mode: send to supernode
PingMessage Vertex = math.MaxUint32 - iota // boardsact to every know peer but don't transit
SuperNodeMessage Vertex = math.MaxUint32 - iota
Special_NodeID Vertex = SuperNodeMessage
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
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
PrivKeyV4 string
PrivKeyV6 string
ListenPort int
LogLevel LoggerInfo
2021-08-21 16:54:24 +02:00
RePushConfigInterval float64
2021-08-25 10:13:53 +02:00
StatePassword string
2021-08-20 19:32:50 +02:00
GraphRecalculateSetting GraphRecalculateSetting
Peers []PeerInfo
}
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
}
type LoggerInfo struct {
LogLevel string
LogTransit bool
2021-08-21 16:54:24 +02:00
LogControl bool
2021-08-25 10:13:53 +02:00
LogNormal bool
2021-08-25 13:54:13 +02:00
LogNTP bool
2021-08-20 19:32:50 +02:00
}
// Nonnegative integer ID of vertex
type Vertex uint32
2021-08-25 10:13:53 +02:00
func (v *Vertex) ToString() string {
2021-08-25 13:54:13 +02:00
switch *v {
2021-08-25 10:13:53 +02:00
case Boardcast:
return "B"
case ControlMessage:
return "C"
case PingMessage:
return "P"
case SuperNodeMessage:
return "S"
default:
return strconv.Itoa(int(*v))
}
}
2021-08-20 19:32:50 +02:00
type DynamicRouteInfo struct {
SendPingInterval float64
DupCheckTimeout float64
ConnTimeOut float64
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
ConnURLV4 string
PubKeyV4 string
ConnURLV6 string
PubKeyV6 string
APIUrl string
SuperNodeInfoTimeout float64
}
type P2Pinfo struct {
UseP2P bool
SendPeerInterval float64
PeerAliveTimeout float64
GraphRecalculateSetting GraphRecalculateSetting
}
type GraphRecalculateSetting struct {
JitterTolerance float64
JitterToleranceMultiplier float64
NodeReportTimeout float64
RecalculateCoolDown float64
}
type DistTable map[Vertex]map[Vertex]float64
type NextHopTable map[Vertex]map[Vertex]*Vertex
type HTTP_Peerinfo struct {
NodeID Vertex
PubKey string
PSKey string
Connurl map[string]bool
}
2021-08-24 20:16:21 +02:00
type HTTP_Peers map[string]HTTP_Peerinfo
2021-08-23 21:11:01 +02:00
const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
func RandomStr(length int, defaults string) string {
bytes := make([]byte, length)
if _, err := rand.Read(bytes); err != nil {
return defaults
}
for i, b := range bytes {
bytes[i] = chars[b%byte(len(chars))]
}
return string(bytes)
}