Browse Source

:gear: Enable relayv1 circuit if desired

Ettore Di Giacinto 3 years ago
parent
commit
2f0906bb5e
2 changed files with 13 additions and 1 deletions
  1. 6 0
      cmd/util.go
  2. 7 1
      pkg/config/config.go

+ 6 - 0
cmd/util.go

@@ -127,6 +127,11 @@ var CommonFlags []cli.Flag = []cli.Flag{
 		Usage:  "Automatically act as a relay if the node can accept inbound connections",
 		Usage:  "Automatically act as a relay if the node can accept inbound connections",
 		EnvVar: "EDGEVPNAUTORELAY",
 		EnvVar: "EDGEVPNAUTORELAY",
 	},
 	},
+	&cli.BoolFlag{
+		Name:   "autorelay-v1",
+		Usage:  "Enable autorelay v1 circuits",
+		EnvVar: "EDGEVPNAUTORELAYV1",
+	},
 	&cli.IntFlag{
 	&cli.IntFlag{
 		Name:  "concurrency",
 		Name:  "concurrency",
 		Usage: "Number of concurrent requests to serve",
 		Usage: "Number of concurrent requests to serve",
@@ -354,6 +359,7 @@ func cliToOpts(c *cli.Context) ([]node.Option, []vpn.Option, *logger.Logger) {
 		},
 		},
 		Connection: config.Connection{
 		Connection: config.Connection{
 			AutoRelay:      c.Bool("autorelay"),
 			AutoRelay:      c.Bool("autorelay"),
+			RelayV1:        c.Bool("autorelay-v1"),
 			MaxConnections: c.Int("max-connections"),
 			MaxConnections: c.Int("max-connections"),
 			MaxStreams:     c.Int("max-streams"),
 			MaxStreams:     c.Int("max-streams"),
 			HolePunch:      c.Bool("holepunch"),
 			HolePunch:      c.Bool("holepunch"),

+ 7 - 1
pkg/config/config.go

@@ -27,6 +27,7 @@ import (
 	"github.com/libp2p/go-libp2p-core/network"
 	"github.com/libp2p/go-libp2p-core/network"
 	dht "github.com/libp2p/go-libp2p-kad-dht"
 	dht "github.com/libp2p/go-libp2p-kad-dht"
 	rcmgr "github.com/libp2p/go-libp2p-resource-manager"
 	rcmgr "github.com/libp2p/go-libp2p-resource-manager"
+	"github.com/libp2p/go-libp2p/p2p/host/autorelay"
 	"github.com/mudler/edgevpn/pkg/blockchain"
 	"github.com/mudler/edgevpn/pkg/blockchain"
 	"github.com/mudler/edgevpn/pkg/crypto"
 	"github.com/mudler/edgevpn/pkg/crypto"
 	"github.com/mudler/edgevpn/pkg/discovery"
 	"github.com/mudler/edgevpn/pkg/discovery"
@@ -87,6 +88,7 @@ type Discovery struct {
 type Connection struct {
 type Connection struct {
 	HolePunch      bool
 	HolePunch      bool
 	AutoRelay      bool
 	AutoRelay      bool
+	RelayV1        bool
 	MaxConnections int
 	MaxConnections int
 	MaxStreams     int
 	MaxStreams     int
 }
 }
@@ -194,7 +196,11 @@ func (c Config) ToOpts(l *logger.Logger) ([]node.Option, []vpn.Option, error) {
 	libp2pOpts := []libp2p.Option{libp2p.UserAgent("edgevpn")}
 	libp2pOpts := []libp2p.Option{libp2p.UserAgent("edgevpn")}
 
 
 	if c.Connection.AutoRelay {
 	if c.Connection.AutoRelay {
-		libp2pOpts = append(libp2pOpts, libp2p.EnableAutoRelay())
+		relayOpts := []autorelay.Option{}
+		if c.Connection.RelayV1 {
+			relayOpts = append(relayOpts, autorelay.WithCircuitV1Support())
+		}
+		libp2pOpts = append(libp2pOpts, libp2p.EnableAutoRelay(relayOpts...))
 	}
 	}
 
 
 	if c.NAT.RateLimit {
 	if c.NAT.RateLimit {