github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/p2p/net/conn/reuseport.go (about) 1 package conn 2 3 import ( 4 "os" 5 "strings" 6 7 reuseport "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-reuseport" 8 ) 9 10 // envReuseport is the env variable name used to turn off reuse port. 11 // It default to true. 12 const envReuseport = "IPFS_REUSEPORT" 13 14 // envReuseportVal stores the value of envReuseport. defaults to true. 15 var envReuseportVal = true 16 17 func init() { 18 v := strings.ToLower(os.Getenv(envReuseport)) 19 if v == "false" || v == "f" || v == "0" { 20 envReuseportVal = false 21 log.Infof("REUSEPORT disabled (IPFS_REUSEPORT=%s)", v) 22 } 23 } 24 25 // reuseportIsAvailable returns whether reuseport is available to be used. This 26 // is here because we want to be able to turn reuseport on and off selectively. 27 // For now we use an ENV variable, as this handles our pressing need: 28 // 29 // IPFS_REUSEPORT=false ipfs daemon 30 // 31 // If this becomes a sought after feature, we could add this to the config. 32 // In the end, reuseport is a stop-gap. 33 func reuseportIsAvailable() bool { 34 return envReuseportVal && reuseport.Available() 35 }