accept the control stream and parse SETTINGS frame, for the H3 server

This commit is contained in:
Marten Seemann
2020-12-21 15:18:09 +07:00
parent 9693a46d31
commit bf54ffe0df
3 changed files with 166 additions and 4 deletions

View File

@@ -37,8 +37,9 @@ var (
)
const (
nextProtoH3Draft29 = "h3-29"
nextProtoH3Draft32 = "h3-32"
nextProtoH3Draft29 = "h3-29"
nextProtoH3Draft32 = "h3-32"
streamTypeControlStream = 0
)
func versionToALPN(v protocol.VersionNumber) string {
@@ -219,10 +220,13 @@ func (s *Server) handleConn(sess quic.EarlySession) {
s.logger.Debugf("Opening the control stream failed.")
return
}
buf := bytes.NewBuffer([]byte{0})
buf := &bytes.Buffer{}
utils.WriteVarInt(buf, streamTypeControlStream) // stream type
(&settingsFrame{}).Write(buf)
str.Write(buf.Bytes())
go s.handleUnidirectionalStreams(sess)
// Process all requests immediately.
// It's the client's responsibility to decide which requests are eligible for 0-RTT.
for {
@@ -254,6 +258,35 @@ func (s *Server) handleConn(sess quic.EarlySession) {
}
}
func (s *Server) handleUnidirectionalStreams(sess quic.EarlySession) {
for {
str, err := sess.AcceptUniStream(context.Background())
if err != nil {
s.logger.Debugf("accepting unidirectional stream failed: %s", err)
return
}
go func(str quic.ReceiveStream) {
streamType, err := utils.ReadVarInt(&byteReaderImpl{str})
if err != nil {
s.logger.Debugf("reading stream type on stream %d failed: %s", str.StreamID(), err)
return
}
if streamType != streamTypeControlStream {
return
}
f, err := parseNextFrame(str)
if err != nil {
sess.CloseWithError(quic.ErrorCode(errorFrameError), "")
return
}
if _, ok := f.(*settingsFrame); !ok {
sess.CloseWithError(quic.ErrorCode(errorMissingSettings), "")
}
}(str)
}
}
func (s *Server) maxHeaderBytes() uint64 {
if s.Server.MaxHeaderBytes <= 0 {
return http.DefaultMaxHeaderBytes