allow gencfg overwrite and ntp all failed

This commit is contained in:
KusakabeSi 2022-02-10 15:31:11 +00:00
parent 76071f0d0d
commit 9fce61bf11
14 changed files with 167 additions and 81 deletions

View File

@ -1,4 +1,6 @@
Config output dir: /tmp/eg_gen_p2p Config output dir: /tmp/eg_gen_p2p
Enable generated config overwrite: false
Add NodeID to the interface name: true
ConfigTemplate for edge node: "" ConfigTemplate for edge node: ""
Network name: "EgNet" Network name: "EgNet"
Edge Node: Edge Node:

View File

@ -1,4 +1,6 @@
Config output dir: /tmp/eg_gen_p2p Config output dir: /tmp/eg_gen_p2p
Enable generated config overwrite: false
Add NodeID to the interface name: true
ConfigTemplate for edge node: "EgNet_edge1.yaml" ConfigTemplate for edge node: "EgNet_edge1.yaml"
Network name: "EgNet" Network name: "EgNet"
Edge Node: Edge Node:

View File

@ -1,4 +1,6 @@
Config output dir: /tmp/eg_gen_static Config output dir: /tmp/eg_gen_static
Enable generated config overwrite: false
Add NodeID to the interface name: true
ConfigTemplate for edge node: "EgNet_edge1.yaml" ConfigTemplate for edge node: "EgNet_edge1.yaml"
Network name: "EgNet" Network name: "EgNet"
Edge Node: Edge Node:

View File

@ -3,7 +3,7 @@ Interface:
Name: EgNet001 Name: EgNet001
VPPIFaceID: 1 VPPIFaceID: 1
VPPBridgeID: 4242 VPPBridgeID: 4242
MacAddrPrefix: FA:A7:11:D6 MacAddrPrefix: 96:BB:DC:52
IPv4CIDR: 192.168.76.0/24 IPv4CIDR: 192.168.76.0/24
IPv6CIDR: fd95:71cb:a3df:e586::/64 IPv6CIDR: fd95:71cb:a3df:e586::/64
IPv6LLPrefix: fe80::a3df:0/112 IPv6LLPrefix: fe80::a3df:0/112
@ -16,7 +16,7 @@ NodeName: EgNet001
PostScript: "" PostScript: ""
DefaultTTL: 200 DefaultTTL: 200
L2FIBTimeout: 3600 L2FIBTimeout: 3600
PrivKey: +KAYwkRgacUbxc52t04z8fTJBgvrkPLsisr0qJOhIUE= PrivKey: lyQLML+TbAZvrJpa25ARTAfMvHVQa/a1n3Wcwo7nkDU=
ListenPort: 3001 ListenPort: 3001
DisabledAf: DisabledAf:
IPv4: false IPv4: false
@ -40,11 +40,11 @@ DynamicRoute:
SaveNewPeers: true SaveNewPeers: true
SuperNode: SuperNode:
UseSuperNode: true UseSuperNode: true
PSKey: yl/4SNFee7+kNekajVCrK0toqXJ4mlT4IN0klyAgyqU= PSKey: Ld8FN/TNcmR21xdhMTCSeZBxrJ1z+FFvnQSnTwSxgUE=
EndpointV4: 127.0.0.1:3456 EndpointV4: 127.0.0.1:3456
PubKeyV4: 1NS6MxL2LUIlMsppJ5JfHnlofQfCxDUzaItBGwz+jBo= PubKeyV4: j6+qNLYwGLILh4VKXc2fGeQy828RnRasA6zKHk3T/kw=
EndpointV6: "" EndpointV6: ""
PubKeyV6: gSBwlJH4aUPRfSP4ZHKAnXIkPZuVaEhsLBispLYFiwo= PubKeyV6: SdrhLctYIQ7lEurGNn0ZjM8ezkPaKPCI+nAbrnwvUDA=
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: [] AdditionalLocalIP: []
@ -62,7 +62,7 @@ DynamicRoute:
NTPConfig: NTPConfig:
UseNTP: true UseNTP: true
MaxServerUse: 8 MaxServerUse: 8
SyncTimeInterval: 3600 SyncTimeInterval: 99999
NTPTimeout: 3 NTPTimeout: 3
Servers: Servers:
- time.google.com - time.google.com
@ -85,6 +85,13 @@ DynamicRoute:
- 1.pool.ntp.org - 1.pool.ntp.org
- 2.pool.ntp.org - 2.pool.ntp.org
- 3.pool.ntp.org - 3.pool.ntp.org
- cn.ntp.org.cn
- edu.ntp.org.cn
- hk.ntp.org.cn
- tw.ntp.org.cn
- ntp.aliyun.com
- time1.cloud.tencent.com
- ntp.tuna.tsinghua.edu.cn
NextHopTable: {} NextHopTable: {}
ResetEndPointInterval: 600 ResetEndPointInterval: 600
Peers: [] Peers: []

