(ctx context.Context, invitation protocol.SessionInvitation)
| 77 | } |
| 78 | |
| 79 | func JoinSession(ctx context.Context, invitation protocol.SessionInvitation) (net.Conn, error) { |
| 80 | addr := net.JoinHostPort(net.IP(invitation.Address).String(), strconv.Itoa(int(invitation.Port))) |
| 81 | |
| 82 | ctx, cancel := context.WithTimeout(ctx, 10*time.Second) |
| 83 | defer cancel() |
| 84 | conn, err := dialer.DialContext(ctx, "tcp", addr) |
| 85 | if err != nil { |
| 86 | return nil, err |
| 87 | } |
| 88 | |
| 89 | request := protocol.JoinSessionRequest{ |
| 90 | Key: invitation.Key, |
| 91 | } |
| 92 | |
| 93 | conn.SetDeadline(time.Now().Add(10 * time.Second)) |
| 94 | err = protocol.WriteMessage(conn, request) |
| 95 | if err != nil { |
| 96 | return nil, err |
| 97 | } |
| 98 | |
| 99 | message, err := protocol.ReadMessage(conn) |
| 100 | if err != nil { |
| 101 | return nil, err |
| 102 | } |
| 103 | |
| 104 | conn.SetDeadline(time.Time{}) |
| 105 | |
| 106 | switch msg := message.(type) { |
| 107 | case protocol.Response: |
| 108 | if msg.Code != 0 { |
| 109 | return nil, fmt.Errorf("incorrect response code %d: %s", msg.Code, msg.Message) |
| 110 | } |
| 111 | return conn, nil |
| 112 | default: |
| 113 | return nil, fmt.Errorf("protocol error: expecting response got %v", msg) |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | func TestRelay(ctx context.Context, uri *url.URL, certs []tls.Certificate, sleep, timeout time.Duration, times int) error { |
| 118 | id := syncthingprotocol.NewDeviceID(certs[0].Certificate[0]) |
no test coverage detected