portmap loss & android ipv6 failed & public ip detect
This commit is contained in:
@@ -203,7 +203,8 @@ class OpenP2PService : VpnService() {
|
|||||||
val network = Network(id, name, gateway, nodeList)
|
val network = Network(id, name, gateway, nodeList)
|
||||||
println(network)
|
println(network)
|
||||||
Log.i(OpenP2PService.LOG_TAG, "onBind");
|
Log.i(OpenP2PService.LOG_TAG, "onBind");
|
||||||
builder.addDnsServer("8.8.8.8")
|
builder.addDnsServer("223.5.5.5")
|
||||||
|
builder.addDnsServer("2400:3200::1") // alicloud dns v6 & v4
|
||||||
builder.addRoute("10.2.3.0", 24)
|
builder.addRoute("10.2.3.0", 24)
|
||||||
// builder.addRoute("0.0.0.0", 0);
|
// builder.addRoute("0.0.0.0", 0);
|
||||||
builder.setSession(LOG_TAG!!)
|
builder.setSession(LOG_TAG!!)
|
||||||
|
|||||||
+1
-1
@@ -239,7 +239,7 @@ func (c *Config) delete(app AppConfig) {
|
|||||||
defer c.save()
|
defer c.save()
|
||||||
for i := 0; i < len(c.Apps); i++ {
|
for i := 0; i < len(c.Apps); i++ {
|
||||||
if (app.SrcPort != 0 && c.Apps[i].Protocol == app.Protocol && c.Apps[i].SrcPort == app.SrcPort) || // normal app
|
if (app.SrcPort != 0 && c.Apps[i].Protocol == app.Protocol && c.Apps[i].SrcPort == app.SrcPort) || // normal app
|
||||||
(app.SrcPort == 0 && c.Apps[i].PeerNode == app.PeerNode) { // memapp
|
(app.SrcPort == 0 && c.Apps[i].SrcPort == 0 && c.Apps[i].PeerNode == app.PeerNode) { // memapp
|
||||||
if i == len(c.Apps)-1 {
|
if i == len(c.Apps)-1 {
|
||||||
c.Apps = c.Apps[:i]
|
c.Apps = c.Apps[:i]
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+21
-5
@@ -66,7 +66,7 @@ func natTest(serverHost string, serverPort int, localPort int) (publicIP string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The connection can write data to the desired address.
|
// The connection can write data to the desired address.
|
||||||
msg, err := newMessage(MsgNATDetect, 0, nil)
|
msg, err := newMessage(MsgNATDetect, MsgNAT, nil)
|
||||||
_, err = conn.WriteTo(msg, dst)
|
_, err = conn.WriteTo(msg, dst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, err
|
return "", 0, err
|
||||||
@@ -164,17 +164,33 @@ func publicIPTest(publicIP string, echoPort int) (hasPublicIP int, hasUPNPorNATP
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
dst, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", publicIP, echoPort))
|
dst, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", gConf.Network.ServerHost, gConf.Network.ServerPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
conn.WriteTo([]byte("echo"), dst)
|
|
||||||
|
// The connection can write data to the desired address.
|
||||||
|
msg, _ := newMessage(MsgNATDetect, MsgPublicIP, NatDetectReq{EchoPort: echoPort})
|
||||||
|
_, err = conn.WriteTo(msg, dst)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
buf := make([]byte, 1600)
|
buf := make([]byte, 1600)
|
||||||
|
|
||||||
// wait for echo testing
|
// wait for echo testing
|
||||||
conn.SetReadDeadline(time.Now().Add(PublicIPEchoTimeout))
|
conn.SetReadDeadline(time.Now().Add(PublicIPEchoTimeout))
|
||||||
_, _, err = conn.ReadFromUDP(buf)
|
nRead, _, err := conn.ReadFromUDP(buf)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
|
gLog.Println(LvERROR, "PublicIP detect error:", err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
natRsp := NatDetectRsp{}
|
||||||
|
err = json.Unmarshal(buf[openP2PHeaderSize:nRead], &natRsp)
|
||||||
|
if err != nil {
|
||||||
|
gLog.Println(LvERROR, "PublicIP detect error:", err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if natRsp.Port == echoPort {
|
||||||
if i == 1 {
|
if i == 1 {
|
||||||
gLog.Println(LvDEBUG, "UPNP or NAT-PMP:YES")
|
gLog.Println(LvDEBUG, "UPNP or NAT-PMP:YES")
|
||||||
hasUPNPorNATPMP = 1
|
hasUPNPorNATPMP = 1
|
||||||
|
|||||||
+7
-1
@@ -10,7 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const OpenP2PVersion = "3.21.8"
|
const OpenP2PVersion = "3.21.10"
|
||||||
const ProductName string = "openp2p"
|
const ProductName string = "openp2p"
|
||||||
const LeastSupportVersion = "3.0.0"
|
const LeastSupportVersion = "3.0.0"
|
||||||
const SyncServerTimeVersion = "3.9.0"
|
const SyncServerTimeVersion = "3.9.0"
|
||||||
@@ -217,6 +217,12 @@ const (
|
|||||||
MsgSDWANInfoRsp
|
MsgSDWANInfoRsp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// MsgNATDetect
|
||||||
|
const (
|
||||||
|
MsgNAT = iota
|
||||||
|
MsgPublicIP
|
||||||
|
)
|
||||||
|
|
||||||
func newMessage(mainType uint16, subType uint16, packet interface{}) ([]byte, error) {
|
func newMessage(mainType uint16, subType uint16, packet interface{}) ([]byte, error) {
|
||||||
data, err := json.Marshal(packet)
|
data, err := json.Marshal(packet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ func DefaultReadBuffer(ul underlay) (*openP2PHeader, []byte, error) {
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
head, err := decodeHeader(headBuf)
|
head, err := decodeHeader(headBuf)
|
||||||
if err != nil {
|
if err != nil || head.MainType > 16 {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
dataBuf := make([]byte, head.DataLen)
|
dataBuf := make([]byte, head.DataLen)
|
||||||
|
|||||||
Reference in New Issue
Block a user