View File

@ -3,7 +3,7 @@ Interface:
Name: EgNet002 Name: EgNet002
VPPIFaceID: 1 VPPIFaceID: 1
VPPBridgeID: 4242 VPPBridgeID: 4242
MacAddrPrefix: FA:A7:11:D6 MacAddrPrefix: 96:BB:DC:52
IPv4CIDR: 192.168.76.0/24 IPv4CIDR: 192.168.76.0/24
IPv6CIDR: fd95:71cb:a3df:e586::/64 IPv6CIDR: fd95:71cb:a3df:e586::/64
IPv6LLPrefix: fe80::a3df:0/112 IPv6LLPrefix: fe80::a3df:0/112
@ -16,7 +16,7 @@ NodeName: EgNet002
PostScript: "" PostScript: ""
DefaultTTL: 200 DefaultTTL: 200
L2FIBTimeout: 3600 L2FIBTimeout: 3600
PrivKey: jDAolOiiRj/ju1xpVagZTtsxJSJba2rjp7J2XMc3yoM= PrivKey: r6vMkwreEkbpXoaHgdecPuWhaVK4qWlKazgQbYPDSQ4=
ListenPort: 3002 ListenPort: 3002
DisabledAf: DisabledAf:
IPv4: false IPv4: false
@ -40,11 +40,11 @@ DynamicRoute:
SaveNewPeers: true SaveNewPeers: true
SuperNode: SuperNode:
UseSuperNode: true UseSuperNode: true
PSKey: FJfjc+wRfk0FSuUkHlXl6D8xPzOKYdy3bxeYr5cpevQ= PSKey: Wmhz6SvUNBGczD0iJjHn7gUGy15ahjQsr4lKJAqDE3A=
EndpointV4: 127.0.0.1:3456 EndpointV4: 127.0.0.1:3456
PubKeyV4: 1NS6MxL2LUIlMsppJ5JfHnlofQfCxDUzaItBGwz+jBo= PubKeyV4: j6+qNLYwGLILh4VKXc2fGeQy828RnRasA6zKHk3T/kw=
EndpointV6: "" EndpointV6: ""
PubKeyV6: gSBwlJH4aUPRfSP4ZHKAnXIkPZuVaEhsLBispLYFiwo= PubKeyV6: SdrhLctYIQ7lEurGNn0ZjM8ezkPaKPCI+nAbrnwvUDA=
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: [] AdditionalLocalIP: []
@ -62,7 +62,7 @@ DynamicRoute:
NTPConfig: NTPConfig:
UseNTP: true UseNTP: true
MaxServerUse: 8 MaxServerUse: 8
SyncTimeInterval: 3600 SyncTimeInterval: 99999
NTPTimeout: 3 NTPTimeout: 3
Servers: Servers:
- time.google.com - time.google.com
@ -85,6 +85,13 @@ DynamicRoute:
- 1.pool.ntp.org - 1.pool.ntp.org
- 2.pool.ntp.org - 2.pool.ntp.org
- 3.pool.ntp.org - 3.pool.ntp.org
- cn.ntp.org.cn
- edu.ntp.org.cn
- hk.ntp.org.cn
- tw.ntp.org.cn
- ntp.aliyun.com
- time1.cloud.tencent.com
- ntp.tuna.tsinghua.edu.cn
NextHopTable: {} NextHopTable: {}
ResetEndPointInterval: 600 ResetEndPointInterval: 600
Peers: [] Peers: []

