Add timeouts to relay methods
This commit is contained in:
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/syncthing/syncthing/lib/relay/protocol"
|
||||
)
|
||||
|
||||
func GetInvitationFromRelay(uri *url.URL, id syncthingprotocol.DeviceID, certs []tls.Certificate) (protocol.SessionInvitation, error) {
|
||||
func GetInvitationFromRelay(uri *url.URL, id syncthingprotocol.DeviceID, certs []tls.Certificate, timeout time.Duration) (protocol.SessionInvitation, error) {
|
||||
if uri.Scheme != "relay" {
|
||||
return protocol.SessionInvitation{}, fmt.Errorf("Unsupported relay scheme: %v", uri.Scheme)
|
||||
}
|
||||
@@ -27,7 +27,7 @@ func GetInvitationFromRelay(uri *url.URL, id syncthingprotocol.DeviceID, certs [
|
||||
}
|
||||
|
||||
conn := tls.Client(rconn, configForCerts(certs))
|
||||
conn.SetDeadline(time.Now().Add(10 * time.Second))
|
||||
conn.SetDeadline(time.Now().Add(timeout))
|
||||
|
||||
if err := performHandshakeAndValidation(conn, uri); err != nil {
|
||||
return protocol.SessionInvitation{}, err
|
||||
@@ -99,10 +99,10 @@ func JoinSession(invitation protocol.SessionInvitation) (net.Conn, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRelay(uri *url.URL, certs []tls.Certificate, sleep time.Duration, times int) bool {
|
||||
func TestRelay(uri *url.URL, certs []tls.Certificate, sleep, timeout time.Duration, times int) bool {
|
||||
id := syncthingprotocol.NewDeviceID(certs[0].Certificate[0])
|
||||
invs := make(chan protocol.SessionInvitation, 1)
|
||||
c, err := NewClient(uri, certs, invs)
|
||||
c, err := NewClient(uri, certs, invs, timeout)
|
||||
if err != nil {
|
||||
close(invs)
|
||||
return false
|
||||
@@ -114,7 +114,7 @@ func TestRelay(uri *url.URL, certs []tls.Certificate, sleep time.Duration, times
|
||||
}()
|
||||
|
||||
for i := 0; i < times; i++ {
|
||||
_, err := GetInvitationFromRelay(uri, id, certs)
|
||||
_, err := GetInvitationFromRelay(uri, id, certs, timeout)
|
||||
if err == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user