mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-22 10:40:27 +00:00
move GenerateConfig to defaults, to adjust dependency ordering, needed for stuff later
This commit is contained in:
parent
2db46c1250
commit
2a7a53b6b6
@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/yggdrasil-network/yggdrasil-go/src/address"
|
"github.com/yggdrasil-network/yggdrasil-go/src/address"
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/admin"
|
"github.com/yggdrasil-network/yggdrasil-go/src/admin"
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/config"
|
"github.com/yggdrasil-network/yggdrasil-go/src/config"
|
||||||
|
"github.com/yggdrasil-network/yggdrasil-go/src/defaults"
|
||||||
|
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/core"
|
"github.com/yggdrasil-network/yggdrasil-go/src/core"
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/multicast"
|
"github.com/yggdrasil-network/yggdrasil-go/src/multicast"
|
||||||
@ -73,7 +74,7 @@ func readConfig(log *log.Logger, useconf *bool, useconffile *string, normaliseco
|
|||||||
// then parse the configuration we loaded above on top of it. The effect
|
// then parse the configuration we loaded above on top of it. The effect
|
||||||
// of this is that any configuration item that is missing from the provided
|
// of this is that any configuration item that is missing from the provided
|
||||||
// configuration will use a sane default.
|
// configuration will use a sane default.
|
||||||
cfg := config.GenerateConfig()
|
cfg := defaults.GenerateConfig()
|
||||||
var dat map[string]interface{}
|
var dat map[string]interface{}
|
||||||
if err := hjson.Unmarshal(conf, &dat); err != nil {
|
if err := hjson.Unmarshal(conf, &dat); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -114,7 +115,7 @@ func readConfig(log *log.Logger, useconf *bool, useconffile *string, normaliseco
|
|||||||
// Generates a new configuration and returns it in HJSON format. This is used
|
// Generates a new configuration and returns it in HJSON format. This is used
|
||||||
// with -genconf.
|
// with -genconf.
|
||||||
func doGenconf(isjson bool) string {
|
func doGenconf(isjson bool) string {
|
||||||
cfg := config.GenerateConfig()
|
cfg := defaults.GenerateConfig()
|
||||||
var bs []byte
|
var bs []byte
|
||||||
var err error
|
var err error
|
||||||
if isjson {
|
if isjson {
|
||||||
@ -205,7 +206,7 @@ func main() {
|
|||||||
case *autoconf:
|
case *autoconf:
|
||||||
// Use an autoconf-generated config, this will give us random keys and
|
// Use an autoconf-generated config, this will give us random keys and
|
||||||
// port numbers, and will use an automatically selected TUN/TAP interface.
|
// port numbers, and will use an automatically selected TUN/TAP interface.
|
||||||
cfg = config.GenerateConfig()
|
cfg = defaults.GenerateConfig()
|
||||||
case *useconffile != "" || *useconf:
|
case *useconffile != "" || *useconf:
|
||||||
// Read the configuration from either stdin or from the filesystem
|
// Read the configuration from either stdin or from the filesystem
|
||||||
cfg = readConfig(logger, useconf, useconffile, normaliseconf)
|
cfg = readConfig(logger, useconf, useconffile, normaliseconf)
|
||||||
|
@ -20,8 +20,6 @@ import (
|
|||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/defaults"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NodeConfig is the main configuration structure, containing configuration
|
// NodeConfig is the main configuration structure, containing configuration
|
||||||
@ -44,32 +42,6 @@ type NodeConfig struct {
|
|||||||
NodeInfo map[string]interface{} `comment:"Optional node info. This must be a { \"key\": \"value\", ... } map\nor set as null. This is entirely optional but, if set, is visible\nto the whole network on request."`
|
NodeInfo map[string]interface{} `comment:"Optional node info. This must be a { \"key\": \"value\", ... } map\nor set as null. This is entirely optional but, if set, is visible\nto the whole network on request."`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generates default configuration and returns a pointer to the resulting
|
|
||||||
// NodeConfig. This is used when outputting the -genconf parameter and also when
|
|
||||||
// using -autoconf.
|
|
||||||
func GenerateConfig() *NodeConfig {
|
|
||||||
// Generate encryption keys.
|
|
||||||
spub, spriv, err := ed25519.GenerateKey(nil)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
// Create a node configuration and populate it.
|
|
||||||
cfg := NodeConfig{}
|
|
||||||
cfg.Listen = []string{}
|
|
||||||
cfg.AdminListen = defaults.GetDefaults().DefaultAdminListen
|
|
||||||
cfg.PublicKey = hex.EncodeToString(spub[:])
|
|
||||||
cfg.PrivateKey = hex.EncodeToString(spriv[:])
|
|
||||||
cfg.Peers = []string{}
|
|
||||||
cfg.InterfacePeers = map[string][]string{}
|
|
||||||
cfg.AllowedPublicKeys = []string{}
|
|
||||||
cfg.MulticastInterfaces = defaults.GetDefaults().DefaultMulticastInterfaces
|
|
||||||
cfg.IfName = defaults.GetDefaults().DefaultIfName
|
|
||||||
cfg.IfMTU = defaults.GetDefaults().DefaultIfMTU
|
|
||||||
cfg.NodeInfoPrivacy = false
|
|
||||||
|
|
||||||
return &cfg
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewSigningKeys replaces the signing keypair in the NodeConfig with a new
|
// NewSigningKeys replaces the signing keypair in the NodeConfig with a new
|
||||||
// signing keypair. The signing keys are used by the switch to derive the
|
// signing keypair. The signing keys are used by the switch to derive the
|
||||||
// structure of the spanning tree.
|
// structure of the spanning tree.
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package defaults
|
package defaults
|
||||||
|
|
||||||
|
import "github.com/yggdrasil-network/yggdrasil-go/src/config"
|
||||||
|
|
||||||
// Defines which parameters are expected by default for configuration on a
|
// Defines which parameters are expected by default for configuration on a
|
||||||
// specific platform. These values are populated in the relevant defaults_*.go
|
// specific platform. These values are populated in the relevant defaults_*.go
|
||||||
// for the platform being targeted. They must be set.
|
// for the platform being targeted. They must be set.
|
||||||
@ -18,3 +20,23 @@ type platformDefaultParameters struct {
|
|||||||
DefaultIfMTU uint64
|
DefaultIfMTU uint64
|
||||||
DefaultIfName string
|
DefaultIfName string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generates default configuration and returns a pointer to the resulting
|
||||||
|
// NodeConfig. This is used when outputting the -genconf parameter and also when
|
||||||
|
// using -autoconf.
|
||||||
|
func GenerateConfig() *config.NodeConfig {
|
||||||
|
// Create a node configuration and populate it.
|
||||||
|
cfg := new(config.NodeConfig)
|
||||||
|
cfg.NewKeys()
|
||||||
|
cfg.Listen = []string{}
|
||||||
|
cfg.AdminListen = GetDefaults().DefaultAdminListen
|
||||||
|
cfg.Peers = []string{}
|
||||||
|
cfg.InterfacePeers = map[string][]string{}
|
||||||
|
cfg.AllowedPublicKeys = []string{}
|
||||||
|
cfg.MulticastInterfaces = GetDefaults().DefaultMulticastInterfaces
|
||||||
|
cfg.IfName = GetDefaults().DefaultIfName
|
||||||
|
cfg.IfMTU = GetDefaults().DefaultIfMTU
|
||||||
|
cfg.NodeInfoPrivacy = false
|
||||||
|
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user