diff --git a/server/go.mod b/server/go.mod index dcb38e7..09af253 100644 --- a/server/go.mod +++ b/server/go.mod @@ -5,8 +5,8 @@ go 1.18 require ( github.com/abema/go-mp4 v0.7.2 github.com/kixelated/invoker v1.0.0 - github.com/lucas-clemente/quic-go v0.30.0 - github.com/marten-seemann/webtransport-go v0.2.0 + github.com/kixelated/quic-go v1.31.0 + github.com/kixelated/webtransport-go v1.4.1 github.com/zencoder/go-dash/v3 v3.0.2 ) @@ -24,11 +24,7 @@ require ( golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect - golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect + golang.org/x/sys v0.1.1-0.20221102194838-fc697a31fa06 // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/tools v0.1.12 // indirect ) - -replace github.com/lucas-clemente/quic-go => ../../quic-go - -replace github.com/marten-seemann/webtransport-go => ../../webtransport-go diff --git a/server/go.sum b/server/go.sum index 0e33684..fd6ebf9 100644 --- a/server/go.sum +++ b/server/go.sum @@ -68,11 +68,16 @@ github.com/kisielk/errcheck v1.4.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kixelated/invoker v1.0.0 h1:0wYlvK39yQPbkwIFy+YN41AhF89WOtGyWqV2pZB39xw= github.com/kixelated/invoker v1.0.0/go.mod h1:RjG3iqm/sKwZjOpcW4SGq+l+4DJCDR/yUtc70VjCRB8= +github.com/kixelated/quic-go v1.31.0 h1:O3JomeXPnLNSCNpZF415NWOyfpzbFfuvP6dlIDg8VEA= +github.com/kixelated/quic-go v1.31.0/go.mod h1:AO7pURnb8HXHmdalp5e09UxQfsuwseEhl0NLmwiSOFY= +github.com/kixelated/webtransport-go v1.4.1 h1:ZtY3P7hVe1wK5fAt71b+HHnNISFDcQ913v+bvaNATxA= +github.com/kixelated/webtransport-go v1.4.1/go.mod h1:6RV5pTXF7oP53T83bosSDsLdSdw31j5cfpMDqsO4D5k= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lucas-clemente/quic-go v0.31.0 h1:MfNp3fk0wjWRajw6quMFA3ap1AVtlU+2mtwmbVogB2M= github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/marten-seemann/qpack v0.3.0 h1:UiWstOgT8+znlkDPOg2+3rIuYXJ2CnGDkGUXN6ki6hE= @@ -198,8 +203,8 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.1-0.20221102194838-fc697a31fa06 h1:E1pm64FqQa4v8dHd/bAneyMkR4hk8LTJhoSlc5mc1cM= +golang.org/x/sys v0.1.1-0.20221102194838-fc697a31fa06/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/server/internal/warp/server.go b/server/internal/warp/server.go index 3cd1391..1b78d17 100644 --- a/server/internal/warp/server.go +++ b/server/internal/warp/server.go @@ -12,11 +12,11 @@ import ( "path/filepath" "github.com/kixelated/invoker" - "github.com/lucas-clemente/quic-go" - "github.com/lucas-clemente/quic-go/http3" - "github.com/lucas-clemente/quic-go/logging" - "github.com/lucas-clemente/quic-go/qlog" - "github.com/marten-seemann/webtransport-go" + "github.com/kixelated/quic-go" + "github.com/kixelated/quic-go/http3" + "github.com/kixelated/quic-go/logging" + "github.com/kixelated/quic-go/qlog" + "github.com/kixelated/webtransport-go" ) type Server struct { @@ -70,33 +70,22 @@ func NewServer(config ServerConfig, media *Media) (s *Server, err error) { s.media = media mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - session, err := s.inner.Upgrade(w, r) + hijacker, ok := w.(http3.Hijacker) + if !ok { + panic("unable to hijack connection: must use kixelated/quic-go") + } + + conn := hijacker.Connection() + + sess, err := s.inner.Upgrade(w, r) if err != nil { http.Error(w, "failed to upgrade session", 500) return } - defer session.Close() - - hijacker, ok := w.(http3.Hijacker) - if !ok { - log.Printf("unable to hijack connection") - return - } - - conn := hijacker.Connection() - - ss, err := NewSession(conn, session, s.media) + err = s.serve(r.Context(), conn, sess) if err != nil { - log.Printf("failed to create session: %s", err) - return - } - - // Run the session in parallel, logging errors instead of crashing - err = ss.Run(r.Context()) - if err != nil { - log.Printf("terminated session: %s", err) - return + log.Println(err) } }) @@ -116,3 +105,25 @@ func (s *Server) runShutdown(ctx context.Context) (err error) { func (s *Server) Run(ctx context.Context) (err error) { return invoker.Run(ctx, s.runServe, s.runShutdown, s.sessions.Repeat) } + +func (s *Server) serve(ctx context.Context, conn quic.Connection, sess *webtransport.Session) (err error) { + defer func() { + if err != nil { + sess.CloseWithError(1, err.Error()) + } else { + sess.CloseWithError(0, "end of broadcast") + } + }() + + ss, err := NewSession(conn, sess, s.media) + if err != nil { + return fmt.Errorf("failed to create session: %w", err) + } + + err = ss.Run(ctx) + if err != nil { + return fmt.Errorf("terminated session: %w", err) + } + + return nil +} diff --git a/server/internal/warp/session.go b/server/internal/warp/session.go index 6a98b02..dac1cb1 100644 --- a/server/internal/warp/session.go +++ b/server/internal/warp/session.go @@ -12,8 +12,8 @@ import ( "time" "github.com/kixelated/invoker" - "github.com/lucas-clemente/quic-go" - "github.com/marten-seemann/webtransport-go" + "github.com/kixelated/quic-go" + "github.com/kixelated/webtransport-go" ) // A single WebTransport session @@ -38,8 +38,6 @@ func NewSession(connection quic.Connection, session *webtransport.Session, media } func (s *Session) Run(ctx context.Context) (err error) { - defer s.inner.Close() - s.inits, s.audio, s.video, err = s.media.Start(s.conn.GetMaxBandwidth) if err != nil { return fmt.Errorf("failed to start media: %w", err) diff --git a/server/internal/warp/stream.go b/server/internal/warp/stream.go index 34ff30c..2ba56b6 100644 --- a/server/internal/warp/stream.go +++ b/server/internal/warp/stream.go @@ -7,7 +7,7 @@ import ( "fmt" "sync" - "github.com/marten-seemann/webtransport-go" + "github.com/kixelated/webtransport-go" ) // Wrapper around quic.SendStream to make Write non-blocking. @@ -118,7 +118,7 @@ func (s *Stream) WriteMessage(msg Message) (err error) { return nil } -func (s *Stream) WriteCancel(code webtransport.ErrorCode) { +func (s *Stream) WriteCancel(code webtransport.StreamErrorCode) { s.inner.CancelWrite(code) }