fix system service bug and docker run path and nat detect bug
This commit is contained in:
+14
-14
@@ -385,11 +385,11 @@ type NetworkConfig struct {
|
|||||||
hasUPNPorNATPMP int
|
hasUPNPorNATPMP int
|
||||||
ShareBandwidth int
|
ShareBandwidth int
|
||||||
// server info
|
// server info
|
||||||
ServerHost string
|
ServerHost string
|
||||||
ServerPort int
|
ServerPort int
|
||||||
UDPPort1 int
|
NATDetectPort1 int
|
||||||
UDPPort2 int
|
NATDetectPort2 int
|
||||||
TCPPort int
|
PublicIPPort int
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseParams(subCommand string, cmd string) {
|
func parseParams(subCommand string, cmd string) {
|
||||||
@@ -404,7 +404,7 @@ func parseParams(subCommand string, cmd string) {
|
|||||||
whiteList := fset.String("whitelist", "", "whitelist for p2pApp ")
|
whiteList := fset.String("whitelist", "", "whitelist for p2pApp ")
|
||||||
dstPort := fset.Int("dstport", 0, "destination port ")
|
dstPort := fset.Int("dstport", 0, "destination port ")
|
||||||
srcPort := fset.Int("srcport", 0, "source port ")
|
srcPort := fset.Int("srcport", 0, "source port ")
|
||||||
tcpPort := fset.Int("tcpport", 0, "tcp port for upnp or publicip")
|
publicIPPort := fset.Int("publicipport", 0, "public ip port for upnp or publicip")
|
||||||
protocol := fset.String("protocol", "tcp", "tcp or udp")
|
protocol := fset.String("protocol", "tcp", "tcp or udp")
|
||||||
underlayProtocol := fset.String("underlay_protocol", "quic", "quic or kcp")
|
underlayProtocol := fset.String("underlay_protocol", "quic", "quic or kcp")
|
||||||
punchPriority := fset.Int("punch_priority", 0, "bitwise DisableTCP|DisableUDP|UDPFirst 0:tcp and udp both enable, tcp first")
|
punchPriority := fset.Int("punch_priority", 0, "bitwise DisableTCP|DisableUDP|UDPFirst 0:tcp and udp both enable, tcp first")
|
||||||
@@ -464,8 +464,8 @@ func parseParams(subCommand string, cmd string) {
|
|||||||
if f.Name == "maxlogsize" {
|
if f.Name == "maxlogsize" {
|
||||||
gConf.MaxLogSize = *maxLogSize
|
gConf.MaxLogSize = *maxLogSize
|
||||||
}
|
}
|
||||||
if f.Name == "tcpport" {
|
if f.Name == "publicipport" {
|
||||||
gConf.Network.TCPPort = *tcpPort
|
gConf.Network.PublicIPPort = *publicIPPort
|
||||||
}
|
}
|
||||||
if f.Name == "token" {
|
if f.Name == "token" {
|
||||||
gConf.setToken(*token)
|
gConf.setToken(*token)
|
||||||
@@ -486,12 +486,12 @@ func parseParams(subCommand string, cmd string) {
|
|||||||
gConf.setNode(defaultNodeName())
|
gConf.setNode(defaultNodeName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if gConf.Network.TCPPort == 0 {
|
if gConf.Network.PublicIPPort == 0 {
|
||||||
if *tcpPort == 0 {
|
if *publicIPPort == 0 {
|
||||||
p := int(gConf.nodeID()%15000 + 50000)
|
p := int(gConf.nodeID()%15000 + 50000)
|
||||||
tcpPort = &p
|
publicIPPort = &p
|
||||||
}
|
}
|
||||||
gConf.Network.TCPPort = *tcpPort
|
gConf.Network.PublicIPPort = *publicIPPort
|
||||||
}
|
}
|
||||||
if *token == 0 {
|
if *token == 0 {
|
||||||
envToken := os.Getenv("OPENP2P_TOKEN")
|
envToken := os.Getenv("OPENP2P_TOKEN")
|
||||||
@@ -502,8 +502,8 @@ func parseParams(subCommand string, cmd string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
gConf.Network.ServerPort = *serverPort
|
gConf.Network.ServerPort = *serverPort
|
||||||
gConf.Network.UDPPort1 = UDPPort1
|
gConf.Network.NATDetectPort1 = NATDetectPort1
|
||||||
gConf.Network.UDPPort2 = UDPPort2
|
gConf.Network.NATDetectPort2 = NATDetectPort2
|
||||||
gLog.setLevel(LogLevel(gConf.LogLevel))
|
gLog.setLevel(LogLevel(gConf.LogLevel))
|
||||||
gLog.setMaxSize(int64(gConf.MaxLogSize))
|
gLog.setMaxSize(int64(gConf.MaxLogSize))
|
||||||
if *notVerbose {
|
if *notVerbose {
|
||||||
|
|||||||
+1
-1
@@ -149,7 +149,7 @@ 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", gConf.Network.ServerIP, gConf.Network.ServerPort))
|
dst, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", gConf.Network.ServerHost, gConf.Network.ServerPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -507,13 +507,13 @@ func (pn *P2PNetwork) init() error {
|
|||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
// detect nat type
|
// detect nat type
|
||||||
gConf.Network.publicIP, gConf.Network.natType, err = getNATType(gConf.Network.ServerHost, gConf.Network.UDPPort1, gConf.Network.UDPPort2)
|
gConf.Network.publicIP, gConf.Network.natType, err = getNATType(gConf.Network.ServerHost, gConf.Network.NATDetectPort1, gConf.Network.NATDetectPort2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gLog.Println(LvDEBUG, "detect NAT type error:", err)
|
gLog.Println(LvDEBUG, "detect NAT type error:", err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if gConf.Network.hasIPv4 == 0 && gConf.Network.hasUPNPorNATPMP == 0 { // if already has ipv4 or upnp no need test again
|
if gConf.Network.hasIPv4 == 0 && gConf.Network.hasUPNPorNATPMP == 0 { // if already has ipv4 or upnp no need test again
|
||||||
gConf.Network.hasIPv4, gConf.Network.hasUPNPorNATPMP = publicIPTest(gConf.Network.publicIP, gConf.Network.TCPPort)
|
gConf.Network.hasIPv4, gConf.Network.hasUPNPorNATPMP = publicIPTest(gConf.Network.publicIP, gConf.Network.PublicIPPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
// for testcase
|
// for testcase
|
||||||
@@ -533,7 +533,7 @@ func (pn *P2PNetwork) init() error {
|
|||||||
|
|
||||||
// public ip and intranet connect
|
// public ip and intranet connect
|
||||||
onceV4Listener.Do(func() {
|
onceV4Listener.Do(func() {
|
||||||
v4l = &v4Listener{port: gConf.Network.TCPPort}
|
v4l = &v4Listener{port: gConf.Network.PublicIPPort}
|
||||||
go v4l.start()
|
go v4l.start()
|
||||||
})
|
})
|
||||||
gLog.Printf(LvINFO, "hasIPv4:%d, UPNP:%d, NAT type:%d, publicIP:%s", gConf.Network.hasIPv4, gConf.Network.hasUPNPorNATPMP, gConf.Network.natType, gConf.Network.publicIP)
|
gLog.Printf(LvINFO, "hasIPv4:%d, UPNP:%d, NAT type:%d, publicIP:%s", gConf.Network.hasIPv4, gConf.Network.hasUPNPorNATPMP, gConf.Network.natType, gConf.Network.publicIP)
|
||||||
|
|||||||
+4
-4
@@ -42,18 +42,18 @@ func (t *P2PTunnel) initPort() {
|
|||||||
t.running = true
|
t.running = true
|
||||||
localPort := int(rand.Uint32()%15000 + 50000) // if the process has bug, will add many upnp port. use specify p2p port by param
|
localPort := int(rand.Uint32()%15000 + 50000) // if the process has bug, will add many upnp port. use specify p2p port by param
|
||||||
if t.config.linkMode == LinkModeTCP6 || t.config.linkMode == LinkModeTCP4 || t.config.linkMode == LinkModeIntranet {
|
if t.config.linkMode == LinkModeTCP6 || t.config.linkMode == LinkModeTCP4 || t.config.linkMode == LinkModeIntranet {
|
||||||
t.coneLocalPort = gConf.Network.TCPPort
|
t.coneLocalPort = gConf.Network.PublicIPPort
|
||||||
t.coneNatPort = gConf.Network.TCPPort // symmetric doesn't need coneNatPort
|
t.coneNatPort = gConf.Network.PublicIPPort // symmetric doesn't need coneNatPort
|
||||||
}
|
}
|
||||||
if t.config.linkMode == LinkModeUDPPunch {
|
if t.config.linkMode == LinkModeUDPPunch {
|
||||||
// prepare one random cone hole manually
|
// prepare one random cone hole manually
|
||||||
_, natPort, _ := natTest(gConf.Network.ServerHost, gConf.Network.UDPPort1, localPort)
|
_, natPort, _ := natDetectUDP(gConf.Network.ServerHost, NATDetectPort1, localPort)
|
||||||
t.coneLocalPort = localPort
|
t.coneLocalPort = localPort
|
||||||
t.coneNatPort = natPort
|
t.coneNatPort = natPort
|
||||||
}
|
}
|
||||||
if t.config.linkMode == LinkModeTCPPunch {
|
if t.config.linkMode == LinkModeTCPPunch {
|
||||||
// prepare one random cone hole by system automatically
|
// prepare one random cone hole by system automatically
|
||||||
_, natPort, localPort2 := natTCP(gConf.Network.ServerHost, IfconfigPort1)
|
_, natPort, localPort2, _ := natDetectTCP(gConf.Network.ServerHost, NATDetectPort1, 0)
|
||||||
t.coneLocalPort = localPort2
|
t.coneLocalPort = localPort2
|
||||||
t.coneNatPort = natPort
|
t.coneNatPort = natPort
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -20,11 +20,11 @@ const SupportIntranetVersion = "3.14.5"
|
|||||||
const SupportDualTunnelVersion = "3.15.5"
|
const SupportDualTunnelVersion = "3.15.5"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
IfconfigPort1 = 27180
|
IfconfigPort1 = 27180
|
||||||
IfconfigPort2 = 27181
|
IfconfigPort2 = 27181
|
||||||
WsPort = 27183
|
WsPort = 27183
|
||||||
UDPPort1 = 27182
|
NATDetectPort1 = 27182
|
||||||
UDPPort2 = 27183
|
NATDetectPort2 = 27183
|
||||||
)
|
)
|
||||||
|
|
||||||
type openP2PHeader struct {
|
type openP2PHeader struct {
|
||||||
@@ -173,7 +173,7 @@ const (
|
|||||||
Cone2ConeTCPPunchMaxRetry = 1
|
Cone2ConeTCPPunchMaxRetry = 1
|
||||||
Cone2ConeUDPPunchMaxRetry = 1
|
Cone2ConeUDPPunchMaxRetry = 1
|
||||||
PublicIPEchoTimeout = time.Second * 3
|
PublicIPEchoTimeout = time.Second * 3
|
||||||
NatTestTimeout = time.Second * 5
|
NatDetectTimeout = time.Second * 5
|
||||||
UDPReadTimeout = time.Second * 5
|
UDPReadTimeout = time.Second * 5
|
||||||
ClientAPITimeout = time.Second * 10
|
ClientAPITimeout = time.Second * 10
|
||||||
UnderlayConnectTimeout = time.Second * 10
|
UnderlayConnectTimeout = time.Second * 10
|
||||||
|
|||||||
Reference in New Issue
Block a user