Browse Source

stab an high number for default connmanager limits

Signed-off-by: mudler <[email protected]>
mudler 1 year ago
parent
commit
2d525b6a40
2 changed files with 31 additions and 3 deletions
  1. 14 0
      cmd/util.go
  2. 17 3
      pkg/config/config.go

+ 14 - 0
cmd/util.go

@@ -213,6 +213,18 @@ var CommonFlags []cli.Flag = []cli.Flag{
 		Usage:  "List of discovery peers to use",
 		EnvVar: "EDGEVPNBOOTSTRAPPEERS",
 	},
+	&cli.IntFlag{
+		Name:   "connection-high-water",
+		Usage:  "max number of connection allowed",
+		EnvVar: "EDGEVPN_CONNECTION_HIGH_WATER",
+		Value:  0,
+	},
+	&cli.IntFlag{
+		Name:   "connection-low-water",
+		Usage:  "low number of connection allowed",
+		EnvVar: "EDGEVPN_CONNECTION_LOW_WATER",
+		Value:  0,
+	},
 	&cli.StringSliceFlag{
 		Name:   "autorelay-static-peer",
 		Usage:  "List of autorelay static peers to use",
@@ -427,6 +439,8 @@ func cliToOpts(c *cli.Context) ([]node.Option, []vpn.Option, *logger.Logger) {
 			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"),

+ 17 - 3
pkg/config/config.go

@@ -117,6 +117,9 @@ type Connection struct {
 	PeerTable map[string]peer.ID
 
 	MaxConnections int
+
+	LowWater  int
+	HighWater int
 }
 
 // NAT is the structure relative to NAT configuration settings
@@ -268,10 +271,21 @@ func (c Config) ToOpts(l *logger.Logger) ([]node.Option, []vpn.Option, error) {
 		))
 	}
 
-	if c.Connection.MaxConnections != 0 {
+	if c.Connection.LowWater != 0 && c.Connection.HighWater != 0 {
+		cm, err := connmanager.NewConnManager(
+			c.Connection.LowWater,
+			c.Connection.HighWater,
+			connmanager.WithGracePeriod(80*time.Second),
+		)
+		if err != nil {
+			llger.Fatal("could not create connection manager")
+		}
+
+		libp2pOpts = append(libp2pOpts, libp2p.ConnectionManager(cm))
+	} else {
 		cm, err := connmanager.NewConnManager(
-			1,
-			c.Connection.MaxConnections,
+			9999999999,
+			9999999999,
 			connmanager.WithGracePeriod(80*time.Second),
 		)
 		if err != nil {