func echoTCPIdent(tt *tunneltest.TunnelTest, echo, ident string) (string, error) { addr := tt.Addr(ident) if addr == nil { return "", fmt.Errorf("tunnel %q does not exist", ident) } s := addr.String() ip := tt.Tunnels[ident].IP if ip != nil { _, port, err := net.SplitHostPort(s) if err != nil { return "", err } s = net.JoinHostPort(ip.String(), port) } c, err := dialTCP(s) if err != nil { return "", err } c.out <- echo select { case reply := <-c.in: return reply, nil case <-time.After(tcpTimeout): return "", fmt.Errorf("timed out waiting for reply from %s (%s) after %v", s, addr, tcpTimeout) } }
func websocketDial(tt *tunneltest.TunnelTest, ident string) (*websocket.Conn, error) { req := tt.Request(ident, nil) if req == nil { return nil, fmt.Errorf("no client found for ident %q", ident) } h := http.Header{"Host": {req.Host}} wsurl := fmt.Sprintf("ws://%s", tt.ServerAddr()) conn, _, err := dialer.Dial(wsurl, h) return conn, err }
func echoHTTP(tt *tunneltest.TunnelTest, echo string) (string, error) { req := tt.Request("http", url.Values{"echo": []string{echo}}) if req == nil { return "", fmt.Errorf(`tunnel "http" does not exist`) } req.Close = rand.Int()%2 == 0 resp, err := http.DefaultClient.Do(req) if err != nil { return "", err } defer resp.Body.Close() p, err := ioutil.ReadAll(resp.Body) if err != nil { return "", err } return string(bytes.TrimSpace(p)), nil }