View File

@ -3,7 +3,7 @@ Interface:
Name: EgNet100 Name: EgNet100
VPPIFaceID: 1 VPPIFaceID: 1
VPPBridgeID: 4242 VPPBridgeID: 4242
MacAddrPrefix: FA:A7:11:D6 MacAddrPrefix: 96:BB:DC:52
IPv4CIDR: 192.168.76.0/24 IPv4CIDR: 192.168.76.0/24
IPv6CIDR: fd95:71cb:a3df:e586::/64 IPv6CIDR: fd95:71cb:a3df:e586::/64
IPv6LLPrefix: fe80::a3df:0/112 IPv6LLPrefix: fe80::a3df:0/112
@ -16,7 +16,7 @@ NodeName: EgNet100
PostScript: "" PostScript: ""
DefaultTTL: 200 DefaultTTL: 200
L2FIBTimeout: 3600 L2FIBTimeout: 3600
PrivKey: yNf1SkvwV8c59GmesfTNxSut6gFjYKEg9uIsE05XQUI= PrivKey: U68wDkoic4xviKbOed9EBykI/wgpfpHGmc8N4ML5spE=
ListenPort: 0 ListenPort: 0
DisabledAf: DisabledAf:
IPv4: false IPv4: false
@ -40,11 +40,11 @@ DynamicRoute:
SaveNewPeers: true SaveNewPeers: true
SuperNode: SuperNode:
UseSuperNode: true UseSuperNode: true
PSKey: 5BPLK4IX3oUd4ILQct2Xc690kkKeUd4jlyeFBkO6pHA= PSKey: Ffe8veAmFX/L8lmNxbb2sofBx/K1CCY3u1osKh0sL2g=
EndpointV4: 127.0.0.1:3456 EndpointV4: 127.0.0.1:3456
PubKeyV4: 1NS6MxL2LUIlMsppJ5JfHnlofQfCxDUzaItBGwz+jBo= PubKeyV4: j6+qNLYwGLILh4VKXc2fGeQy828RnRasA6zKHk3T/kw=
EndpointV6: "" EndpointV6: ""
PubKeyV6: gSBwlJH4aUPRfSP4ZHKAnXIkPZuVaEhsLBispLYFiwo= PubKeyV6: SdrhLctYIQ7lEurGNn0ZjM8ezkPaKPCI+nAbrnwvUDA=
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: [] AdditionalLocalIP: []
@ -62,7 +62,7 @@ DynamicRoute:
NTPConfig: NTPConfig:
UseNTP: true UseNTP: true
MaxServerUse: 8 MaxServerUse: 8
SyncTimeInterval: 3600 SyncTimeInterval: 99999
NTPTimeout: 3 NTPTimeout: 3
Servers: Servers:
- time.google.com - time.google.com
@ -85,6 +85,13 @@ DynamicRoute:
- 1.pool.ntp.org - 1.pool.ntp.org
- 2.pool.ntp.org - 2.pool.ntp.org
- 3.pool.ntp.org - 3.pool.ntp.org
- cn.ntp.org.cn
- edu.ntp.org.cn
- hk.ntp.org.cn
- tw.ntp.org.cn
- ntp.aliyun.com
- time1.cloud.tencent.com
- ntp.tuna.tsinghua.edu.cn
NextHopTable: {} NextHopTable: {}
ResetEndPointInterval: 600 ResetEndPointInterval: 600
Peers: [] Peers: []

View File

