mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
Merge branch 'develop' into go-webview-selector
This commit is contained in:
commit
7b340d1b42
19 changed files with 265 additions and 168 deletions
6
build
6
build
|
@ -4,6 +4,8 @@ set -ef
|
||||||
PKGSRC=${PKGSRC:-github.com/RiV-chain/RiV-mesh/src/version}
|
PKGSRC=${PKGSRC:-github.com/RiV-chain/RiV-mesh/src/version}
|
||||||
PKGNAME=${PKGNAME:-$(sh contrib/semver/name.sh)}
|
PKGNAME=${PKGNAME:-$(sh contrib/semver/name.sh)}
|
||||||
PKGVER=${PKGVER:-$(sh contrib/semver/version.sh --bare)}
|
PKGVER=${PKGVER:-$(sh contrib/semver/version.sh --bare)}
|
||||||
|
echo "Building: $PKGVER"
|
||||||
|
|
||||||
if [ "$LDFLAGS" ]; then
|
if [ "$LDFLAGS" ]; then
|
||||||
LDFLAGS="$LDFLAGS -X $PKGSRC.buildName=$PKGNAME -X $PKGSRC.buildVersion=$PKGVER"
|
LDFLAGS="$LDFLAGS -X $PKGSRC.buildName=$PKGNAME -X $PKGSRC.buildVersion=$PKGVER"
|
||||||
else
|
else
|
||||||
|
@ -58,10 +60,6 @@ build_meshctl() {
|
||||||
}
|
}
|
||||||
|
|
||||||
build_mesh_ui() {
|
build_mesh_ui() {
|
||||||
#only UI should be built with windowsgui flag
|
|
||||||
if [ "$GOOS" == "windows" ]; then
|
|
||||||
LDFLAGS2=" -H windowsgui"
|
|
||||||
fi
|
|
||||||
buildbin ./contrib/ui/mesh-ui
|
buildbin ./contrib/ui/mesh-ui
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,11 +47,16 @@ cp meshctl pkgbuild/root/usr/local/bin
|
||||||
cp mesh pkgbuild/root/Applications/RiV-mesh.app/Contents/MacOS
|
cp mesh pkgbuild/root/Applications/RiV-mesh.app/Contents/MacOS
|
||||||
cp mesh-ui pkgbuild/root/Applications/RiV-mesh.app/Contents/MacOS
|
cp mesh-ui pkgbuild/root/Applications/RiV-mesh.app/Contents/MacOS
|
||||||
cp riv.icns pkgbuild/root/Applications/RiV-mesh.app/Contents/Resources
|
cp riv.icns pkgbuild/root/Applications/RiV-mesh.app/Contents/Resources
|
||||||
cp contrib/ui/mesh-ui/ui/index.html pkgbuild/root/Applications/RiV-mesh.app/Contents/MacOS
|
cp -r contrib/ui/mesh-ui/ui pkgbuild/root/Applications/RiV-mesh.app/Contents/Resources
|
||||||
cp -r contrib/ui/mesh-ui/ui/assets pkgbuild/root/Applications/RiV-mesh.app/Contents/MacOS
|
|
||||||
cp -r contrib/ui/mesh-ui/ui/webfonts pkgbuild/root/Applications/RiV-mesh.app/Contents/MacOS
|
|
||||||
cp contrib/macos/mesh.plist pkgbuild/root/Library/LaunchDaemons
|
cp contrib/macos/mesh.plist pkgbuild/root/Library/LaunchDaemons
|
||||||
|
|
||||||
|
# Create open script
|
||||||
|
cat > pkgbuild/root/Applications/RiV-mesh.app/Contents/MacOS/open-mesh-ui << EOF
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
exec /Applications/RiV-mesh.app/Contents/MacOS/mesh-ui /Applications/RiV-mesh.app/Contents/Resources/ui/index.html 1>/tmp/mesh-ui.stdout.log 2>/tmp/mesh-ui.stderr.log
|
||||||
|
EOF
|
||||||
|
|
||||||
# Create the postinstall script
|
# Create the postinstall script
|
||||||
cat > pkgbuild/scripts/postinstall << EOF
|
cat > pkgbuild/scripts/postinstall << EOF
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
@ -82,7 +87,7 @@ chmod 755 pkgbuild/scripts/postinstall
|
||||||
chmod 755 pkgbuild/root/usr/local/bin/meshctl
|
chmod 755 pkgbuild/root/usr/local/bin/meshctl
|
||||||
chmod 755 pkgbuild/root/Applications/RiV-mesh.app/Contents/MacOS/mesh
|
chmod 755 pkgbuild/root/Applications/RiV-mesh.app/Contents/MacOS/mesh
|
||||||
chmod 755 pkgbuild/root/Applications/RiV-mesh.app/Contents/MacOS/mesh-ui
|
chmod 755 pkgbuild/root/Applications/RiV-mesh.app/Contents/MacOS/mesh-ui
|
||||||
chmod 755 pkgbuild/root/Applications/RiV-mesh.app/Contents/MacOS/index.html
|
chmod 755 pkgbuild/root/Applications/RiV-mesh.app/Contents/MacOS/open-mesh-ui
|
||||||
|
|
||||||
# Work out metadata for the package info
|
# Work out metadata for the package info
|
||||||
PKGNAME=$(sh contrib/semver/name.sh)
|
PKGNAME=$(sh contrib/semver/name.sh)
|
||||||
|
@ -115,13 +120,9 @@ cat > pkgbuild/root/Applications/RiV-mesh.app/Contents/Info.plist << EOF
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>${PKGVERSION}</string>
|
<string>${PKGVERSION}</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>mesh-ui</string>
|
<string>open-mesh-ui</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
<string>io.github.RiV-mesh.pkg</string>
|
<string>io.github.RiV-mesh.pkg</string>
|
||||||
<key>StandardOutPath</key>
|
|
||||||
<string>/tmp/mesh-ui.stdout.log</string>
|
|
||||||
<key>StandardErrorPath</key>
|
|
||||||
<string>/tmp/mesh-ui.stderr.log</string>
|
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
EOF
|
EOF
|
||||||
|
|
|
@ -47,13 +47,17 @@ func (m *Mesh) StartJSON(configjson []byte) error {
|
||||||
if err := json.Unmarshal(configjson, &m.config); err != nil {
|
if err := json.Unmarshal(configjson, &m.config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Setup the Yggdrasil node itself.
|
// Setup the Mesh node itself.
|
||||||
{
|
{
|
||||||
sk, err := hex.DecodeString(m.config.PrivateKey)
|
sk, err := hex.DecodeString(m.config.PrivateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
options := []core.SetupOption{}
|
options := []core.SetupOption{
|
||||||
|
core.NodeInfo(m.config.NodeInfo),
|
||||||
|
core.NodeInfoPrivacy(m.config.NodeInfoPrivacy),
|
||||||
|
core.NetworkDomain(m.config.NetworkDomain),
|
||||||
|
}
|
||||||
for _, peer := range m.config.Peers {
|
for _, peer := range m.config.Peers {
|
||||||
options = append(options, core.Peer{URI: peer})
|
options = append(options, core.Peer{URI: peer})
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
case "$*" in
|
case "$*" in
|
||||||
*--bare*)
|
*--bare*)
|
||||||
# Remove the "v" prefix
|
# Remove the "v" prefix
|
||||||
git describe --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" | cut -c 2-
|
git describe --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" --abbrev=7 | cut -c 2-
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
git describe --tags --match="v[0-9]*\.[0-9]*\.[0-9]*"
|
git describe --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" --abbrev=7
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -136,23 +136,23 @@
|
||||||
var message = document.getElementById("info_window");
|
var message = document.getElementById("info_window");
|
||||||
message.innerHTML = text;
|
message.innerHTML = text;
|
||||||
|
|
||||||
info.className = "notification is-primary";
|
info.classList.remove("is-hidden");
|
||||||
var button_info_close = document.getElementById("info_close");
|
var button_info_close = document.getElementById("info_close");
|
||||||
button_info_close.onclick = function () {
|
button_info_close.onclick = function () {
|
||||||
message.value = "";
|
message.value = "";
|
||||||
info.className = "notification is-primary is-hidden";
|
info.classList.add("is-hidden");
|
||||||
//document.getElementById("peer_list").remove();
|
//document.getElementById("peer_list").remove();
|
||||||
};
|
};
|
||||||
var button_window_close = document.getElementById("window_close");
|
var button_window_close = document.getElementById("window_close");
|
||||||
button_window_close.onclick = function () {
|
button_window_close.onclick = function () {
|
||||||
message.value = "";
|
message.value = "";
|
||||||
info.className = "notification is-primary is-hidden";
|
info.classList.add("is-hidden");
|
||||||
//document.getElementById("peer_list").remove();
|
//document.getElementById("peer_list").remove();
|
||||||
};
|
};
|
||||||
var button_window_save = document.getElementById("window_save");
|
var button_window_save = document.getElementById("window_save");
|
||||||
button_window_save.onclick = function () {
|
button_window_save.onclick = function () {
|
||||||
message.value = "";
|
message.value = "";
|
||||||
info.className = "notification is-primary is-hidden";
|
info.classList.add("is-hidden");
|
||||||
//todo save peers
|
//todo save peers
|
||||||
var peers = document.querySelectorAll('*[id^="peer-"]');
|
var peers = document.querySelectorAll('*[id^="peer-"]');
|
||||||
var peer_list = [];
|
var peer_list = [];
|
||||||
|
@ -327,9 +327,9 @@
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body onload="onLoad();">
|
<body onload="onLoad();">
|
||||||
<div class="container hero is-fullheight" style="padding:3px;">
|
<div class="container hero is-fullheight">
|
||||||
<div class="box is-hidden">
|
<div class="box is-hidden" id="notification_window">
|
||||||
<div style="z-index: 9;" class="box stack-top notification is-primary is-hidden" id="notification_window">
|
<div style="z-index: 9;" class="notification is-primary">
|
||||||
<button class="delete" id="info_close"></button>
|
<button class="delete" id="info_close"></button>
|
||||||
<p style="padding:3px; max-height: 250px; overflow-y: auto;" id="info_window"></p>
|
<p style="padding:3px; max-height: 250px; overflow-y: auto;" id="info_window"></p>
|
||||||
<div style="padding-left:100px; padding-top:15px;" class="field is-grouped">
|
<div style="padding-left:100px; padding-top:15px;" class="field is-grouped">
|
||||||
|
|
214
contrib/ui/mesh-ui/webview.go
Executable file → Normal file
214
contrib/ui/mesh-ui/webview.go
Executable file → Normal file
|
@ -1,7 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -9,20 +11,45 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hjson/hjson-go"
|
"github.com/hjson/hjson-go"
|
||||||
"github.com/jchv/go-webview-selector"
|
"github.com/webview/webview"
|
||||||
|
"golang.org/x/text/encoding/unicode"
|
||||||
|
|
||||||
"github.com/RiV-chain/RiV-mesh/src/admin"
|
"github.com/RiV-chain/RiV-mesh/src/admin"
|
||||||
|
"github.com/RiV-chain/RiV-mesh/src/defaults"
|
||||||
|
"github.com/docopt/docopt-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var usage = `Graphical interface for RiV mesh.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
mesh-ui [<index>] [-c]
|
||||||
|
mesh-ui -h | --help
|
||||||
|
mesh-ui -v | --version
|
||||||
|
|
||||||
|
Options:
|
||||||
|
<index> Index file name [default: index.html].
|
||||||
|
-c --console Show debug console window.
|
||||||
|
-h --help Show this screen.
|
||||||
|
-v --version Show version.`
|
||||||
|
|
||||||
|
var confui struct {
|
||||||
|
IndexHtml string `docopt:"<index>"`
|
||||||
|
Console bool `docopt:"-c,--console"`
|
||||||
|
}
|
||||||
|
|
||||||
var uiVersion = "0.0.1"
|
var uiVersion = "0.0.1"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
opts, _ := docopt.ParseArgs(usage, os.Args[1:], uiVersion)
|
||||||
|
opts.Bind(&confui)
|
||||||
|
if !confui.Console {
|
||||||
|
Console(false)
|
||||||
|
}
|
||||||
debug := true
|
debug := true
|
||||||
w := webview.New(debug)
|
w := webview.New(debug)
|
||||||
defer w.Destroy()
|
defer w.Destroy()
|
||||||
|
@ -42,7 +69,6 @@ func main() {
|
||||||
fmt.Printf("Unable to create folder: %v", err)
|
fmt.Printf("Unable to create folder: %v", err)
|
||||||
}
|
}
|
||||||
mesh_settings_path := filepath.Join(user_home, mesh_folder, mesh_conf)
|
mesh_settings_path := filepath.Join(user_home, mesh_folder, mesh_conf)
|
||||||
riv_ctrl_path = get_ctl_path()
|
|
||||||
if _, err := os.Stat(mesh_settings_path); os.IsNotExist(err) {
|
if _, err := os.Stat(mesh_settings_path); os.IsNotExist(err) {
|
||||||
err := ioutil.WriteFile(mesh_settings_path, []byte(""), 0750)
|
err := ioutil.WriteFile(mesh_settings_path, []byte(""), 0750)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -67,18 +93,32 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var path string
|
|
||||||
|
|
||||||
if len(os.Args) > 1 {
|
if confui.IndexHtml == "" {
|
||||||
path, err = filepath.Abs(filepath.Dir(os.Args[1]))
|
confui.IndexHtml = "index.html"
|
||||||
} else {
|
|
||||||
path, err = filepath.Abs(filepath.Dir(os.Args[0]))
|
|
||||||
}
|
}
|
||||||
|
//Check is it URL already
|
||||||
|
indexUrl, err := url.ParseRequestURI(confui.IndexHtml)
|
||||||
|
if err != nil || len(indexUrl.Scheme) < 2 { // handling no scheme at all and windows c:\ as scheme detection
|
||||||
|
confui.IndexHtml, err = filepath.Abs(confui.IndexHtml)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
panic(errors.New("Index file not found: " + err.Error()))
|
||||||
|
}
|
||||||
|
if stat, err := os.Stat(confui.IndexHtml); err != nil {
|
||||||
|
panic(errors.New(fmt.Sprintf("Index file %v not found or permissians denied: %v", confui.IndexHtml, err.Error())))
|
||||||
|
} else if stat.IsDir() {
|
||||||
|
panic(errors.New(fmt.Sprintf("Index file %v not found", confui.IndexHtml)))
|
||||||
|
}
|
||||||
|
path_prefix := ""
|
||||||
|
if indexUrl != nil && len(indexUrl.Scheme) == 1 {
|
||||||
|
path_prefix = "/"
|
||||||
|
}
|
||||||
|
indexUrl, err = url.ParseRequestURI("file://" + path_prefix + strings.ReplaceAll(confui.IndexHtml, "\\", "/"))
|
||||||
|
if err != nil {
|
||||||
|
panic(errors.New("Index file URL parse error: " + err.Error()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println(path)
|
|
||||||
w.Bind("onLoad", func() {
|
w.Bind("onLoad", func() {
|
||||||
log.Println("page loaded")
|
log.Println("page loaded")
|
||||||
go run(w)
|
go run(w)
|
||||||
|
@ -105,10 +145,8 @@ func main() {
|
||||||
w.Bind("ping", func(peer_list string) {
|
w.Bind("ping", func(peer_list string) {
|
||||||
go ping(w, peer_list)
|
go ping(w, peer_list)
|
||||||
})
|
})
|
||||||
//dat, err := ioutil.ReadFile(path+"/index.html")
|
log.Printf("Opening: %v", indexUrl)
|
||||||
//w.Navigate("data:text/html,"+url.QueryEscape(string(dat)))
|
w.Navigate(indexUrl.String())
|
||||||
//w.Navigate("data:text/html,"+"<html>"+path+"</html>")
|
|
||||||
w.Navigate("file://" + path + "/index.html")
|
|
||||||
w.Run()
|
w.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,45 +176,19 @@ func check(peer string) int64 {
|
||||||
return d.Milliseconds()
|
return d.Milliseconds()
|
||||||
}
|
}
|
||||||
|
|
||||||
func get_user_home_path() string {
|
|
||||||
path, exists := os.LookupEnv("HOME")
|
|
||||||
if exists {
|
|
||||||
return path
|
|
||||||
} else {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func get_ctl_path() string {
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
program_path := "programfiles"
|
|
||||||
path, exists := os.LookupEnv(program_path)
|
|
||||||
if exists {
|
|
||||||
fmt.Println("Program path: %s", path)
|
|
||||||
ctl_path := fmt.Sprintf("%s\\RiV-mesh\\meshctl.exe", path)
|
|
||||||
return ctl_path
|
|
||||||
} else {
|
|
||||||
fmt.Println("could not find Program Files path")
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ctl_path := fmt.Sprintf("/usr/local/bin/meshctl")
|
|
||||||
return ctl_path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func run(w webview.WebView) {
|
func run(w webview.WebView) {
|
||||||
if len(riv_ctrl_path) > 0 {
|
|
||||||
get_self(w)
|
get_self(w)
|
||||||
get_peers(w)
|
get_peers(w)
|
||||||
}
|
|
||||||
_ = time.AfterFunc(10*time.Second, func() {
|
_ = time.AfterFunc(10*time.Second, func() {
|
||||||
run(w)
|
run(w)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func add_peers(uri string) {
|
func add_peers(uri string) {
|
||||||
run_command_with_arg("addpeers", "uri="+uri)
|
_, err := run_command_with_arg("addpeers", "uri="+uri)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error in the add_peers() call:", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func remove_peers() {
|
func remove_peers() {
|
||||||
|
@ -237,3 +249,117 @@ func setPingValue(p webview.WebView, peer string, value string) {
|
||||||
p.Eval("setPingValue('" + peer + "','" + value + "');")
|
p.Eval("setPingValue('" + peer + "','" + value + "');")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func run_command(command string) []byte {
|
||||||
|
data, err := run_command_with_arg(command, "")
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error in the "+command+" call:", err)
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
func run_command_with_arg(command string, arg string) ([]byte, error) {
|
||||||
|
logbuffer := &bytes.Buffer{}
|
||||||
|
logger := log.New(logbuffer, "", log.Flags())
|
||||||
|
|
||||||
|
wrapErr := func(err error) error {
|
||||||
|
logger.Println("Error:", err)
|
||||||
|
return errors.New(fmt.Sprintln(logbuffer))
|
||||||
|
}
|
||||||
|
|
||||||
|
endpoint := getEndpoint(logger)
|
||||||
|
|
||||||
|
var conn net.Conn
|
||||||
|
u, err := url.Parse(endpoint)
|
||||||
|
d := net.Dialer{Timeout: 5000 * time.Millisecond}
|
||||||
|
if err == nil {
|
||||||
|
switch strings.ToLower(u.Scheme) {
|
||||||
|
case "unix":
|
||||||
|
logger.Println("Connecting to UNIX socket", endpoint[7:])
|
||||||
|
conn, err = d.Dial("unix", endpoint[7:])
|
||||||
|
case "tcp":
|
||||||
|
logger.Println("Connecting to TCP socket", u.Host)
|
||||||
|
conn, err = d.Dial("tcp", u.Host)
|
||||||
|
default:
|
||||||
|
logger.Println("Unknown protocol or malformed address - check your endpoint")
|
||||||
|
err = errors.New("protocol not supported")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.Println("Connecting to TCP socket", u.Host)
|
||||||
|
conn, err = d.Dial("tcp", endpoint)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, wrapErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Println("Connected")
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
decoder := json.NewDecoder(conn)
|
||||||
|
encoder := json.NewEncoder(conn)
|
||||||
|
send := &admin.AdminSocketRequest{}
|
||||||
|
recv := &admin.AdminSocketResponse{}
|
||||||
|
send.Name = command
|
||||||
|
args := map[string]string{}
|
||||||
|
switch {
|
||||||
|
case len(arg) > 0:
|
||||||
|
tokens := strings.SplitN(arg, "=", 2)
|
||||||
|
args[tokens[0]] = tokens[1]
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
if send.Arguments, err = json.Marshal(args); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := encoder.Encode(&send); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
logger.Printf("Request sent")
|
||||||
|
//js, _ := json.Marshal(send)
|
||||||
|
//fmt.Println("sent:", string(js))
|
||||||
|
if err := decoder.Decode(&recv); err != nil {
|
||||||
|
return nil, wrapErr(err)
|
||||||
|
}
|
||||||
|
if recv.Status == "error" {
|
||||||
|
if err := recv.Error; err != "" {
|
||||||
|
return nil, wrapErr(errors.New("Admin socket returned an error:" + err))
|
||||||
|
} else {
|
||||||
|
return nil, wrapErr(errors.New("Admin socket returned an error but didn't specify any error text"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if json, err := json.MarshalIndent(recv.Response, "", " "); err == nil {
|
||||||
|
return json, nil
|
||||||
|
}
|
||||||
|
return nil, wrapErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getEndpoint(logger *log.Logger) string {
|
||||||
|
if config, err := os.ReadFile(defaults.GetDefaults().DefaultConfigFile); err == nil {
|
||||||
|
if bytes.Equal(config[0:2], []byte{0xFF, 0xFE}) ||
|
||||||
|
bytes.Equal(config[0:2], []byte{0xFE, 0xFF}) {
|
||||||
|
utf := unicode.UTF16(unicode.BigEndian, unicode.UseBOM)
|
||||||
|
decoder := utf.NewDecoder()
|
||||||
|
config, err = decoder.Bytes(config)
|
||||||
|
if err != nil {
|
||||||
|
return defaults.GetDefaults().DefaultAdminListen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var dat map[string]interface{}
|
||||||
|
if err := hjson.Unmarshal(config, &dat); err != nil {
|
||||||
|
return defaults.GetDefaults().DefaultAdminListen
|
||||||
|
}
|
||||||
|
if ep, ok := dat["AdminListen"].(string); ok && (ep != "none" && ep != "") {
|
||||||
|
logger.Println("Found platform default config file", defaults.GetDefaults().DefaultConfigFile)
|
||||||
|
logger.Println("Using endpoint", ep, "from AdminListen")
|
||||||
|
return ep
|
||||||
|
} else {
|
||||||
|
logger.Println("Configuration file doesn't contain appropriate AdminListen option")
|
||||||
|
logger.Println("Falling back to platform default", defaults.GetDefaults().DefaultAdminListen)
|
||||||
|
return defaults.GetDefaults().DefaultAdminListen
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.Println("Can't open config file from default location", defaults.GetDefaults().DefaultConfigFile)
|
||||||
|
logger.Println("Falling back to platform default", defaults.GetDefaults().DefaultAdminListen)
|
||||||
|
return defaults.GetDefaults().DefaultAdminListen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,30 +3,16 @@
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "os"
|
||||||
"os/exec"
|
|
||||||
)
|
|
||||||
|
|
||||||
var riv_ctrl_path string
|
func get_user_home_path() string {
|
||||||
|
path, exists := os.LookupEnv("HOME")
|
||||||
func run_command(command string) []byte {
|
if exists {
|
||||||
args := []string{"-json", command}
|
return path
|
||||||
cmd := exec.Command(riv_ctrl_path, args...)
|
} else {
|
||||||
out, err := cmd.CombinedOutput()
|
return ""
|
||||||
if err != nil {
|
|
||||||
//log.Fatalf("cmd.Run() failed with %s\n", err)
|
|
||||||
return []byte(err.Error())
|
|
||||||
}
|
}
|
||||||
return out
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func run_command_with_arg(command string, arg string) []byte {
|
func Console(show bool) {
|
||||||
args := []string{"-json", command, arg}
|
|
||||||
cmd := exec.Command(riv_ctrl_path, args...)
|
|
||||||
out, err := cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
|
||||||
//log.Fatalf("command failed: %s\n", riv_ctrl_path+" "+strings.Join(args, " "))
|
|
||||||
return []byte(err.Error())
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,32 +4,31 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os/exec"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
var riv_ctrl_path string
|
func get_user_home_path() string {
|
||||||
|
path, exists := os.LookupEnv("USERPROFILE")
|
||||||
func run_command(command string) []byte {
|
if exists {
|
||||||
args := []string{"-json", command}
|
return path
|
||||||
cmd := exec.Command(riv_ctrl_path, args...)
|
} else {
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
|
return ""
|
||||||
out, err := cmd.CombinedOutput()
|
|
||||||
if err != nil {
|
|
||||||
//log.Fatalf("cmd.Run() failed with %s\n", err)
|
|
||||||
return []byte(err.Error())
|
|
||||||
}
|
}
|
||||||
return out
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func run_command_with_arg(command string, arg string) []byte {
|
func Console(show bool) {
|
||||||
args := []string{"-json", command, arg}
|
var getWin = syscall.NewLazyDLL("kernel32.dll").NewProc("GetConsoleWindow")
|
||||||
cmd := exec.Command(riv_ctrl_path, args...)
|
var showWin = syscall.NewLazyDLL("user32.dll").NewProc("ShowWindow")
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
|
hwnd, _, _ := getWin.Call()
|
||||||
out, err := cmd.CombinedOutput()
|
if hwnd == 0 {
|
||||||
if err != nil {
|
return
|
||||||
//log.Fatalf("command failed: %s\n", riv_ctrl_path+" "+strings.Join(args, " "))
|
}
|
||||||
return []byte(err.Error())
|
if show {
|
||||||
|
var SW_RESTORE uintptr = 9
|
||||||
|
showWin.Call(hwnd, SW_RESTORE)
|
||||||
|
} else {
|
||||||
|
var SW_HIDE uintptr = 0
|
||||||
|
showWin.Call(hwnd, SW_HIDE)
|
||||||
}
|
}
|
||||||
return out
|
|
||||||
}
|
}
|
||||||
|
|
6
go.mod
6
go.mod
|
@ -22,6 +22,7 @@ require (
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 // indirect
|
||||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
github.com/dustin/go-humanize v1.0.0 // indirect
|
||||||
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 // indirect
|
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 // indirect
|
||||||
github.com/getlantern/ema v0.0.0-20190620044903-5943d28f40e4 // indirect
|
github.com/getlantern/ema v0.0.0-20190620044903-5943d28f40e4 // indirect
|
||||||
|
@ -32,14 +33,11 @@ require (
|
||||||
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f // indirect
|
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f // indirect
|
||||||
github.com/go-stack/stack v1.8.0 // indirect
|
github.com/go-stack/stack v1.8.0 // indirect
|
||||||
github.com/google/uuid v1.1.2 // indirect
|
github.com/google/uuid v1.1.2 // indirect
|
||||||
github.com/jchv/go-webview-selector v0.0.0-20220126075917-13df59bce3cf // direct
|
github.com/webview/webview v0.0.0-20210330151455-f540d88dde4e
|
||||||
github.com/jchv/go-webview2 v0.0.0-20220126073738-2ea27096a5eb // indirect
|
|
||||||
github.com/jchv/go-winloader v0.0.0-20200815041850-dec1ee9a7fd5 // indirect
|
|
||||||
github.com/libp2p/go-buffer-pool v0.0.2 // indirect
|
github.com/libp2p/go-buffer-pool v0.0.2 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.8 // indirect
|
github.com/mattn/go-colorable v0.1.8 // indirect
|
||||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
|
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
|
||||||
github.com/rivo/uniseg v0.2.0 // indirect
|
github.com/rivo/uniseg v0.2.0 // indirect
|
||||||
github.com/webview/webview v0.0.0-20221206071508-862eb96057ff // indirect
|
|
||||||
go.uber.org/atomic v1.7.0 // indirect
|
go.uber.org/atomic v1.7.0 // indirect
|
||||||
go.uber.org/multierr v1.6.0 // indirect
|
go.uber.org/multierr v1.6.0 // indirect
|
||||||
go.uber.org/zap v1.19.1 // indirect
|
go.uber.org/zap v1.19.1 // indirect
|
||||||
|
|
14
go.sum
14
go.sum
|
@ -12,6 +12,8 @@ github.com/cheggaaa/pb/v3 v3.0.8/go.mod h1:UICbiLec/XO6Hw6k+BHEtHeQFzzBH4i2/qk/o
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ=
|
||||||
|
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
|
||||||
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
|
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
|
||||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||||
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
|
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
|
||||||
|
@ -43,12 +45,6 @@ github.com/hashicorp/go-syslog v1.0.0 h1:KaodqZuhUoZereWVIYmpUgZysurB1kBLX2j0MwM
|
||||||
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
|
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
|
||||||
github.com/hjson/hjson-go v3.1.0+incompatible h1:DY/9yE8ey8Zv22bY+mHV1uk2yRy0h8tKhZ77hEdi0Aw=
|
github.com/hjson/hjson-go v3.1.0+incompatible h1:DY/9yE8ey8Zv22bY+mHV1uk2yRy0h8tKhZ77hEdi0Aw=
|
||||||
github.com/hjson/hjson-go v3.1.0+incompatible/go.mod h1:qsetwF8NlsTsOTwZTApNlTCerV+b2GjYRRcIk4JMFio=
|
github.com/hjson/hjson-go v3.1.0+incompatible/go.mod h1:qsetwF8NlsTsOTwZTApNlTCerV+b2GjYRRcIk4JMFio=
|
||||||
github.com/jchv/go-webview-selector v0.0.0-20220126075917-13df59bce3cf h1:LfCNdIjo0pYj7ChAEkRZKPW/GKOzQLGqz/8CbDTxBvE=
|
|
||||||
github.com/jchv/go-webview-selector v0.0.0-20220126075917-13df59bce3cf/go.mod h1:RfUO9QcPUZ27qVS+rq9SYhhjsVNiolWwaIQdNjqFUsQ=
|
|
||||||
github.com/jchv/go-webview2 v0.0.0-20220126073738-2ea27096a5eb h1:oKKhiqJVbFqiPo+cj7zmY/R8AaOxgLQixUAOP/bKuRM=
|
|
||||||
github.com/jchv/go-webview2 v0.0.0-20220126073738-2ea27096a5eb/go.mod h1:/BNVc0Sw3Wj6Sz9uSxPwhCEUhhWs92hPde75K2YV24A=
|
|
||||||
github.com/jchv/go-winloader v0.0.0-20200815041850-dec1ee9a7fd5 h1:pdFFlHXY9tZXmJz+tRSm1DzYEH4ebha7cffmm607bMU=
|
|
||||||
github.com/jchv/go-winloader v0.0.0-20200815041850-dec1ee9a7fd5/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs=
|
|
||||||
github.com/kardianos/minwinsvc v1.0.2 h1:JmZKFJQrmTGa/WiW+vkJXKmfzdjabuEW4Tirj5lLdR0=
|
github.com/kardianos/minwinsvc v1.0.2 h1:JmZKFJQrmTGa/WiW+vkJXKmfzdjabuEW4Tirj5lLdR0=
|
||||||
github.com/kardianos/minwinsvc v1.0.2/go.mod h1:LUZNYhNmxujx2tR7FbdxqYJ9XDDoCd3MQcl1o//FWl4=
|
github.com/kardianos/minwinsvc v1.0.2/go.mod h1:LUZNYhNmxujx2tR7FbdxqYJ9XDDoCd3MQcl1o//FWl4=
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
|
@ -94,8 +90,8 @@ github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYp
|
||||||
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
|
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
|
||||||
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f h1:p4VB7kIXpOQvVn1ZaTIVp+3vuYAXFe3OJEvjbUYJLaA=
|
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f h1:p4VB7kIXpOQvVn1ZaTIVp+3vuYAXFe3OJEvjbUYJLaA=
|
||||||
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
|
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
|
||||||
github.com/webview/webview v0.0.0-20221206071508-862eb96057ff h1:pW+h72sRgm/o52LUihH14fjYukxmAqbGePUVSKOTZyQ=
|
github.com/webview/webview v0.0.0-20210330151455-f540d88dde4e h1:z780M7mCrdt6KiICeW9SGirvQjxDlrVU+n99FO93nbI=
|
||||||
github.com/webview/webview v0.0.0-20221206071508-862eb96057ff/go.mod h1:rpXAuuHgyEJb6kXcXldlkOjU6y4x+YcASKKXJNUhh0Y=
|
github.com/webview/webview v0.0.0-20210330151455-f540d88dde4e/go.mod h1:rpXAuuHgyEJb6kXcXldlkOjU6y4x+YcASKKXJNUhh0Y=
|
||||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
|
@ -137,10 +133,8 @@ golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200810151505-1b9f1253b3ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210218145245-beda7e5e158e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
|
|
@ -234,11 +234,18 @@ func (c *Core) RemovePeer(uri string, sourceInterface string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Core) RemovePeers() error {
|
func (c *Core) RemovePeers() error {
|
||||||
c.config._peers = map[Peer]*linkInfo{}
|
phony.Block(c, func() {
|
||||||
//for k := range c.config.InterfacePeers {
|
for peer, linkInfo := range c.config._peers {
|
||||||
// delete(c.config.InterfacePeers, k)
|
if linkInfo != nil {
|
||||||
//}
|
c.links.Act(nil, func() {
|
||||||
|
if link := c.links._links[*linkInfo]; link != nil {
|
||||||
|
_ = link.close()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
delete(c.config._peers, peer)
|
||||||
|
}
|
||||||
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
// The Core object represents the Mesh node. You should create a Core
|
// The Core object represents the Mesh node. You should create a Core
|
||||||
// object for each Mesh node you plan to run.
|
// object for each Mesh node you plan to run.
|
||||||
type Core struct {
|
type Core struct {
|
||||||
address Address
|
|
||||||
// This is the main data structure that holds everything else for a node
|
// This is the main data structure that holds everything else for a node
|
||||||
// We're going to keep our own copy of the provided config - that way we can
|
// We're going to keep our own copy of the provided config - that way we can
|
||||||
// guarantee that it will be covered by the mutex
|
// guarantee that it will be covered by the mutex
|
||||||
|
|
|
@ -8,6 +8,12 @@ type NetworkDomainConfig = config.NetworkDomainConfig
|
||||||
var defaultConfig = "" // LDFLAGS='-X github.com/yggdrasil-network/yggdrasil-go/src/defaults.defaultConfig=/path/to/config
|
var defaultConfig = "" // LDFLAGS='-X github.com/yggdrasil-network/yggdrasil-go/src/defaults.defaultConfig=/path/to/config
|
||||||
var defaultAdminListen = "" // LDFLAGS='-X github.com/yggdrasil-network/yggdrasil-go/src/defaults.defaultAdminListen=unix://path/to/sock'
|
var defaultAdminListen = "" // LDFLAGS='-X github.com/yggdrasil-network/yggdrasil-go/src/defaults.defaultAdminListen=unix://path/to/sock'
|
||||||
|
|
||||||
|
type defaultParameters struct {
|
||||||
|
|
||||||
|
//Network domain
|
||||||
|
DefaultNetworkDomain NetworkDomainConfig
|
||||||
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -21,15 +27,23 @@ type platformDefaultParameters struct {
|
||||||
// Multicast interfaces
|
// Multicast interfaces
|
||||||
DefaultMulticastInterfaces []MulticastInterfaceConfig
|
DefaultMulticastInterfaces []MulticastInterfaceConfig
|
||||||
|
|
||||||
//Network domain
|
|
||||||
DefaultNetworkDomain NetworkDomainConfig
|
|
||||||
|
|
||||||
// TUN
|
// TUN
|
||||||
MaximumIfMTU uint64
|
MaximumIfMTU uint64
|
||||||
DefaultIfMTU uint64
|
DefaultIfMTU uint64
|
||||||
DefaultIfName string
|
DefaultIfName string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Defines defaults for the all platforms.
|
||||||
|
func define() defaultParameters {
|
||||||
|
return defaultParameters{
|
||||||
|
|
||||||
|
// Network domain
|
||||||
|
DefaultNetworkDomain: NetworkDomainConfig{
|
||||||
|
Prefix: "fc",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func GetDefaults() platformDefaultParameters {
|
func GetDefaults() platformDefaultParameters {
|
||||||
defaults := getDefaults()
|
defaults := getDefaults()
|
||||||
if defaultConfig != "" {
|
if defaultConfig != "" {
|
||||||
|
@ -56,10 +70,10 @@ func GenerateConfig() *config.NodeConfig {
|
||||||
cfg.InterfacePeers = map[string][]string{}
|
cfg.InterfacePeers = map[string][]string{}
|
||||||
cfg.AllowedPublicKeys = []string{}
|
cfg.AllowedPublicKeys = []string{}
|
||||||
cfg.MulticastInterfaces = defaults.DefaultMulticastInterfaces
|
cfg.MulticastInterfaces = defaults.DefaultMulticastInterfaces
|
||||||
cfg.NetworkDomain = defaults.DefaultNetworkDomain
|
|
||||||
cfg.IfName = defaults.DefaultIfName
|
cfg.IfName = defaults.DefaultIfName
|
||||||
cfg.IfMTU = defaults.DefaultIfMTU
|
cfg.IfMTU = defaults.DefaultIfMTU
|
||||||
cfg.NodeInfoPrivacy = false
|
cfg.NodeInfoPrivacy = false
|
||||||
|
cfg.NetworkDomain = define().DefaultNetworkDomain
|
||||||
|
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,6 @@ func getDefaults() platformDefaultParameters {
|
||||||
{Regex: "bridge.*", Beacon: true, Listen: true},
|
{Regex: "bridge.*", Beacon: true, Listen: true},
|
||||||
},
|
},
|
||||||
|
|
||||||
// Network domain
|
|
||||||
DefaultNetworkDomain: NetworkDomainConfig{
|
|
||||||
Prefix: "fc",
|
|
||||||
},
|
|
||||||
|
|
||||||
// TUN
|
// TUN
|
||||||
MaximumIfMTU: 65535,
|
MaximumIfMTU: 65535,
|
||||||
DefaultIfMTU: 65535,
|
DefaultIfMTU: 65535,
|
||||||
|
|
|
@ -18,11 +18,6 @@ func getDefaults() platformDefaultParameters {
|
||||||
{Regex: ".*", Beacon: true, Listen: true},
|
{Regex: ".*", Beacon: true, Listen: true},
|
||||||
},
|
},
|
||||||
|
|
||||||
// Network domain
|
|
||||||
DefaultNetworkDomain: NetworkDomainConfig{
|
|
||||||
Prefix: "fc",
|
|
||||||
},
|
|
||||||
|
|
||||||
// TUN
|
// TUN
|
||||||
MaximumIfMTU: 32767,
|
MaximumIfMTU: 32767,
|
||||||
DefaultIfMTU: 32767,
|
DefaultIfMTU: 32767,
|
||||||
|
|
|
@ -18,11 +18,6 @@ func getDefaults() platformDefaultParameters {
|
||||||
{Regex: ".*", Beacon: true, Listen: true},
|
{Regex: ".*", Beacon: true, Listen: true},
|
||||||
},
|
},
|
||||||
|
|
||||||
// Network domain
|
|
||||||
DefaultNetworkDomain: NetworkDomainConfig{
|
|
||||||
Prefix: "fc",
|
|
||||||
},
|
|
||||||
|
|
||||||
// TUN
|
// TUN
|
||||||
MaximumIfMTU: 65535,
|
MaximumIfMTU: 65535,
|
||||||
DefaultIfMTU: 65535,
|
DefaultIfMTU: 65535,
|
||||||
|
|
|
@ -18,11 +18,6 @@ func getDefaults() platformDefaultParameters {
|
||||||
{Regex: ".*", Beacon: true, Listen: true},
|
{Regex: ".*", Beacon: true, Listen: true},
|
||||||
},
|
},
|
||||||
|
|
||||||
// Network domain
|
|
||||||
DefaultNetworkDomain: NetworkDomainConfig{
|
|
||||||
Prefix: "fc",
|
|
||||||
},
|
|
||||||
|
|
||||||
// TUN
|
// TUN
|
||||||
MaximumIfMTU: 16384,
|
MaximumIfMTU: 16384,
|
||||||
DefaultIfMTU: 16384,
|
DefaultIfMTU: 16384,
|
||||||
|
|
|
@ -18,11 +18,6 @@ func getDefaults() platformDefaultParameters {
|
||||||
{Regex: ".*", Beacon: true, Listen: true},
|
{Regex: ".*", Beacon: true, Listen: true},
|
||||||
},
|
},
|
||||||
|
|
||||||
// Network domain
|
|
||||||
DefaultNetworkDomain: NetworkDomainConfig{
|
|
||||||
Prefix: "fc",
|
|
||||||
},
|
|
||||||
|
|
||||||
// TUN
|
// TUN
|
||||||
MaximumIfMTU: 65535,
|
MaximumIfMTU: 65535,
|
||||||
DefaultIfMTU: 65535,
|
DefaultIfMTU: 65535,
|
||||||
|
|
|
@ -18,11 +18,6 @@ func getDefaults() platformDefaultParameters {
|
||||||
{Regex: ".*", Beacon: true, Listen: true},
|
{Regex: ".*", Beacon: true, Listen: true},
|
||||||
},
|
},
|
||||||
|
|
||||||
// Network domain
|
|
||||||
DefaultNetworkDomain: NetworkDomainConfig{
|
|
||||||
Prefix: "fc",
|
|
||||||
},
|
|
||||||
|
|
||||||
// TUN
|
// TUN
|
||||||
MaximumIfMTU: 65535,
|
MaximumIfMTU: 65535,
|
||||||
DefaultIfMTU: 65535,
|
DefaultIfMTU: 65535,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue