Skip to content

Commit 730e177

Browse files
authored
Merge pull request #102 from raulk/env-var-fd-limit
Make FD limits configurable by environment property
2 parents b601f9a + 96a640d commit 730e177

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

p2p/net/swarm/limiter.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package swarm
22

33
import (
44
"context"
5+
"os"
6+
"strconv"
57
"sync"
68
"time"
79

@@ -59,7 +61,13 @@ type dialLimiter struct {
5961
type dialfunc func(context.Context, peer.ID, ma.Multiaddr) (transport.Conn, error)
6062

6163
func newDialLimiter(df dialfunc) *dialLimiter {
62-
return newDialLimiterWithParams(df, ConcurrentFdDials, DefaultPerPeerRateLimit)
64+
fd := ConcurrentFdDials
65+
if env := os.Getenv("LIBP2P_SWARM_FD_LIMIT"); env != "" {
66+
if n, err := strconv.ParseInt(env, 10, 32); err == nil {
67+
fd = int(n)
68+
}
69+
}
70+
return newDialLimiterWithParams(df, fd, DefaultPerPeerRateLimit)
6371
}
6472

6573
func newDialLimiterWithParams(df dialfunc, fdLimit, perPeerLimit int) *dialLimiter {

0 commit comments

Comments
 (0)