Pick a single relay (fixes #2182)

This commit is contained in:
AudriusButkevicius
2015-09-02 17:56:44 +01:00
parent cf802dc67e
commit 876d7ac85e
3 changed files with 70 additions and 43 deletions

View File

@@ -8,6 +8,7 @@ package osutil
import (
"net"
"net/url"
"time"
)
@@ -25,3 +26,14 @@ func TCPPing(address string) (time.Duration, error) {
}
return time.Since(start), err
}
// GetLatencyForURL parses the given URL, tries opening a TCP connection to it
// and returns the time it took to establish the connection.
func GetLatencyForURL(addr string) (time.Duration, error) {
uri, err := url.Parse(addr)
if err != nil {
return 0, err
}
return TCPPing(uri.Host)
}