Skip to content
Snippets Groups Projects
Unverified Commit 7943e9db authored by Philipp Winter's avatar Philipp Winter
Browse files

Turn timeout variable into constant.

Thanks to Cecylia for suggesting this here:
<https://bugs.torproject.org/30472#comment:6>
parent 45ad51f0
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,10 @@ import (
"time"
)
// timeout specifies the number of seconds we're willing to wait until we
// decide that the given destination is offline.
const timeout time.Duration = 3 * time.Second
// limiter implements a rate limiter. We allow 1 request per second on average
// with bursts of up to 5 requests per second.
var limiter = rate.NewLimiter(1, 5)
......@@ -38,10 +42,6 @@ func ScanDestination(w http.ResponseWriter, r *http.Request) {
return
}
// The number of seconds we're willing to wait until we decide that the
// given destination is offline.
timeout, _ := time.ParseDuration("3s")
r.ParseForm()
// These variables will be "" if they're not set.
address := r.Form.Get("address")
......@@ -56,7 +56,7 @@ func ScanDestination(w http.ResponseWriter, r *http.Request) {
return
}
portReachable, err := IsTCPPortReachable(address, port, timeout)
portReachable, err := IsTCPPortReachable(address, port)
if portReachable {
SendResponse(w, SuccessPage)
} else {
......@@ -67,7 +67,7 @@ func ScanDestination(w http.ResponseWriter, r *http.Request) {
// IsTCPPortReachable returns `true' if it can establish a TCP connection with
// the given IP address and port. If not, it returns `false' and the
// respective error, as reported by `net.DialTimeout'.
func IsTCPPortReachable(addr, port string, timeout time.Duration) (bool, error) {
func IsTCPPortReachable(addr, port string) (bool, error) {
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%s", addr, port), timeout)
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment