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

Commit

Permalink
Merge pull request #102 from raulk/env-var-fd-limit
Browse files Browse the repository at this point in the history
Make FD limits configurable by environment property
  • Loading branch information
raulk authored Feb 5, 2019
2 parents 65dbfb6 + 34138bb commit 8afd25a
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 8afd25a

Please sign in to comment.