forked from quic-go/quic-go
accept the control stream and parse SETTINGS frame, for the H3 server
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user