AdditionalLocalIP

This commit is contained in:
Kusakabe Si 2021-12-15 07:55:28 +00:00
parent 6ca992a1db
commit b4285d3e5d
9 changed files with 41 additions and 21 deletions

View File

@ -150,7 +150,7 @@ func parseEndpoint(s string) (*net.UDPAddr, error) {
return addr, err
}
func LookupIP(host_port string, af int) (string, error) {
func LookupIP(host_port string, af int) (net.Addr, string, error) {
network := "udp"
if af == 4 {
network = "udp4"
@ -159,10 +159,10 @@ func LookupIP(host_port string, af int) (string, error) {
}
conn, err := net.Dial(network, host_port)
if err != nil {
return "", err
return nil, "", err
}
defer conn.Close()
return conn.RemoteAddr().String(), nil
return conn.RemoteAddr(), conn.RemoteAddr().String(), nil
}
func ValidIP(ip net.IP) bool {

View File

@ -57,7 +57,7 @@ func (et *endpoint_trylist) UpdateSuper(urls mtypes.API_connurl, UseLocalIP bool
if url == "" {
continue
}
_, err := conn.LookupIP(url, 0)
_, _, err := conn.LookupIP(url, 0)
if err != nil {
if et.peer.device.LogLevel.LogInternal {
fmt.Printf("Internal: Peer %v : Update trylist(super) %v error: %v\n", et.peer.ID.ToString(), url, err)
@ -84,7 +84,7 @@ func (et *endpoint_trylist) UpdateSuper(urls mtypes.API_connurl, UseLocalIP bool
}
func (et *endpoint_trylist) UpdateP2P(url string) {
_, err := conn.LookupIP(url, 0)
_, _, err := conn.LookupIP(url, 0)
if err != nil {
return
}
@ -471,7 +471,7 @@ func (peer *Peer) SetEndpointFromConnURL(connurl string, af int, static bool) er
fmt.Println("Internal: Set endpoint to " + connurl + " for NodeID:" + peer.ID.ToString())
}
var err error
connurl, err = conn.LookupIP(connurl, af)
_, connurl, err = conn.LookupIP(connurl, af)
if err != nil {
return err
}

View File

@ -20,6 +20,7 @@ import (
"syscall"
"time"
"github.com/KusakabeSi/EtherGuard-VPN/conn"
"github.com/KusakabeSi/EtherGuard-VPN/mtypes"
"github.com/KusakabeSi/EtherGuard-VPN/path"
"github.com/KusakabeSi/EtherGuard-VPN/tap"
@ -941,7 +942,23 @@ func (device *Device) RoutinePostPeerInfo(startchan <-chan struct{}) {
IP: device.peers.LocalV6,
Port: int(device.net.port),
}
LocalV4s[LocalV6.String()] = 100
LocalV6s[LocalV6.String()] = 100
}
}
for _, AIP := range device.EdgeConfig.DynamicRoute.SuperNode.AdditionalLocalIP {
success := false
_, ipstr, err := conn.LookupIP(AIP, 4)
if err == nil {
success = true
LocalV4s[ipstr] = 50
}
_, ipstr, err = conn.LookupIP(AIP, 6)
if err == nil {
success = true
LocalV6s[ipstr] = 50
}
if !success {
device.log.Errorf("AdditionalLocalIP: Failed to LookupIP %v", AIP)
}
}

View File

@ -43,6 +43,8 @@ DynamicRoute:
PubKeyV6: KhpV1fJ+jtNT6S5wKUZJbb0oFlDNMS5qxO0f5Ow/QQU=
EndpointEdgeAPIUrl: http://127.0.0.1:3456/eg_net/eg_api
SkipLocalIP: false
AdditionalLocalIP:
- 136.243.28.150:56238
SuperNodeInfoTimeout: 50
P2P:
UseP2P: false

View File

@ -71,6 +71,7 @@ func GetExampleEdgeConf(templatePath string, getDemo bool) (mtypes.EdgeConfig, e
EndpointEdgeAPIUrl: "http://127.0.0.1:3000/eg_api",
SuperNodeInfoTimeout: 50,
SkipLocalIP: false,
AdditionalLocalIP: []string{"11.11.11.11:11111"},
},
P2P: mtypes.P2PInfo{
UseP2P: false,
@ -163,6 +164,7 @@ func GetExampleEdgeConf(templatePath string, getDemo bool) (mtypes.EdgeConfig, e
econfig.DynamicRoute.P2P.GraphRecalculateSetting.ManualLatency = make(mtypes.DistTable)
econfig.DynamicRoute.SuperNode.EndpointV4 = ""
econfig.DynamicRoute.SuperNode.EndpointV6 = ""
econfig.DynamicRoute.SuperNode.AdditionalLocalIP = make([]string, 0)
}
return econfig, &fs.PathError{Path: "", Err: fmt.Errorf("no path provided")}
}

View File

@ -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)
_, _, err = conn.LookupIP(endpoint, 0)
if err != nil {
return err
}

View File

@ -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)
_, _, err = conn.LookupIP(EndpointV4+":"+ListenPort, 4)
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)
_, _, err = conn.LookupIP(EndpointV6+":"+ListenPort, 6)
if err != nil {
return
}

View File

@ -190,8 +190,6 @@ func Edge(configPath string, useUAPI bool, printExample bool, bindmode string) (
return err
}
peer.SetPSK(psk)
peer.StaticConn = false
peer.ConnURL = econfig.DynamicRoute.SuperNode.EndpointV6
err = peer.SetEndpointFromConnURL(econfig.DynamicRoute.SuperNode.EndpointV6, 6, false)
if err != nil {
logger.Errorf("Failed to set endpoint for supernode v6 %v: %v", econfig.DynamicRoute.SuperNode.EndpointV6, err)

View File

@ -144,15 +144,16 @@ type NTPInfo struct {
}
type SuperInfo struct {
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"`
SuperNodeInfoTimeout float64 `yaml:"SuperNodeInfoTimeout"`
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"`
}
type P2PInfo struct {