send ConnectionCloseFrame as a response to unhandled frames

This commit is contained in:
Marten Seemann
2016-04-19 13:03:51 +07:00
parent ec64be840e
commit 600d3805a2
3 changed files with 44 additions and 0 deletions

View File

@@ -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)