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

Make FD limits configurable by environment property #102

Merged
merged 1 commit into from
Feb 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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