rename occurrences of session in HTTP/3 server and client

This commit is contained in:
Marten Seemann
2022-03-26 16:04:45 +01:00
parent 9bc32cd021
commit f68b38635a
2 changed files with 40 additions and 40 deletions

View File

@@ -59,7 +59,7 @@ type client struct {
decoder *qpack.Decoder
hostname string
session quic.EarlyConnection
conn quic.EarlyConnection
logger utils.Logger
}
@@ -101,9 +101,9 @@ func newClient(hostname string, tlsConf *tls.Config, opts *roundTripperOpts, con
func (c *client) dial(ctx context.Context) error {
var err error
if c.dialer != nil {
c.session, err = c.dialer(ctx, "udp", c.hostname, c.tlsConf, c.config)
c.conn, err = c.dialer(ctx, "udp", c.hostname, c.tlsConf, c.config)
} else {
c.session, err = dialAddr(ctx, c.hostname, c.tlsConf, c.config)
c.conn, err = dialAddr(ctx, c.hostname, c.tlsConf, c.config)
}
if err != nil {
return err
@@ -111,9 +111,9 @@ func (c *client) dial(ctx context.Context) error {
// send the SETTINGs frame, using 0-RTT data, if possible
go func() {
if err := c.setupSession(); err != nil {
c.logger.Debugf("Setting up session failed: %s", err)
c.session.CloseWithError(quic.ApplicationErrorCode(errorInternalError), "")
if err := c.setupConn(); err != nil {
c.logger.Debugf("Setting up connection failed: %s", err)
c.conn.CloseWithError(quic.ApplicationErrorCode(errorInternalError), "")
}
}()
@@ -121,9 +121,9 @@ func (c *client) dial(ctx context.Context) error {
return nil
}
func (c *client) setupSession() error {
func (c *client) setupConn() error {
// open the control stream
str, err := c.session.OpenUniStream()
str, err := c.conn.OpenUniStream()
if err != nil {
return err
}
@@ -137,7 +137,7 @@ func (c *client) setupSession() error {
func (c *client) handleUnidirectionalStreams() {
for {
str, err := c.session.AcceptUniStream(context.Background())
str, err := c.conn.AcceptUniStream(context.Background())
if err != nil {
c.logger.Debugf("accepting unidirectional stream failed: %s", err)
return
@@ -158,7 +158,7 @@ func (c *client) handleUnidirectionalStreams() {
return
case streamTypePushStream:
// We never increased the Push ID, so we don't expect any push streams.
c.session.CloseWithError(quic.ApplicationErrorCode(errorIDError), "")
c.conn.CloseWithError(quic.ApplicationErrorCode(errorIDError), "")
return
default:
str.CancelRead(quic.StreamErrorCode(errorStreamCreationError))
@@ -166,12 +166,12 @@ func (c *client) handleUnidirectionalStreams() {
}
f, err := parseNextFrame(str)
if err != nil {
c.session.CloseWithError(quic.ApplicationErrorCode(errorFrameError), "")
c.conn.CloseWithError(quic.ApplicationErrorCode(errorFrameError), "")
return
}
sf, ok := f.(*settingsFrame)
if !ok {
c.session.CloseWithError(quic.ApplicationErrorCode(errorMissingSettings), "")
c.conn.CloseWithError(quic.ApplicationErrorCode(errorMissingSettings), "")
return
}
if !sf.Datagram {
@@ -180,18 +180,18 @@ func (c *client) handleUnidirectionalStreams() {
// If datagram support was enabled on our side as well as on the server side,
// we can expect it to have been negotiated both on the transport and on the HTTP/3 layer.
// Note: ConnectionState() will block until the handshake is complete (relevant when using 0-RTT).
if c.opts.EnableDatagram && !c.session.ConnectionState().SupportsDatagrams {
c.session.CloseWithError(quic.ApplicationErrorCode(errorSettingsError), "missing QUIC Datagram support")
if c.opts.EnableDatagram && !c.conn.ConnectionState().SupportsDatagrams {
c.conn.CloseWithError(quic.ApplicationErrorCode(errorSettingsError), "missing QUIC Datagram support")
}
}()
}
}
func (c *client) Close() error {
if c.session == nil {
if c.conn == nil {
return nil
}
return c.session.CloseWithError(quic.ApplicationErrorCode(errorNoError), "")
return c.conn.CloseWithError(quic.ApplicationErrorCode(errorNoError), "")
}
func (c *client) maxHeaderBytes() uint64 {
@@ -221,13 +221,13 @@ func (c *client) RoundTrip(req *http.Request) (*http.Response, error) {
} else {
// wait for the handshake to complete
select {
case <-c.session.HandshakeComplete().Done():
case <-c.conn.HandshakeComplete().Done():
case <-req.Context().Done():
return nil, req.Context().Err()
}
}
str, err := c.session.OpenStreamSync(req.Context())
str, err := c.conn.OpenStreamSync(req.Context())
if err != nil {
return nil, err
}
@@ -256,7 +256,7 @@ func (c *client) RoundTrip(req *http.Request) (*http.Response, error) {
if rerr.err != nil {
reason = rerr.err.Error()
}
c.session.CloseWithError(quic.ApplicationErrorCode(rerr.connErr), reason)
c.conn.CloseWithError(quic.ApplicationErrorCode(rerr.connErr), reason)
}
}
return rsp, rerr.err
@@ -296,7 +296,7 @@ func (c *client) doRequest(
return nil, newConnError(errorGeneralProtocolError, err)
}
connState := qtls.ToTLSConnectionState(c.session.ConnectionState().TLS)
connState := qtls.ToTLSConnectionState(c.conn.ConnectionState().TLS)
res := &http.Response{
Proto: "HTTP/3",
ProtoMajor: 3,
@@ -317,7 +317,7 @@ func (c *client) doRequest(
}
}
respBody := newResponseBody(str, reqDone, func() {
c.session.CloseWithError(quic.ApplicationErrorCode(errorFrameUnexpected), "")
c.conn.CloseWithError(quic.ApplicationErrorCode(errorFrameUnexpected), "")
})
// Rules for when to set Content-Length are defined in https://tools.ietf.org/html/rfc7230#section-3.3.2.

View File

@@ -235,11 +235,11 @@ func (s *Server) serveImpl(startListener func() (quic.EarlyListener, error)) err
defer s.removeListener(&ln)
for {
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
if err != nil {
return err
}
go s.handleConn(sess)
go s.handleConn(conn)
}
}
@@ -334,11 +334,11 @@ func (s *Server) removeListener(l *quic.EarlyListener) {
s.mutex.Unlock()
}
func (s *Server) handleConn(sess quic.EarlyConnection) {
func (s *Server) handleConn(conn quic.EarlyConnection) {
decoder := qpack.NewDecoder(nil)
// send a SETTINGS frame
str, err := sess.OpenUniStream()
str, err := conn.OpenUniStream()
if err != nil {
s.logger.Debugf("Opening the control stream failed.")
return
@@ -348,19 +348,19 @@ func (s *Server) handleConn(sess quic.EarlyConnection) {
(&settingsFrame{Datagram: s.EnableDatagrams}).Write(buf)
str.Write(buf.Bytes())
go s.handleUnidirectionalStreams(sess)
go s.handleUnidirectionalStreams(conn)
// Process all requests immediately.
// It's the client's responsibility to decide which requests are eligible for 0-RTT.
for {
str, err := sess.AcceptStream(context.Background())
str, err := conn.AcceptStream(context.Background())
if err != nil {
s.logger.Debugf("Accepting stream failed: %s", err)
return
}
go func() {
rerr := s.handleRequest(sess, str, decoder, func() {
sess.CloseWithError(quic.ApplicationErrorCode(errorFrameUnexpected), "")
rerr := s.handleRequest(conn, str, decoder, func() {
conn.CloseWithError(quic.ApplicationErrorCode(errorFrameUnexpected), "")
})
if rerr.err != nil || rerr.streamErr != 0 || rerr.connErr != 0 {
s.logger.Debugf("Handling request failed: %s", err)
@@ -372,7 +372,7 @@ func (s *Server) handleConn(sess quic.EarlyConnection) {
if rerr.err != nil {
reason = rerr.err.Error()
}
sess.CloseWithError(quic.ApplicationErrorCode(rerr.connErr), reason)
conn.CloseWithError(quic.ApplicationErrorCode(rerr.connErr), reason)
}
return
}
@@ -381,9 +381,9 @@ func (s *Server) handleConn(sess quic.EarlyConnection) {
}
}
func (s *Server) handleUnidirectionalStreams(sess quic.EarlyConnection) {
func (s *Server) handleUnidirectionalStreams(conn quic.EarlyConnection) {
for {
str, err := sess.AcceptUniStream(context.Background())
str, err := conn.AcceptUniStream(context.Background())
if err != nil {
s.logger.Debugf("accepting unidirectional stream failed: %s", err)
return
@@ -403,7 +403,7 @@ func (s *Server) handleUnidirectionalStreams(sess quic.EarlyConnection) {
// TODO: check that only one stream of each type is opened.
return
case streamTypePushStream: // only the server can push
sess.CloseWithError(quic.ApplicationErrorCode(errorStreamCreationError), "")
conn.CloseWithError(quic.ApplicationErrorCode(errorStreamCreationError), "")
return
default:
str.CancelRead(quic.StreamErrorCode(errorStreamCreationError))
@@ -411,12 +411,12 @@ func (s *Server) handleUnidirectionalStreams(sess quic.EarlyConnection) {
}
f, err := parseNextFrame(str)
if err != nil {
sess.CloseWithError(quic.ApplicationErrorCode(errorFrameError), "")
conn.CloseWithError(quic.ApplicationErrorCode(errorFrameError), "")
return
}
sf, ok := f.(*settingsFrame)
if !ok {
sess.CloseWithError(quic.ApplicationErrorCode(errorMissingSettings), "")
conn.CloseWithError(quic.ApplicationErrorCode(errorMissingSettings), "")
return
}
if !sf.Datagram {
@@ -425,8 +425,8 @@ func (s *Server) handleUnidirectionalStreams(sess quic.EarlyConnection) {
// If datagram support was enabled on our side as well as on the client side,
// we can expect it to have been negotiated both on the transport and on the HTTP/3 layer.
// Note: ConnectionState() will block until the handshake is complete (relevant when using 0-RTT).
if s.EnableDatagrams && !sess.ConnectionState().SupportsDatagrams {
sess.CloseWithError(quic.ApplicationErrorCode(errorSettingsError), "missing QUIC Datagram support")
if s.EnableDatagrams && !conn.ConnectionState().SupportsDatagrams {
conn.CloseWithError(quic.ApplicationErrorCode(errorSettingsError), "missing QUIC Datagram support")
}
}(str)
}
@@ -439,7 +439,7 @@ func (s *Server) maxHeaderBytes() uint64 {
return uint64(s.Server.MaxHeaderBytes)
}
func (s *Server) handleRequest(sess quic.Connection, str quic.Stream, decoder *qpack.Decoder, onFrameError func()) requestError {
func (s *Server) handleRequest(conn quic.Connection, str quic.Stream, decoder *qpack.Decoder, onFrameError func()) requestError {
frame, err := parseNextFrame(str)
if err != nil {
return newStreamError(errorRequestIncomplete, err)
@@ -466,7 +466,7 @@ func (s *Server) handleRequest(sess quic.Connection, str quic.Stream, decoder *q
return newStreamError(errorGeneralProtocolError, err)
}
req.RemoteAddr = sess.RemoteAddr().String()
req.RemoteAddr = conn.RemoteAddr().String()
req.Body = newRequestBody(str, onFrameError)
if s.logger.Debug() {
@@ -477,7 +477,7 @@ func (s *Server) handleRequest(sess quic.Connection, str quic.Stream, decoder *q
ctx := str.Context()
ctx = context.WithValue(ctx, ServerContextKey, s)
ctx = context.WithValue(ctx, http.LocalAddrContextKey, sess.LocalAddr())
ctx = context.WithValue(ctx, http.LocalAddrContextKey, conn.LocalAddr())
req = req.WithContext(ctx)
r := newResponseWriter(str, s.logger)
defer func() {