packages/hyprspace: ban yaml from existence

This commit is contained in:
Max Headroom 2023-10-23 23:12:48 +02:00
parent 16384da670
commit dc51c4250c
8 changed files with 36 additions and 74 deletions

View file

@ -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 <YOUR_TUN_NET>/24 -o eth0 -j MASQUERADE
iptables -A FORWARD 1 -i <HS_TUN> -o <DEV_GATEWAY> -j ACCEPT
iptables -A FORWARD 1 -i <DEV_GATEWAY> -o <HS_TUN> -j ACCEPT
```
Determine gateway router:
```
# curl ifconfg.me
<GATEWAY_ROUTER>
```
### 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 <GATEWAY_ROUTER> via <YOUR_GATEWAY>
And all traffic for hyprspace tun
# ip route add default dev <HS_TUN> metric 1
```
## License
Copyright 2021-2022 Alec Scott <hi@alecbcs.com>

View file

@ -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.

View file

@ -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)

View file

@ -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.

View file

@ -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
}

View file

@ -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 (

View file

@ -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=

View file

@ -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.";