diff --git a/packet_unpacker.go b/packet_unpacker.go index 85fc0390..f80ba61b 100644 --- a/packet_unpacker.go +++ b/packet_unpacker.go @@ -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.DecryptionFailure, err.Error()) + return nil, protocol.Error(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.InvalidFrameData, fmt.Sprintf("unknown type byte 0x%x", typeByte)) + err = protocol.Error(errorcodes.InvalidFrameData, fmt.Sprintf("unknown type byte 0x%x", typeByte)) } } if err != nil { diff --git a/protocol/quic_error.go b/protocol/quic_error.go index f8cb9212..4d75090e 100644 --- a/protocol/quic_error.go +++ b/protocol/quic_error.go @@ -6,8 +6,8 @@ type QuicError struct { ErrorMessage string } -// NewQuicError creates a new Quic Error -func NewQuicError(errorCode ErrorCode, errorMessage string) *QuicError { +// Error creates a new Quic Error +func Error(errorCode ErrorCode, errorMessage string) *QuicError { return &QuicError{ ErrorCode: errorCode, ErrorMessage: errorMessage, diff --git a/session.go b/session.go index a1224ad4..e0c859f2 100644 --- a/session.go +++ b/session.go @@ -161,7 +161,7 @@ func (s *Session) run() { case <-s.aeadChanged: s.tryDecryptingQueuedPackets() case <-time.After(s.connectionParametersManager.GetIdleConnectionStateLifetime()): - s.Close(protocol.NewQuicError(errorcodes.NetworkIdleTimeout, "No recent network activity."), true) + s.Close(protocol.Error(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.PeerGoingAway, "peer going away") + e = protocol.Error(errorcodes.PeerGoingAway, "peer going away") } utils.Errorf("Closing session with error: %s", e.Error()) @@ -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.DecryptionFailure, "too many undecryptable packets received"), true) + s.Close(protocol.Error(errorcodes.DecryptionFailure, "too many undecryptable packets received"), true) } s.undecryptablePackets = append(s.undecryptablePackets, p) }