From dc51c4250c7e484adfa043fe3baf62da66df7763 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 23 Oct 2023 23:12:48 +0200 Subject: [PATCH] packages/hyprspace: ban yaml from existence --- packages/networking/hyprspace/README.md | 67 +++++-------------- packages/networking/hyprspace/cli/down.go | 2 +- packages/networking/hyprspace/cli/init.go | 7 +- packages/networking/hyprspace/cli/up.go | 2 +- .../networking/hyprspace/config/config.go | 28 ++++---- packages/networking/hyprspace/go.mod | 1 - packages/networking/hyprspace/go.sum | 1 - packages/networking/hyprspace/project.nix | 2 +- 8 files changed, 36 insertions(+), 74 deletions(-) diff --git a/packages/networking/hyprspace/README.md b/packages/networking/hyprspace/README.md index 58c9afd..761d26e 100644 --- a/packages/networking/hyprspace/README.md +++ b/packages/networking/hyprspace/README.md @@ -108,19 +108,19 @@ sudo hyprspace init hs1 Now that we've got a set of configurations we'll want to tell the machines about each other. By default Hyprspace will -put the interface configurations in `/etc/hyprspace/interface-name.yaml`. +put the interface configurations in `/etc/hyprspace/interface-name.json`. So for our example we'll run ###### Local Machine ```bash -sudo nano /etc/hyprspace/hs0.yaml +sudo nano /etc/hyprspace/hs0.json ``` and ###### Remote Machine ```bash -sudo nano /etc/hyprspace/hs1.yaml +sudo nano /etc/hyprspace/hs1.json ``` ### Update Peer Configs @@ -129,14 +129,20 @@ Now in each config we'll add the other machine's ID as a peer. You can find each machine's ID at the top of their configuration file. Update, -```yaml -peers: {} +```json +{ + "peers": {} +} ``` to -```yaml -peers: - 10.1.1.2: - id: YOUR-OTHER-PEER-ID +```json +{ + "peers": { + "10.1.1.2": { + "id": "YOUR-OTHER-PEER-ID" + } + } +} ``` Notice here we'll have to pick one of our machines to be `10.1.1.1` @@ -186,49 +192,6 @@ sudo hyprspace down hs1 WireGuard is a registered trademark of Jason A. Donenfeld. - -## Routes - -### Prepare each route node: - -``` -# sysctl -n net.ipv4.ip_forward -0 -# sysctl -w net.ipv4.ip_forward=1 -iptables -t nat -A POSTROUTING -s /24 -o eth0 -j MASQUERADE -iptables -A FORWARD 1 -i -o -j ACCEPT -iptables -A FORWARD 1 -i -o -j ACCEPT - -``` -Determine gateway router: -``` -# curl ifconfg.me - -``` - -### Configure client: -Config hyprspace yaml configuration file: -``` -interface: - ... -peers: - ID: ... - ... -routes: - 192.168.3.0/24: - ip: 10.0.0.3 - 0.0.0.0/0: - ip: 10.0.0.1 - -``` -Prepare routes -``` -One for each route: -# ip route add via - -And all traffic for hyprspace tun -# ip route add default dev metric 1 -``` ## License Copyright 2021-2022 Alec Scott diff --git a/packages/networking/hyprspace/cli/down.go b/packages/networking/hyprspace/cli/down.go index 4965c19..dae2a29 100644 --- a/packages/networking/hyprspace/cli/down.go +++ b/packages/networking/hyprspace/cli/down.go @@ -32,7 +32,7 @@ func DownRun(r *cmd.Root, c *cmd.Sub) { // Parse Global Config Flag for Custom Config Path configPath := r.Flags.(*GlobalFlags).Config if configPath == "" { - configPath = "/etc/hyprspace/" + args.InterfaceName + ".yaml" + configPath = "/etc/hyprspace/" + args.InterfaceName + ".json" } // Read lock from file system to stop process. diff --git a/packages/networking/hyprspace/cli/init.go b/packages/networking/hyprspace/cli/init.go index dbd67a4..62715ee 100644 --- a/packages/networking/hyprspace/cli/init.go +++ b/packages/networking/hyprspace/cli/init.go @@ -1,6 +1,7 @@ package cli import ( + "encoding/json" "fmt" "os" "path/filepath" @@ -11,7 +12,6 @@ import ( "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/core/crypto" "github.com/multiformats/go-multibase" - "gopkg.in/yaml.v2" ) // Init creates a configuration for a Hyprspace Interface. @@ -36,7 +36,7 @@ func InitRun(r *cmd.Root, c *cmd.Sub) { // Parse Global Config Flag configPath := r.Flags.(*GlobalFlags).Config if configPath == "" { - configPath = "/etc/hyprspace/" + args.InterfaceName + ".yaml" + configPath = "/etc/hyprspace/" + args.InterfaceName + ".json" } // Create New Libp2p Node @@ -56,9 +56,10 @@ func InitRun(r *cmd.Root, c *cmd.Sub) { ID: host.ID(), PrivateKey: multibase.MustNewEncoder(multibase.Base58BTC).Encode(keyBytes), }, + Peers: make([]config.Peer, 0), } - out, err := yaml.Marshal(&new) + out, err := json.MarshalIndent(&new, "", " ") checkErr(err) err = os.MkdirAll(filepath.Dir(configPath), os.ModePerm) diff --git a/packages/networking/hyprspace/cli/up.go b/packages/networking/hyprspace/cli/up.go index 4461871..a68ea64 100644 --- a/packages/networking/hyprspace/cli/up.go +++ b/packages/networking/hyprspace/cli/up.go @@ -72,7 +72,7 @@ func UpRun(r *cmd.Root, c *cmd.Sub) { // Parse Global Config Flag for Custom Config Path configPath := r.Flags.(*GlobalFlags).Config if configPath == "" { - configPath = "/etc/hyprspace/" + args.InterfaceName + ".yaml" + configPath = "/etc/hyprspace/" + args.InterfaceName + ".json" } // Read in configuration from file. diff --git a/packages/networking/hyprspace/config/config.go b/packages/networking/hyprspace/config/config.go index 0f7f632..cba4b70 100644 --- a/packages/networking/hyprspace/config/config.go +++ b/packages/networking/hyprspace/config/config.go @@ -1,41 +1,41 @@ package config import ( + "encoding/json" "fmt" "log" "net" "os" "github.com/libp2p/go-libp2p/core/peer" - "gopkg.in/yaml.v2" ) // Config is the main Configuration Struct for Hyprspace. type Config struct { - Path string `yaml:"path,omitempty"` - Interface Interface `yaml:"interface"` - Peers []Peer `yaml:"peers"` - Routes []Route + Path string `json:"-"` + Interface Interface `json:"interface"` + Peers []Peer `json:"peers"` + Routes []Route `json:"-"` } // Interface defines all of the fields that a local node needs to know about itself! type Interface struct { - Name string `yaml:"name"` - ID peer.ID `yaml:"id"` - ListenPort int `yaml:"listen_port"` - Address string `yaml:"address"` - PrivateKey string `yaml:"private_key"` + Name string `json:"name"` + ID peer.ID `json:"id"` + ListenPort int `json:"listen_port"` + Address string `json:"address"` + PrivateKey string `json:"private_key"` } // Peer defines a peer in the configuration. We might add more to this later. type Peer struct { - ID peer.ID `yaml:"id"` - Routes []Route `yaml:"routes"` + ID peer.ID `json:"id"` + Routes []Route `json:"routes"` } type Route struct { Target Peer - NetworkStr string `yaml:"net"` + NetworkStr string `json:"net"` Network net.IPNet } @@ -56,7 +56,7 @@ func Read(path string) (*Config, error) { } // Read in config settings from file. - err = yaml.Unmarshal(in, &result) + err = json.Unmarshal(in, &result) if err != nil { return nil, err } diff --git a/packages/networking/hyprspace/go.mod b/packages/networking/hyprspace/go.mod index 9c79d18..67fdcd5 100644 --- a/packages/networking/hyprspace/go.mod +++ b/packages/networking/hyprspace/go.mod @@ -11,7 +11,6 @@ require ( github.com/prometheus/client_golang v1.16.0 github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 github.com/vishvananda/netlink v1.1.0 - gopkg.in/yaml.v2 v2.4.0 ) require ( diff --git a/packages/networking/hyprspace/go.sum b/packages/networking/hyprspace/go.sum index 4a318df..d672bef 100644 --- a/packages/networking/hyprspace/go.sum +++ b/packages/networking/hyprspace/go.sum @@ -569,7 +569,6 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/packages/networking/hyprspace/project.nix b/packages/networking/hyprspace/project.nix index 493f6e0..b058809 100644 --- a/packages/networking/hyprspace/project.nix +++ b/packages/networking/hyprspace/project.nix @@ -29,7 +29,7 @@ ]); }; - vendorSha256 = "sha256-6Hg1XdDIs6rXmag0oihCDqgNRDTQRwgPDj40q/b4+mo="; + vendorSha256 = "sha256-zr9gRYA979VYaD8jvK1MMEDhbcpHvaJccR91wp5qClU="; meta = with lib; { description = "A Lightweight VPN Built on top of Libp2p for Truly Distributed Networks.";