remove unused error codes and name the constants according to go style

ref #86
This commit is contained in:
Lucas Clemente
2016-05-16 20:41:56 +02:00
parent 565f4c9fda
commit f624592198
3 changed files with 14 additions and 34 deletions

View File

@@ -2,31 +2,11 @@ package errorcodes
import "github.com/lucas-clemente/quic-go/protocol"
// The error codes defined by QUIC
const (
QUIC_NO_ERROR = protocol.ErrorCode(0)
QUIC_INTERNAL_ERROR = protocol.ErrorCode(1)
QUIC_STREAM_DATA_AFTER_TERMINATION = protocol.ErrorCode(2)
// QUIC_SERVER_ERROR_PROCESSING_STREAM= There was some server error which halted stream processing.
// QUIC_MULTIPLE_TERMINATION_OFFSETS= The sender received two mismatching fin or reset offsets for a single stream.
// QUIC_BAD_APPLICATION_PAYLOAD= The sender received bad application data.
QUIC_INVALID_PACKET_HEADER = protocol.ErrorCode(3)
QUIC_INVALID_FRAME_DATA = protocol.ErrorCode(4)
QUIC_INVALID_FEC_DATA = protocol.ErrorCode(5)
QUIC_INVALID_RST_STREAM_DATA = protocol.ErrorCode(6)
QUIC_INVALID_CONNECTION_CLOSE_DATA = protocol.ErrorCode(7)
QUIC_INVALID_ACK_DATA = protocol.ErrorCode(9)
QUIC_DECRYPTION_FAILURE = protocol.ErrorCode(12)
QUIC_ENCRYPTION_FAILURE = protocol.ErrorCode(13)
QUIC_PACKET_TOO_LARGE = protocol.ErrorCode(14)
// QUIC_PACKET_FOR_NONEXISTENT_STREAM= Data was sent for a stream which did not exist.
QUIC_PEER_GOING_AWAY = protocol.ErrorCode(16)
QUIC_INVALID_STREAM_ID = protocol.ErrorCode(17)
QUIC_TOO_MANY_OPEN_STREAMS = protocol.ErrorCode(18)
QUIC_NETWORK_IDLE_TIMEOUT = protocol.ErrorCode(25)
QUIC_CRYPTO_TAGS_OUT_OF_ORDER = protocol.ErrorCode(29)
QUIC_CRYPTO_TOO_MANY_ENTRIES = protocol.ErrorCode(30)
QUIC_CRYPTO_INVALID_VALUE_LENGTH = protocol.ErrorCode(31)
QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = protocol.ErrorCode(32)
QUIC_INVALID_CRYPTO_MESSAGE_TYPE = protocol.ErrorCode(33)
// QUIC_SEQUENCE_NUMBER_LIMIT_REACHED= Transmitting an additional packet would cause a packet number to be reused.
InternalError = protocol.ErrorCode(1)
InvalidFrameData = protocol.ErrorCode(4)
DecryptionFailure = protocol.ErrorCode(12)
PeerGoingAway = protocol.ErrorCode(16)
NetworkIdleTimeout = protocol.ErrorCode(25)
)

View File

@@ -27,7 +27,7 @@ func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *publicHeader, r
plaintext, err := u.aead.Open(hdr.PacketNumber, publicHeaderBinary, ciphertext)
if err != nil {
// Wrap err in quicError so that public reset is sent by session
return nil, protocol.NewQuicError(errorcodes.QUIC_DECRYPTION_FAILURE, err.Error())
return nil, protocol.NewQuicError(errorcodes.DecryptionFailure, err.Error())
}
r = bytes.NewReader(plaintext)
@@ -71,7 +71,7 @@ ReadLoop:
case 0x07:
frame, err = frames.ParsePingFrame(r)
default:
err = protocol.NewQuicError(errorcodes.QUIC_INVALID_FRAME_DATA, fmt.Sprintf("unknown type byte 0x%x", typeByte))
err = protocol.NewQuicError(errorcodes.InvalidFrameData, fmt.Sprintf("unknown type byte 0x%x", typeByte))
}
}
if err != nil {

View File

@@ -149,7 +149,7 @@ func (s *Session) run() {
return
case p := <-s.receivedPackets:
err = s.handlePacketImpl(p.remoteAddr, p.publicHeader, p.data)
if qErr, ok := err.(*protocol.QuicError); ok && qErr.ErrorCode == errorcodes.QUIC_DECRYPTION_FAILURE {
if qErr, ok := err.(*protocol.QuicError); ok && qErr.ErrorCode == errorcodes.DecryptionFailure {
s.tryQueueingUndecryptablePacket(p)
continue
}
@@ -161,7 +161,7 @@ func (s *Session) run() {
case <-s.aeadChanged:
s.tryDecryptingQueuedPackets()
case <-time.After(s.connectionParametersManager.GetIdleConnectionStateLifetime()):
s.Close(protocol.NewQuicError(errorcodes.QUIC_NETWORK_IDLE_TIMEOUT, "No recent network activity."), true)
s.Close(protocol.NewQuicError(errorcodes.NetworkIdleTimeout, "No recent network activity."), true)
}
if err != nil {
@@ -363,7 +363,7 @@ func (s *Session) Close(e error, sendConnectionClose bool) error {
}
if e == nil {
e = protocol.NewQuicError(errorcodes.QUIC_PEER_GOING_AWAY, "peer going away")
e = protocol.NewQuicError(errorcodes.PeerGoingAway, "peer going away")
}
utils.Errorf("Closing session with error: %s", e.Error())
@@ -376,11 +376,11 @@ func (s *Session) Close(e error, sendConnectionClose bool) error {
errorCode = quicError.ErrorCode
reasonPhrase = e.Error()
} else {
errorCode = errorcodes.QUIC_INTERNAL_ERROR
errorCode = errorcodes.InternalError
}
s.closeStreamsWithError(e)
if errorCode == errorcodes.QUIC_DECRYPTION_FAILURE {
if errorCode == errorcodes.DecryptionFailure {
return s.sendPublicReset(s.lastRcvdPacketNumber)
}
@@ -621,7 +621,7 @@ func (s *Session) congestionAllowsSending() bool {
func (s *Session) tryQueueingUndecryptablePacket(p receivedPacket) {
utils.Debugf("Queueing packet 0x%x for later decryption", p.publicHeader.PacketNumber)
if len(s.undecryptablePackets)+1 >= protocol.MaxUndecryptablePackets {
s.Close(protocol.NewQuicError(errorcodes.QUIC_DECRYPTION_FAILURE, "too many undecryptable packets received"), true)
s.Close(protocol.NewQuicError(errorcodes.DecryptionFailure, "too many undecryptable packets received"), true)
}
s.undecryptablePackets = append(s.undecryptablePackets, p)
}