rm some config save
This commit is contained in:
+7
-3
@@ -210,7 +210,6 @@ func (c *Config) add(app AppConfig, override bool) {
|
||||
}
|
||||
c.mtx.Lock()
|
||||
defer c.mtx.Unlock()
|
||||
defer c.save()
|
||||
if override {
|
||||
for i := 0; i < len(c.Apps); i++ {
|
||||
if c.Apps[i].PeerNode == app.PeerNode && c.Apps[i].Protocol == app.Protocol && c.Apps[i].SrcPort == app.SrcPort {
|
||||
@@ -220,12 +219,14 @@ func (c *Config) add(app AppConfig, override bool) {
|
||||
}
|
||||
}
|
||||
c.Apps = append(c.Apps, &app)
|
||||
if app.SrcPort != 0 {
|
||||
c.save()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Config) delete(app AppConfig) {
|
||||
c.mtx.Lock()
|
||||
defer c.mtx.Unlock()
|
||||
defer c.save()
|
||||
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
|
||||
(app.SrcPort == 0 && c.Apps[i].SrcPort == 0 && c.Apps[i].PeerNode == app.PeerNode) { // memapp
|
||||
@@ -234,9 +235,12 @@ func (c *Config) delete(app AppConfig) {
|
||||
} else {
|
||||
c.Apps = append(c.Apps[:i], c.Apps[i+1:]...)
|
||||
}
|
||||
return
|
||||
break
|
||||
}
|
||||
}
|
||||
if app.SrcPort != 0 {
|
||||
c.save()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Config) save() {
|
||||
|
||||
@@ -211,6 +211,8 @@ func handlePush(subType uint16, msg []byte) error {
|
||||
gConf.Network.specTunnel = int(req.TunnelIndex)
|
||||
case MsgPushSDWanRefresh:
|
||||
GNetwork.write(MsgSDWAN, MsgSDWANInfoReq, nil)
|
||||
case MsgPushNat4Detect:
|
||||
handleNat4Detect(msg)
|
||||
default:
|
||||
i, ok := GNetwork.msgMap.Load(pushHead.From)
|
||||
if !ok {
|
||||
@@ -222,6 +224,45 @@ func handlePush(subType uint16, msg []byte) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func handleNat4Detect(msg []byte) (err error) {
|
||||
gLog.d("handleNat4Detect")
|
||||
nd := Nat4Detect{}
|
||||
if err = json.Unmarshal(msg[openP2PHeaderSize:], &nd); err != nil {
|
||||
gLog.e("Unmarshal %v:%s %s", reflect.TypeOf(nd), err, string(msg[openP2PHeaderSize:]))
|
||||
return err
|
||||
}
|
||||
detectNatPort := func(protocol, server string, serverPort, localPort int) int {
|
||||
natPort := 0
|
||||
if protocol == "tcp" {
|
||||
_, natPort, _, _ = natDetectTCP(server, serverPort, localPort)
|
||||
} else {
|
||||
_, natPort, _ = natDetectUDP(server, serverPort, localPort)
|
||||
}
|
||||
// gLog.i("%s %s %d %d %d", protocol, server, serverPort, localPort, natPort)
|
||||
return natPort
|
||||
}
|
||||
|
||||
result := ""
|
||||
if nd.Num > 0 {
|
||||
for i := 0; i < int(nd.Num); i++ {
|
||||
natPort := detectNatPort(nd.Protocol, nd.Server, int(nd.ServerPort), int(nd.LocalPort)+i)
|
||||
if i > 0 {
|
||||
result += ","
|
||||
}
|
||||
result += fmt.Sprintf("%d", natPort)
|
||||
}
|
||||
} else {
|
||||
for idx, item := range nd.CustomData {
|
||||
natPort := detectNatPort(item.Protocol, item.Server, int(item.ServerPort), int(item.LocalPort))
|
||||
if idx > 0 {
|
||||
result += ","
|
||||
}
|
||||
result += fmt.Sprintf("%d", natPort)
|
||||
}
|
||||
}
|
||||
return GNetwork.write(MsgReport, MsgPushReportLog, &result)
|
||||
}
|
||||
|
||||
func handleEditApp(msg []byte) (err error) {
|
||||
gLog.i("MsgPushEditApp")
|
||||
newApp := AppInfo{}
|
||||
|
||||
+15
-1
@@ -10,7 +10,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const OpenP2PVersion = "3.24.28"
|
||||
const OpenP2PVersion = "3.24.33"
|
||||
const ProductName string = "openp2p"
|
||||
const LeastSupportVersion = "3.0.0"
|
||||
const SyncServerTimeVersion = "3.9.0"
|
||||
@@ -119,6 +119,7 @@ const (
|
||||
MsgPushSpecTunnel = 20
|
||||
MsgPushReportHeap = 21
|
||||
MsgPushSDWanRefresh = 22
|
||||
MsgPushNat4Detect = 23
|
||||
)
|
||||
|
||||
// MsgP2P sub type message
|
||||
@@ -566,6 +567,19 @@ type SpecTunnel struct {
|
||||
TunnelIndex uint32 `json:"tunnelIndex,omitempty"`
|
||||
}
|
||||
|
||||
type Nat4Detect struct {
|
||||
CustomData []*Nat4DetectItem
|
||||
Num int32 `json:"num,omitempty"`
|
||||
*Nat4DetectItem
|
||||
}
|
||||
|
||||
type Nat4DetectItem struct {
|
||||
Protocol string `json:"protocol,omitempty"`
|
||||
Server string `json:"server,omitempty"`
|
||||
ServerPort int32 `json:"serverPort,omitempty"`
|
||||
LocalPort int32 `json:"localPort,omitempty"`
|
||||
}
|
||||
|
||||
const rootCA = `-----BEGIN CERTIFICATE-----
|
||||
MIIDhTCCAm0CFHm0cd8dnGCbUW/OcS56jf0gvRk7MA0GCSqGSIb3DQEBCwUAMH4x
|
||||
CzAJBgNVBAYTAkNOMQswCQYDVQQIDAJHRDETMBEGA1UECgwKb3BlbnAycC5jbjET
|
||||
|
||||
Reference in New Issue
Block a user