Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Refactor edgevpn integration #549

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/kairos-io/kairos-agent/v2 v2.9.1
github.com/kairos-io/kairos-sdk v0.1.1
github.com/mudler/edgevpn v0.25.3-0.20240423154352-8cf7992723be
github.com/mudler/edgevpn v0.25.3
github.com/mudler/go-pluggable v0.0.0-20230126220627-7710299a0ae5
github.com/mudler/go-processmanager v0.0.0-20230818213616-f204007f963c
github.com/onsi/ginkgo/v2 v2.17.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@ github.com/mudler/edgevpn v0.25.2 h1:9VH1eSUkObEa0WzO+ohBAO/FTLKG0WENVfJ1ad3UPr0
github.com/mudler/edgevpn v0.25.2/go.mod h1:/TNk/6bdSjzs7UsALlsw4c3GbJk/kzephVeIpTQ20Xk=
github.com/mudler/edgevpn v0.25.3-0.20240423154352-8cf7992723be h1:aIWSHmZj3XmcowS4/Za253gR2dEoMogmqkFNGCkpCqg=
github.com/mudler/edgevpn v0.25.3-0.20240423154352-8cf7992723be/go.mod h1:fzwR+lqzXYEaOEv1kMYqSIBcH1SJ+bxvi+p4N2s/9D4=
github.com/mudler/edgevpn v0.25.3 h1:mfz1L8ks+Qdbf6VuD7JhB6xNDgjCYCdcOUE5pUVUemQ=
github.com/mudler/edgevpn v0.25.3/go.mod h1:SQdr1svvxv6vqADXSpdWGn/cMCJse2nNNFDu+AT913M=
github.com/mudler/entities v0.0.0-20220905203055-68348bae0f49 h1:P1QgHLh0hX935j6m9K6rlSxc0mkD1UuIAOQEu+1VCW4=
github.com/mudler/entities v0.0.0-20220905203055-68348bae0f49/go.mod h1:qquFT9tYp+/NO7tTotto4BT9zSRYSMDxo2PGZwujpFA=
github.com/mudler/go-pluggable v0.0.0-20230126220627-7710299a0ae5 h1:FaZD86+A9mVt7lh9glAryzQblMsbJYU2VnrdZ8yHlTs=
Expand Down
89 changes: 1 addition & 88 deletions internal/cli/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ import (
"github.com/ipfs/go-log"
qr "github.com/kairos-io/go-nodepair/qrcode"
"github.com/kairos-io/kairos-sdk/utils"
rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager"
"github.com/mudler/edgevpn/api"
"github.com/mudler/edgevpn/cmd"
"github.com/mudler/edgevpn/pkg/config"
"github.com/mudler/edgevpn/pkg/logger"
"github.com/mudler/edgevpn/pkg/node"
"github.com/mudler/edgevpn/pkg/services"
"github.com/mudler/edgevpn/pkg/vpn"
"github.com/multiformats/go-multiaddr"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -113,90 +110,6 @@ func BridgeCMD(toolName string) *cli.Command {
}
}

func stringsToMultiAddr(peers []string) []multiaddr.Multiaddr {
res := []multiaddr.Multiaddr{}
for _, p := range peers {
addr, err := multiaddr.NewMultiaddr(p)
if err != nil {
continue
}
res = append(res, addr)
}
return res
}

func configFromContext(c *cli.Context) *config.Config {
autorelayInterval, err := time.ParseDuration(c.String("autorelay-discovery-interval"))
if err != nil {
autorelayInterval = 0
}
var limitConfig *rcmgr.PartialLimitConfig
d := map[string]map[string]interface{}{}

return &config.Config{
NetworkConfig: c.String("config"),
NetworkToken: c.String("token"),
Address: c.String("address"),
Router: c.String("router"),
Interface: c.String("interface"),
Libp2pLogLevel: c.String("libp2p-log-level"),
LogLevel: c.String("log-level"),
LowProfile: c.Bool("low-profile"),
Blacklist: c.StringSlice("blacklist"),
Concurrency: c.Int("concurrency"),
FrameTimeout: c.String("timeout"),
ChannelBufferSize: c.Int("channel-buffer-size"),
InterfaceMTU: c.Int("mtu"),
PacketMTU: c.Int("packet-mtu"),
BootstrapIface: c.Bool("bootstrap-iface"),
Whitelist: stringsToMultiAddr(c.StringSlice("whitelist")),
Ledger: config.Ledger{
StateDir: c.String("ledger-state"),
AnnounceInterval: time.Duration(c.Int("ledger-announce-interval")) * time.Second,
SyncInterval: time.Duration(c.Int("ledger-syncronization-interval")) * time.Second,
},
NAT: config.NAT{
Service: c.Bool("natservice"),
Map: c.Bool("natmap"),
RateLimit: c.Bool("nat-ratelimit"),
RateLimitGlobal: c.Int("nat-ratelimit-global"),
RateLimitPeer: c.Int("nat-ratelimit-peer"),
RateLimitInterval: time.Duration(c.Int("nat-ratelimit-interval")) * time.Second,
},
Discovery: config.Discovery{
BootstrapPeers: c.StringSlice("discovery-bootstrap-peers"),
DHT: c.Bool("dht"),
MDNS: c.Bool("mdns"),
Interval: time.Duration(c.Int("discovery-interval")) * time.Second,
},
Connection: config.Connection{
AutoRelay: c.Bool("autorelay"),
MaxConnections: c.Int("max-connections"),
HolePunch: c.Bool("holepunch"),
StaticRelays: c.StringSlice("autorelay-static-peer"),
AutoRelayDiscoveryInterval: autorelayInterval,
OnlyStaticRelays: c.Bool("autorelay-static-only"),
HighWater: c.Int("connection-high-water"),
LowWater: c.Int("connection-low-water"),
},
Limit: config.ResourceLimit{
Enable: c.Bool("limit-enable"),
FileLimit: c.String("limit-file"),
Scope: c.String("limit-scope"),
MaxConns: c.Int("max-connections"), // Turn to 0 to use other way of limiting. Files take precedence
LimitConfig: limitConfig,
},
PeerGuard: config.PeerGuard{
Enable: c.Bool("peerguard"),
PeerGate: c.Bool("peergate"),
Relaxed: c.Bool("peergate-relaxed"),
Autocleanup: c.Bool("peergate-autoclean"),
SyncInterval: time.Duration(c.Int("peergate-interval")) * time.Second,
AuthProviders: d,
},
}
}

// bridge is just starting a VPN with edgevpn to the given network token.
func bridge(c *cli.Context) error {
qrCodePath := ""
Expand Down Expand Up @@ -234,7 +147,7 @@ func bridge(c *cli.Context) error {

ctx := context.Background()

nc := configFromContext(c)
nc := cmd.ConfigFromContext(c)

lvl, err := log.LevelFromString(nc.LogLevel)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion internal/cli/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/creack/pty"
"github.com/gliderlabs/ssh"
"github.com/mudler/edgevpn/cmd"
"github.com/mudler/edgevpn/pkg/logger"
"github.com/mudler/edgevpn/pkg/node"
"github.com/mudler/edgevpn/pkg/services"
Expand All @@ -24,7 +25,7 @@ func startRecoveryService(ctx context.Context, loglevel string, c *cliV2.Context
return err
}

nc := configFromContext(c)
nc := cmd.ConfigFromContext(c)

lvl, err := log.LevelFromString(loglevel)
if err != nil {
Expand Down
Loading