mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-25 20:41:36 +00:00
Merge pull request #53 from neilalexander/genconf
Generate a random port number in -genconf instead of :0
This commit is contained in:
commit
e04ab7cfe6
14
yggdrasil.go
14
yggdrasil.go
@ -12,6 +12,7 @@ import "os/signal"
|
|||||||
import "syscall"
|
import "syscall"
|
||||||
import "time"
|
import "time"
|
||||||
import "regexp"
|
import "regexp"
|
||||||
|
import "math/rand"
|
||||||
|
|
||||||
import _ "net/http/pprof"
|
import _ "net/http/pprof"
|
||||||
import "net/http"
|
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{}
|
core := Core{}
|
||||||
bpub, bpriv := core.DEBUG_newBoxKeys()
|
bpub, bpriv := core.DEBUG_newBoxKeys()
|
||||||
spub, spriv := core.DEBUG_newSigKeys()
|
spub, spriv := core.DEBUG_newSigKeys()
|
||||||
cfg := nodeConfig{}
|
cfg := nodeConfig{}
|
||||||
|
if isAutoconf {
|
||||||
cfg.Listen = "[::]:0"
|
cfg.Listen = "[::]:0"
|
||||||
|
} else {
|
||||||
|
r1 := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
|
cfg.Listen = fmt.Sprintf("[::]:%d", r1.Intn(65534 - 32768) + 32768)
|
||||||
|
}
|
||||||
cfg.AdminListen = "[::1]:9001"
|
cfg.AdminListen = "[::1]:9001"
|
||||||
cfg.BoxPub = hex.EncodeToString(bpub[:])
|
cfg.BoxPub = hex.EncodeToString(bpub[:])
|
||||||
cfg.BoxPriv = hex.EncodeToString(bpriv[:])
|
cfg.BoxPriv = hex.EncodeToString(bpriv[:])
|
||||||
@ -124,7 +130,7 @@ func generateConfig() *nodeConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func doGenconf() string {
|
func doGenconf() string {
|
||||||
cfg := generateConfig()
|
cfg := generateConfig(false)
|
||||||
bs, err := json.MarshalIndent(cfg, "", " ")
|
bs, err := json.MarshalIndent(cfg, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -235,7 +241,7 @@ func main() {
|
|||||||
var cfg *nodeConfig
|
var cfg *nodeConfig
|
||||||
switch {
|
switch {
|
||||||
case *autoconf:
|
case *autoconf:
|
||||||
cfg = generateConfig()
|
cfg = generateConfig(true)
|
||||||
case *useconffile != "" || *useconf:
|
case *useconffile != "" || *useconf:
|
||||||
var config []byte
|
var config []byte
|
||||||
var err error
|
var err error
|
||||||
@ -248,7 +254,7 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
decoder := json.NewDecoder(bytes.NewReader(config))
|
decoder := json.NewDecoder(bytes.NewReader(config))
|
||||||
cfg = generateConfig()
|
cfg = generateConfig(false)
|
||||||
err = decoder.Decode(cfg)
|
err = decoder.Decode(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user