Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
make FD limits configurable by env prop.
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk committed Feb 4, 2019
1 parent 65dbfb6 commit 34138bb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package swarm

import (
"context"
"os"
"strconv"
"sync"
"time"

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

func newDialLimiter(df dialfunc) *dialLimiter {
return newDialLimiterWithParams(df, ConcurrentFdDials, DefaultPerPeerRateLimit)
fd := ConcurrentFdDials
if env := os.Getenv("LIBP2P_SWARM_FD_LIMIT"); env != "" {
if n, err := strconv.ParseInt(env, 10, 32); err == nil {
fd = int(n)
}
}
return newDialLimiterWithParams(df, fd, DefaultPerPeerRateLimit)
}

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

0 comments on commit 34138bb

Please sign in to comment.