From a54ff0180c9c99b0ef74e1e4420329bb9216a248 Mon Sep 17 00:00:00 2001 From: Ivan Tivonenko Date: Fri, 14 Feb 2020 00:40:09 +0200 Subject: [PATCH] Use HTTP2 only for https urls --- apis/livepeer/livepeer.go | 6 ++---- cmd/streamtester/streamtester.go | 3 ++- internal/server/server.go | 2 +- internal/testers/http_load_tester.go | 7 ++++--- internal/testers/http_streamer.go | 9 +++++++-- internal/testers/m3utester.go | 12 ++++++++++-- mist/mist.go | 7 +++---- 7 files changed, 29 insertions(+), 17 deletions(-) diff --git a/apis/livepeer/livepeer.go b/apis/livepeer/livepeer.go index d316774a..74af5e85 100644 --- a/apis/livepeer/livepeer.go +++ b/apis/livepeer/livepeer.go @@ -3,7 +3,6 @@ package livepeer import ( "bytes" - "crypto/tls" "encoding/json" "fmt" "io/ioutil" @@ -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 ( diff --git a/cmd/streamtester/streamtester.go b/cmd/streamtester/streamtester.go index fa8485df..48264d2e 100644 --- a/cmd/streamtester/streamtester.go +++ b/cmd/streamtester/streamtester.go @@ -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:], @@ -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 { diff --git a/internal/server/server.go b/internal/server/server.go index 03034f77..24752dab 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -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) } diff --git a/internal/testers/http_load_tester.go b/internal/testers/http_load_tester.go index 75a5f53d..acd3156e 100644 --- a/internal/testers/http_load_tester.go +++ b/internal/testers/http_load_tester.go @@ -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 @@ -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) diff --git a/internal/testers/http_streamer.go b/internal/testers/http_streamer.go index cd64e2c5..d27c3735 100644 --- a/internal/testers/http_streamer.go +++ b/internal/testers/http_streamer.go @@ -14,6 +14,7 @@ import ( "os" "path" "strconv" + "strings" "sync" "time" @@ -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) @@ -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 diff --git a/internal/testers/m3utester.go b/internal/testers/m3utester.go index 065ef535..1238fcee 100644 --- a/internal/testers/m3utester.go +++ b/internal/testers/m3utester.go @@ -2,7 +2,6 @@ package testers import ( "bytes" - "crypto/tls" "fmt" "io" "io/ioutil" @@ -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, } diff --git a/mist/mist.go b/mist/mist.go index f6b4c0f3..4f6b15c4 100644 --- a/mist/mist.go +++ b/mist/mist.go @@ -3,7 +3,6 @@ package mist import ( "crypto/md5" - "crypto/tls" "encoding/hex" "encoding/json" "fmt" @@ -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 (