Skip to content

Commit

Permalink
Use HTTP2 only for https urls
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdarkdragon committed Feb 13, 2020
1 parent baf1a46 commit a54ff01
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 17 deletions.
6 changes: 2 additions & 4 deletions apis/livepeer/livepeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package livepeer

import (
"bytes"
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
Expand All @@ -13,15 +12,14 @@ import (
"github.com/golang/glog"
"github.com/livepeer/stream-tester/internal/utils/uhttp"
"github.com/livepeer/stream-tester/model"
"golang.org/x/net/http2"
)

const httpTimeout = 2 * time.Second

var httpClient = &http.Client{
// Transport: &http2.Transport{TLSClientConfig: tlsConfig},
Transport: &http2.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: false}},
Timeout: httpTimeout,
// Transport: &http2.Transport{AllowHTTP: true},
Timeout: httpTimeout,
}

const (
Expand Down
3 changes: 2 additions & 1 deletion cmd/streamtester/streamtester.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func main() {
apiToken := flag.String("api-token", "", "Token of the Livepeer API to be used by the Mist server")
lapiFlag := flag.Bool("lapi", false, "Use Livepeer API to create streams. api-token should be specified")
presets := flag.String("presets", "", "Comma separate list of transcoding profiels to use along with Livepeer API")
skipTime := flag.Duration("skip-time", 0, "Skips first x(s|m)")
_ = flag.String("config", "", "config file (optional)")

ff.Parse(flag.CommandLine, os.Args[1:],
Expand Down Expand Up @@ -214,7 +215,7 @@ func main() {
if !*httpIngest {
sr = testers.NewStreamer(*wowza, *mist, mapi, lapi)
} else {
sr = testers.NewHTTPLoadTester(lapi)
sr = testers.NewHTTPLoadTester(lapi, *skipTime)
}
_, err = sr.StartStreams(fn, *bhost, *rtmp, mHost, *media, *sim, *repeat, streamDuration, false, *latency, *noBar, 3, 5*time.Second, waitForDur)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (ss *StreamerServer) handleStartStreams(w http.ResponseWriter, r *http.Requ
glog.Infof("Get request: %+v", ssr)
if !ssr.DoNotClearStats || ss.streamer == nil {
if ssr.HTTPIngest {
ss.streamer = testers.NewHTTPLoadTester(nil)
ss.streamer = testers.NewHTTPLoadTester(nil, 0)
} else {
ss.streamer = testers.NewStreamer(ss.wowzaMode, ss.mistMode, nil, nil)
}
Expand Down
7 changes: 4 additions & 3 deletions internal/testers/http_load_tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ type HTTPLoadTester struct {
cancel func()
streamers []*httpStreamer
lapi *livepeer.API
skipFirst time.Duration
}

// NewHTTPLoadTester returns new HTTPLoadTester
func NewHTTPLoadTester(lapi *livepeer.API) model.Streamer {
func NewHTTPLoadTester(lapi *livepeer.API, skipFirst time.Duration) model.Streamer {
ctx, cancel := context.WithCancel(context.Background())
return &HTTPLoadTester{ctx: ctx, cancel: cancel, lapi: lapi}
return &HTTPLoadTester{ctx: ctx, cancel: cancel, lapi: lapi, skipFirst: skipFirst}
}

// Done returns channel that will be closed once streaming is done
Expand Down Expand Up @@ -143,7 +144,7 @@ func (hlt *HTTPLoadTester) startStreams(baseManifestID, sourceFileName string, r
up := newHTTPtreamer(hlt.ctx, measureLatency, baseManifestID)
wg.Add(1)
go func() {
up.StartUpload(sourceFileName, httpIngestURL, manifestID, 0, waitForTarget, stopAfter)
up.StartUpload(sourceFileName, httpIngestURL, manifestID, 0, waitForTarget, stopAfter, hlt.skipFirst)
wg.Done()
}()
hlt.streamers = append(hlt.streamers, up)
Expand Down
9 changes: 7 additions & 2 deletions internal/testers/http_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"
"path"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -121,7 +122,7 @@ func pushHLSSegmentsLoop(dir string, pl *m3u8.MediaPlaylist, stopAfter time.Dura
}

// StartUpload starts HTTP segments. Blocks until end.
func (hs *httpStreamer) StartUpload(fn, httpURL, manifestID string, segmentsToStream int, waitForTarget, stopAfter time.Duration) {
func (hs *httpStreamer) StartUpload(fn, httpURL, manifestID string, segmentsToStream int, waitForTarget, stopAfter, skipFirst time.Duration) {
segmentsIn := make(chan *hlsSegment)
var err error
ext := path.Ext(fn)
Expand Down Expand Up @@ -172,8 +173,12 @@ func (hs *httpStreamer) pushSegment(httpURL, manifestID string, seg *hlsSegment)
}
req.Header.Set("Accept", "multipart/mixed")
req.Header.Set("Content-Duration", strconv.FormatInt(seg.duration.Milliseconds(), 10))
hc := httpClient
if strings.HasPrefix(urlToUp, "https:") {
hc = http2Client
}
postStarted := time.Now()
resp, err := httpClient.Do(req)
resp, err := hc.Do(req)
postTook := time.Since(postStarted)
var timedout bool
var status string
Expand Down
12 changes: 10 additions & 2 deletions internal/testers/m3utester.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package testers

import (
"bytes"
"crypto/tls"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -30,7 +29,16 @@ const HTTPTimeout = 16 * time.Second

var httpClient = &http.Client{
// Transport: &http2.Transport{TLSClientConfig: tlsConfig},
Transport: &http2.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: false}},
// Transport: &http2.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: false}},
// Transport: &http2.Transport{AllowHTTP: true},
Timeout: HTTPTimeout,
}

var http2Client = &http.Client{
// Transport: &http2.Transport{TLSClientConfig: tlsConfig},
// Transport: &http2.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: false}},
// Transport: &http2.Transport{AllowHTTP: true},
Transport: &http2.Transport{},
Timeout: HTTPTimeout,
}

Expand Down
7 changes: 3 additions & 4 deletions mist/mist.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package mist

import (
"crypto/md5"
"crypto/tls"
"encoding/hex"
"encoding/json"
"fmt"
Expand All @@ -15,15 +14,15 @@ import (

"github.com/golang/glog"
"github.com/livepeer/stream-tester/internal/utils/uhttp"
"golang.org/x/net/http2"
)

const httpTimeout = 2 * time.Second

var httpClient = &http.Client{
// Transport: &http2.Transport{TLSClientConfig: tlsConfig},
Transport: &http2.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: false}},
Timeout: httpTimeout,
// Transport: &http2.Transport{AllowHTTP: true},
// Transport: &http2.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, AllowHTTP: true},
Timeout: httpTimeout,
}

type (
Expand Down

0 comments on commit a54ff01

Please sign in to comment.