5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 07:11:40 +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) { func (c *Core) DEBUG_setupAndStartGlobalUDPInterface(addrport string) {
iface := udpInterface{} if err := c.udp.init(c, addrport); err != nil {
iface.init(c, addrport) c.log.Println("Failed to start UDP interface:", err)
c.udp = &iface panic(err)
}
} }
func (c *Core) DEBUG_getGlobalUDPAddr() *net.UDPAddr { 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) { func (c *Core) DEBUG_setupAndStartGlobalTCPInterface(addrport string) {
iface := tcpInterface{} if err := c.tcp.init(c, addrport); err != nil {
iface.init(c, addrport) c.log.Println("Failed to start TCP interface:", err)
c.tcp = &iface panic(err)
}
} }
func (c *Core) DEBUG_getGlobalTCPAddr() *net.TCPAddr { func (c *Core) DEBUG_getGlobalTCPAddr() *net.TCPAddr {

View File

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

View File

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