move ErrorCode type to errorcodes package

This commit is contained in:
Lucas Clemente
2016-05-17 00:25:51 +02:00
parent fec9786939
commit 69e302812d
5 changed files with 21 additions and 15 deletions

View File

@@ -1,12 +1,15 @@
// Package errorcodes defines the error codes in QUIC.
//
package errorcodes
import "github.com/lucas-clemente/quic-go/protocol"
// An ErrorCode in QUIC
type ErrorCode uint32
// The error codes defined by QUIC
const (
InternalError protocol.ErrorCode = 1
InvalidFrameData protocol.ErrorCode = 4
DecryptionFailure protocol.ErrorCode = 12
PeerGoingAway protocol.ErrorCode = 16
NetworkIdleTimeout protocol.ErrorCode = 25
InternalError ErrorCode = 1
InvalidFrameData ErrorCode = 4
DecryptionFailure ErrorCode = 12
PeerGoingAway ErrorCode = 16
NetworkIdleTimeout ErrorCode = 25
)

View File

@@ -6,13 +6,14 @@ import (
"io"
"math"
"github.com/lucas-clemente/quic-go/errorcodes"
"github.com/lucas-clemente/quic-go/protocol"
"github.com/lucas-clemente/quic-go/utils"
)
// A ConnectionCloseFrame in QUIC
type ConnectionCloseFrame struct {
ErrorCode protocol.ErrorCode
ErrorCode errorcodes.ErrorCode
ReasonPhrase string
}
@@ -30,7 +31,7 @@ func ParseConnectionCloseFrame(r *bytes.Reader) (*ConnectionCloseFrame, error) {
if err != nil {
return nil, err
}
frame.ErrorCode = protocol.ErrorCode(errorCode)
frame.ErrorCode = errorcodes.ErrorCode(errorCode)
reasonPhraseLen, err := utils.ReadUint16(r)
if err != nil {

View File

@@ -3,6 +3,7 @@ package frames
import (
"bytes"
"github.com/lucas-clemente/quic-go/errorcodes"
"github.com/lucas-clemente/quic-go/protocol"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -14,7 +15,7 @@ var _ = Describe("ConnectionCloseFrame", func() {
b := bytes.NewReader([]byte{0x40, 0x19, 0x00, 0x00, 0x00, 0x1B, 0x00, 0x4e, 0x6f, 0x20, 0x72, 0x65, 0x63, 0x65, 0x6e, 0x74, 0x20, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x20, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x2e})
frame, err := ParseConnectionCloseFrame(b)
Expect(err).ToNot(HaveOccurred())
Expect(frame.ErrorCode).To(Equal(protocol.ErrorCode(0x19)))
Expect(frame.ErrorCode).To(Equal(errorcodes.ErrorCode(0x19)))
Expect(frame.ReasonPhrase).To(Equal("No recent network activity."))
Expect(b.Len()).To(Equal(0))
})
@@ -23,7 +24,7 @@ var _ = Describe("ConnectionCloseFrame", func() {
b := bytes.NewReader([]byte{0x02, 0xAD, 0xFB, 0xCA, 0xDE, 0x00, 0x00})
frame, err := ParseConnectionCloseFrame(b)
Expect(err).ToNot(HaveOccurred())
Expect(frame.ErrorCode).To(Equal(protocol.ErrorCode(0xDECAFBAD)))
Expect(frame.ErrorCode).To(Equal(errorcodes.ErrorCode(0xDECAFBAD)))
Expect(frame.ReasonPhrase).To(BeEmpty())
Expect(b.Len()).To(Equal(0))
})

View File

@@ -1,16 +1,17 @@
package protocol
// An ErrorCode in QUIC
type ErrorCode uint32
import (
"github.com/lucas-clemente/quic-go/errorcodes"
)
// A QuicError is a QUIC error
type QuicError struct {
ErrorCode ErrorCode
ErrorCode errorcodes.ErrorCode
ErrorMessage string
}
// Error creates a new Quic Error
func Error(errorCode ErrorCode, errorMessage string) *QuicError {
func Error(errorCode errorcodes.ErrorCode, errorMessage string) *QuicError {
return &QuicError{
ErrorCode: errorCode,
ErrorMessage: errorMessage,

View File

@@ -369,7 +369,7 @@ func (s *Session) Close(e error, sendConnectionClose bool) error {
// if e is a QUIC error, send it to the client
// else, send the generic QUIC internal error
var errorCode protocol.ErrorCode
var errorCode errorcodes.ErrorCode
var reasonPhrase string
quicError, ok := e.(*protocol.QuicError)
if ok {