mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	Merge pull request #76 from neilalexander/hjson
Use HJSON for config instead of JSON
This commit is contained in:
		
						commit
						96c55da987
					
				
					 2 changed files with 24 additions and 22 deletions
				
			
		| 
						 | 
					@ -2,24 +2,24 @@ package config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NodeConfig defines all configuration values needed to run a signle yggdrasil node
 | 
					// NodeConfig defines all configuration values needed to run a signle yggdrasil node
 | 
				
			||||||
type NodeConfig struct {
 | 
					type NodeConfig struct {
 | 
				
			||||||
	Listen         string
 | 
						Listen         string    `comment:"Listen address for peer connections (default is to listen for all\nconnections over IPv4 and IPv6)"`
 | 
				
			||||||
	AdminListen    string
 | 
						AdminListen    string    `comment:"Listen address for admin connections (default is to listen only\nfor local connections)"`
 | 
				
			||||||
	Peers          []string
 | 
						Peers          []string  `comment:"List of connection strings for static peers (i.e. tcp://a.b.c.d:e)"`
 | 
				
			||||||
	AllowedBoxPubs []string
 | 
						AllowedBoxPubs []string  `comment:"List of peer BoxPubs to allow UDP incoming TCP connections from\n(if left empty/undefined then connections will be allowed by default)"`
 | 
				
			||||||
	BoxPub         string
 | 
						BoxPub         string    `comment:"Your public encryption key (your peers may ask you for this to put\ninto their AllowedBoxPubs configuration)"`
 | 
				
			||||||
	BoxPriv        string
 | 
						BoxPriv        string    `comment:"Your private encryption key (do not share this with anyone!)"`
 | 
				
			||||||
	SigPub         string
 | 
						SigPub         string    `comment:"Your public signing key"`
 | 
				
			||||||
	SigPriv        string
 | 
						SigPriv        string    `comment:"Your private signing key (do not share this with anyone!)"`
 | 
				
			||||||
	Multicast      bool
 | 
						Multicast      bool      `comment:"Enable or disable automatic peer discovery on the same LAN using multicast"`
 | 
				
			||||||
	LinkLocal      string
 | 
						LinkLocal      string    `comment:"Regex for which interfaces multicast peer discovery should be enabled on"`
 | 
				
			||||||
	IfName         string
 | 
						IfName         string    `comment:"Local network interface name for TUN/TAP adapter, or \"auto\", or \"none\""`
 | 
				
			||||||
	IfTAPMode      bool
 | 
						IfTAPMode      bool      `comment:"Set local network interface to TAP mode rather than TUN mode (if supported\nby your platform, option will be ignored if not)"`
 | 
				
			||||||
	IfMTU          int
 | 
						IfMTU          int       `comment:"Maximux Transmission Unit (MTU) size for your local network interface"`
 | 
				
			||||||
	Net            NetConfig
 | 
						Net            NetConfig `comment:"Extended options for interoperability with other networks"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NetConfig defines network/proxy related configuration values
 | 
					// NetConfig defines network/proxy related configuration values
 | 
				
			||||||
type NetConfig struct {
 | 
					type NetConfig struct {
 | 
				
			||||||
	Tor TorConfig
 | 
						Tor TorConfig `comment:"Experimental options for configuring peerings over Tor"`
 | 
				
			||||||
	I2P I2PConfig
 | 
						I2P I2PConfig `comment:"Experimental options for configuring peerings over I2P"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										14
									
								
								yggdrasil.go
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								yggdrasil.go
									
										
									
									
									
								
							| 
						 | 
					@ -1,8 +1,6 @@
 | 
				
			||||||
package main
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import "bytes"
 | 
					 | 
				
			||||||
import "encoding/hex"
 | 
					import "encoding/hex"
 | 
				
			||||||
import "encoding/json"
 | 
					 | 
				
			||||||
import "flag"
 | 
					import "flag"
 | 
				
			||||||
import "fmt"
 | 
					import "fmt"
 | 
				
			||||||
import "io/ioutil"
 | 
					import "io/ioutil"
 | 
				
			||||||
| 
						 | 
					@ -25,6 +23,8 @@ import "yggdrasil"
 | 
				
			||||||
import "yggdrasil/config"
 | 
					import "yggdrasil/config"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import "github.com/kardianos/minwinsvc"
 | 
					import "github.com/kardianos/minwinsvc"
 | 
				
			||||||
 | 
					import "github.com/neilalexander/hjson-go"
 | 
				
			||||||
 | 
					import "github.com/mitchellh/mapstructure"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type nodeConfig = config.NodeConfig
 | 
					type nodeConfig = config.NodeConfig
 | 
				
			||||||
type Core = yggdrasil.Core
 | 
					type Core = yggdrasil.Core
 | 
				
			||||||
| 
						 | 
					@ -113,7 +113,7 @@ func generateConfig(isAutoconf bool) *nodeConfig {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func doGenconf() string {
 | 
					func doGenconf() string {
 | 
				
			||||||
	cfg := generateConfig(false)
 | 
						cfg := generateConfig(false)
 | 
				
			||||||
	bs, err := json.MarshalIndent(cfg, "", "  ")
 | 
						bs, err := hjson.Marshal(cfg)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		panic(err)
 | 
							panic(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -235,10 +235,12 @@ func main() {
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			panic(err)
 | 
								panic(err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		decoder := json.NewDecoder(bytes.NewReader(config))
 | 
					 | 
				
			||||||
		cfg = generateConfig(false)
 | 
							cfg = generateConfig(false)
 | 
				
			||||||
		err = decoder.Decode(cfg)
 | 
							var dat map[string]interface{}
 | 
				
			||||||
		if err != nil {
 | 
							if err := hjson.Unmarshal(config, &dat); err != nil {
 | 
				
			||||||
 | 
								panic(err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if err = mapstructure.Decode(dat, &cfg); err != nil {
 | 
				
			||||||
			panic(err)
 | 
								panic(err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	case *genconf:
 | 
						case *genconf:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue