mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-30 07:05:06 +03:00
Tweaks
This commit is contained in:
parent
6f824e8405
commit
9286bed140
3 changed files with 17 additions and 111 deletions
|
@ -1,7 +1,6 @@
|
||||||
---
|
|
||||||
run:
|
run:
|
||||||
build-tags:
|
build-tags:
|
||||||
- debug
|
- lint
|
||||||
issues-exit-code: 0 # TODO: change this to 1 when we want it to fail builds
|
issues-exit-code: 0 # TODO: change this to 1 when we want it to fail builds
|
||||||
skip-dirs:
|
skip-dirs:
|
||||||
- contrib/
|
- contrib/
|
||||||
|
|
|
@ -1,97 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
/*
|
|
||||||
This is a small utility that is designed to accompany the vyatta-yggdrasil
|
|
||||||
package. It takes a HJSON configuration file, makes changes to it based on
|
|
||||||
the command line arguments, and then spits out an updated file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/hjson/hjson-go"
|
|
||||||
"golang.org/x/text/encoding/unicode"
|
|
||||||
|
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
type nodeConfig = config.NodeConfig
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
useconffile := flag.String("useconffile", "/etc/yggdrasil.conf", "update config at specified file path")
|
|
||||||
flag.Parse()
|
|
||||||
cfg := nodeConfig{}
|
|
||||||
var config []byte
|
|
||||||
var err error
|
|
||||||
config, err = ioutil.ReadFile(*useconffile)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if bytes.Compare(config[0:2], []byte{0xFF, 0xFE}) == 0 ||
|
|
||||||
bytes.Compare(config[0:2], []byte{0xFE, 0xFF}) == 0 {
|
|
||||||
utf := unicode.UTF16(unicode.BigEndian, unicode.UseBOM)
|
|
||||||
decoder := utf.NewDecoder()
|
|
||||||
config, err = decoder.Bytes(config)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var dat map[string]interface{}
|
|
||||||
if err := hjson.Unmarshal(config, &dat); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
confJson, err := json.Marshal(dat)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
json.Unmarshal(confJson, &cfg)
|
|
||||||
switch flag.Arg(0) {
|
|
||||||
case "setMTU":
|
|
||||||
cfg.IfMTU, err = strconv.Atoi(flag.Arg(1))
|
|
||||||
if err != nil {
|
|
||||||
cfg.IfMTU = 1280
|
|
||||||
}
|
|
||||||
if mtu, _ := strconv.Atoi(flag.Arg(1)); mtu < 1280 {
|
|
||||||
cfg.IfMTU = 1280
|
|
||||||
}
|
|
||||||
case "setIfName":
|
|
||||||
cfg.IfName = flag.Arg(1)
|
|
||||||
case "setListen":
|
|
||||||
cfg.Listen = flag.Arg(1)
|
|
||||||
case "setAdminListen":
|
|
||||||
cfg.AdminListen = flag.Arg(1)
|
|
||||||
case "setIfTapMode":
|
|
||||||
if flag.Arg(1) == "true" {
|
|
||||||
cfg.IfTAPMode = true
|
|
||||||
} else {
|
|
||||||
cfg.IfTAPMode = false
|
|
||||||
}
|
|
||||||
case "addPeer":
|
|
||||||
found := false
|
|
||||||
for _, v := range cfg.Peers {
|
|
||||||
if v == flag.Arg(1) {
|
|
||||||
found = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
cfg.Peers = append(cfg.Peers, flag.Arg(1))
|
|
||||||
}
|
|
||||||
case "removePeer":
|
|
||||||
for k, v := range cfg.Peers {
|
|
||||||
if v == flag.Arg(1) {
|
|
||||||
cfg.Peers = append(cfg.Peers[:k], cfg.Peers[k+1:]...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bs, err := hjson.Marshal(cfg)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
fmt.Println(string(bs))
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,20 +1,24 @@
|
||||||
|
// +build !lint
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
import "bufio"
|
"bufio"
|
||||||
import "os"
|
"flag"
|
||||||
import "strings"
|
"fmt"
|
||||||
import "strconv"
|
"os"
|
||||||
import "time"
|
"runtime"
|
||||||
|
"runtime/pprof"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
import "runtime"
|
"github.com/gologme/log"
|
||||||
import "runtime/pprof"
|
|
||||||
import "flag"
|
|
||||||
|
|
||||||
import "github.com/gologme/log"
|
. "github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil"
|
||||||
|
|
||||||
import . "github.com/yggdrasil-network/yggdrasil-go/src/yggdrasil"
|
. "github.com/yggdrasil-network/yggdrasil-go/src/crypto"
|
||||||
import . "github.com/yggdrasil-network/yggdrasil-go/src/crypto"
|
)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue