From e3ca797dadcbec00b8e5bd7d98cb2f2b2bb43a7a Mon Sep 17 00:00:00 2001 From: AudriusButkevicius Date: Sun, 6 Sep 2015 20:25:53 +0100 Subject: [PATCH] Receive the invite, otherwise stop blocks, add extra arguments --- client/methods.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/client/methods.go b/client/methods.go index cfc810f5e..67a9a71c1 100644 --- a/client/methods.go +++ b/client/methods.go @@ -98,13 +98,17 @@ func JoinSession(invitation protocol.SessionInvitation) (net.Conn, error) { } } -func TestRelay(uri *url.URL, certs []tls.Certificate) bool { +func TestRelay(uri *url.URL, certs []tls.Certificate, sleep time.Duration, times int) bool { id := syncthingprotocol.NewDeviceID(certs[0].Certificate[0]) - c := NewProtocolClient(uri, certs, nil) + invs := make(chan protocol.SessionInvitation, 1) + c := NewProtocolClient(uri, certs, invs) go c.Serve() - defer c.Stop() + defer func() { + close(invs) + c.Stop() + }() - for i := 0; i < 5; i++ { + for i := 0; i < times; i++ { _, err := GetInvitationFromRelay(uri, id, certs) if err == nil { return true @@ -112,7 +116,7 @@ func TestRelay(uri *url.URL, certs []tls.Certificate) bool { if !strings.Contains(err.Error(), "Incorrect response code") { return false } - time.Sleep(time.Second) + time.Sleep(sleep) } return false }