From 95a6cfff10be1e859314614246679380ecb14473 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 7 Mar 2018 19:41:56 +0000 Subject: [PATCH 1/2] Generate a random port number in -genconf instead of :0 (#51) --- yggdrasil.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/yggdrasil.go b/yggdrasil.go index 68f2396..16d44ac 100644 --- a/yggdrasil.go +++ b/yggdrasil.go @@ -12,6 +12,7 @@ import "os/signal" import "syscall" import "time" import "regexp" +import "math/rand" import _ "net/http/pprof" import "net/http" @@ -103,12 +104,17 @@ func (n *node) init(cfg *nodeConfig, logger *log.Logger) { }() } -func generateConfig() *nodeConfig { +func generateConfig(isAutoconf bool) *nodeConfig { core := Core{} bpub, bpriv := core.DEBUG_newBoxKeys() spub, spriv := core.DEBUG_newSigKeys() cfg := nodeConfig{} - cfg.Listen = "[::]:0" + if isAutoconf { + cfg.Listen = "[::]:0" + } else { + r1 := rand.New(rand.NewSource(time.Now().UnixNano())) + cfg.Listen = fmt.Sprintf("[::]:%d", r1.Intn(65534 - 1024) + 1024) + } cfg.AdminListen = "[::1]:9001" cfg.BoxPub = hex.EncodeToString(bpub[:]) cfg.BoxPriv = hex.EncodeToString(bpriv[:]) @@ -124,7 +130,7 @@ func generateConfig() *nodeConfig { } func doGenconf() string { - cfg := generateConfig() + cfg := generateConfig(false) bs, err := json.MarshalIndent(cfg, "", " ") if err != nil { panic(err) @@ -235,7 +241,7 @@ func main() { var cfg *nodeConfig switch { case *autoconf: - cfg = generateConfig() + cfg = generateConfig(true) case *useconffile != "" || *useconf: var config []byte var err error @@ -248,7 +254,7 @@ func main() { panic(err) } decoder := json.NewDecoder(bytes.NewReader(config)) - cfg = generateConfig() + cfg = generateConfig(false) err = decoder.Decode(cfg) if err != nil { panic(err) From 6388b9b99d8c7023da276aff1f4194548959cdd4 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 7 Mar 2018 22:36:16 +0000 Subject: [PATCH 2/2] Increase the randomly generated port in -genconf to values above 32768 --- yggdrasil.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yggdrasil.go b/yggdrasil.go index 16d44ac..3eedd49 100644 --- a/yggdrasil.go +++ b/yggdrasil.go @@ -113,7 +113,7 @@ func generateConfig(isAutoconf bool) *nodeConfig { cfg.Listen = "[::]:0" } else { r1 := rand.New(rand.NewSource(time.Now().UnixNano())) - cfg.Listen = fmt.Sprintf("[::]:%d", r1.Intn(65534 - 1024) + 1024) + cfg.Listen = fmt.Sprintf("[::]:%d", r1.Intn(65534 - 32768) + 32768) } cfg.AdminListen = "[::1]:9001" cfg.BoxPub = hex.EncodeToString(bpub[:])