mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-11-22 07:13:09 +01:00
AdditionalLocalIP
This commit is contained in:
parent
6ca992a1db
commit
b4285d3e5d
@ -150,7 +150,7 @@ func parseEndpoint(s string) (*net.UDPAddr, error) {
|
|||||||
return addr, err
|
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"
|
network := "udp"
|
||||||
if af == 4 {
|
if af == 4 {
|
||||||
network = "udp4"
|
network = "udp4"
|
||||||
@ -159,10 +159,10 @@ func LookupIP(host_port string, af int) (string, error) {
|
|||||||
}
|
}
|
||||||
conn, err := net.Dial(network, host_port)
|
conn, err := net.Dial(network, host_port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
return conn.RemoteAddr().String(), nil
|
return conn.RemoteAddr(), conn.RemoteAddr().String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidIP(ip net.IP) bool {
|
func ValidIP(ip net.IP) bool {
|
||||||
|
@ -57,7 +57,7 @@ func (et *endpoint_trylist) UpdateSuper(urls mtypes.API_connurl, UseLocalIP bool
|
|||||||
if url == "" {
|
if url == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
_, err := conn.LookupIP(url, 0)
|
_, _, err := conn.LookupIP(url, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if et.peer.device.LogLevel.LogInternal {
|
if et.peer.device.LogLevel.LogInternal {
|
||||||
fmt.Printf("Internal: Peer %v : Update trylist(super) %v error: %v\n", et.peer.ID.ToString(), url, err)
|
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) {
|
func (et *endpoint_trylist) UpdateP2P(url string) {
|
||||||
_, err := conn.LookupIP(url, 0)
|
_, _, err := conn.LookupIP(url, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
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())
|
fmt.Println("Internal: Set endpoint to " + connurl + " for NodeID:" + peer.ID.ToString())
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
connurl, err = conn.LookupIP(connurl, af)
|
_, connurl, err = conn.LookupIP(connurl, af)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/KusakabeSi/EtherGuard-VPN/conn"
|
||||||
"github.com/KusakabeSi/EtherGuard-VPN/mtypes"
|
"github.com/KusakabeSi/EtherGuard-VPN/mtypes"
|
||||||
"github.com/KusakabeSi/EtherGuard-VPN/path"
|
"github.com/KusakabeSi/EtherGuard-VPN/path"
|
||||||
"github.com/KusakabeSi/EtherGuard-VPN/tap"
|
"github.com/KusakabeSi/EtherGuard-VPN/tap"
|
||||||
@ -941,7 +942,23 @@ func (device *Device) RoutinePostPeerInfo(startchan <-chan struct{}) {
|
|||||||
IP: device.peers.LocalV6,
|
IP: device.peers.LocalV6,
|
||||||
Port: int(device.net.port),
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,8 @@ DynamicRoute:
|
|||||||
PubKeyV6: KhpV1fJ+jtNT6S5wKUZJbb0oFlDNMS5qxO0f5Ow/QQU=
|
PubKeyV6: KhpV1fJ+jtNT6S5wKUZJbb0oFlDNMS5qxO0f5Ow/QQU=
|
||||||
EndpointEdgeAPIUrl: http://127.0.0.1:3456/eg_net/eg_api
|
EndpointEdgeAPIUrl: http://127.0.0.1:3456/eg_net/eg_api
|
||||||
SkipLocalIP: false
|
SkipLocalIP: false
|
||||||
|
AdditionalLocalIP:
|
||||||
|
- 136.243.28.150:56238
|
||||||
SuperNodeInfoTimeout: 50
|
SuperNodeInfoTimeout: 50
|
||||||
P2P:
|
P2P:
|
||||||
UseP2P: false
|
UseP2P: false
|
||||||
|
@ -71,6 +71,7 @@ func GetExampleEdgeConf(templatePath string, getDemo bool) (mtypes.EdgeConfig, e
|
|||||||
EndpointEdgeAPIUrl: "http://127.0.0.1:3000/eg_api",
|
EndpointEdgeAPIUrl: "http://127.0.0.1:3000/eg_api",
|
||||||
SuperNodeInfoTimeout: 50,
|
SuperNodeInfoTimeout: 50,
|
||||||
SkipLocalIP: false,
|
SkipLocalIP: false,
|
||||||
|
AdditionalLocalIP: []string{"11.11.11.11:11111"},
|
||||||
},
|
},
|
||||||
P2P: mtypes.P2PInfo{
|
P2P: mtypes.P2PInfo{
|
||||||
UseP2P: false,
|
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.P2P.GraphRecalculateSetting.ManualLatency = make(mtypes.DistTable)
|
||||||
econfig.DynamicRoute.SuperNode.EndpointV4 = ""
|
econfig.DynamicRoute.SuperNode.EndpointV4 = ""
|
||||||
econfig.DynamicRoute.SuperNode.EndpointV6 = ""
|
econfig.DynamicRoute.SuperNode.EndpointV6 = ""
|
||||||
|
econfig.DynamicRoute.SuperNode.AdditionalLocalIP = make([]string, 0)
|
||||||
}
|
}
|
||||||
return econfig, &fs.PathError{Path: "", Err: fmt.Errorf("no path provided")}
|
return econfig, &fs.PathError{Path: "", Err: fmt.Errorf("no path provided")}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ func GenNMCfg(NMCinfigPath string, enableP2P bool, printExample bool) (err error
|
|||||||
return fmt.Errorf("duplicate definition: NodeID %v ", NodeID)
|
return fmt.Errorf("duplicate definition: NodeID %v ", NodeID)
|
||||||
}
|
}
|
||||||
if endpoint != "" {
|
if endpoint != "" {
|
||||||
_, err = conn.LookupIP(endpoint, 0)
|
_, _, err = conn.LookupIP(endpoint, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ func GenSuperCfg(SMCinfigPath string, printExample bool) (err error) {
|
|||||||
API_Prefix := SMCfg.Supernode.EdgeAPI_Prefix
|
API_Prefix := SMCfg.Supernode.EdgeAPI_Prefix
|
||||||
EndpointV4 := SMCfg.Supernode.EndpointV4
|
EndpointV4 := SMCfg.Supernode.EndpointV4
|
||||||
if EndpointV4 != "" {
|
if EndpointV4 != "" {
|
||||||
_, err = conn.LookupIP(EndpointV4+":"+ListenPort, 4)
|
_, _, err = conn.LookupIP(EndpointV4+":"+ListenPort, 4)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -188,7 +188,7 @@ func GenSuperCfg(SMCinfigPath string, printExample bool) (err error) {
|
|||||||
if strings.Contains(EndpointV6, ":") && (EndpointV6[0] != '[' || EndpointV6[len(EndpointV6)-1] != ']') {
|
if strings.Contains(EndpointV6, ":") && (EndpointV6[0] != '[' || EndpointV6[len(EndpointV6)-1] != ']') {
|
||||||
return fmt.Errorf("Invalid IPv6 format, please use [%v] instead", EndpointV6)
|
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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -190,8 +190,6 @@ func Edge(configPath string, useUAPI bool, printExample bool, bindmode string) (
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
peer.SetPSK(psk)
|
peer.SetPSK(psk)
|
||||||
peer.StaticConn = false
|
|
||||||
peer.ConnURL = econfig.DynamicRoute.SuperNode.EndpointV6
|
|
||||||
err = peer.SetEndpointFromConnURL(econfig.DynamicRoute.SuperNode.EndpointV6, 6, false)
|
err = peer.SetEndpointFromConnURL(econfig.DynamicRoute.SuperNode.EndpointV6, 6, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Failed to set endpoint for supernode v6 %v: %v", econfig.DynamicRoute.SuperNode.EndpointV6, err)
|
logger.Errorf("Failed to set endpoint for supernode v6 %v: %v", econfig.DynamicRoute.SuperNode.EndpointV6, err)
|
||||||
|
@ -144,15 +144,16 @@ type NTPInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SuperInfo struct {
|
type SuperInfo struct {
|
||||||
UseSuperNode bool `yaml:"UseSuperNode"`
|
UseSuperNode bool `yaml:"UseSuperNode"`
|
||||||
PSKey string `yaml:"PSKey"`
|
PSKey string `yaml:"PSKey"`
|
||||||
EndpointV4 string `yaml:"EndpointV4"`
|
EndpointV4 string `yaml:"EndpointV4"`
|
||||||
PubKeyV4 string `yaml:"PubKeyV4"`
|
PubKeyV4 string `yaml:"PubKeyV4"`
|
||||||
EndpointV6 string `yaml:"EndpointV6"`
|
EndpointV6 string `yaml:"EndpointV6"`
|
||||||
PubKeyV6 string `yaml:"PubKeyV6"`
|
PubKeyV6 string `yaml:"PubKeyV6"`
|
||||||
EndpointEdgeAPIUrl string `yaml:"EndpointEdgeAPIUrl"`
|
EndpointEdgeAPIUrl string `yaml:"EndpointEdgeAPIUrl"`
|
||||||
SkipLocalIP bool `yaml:"SkipLocalIP"`
|
SkipLocalIP bool `yaml:"SkipLocalIP"`
|
||||||
SuperNodeInfoTimeout float64 `yaml:"SuperNodeInfoTimeout"`
|
AdditionalLocalIP []string `yaml:"AdditionalLocalIP"`
|
||||||
|
SuperNodeInfoTimeout float64 `yaml:"SuperNodeInfoTimeout"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type P2PInfo struct {
|
type P2PInfo struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user