Compare commits
No commits in common. "64fdba0a485eda5e941d8e93e32f5f84f96c3294" and "8c3e6a2845f2392bc0fe066c5b2671035c645568" have entirely different histories.
64fdba0a48
...
8c3e6a2845
@ -1,3 +1,4 @@
|
||||
|
||||
#
|
||||
# This file defines all configuration directives which can be modified for
|
||||
# the isle daemon at runtime. All values specified here are the
|
||||
@ -5,23 +6,17 @@
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# Configuration broken down by network. Each network can be identified by its
|
||||
# ID, its name, or its domain.
|
||||
#networks:
|
||||
|
||||
#id-or-name-or-domain:
|
||||
|
||||
# A DNS service runs as part of every isle process.
|
||||
#dns:
|
||||
# A DNS service runs as part of every isle process.
|
||||
dns:
|
||||
|
||||
# list of IPs that the DNS service will use to resolve requests outside the
|
||||
# network's domain.
|
||||
#resolvers:
|
||||
# - 1.1.1.1
|
||||
# - 8.8.8.8
|
||||
resolvers:
|
||||
- 1.1.1.1
|
||||
- 8.8.8.8
|
||||
|
||||
# A VPN service runs as part of every isle process.
|
||||
#vpn:
|
||||
# A VPN service runs as part of every isle process.
|
||||
vpn:
|
||||
|
||||
# Enable this field if the vpn will be made to be publicly accessible at a
|
||||
# particular IP or hostname. At least one host must have a publicly accessible
|
||||
@ -30,28 +25,38 @@
|
||||
|
||||
# Firewall directives, as described here:
|
||||
# https://github.com/slackhq/nebula/blob/v1.6.1/examples/config.yml#L260
|
||||
#firewall:
|
||||
firewall:
|
||||
|
||||
conntrack:
|
||||
tcp_timeout: 12m
|
||||
udp_timeout: 3m
|
||||
default_timeout: 10m
|
||||
max_connections: 100000
|
||||
|
||||
outbound:
|
||||
|
||||
# Allow all outbound traffic from this node.
|
||||
#outbound:
|
||||
# - port: any
|
||||
# proto: any
|
||||
# host: any
|
||||
- port: any
|
||||
proto: any
|
||||
host: any
|
||||
|
||||
inbound:
|
||||
|
||||
# If any storage allocations are declared below, the ports used will be
|
||||
# allowed here automatically.
|
||||
|
||||
# Allow ICMP between hosts.
|
||||
#inbound:
|
||||
# - port: any
|
||||
# proto: icmp
|
||||
# host: any
|
||||
#
|
||||
# # If any storage allocations are declared below, the ports used will be
|
||||
# # allowed here automatically.
|
||||
- port: any
|
||||
proto: icmp
|
||||
host: any
|
||||
|
||||
#tun:
|
||||
# That's it.
|
||||
|
||||
tun:
|
||||
# Name of the tun network device which will route VPN traffic.
|
||||
#device: isle-tun
|
||||
device: isle-tun
|
||||
|
||||
#storage:
|
||||
storage:
|
||||
|
||||
# Allocations defined here are used to store data in the distributed storage
|
||||
# network. If no allocations are defined then no data is replicated to this
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
"net/netip"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"dev.mediocregopher.com/mediocre-go-lib.git/mctx"
|
||||
)
|
||||
@ -53,42 +52,6 @@ func (p CreationParams) Annotate(aa mctx.Annotations) {
|
||||
aa["networkDomain"] = p.Domain
|
||||
}
|
||||
|
||||
// Matches returns true if the given string matches some aspect of the
|
||||
// CreationParams.
|
||||
func (p CreationParams) Matches(str string) bool {
|
||||
if strings.HasPrefix(p.ID, str) {
|
||||
return true
|
||||
}
|
||||
|
||||
if strings.EqualFold(p.Name, str) {
|
||||
return true
|
||||
}
|
||||
|
||||
if strings.EqualFold(p.Domain, str) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Conflicts returns true if either CreationParams has some parameter which
|
||||
// overlaps with that of the other.
|
||||
func (p CreationParams) Conflicts(p2 CreationParams) bool {
|
||||
if p.ID == p2.ID {
|
||||
return true
|
||||
}
|
||||
|
||||
if strings.EqualFold(p.Name, p2.Name) {
|
||||
return true
|
||||
}
|
||||
|
||||
if strings.EqualFold(p.Domain, p2.Domain) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Bootstrap contains all information which is needed by a host daemon to join a
|
||||
// network on boot.
|
||||
type Bootstrap struct {
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func (ctx subCmdCtx) getHosts() ([]bootstrap.Host, error) {
|
||||
res, err := newDaemonRPCClient().GetHosts(ctx)
|
||||
res, err := ctx.daemonRPC.GetHosts(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("calling GetHosts: %w", err)
|
||||
}
|
||||
|
@ -18,25 +18,26 @@ import (
|
||||
var subCmdDaemon = subCmd{
|
||||
name: "daemon",
|
||||
descr: "Runs the isle daemon (Default if no sub-command given)",
|
||||
noNetwork: true,
|
||||
do: func(ctx subCmdCtx) error {
|
||||
daemonConfigPath := ctx.flags.StringP(
|
||||
|
||||
flags := ctx.flagSet(false)
|
||||
|
||||
daemonConfigPath := flags.StringP(
|
||||
"config-path", "c", "",
|
||||
"Optional path to a daemon.yml file to load configuration from.",
|
||||
)
|
||||
|
||||
dumpConfig := ctx.flags.Bool(
|
||||
dumpConfig := flags.Bool(
|
||||
"dump-config", false,
|
||||
"Write the default configuration file to stdout and exit.",
|
||||
)
|
||||
|
||||
logLevelStr := ctx.flags.StringP(
|
||||
logLevelStr := flags.StringP(
|
||||
"log-level", "l", "info",
|
||||
`Maximum log level which should be output. Values can be "debug", "info", "warn", "error", "fatal". Does not apply to sub-processes`,
|
||||
)
|
||||
|
||||
ctx, err := ctx.withParsedFlags()
|
||||
if err != nil {
|
||||
if err := flags.Parse(ctx.args); err != nil {
|
||||
return fmt.Errorf("parsing flags: %w", err)
|
||||
}
|
||||
|
||||
@ -55,7 +56,7 @@ var subCmdDaemon = subCmd{
|
||||
// required linux capabilities are set.
|
||||
// TODO check that the tun module is loaded (for nebula).
|
||||
|
||||
daemonConfig, err := daecommon.LoadConfig(*daemonConfigPath)
|
||||
daemonConfig, err := daecommon.LoadConfig(envAppDirPath, *daemonConfigPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("loading daemon config: %w", err)
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"isle/daemon"
|
||||
"isle/daemon/jsonrpc2"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -17,14 +16,6 @@ import (
|
||||
|
||||
const daemonHTTPRPCPath = "/rpc/v0.json"
|
||||
|
||||
func newDaemonRPCClient() daemon.RPC {
|
||||
return daemon.RPCFromClient(
|
||||
jsonrpc2.NewUnixHTTPClient(
|
||||
daemon.HTTPSocketPath(), daemonHTTPRPCPath,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
func newHTTPServer(
|
||||
ctx context.Context, logger *mlog.Logger, daemonInst *daemon.Daemon,
|
||||
) (
|
||||
|
@ -34,24 +34,25 @@ func initMCConfigDir(envVars daecommon.EnvVars) (string, error) {
|
||||
var subCmdGarageMC = subCmd{
|
||||
name: "mc",
|
||||
descr: "Runs the mc (minio-client) binary. The isle garage can be accessed under the `garage` alias",
|
||||
passthroughArgs: true,
|
||||
do: func(ctx subCmdCtx) error {
|
||||
keyID := ctx.flags.StringP(
|
||||
|
||||
flags := ctx.flagSet(true)
|
||||
|
||||
keyID := flags.StringP(
|
||||
"key-id", "i", "",
|
||||
"Optional key ID to use, defaults to that of the shared global key",
|
||||
)
|
||||
|
||||
keySecret := ctx.flags.StringP(
|
||||
keySecret := flags.StringP(
|
||||
"key-secret", "s", "",
|
||||
"Optional key secret to use, defaults to that of the shared global key",
|
||||
)
|
||||
|
||||
ctx, err := ctx.withParsedFlags()
|
||||
if err != nil {
|
||||
if err := flags.Parse(ctx.args); err != nil {
|
||||
return fmt.Errorf("parsing flags: %w", err)
|
||||
}
|
||||
|
||||
clientParams, err := newDaemonRPCClient().GetGarageClientParams(ctx)
|
||||
clientParams, err := ctx.daemonRPC.GetGarageClientParams(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("calling GetGarageClientParams: %w", err)
|
||||
}
|
||||
@ -66,9 +67,9 @@ var subCmdGarageMC = subCmd{
|
||||
*keySecret = clientParams.GlobalBucketS3APICredentials.Secret
|
||||
}
|
||||
|
||||
args := ctx.flags.Args()
|
||||
args := flags.Args()
|
||||
|
||||
if i := ctx.flags.ArgsLenAtDash(); i >= 0 {
|
||||
if i := flags.ArgsLenAtDash(); i >= 0 {
|
||||
args = args[i:]
|
||||
}
|
||||
|
||||
@ -116,12 +117,8 @@ var subCmdGarageCLI = subCmd{
|
||||
name: "cli",
|
||||
descr: "Runs the garage binary, automatically configured to point to the garage sub-process of a running isle daemon",
|
||||
do: func(ctx subCmdCtx) error {
|
||||
ctx, err := ctx.withParsedFlags()
|
||||
if err != nil {
|
||||
return fmt.Errorf("parsing flags: %w", err)
|
||||
}
|
||||
|
||||
clientParams, err := newDaemonRPCClient().GetGarageClientParams(ctx)
|
||||
clientParams, err := ctx.daemonRPC.GetGarageClientParams(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("calling GetGarageClientParams: %w", err)
|
||||
}
|
||||
|
@ -16,26 +16,26 @@ var subCmdHostCreate = subCmd{
|
||||
descr: "Creates a new host in the network, writing its new bootstrap.json to stdout",
|
||||
do: func(ctx subCmdCtx) error {
|
||||
var (
|
||||
flags = ctx.flagSet(false)
|
||||
hostName hostNameFlag
|
||||
ip ipFlag
|
||||
)
|
||||
|
||||
hostNameF := ctx.flags.VarPF(
|
||||
hostNameF := flags.VarPF(
|
||||
&hostName,
|
||||
"hostname", "n",
|
||||
"Name of the host to generate bootstrap.json for",
|
||||
)
|
||||
|
||||
ctx.flags.VarP(&ip, "ip", "i", "IP of the new host. An available IP will be chosen if none is given.")
|
||||
flags.VarP(&ip, "ip", "i", "IP of the new host. An available IP will be chosen if none is given.")
|
||||
|
||||
canCreateHosts := ctx.flags.Bool(
|
||||
canCreateHosts := flags.Bool(
|
||||
"can-create-hosts",
|
||||
false,
|
||||
"The new host should have the ability to create hosts too",
|
||||
)
|
||||
|
||||
ctx, err := ctx.withParsedFlags()
|
||||
if err != nil {
|
||||
if err := flags.Parse(ctx.args); err != nil {
|
||||
return fmt.Errorf("parsing flags: %w", err)
|
||||
}
|
||||
|
||||
@ -43,7 +43,11 @@ var subCmdHostCreate = subCmd{
|
||||
return errors.New("--hostname is required")
|
||||
}
|
||||
|
||||
res, err := newDaemonRPCClient().CreateHost(
|
||||
var (
|
||||
res network.JoiningBootstrap
|
||||
err error
|
||||
)
|
||||
res, err = ctx.daemonRPC.CreateHost(
|
||||
ctx, hostName.V, network.CreateHostOpts{
|
||||
IP: ip.V,
|
||||
CanCreateHosts: *canCreateHosts,
|
||||
@ -61,11 +65,6 @@ var subCmdHostList = subCmd{
|
||||
name: "list",
|
||||
descr: "Lists all hosts in the network, and their IPs",
|
||||
do: func(ctx subCmdCtx) error {
|
||||
ctx, err := ctx.withParsedFlags()
|
||||
if err != nil {
|
||||
return fmt.Errorf("parsing flags: %w", err)
|
||||
}
|
||||
|
||||
hostsRes, err := ctx.getHosts()
|
||||
if err != nil {
|
||||
return fmt.Errorf("calling GetHosts: %w", err)
|
||||
@ -103,17 +102,17 @@ var subCmdHostRemove = subCmd{
|
||||
descr: "Removes a host from the network",
|
||||
do: func(ctx subCmdCtx) error {
|
||||
var (
|
||||
flags = ctx.flagSet(false)
|
||||
hostName hostNameFlag
|
||||
)
|
||||
|
||||
hostNameF := ctx.flags.VarPF(
|
||||
hostNameF := flags.VarPF(
|
||||
&hostName,
|
||||
"hostname", "n",
|
||||
"Name of the host to remove",
|
||||
)
|
||||
|
||||
ctx, err := ctx.withParsedFlags()
|
||||
if err != nil {
|
||||
if err := flags.Parse(ctx.args); err != nil {
|
||||
return fmt.Errorf("parsing flags: %w", err)
|
||||
}
|
||||
|
||||
@ -121,7 +120,7 @@ var subCmdHostRemove = subCmd{
|
||||
return errors.New("--hostname is required")
|
||||
}
|
||||
|
||||
if err := newDaemonRPCClient().RemoveHost(ctx, hostName.V); err != nil {
|
||||
if err := ctx.daemonRPC.RemoveHost(ctx, hostName.V); err != nil {
|
||||
return fmt.Errorf("calling RemoveHost: %w", err)
|
||||
}
|
||||
|
||||
|
@ -56,8 +56,8 @@ func main() {
|
||||
|
||||
err := subCmdCtx{
|
||||
Context: ctx,
|
||||
logger: logger,
|
||||
args: os.Args[1:],
|
||||
logger: logger,
|
||||
}.doSubCmd(
|
||||
subCmdDaemon,
|
||||
subCmdGarage,
|
||||
|
@ -12,21 +12,23 @@ var subCmdNebulaCreateCert = subCmd{
|
||||
name: "create-cert",
|
||||
descr: "Creates a signed nebula certificate file for an existing host and writes it to stdout",
|
||||
do: func(ctx subCmdCtx) error {
|
||||
var (
|
||||
flags = ctx.flagSet(false)
|
||||
hostName hostNameFlag
|
||||
)
|
||||
|
||||
var hostName hostNameFlag
|
||||
hostNameF := ctx.flags.VarPF(
|
||||
hostNameF := flags.VarPF(
|
||||
&hostName,
|
||||
"hostname", "n",
|
||||
"Name of the host to generate a certificate for",
|
||||
)
|
||||
|
||||
pubKeyPath := ctx.flags.StringP(
|
||||
pubKeyPath := flags.StringP(
|
||||
"public-key-path", "p", "",
|
||||
`Path to PEM file containing public key which will be embedded in the cert.`,
|
||||
)
|
||||
|
||||
ctx, err := ctx.withParsedFlags()
|
||||
if err != nil {
|
||||
if err := flags.Parse(ctx.args); err != nil {
|
||||
return fmt.Errorf("parsing flags: %w", err)
|
||||
}
|
||||
|
||||
@ -44,7 +46,7 @@ var subCmdNebulaCreateCert = subCmd{
|
||||
return fmt.Errorf("unmarshaling public key as PEM: %w", err)
|
||||
}
|
||||
|
||||
res, err := newDaemonRPCClient().CreateNebulaCertificate(
|
||||
res, err := ctx.daemonRPC.CreateNebulaCertificate(
|
||||
ctx, hostName.V, hostPub,
|
||||
)
|
||||
if err != nil {
|
||||
@ -68,8 +70,9 @@ var subCmdNebulaShow = subCmd{
|
||||
name: "show",
|
||||
descr: "Writes nebula network information to stdout in JSON format",
|
||||
do: func(ctx subCmdCtx) error {
|
||||
ctx, err := ctx.withParsedFlags()
|
||||
if err != nil {
|
||||
|
||||
flags := ctx.flagSet(false)
|
||||
if err := flags.Parse(ctx.args); err != nil {
|
||||
return fmt.Errorf("parsing flags: %w", err)
|
||||
}
|
||||
|
||||
@ -78,7 +81,7 @@ var subCmdNebulaShow = subCmd{
|
||||
return fmt.Errorf("getting hosts: %w", err)
|
||||
}
|
||||
|
||||
caPublicCreds, err := newDaemonRPCClient().GetNebulaCAPublicCredentials(ctx)
|
||||
caPublicCreds, err := ctx.daemonRPC.GetNebulaCAPublicCredentials(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("calling GetNebulaCAPublicCredentials: %w", err)
|
||||
}
|
||||
|
@ -5,44 +5,42 @@ import (
|
||||
"fmt"
|
||||
"isle/daemon/network"
|
||||
"isle/jsonutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
var subCmdNetworkCreate = subCmd{
|
||||
name: "create",
|
||||
descr: "Create's a new network, with this host being the first host in that network.",
|
||||
noNetwork: true,
|
||||
do: func(ctx subCmdCtx) error {
|
||||
var (
|
||||
flags = ctx.flagSet(false)
|
||||
ipNet ipNetFlag
|
||||
hostName hostNameFlag
|
||||
)
|
||||
|
||||
name := ctx.flags.StringP(
|
||||
name := flags.StringP(
|
||||
"name", "N", "",
|
||||
"Human-readable name to identify the network as.",
|
||||
)
|
||||
|
||||
domain := ctx.flags.StringP(
|
||||
domain := flags.StringP(
|
||||
"domain", "d", "",
|
||||
"Domain name that should be used as the root domain in the network.",
|
||||
)
|
||||
|
||||
ipNetF := ctx.flags.VarPF(
|
||||
ipNetF := flags.VarPF(
|
||||
&ipNet, "ip-net", "i",
|
||||
`An IP subnet, in CIDR form, which will be the overall range of`+
|
||||
` possible IPs in the network. The first IP in this network`+
|
||||
` range will become this first host's IP.`,
|
||||
)
|
||||
|
||||
hostNameF := ctx.flags.VarPF(
|
||||
hostNameF := flags.VarPF(
|
||||
&hostName,
|
||||
"hostname", "n",
|
||||
"Name of this host, which will be the first host in the network",
|
||||
)
|
||||
|
||||
ctx, err := ctx.withParsedFlags()
|
||||
if err != nil {
|
||||
if err := flags.Parse(ctx.args); err != nil {
|
||||
return fmt.Errorf("parsing flags: %w", err)
|
||||
}
|
||||
|
||||
@ -53,7 +51,7 @@ var subCmdNetworkCreate = subCmd{
|
||||
return errors.New("--name, --domain, --ip-net, and --hostname are required")
|
||||
}
|
||||
|
||||
err = newDaemonRPCClient().CreateNetwork(
|
||||
err := ctx.daemonRPC.CreateNetwork(
|
||||
ctx, *name, *domain, ipNet.V, hostName.V,
|
||||
)
|
||||
if err != nil {
|
||||
@ -67,14 +65,15 @@ var subCmdNetworkCreate = subCmd{
|
||||
var subCmdNetworkJoin = subCmd{
|
||||
name: "join",
|
||||
descr: "Joins this host to an existing network",
|
||||
noNetwork: true,
|
||||
do: func(ctx subCmdCtx) error {
|
||||
bootstrapPath := ctx.flags.StringP(
|
||||
var (
|
||||
flags = ctx.flagSet(false)
|
||||
bootstrapPath = flags.StringP(
|
||||
"bootstrap-path", "b", "", "Path to a bootstrap.json file.",
|
||||
)
|
||||
)
|
||||
|
||||
ctx, err := ctx.withParsedFlags()
|
||||
if err != nil {
|
||||
if err := flags.Parse(ctx.args); err != nil {
|
||||
return fmt.Errorf("parsing flags: %w", err)
|
||||
}
|
||||
|
||||
@ -89,38 +88,17 @@ var subCmdNetworkJoin = subCmd{
|
||||
)
|
||||
}
|
||||
|
||||
return newDaemonRPCClient().JoinNetwork(ctx, newBootstrap)
|
||||
},
|
||||
}
|
||||
|
||||
var subCmdNetworkList = subCmd{
|
||||
name: "list",
|
||||
descr: "Lists all networks which have been joined",
|
||||
noNetwork: true,
|
||||
do: func(ctx subCmdCtx) error {
|
||||
ctx, err := ctx.withParsedFlags()
|
||||
if err != nil {
|
||||
return fmt.Errorf("parsing flags: %w", err)
|
||||
}
|
||||
|
||||
creationParams, err := newDaemonRPCClient().GetNetworks(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getting joined networks: %w", err)
|
||||
}
|
||||
|
||||
return jsonutil.WriteIndented(os.Stdout, creationParams)
|
||||
return ctx.daemonRPC.JoinNetwork(ctx, newBootstrap)
|
||||
},
|
||||
}
|
||||
|
||||
var subCmdNetwork = subCmd{
|
||||
name: "network",
|
||||
descr: "Sub-commands related to network membership",
|
||||
plural: "s",
|
||||
do: func(ctx subCmdCtx) error {
|
||||
return ctx.doSubCmd(
|
||||
subCmdNetworkCreate,
|
||||
subCmdNetworkJoin,
|
||||
subCmdNetworkList,
|
||||
)
|
||||
},
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"isle/daemon"
|
||||
"isle/daemon/jsonrpc2"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@ -13,8 +14,30 @@ import (
|
||||
|
||||
type flagSet struct {
|
||||
*pflag.FlagSet
|
||||
}
|
||||
|
||||
network string
|
||||
func (fs flagSet) Parse(args []string) error {
|
||||
fs.VisitAll(func(f *pflag.Flag) {
|
||||
if f.Shorthand == "h" {
|
||||
panic(fmt.Sprintf("flag %+v has reserved shorthand `-h`", f))
|
||||
}
|
||||
if f.Name == "help" {
|
||||
panic(fmt.Sprintf("flag %+v has reserved name `--help`", f))
|
||||
}
|
||||
})
|
||||
return fs.FlagSet.Parse(args)
|
||||
}
|
||||
|
||||
// subCmdCtx contains all information available to a subCmd's do method.
|
||||
type subCmdCtx struct {
|
||||
context.Context
|
||||
|
||||
subCmd subCmd // the subCmd itself
|
||||
args []string // command-line arguments, excluding the subCmd itself.
|
||||
subCmdNames []string // names of subCmds so far, including this one
|
||||
|
||||
logger *mlog.Logger
|
||||
daemonRPC daemon.RPC
|
||||
}
|
||||
|
||||
type subCmd struct {
|
||||
@ -24,74 +47,11 @@ type subCmd struct {
|
||||
|
||||
// If set then the name will be allowed to be suffixed with this string.
|
||||
plural string
|
||||
|
||||
// noNetwork, if true, means the call doesn't require a network to be
|
||||
// specified on the command-line if there are more than one networks
|
||||
// configured.
|
||||
noNetwork bool
|
||||
|
||||
// Extra arguments on the command-line will be passed through to some
|
||||
// underlying command.
|
||||
passthroughArgs bool
|
||||
}
|
||||
|
||||
// subCmdCtx contains all information available to a subCmd's do method.
|
||||
type subCmdCtx struct {
|
||||
context.Context
|
||||
logger *mlog.Logger
|
||||
func (ctx subCmdCtx) usagePrefix() string {
|
||||
|
||||
subCmd subCmd // the subCmd itself
|
||||
args []string // command-line arguments, excluding the subCmd itself.
|
||||
subCmdNames []string // names of subCmds so far, including this one
|
||||
|
||||
flags flagSet
|
||||
}
|
||||
|
||||
func newSubCmdCtx(
|
||||
ctx context.Context,
|
||||
logger *mlog.Logger,
|
||||
subCmd subCmd,
|
||||
args []string,
|
||||
subCmdNames []string,
|
||||
) subCmdCtx {
|
||||
flags := pflag.NewFlagSet(subCmd.name, pflag.ExitOnError)
|
||||
flags.Usage = func() {
|
||||
var passthroughStr string
|
||||
if subCmd.passthroughArgs {
|
||||
passthroughStr = " [--] [args...]"
|
||||
}
|
||||
|
||||
fmt.Fprintf(
|
||||
os.Stderr, "%s[-h|--help] [%s flags...]%s\n\n",
|
||||
usagePrefix(subCmdNames), subCmd.name, passthroughStr,
|
||||
)
|
||||
fmt.Fprintf(os.Stderr, "%s FLAGS:\n\n", strings.ToUpper(subCmd.name))
|
||||
fmt.Fprintln(os.Stderr, flags.FlagUsages())
|
||||
|
||||
os.Stderr.Sync()
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
fs := flagSet{FlagSet: flags}
|
||||
|
||||
if !subCmd.noNetwork {
|
||||
fs.FlagSet.StringVar(
|
||||
&fs.network, "network", "", "Which network to perform the command against, if more than one is joined. Can be ID, name, or domain",
|
||||
)
|
||||
}
|
||||
|
||||
return subCmdCtx{
|
||||
Context: ctx,
|
||||
logger: logger,
|
||||
subCmd: subCmd,
|
||||
args: args,
|
||||
subCmdNames: subCmdNames,
|
||||
flags: fs,
|
||||
}
|
||||
}
|
||||
|
||||
func usagePrefix(subCmdNames []string) string {
|
||||
subCmdNamesStr := strings.Join(subCmdNames, " ")
|
||||
subCmdNamesStr := strings.Join(ctx.subCmdNames, " ")
|
||||
if subCmdNamesStr != "" {
|
||||
subCmdNamesStr += " "
|
||||
}
|
||||
@ -99,22 +59,26 @@ func usagePrefix(subCmdNames []string) string {
|
||||
return fmt.Sprintf("\nUSAGE: %s %s", os.Args[0], subCmdNamesStr)
|
||||
}
|
||||
|
||||
func (ctx subCmdCtx) withParsedFlags() (subCmdCtx, error) {
|
||||
ctx.flags.VisitAll(func(f *pflag.Flag) {
|
||||
if f.Shorthand == "h" {
|
||||
panic(fmt.Sprintf("flag %+v has reserved shorthand `-h`", f))
|
||||
}
|
||||
if f.Name == "help" {
|
||||
panic(fmt.Sprintf("flag %+v has reserved name `--help`", f))
|
||||
}
|
||||
})
|
||||
func (ctx subCmdCtx) flagSet(withPassthrough bool) flagSet {
|
||||
flags := pflag.NewFlagSet(ctx.subCmd.name, pflag.ExitOnError)
|
||||
flags.Usage = func() {
|
||||
|
||||
if err := ctx.flags.Parse(ctx.args); err != nil {
|
||||
return ctx, err
|
||||
var passthroughStr string
|
||||
if withPassthrough {
|
||||
passthroughStr = " [--] [args...]"
|
||||
}
|
||||
|
||||
ctx.Context = daemon.WithNetwork(ctx.Context, ctx.flags.network)
|
||||
return ctx, nil
|
||||
fmt.Fprintf(
|
||||
os.Stderr, "%s[-h|--help] [%s flags...]%s\n\n",
|
||||
ctx.usagePrefix(), ctx.subCmd.name, passthroughStr,
|
||||
)
|
||||
fmt.Fprintf(os.Stderr, "%s FLAGS:\n\n", strings.ToUpper(ctx.subCmd.name))
|
||||
fmt.Fprintln(os.Stderr, flags.FlagUsages())
|
||||
|
||||
os.Stderr.Sync()
|
||||
os.Exit(2)
|
||||
}
|
||||
return flagSet{flags}
|
||||
}
|
||||
|
||||
func (ctx subCmdCtx) doSubCmd(subCmds ...subCmd) error {
|
||||
@ -126,7 +90,7 @@ func (ctx subCmdCtx) doSubCmd(subCmds ...subCmd) error {
|
||||
fmt.Fprintf(
|
||||
os.Stderr,
|
||||
"%s<subCmd> [-h|--help] [sub-command flags...]\n",
|
||||
usagePrefix(ctx.subCmdNames),
|
||||
ctx.usagePrefix(),
|
||||
)
|
||||
|
||||
fmt.Fprintf(os.Stderr, "\nSUB-COMMANDS:\n\n")
|
||||
@ -159,21 +123,28 @@ func (ctx subCmdCtx) doSubCmd(subCmds ...subCmd) error {
|
||||
}
|
||||
|
||||
subCmdName, args := args[0], args[1:]
|
||||
|
||||
subCmd, ok := subCmdsMap[subCmdName]
|
||||
|
||||
if !ok {
|
||||
printUsageExit(subCmdName)
|
||||
}
|
||||
|
||||
nextSubCmdCtx := newSubCmdCtx(
|
||||
ctx.Context,
|
||||
ctx.logger,
|
||||
subCmd,
|
||||
args,
|
||||
append(ctx.subCmdNames, subCmdName),
|
||||
daemonRPC := daemon.RPCFromClient(
|
||||
jsonrpc2.NewUnixHTTPClient(
|
||||
daemon.HTTPSocketPath(), daemonHTTPRPCPath,
|
||||
),
|
||||
)
|
||||
|
||||
if err := subCmd.do(nextSubCmdCtx); err != nil {
|
||||
err := subCmd.do(subCmdCtx{
|
||||
Context: ctx.Context,
|
||||
subCmd: subCmd,
|
||||
args: args,
|
||||
subCmdNames: append(ctx.subCmdNames, subCmdName),
|
||||
logger: ctx.logger,
|
||||
daemonRPC: daemonRPC,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
var subCmdVersion = subCmd{
|
||||
name: "version",
|
||||
descr: "Dumps version and build info to stdout",
|
||||
noNetwork: true,
|
||||
do: func(ctx subCmdCtx) error {
|
||||
|
||||
versionPath := filepath.Join(envAppDirPath, "share/version")
|
||||
|
@ -49,7 +49,7 @@ func (o *Opts) withDefaults() *Opts {
|
||||
// - garage (0 or more, depending on configured storage allocations)
|
||||
type Children struct {
|
||||
logger *mlog.Logger
|
||||
networkConfig daecommon.NetworkConfig
|
||||
daemonConfig daecommon.Config
|
||||
runtimeDir toolkit.Dir
|
||||
opts Opts
|
||||
|
||||
@ -63,7 +63,7 @@ func New(
|
||||
logger *mlog.Logger,
|
||||
binDirPath string,
|
||||
secretsStore secrets.Store,
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
runtimeDir toolkit.Dir,
|
||||
garageAdminToken string,
|
||||
hostBootstrap bootstrap.Bootstrap,
|
||||
@ -81,7 +81,7 @@ func New(
|
||||
|
||||
c := &Children{
|
||||
logger: logger,
|
||||
networkConfig: networkConfig,
|
||||
daemonConfig: daemonConfig,
|
||||
runtimeDir: runtimeDir,
|
||||
opts: *opts,
|
||||
}
|
||||
@ -90,7 +90,7 @@ func New(
|
||||
ctx,
|
||||
garageRPCSecret,
|
||||
binDirPath,
|
||||
networkConfig,
|
||||
daemonConfig,
|
||||
garageAdminToken,
|
||||
hostBootstrap,
|
||||
)
|
||||
@ -101,7 +101,7 @@ func New(
|
||||
c.pmux = pmuxlib.NewPmux(pmuxConfig, c.opts.Stdout, c.opts.Stderr)
|
||||
|
||||
initErr := c.postPmuxInit(
|
||||
ctx, networkConfig, garageAdminToken, hostBootstrap,
|
||||
ctx, daemonConfig, garageAdminToken, hostBootstrap,
|
||||
)
|
||||
if initErr != nil {
|
||||
logger.Warn(ctx, "failed to initialize Children, shutting down child processes", err)
|
||||
@ -118,7 +118,7 @@ func New(
|
||||
// successfully.
|
||||
func (c *Children) RestartDNSMasq(hostBootstrap bootstrap.Bootstrap) error {
|
||||
_, err := dnsmasqWriteConfig(
|
||||
c.runtimeDir.Path, c.networkConfig, hostBootstrap,
|
||||
c.runtimeDir.Path, c.daemonConfig, hostBootstrap,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("writing new dnsmasq config: %w", err)
|
||||
@ -134,7 +134,7 @@ func (c *Children) RestartDNSMasq(hostBootstrap bootstrap.Bootstrap) error {
|
||||
// successfully.
|
||||
func (c *Children) RestartNebula(hostBootstrap bootstrap.Bootstrap) error {
|
||||
_, err := nebulaWriteConfig(
|
||||
c.runtimeDir.Path, c.networkConfig, hostBootstrap,
|
||||
c.runtimeDir.Path, c.daemonConfig, hostBootstrap,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("writing a new nebula config: %w", err)
|
||||
|
@ -18,14 +18,14 @@ type ReloadDiff struct {
|
||||
// CalculateReloadDiff calculates a ReloadDiff based on an old and new
|
||||
// bootstrap.
|
||||
func CalculateReloadDiff(
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
prevBootstrap, nextBootstrap bootstrap.Bootstrap,
|
||||
) (
|
||||
diff ReloadDiff, err error,
|
||||
) {
|
||||
{
|
||||
prevNebulaConfig, prevErr := nebulaConfig(networkConfig, prevBootstrap)
|
||||
nextNebulaConfig, nextErr := nebulaConfig(networkConfig, nextBootstrap)
|
||||
prevNebulaConfig, prevErr := nebulaConfig(daemonConfig, prevBootstrap)
|
||||
nextNebulaConfig, nextErr := nebulaConfig(daemonConfig, nextBootstrap)
|
||||
if err = errors.Join(prevErr, nextErr); err != nil {
|
||||
err = fmt.Errorf("calculating nebula config: %w", err)
|
||||
return
|
||||
@ -38,8 +38,8 @@ func CalculateReloadDiff(
|
||||
|
||||
{
|
||||
diff.DNSChanged = !reflect.DeepEqual(
|
||||
dnsmasqConfig(networkConfig, prevBootstrap),
|
||||
dnsmasqConfig(networkConfig, nextBootstrap),
|
||||
dnsmasqConfig(daemonConfig, prevBootstrap),
|
||||
dnsmasqConfig(daemonConfig, nextBootstrap),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func dnsmasqConfig(
|
||||
networkConfig daecommon.NetworkConfig, hostBootstrap bootstrap.Bootstrap,
|
||||
daemonConfig daecommon.Config, hostBootstrap bootstrap.Bootstrap,
|
||||
) dnsmasq.ConfData {
|
||||
hostsSlice := make([]dnsmasq.ConfDataHost, 0, len(hostBootstrap.Hosts))
|
||||
for _, host := range hostBootstrap.Hosts {
|
||||
@ -29,7 +29,7 @@ func dnsmasqConfig(
|
||||
})
|
||||
|
||||
return dnsmasq.ConfData{
|
||||
Resolvers: networkConfig.DNS.Resolvers,
|
||||
Resolvers: daemonConfig.DNS.Resolvers,
|
||||
Domain: hostBootstrap.NetworkCreationParams.Domain,
|
||||
IP: hostBootstrap.ThisHost().IP().String(),
|
||||
Hosts: hostsSlice,
|
||||
@ -38,14 +38,14 @@ func dnsmasqConfig(
|
||||
|
||||
func dnsmasqWriteConfig(
|
||||
runtimeDirPath string,
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
hostBootstrap bootstrap.Bootstrap,
|
||||
) (
|
||||
string, error,
|
||||
) {
|
||||
var (
|
||||
confPath = filepath.Join(runtimeDirPath, "dnsmasq.conf")
|
||||
confData = dnsmasqConfig(networkConfig, hostBootstrap)
|
||||
confData = dnsmasqConfig(daemonConfig, hostBootstrap)
|
||||
)
|
||||
|
||||
if err := dnsmasq.WriteConfFile(confPath, confData); err != nil {
|
||||
@ -58,13 +58,13 @@ func dnsmasqWriteConfig(
|
||||
func dnsmasqPmuxProcConfig(
|
||||
logger *mlog.Logger,
|
||||
runtimeDirPath, binDirPath string,
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
hostBootstrap bootstrap.Bootstrap,
|
||||
) (
|
||||
pmuxlib.ProcessConfig, error,
|
||||
) {
|
||||
confPath, err := dnsmasqWriteConfig(
|
||||
runtimeDirPath, networkConfig, hostBootstrap,
|
||||
runtimeDirPath, daemonConfig, hostBootstrap,
|
||||
)
|
||||
if err != nil {
|
||||
return pmuxlib.ProcessConfig{}, fmt.Errorf(
|
||||
|
@ -23,12 +23,12 @@ func garageAdminClientLogger(logger *mlog.Logger) *mlog.Logger {
|
||||
func waitForGarage(
|
||||
ctx context.Context,
|
||||
logger *mlog.Logger,
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
adminToken string,
|
||||
hostBootstrap bootstrap.Bootstrap,
|
||||
) error {
|
||||
|
||||
allocs := networkConfig.Storage.Allocations
|
||||
allocs := daemonConfig.Storage.Allocations
|
||||
|
||||
// if this host doesn't have any allocations specified then fall back to
|
||||
// waiting for nebula
|
||||
@ -108,7 +108,7 @@ func garagePmuxProcConfigs(
|
||||
ctx context.Context,
|
||||
logger *mlog.Logger,
|
||||
rpcSecret, runtimeDirPath, binDirPath string,
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
adminToken string,
|
||||
hostBootstrap bootstrap.Bootstrap,
|
||||
) (
|
||||
@ -116,7 +116,7 @@ func garagePmuxProcConfigs(
|
||||
) {
|
||||
var (
|
||||
pmuxProcConfigs = map[string]pmuxlib.ProcessConfig{}
|
||||
allocs = networkConfig.Storage.Allocations
|
||||
allocs = daemonConfig.Storage.Allocations
|
||||
)
|
||||
|
||||
if len(allocs) > 0 && rpcSecret == "" {
|
||||
|
@ -48,7 +48,7 @@ func waitForNebula(
|
||||
}
|
||||
|
||||
func nebulaConfig(
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
hostBootstrap bootstrap.Bootstrap,
|
||||
) (
|
||||
map[string]any, error,
|
||||
@ -95,12 +95,12 @@ func nebulaConfig(
|
||||
"respond": true,
|
||||
},
|
||||
"tun": map[string]any{
|
||||
"dev": networkConfig.VPN.Tun.Device,
|
||||
"dev": daemonConfig.VPN.Tun.Device,
|
||||
},
|
||||
"firewall": networkConfig.VPN.Firewall,
|
||||
"firewall": daemonConfig.VPN.Firewall,
|
||||
}
|
||||
|
||||
if publicAddr := networkConfig.VPN.PublicAddr; publicAddr == "" {
|
||||
if publicAddr := daemonConfig.VPN.PublicAddr; publicAddr == "" {
|
||||
|
||||
config["listen"] = map[string]string{
|
||||
"host": "0.0.0.0",
|
||||
@ -137,12 +137,12 @@ func nebulaConfig(
|
||||
|
||||
func nebulaWriteConfig(
|
||||
runtimeDirPath string,
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
hostBootstrap bootstrap.Bootstrap,
|
||||
) (
|
||||
string, error,
|
||||
) {
|
||||
config, err := nebulaConfig(networkConfig, hostBootstrap)
|
||||
config, err := nebulaConfig(daemonConfig, hostBootstrap)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("creating nebula config: %w", err)
|
||||
}
|
||||
@ -158,12 +158,12 @@ func nebulaWriteConfig(
|
||||
|
||||
func nebulaPmuxProcConfig(
|
||||
runtimeDirPath, binDirPath string,
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
hostBootstrap bootstrap.Bootstrap,
|
||||
) (
|
||||
pmuxlib.ProcessConfig, error,
|
||||
) {
|
||||
config, err := nebulaConfig(networkConfig, hostBootstrap)
|
||||
config, err := nebulaConfig(daemonConfig, hostBootstrap)
|
||||
if err != nil {
|
||||
return pmuxlib.ProcessConfig{}, fmt.Errorf(
|
||||
"creating nebula config: %w", err,
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
func (c *Children) newPmuxConfig(
|
||||
ctx context.Context,
|
||||
garageRPCSecret, binDirPath string,
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
garageAdminToken string,
|
||||
hostBootstrap bootstrap.Bootstrap,
|
||||
) (
|
||||
@ -21,7 +21,7 @@ func (c *Children) newPmuxConfig(
|
||||
nebulaPmuxProcConfig, err := nebulaPmuxProcConfig(
|
||||
c.runtimeDir.Path,
|
||||
binDirPath,
|
||||
networkConfig,
|
||||
daemonConfig,
|
||||
hostBootstrap,
|
||||
)
|
||||
if err != nil {
|
||||
@ -32,7 +32,7 @@ func (c *Children) newPmuxConfig(
|
||||
c.logger,
|
||||
c.runtimeDir.Path,
|
||||
binDirPath,
|
||||
networkConfig,
|
||||
daemonConfig,
|
||||
hostBootstrap,
|
||||
)
|
||||
if err != nil {
|
||||
@ -47,7 +47,7 @@ func (c *Children) newPmuxConfig(
|
||||
garageRPCSecret,
|
||||
c.runtimeDir.Path,
|
||||
binDirPath,
|
||||
networkConfig,
|
||||
daemonConfig,
|
||||
garageAdminToken,
|
||||
hostBootstrap,
|
||||
)
|
||||
@ -68,7 +68,7 @@ func (c *Children) newPmuxConfig(
|
||||
|
||||
func (c *Children) postPmuxInit(
|
||||
ctx context.Context,
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
garageAdminToken string,
|
||||
hostBootstrap bootstrap.Bootstrap,
|
||||
) error {
|
||||
@ -79,7 +79,7 @@ func (c *Children) postPmuxInit(
|
||||
|
||||
c.logger.Info(ctx, "Waiting for garage instances to come online")
|
||||
err := waitForGarage(
|
||||
ctx, c.logger, networkConfig, garageAdminToken, hostBootstrap,
|
||||
ctx, c.logger, daemonConfig, garageAdminToken, hostBootstrap,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("waiting for garage to start: %w", err)
|
||||
|
@ -86,15 +86,6 @@ func (c *rpcClient) GetNebulaCAPublicCredentials(ctx context.Context) (c2 nebula
|
||||
return
|
||||
}
|
||||
|
||||
func (c *rpcClient) GetNetworks(ctx context.Context) (ca1 []bootstrap.CreationParams, err error) {
|
||||
err = c.client.Call(
|
||||
ctx,
|
||||
&ca1,
|
||||
"GetNetworks",
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *rpcClient) JoinNetwork(ctx context.Context, j1 network.JoiningBootstrap) (err error) {
|
||||
err = c.client.Call(
|
||||
ctx,
|
||||
|
@ -4,8 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"isle/bootstrap"
|
||||
"isle/daemon/daecommon"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
@ -42,26 +40,6 @@ var HTTPSocketPath = sync.OnceValue(func() string {
|
||||
)
|
||||
})
|
||||
|
||||
func pickNetworkConfig(
|
||||
daemonConfig daecommon.Config, creationParams bootstrap.CreationParams,
|
||||
) (
|
||||
daecommon.NetworkConfig, bool,
|
||||
) {
|
||||
if len(daemonConfig.Networks) == 1 { // DEPRECATED
|
||||
if c, ok := daemonConfig.Networks[daecommon.DeprecatedNetworkID]; ok {
|
||||
return c, true
|
||||
}
|
||||
}
|
||||
|
||||
for searchStr, networkConfig := range daemonConfig.Networks {
|
||||
if creationParams.Matches(searchStr) {
|
||||
return networkConfig, true
|
||||
}
|
||||
}
|
||||
|
||||
return daecommon.NetworkConfig{}, false
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Jigs
|
||||
|
||||
|
@ -1,20 +0,0 @@
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"isle/daemon/jsonrpc2"
|
||||
)
|
||||
|
||||
const metaKeyNetworkSearchStr = "daemon.networkSearchStr"
|
||||
|
||||
// WithNetwork returns the Context so that, when used against a daemon RPC
|
||||
// endpoint, the endpoint knows which network is being targetted for the call.
|
||||
// The network can be identified by its ID, name, or domain.
|
||||
func WithNetwork(ctx context.Context, searchStr string) context.Context {
|
||||
return jsonrpc2.WithMeta(ctx, metaKeyNetworkSearchStr, searchStr)
|
||||
}
|
||||
|
||||
func getNetworkSearchStr(ctx context.Context) string {
|
||||
v, _ := jsonrpc2.GetMeta(ctx)[metaKeyNetworkSearchStr].(string)
|
||||
return v
|
||||
}
|
@ -4,21 +4,15 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"isle/bootstrap"
|
||||
"isle/toolkit"
|
||||
"net"
|
||||
"isle/yamlutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
const (
|
||||
// Network ID used when translating from the old single-network daemon
|
||||
// config to the multi-network config.
|
||||
DeprecatedNetworkID = "_" // DEPRECATED
|
||||
)
|
||||
|
||||
func defaultConfigPath(appDirPath string) string {
|
||||
return filepath.Join(appDirPath, "etc", "daemon.yml")
|
||||
}
|
||||
@ -28,10 +22,18 @@ type ConfigTun struct {
|
||||
}
|
||||
|
||||
type ConfigFirewall struct {
|
||||
Conntrack ConfigConntrack `yaml:"conntrack"`
|
||||
Outbound []ConfigFirewallRule `yaml:"outbound"`
|
||||
Inbound []ConfigFirewallRule `yaml:"inbound"`
|
||||
}
|
||||
|
||||
type ConfigConntrack struct {
|
||||
TCPTimeout string `yaml:"tcp_timeout"`
|
||||
UDPTimeout string `yaml:"udp_timeout"`
|
||||
DefaultTimeout string `yaml:"default_timeout"`
|
||||
MaxConnections int `yaml:"max_connections"`
|
||||
}
|
||||
|
||||
type ConfigFirewallRule struct {
|
||||
Port string `yaml:"port,omitempty"`
|
||||
Code string `yaml:"code,omitempty"`
|
||||
@ -59,8 +61,8 @@ type ConfigStorageAllocation struct {
|
||||
Zone string `yaml:"zone"`
|
||||
}
|
||||
|
||||
// NetworkConfig describes the configuration of a single network.
|
||||
type NetworkConfig struct {
|
||||
// Config describes the structure of the daemon config file.
|
||||
type Config struct {
|
||||
DNS struct {
|
||||
Resolvers []string `yaml:"resolvers"`
|
||||
} `yaml:"dns"`
|
||||
@ -74,37 +76,7 @@ type NetworkConfig struct {
|
||||
} `yaml:"storage"`
|
||||
}
|
||||
|
||||
func (c *NetworkConfig) fillDefaults() {
|
||||
if c.DNS.Resolvers == nil {
|
||||
c.DNS.Resolvers = []string{
|
||||
"1.1.1.1",
|
||||
"8.8.8.8",
|
||||
}
|
||||
}
|
||||
|
||||
if c.VPN.Firewall.Outbound == nil {
|
||||
c.VPN.Firewall.Outbound = []ConfigFirewallRule{
|
||||
{
|
||||
Port: "any",
|
||||
Proto: "any",
|
||||
Host: "any",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if c.VPN.Firewall.Inbound == nil {
|
||||
c.VPN.Firewall.Inbound = []ConfigFirewallRule{
|
||||
{
|
||||
Port: "any",
|
||||
Proto: "icmp",
|
||||
Host: "any",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if c.VPN.Tun.Device == "" {
|
||||
c.VPN.Tun.Device = "isle-tun"
|
||||
}
|
||||
func (c *Config) fillDefaults() {
|
||||
|
||||
var firewallGarageInbound []ConfigFirewallRule
|
||||
|
||||
@ -144,40 +116,6 @@ func (c *NetworkConfig) fillDefaults() {
|
||||
)
|
||||
}
|
||||
|
||||
// Config describes the structure of the daemon config file.
|
||||
type Config struct {
|
||||
Networks map[string]NetworkConfig `yaml:"networks"`
|
||||
}
|
||||
|
||||
// Validate asserts that the Config has no internal inconsistencies which would
|
||||
// render it unusable.
|
||||
func (c Config) Validate() error {
|
||||
nebulaPorts := map[string]string{}
|
||||
|
||||
for id, network := range c.Networks {
|
||||
if network.VPN.PublicAddr == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
_, port, err := net.SplitHostPort(network.VPN.PublicAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"invalid vpn.public_addr %q: %w", network.VPN.PublicAddr, err,
|
||||
)
|
||||
} else if otherID, ok := nebulaPorts[port]; ok {
|
||||
return fmt.Errorf(
|
||||
"two networks with the same vpn.public_addr: %q and %q",
|
||||
id,
|
||||
otherID,
|
||||
)
|
||||
}
|
||||
|
||||
nebulaPorts[port] = id
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CopyDefaultConfig copies the daemon config file embedded in the AppDir into
|
||||
// the given io.Writer.
|
||||
func CopyDefaultConfig(into io.Writer, appDirPath string) error {
|
||||
@ -198,45 +136,51 @@ func CopyDefaultConfig(into io.Writer, appDirPath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadConfig loads the daemon config from userConfigPath.
|
||||
// LoadConfig loads the daemon config from userConfigPath, merges it with
|
||||
// the default found in the appDirPath, and returns the result.
|
||||
//
|
||||
// If userConfigPath is not given then the default is loaded and returned.
|
||||
func LoadConfig(userConfigPath string) (Config, error) {
|
||||
if userConfigPath == "" {
|
||||
return Config{}, nil
|
||||
func LoadConfig(
|
||||
appDirPath, userConfigPath string,
|
||||
) (
|
||||
Config, error,
|
||||
) {
|
||||
|
||||
defaultConfigPath := defaultConfigPath(appDirPath)
|
||||
|
||||
var fullDaemon map[string]interface{}
|
||||
|
||||
if err := yamlutil.LoadYamlFile(&fullDaemon, defaultConfigPath); err != nil {
|
||||
return Config{}, fmt.Errorf("parsing default daemon config file: %w", err)
|
||||
}
|
||||
|
||||
userConfigB, err := os.ReadFile(userConfigPath)
|
||||
if userConfigPath != "" {
|
||||
|
||||
var daemonConfig map[string]interface{}
|
||||
if err := yamlutil.LoadYamlFile(&daemonConfig, userConfigPath); err != nil {
|
||||
return Config{}, fmt.Errorf("parsing %q: %w", userConfigPath, err)
|
||||
}
|
||||
|
||||
err := mergo.Merge(&fullDaemon, daemonConfig, mergo.WithOverride)
|
||||
if err != nil {
|
||||
return Config{}, fmt.Errorf("reading from file: %w", err)
|
||||
return Config{}, fmt.Errorf("merging contents of file %q: %w", userConfigPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
{ // DEPRECATED
|
||||
var networkConfig NetworkConfig
|
||||
_ = yaml.Unmarshal(userConfigB, &networkConfig)
|
||||
if !toolkit.IsZero(networkConfig) {
|
||||
networkConfig.fillDefaults()
|
||||
config := Config{
|
||||
Networks: map[string]NetworkConfig{
|
||||
DeprecatedNetworkID: networkConfig,
|
||||
},
|
||||
}
|
||||
return config, config.Validate()
|
||||
}
|
||||
fullDaemonB, err := yaml.Marshal(fullDaemon)
|
||||
|
||||
if err != nil {
|
||||
return Config{}, fmt.Errorf("yaml marshaling: %w", err)
|
||||
}
|
||||
|
||||
var config Config
|
||||
if err := yaml.Unmarshal(userConfigB, &config); err != nil {
|
||||
if err := yaml.Unmarshal(fullDaemonB, &config); err != nil {
|
||||
return Config{}, fmt.Errorf("yaml unmarshaling back into Config struct: %w", err)
|
||||
}
|
||||
|
||||
for id := range config.Networks {
|
||||
network := config.Networks[id]
|
||||
network.fillDefaults()
|
||||
config.Networks[id] = network
|
||||
}
|
||||
config.fillDefaults()
|
||||
|
||||
return config, config.Validate()
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// BootstrapGarageHostForAlloc returns the bootstrap.GarageHostInstance which
|
||||
|
@ -4,7 +4,6 @@ package daemon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"isle/bootstrap"
|
||||
"isle/daemon/children"
|
||||
@ -12,7 +11,6 @@ import (
|
||||
"isle/daemon/network"
|
||||
"isle/nebula"
|
||||
"isle/toolkit"
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
"dev.mediocregopher.com/mediocre-go-lib.git/mctx"
|
||||
@ -67,7 +65,7 @@ type Daemon struct {
|
||||
networksRuntimeDir toolkit.Dir
|
||||
|
||||
l sync.RWMutex
|
||||
networks map[string]network.Network
|
||||
network network.Network
|
||||
}
|
||||
|
||||
// New initializes and returns a Daemon.
|
||||
@ -80,24 +78,11 @@ func New(
|
||||
) (
|
||||
*Daemon, error,
|
||||
) {
|
||||
opts = opts.withDefaults()
|
||||
|
||||
if err := migrateToMultiNetworkStateDirectory(
|
||||
ctx,
|
||||
logger.WithNamespace("migration-multi-network-state-dir"),
|
||||
opts.EnvVars,
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"migrating to multi-network state directory: %w", err,
|
||||
)
|
||||
}
|
||||
|
||||
d := &Daemon{
|
||||
logger: logger,
|
||||
daemonConfig: daemonConfig,
|
||||
envBinDirPath: envBinDirPath,
|
||||
opts: opts,
|
||||
networks: map[string]network.Network{},
|
||||
opts: opts.withDefaults(),
|
||||
}
|
||||
|
||||
{
|
||||
@ -115,14 +100,18 @@ func New(
|
||||
}
|
||||
}
|
||||
|
||||
loadableNetworks, err := loadableNetworks(d.networksStateDir)
|
||||
loadableNetworks, err := LoadableNetworks(d.networksStateDir)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("listing loadable networks: %w", err)
|
||||
}
|
||||
|
||||
for _, creationParams := range loadableNetworks {
|
||||
id := creationParams.ID
|
||||
ctx = mctx.WithAnnotator(ctx, creationParams)
|
||||
if len(loadableNetworks) > 1 {
|
||||
return nil, fmt.Errorf(
|
||||
"more then one loadable Network found: %+v", loadableNetworks,
|
||||
)
|
||||
} else if len(loadableNetworks) == 1 {
|
||||
id := loadableNetworks[0].ID
|
||||
ctx = mctx.WithAnnotator(ctx, loadableNetworks[0])
|
||||
|
||||
networkStateDir, networkRuntimeDir, err := networkDirs(
|
||||
d.networksStateDir, d.networksRuntimeDir, id, true,
|
||||
@ -133,13 +122,11 @@ func New(
|
||||
)
|
||||
}
|
||||
|
||||
networkConfig, _ := pickNetworkConfig(daemonConfig, creationParams)
|
||||
|
||||
d.networks[id], err = network.Load(
|
||||
d.network, err = network.Load(
|
||||
ctx,
|
||||
logger.WithNamespace("network"),
|
||||
id,
|
||||
networkConfig,
|
||||
d.daemonConfig,
|
||||
d.envBinDirPath,
|
||||
networkStateDir,
|
||||
networkRuntimeDir,
|
||||
@ -175,19 +162,10 @@ func (d *Daemon) CreateNetwork(
|
||||
creationParams := bootstrap.NewCreationParams(name, domain)
|
||||
ctx = mctx.WithAnnotator(ctx, creationParams)
|
||||
|
||||
networkConfig, ok := pickNetworkConfig(
|
||||
d.daemonConfig, creationParams,
|
||||
)
|
||||
if !ok {
|
||||
return errors.New("couldn't find network config for network being created")
|
||||
}
|
||||
|
||||
d.l.Lock()
|
||||
defer d.l.Unlock()
|
||||
|
||||
if joined, err := alreadyJoined(ctx, d.networks, creationParams); err != nil {
|
||||
return fmt.Errorf("checking if already joined to network: %w", err)
|
||||
} else if joined {
|
||||
if d.network != nil {
|
||||
return ErrAlreadyJoined
|
||||
}
|
||||
|
||||
@ -206,7 +184,7 @@ func (d *Daemon) CreateNetwork(
|
||||
n, err := network.Create(
|
||||
ctx,
|
||||
d.logger.WithNamespace("network"),
|
||||
networkConfig,
|
||||
d.daemonConfig,
|
||||
d.envBinDirPath,
|
||||
networkStateDir,
|
||||
networkRuntimeDir,
|
||||
@ -222,7 +200,7 @@ func (d *Daemon) CreateNetwork(
|
||||
}
|
||||
|
||||
d.logger.Info(ctx, "Network created successfully")
|
||||
d.networks[creationParams.ID] = n
|
||||
d.network = n
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -234,20 +212,13 @@ func (d *Daemon) CreateNetwork(
|
||||
func (d *Daemon) JoinNetwork(
|
||||
ctx context.Context, newBootstrap network.JoiningBootstrap,
|
||||
) error {
|
||||
var (
|
||||
creationParams = newBootstrap.Bootstrap.NetworkCreationParams
|
||||
networkConfig, _ = pickNetworkConfig(d.daemonConfig, creationParams)
|
||||
networkID = creationParams.ID
|
||||
)
|
||||
|
||||
networkID := newBootstrap.Bootstrap.NetworkCreationParams.ID
|
||||
ctx = mctx.WithAnnotator(ctx, newBootstrap.Bootstrap.NetworkCreationParams)
|
||||
|
||||
d.l.Lock()
|
||||
defer d.l.Unlock()
|
||||
|
||||
if joined, err := alreadyJoined(ctx, d.networks, creationParams); err != nil {
|
||||
return fmt.Errorf("checking if already joined to network: %w", err)
|
||||
} else if joined {
|
||||
if d.network != nil {
|
||||
return ErrAlreadyJoined
|
||||
}
|
||||
|
||||
@ -264,7 +235,7 @@ func (d *Daemon) JoinNetwork(
|
||||
n, err := network.Join(
|
||||
ctx,
|
||||
d.logger.WithNamespace("network"),
|
||||
networkConfig,
|
||||
d.daemonConfig,
|
||||
newBootstrap,
|
||||
d.envBinDirPath,
|
||||
networkStateDir,
|
||||
@ -280,7 +251,7 @@ func (d *Daemon) JoinNetwork(
|
||||
}
|
||||
|
||||
d.logger.Info(ctx, "Network joined successfully")
|
||||
d.networks[networkID] = n
|
||||
d.network = n
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -294,42 +265,12 @@ func withNetwork[Res any](
|
||||
d.l.RLock()
|
||||
defer d.l.RUnlock()
|
||||
|
||||
network, err := pickNetwork(ctx, d.networks, d.networksStateDir)
|
||||
if err != nil {
|
||||
if d.network == nil {
|
||||
var zero Res
|
||||
return zero, nil
|
||||
return zero, ErrNoNetwork
|
||||
}
|
||||
|
||||
return fn(ctx, network)
|
||||
}
|
||||
|
||||
// GetNetworks returns all networks which have been joined by the Daemon,
|
||||
// ordered by their name.
|
||||
func (d *Daemon) GetNetworks(
|
||||
ctx context.Context,
|
||||
) (
|
||||
[]bootstrap.CreationParams, error,
|
||||
) {
|
||||
d.l.RLock()
|
||||
defer d.l.RUnlock()
|
||||
|
||||
res := make([]bootstrap.CreationParams, 0, len(d.networks))
|
||||
for id, network := range d.networks {
|
||||
creationParams, err := network.GetNetworkCreationParams(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"getting network creation params of network %q: %w", id, err,
|
||||
)
|
||||
}
|
||||
|
||||
res = append(res, creationParams)
|
||||
}
|
||||
|
||||
sort.Slice(res, func(i, j int) bool {
|
||||
return res[i].Name < res[j].Name
|
||||
})
|
||||
|
||||
return res, nil
|
||||
return fn(ctx, d.network)
|
||||
}
|
||||
|
||||
// GetHost implements the method for the network.RPC interface.
|
||||
@ -449,28 +390,32 @@ func (d *Daemon) Shutdown() error {
|
||||
d.l.Lock()
|
||||
defer d.l.Unlock()
|
||||
|
||||
var (
|
||||
errCh = make(chan error, len(d.networks))
|
||||
errs []error
|
||||
)
|
||||
|
||||
for id := range d.networks {
|
||||
var (
|
||||
id = id
|
||||
n = d.networks[id]
|
||||
)
|
||||
|
||||
go func() {
|
||||
if err := n.Shutdown(); err != nil {
|
||||
errCh <- fmt.Errorf("shutting down network %q: %w", id, err)
|
||||
}
|
||||
errCh <- nil
|
||||
}()
|
||||
if d.network != nil {
|
||||
return d.network.Shutdown()
|
||||
}
|
||||
return nil
|
||||
|
||||
for range cap(errCh) {
|
||||
errs = append(errs, <-errCh)
|
||||
}
|
||||
//var (
|
||||
// errCh = make(chan error, len(d.networks))
|
||||
// errs []error
|
||||
//)
|
||||
|
||||
return errors.Join(errs...)
|
||||
//for id := range d.networks {
|
||||
// id := id
|
||||
// n := d.networks[id]
|
||||
// go func() {
|
||||
// if err := n.Shutdown(); err != nil {
|
||||
// errCh <- fmt.Errorf("shutting down network %q: %w", id, err)
|
||||
// }
|
||||
// errCh <- nil
|
||||
// }()
|
||||
//}
|
||||
|
||||
//for range cap(errCh) {
|
||||
// if err := <-errCh; err != nil {
|
||||
// errs = append(errs, err)
|
||||
// }
|
||||
//}
|
||||
|
||||
//return errors.Join(errs...)
|
||||
}
|
||||
|
@ -8,8 +8,6 @@ import (
|
||||
const (
|
||||
errCodeNoNetwork = daecommon.ErrorCodeRangeDaemon + iota
|
||||
errCodeAlreadyJoined
|
||||
errCodeNoMatchingNetworks
|
||||
errCodeMultipleMatchingNetworks
|
||||
)
|
||||
|
||||
var (
|
||||
@ -18,19 +16,6 @@ var (
|
||||
ErrNoNetwork = jsonrpc2.NewError(errCodeNoNetwork, "No network configured")
|
||||
|
||||
// ErrAlreadyJoined is returned when the daemon is instructed to create or
|
||||
// join a new network, but it is already joined to that network.
|
||||
// join a new network, but it is already joined to a network.
|
||||
ErrAlreadyJoined = jsonrpc2.NewError(errCodeAlreadyJoined, "Already joined to a network")
|
||||
|
||||
// ErrNoMatchingNetworks is returned if the search string didn't match any
|
||||
// networks.
|
||||
ErrNoMatchingNetworks = jsonrpc2.NewError(
|
||||
errCodeNoMatchingNetworks, "No networks matched the search string",
|
||||
)
|
||||
|
||||
// ErrMultipleMatchingNetworks is returned if the search string matched
|
||||
// multiple networks.
|
||||
ErrMultipleMatchingNetworks = jsonrpc2.NewError(
|
||||
errCodeMultipleMatchingNetworks,
|
||||
"Multiple networks matched the search string",
|
||||
)
|
||||
)
|
||||
|
@ -13,11 +13,7 @@ type Client interface {
|
||||
// receiver pointer, unless it is nil in which case the result will be
|
||||
// discarded.
|
||||
//
|
||||
// If the Context was produced using WithMeta then that metadata will be
|
||||
// carried with the request to the server via the Meta field of the
|
||||
// RequestParams.
|
||||
//
|
||||
// If an error result is returned from the server that will be returned as
|
||||
// an Error struct.
|
||||
Call(ctx context.Context, rcv any, method string, args ...any) error
|
||||
Call(ctx context.Context, rcv any, method string, params ...any) error
|
||||
}
|
||||
|
@ -49,14 +49,14 @@ func NewUnixHTTPClient(unixSocketPath, reqPath string) Client {
|
||||
}
|
||||
|
||||
func (c *httpClient) Call(
|
||||
ctx context.Context, rcv any, method string, args ...any,
|
||||
ctx context.Context, rcv any, method string, params ...any,
|
||||
) error {
|
||||
var (
|
||||
body = new(bytes.Buffer)
|
||||
enc = json.NewEncoder(body)
|
||||
)
|
||||
|
||||
id, err := encodeRequest(ctx, enc, method, args)
|
||||
id, err := encodeRequest(enc, method, params)
|
||||
if err != nil {
|
||||
return fmt.Errorf("encoding request: %w", err)
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ func NewReadWriterClient(rw io.ReadWriter) Client {
|
||||
}
|
||||
|
||||
func (c rwClient) Call(
|
||||
ctx context.Context, rcv any, method string, args ...any,
|
||||
ctx context.Context, rcv any, method string, params ...any,
|
||||
) error {
|
||||
id, err := encodeRequest(ctx, c.enc, method, args)
|
||||
id, err := encodeRequest(c.enc, method, params)
|
||||
if err != nil {
|
||||
return fmt.Errorf("encoding request: %w", err)
|
||||
}
|
||||
|
@ -18,21 +18,19 @@ type methodDispatchFunc func(context.Context, Request) (any, error)
|
||||
func newMethodDispatchFunc(
|
||||
method reflect.Value,
|
||||
) methodDispatchFunc {
|
||||
argTs := make([]reflect.Type, method.Type().NumIn()-1)
|
||||
for i := range argTs {
|
||||
argTs[i] = method.Type().In(i + 1)
|
||||
paramTs := make([]reflect.Type, method.Type().NumIn()-1)
|
||||
for i := range paramTs {
|
||||
paramTs[i] = method.Type().In(i + 1)
|
||||
}
|
||||
|
||||
return func(ctx context.Context, req Request) (any, error) {
|
||||
ctx = context.WithValue(ctx, ctxKeyMeta(0), req.Params.Meta)
|
||||
|
||||
callVals := make([]reflect.Value, 0, len(argTs)+1)
|
||||
callVals := make([]reflect.Value, 0, len(paramTs)+1)
|
||||
callVals = append(callVals, reflect.ValueOf(ctx))
|
||||
|
||||
for i, argT := range argTs {
|
||||
argPtrV := reflect.New(argT)
|
||||
for i, paramT := range paramTs {
|
||||
paramPtrV := reflect.New(paramT)
|
||||
|
||||
err := json.Unmarshal(req.Params.Args[i], argPtrV.Interface())
|
||||
err := json.Unmarshal(req.Params[i], paramPtrV.Interface())
|
||||
if err != nil {
|
||||
// The JSON has already been validated, so this is not an
|
||||
// errCodeParse situation. We assume it's an invalid param then,
|
||||
@ -40,13 +38,13 @@ func newMethodDispatchFunc(
|
||||
// returning an Error of its own.
|
||||
if !errors.As(err, new(Error)) {
|
||||
err = NewInvalidParamsError(
|
||||
"JSON unmarshaling arg %d into %T: %v", i, argT, err,
|
||||
"JSON unmarshaling param %d into %T: %v", i, paramT, err,
|
||||
)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
callVals = append(callVals, argPtrV.Elem())
|
||||
callVals = append(callVals, paramPtrV.Elem())
|
||||
}
|
||||
|
||||
var (
|
||||
@ -84,8 +82,7 @@ type dispatcher struct {
|
||||
// MethodName(context.Context, ...ParamType) (ResponseType, error)
|
||||
// MethodName(context.Context, ...ParamType) error
|
||||
//
|
||||
// will be available via RPC calls. Any Meta data in the request can be obtained
|
||||
// within the method handler by calling GetMeta on the method's Context.
|
||||
// will be available via RPC calls.
|
||||
func NewDispatchHandler(i any) Handler {
|
||||
v := reflect.ValueOf(i)
|
||||
if v.Kind() != reflect.Pointer {
|
||||
|
@ -57,16 +57,15 @@ func NewMLogMiddleware(logger *mlog.Logger) Middleware {
|
||||
ctx,
|
||||
"rpcRequestID", req.ID,
|
||||
"rpcRequestMethod", req.Method,
|
||||
"rpcRequestMeta", req.Params.Meta,
|
||||
)
|
||||
|
||||
if logger.MaxLevel() >= mlog.LevelDebug.Int() {
|
||||
ctx := ctx
|
||||
for i := range req.Params.Args {
|
||||
for i := range req.Params {
|
||||
ctx = mctx.Annotate(
|
||||
ctx,
|
||||
fmt.Sprintf("rpcRequestArgs%d", i),
|
||||
string(req.Params.Args[i]),
|
||||
fmt.Sprintf("rpcRequestParam%d", i),
|
||||
string(req.Params[i]),
|
||||
)
|
||||
}
|
||||
logger.Debug(ctx, "Handling RPC request")
|
||||
|
@ -3,7 +3,6 @@
|
||||
package jsonrpc2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@ -12,19 +11,11 @@ import (
|
||||
|
||||
const version = "2.0"
|
||||
|
||||
// RequestParams are the parameters passed in a Request. Meta contains
|
||||
// information that is not directly related to what is being requested, while
|
||||
// Args are the request's actual arguments.
|
||||
type RequestParams struct {
|
||||
Meta map[string]any `json:"meta,omitempty"`
|
||||
Args []json.RawMessage `json:"args,omitempty"`
|
||||
}
|
||||
|
||||
// Request encodes an RPC request according to the spec.
|
||||
type Request struct {
|
||||
Version string `json:"jsonrpc"` // must be "2.0"
|
||||
Method string `json:"method"`
|
||||
Params RequestParams `json:"params,omitempty"`
|
||||
Params []json.RawMessage `json:"params,omitempty"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
@ -46,18 +37,18 @@ func newID() string {
|
||||
// encodeRequest writes a request to an io.Writer, returning the ID of the
|
||||
// request.
|
||||
func encodeRequest(
|
||||
ctx context.Context, enc *json.Encoder, method string, args []any,
|
||||
enc *json.Encoder, method string, params []any,
|
||||
) (
|
||||
string, error,
|
||||
) {
|
||||
var (
|
||||
argsBs = make([]json.RawMessage, len(args))
|
||||
paramsBs = make([]json.RawMessage, len(params))
|
||||
err error
|
||||
)
|
||||
for i := range args {
|
||||
argsBs[i], err = json.Marshal(args[i])
|
||||
for i := range params {
|
||||
paramsBs[i], err = json.Marshal(params[i])
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("encoding arg %d as JSON: %w", i, err)
|
||||
return "", fmt.Errorf("encoding param %d as JSON: %w", i, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,10 +57,7 @@ func encodeRequest(
|
||||
reqEnvelope = Request{
|
||||
Version: version,
|
||||
Method: method,
|
||||
Params: RequestParams{
|
||||
Meta: GetMeta(ctx),
|
||||
Args: argsBs,
|
||||
},
|
||||
Params: paramsBs,
|
||||
ID: id,
|
||||
}
|
||||
)
|
||||
|
@ -48,16 +48,6 @@ func (i dividerImpl) Noop(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i dividerImpl) Divide2FromMeta(ctx context.Context) (int, error) {
|
||||
var (
|
||||
meta = GetMeta(ctx)
|
||||
top = int(meta["top"].(float64))
|
||||
bottom = int(meta["bottom"].(float64))
|
||||
)
|
||||
|
||||
return i.Divide2(ctx, top, bottom)
|
||||
}
|
||||
|
||||
func (dividerImpl) Hidden(ctx context.Context, p struct{}) (int, error) {
|
||||
return 0, errors.New("Shouldn't be possible to call this!")
|
||||
}
|
||||
@ -67,7 +57,6 @@ type divider interface {
|
||||
Divide(ctx context.Context, p DivideParams) (int, error)
|
||||
One(ctx context.Context) (int, error)
|
||||
Noop(ctx context.Context) error
|
||||
Divide2FromMeta(ctx context.Context) (int, error)
|
||||
}
|
||||
|
||||
var testHandler = func() Handler {
|
||||
@ -135,19 +124,6 @@ func testClient(t *testing.T, client Client) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("success/meta", func(t *testing.T) {
|
||||
ctx = WithMeta(ctx, "top", 6)
|
||||
ctx = WithMeta(ctx, "bottom", 2)
|
||||
|
||||
var res int
|
||||
err := client.Call(ctx, &res, "Divide2FromMeta")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else if res != 3 {
|
||||
t.Fatalf("expected 2, got %d", res)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("err/application", func(t *testing.T) {
|
||||
err := client.Call(ctx, nil, "Divide", DivideParams{})
|
||||
if !errors.Is(err, ErrDivideByZero) {
|
||||
|
@ -1,30 +0,0 @@
|
||||
package jsonrpc2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"maps"
|
||||
)
|
||||
|
||||
type ctxKeyMeta int
|
||||
|
||||
// WithMeta returns a Context where the given key will be set to the given value
|
||||
// in the Meta field of all JSONRPC2 requests made using Clients from this
|
||||
// package.
|
||||
func WithMeta(ctx context.Context, key string, value any) context.Context {
|
||||
m, _ := ctx.Value(ctxKeyMeta(0)).(map[string]any)
|
||||
if m == nil {
|
||||
m = map[string]any{}
|
||||
} else {
|
||||
m = maps.Clone(m)
|
||||
}
|
||||
|
||||
m[key] = value
|
||||
return context.WithValue(ctx, ctxKeyMeta(0), m)
|
||||
}
|
||||
|
||||
// GetMeta returns all key/values which have been set on the Context using
|
||||
// WithMeta. This may return nil if WithMeta was never called.
|
||||
func GetMeta(ctx context.Context) map[string]any {
|
||||
m, _ := ctx.Value(ctxKeyMeta(0)).(map[string]any)
|
||||
return m
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"isle/daemon/daecommon"
|
||||
"isle/jsonutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"dev.mediocregopher.com/mediocre-go-lib.git/mctx"
|
||||
"dev.mediocregopher.com/mediocre-go-lib.git/mlog"
|
||||
)
|
||||
|
||||
// DEPRECATED
|
||||
func migrateToMultiNetworkStateDirectory(
|
||||
ctx context.Context, logger *mlog.Logger, envVars daecommon.EnvVars,
|
||||
) error {
|
||||
var (
|
||||
legacyBootstrapPath = filepath.Join(
|
||||
envVars.StateDir.Path, "bootstrap.json",
|
||||
)
|
||||
legacySecretsPath = filepath.Join(envVars.StateDir.Path, "secrets")
|
||||
)
|
||||
|
||||
if _, err := os.Stat(legacyBootstrapPath); errors.Is(err, fs.ErrNotExist) {
|
||||
return nil // no bootstrap in the legacy path
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("checking file %q: %w", legacyBootstrapPath, err)
|
||||
}
|
||||
|
||||
var bootstrapBody struct {
|
||||
NetworkCreationParams struct {
|
||||
ID string
|
||||
}
|
||||
}
|
||||
|
||||
if err := jsonutil.LoadFile(
|
||||
&bootstrapBody, legacyBootstrapPath,
|
||||
); err != nil {
|
||||
return fmt.Errorf(
|
||||
"loading bootstrap from %q: %w", legacyBootstrapPath, err,
|
||||
)
|
||||
}
|
||||
|
||||
var (
|
||||
networkStateDirPath = filepath.Join(
|
||||
envVars.StateDir.Path,
|
||||
"networks",
|
||||
bootstrapBody.NetworkCreationParams.ID,
|
||||
)
|
||||
|
||||
newBootstrapPath = filepath.Join(networkStateDirPath, "bootstrap.json")
|
||||
newSecretsPath = filepath.Join(networkStateDirPath, "secrets")
|
||||
)
|
||||
|
||||
ctx = mctx.Annotate(
|
||||
ctx,
|
||||
"legacyBootstrapPath", legacyBootstrapPath,
|
||||
"legacySecretsPath", legacySecretsPath,
|
||||
"newBootstrapPath", newBootstrapPath,
|
||||
"newSecretsPath", newSecretsPath,
|
||||
)
|
||||
|
||||
logger.Info(ctx, "Migrating to multi-network state directory layout")
|
||||
|
||||
if err := os.MkdirAll(networkStateDirPath, 0700); err != nil {
|
||||
return fmt.Errorf("creating %q: %w", networkStateDirPath, err)
|
||||
}
|
||||
|
||||
if err := os.Rename(legacyBootstrapPath, newBootstrapPath); err != nil {
|
||||
return fmt.Errorf(
|
||||
"renaming %q to %q: %w", legacyBootstrapPath, newBootstrapPath, err,
|
||||
)
|
||||
}
|
||||
|
||||
if err := os.Rename(legacySecretsPath, newSecretsPath); err != nil {
|
||||
return fmt.Errorf(
|
||||
"renaming %q to %q: %w", legacySecretsPath, newSecretsPath, err,
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"isle/bootstrap"
|
||||
"isle/daemon/network"
|
||||
@ -42,9 +41,9 @@ func networkDirs(
|
||||
return
|
||||
}
|
||||
|
||||
// loadableNetworks returns the CreationParams for each Network which is able to
|
||||
// LoadableNetworks returns the CreationParams for each Network which is able to
|
||||
// be loaded.
|
||||
func loadableNetworks(
|
||||
func LoadableNetworks(
|
||||
networksStateDir toolkit.Dir,
|
||||
) (
|
||||
[]bootstrap.CreationParams, error,
|
||||
@ -72,60 +71,3 @@ func loadableNetworks(
|
||||
|
||||
return creationParams, nil
|
||||
}
|
||||
|
||||
func pickNetwork(
|
||||
ctx context.Context,
|
||||
networks map[string]network.Network,
|
||||
networksStateDir toolkit.Dir,
|
||||
) (
|
||||
network.Network, error,
|
||||
) {
|
||||
if len(networks) == 0 {
|
||||
return nil, ErrNoNetwork
|
||||
}
|
||||
|
||||
creationParams, err := loadableNetworks(networksStateDir)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getting loadable networks: %w", err)
|
||||
}
|
||||
|
||||
var (
|
||||
networkSearchStr = getNetworkSearchStr(ctx)
|
||||
matchingNetworkIDs = make([]string, 0, len(networks))
|
||||
)
|
||||
|
||||
for _, creationParam := range creationParams {
|
||||
if networkSearchStr == "" || creationParam.Matches(networkSearchStr) {
|
||||
matchingNetworkIDs = append(matchingNetworkIDs, creationParam.ID)
|
||||
}
|
||||
}
|
||||
|
||||
if len(matchingNetworkIDs) == 0 {
|
||||
return nil, ErrNoMatchingNetworks
|
||||
} else if len(matchingNetworkIDs) > 1 {
|
||||
return nil, ErrMultipleMatchingNetworks
|
||||
}
|
||||
|
||||
return networks[matchingNetworkIDs[0]], nil
|
||||
}
|
||||
|
||||
func alreadyJoined(
|
||||
ctx context.Context,
|
||||
networks map[string]network.Network,
|
||||
creationParams bootstrap.CreationParams,
|
||||
) (
|
||||
bool, error,
|
||||
) {
|
||||
for networkID, network := range networks {
|
||||
existingCreationParams, err := network.GetNetworkCreationParams(ctx)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf(
|
||||
"getting creation params of network %q: %w", networkID, err,
|
||||
)
|
||||
} else if existingCreationParams.Conflicts(creationParams) {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ func writeBootstrapToStateDir(
|
||||
return nil
|
||||
}
|
||||
|
||||
func coalesceNetworkConfigAndBootstrap(
|
||||
networkConfig daecommon.NetworkConfig, hostBootstrap bootstrap.Bootstrap,
|
||||
func coalesceDaemonConfigAndBootstrap(
|
||||
daemonConfig daecommon.Config, hostBootstrap bootstrap.Bootstrap,
|
||||
) (
|
||||
bootstrap.Bootstrap, error,
|
||||
) {
|
||||
@ -38,12 +38,12 @@ func coalesceNetworkConfigAndBootstrap(
|
||||
HostAssigned: hostBootstrap.HostAssigned,
|
||||
HostConfigured: bootstrap.HostConfigured{
|
||||
Nebula: bootstrap.NebulaHost{
|
||||
PublicAddr: networkConfig.VPN.PublicAddr,
|
||||
PublicAddr: daemonConfig.VPN.PublicAddr,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if allocs := networkConfig.Storage.Allocations; len(allocs) > 0 {
|
||||
if allocs := daemonConfig.Storage.Allocations; len(allocs) > 0 {
|
||||
|
||||
for i, alloc := range allocs {
|
||||
|
||||
|
@ -57,7 +57,7 @@ func garageAdminClientLogger(logger *mlog.Logger) *mlog.Logger {
|
||||
// or it will _panic_ if there is no local instance configured.
|
||||
func newGarageAdminClient(
|
||||
logger *mlog.Logger,
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
adminToken string,
|
||||
hostBootstrap bootstrap.Bootstrap,
|
||||
) *garage.AdminClient {
|
||||
@ -68,7 +68,7 @@ func newGarageAdminClient(
|
||||
garageAdminClientLogger(logger),
|
||||
net.JoinHostPort(
|
||||
thisHost.IP().String(),
|
||||
strconv.Itoa(networkConfig.Storage.Allocations[0].AdminPort),
|
||||
strconv.Itoa(daemonConfig.Storage.Allocations[0].AdminPort),
|
||||
),
|
||||
adminToken,
|
||||
)
|
||||
@ -77,18 +77,18 @@ func newGarageAdminClient(
|
||||
func garageApplyLayout(
|
||||
ctx context.Context,
|
||||
logger *mlog.Logger,
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
adminToken string,
|
||||
hostBootstrap bootstrap.Bootstrap,
|
||||
) error {
|
||||
|
||||
var (
|
||||
adminClient = newGarageAdminClient(
|
||||
logger, networkConfig, adminToken, hostBootstrap,
|
||||
logger, daemonConfig, adminToken, hostBootstrap,
|
||||
)
|
||||
thisHost = hostBootstrap.ThisHost()
|
||||
hostName = thisHost.Name
|
||||
allocs = networkConfig.Storage.Allocations
|
||||
allocs = daemonConfig.Storage.Allocations
|
||||
peers = make([]garage.PeerLayout, len(allocs))
|
||||
)
|
||||
|
||||
@ -115,14 +115,14 @@ func garageApplyLayout(
|
||||
func garageInitializeGlobalBucket(
|
||||
ctx context.Context,
|
||||
logger *mlog.Logger,
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
adminToken string,
|
||||
hostBootstrap bootstrap.Bootstrap,
|
||||
) (
|
||||
garage.S3APICredentials, error,
|
||||
) {
|
||||
adminClient := newGarageAdminClient(
|
||||
logger, networkConfig, adminToken, hostBootstrap,
|
||||
logger, daemonConfig, adminToken, hostBootstrap,
|
||||
)
|
||||
|
||||
creds, err := adminClient.CreateS3APICredentials(
|
||||
|
14
go/daemon/network/jigs.go
Normal file
14
go/daemon/network/jigs.go
Normal file
@ -0,0 +1,14 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
func randStr(l int) string {
|
||||
b := make([]byte, l)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return hex.EncodeToString(b)
|
||||
}
|
@ -18,6 +18,7 @@ import (
|
||||
"isle/nebula"
|
||||
"isle/secrets"
|
||||
"isle/toolkit"
|
||||
"log"
|
||||
"net/netip"
|
||||
"slices"
|
||||
"sync"
|
||||
@ -153,7 +154,7 @@ func (o *Opts) withDefaults() *Opts {
|
||||
|
||||
type network struct {
|
||||
logger *mlog.Logger
|
||||
networkConfig daecommon.NetworkConfig
|
||||
daemonConfig daecommon.Config
|
||||
|
||||
envBinDirPath string
|
||||
stateDir toolkit.Dir
|
||||
@ -177,20 +178,21 @@ type network struct {
|
||||
func instatiateNetwork(
|
||||
logger *mlog.Logger,
|
||||
networkID string,
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
envBinDirPath string,
|
||||
stateDir toolkit.Dir,
|
||||
runtimeDir toolkit.Dir,
|
||||
opts *Opts,
|
||||
) *network {
|
||||
log.Printf("DEBUG: network stateDir:%+v runtimeDir:%+v", stateDir, runtimeDir)
|
||||
return &network{
|
||||
logger: logger,
|
||||
networkConfig: networkConfig,
|
||||
daemonConfig: daemonConfig,
|
||||
envBinDirPath: envBinDirPath,
|
||||
stateDir: stateDir,
|
||||
runtimeDir: runtimeDir,
|
||||
opts: opts.withDefaults(),
|
||||
garageAdminToken: toolkit.RandStr(32),
|
||||
garageAdminToken: randStr(32),
|
||||
shutdownCh: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
@ -225,7 +227,7 @@ func Load(
|
||||
ctx context.Context,
|
||||
logger *mlog.Logger,
|
||||
networkID string,
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
envBinDirPath string,
|
||||
stateDir toolkit.Dir,
|
||||
runtimeDir toolkit.Dir,
|
||||
@ -236,7 +238,7 @@ func Load(
|
||||
n := instatiateNetwork(
|
||||
logger,
|
||||
networkID,
|
||||
networkConfig,
|
||||
daemonConfig,
|
||||
envBinDirPath,
|
||||
stateDir,
|
||||
runtimeDir,
|
||||
@ -270,7 +272,7 @@ func Load(
|
||||
func Join(
|
||||
ctx context.Context,
|
||||
logger *mlog.Logger,
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
joiningBootstrap JoiningBootstrap,
|
||||
envBinDirPath string,
|
||||
stateDir toolkit.Dir,
|
||||
@ -282,7 +284,7 @@ func Join(
|
||||
n := instatiateNetwork(
|
||||
logger,
|
||||
joiningBootstrap.Bootstrap.NetworkCreationParams.ID,
|
||||
networkConfig,
|
||||
daemonConfig,
|
||||
envBinDirPath,
|
||||
stateDir,
|
||||
runtimeDir,
|
||||
@ -322,7 +324,7 @@ func Join(
|
||||
func Create(
|
||||
ctx context.Context,
|
||||
logger *mlog.Logger,
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
daemonConfig daecommon.Config,
|
||||
envBinDirPath string,
|
||||
stateDir toolkit.Dir,
|
||||
runtimeDir toolkit.Dir,
|
||||
@ -333,7 +335,7 @@ func Create(
|
||||
) (
|
||||
Network, error,
|
||||
) {
|
||||
if len(networkConfig.Storage.Allocations) < 3 {
|
||||
if len(daemonConfig.Storage.Allocations) < 3 {
|
||||
return nil, ErrInvalidConfig.WithData(
|
||||
"At least three storage allocations are required.",
|
||||
)
|
||||
@ -344,12 +346,12 @@ func Create(
|
||||
return nil, fmt.Errorf("creating nebula CA cert: %w", err)
|
||||
}
|
||||
|
||||
garageRPCSecret := toolkit.RandStr(32)
|
||||
garageRPCSecret := randStr(32)
|
||||
|
||||
n := instatiateNetwork(
|
||||
logger,
|
||||
creationParams.ID,
|
||||
networkConfig,
|
||||
daemonConfig,
|
||||
envBinDirPath,
|
||||
stateDir,
|
||||
runtimeDir,
|
||||
@ -407,8 +409,8 @@ func (n *network) initialize(
|
||||
// by the daemon config. This way the network has the most up-to-date
|
||||
// possible bootstrap. This updated bootstrap will later get updated in
|
||||
// garage as a background task, so other hosts will see it as well.
|
||||
currBootstrap, err := coalesceNetworkConfigAndBootstrap(
|
||||
n.networkConfig, currBootstrap,
|
||||
currBootstrap, err := coalesceDaemonConfigAndBootstrap(
|
||||
n.daemonConfig, currBootstrap,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("combining configuration into bootstrap: %w", err)
|
||||
@ -427,7 +429,7 @@ func (n *network) initialize(
|
||||
n.logger.WithNamespace("children"),
|
||||
n.envBinDirPath,
|
||||
n.secretsStore,
|
||||
n.networkConfig,
|
||||
n.daemonConfig,
|
||||
n.runtimeDir,
|
||||
n.garageAdminToken,
|
||||
currBootstrap,
|
||||
@ -465,10 +467,10 @@ func (n *network) initialize(
|
||||
}
|
||||
|
||||
func (n *network) postInit(ctx context.Context) error {
|
||||
if len(n.networkConfig.Storage.Allocations) > 0 {
|
||||
if len(n.daemonConfig.Storage.Allocations) > 0 {
|
||||
n.logger.Info(ctx, "Applying garage layout")
|
||||
if err := garageApplyLayout(
|
||||
ctx, n.logger, n.networkConfig, n.garageAdminToken, n.currBootstrap,
|
||||
ctx, n.logger, n.daemonConfig, n.garageAdminToken, n.currBootstrap,
|
||||
); err != nil {
|
||||
return fmt.Errorf("applying garage layout: %w", err)
|
||||
}
|
||||
@ -487,7 +489,7 @@ func (n *network) postInit(ctx context.Context) error {
|
||||
garageGlobalBucketCreds, err := garageInitializeGlobalBucket(
|
||||
ctx,
|
||||
n.logger,
|
||||
n.networkConfig,
|
||||
n.daemonConfig,
|
||||
n.garageAdminToken,
|
||||
n.currBootstrap,
|
||||
)
|
||||
@ -566,7 +568,7 @@ func (n *network) reload(
|
||||
newBootstrap.Hosts[thisHost.Name] = thisHost
|
||||
|
||||
diff, err := children.CalculateReloadDiff(
|
||||
n.networkConfig, currBootstrap, newBootstrap,
|
||||
n.daemonConfig, currBootstrap, newBootstrap,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("calculating diff between bootstraps: %w", err)
|
||||
|
@ -2,7 +2,6 @@ package daemon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"isle/bootstrap"
|
||||
"isle/daemon/jsonrpc2"
|
||||
"isle/daemon/network"
|
||||
"isle/nebula"
|
||||
@ -23,19 +22,9 @@ type RPC interface {
|
||||
|
||||
JoinNetwork(context.Context, network.JoiningBootstrap) error
|
||||
|
||||
GetNetworks(context.Context) ([]bootstrap.CreationParams, error)
|
||||
|
||||
// All network.RPC methods are automatically implemented by Daemon using the
|
||||
// currently joined network. If no network is joined then any call to these
|
||||
// methods will return ErrNoNetwork.
|
||||
//
|
||||
// All calls to these methods must be accompanied with a context produced by
|
||||
// WithNetwork, in order to choose the network. These methods may return
|
||||
// these errors, in addition to those documented on the individual methods:
|
||||
//
|
||||
// Errors:
|
||||
// - ErrNoMatchingNetworks
|
||||
// - ErrMultipleMatchingNetworks
|
||||
network.RPC
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,3 @@
|
||||
// Package toolkit contains useful utilities which are not specific to any
|
||||
// specific part of isle.
|
||||
package toolkit
|
||||
|
||||
import "reflect"
|
||||
|
||||
// IsZero returns true if the value is equal to its zero value according to
|
||||
// reflect.DeepEqual.
|
||||
func IsZero[T any](v T) bool {
|
||||
var zero T
|
||||
return reflect.DeepEqual(v, zero)
|
||||
}
|
||||
|
@ -33,8 +33,6 @@ if [ ! -d "$XDG_RUNTIME_DIR/isle" ]; then
|
||||
mkdir c
|
||||
|
||||
cat >daemon.yml <<EOF
|
||||
networks:
|
||||
testing:
|
||||
vpn:
|
||||
public_addr: 127.0.0.1:60000
|
||||
tun:
|
||||
|
Loading…
Reference in New Issue
Block a user