Browse Source

:gear: Allow to enable transient connections

Ettore Di Giacinto 3 years ago
parent
commit
e9e6a58bca
1 changed files with 12 additions and 0 deletions
  1. 12 0
      cmd/main.go

+ 12 - 0
cmd/main.go

@@ -23,6 +23,8 @@ import (
 	"path/filepath"
 	"path/filepath"
 	"time"
 	"time"
 
 
+	"github.com/libp2p/go-libp2p-core/network"
+
 	"github.com/mudler/edgevpn/api"
 	"github.com/mudler/edgevpn/api"
 	edgevpn "github.com/mudler/edgevpn/pkg/node"
 	edgevpn "github.com/mudler/edgevpn/pkg/node"
 	"github.com/mudler/edgevpn/pkg/services"
 	"github.com/mudler/edgevpn/pkg/services"
@@ -71,6 +73,11 @@ func MainFlags() []cli.Flag {
 			Usage:  "Enables p2p ip negotiation (experimental)",
 			Usage:  "Enables p2p ip negotiation (experimental)",
 			EnvVar: "DHCP",
 			EnvVar: "DHCP",
 		},
 		},
+		&cli.BoolFlag{
+			Name:   "transient-conn",
+			Usage:  "Allow transient connections",
+			EnvVar: "TRANSIENTCONN",
+		},
 		&cli.StringFlag{
 		&cli.StringFlag{
 			Name:   "lease-dir",
 			Name:   "lease-dir",
 			Value:  filepath.Join(basedir, ".edgevpn", "leases"),
 			Value:  filepath.Join(basedir, ".edgevpn", "leases"),
@@ -192,6 +199,11 @@ func Main() func(c *cli.Context) error {
 		displayStart(ll)
 		displayStart(ll)
 
 
 		ctx := context.Background()
 		ctx := context.Background()
+
+		if c.Bool("transient-conn") {
+			ctx = network.WithUseTransient(ctx, "accept")
+		}
+
 		if c.Bool("api") {
 		if c.Bool("api") {
 			go api.API(ctx, c.String("api-listen"), 5*time.Second, 20*time.Second, e)
 			go api.API(ctx, c.String("api-listen"), 5*time.Second, 20*time.Second, e)
 		}
 		}