forked from quic-go/quic-go
send ConnectionCloseFrame as a response to unhandled frames
This commit is contained in:
10
session.go
10
session.go
@@ -8,6 +8,7 @@ import (
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/errorcodes"
|
||||
"github.com/lucas-clemente/quic-go/frames"
|
||||
"github.com/lucas-clemente/quic-go/handshake"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
@@ -140,6 +141,7 @@ func (s *Session) HandlePacket(addr *net.UDPAddr, publicHeaderBinary []byte, pub
|
||||
err = fmt.Errorf("unknown frame type: %x", typeByte)
|
||||
}
|
||||
if err != nil {
|
||||
s.Close(errorcodes.QUIC_INVALID_FRAME_DATA)
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -228,6 +230,14 @@ func (s *Session) handleRstStreamFrame(r *bytes.Reader) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close closes the connection by sending a ConnectionClose frame
|
||||
func (s *Session) Close(errorCode protocol.ErrorCode) error {
|
||||
frame := &frames.ConnectionCloseFrame{
|
||||
ErrorCode: errorCode,
|
||||
}
|
||||
return s.SendFrame(frame)
|
||||
}
|
||||
|
||||
// SendFrame sends a frame to the client
|
||||
func (s *Session) SendFrame(frame frames.Frame) error {
|
||||
streamframe, ok := frame.(*frames.StreamFrame)
|
||||
|
||||
Reference in New Issue
Block a user