-
-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add force relay conn env var for debug purpose (#904)
Add force relay conn env var for debug purpose. Move another conn related env settings into a common go file.
- Loading branch information
Showing
2 changed files
with
60 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package peer | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
const ( | ||
envICEKeepAliveIntervalSec = "NB_ICE_KEEP_ALIVE_INTERVAL_SEC" | ||
envICEDisconnectedTimeoutSec = "NB_ICE_DISCONNECTED_TIMEOUT_SEC" | ||
envICEForceRelayConn = "NB_ICE_FORCE_RELAY_CONN" | ||
) | ||
|
||
func iceKeepAlive() time.Duration { | ||
keepAliveEnv := os.Getenv(envICEKeepAliveIntervalSec) | ||
if keepAliveEnv == "" { | ||
return iceKeepAliveDefault | ||
} | ||
|
||
log.Debugf("setting ICE keep alive interval to %s seconds", keepAliveEnv) | ||
keepAliveEnvSec, err := strconv.Atoi(keepAliveEnv) | ||
if err != nil { | ||
log.Warnf("invalid value %s set for %s, using default %v", keepAliveEnv, envICEKeepAliveIntervalSec, iceKeepAliveDefault) | ||
return iceKeepAliveDefault | ||
} | ||
|
||
return time.Duration(keepAliveEnvSec) * time.Second | ||
} | ||
|
||
func iceDisconnectedTimeout() time.Duration { | ||
disconnectedTimeoutEnv := os.Getenv(envICEDisconnectedTimeoutSec) | ||
if disconnectedTimeoutEnv == "" { | ||
return iceDisconnectedTimeoutDefault | ||
} | ||
|
||
log.Debugf("setting ICE disconnected timeout to %s seconds", disconnectedTimeoutEnv) | ||
disconnectedTimeoutSec, err := strconv.Atoi(disconnectedTimeoutEnv) | ||
if err != nil { | ||
log.Warnf("invalid value %s set for %s, using default %v", disconnectedTimeoutEnv, envICEDisconnectedTimeoutSec, iceDisconnectedTimeoutDefault) | ||
return iceDisconnectedTimeoutDefault | ||
} | ||
|
||
return time.Duration(disconnectedTimeoutSec) * time.Second | ||
} | ||
|
||
func hasICEForceRelayConn() bool { | ||
disconnectedTimeoutEnv := os.Getenv(envICEForceRelayConn) | ||
return strings.ToLower(disconnectedTimeoutEnv) == "true" | ||
} |