-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ipfs#1038 from ipfs/reuseport-disable
reuseport: env var to turn it off
- Loading branch information
Showing
3 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package conn | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
|
||
reuseport "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-reuseport" | ||
) | ||
|
||
// envReuseport is the env variable name used to turn off reuse port. | ||
// It default to true. | ||
const envReuseport = "IPFS_REUSEPORT" | ||
|
||
// envReuseportVal stores the value of envReuseport. defaults to true. | ||
var envReuseportVal = true | ||
|
||
func init() { | ||
v := strings.ToLower(os.Getenv(envReuseport)) | ||
if v == "false" || v == "f" || v == "0" { | ||
envReuseportVal = false | ||
log.Infof("REUSEPORT disabled (IPFS_REUSEPORT=%s)", v) | ||
} | ||
} | ||
|
||
// reuseportIsAvailable returns whether reuseport is available to be used. This | ||
// is here because we want to be able to turn reuseport on and off selectively. | ||
// For now we use an ENV variable, as this handles our pressing need: | ||
// | ||
// IPFS_REUSEPORT=false ipfs daemon | ||
// | ||
// If this becomes a sought after feature, we could add this to the config. | ||
// In the end, reuseport is a stop-gap. | ||
func reuseportIsAvailable() bool { | ||
return envReuseportVal && reuseport.Available() | ||
} |