mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-11-21 23:03:08 +01:00
Add DisabledAf
This commit is contained in:
parent
eb6bb7d15d
commit
b4ce21f5c5
@ -69,16 +69,23 @@ func NewLinuxSocketBindAf(use4 bool, use6 bool) Bind {
|
||||
return &LinuxSocketBind{sock4: -1, sock6: -1, use4: use4, use6: use6}
|
||||
}
|
||||
|
||||
func NewDefaultBind(use4 bool, use6 bool, bindmode string) Bind {
|
||||
func NewDefaultBind(Af EnabledAf, bindmode string) Bind {
|
||||
if bindmode == "std" {
|
||||
return NewStdNetBindAf(use4, use6)
|
||||
return NewStdNetBindAf(Af.IPv4, Af.IPv6)
|
||||
}
|
||||
return NewLinuxSocketBindAf(use4, use6)
|
||||
return NewLinuxSocketBindAf(Af.IPv4, Af.IPv6)
|
||||
}
|
||||
|
||||
var _ Endpoint = (*LinuxSocketEndpoint)(nil)
|
||||
var _ Bind = (*LinuxSocketBind)(nil)
|
||||
|
||||
func (s *LinuxSocketBind) EnabledAf() EnabledAf {
|
||||
return EnabledAf{
|
||||
s.use4,
|
||||
s.use6,
|
||||
}
|
||||
}
|
||||
|
||||
func (*LinuxSocketBind) ParseEndpoint(s string) (Endpoint, error) {
|
||||
var end LinuxSocketEndpoint
|
||||
addr, err := parseEndpoint(s)
|
||||
|
@ -43,6 +43,13 @@ func (*StdNetBind) ParseEndpoint(s string) (Endpoint, error) {
|
||||
|
||||
func (*StdNetEndpoint) ClearSrc() {}
|
||||
|
||||
func (s *StdNetBind) EnabledAf() EnabledAf {
|
||||
return EnabledAf{
|
||||
s.use4,
|
||||
s.use6,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *StdNetEndpoint) DstIP() net.IP {
|
||||
return (*net.UDPAddr)(e).IP
|
||||
}
|
||||
|
@ -53,6 +53,13 @@ func NewChannelBinds() [2]conn.Bind {
|
||||
return [2]conn.Bind{&binds[0], &binds[1]}
|
||||
}
|
||||
|
||||
func (s *ChannelBind) EnabledAf() conn.EnabledAf {
|
||||
return conn.EnabledAf{
|
||||
IPv4: true,
|
||||
IPv6: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (c ChannelEndpoint) ClearSrc() {}
|
||||
|
||||
func (c ChannelEndpoint) SrcToString() string { return "" }
|
||||
|
37
conn/conn.go
37
conn/conn.go
@ -43,6 +43,26 @@ type Bind interface {
|
||||
|
||||
// ParseEndpoint creates a new endpoint from a string.
|
||||
ParseEndpoint(s string) (Endpoint, error)
|
||||
|
||||
EnabledAf() EnabledAf
|
||||
}
|
||||
|
||||
type EnabledAf struct {
|
||||
IPv4 bool `yaml:"IPv4"`
|
||||
IPv6 bool `yaml:"IPv6"`
|
||||
}
|
||||
|
||||
var EnabledAf4 = EnabledAf{
|
||||
IPv4: true,
|
||||
IPv6: false,
|
||||
}
|
||||
var EnabledAf6 = EnabledAf{
|
||||
IPv4: false,
|
||||
IPv6: true,
|
||||
}
|
||||
var EnabledAf46 = EnabledAf{
|
||||
IPv4: true,
|
||||
IPv6: true,
|
||||
}
|
||||
|
||||
// BindSocketToInterface is implemented by Bind objects that support being
|
||||
@ -150,7 +170,7 @@ func parseEndpoint(s string) (*net.UDPAddr, error) {
|
||||
return addr, err
|
||||
}
|
||||
|
||||
func LookupIP(host_port string, Af int, AfPrefer int) (string, string, error) {
|
||||
func LookupIP(host_port string, Af EnabledAf, AfPrefer int) (string, string, error) {
|
||||
if host_port == "" {
|
||||
return "", "", fmt.Errorf("error lookup ip from empty string")
|
||||
}
|
||||
@ -159,12 +179,7 @@ func LookupIP(host_port string, Af int, AfPrefer int) (string, string, error) {
|
||||
var af_try_order []string
|
||||
|
||||
var NetStr string
|
||||
switch Af {
|
||||
case 4:
|
||||
af_try_order = []string{"udp4"}
|
||||
case 6:
|
||||
af_try_order = []string{"udp6"}
|
||||
case 0:
|
||||
if Af.IPv4 && Af.IPv6 {
|
||||
switch AfPrefer {
|
||||
case 0:
|
||||
af_try_order = []string{"udp"}
|
||||
@ -175,8 +190,12 @@ func LookupIP(host_port string, Af int, AfPrefer int) (string, string, error) {
|
||||
default:
|
||||
return "", "", fmt.Errorf("unknown address family:%v", AfPrefer)
|
||||
}
|
||||
default:
|
||||
return "", "", fmt.Errorf("unknown address family:%v", Af)
|
||||
} else if Af.IPv4 {
|
||||
af_try_order = []string{"udp4"}
|
||||
} else if Af.IPv6 {
|
||||
af_try_order = []string{"udp6"}
|
||||
} else {
|
||||
return "", "", fmt.Errorf("no EnabledAf:%v", Af)
|
||||
}
|
||||
for _, af := range af_try_order {
|
||||
conn, err = net.Dial(af, host_port)
|
||||
|
@ -82,6 +82,7 @@ type Device struct {
|
||||
EdgeConfig *mtypes.EdgeConfig
|
||||
SuperConfigPath string
|
||||
SuperConfig *mtypes.SuperConfig
|
||||
enabledAf conn.EnabledAf
|
||||
|
||||
Chan_server_register chan mtypes.RegisterMsg
|
||||
Chan_server_pong chan mtypes.PongMsg
|
||||
@ -344,6 +345,7 @@ func NewDevice(tapDevice tap.Device, id mtypes.Vertex, bind conn.Bind, logger *L
|
||||
device.graph = graph
|
||||
device.Version = version
|
||||
device.JWTSecret = mtypes.ByteSlice2Byte32(mtypes.RandomBytes(32, []byte(fmt.Sprintf("%v", time.Now()))))
|
||||
device.enabledAf = bind.EnabledAf()
|
||||
|
||||
device.state_hashes.NhTable.Store("")
|
||||
device.state_hashes.Peer.Store("")
|
||||
|
@ -33,15 +33,17 @@ type endpoint_tryitem struct {
|
||||
type endpoint_trylist struct {
|
||||
sync.RWMutex
|
||||
timeout time.Duration
|
||||
enabledAf conn.EnabledAf
|
||||
peer *Peer
|
||||
trymap_super map[string]*endpoint_tryitem
|
||||
trymap_p2p map[string]*endpoint_tryitem
|
||||
}
|
||||
|
||||
func NewEndpoint_trylist(peer *Peer, timeout time.Duration) *endpoint_trylist {
|
||||
func NewEndpoint_trylist(peer *Peer, timeout time.Duration, enabledAf conn.EnabledAf) *endpoint_trylist {
|
||||
return &endpoint_trylist{
|
||||
timeout: timeout,
|
||||
peer: peer,
|
||||
enabledAf: enabledAf,
|
||||
trymap_super: make(map[string]*endpoint_tryitem),
|
||||
trymap_p2p: make(map[string]*endpoint_tryitem),
|
||||
}
|
||||
@ -60,7 +62,7 @@ func (et *endpoint_trylist) UpdateSuper(urls mtypes.API_connurl, UseLocalIP bool
|
||||
if url == "" {
|
||||
continue
|
||||
}
|
||||
addr, _, err := conn.LookupIP(url, 0, AfPerfer)
|
||||
addr, _, err := conn.LookupIP(url, et.enabledAf, AfPerfer)
|
||||
switch AfPerfer {
|
||||
case 4:
|
||||
if addr == "udp4" {
|
||||
@ -97,7 +99,7 @@ func (et *endpoint_trylist) UpdateSuper(urls mtypes.API_connurl, UseLocalIP bool
|
||||
}
|
||||
|
||||
func (et *endpoint_trylist) UpdateP2P(url string) {
|
||||
_, _, err := conn.LookupIP(url, 0, 0)
|
||||
_, _, err := conn.LookupIP(url, et.enabledAf, 0)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -254,7 +256,7 @@ type Peer struct {
|
||||
AskedForNeighbor bool
|
||||
StaticConn bool //if true, this peer will not write to config file when roaming, and the endpoint will be reset periodically
|
||||
ConnURL string
|
||||
ConnAF int //0: both, 4: ipv4 only, 6: ipv6 only
|
||||
ConnAF conn.EnabledAf
|
||||
|
||||
// These fields are accessed with atomic operations, which must be
|
||||
// 64-bit aligned even on 32-bit platforms. Go guarantees that an
|
||||
@ -330,6 +332,7 @@ func (device *Device) NewPeer(pk NoisePublicKey, id mtypes.Vertex, isSuper bool,
|
||||
fmt.Println("Internal: Create peer with ID : " + id.ToString() + " and PubKey:" + pk.ToString())
|
||||
}
|
||||
peer := new(Peer)
|
||||
peer.ConnAF = conn.EnabledAf46
|
||||
atomic.SwapUint32(&peer.persistentKeepaliveInterval, PersistentKeepalive)
|
||||
peer.LastPacketReceivedAdd1Sec.Store(&time.Time{})
|
||||
peer.Lock()
|
||||
@ -337,7 +340,7 @@ func (device *Device) NewPeer(pk NoisePublicKey, id mtypes.Vertex, isSuper bool,
|
||||
|
||||
peer.cookieGenerator.Init(pk)
|
||||
peer.device = device
|
||||
peer.endpoint_trylist = NewEndpoint_trylist(peer, mtypes.S2TD(device.EdgeConfig.DynamicRoute.PeerAliveTimeout))
|
||||
peer.endpoint_trylist = NewEndpoint_trylist(peer, mtypes.S2TD(device.EdgeConfig.DynamicRoute.PeerAliveTimeout), device.enabledAf)
|
||||
peer.SingleWayLatency.device = device
|
||||
peer.SingleWayLatency.Push(mtypes.Infinity)
|
||||
peer.queue.outbound = newAutodrainingOutboundQueue(device)
|
||||
@ -556,7 +559,7 @@ func (peer *Peer) SetPSK(psk NoisePresharedKey) {
|
||||
peer.handshake.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (peer *Peer) SetEndpointFromConnURL(connurl string, af int, af_perfer int, static bool) error {
|
||||
func (peer *Peer) SetEndpointFromConnURL(connurl string, af conn.EnabledAf, af_perfer int, static bool) error {
|
||||
if peer.device.LogLevel.LogInternal {
|
||||
fmt.Printf("Internal: Set endpoint to %v for NodeID: %v static:%v\n", connurl, peer.ID.ToString(), static)
|
||||
}
|
||||
|
@ -757,7 +757,7 @@ func (device *Device) RoutineTryReceivedEndpoint() {
|
||||
if connurl == "" {
|
||||
continue
|
||||
}
|
||||
err := thepeer.SetEndpointFromConnURL(connurl, thepeer.ConnAF, device.EdgeConfig.AfPrefer, thepeer.StaticConn) //trying to bind first url in the list and wait ConnNextTry seconds
|
||||
err := thepeer.SetEndpointFromConnURL(connurl, device.enabledAf, device.EdgeConfig.AfPrefer, thepeer.StaticConn) //trying to bind first url in the list and wait ConnNextTry seconds
|
||||
if err != nil {
|
||||
device.log.Errorf("Bind " + connurl + " failed!")
|
||||
thepeer.endpoint_trylist.Delete(connurl)
|
||||
@ -939,12 +939,12 @@ func (device *Device) RoutinePostPeerInfo(startchan <-chan struct{}) {
|
||||
}
|
||||
for _, AIP := range device.EdgeConfig.DynamicRoute.SuperNode.AdditionalLocalIP {
|
||||
success := false
|
||||
_, ipstr, err := conn.LookupIP(AIP, 4, 0)
|
||||
_, ipstr, err := conn.LookupIP(AIP, conn.EnabledAf4, 0)
|
||||
if err == nil {
|
||||
success = true
|
||||
LocalV4s[ipstr] = 50
|
||||
}
|
||||
_, ipstr, err = conn.LookupIP(AIP, 6, 0)
|
||||
_, ipstr, err = conn.LookupIP(AIP, conn.EnabledAf6, 0)
|
||||
if err == nil {
|
||||
success = true
|
||||
LocalV6s[ipstr] = 50
|
||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
||||
L2FIBTimeout: 3600
|
||||
PrivKey: kkKXE1uFha84Yd8YIDUI02OsjVi2v7CM60rIUgC7zP4=
|
||||
ListenPort: 3001
|
||||
DisabledAf:
|
||||
IPv4: false
|
||||
IPv6: false
|
||||
LogLevel:
|
||||
LogLevel: error
|
||||
LogTransit: true
|
||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
||||
L2FIBTimeout: 3600
|
||||
PrivKey: cK6/KorPQRK2o8w+upCr77XHK9/Mwvab59evSz/Jg0I=
|
||||
ListenPort: 3002
|
||||
DisabledAf:
|
||||
IPv4: false
|
||||
IPv6: false
|
||||
LogLevel:
|
||||
LogLevel: error
|
||||
LogTransit: true
|
||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
||||
L2FIBTimeout: 3600
|
||||
PrivKey: qaSOwMzr7nC7Vcphd7w6q9k6bz1eCVhe9uEt+803lvk=
|
||||
ListenPort: 3003
|
||||
DisabledAf:
|
||||
IPv4: false
|
||||
IPv6: false
|
||||
LogLevel:
|
||||
LogLevel: error
|
||||
LogTransit: true
|
||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
||||
L2FIBTimeout: 3600
|
||||
PrivKey: GL9GrJCeptF8+iiT8Nrem9qMaiQScu6tGjQ4CvEskn0=
|
||||
ListenPort: 3004
|
||||
DisabledAf:
|
||||
IPv4: false
|
||||
IPv6: false
|
||||
LogLevel:
|
||||
LogLevel: error
|
||||
LogTransit: true
|
||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
||||
L2FIBTimeout: 3600
|
||||
PrivKey: 5zWmtAW/NipYIZU1wWM6gWiYGPpz/yPslF3TEdNvUzw=
|
||||
ListenPort: 3005
|
||||
DisabledAf:
|
||||
IPv4: false
|
||||
IPv6: false
|
||||
LogLevel:
|
||||
LogLevel: error
|
||||
LogTransit: true
|
||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
||||
L2FIBTimeout: 3600
|
||||
PrivKey: FxdP9nKi0YLvhMvwYV3NcUixDjb3Q7gBGtmFLPjqLZs=
|
||||
ListenPort: 3006
|
||||
DisabledAf:
|
||||
IPv4: false
|
||||
IPv6: false
|
||||
LogLevel:
|
||||
LogLevel: error
|
||||
LogTransit: true
|
||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
||||
L2FIBTimeout: 3600
|
||||
PrivKey: u1U5zImQ0lByFcJXTysUq9ZSTg3ZLIKMDYn/RAXEtKI=
|
||||
ListenPort: 3001
|
||||
DisabledAf:
|
||||
IPv4: false
|
||||
IPv6: false
|
||||
LogLevel:
|
||||
LogLevel: error
|
||||
LogTransit: true
|
||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
||||
L2FIBTimeout: 3600
|
||||
PrivKey: Gn3hwOAtlKeBldzr6Jmu+aeoXR/TAcT7RzITZGMYfek=
|
||||
ListenPort: 3002
|
||||
DisabledAf:
|
||||
IPv4: false
|
||||
IPv6: false
|
||||
LogLevel:
|
||||
LogLevel: error
|
||||
LogTransit: true
|
||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
||||
L2FIBTimeout: 3600
|
||||
PrivKey: odbxmbr0GhcsZSpyrVLooMixeSg0t1WpL1BYwb8EJWw=
|
||||
ListenPort: 3003
|
||||
DisabledAf:
|
||||
IPv4: false
|
||||
IPv6: false
|
||||
LogLevel:
|
||||
LogLevel: error
|
||||
LogTransit: true
|
||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
||||
L2FIBTimeout: 3600
|
||||
PrivKey: t5DUQqA4/G7ONUVroXuYx94iC8ZEOGW/LH7GT3MfL/8=
|
||||
ListenPort: 3004
|
||||
DisabledAf:
|
||||
IPv4: false
|
||||
IPv6: false
|
||||
LogLevel:
|
||||
LogLevel: error
|
||||
LogTransit: true
|
||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
||||
L2FIBTimeout: 3600
|
||||
PrivKey: MxAk/kCWlBRBpSJqdJImIlG7ic2drOPxEqUr/cyevx4=
|
||||
ListenPort: 3005
|
||||
DisabledAf:
|
||||
IPv4: false
|
||||
IPv6: false
|
||||
LogLevel:
|
||||
LogLevel: error
|
||||
LogTransit: true
|
||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
||||
L2FIBTimeout: 3600
|
||||
PrivKey: zlcpGbnXXtTuaB+XDKtWQpXqxvwzhee2qdMcTI1k3cA=
|
||||
ListenPort: 3006
|
||||
DisabledAf:
|
||||
IPv4: false
|
||||
IPv6: false
|
||||
LogLevel:
|
||||
LogLevel: error
|
||||
LogTransit: true
|
||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
||||
L2FIBTimeout: 3600
|
||||
PrivKey: +KAYwkRgacUbxc52t04z8fTJBgvrkPLsisr0qJOhIUE=
|
||||
ListenPort: 0
|
||||
DisabledAf:
|
||||
IPv4: false
|
||||
IPv6: false
|
||||
AfPrefer: 4
|
||||
LogLevel:
|
||||
LogLevel: error
|
||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
||||
L2FIBTimeout: 3600
|
||||
PrivKey: jDAolOiiRj/ju1xpVagZTtsxJSJba2rjp7J2XMc3yoM=
|
||||
ListenPort: 0
|
||||
DisabledAf:
|
||||
IPv4: false
|
||||
IPv6: false
|
||||
AfPrefer: 4
|
||||
LogLevel:
|
||||
LogLevel: error
|
||||
|
@ -18,6 +18,9 @@ DefaultTTL: 200
|
||||
L2FIBTimeout: 3600
|
||||
PrivKey: yNf1SkvwV8c59GmesfTNxSut6gFjYKEg9uIsE05XQUI=
|
||||
ListenPort: 0
|
||||
DisabledAf:
|
||||
IPv4: false
|
||||
IPv6: false
|
||||
AfPrefer: 4
|
||||
LogLevel:
|
||||
LogLevel: error
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
|
||||
"github.com/KusakabeSi/EtherGuard-VPN/conn"
|
||||
"github.com/KusakabeSi/EtherGuard-VPN/device"
|
||||
"github.com/KusakabeSi/EtherGuard-VPN/mtypes"
|
||||
"github.com/KusakabeSi/EtherGuard-VPN/path"
|
||||
@ -44,6 +45,10 @@ func GetExampleEdgeConf(templatePath string, getDemo bool) (mtypes.EdgeConfig, e
|
||||
L2FIBTimeout: 3600,
|
||||
PrivKey: "6GyDagZKhbm5WNqMiRHhkf43RlbMJ34IieTlIuvfJ1M=",
|
||||
ListenPort: 0,
|
||||
DisableAf: conn.EnabledAf{
|
||||
IPv4: false,
|
||||
IPv6: false,
|
||||
},
|
||||
AfPrefer: 4,
|
||||
LogLevel: mtypes.LoggerInfo{
|
||||
LogLevel: "error",
|
||||
|
@ -114,7 +114,7 @@ func GenNMCfg(NMCinfigPath string, enableP2P bool, printExample bool) (err error
|
||||
return fmt.Errorf("duplicate definition: NodeID %v ", NodeID)
|
||||
}
|
||||
if endpoint != "" {
|
||||
_, _, err = conn.LookupIP(endpoint, 0, 0)
|
||||
_, _, err = conn.LookupIP(endpoint, conn.EnabledAf46, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ func GenSuperCfg(SMCinfigPath string, printExample bool) (err error) {
|
||||
API_Prefix := SMCfg.Supernode.EdgeAPI_Prefix
|
||||
EndpointV4 := SMCfg.Supernode.EndpointV4
|
||||
if EndpointV4 != "" {
|
||||
_, _, err = conn.LookupIP(EndpointV4+":"+ListenPort, 4, 0)
|
||||
_, _, err = conn.LookupIP(EndpointV4+":"+ListenPort, conn.EnabledAf4, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -188,7 +188,7 @@ func GenSuperCfg(SMCinfigPath string, printExample bool) (err error) {
|
||||
if strings.Contains(EndpointV6, ":") && (EndpointV6[0] != '[' || EndpointV6[len(EndpointV6)-1] != ']') {
|
||||
return fmt.Errorf("Invalid IPv6 format, please use [%v] instead", EndpointV6)
|
||||
}
|
||||
_, _, err = conn.LookupIP(EndpointV6+":"+ListenPort, 6, 0)
|
||||
_, _, err = conn.LookupIP(EndpointV6+":"+ListenPort, conn.EnabledAf6, 0)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
17
main_edge.go
17
main_edge.go
@ -120,7 +120,12 @@ func Edge(configPath string, useUAPI bool, printExample bool, bindmode string) (
|
||||
}
|
||||
graph.SetNHTable(econfig.NextHopTable)
|
||||
|
||||
the_device := device.NewDevice(thetap, econfig.NodeID, conn.NewDefaultBind(true, true, bindmode), logger, graph, false, configPath, &econfig, nil, nil, Version)
|
||||
EnabledAf := conn.EnabledAf{
|
||||
IPv4: !econfig.DisableAf.IPv4,
|
||||
IPv6: !econfig.DisableAf.IPv6,
|
||||
}
|
||||
|
||||
the_device := device.NewDevice(thetap, econfig.NodeID, conn.NewDefaultBind(EnabledAf, bindmode), logger, graph, false, configPath, &econfig, nil, nil, Version)
|
||||
defer the_device.Close()
|
||||
pk, err := device.Str2PriKey(econfig.PrivKey)
|
||||
if err != nil {
|
||||
@ -140,7 +145,7 @@ func Edge(configPath string, useUAPI bool, printExample bool, bindmode string) (
|
||||
the_device.NewPeer(pk, peerconf.NodeID, false, peerconf.PersistentKeepalive)
|
||||
if peerconf.EndPoint != "" {
|
||||
peer := the_device.LookupPeer(pk)
|
||||
err = peer.SetEndpointFromConnURL(peerconf.EndPoint, 0, econfig.AfPrefer, peerconf.Static)
|
||||
err = peer.SetEndpointFromConnURL(peerconf.EndPoint, EnabledAf, econfig.AfPrefer, peerconf.Static)
|
||||
if err != nil {
|
||||
logger.Errorf("Failed to set endpoint %v: %w", peerconf.EndPoint, err)
|
||||
return err
|
||||
@ -151,7 +156,7 @@ func Edge(configPath string, useUAPI bool, printExample bool, bindmode string) (
|
||||
if econfig.DynamicRoute.SuperNode.UseSuperNode {
|
||||
S4 := true
|
||||
S6 := true
|
||||
if econfig.DynamicRoute.SuperNode.EndpointV4 != "" {
|
||||
if econfig.DynamicRoute.SuperNode.EndpointV4 != "" && EnabledAf.IPv4 {
|
||||
pk, err := device.Str2PubKey(econfig.DynamicRoute.SuperNode.PubKeyV4)
|
||||
if err != nil {
|
||||
fmt.Println("Error decode base64 ", err)
|
||||
@ -176,13 +181,13 @@ func Edge(configPath string, useUAPI bool, printExample bool, bindmode string) (
|
||||
StaticSuper = false
|
||||
}
|
||||
}
|
||||
err = peer.SetEndpointFromConnURL(econfig.DynamicRoute.SuperNode.EndpointV4, 4, 0, StaticSuper)
|
||||
err = peer.SetEndpointFromConnURL(econfig.DynamicRoute.SuperNode.EndpointV4, conn.EnabledAf4, 0, StaticSuper)
|
||||
if err != nil {
|
||||
logger.Errorf("Failed to set endpoint for supernode v4 %v: %v", econfig.DynamicRoute.SuperNode.EndpointV4, err)
|
||||
S4 = false
|
||||
}
|
||||
}
|
||||
if econfig.DynamicRoute.SuperNode.EndpointV6 != "" {
|
||||
if econfig.DynamicRoute.SuperNode.EndpointV6 != "" && EnabledAf.IPv6 {
|
||||
pk, err := device.Str2PubKey(econfig.DynamicRoute.SuperNode.PubKeyV6)
|
||||
if err != nil {
|
||||
fmt.Println("Error decode base64 ", err)
|
||||
@ -206,7 +211,7 @@ func Edge(configPath string, useUAPI bool, printExample bool, bindmode string) (
|
||||
StaticSuper = false
|
||||
}
|
||||
}
|
||||
err = peer.SetEndpointFromConnURL(econfig.DynamicRoute.SuperNode.EndpointV6, 6, 0, StaticSuper)
|
||||
err = peer.SetEndpointFromConnURL(econfig.DynamicRoute.SuperNode.EndpointV6, conn.EnabledAf6, 0, StaticSuper)
|
||||
if err != nil {
|
||||
logger.Errorf("Failed to set endpoint for supernode v6 %v: %v", econfig.DynamicRoute.SuperNode.EndpointV6, err)
|
||||
S6 = false
|
||||
|
@ -162,7 +162,7 @@ func get_api_peers(old_State_hash string) (api_peerinfo mtypes.API_Peers, StateH
|
||||
if strings.Contains(connV4, ":") {
|
||||
hostport := strings.Split(connV4, ":")
|
||||
ExternalIP = ExternalIP + ":" + hostport[len(hostport)-1]
|
||||
_, ExternalEndPoint_v4, err := conn.LookupIP(ExternalIP, 4, 0)
|
||||
_, ExternalEndPoint_v4, err := conn.LookupIP(ExternalIP, conn.EnabledAf4, 0)
|
||||
if err == nil {
|
||||
connV4 = ExternalEndPoint_v4
|
||||
}
|
||||
@ -170,7 +170,7 @@ func get_api_peers(old_State_hash string) (api_peerinfo mtypes.API_Peers, StateH
|
||||
if strings.Contains(connV6, ":") {
|
||||
hostport := strings.Split(connV6, ":")
|
||||
ExternalIP = ExternalIP + ":" + hostport[len(hostport)-1]
|
||||
_, ExternalEndPoint_v6, err := conn.LookupIP(ExternalIP, 6, 0)
|
||||
_, ExternalEndPoint_v6, err := conn.LookupIP(ExternalIP, conn.EnabledAf6, 0)
|
||||
if err == nil {
|
||||
connV6 = ExternalEndPoint_v6
|
||||
}
|
||||
|
@ -144,10 +144,10 @@ func Super(configPath string, useUAPI bool, printExample bool, bindmode string)
|
||||
}
|
||||
}
|
||||
thetap4, _ := tap.CreateDummyTAP()
|
||||
httpobj.http_device4 = device.NewDevice(thetap4, mtypes.NodeID_SuperNode, conn.NewDefaultBind(true, false, bindmode), logger4, httpobj.http_graph, true, configPath, nil, &sconfig, httpobj.http_super_chains, Version)
|
||||
httpobj.http_device4 = device.NewDevice(thetap4, mtypes.NodeID_SuperNode, conn.NewDefaultBind(conn.EnabledAf4, bindmode), logger4, httpobj.http_graph, true, configPath, nil, &sconfig, httpobj.http_super_chains, Version)
|
||||
defer httpobj.http_device4.Close()
|
||||
thetap6, _ := tap.CreateDummyTAP()
|
||||
httpobj.http_device6 = device.NewDevice(thetap6, mtypes.NodeID_SuperNode, conn.NewDefaultBind(false, true, bindmode), logger6, httpobj.http_graph, true, configPath, nil, &sconfig, httpobj.http_super_chains, Version)
|
||||
httpobj.http_device6 = device.NewDevice(thetap6, mtypes.NodeID_SuperNode, conn.NewDefaultBind(conn.EnabledAf6, bindmode), logger6, httpobj.http_graph, true, configPath, nil, &sconfig, httpobj.http_super_chains, Version)
|
||||
defer httpobj.http_device6.Close()
|
||||
if sconfig.PrivKeyV4 != "" {
|
||||
pk4, err := device.Str2PriKey(sconfig.PrivKeyV4)
|
||||
@ -263,7 +263,7 @@ func super_peeradd(peerconf mtypes.SuperPeerInfo) error {
|
||||
peer4.SetPSK(psk)
|
||||
}
|
||||
if peerconf.EndPoint != "" {
|
||||
err = peer4.SetEndpointFromConnURL(peerconf.EndPoint, 4, 0, true)
|
||||
err = peer4.SetEndpointFromConnURL(peerconf.EndPoint, conn.EnabledAf4, 0, true)
|
||||
if err != nil {
|
||||
if httpobj.http_sconfig.LogLevel.LogInternal {
|
||||
fmt.Printf("Internal: Set endpoint failed:%v\n", err)
|
||||
@ -288,7 +288,7 @@ func super_peeradd(peerconf mtypes.SuperPeerInfo) error {
|
||||
peer6.SetPSK(psk)
|
||||
}
|
||||
if peerconf.EndPoint != "" {
|
||||
err = peer6.SetEndpointFromConnURL(peerconf.EndPoint, 6, 0, true)
|
||||
err = peer6.SetEndpointFromConnURL(peerconf.EndPoint, conn.EnabledAf6, 0, true)
|
||||
if err != nil {
|
||||
if httpobj.http_sconfig.LogLevel.LogInternal {
|
||||
fmt.Printf("Internal: Set endpoint failed:%v\n", err)
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"math"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/KusakabeSi/EtherGuard-VPN/conn"
|
||||
)
|
||||
|
||||
// Nonnegative integer ID of vertex
|
||||
@ -26,6 +28,7 @@ type EdgeConfig struct {
|
||||
L2FIBTimeout float64 `yaml:"L2FIBTimeout"`
|
||||
PrivKey string `yaml:"PrivKey"`
|
||||
ListenPort int `yaml:"ListenPort"`
|
||||
DisableAf conn.EnabledAf `yaml:"DisabledAf"`
|
||||
AfPrefer int `yaml:"AfPrefer"`
|
||||
LogLevel LoggerInfo `yaml:"LogLevel"`
|
||||
DynamicRoute DynamicRouteInfo `yaml:"DynamicRoute"`
|
||||
|
Loading…
Reference in New Issue
Block a user