Use dialer in relay checks (fixes #2732)
This commit is contained in:
@@ -11,12 +11,10 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/calmh/du"
|
||||
"github.com/syncthing/syncthing/lib/sync"
|
||||
@@ -223,21 +221,3 @@ func DiskFreePercentage(path string) (freePct float64, err error) {
|
||||
u, err := du.Get(path)
|
||||
return (float64(u.FreeBytes) / float64(u.TotalBytes)) * 100, err
|
||||
}
|
||||
|
||||
// SetTCPOptions sets syncthings default TCP options on a TCP connection
|
||||
func SetTCPOptions(conn *net.TCPConn) error {
|
||||
var err error
|
||||
if err = conn.SetLinger(0); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = conn.SetNoDelay(false); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = conn.SetKeepAlivePeriod(60 * time.Second); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = conn.SetKeepAlive(true); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -7,20 +7,18 @@
|
||||
package osutil
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/dialer"
|
||||
)
|
||||
|
||||
// TCPPing returns the duration required to establish a TCP connection
|
||||
// to the given host. ICMP packets require root priviledges, hence why we use
|
||||
// tcp.
|
||||
func TCPPing(address string) (time.Duration, error) {
|
||||
dialer := net.Dialer{
|
||||
Deadline: time.Now().Add(time.Second),
|
||||
}
|
||||
start := time.Now()
|
||||
conn, err := dialer.Dial("tcp", address)
|
||||
conn, err := dialer.DialTimeout("tcp", address, time.Second)
|
||||
if conn != nil {
|
||||
conn.Close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user