5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 09:30:28 +00:00

Merge pull request #94 from Arceliar/main-fixes

hjson bugfixes
This commit is contained in:
Neil Alexander 2018-05-27 19:06:16 +01:00 committed by GitHub
commit 5131d854e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 12 deletions

View File

@ -284,9 +284,10 @@ func (c *Core) DEBUG_init(bpub []byte,
////////////////////////////////////////////////////////////////////////////////
func (c *Core) DEBUG_setupAndStartGlobalUDPInterface(addrport string) {
iface := udpInterface{}
iface.init(c, addrport)
c.udp = &iface
if err := c.udp.init(c, addrport); err != nil {
c.log.Println("Failed to start UDP interface:", err)
panic(err)
}
}
func (c *Core) DEBUG_getGlobalUDPAddr() *net.UDPAddr {
@ -337,9 +338,10 @@ func (c *Core) DEBUG_addSOCKSConn(socksaddr, peeraddr string) {
//*
func (c *Core) DEBUG_setupAndStartGlobalTCPInterface(addrport string) {
iface := tcpInterface{}
iface.init(c, addrport)
c.tcp = &iface
if err := c.tcp.init(c, addrport); err != nil {
c.log.Println("Failed to start TCP interface:", err)
panic(err)
}
}
func (c *Core) DEBUG_getGlobalTCPAddr() *net.TCPAddr {

View File

@ -65,18 +65,19 @@ type udpKeys struct {
sig sigPubKey
}
func (iface *udpInterface) init(core *Core, addr string) {
func (iface *udpInterface) init(core *Core, addr string) (err error) {
iface.core = core
udpAddr, err := net.ResolveUDPAddr("udp", addr)
if err != nil {
panic(err)
return
}
iface.sock, err = net.ListenUDP("udp", udpAddr)
if err != nil {
panic(err)
return
}
iface.conns = make(map[connAddr]*connInfo)
go iface.reader()
return
}
func (iface *udpInterface) sendKeys(addr connAddr) {

View File

@ -1,5 +1,6 @@
package main
import "encoding/json"
import "encoding/hex"
import "flag"
import "fmt"
@ -91,11 +92,9 @@ func generateConfig(isAutoconf bool) *nodeConfig {
cfg := nodeConfig{}
if isAutoconf {
cfg.Listen = "[::]:0"
cfg.MulticastInterfaces = []string{".*"}
} else {
r1 := rand.New(rand.NewSource(time.Now().UnixNano()))
cfg.Listen = fmt.Sprintf("[::]:%d", r1.Intn(65534-32768)+32768)
cfg.MulticastInterfaces = []string{}
}
cfg.AdminListen = "[::1]:9001"
cfg.EncryptionPublicKey = hex.EncodeToString(bpub[:])
@ -104,6 +103,7 @@ func generateConfig(isAutoconf bool) *nodeConfig {
cfg.SigningPrivateKey = hex.EncodeToString(spriv[:])
cfg.Peers = []string{}
cfg.AllowedEncryptionPublicKeys = []string{}
cfg.MulticastInterfaces = []string{".*"}
cfg.IfName = core.DEBUG_GetTUNDefaultIfName()
cfg.IfMTU = core.DEBUG_GetTUNDefaultIfMTU()
cfg.IfTAPMode = core.DEBUG_GetTUNDefaultIfTAPMode()
@ -113,7 +113,6 @@ func generateConfig(isAutoconf bool) *nodeConfig {
func doGenconf() string {
cfg := generateConfig(false)
cfg.MulticastInterfaces = append(cfg.MulticastInterfaces, ".*")
bs, err := hjson.Marshal(cfg)
if err != nil {
panic(err)
@ -150,6 +149,11 @@ func main() {
if err := hjson.Unmarshal(config, &dat); err != nil {
panic(err)
}
confJson, err := json.Marshal(dat)
if err != nil {
panic(err)
}
json.Unmarshal(confJson, &cfg)
// For now we will do a little bit to help the user adjust their
// configuration to match the new configuration format
changes := map[string]string{