@ -1,7 +1,7 @@
NodeName: EgNetSP NodeName: EgNetSN
PostScript: "" PostScript: ""
PrivKeyV4: W4hrtkH+htbU3/zAbKLdFeflMSUoKLf741DONjnLk18= PrivKeyV4: vm2M7cNXbrUFORMiLvlbAxXX0l0yduo5TAJ9vyRTQZE=
PrivKeyV6: y47AY2xGs4uiUTHfMLhxooMPu/mFOezSFQ1iZ9giW7E= PrivKeyV6: xUJ4yaVl/O//PRS24UFMNXgmeF/rhykroCxdJrljFgE=
ListenPort: 3456 ListenPort: 3456
ListenPort_EdgeAPI: "3456" ListenPort_EdgeAPI: "3456"
ListenPort_ManageAPI: "3456" ListenPort_ManageAPI: "3456"
@ -42,28 +42,28 @@ GraphRecalculateSetting:
NextHopTable: {} NextHopTable: {}
EdgeTemplate: EgNet_edge001.yaml EdgeTemplate: EgNet_edge001.yaml
UsePSKForInterEdge: true UsePSKForInterEdge: true
makResetEndPointInterval: 1 ResetEndPointInterval: 600
Peers: Peers:
- NodeID: 1 - NodeID: 1
Name: EgNet001 Name: EgNet001
PubKey: 6mdRv+McDgxWIq6bVB1ekxnMMWqhktzHc3JIq5bCSHI= PubKey: lMiu9Qvf9qTo+X539+IxyA3YOleXMVTKtfOVHAnOIic=
PSKey: yl/4SNFee7+kNekajVCrK0toqXJ4mlT4IN0klyAgyqU= PSKey: Ld8FN/TNcmR21xdhMTCSeZBxrJ1z+FFvnQSnTwSxgUE=
AdditionalCost: 10 AdditionalCost: 10
SkipLocalIP: false SkipLocalIP: false
EndPoint: "127.0.0.1:3001" EndPoint: ""
ExternalIP: "" ExternalIP: ""
- NodeID: 2 - NodeID: 2
Name: EgNet002 Name: EgNet002
PubKey: Xb6eYSf4fTkFRLGVqf1sAPBXMKlWsRAbajs1mYABT0w= PubKey: Ev271azq3FXmjhCWtwgVvqe9EN017mijjqMiB9LVQU8=
PSKey: FJfjc+wRfk0FSuUkHlXl6D8xPzOKYdy3bxeYr5cpevQ= PSKey: Wmhz6SvUNBGczD0iJjHn7gUGy15ahjQsr4lKJAqDE3A=
AdditionalCost: 10 AdditionalCost: 10
SkipLocalIP: false SkipLocalIP: false
EndPoint: "127.0.0.1:3002" EndPoint: ""
ExternalIP: "" ExternalIP: ""
- NodeID: 100 - NodeID: 100
Name: EgNet100 Name: EgNet100
PubKey: cZb8NNE1FBLy6kIUGXjdXCprUHuqzfpyXTwUxHJobnM= PubKey: nL3BdnKYt+DGl783iYe/7JETVTZU31RkHQu4x49Wk0s=
PSKey: 5BPLK4IX3oUd4ILQct2Xc690kkKeUd4jlyeFBkO6pHA= PSKey: Ffe8veAmFX/L8lmNxbb2sofBx/K1CCY3u1osKh0sL2g=
AdditionalCost: 10 AdditionalCost: 10
SkipLocalIP: false SkipLocalIP: false
EndPoint: "" EndPoint: ""

View File

@ -1,4 +1,6 @@
Config output dir: /tmp/eg_gen_super Config output dir: /tmp/eg_gen_super
Enable generated config overwrite: false
Add NodeID to the interface name: true
ConfigTemplate for super node: "" # "EgNet_super.yaml" ConfigTemplate for super node: "" # "EgNet_super.yaml"
ConfigTemplate for edge node: "" # "EgNet_edge001.yaml" ConfigTemplate for edge node: "" # "EgNet_edge001.yaml"
Network name: EgNet Network name: EgNet

View File

@ -107,7 +107,7 @@ func GetExampleEdgeConf(templatePath string, getDemo bool) (mtypes.EdgeConfig, e
NTPConfig: mtypes.NTPInfo{ NTPConfig: mtypes.NTPInfo{
UseNTP: true, UseNTP: true,
MaxServerUse: 8, MaxServerUse: 8,
SyncTimeInterval: 604800, SyncTimeInterval: 99999,
NTPTimeout: 3, NTPTimeout: 3,
Servers: []string{ Servers: []string{
"time.google.com", "time.google.com",
@ -136,7 +136,7 @@ func GetExampleEdgeConf(templatePath string, getDemo bool) (mtypes.EdgeConfig, e
"tw.ntp.org.cn", "tw.ntp.org.cn",
"ntp.aliyun.com", "ntp.aliyun.com",
"time1.cloud.tencent.com", "time1.cloud.tencent.com",
"ntp.tuna.tsinghua.edu.cn ", "ntp.tuna.tsinghua.edu.cn",
}, },
}, },
}, },
@ -213,7 +213,7 @@ func GetExampleSuperConf(templatePath string, getDemo bool) (mtypes.SuperConfig,
ListenPort_ManageAPI: "3000", ListenPort_ManageAPI: "3000",
API_Prefix: "/eg_api", API_Prefix: "/eg_api",
LogLevel: mtypes.LoggerInfo{ LogLevel: mtypes.LoggerInfo{
LogLevel: "normal", LogLevel: "error",
LogTransit: false, LogTransit: false,
LogControl: true, LogControl: true,
LogNormal: false, LogNormal: false,

View File

@ -7,7 +7,6 @@ package gencfg
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
@ -50,13 +49,11 @@ func GenNMCfg(NMCinfigPath string, enableP2P bool, printExample bool) (err error
if err != nil { if err != nil {
return err return err
} }
files, err := os.ReadDir(NMCfg.ConfigOutputDir)
if err != nil { var fileWriter bulkFileWriter
return err fileWriter.files = make(map[string]fileWriterfile)
} fileWriter.ow = NMCfg.ConfigOutputDirOW
if len(files) > 0 {
return fmt.Errorf(NMCfg.ConfigOutputDir + " not empty")
}
if NMCfg.EdgeConfigTemplate != "" { if NMCfg.EdgeConfigTemplate != "" {
var econfig mtypes.EdgeConfig var econfig mtypes.EdgeConfig
err = mtypes.ReadYaml(NMCfg.EdgeConfigTemplate, &econfig) err = mtypes.ReadYaml(NMCfg.EdgeConfigTemplate, &econfig)
@ -231,6 +228,8 @@ func GenNMCfg(NMCinfigPath string, enableP2P bool, printExample bool) (err error
var pskdb device.PSKDB var pskdb device.PSKDB
for NodeID, Edge := range edge_infos { for NodeID, Edge := range edge_infos {
econfig.NodeName = NMCfg.NetworkName
econfig.Interface.Name = NMCfg.NetworkName
econfig.Interface.MacAddrPrefix = NMCfg.EdgeNode.MacPrefix econfig.Interface.MacAddrPrefix = NMCfg.EdgeNode.MacPrefix
econfig.Interface.IPv4CIDR = NMCfg.EdgeNode.IPv4Range econfig.Interface.IPv4CIDR = NMCfg.EdgeNode.IPv4Range
econfig.Interface.IPv6CIDR = NMCfg.EdgeNode.IPv6Range econfig.Interface.IPv6CIDR = NMCfg.EdgeNode.IPv6Range
@ -238,7 +237,10 @@ func GenNMCfg(NMCinfigPath string, enableP2P bool, printExample bool) (err error
econfig.PrivKey = Edge.PrivKey econfig.PrivKey = Edge.PrivKey
econfig.NodeID = NodeID econfig.NodeID = NodeID
idstr := fmt.Sprintf("%0"+strconv.Itoa(len(MaxNodeID.ToString()))+"d", NodeID) idstr := fmt.Sprintf("%0"+strconv.Itoa(len(MaxNodeID.ToString()))+"d", NodeID)
econfig.NodeName = NMCfg.NetworkName + idstr if NMCfg.NetworkIFNameID {
econfig.NodeName += idstr
econfig.Interface.Name += idstr
}
PersistentKeepalive := uint32(30) PersistentKeepalive := uint32(30)
econfig.ListenPort = 0 econfig.ListenPort = 0
if Edge.Endpoint != "" { if Edge.Endpoint != "" {
@ -263,9 +265,9 @@ func GenNMCfg(NMCinfigPath string, enableP2P bool, printExample bool) (err error
}) })
} }
mtypesBytes, _ := yaml.Marshal(econfig) mtypesBytes, _ := yaml.Marshal(econfig)
ioutil.WriteFile(filepath.Join(NMCfg.ConfigOutputDir, NMCfg.NetworkName+"_edge"+idstr+".yaml"), mtypesBytes, 0o600) fileWriter.WriteFile(filepath.Join(NMCfg.ConfigOutputDir, NMCfg.NetworkName+"_edge"+idstr+".yaml"), mtypesBytes, 0o600)
fmt.Println(filepath.Join(NMCfg.ConfigOutputDir, NMCfg.NetworkName+"_edge"+idstr+".yaml"))
} }
return nil err = fileWriter.Commit()
return err
} }

View File

@ -8,7 +8,6 @@ package gencfg
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"io/ioutil"
"math" "math"
"os" "os"
"path/filepath" "path/filepath"
@ -133,13 +132,9 @@ func GenSuperCfg(SMCinfigPath string, printExample bool) (err error) {
if err != nil { if err != nil {
return err return err
} }
files, err := os.ReadDir(SMCfg.ConfigOutputDir) var fileWriter bulkFileWriter
if err != nil { fileWriter.files = make(map[string]fileWriterfile)
return err fileWriter.ow = SMCfg.ConfigOutputDirOW
}
if len(files) > 0 {
return fmt.Errorf(SMCfg.ConfigOutputDir + " not empty")
}
if SMCfg.SuperConfigTemplate != "" { if SMCfg.SuperConfigTemplate != "" {
var sconfig mtypes.SuperConfig var sconfig mtypes.SuperConfig
@ -198,7 +193,7 @@ func GenSuperCfg(SMCinfigPath string, printExample bool) (err error) {
EndpointEdgeAPIUrl := SMCfg.Supernode.Endpoint_EdgeAPI EndpointEdgeAPIUrl := SMCfg.Supernode.Endpoint_EdgeAPI
sconfig.NodeName = SMCfg.NetworkName + "SP" sconfig.NodeName = SMCfg.NetworkName + "SN"
sconfig.API_Prefix = API_Prefix sconfig.API_Prefix = API_Prefix
sconfig.ListenPort, _ = strconv.Atoi(ListenPort) sconfig.ListenPort, _ = strconv.Atoi(ListenPort)
sconfig.ListenPort_EdgeAPI = ListenPort sconfig.ListenPort_EdgeAPI = ListenPort
@ -268,14 +263,18 @@ func GenSuperCfg(SMCinfigPath string, printExample bool) (err error) {
peerceconf.DynamicRoute.SuperNode.EndpointV6 = EndpointV6 + ":" + ListenPort peerceconf.DynamicRoute.SuperNode.EndpointV6 = EndpointV6 + ":" + ListenPort
} }
peerceconf.DynamicRoute.SuperNode.EndpointEdgeAPIUrl = EndpointEdgeAPIUrl peerceconf.DynamicRoute.SuperNode.EndpointEdgeAPIUrl = EndpointEdgeAPIUrl
peerceconf.NodeName = SMCfg.NetworkName
peerceconf.Interface.Name = SMCfg.NetworkName
if SMCfg.NetworkIFNameID {
peerceconf.NodeName += idstr
peerceconf.Interface.Name += idstr
}
peerceconf.Interface.MacAddrPrefix = MacPrefix peerceconf.Interface.MacAddrPrefix = MacPrefix
peerceconf.Interface.IPv4CIDR = IPv4Block peerceconf.Interface.IPv4CIDR = IPv4Block
peerceconf.Interface.IPv6CIDR = IPv6Block peerceconf.Interface.IPv6CIDR = IPv6Block
peerceconf.Interface.IPv6LLPrefix = IPv6LLBlock peerceconf.Interface.IPv6LLPrefix = IPv6LLBlock
peerceconf.NodeID = i peerceconf.NodeID = i
peerceconf.NodeName = SMCfg.NetworkName + idstr
peerceconf.Interface.Name = SMCfg.NetworkName + idstr
peerceconf.DynamicRoute.SuperNode.PubKeyV4 = PubKeyS4.ToString() peerceconf.DynamicRoute.SuperNode.PubKeyV4 = PubKeyS4.ToString()
peerceconf.DynamicRoute.SuperNode.PubKeyV6 = PubKeyS6.ToString() peerceconf.DynamicRoute.SuperNode.PubKeyV6 = PubKeyS6.ToString()
peerceconf.DynamicRoute.SuperNode.PSKey = PSKeyE.ToString() peerceconf.DynamicRoute.SuperNode.PSKey = PSKeyE.ToString()
@ -290,12 +289,11 @@ func GenSuperCfg(SMCinfigPath string, printExample bool) (err error) {
SkipLocalIP: peerceconf.DynamicRoute.SuperNode.SkipLocalIP, SkipLocalIP: peerceconf.DynamicRoute.SuperNode.SkipLocalIP,
}) })
mtypesBytes, _ := yaml.Marshal(peerceconf) mtypesBytes, _ := yaml.Marshal(peerceconf)
ioutil.WriteFile(filepath.Join(SMCfg.ConfigOutputDir, SMCfg.NetworkName+"_edge"+idstr+".yaml"), mtypesBytes, 0o600) fileWriter.WriteFile(filepath.Join(SMCfg.ConfigOutputDir, SMCfg.NetworkName+"_edge"+idstr+".yaml"), mtypesBytes, 0o600)
fmt.Println(filepath.Join(SMCfg.ConfigOutputDir, SMCfg.NetworkName+"_edge"+idstr+".yaml"))
} }
sconfig.Peers = SuperPeerInfo sconfig.Peers = SuperPeerInfo
mtypesBytes, _ := yaml.Marshal(sconfig) mtypesBytes, _ := yaml.Marshal(sconfig)
ioutil.WriteFile(filepath.Join(SMCfg.ConfigOutputDir, SMCfg.NetworkName+"_super.yaml"), mtypesBytes, 0o600) fileWriter.WriteFile(filepath.Join(SMCfg.ConfigOutputDir, SMCfg.NetworkName+"_super.yaml"), mtypesBytes, 0o600)
fmt.Println(filepath.Join(SMCfg.ConfigOutputDir, SMCfg.NetworkName+"_super.yaml")) err = fileWriter.Commit()
return nil return err
} }

View File

@ -6,14 +6,21 @@
package gencfg package gencfg
import ( import (
"fmt"
"io/fs"
"io/ioutil"
"os"
"github.com/KusakabeSi/EtherGuard-VPN/mtypes" "github.com/KusakabeSi/EtherGuard-VPN/mtypes"
) )
type SMCfg struct { type SMCfg struct {
ConfigOutputDir string `yaml:"Config output dir"` ConfigOutputDir string `yaml:"Config output dir"`
ConfigOutputDirOW bool `yaml:"Enable generated config overwrite"`
SuperConfigTemplate string `yaml:"ConfigTemplate for super node"` SuperConfigTemplate string `yaml:"ConfigTemplate for super node"`
EdgeConfigTemplate string `yaml:"ConfigTemplate for edge node"` EdgeConfigTemplate string `yaml:"ConfigTemplate for edge node"`
NetworkName string `yaml:"Network name"` NetworkName string `yaml:"Network name"`
NetworkIFNameID bool `yaml:"Add NodeID to the interface name"`
Supernode struct { Supernode struct {
ListenPort int `yaml:"Listen port"` ListenPort int `yaml:"Listen port"`
EdgeAPI_Prefix string `yaml:"EdgeAPI prefix"` EdgeAPI_Prefix string `yaml:"EdgeAPI prefix"`
@ -32,8 +39,10 @@ type SMCfg struct {
type NMCfg struct { type NMCfg struct {
ConfigOutputDir string `yaml:"Config output dir"` ConfigOutputDir string `yaml:"Config output dir"`
ConfigOutputDirOW bool `yaml:"Overwrite old configs"`
EdgeConfigTemplate string `yaml:"ConfigTemplate for edge node"` EdgeConfigTemplate string `yaml:"ConfigTemplate for edge node"`
NetworkName string `yaml:"Network name"` NetworkName string `yaml:"Network name"`
NetworkIFNameID bool `yaml:"Add NodeID to the interface name"`
EdgeNode struct { EdgeNode struct {
MacPrefix string `yaml:"MacAddress prefix"` MacPrefix string `yaml:"MacAddress prefix"`
IPv4Range string `yaml:"IPv4 range"` IPv4Range string `yaml:"IPv4 range"`
@ -45,12 +54,53 @@ type NMCfg struct {
} }
type edge_raw_info struct { type edge_raw_info struct {
Endpoint string `yaml:"Endpoint(optional)"` Endpoint string `yaml:"Endpoint(optional)"`
} }
type edge_info struct { type edge_info struct {
Endpoint string Endpoint string
ConnectedEdge map[mtypes.Vertex]bool ConnectedEdge map[mtypes.Vertex]bool
PrivKey string PrivKey string
PubKey string PubKey string
}
type bulkFileWriter struct {
files map[string]fileWriterfile
committed bool
ow bool
}
type fileWriterfile struct {
content []byte
perm fs.FileMode
}
func (f *bulkFileWriter) WriteFile(path string, content []byte, perm fs.FileMode) {
f.files[path] = fileWriterfile{
content: content,
perm: perm,
}
}
func (f *bulkFileWriter) Commit() error {
if f.committed {
return fmt.Errorf("fileWriter has been commited")
}
f.committed = true
for path, file := range f.files {
if !f.ow {
if _, err := os.Stat(path); os.IsNotExist(err) {
// path/to/whatever does not exist
} else {
return fmt.Errorf("file %v exists, overwrite disabled", path)
}
}
if err := ioutil.WriteFile(path, file.content, file.perm); err != nil {
return err
} else {
fmt.Println(path)
}
}
return nil
} }

View File

@ -98,11 +98,18 @@ func (g *IG) SyncTimeMultiple(count int) {
for _, result := range results { for _, result := range results {
totaltime += result totaltime += result
} }
avgtime := totaltime / time.Duration(len(results)) if len(results) > 0 {
if g.loglevel.LogNTP { avgtime := totaltime / time.Duration(len(results))
fmt.Println("NTP: Arvage offset: " + avgtime.String()) if g.loglevel.LogNTP {
fmt.Println("NTP: Arvage offset: " + avgtime.String())
}
g.ntp_offset = avgtime
} else {
if g.loglevel.LogNTP {
fmt.Println("NTP: All server failed, skip sync")
}
} }
g.ntp_offset = avgtime
} }
func (g *IG) SyncTime(url string, timeout time.Duration) { func (g *IG) SyncTime(url string, timeout time.Duration) {

View File

@ -1,3 +1,3 @@
package main package main
var Version = "v0.3.5" var Version = "v0.3.5-f1"