mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-22 09:30:28 +00:00
gofmt
This commit is contained in:
parent
19014a198e
commit
254be42614
@ -9,13 +9,13 @@ the command line arguments, and then spits out an updated file.
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"golang.org/x/text/encoding/unicode"
|
|
||||||
"github.com/neilalexander/hjson-go"
|
"github.com/neilalexander/hjson-go"
|
||||||
|
"golang.org/x/text/encoding/unicode"
|
||||||
|
|
||||||
"yggdrasil/config"
|
"yggdrasil/config"
|
||||||
)
|
)
|
||||||
@ -23,8 +23,8 @@ import (
|
|||||||
type nodeConfig = config.NodeConfig
|
type nodeConfig = config.NodeConfig
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
useconffile := flag.String("useconffile", "/etc/yggdrasil.conf", "update config at specified file path")
|
useconffile := flag.String("useconffile", "/etc/yggdrasil.conf", "update config at specified file path")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
cfg := nodeConfig{}
|
cfg := nodeConfig{}
|
||||||
var config []byte
|
var config []byte
|
||||||
var err error
|
var err error
|
||||||
@ -50,44 +50,44 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
json.Unmarshal(confJson, &cfg)
|
json.Unmarshal(confJson, &cfg)
|
||||||
switch flag.Arg(0) {
|
switch flag.Arg(0) {
|
||||||
case "setMTU":
|
case "setMTU":
|
||||||
cfg.IfMTU, err = strconv.Atoi(flag.Arg(1))
|
cfg.IfMTU, err = strconv.Atoi(flag.Arg(1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cfg.IfMTU = 1280
|
cfg.IfMTU = 1280
|
||||||
}
|
}
|
||||||
if mtu, _ := strconv.Atoi(flag.Arg(1)); mtu < 1280 {
|
if mtu, _ := strconv.Atoi(flag.Arg(1)); mtu < 1280 {
|
||||||
cfg.IfMTU = 1280
|
cfg.IfMTU = 1280
|
||||||
}
|
}
|
||||||
case "setIfName":
|
case "setIfName":
|
||||||
cfg.IfName = flag.Arg(1)
|
cfg.IfName = flag.Arg(1)
|
||||||
case "setListen":
|
case "setListen":
|
||||||
cfg.Listen = flag.Arg(1)
|
cfg.Listen = flag.Arg(1)
|
||||||
case "setAdminListen":
|
case "setAdminListen":
|
||||||
cfg.AdminListen = flag.Arg(1)
|
cfg.AdminListen = flag.Arg(1)
|
||||||
case "setIfTapMode":
|
case "setIfTapMode":
|
||||||
if flag.Arg(1) == "true" {
|
if flag.Arg(1) == "true" {
|
||||||
cfg.IfTAPMode = true
|
cfg.IfTAPMode = true
|
||||||
} else {
|
} else {
|
||||||
cfg.IfTAPMode = false
|
cfg.IfTAPMode = false
|
||||||
}
|
}
|
||||||
case "addPeer":
|
case "addPeer":
|
||||||
found := false
|
found := false
|
||||||
for _, v := range cfg.Peers {
|
for _, v := range cfg.Peers {
|
||||||
if v == flag.Arg(1) {
|
if v == flag.Arg(1) {
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
cfg.Peers = append(cfg.Peers, flag.Arg(1))
|
cfg.Peers = append(cfg.Peers, flag.Arg(1))
|
||||||
}
|
}
|
||||||
case "removePeer":
|
case "removePeer":
|
||||||
for k, v := range cfg.Peers {
|
for k, v := range cfg.Peers {
|
||||||
if v == flag.Arg(1) {
|
if v == flag.Arg(1) {
|
||||||
cfg.Peers = append(cfg.Peers[:k], cfg.Peers[k+1:]...)
|
cfg.Peers = append(cfg.Peers[:k], cfg.Peers[k+1:]...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bs, err := hjson.Marshal(cfg)
|
bs, err := hjson.Marshal(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -17,7 +17,7 @@ package yggdrasil
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@ -113,7 +113,7 @@ func (iface *tcpInterface) call(saddr string, socksaddr *string) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
// Block new calls for a little while, to mitigate livelock scenarios
|
// Block new calls for a little while, to mitigate livelock scenarios
|
||||||
time.Sleep(tcp_timeout)
|
time.Sleep(tcp_timeout)
|
||||||
time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)
|
time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)
|
||||||
iface.mutex.Lock()
|
iface.mutex.Lock()
|
||||||
delete(iface.calls, saddr)
|
delete(iface.calls, saddr)
|
||||||
iface.mutex.Unlock()
|
iface.mutex.Unlock()
|
||||||
|
Loading…
Reference in New Issue
Block a user