mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	Add -normaliseconf option and temporarily correct old config item names in running config
This commit is contained in:
		
							parent
							
								
									9d9083e373
								
							
						
					
					
						commit
						ce854a76bd
					
				
					 3 changed files with 37 additions and 2 deletions
				
			
		| 
						 | 
					@ -391,7 +391,7 @@ func (c *Core) DEBUG_setupAndStartMulticastInterface() {
 | 
				
			||||||
	m := multicast{}
 | 
						m := multicast{}
 | 
				
			||||||
	m.init(c)
 | 
						m.init(c)
 | 
				
			||||||
	c.multicast = m
 | 
						c.multicast = m
 | 
				
			||||||
	m.Start()
 | 
						m.start()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
////////////////////////////////////////////////////////////////////////////////
 | 
					////////////////////////////////////////////////////////////////////////////////
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,7 +44,7 @@ func (m *multicast) init(core *Core) {
 | 
				
			||||||
	m.core.log.Println("Found", len(m.interfaces), "multicast interface(s)")
 | 
						m.core.log.Println("Found", len(m.interfaces), "multicast interface(s)")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *multicast) Start() {
 | 
					func (m *multicast) start() {
 | 
				
			||||||
	if len(m.core.ifceExpr) == 0 {
 | 
						if len(m.core.ifceExpr) == 0 {
 | 
				
			||||||
		m.core.log.Println("Multicast discovery is disabled")
 | 
							m.core.log.Println("Multicast discovery is disabled")
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										35
									
								
								yggdrasil.go
									
										
									
									
									
								
							
							
						
						
									
										35
									
								
								yggdrasil.go
									
										
									
									
									
								
							| 
						 | 
					@ -123,6 +123,7 @@ var pprof = flag.Bool("pprof", false, "Run pprof, see http://localhost:6060/debu
 | 
				
			||||||
var genconf = flag.Bool("genconf", false, "print a new config to stdout")
 | 
					var genconf = flag.Bool("genconf", false, "print a new config to stdout")
 | 
				
			||||||
var useconf = flag.Bool("useconf", false, "read config from stdin")
 | 
					var useconf = flag.Bool("useconf", false, "read config from stdin")
 | 
				
			||||||
var useconffile = flag.String("useconffile", "", "read config from specified file path")
 | 
					var useconffile = flag.String("useconffile", "", "read config from specified file path")
 | 
				
			||||||
 | 
					var normaliseconf = flag.Bool("normaliseconf", false, "use in combination with either -useconf or -useconffile, outputs your configuration normalised")
 | 
				
			||||||
var autoconf = flag.Bool("autoconf", false, "automatic mode (dynamic IP, peer with IPv6 neighbors)")
 | 
					var autoconf = flag.Bool("autoconf", false, "automatic mode (dynamic IP, peer with IPv6 neighbors)")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
| 
						 | 
					@ -147,9 +148,43 @@ func main() {
 | 
				
			||||||
		if err := hjson.Unmarshal(config, &dat); err != nil {
 | 
							if err := hjson.Unmarshal(config, &dat); err != nil {
 | 
				
			||||||
			panic(err)
 | 
								panic(err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							// For now we will do a little bit to help the user adjust their
 | 
				
			||||||
 | 
							// configuration to match the new configuration format
 | 
				
			||||||
 | 
							changes := map[string]string{
 | 
				
			||||||
 | 
								"Multicast": "",
 | 
				
			||||||
 | 
								"LinkLocal": "MulticastInterfaces",
 | 
				
			||||||
 | 
								"BoxPub": "EncryptionPublicKey",
 | 
				
			||||||
 | 
								"BoxPriv": "EncryptionPrivateKey",
 | 
				
			||||||
 | 
								"SigPub": "SigningPublicKey",
 | 
				
			||||||
 | 
								"SigPriv": "SigningPrivateKey",
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							for from, to := range changes {
 | 
				
			||||||
 | 
								if val, ok := dat[from]; ok {
 | 
				
			||||||
 | 
									if val == "" {
 | 
				
			||||||
 | 
										if !*normaliseconf {
 | 
				
			||||||
 | 
											log.Println("Warning: Deprecated config option", from, " - please remove")
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										if !*normaliseconf {
 | 
				
			||||||
 | 
											log.Println("Warning: Deprecated config option", from, " - please rename to", to)
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										if _, ok := dat[to]; !ok {
 | 
				
			||||||
 | 
											dat[to] = dat[from]
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		if err = mapstructure.Decode(dat, &cfg); err != nil {
 | 
							if err = mapstructure.Decode(dat, &cfg); err != nil {
 | 
				
			||||||
			panic(err)
 | 
								panic(err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							if *normaliseconf {
 | 
				
			||||||
 | 
								bs, err := hjson.Marshal(cfg)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									panic(err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								fmt.Println(string(bs))
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	case *genconf:
 | 
						case *genconf:
 | 
				
			||||||
		fmt.Println(doGenconf())
 | 
							fmt.Println(doGenconf())
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue