Add all edgevpn config features to bridge command (#540)

Fixes kairos-io/kairos#2456

---------

Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com>
This commit is contained in:
Mauro Morales
2024-04-25 16:56:35 +02:00
committed by GitHub
parent ef178fe402
commit 014050b39f
5 changed files with 214 additions and 582 deletions

View File

@@ -5,11 +5,8 @@ import (
"fmt"
"io"
"os/exec"
"runtime"
"time"
edgevpnConfig "github.com/mudler/edgevpn/pkg/config"
"github.com/ipfs/go-log"
"github.com/creack/pty"
@@ -18,49 +15,16 @@ import (
"github.com/mudler/edgevpn/pkg/node"
"github.com/mudler/edgevpn/pkg/services"
"github.com/pterm/pterm"
cliV2 "github.com/urfave/cli/v2"
)
func networkConfig(token, address, loglevel, i string) *edgevpnConfig.Config {
return &edgevpnConfig.Config{
NetworkToken: token,
Address: address,
Libp2pLogLevel: "error",
FrameTimeout: "30s",
BootstrapIface: true,
LogLevel: loglevel,
LowProfile: true,
Interface: i,
Concurrency: runtime.NumCPU(),
PacketMTU: 1420,
InterfaceMTU: 1200,
Ledger: edgevpnConfig.Ledger{
AnnounceInterval: time.Duration(30) * time.Second,
SyncInterval: time.Duration(30) * time.Second,
},
NAT: edgevpnConfig.NAT{
Service: true,
Map: true,
RateLimit: true,
RateLimitGlobal: 10,
RateLimitPeer: 10,
RateLimitInterval: time.Duration(10) * time.Second,
},
Discovery: edgevpnConfig.Discovery{
DHT: true,
MDNS: true,
Interval: time.Duration(120) * time.Second,
},
Connection: edgevpnConfig.Connection{
AutoRelay: true,
MaxConnections: 100,
HolePunch: true,
},
func startRecoveryService(ctx context.Context, loglevel string, c *cliV2.Context) error {
err := c.Set("log-level", loglevel)
if err != nil {
return err
}
}
func startRecoveryService(ctx context.Context, token, name, address, loglevel string) error {
nc := networkConfig(token, "", loglevel, "kairosrecovery0")
nc := configFromContext(c)
lvl, err := log.LevelFromString(loglevel)
if err != nil {
@@ -83,7 +47,7 @@ func startRecoveryService(ctx context.Context, token, name, address, loglevel st
// if err != nil {
// return err
// }
o = append(o, services.RegisterService(llger, time.Duration(5*time.Second), name, address)...)
o = append(o, services.RegisterService(llger, time.Duration(5*time.Second), c.String("service"), c.String("listen"))...)
e, err := node.New(o...)
if err != nil {
@@ -125,14 +89,14 @@ func sshServer(listenAdddr, password string) {
))
}
func StartRecoveryService(tk, serviceUUID, generatedPassword, listenAddr string) error {
func StartRecoveryService(c *cliV2.Context) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if err := startRecoveryService(ctx, tk, serviceUUID, listenAddr, "fatal"); err != nil {
if err := startRecoveryService(ctx, "fatal", c); err != nil {
return err
}
sshServer(listenAddr, generatedPassword)
sshServer(c.String("listen"), c.String("password"))
return fmt.Errorf("should not return")
}