1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-11-10 21:22:20 +03:00
Files
mvfst/quic/QuicException.cpp
Matt Joras b2e1eedfd3 Mostly remove version negotiation
Summary:
Draft-19 onwards effectively punted version negotiation to QUICv2. Now receiving version negotiation on clients is treated as an immediate termination of the connection.

The transport parameter format has also changed to no longer include any reference to the QUIC version. To avoid us (Facebook) having to turn off QUIC traffic in production, our server needs to be able to parse these transport parameters from our older clients. To achieve this when parsing the transport parameters we will, as a temporary measure, check for the Facebook QUIC version to determine which transport parameter format we are parsing. Luckily for us the version we chose maps nicely to an implausible length for the transport parameters (0xface).

Note that this diff still has the client send the old transport parameter format, so that the rollout can be staged.

Reviewed By: yangchi

Differential Revision: D15203481

fbshipit-source-id: dfaaddc3acc76434461b04430b82a0902138c060
2019-05-10 12:55:28 -07:00

182 lines
6.1 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
#include <quic/QuicException.h>
#include <folly/Overload.h>
#include <glog/logging.h>
namespace quic {
QuicTransportException::QuicTransportException(
const std::string& msg,
TransportErrorCode errCode)
: std::runtime_error(msg), errCode_(errCode){};
QuicTransportException::QuicTransportException(
const char* msg,
TransportErrorCode errCode)
: std::runtime_error(msg), errCode_(errCode){};
QuicTransportException::QuicTransportException(
const std::string& msg,
TransportErrorCode errCode,
FrameType frameType)
: std::runtime_error(msg), errCode_(errCode), frameType_(frameType){};
QuicTransportException::QuicTransportException(
const char* msg,
TransportErrorCode errCode,
FrameType frameType)
: std::runtime_error(msg), errCode_(errCode), frameType_(frameType){};
QuicInternalException::QuicInternalException(
const std::string& msg,
LocalErrorCode errCode)
: std::runtime_error(msg), errorCode_(errCode){};
QuicInternalException::QuicInternalException(
const char* msg,
LocalErrorCode errCode)
: std::runtime_error(msg), errorCode_(errCode){};
QuicApplicationException::QuicApplicationException(
const std::string& msg,
ApplicationErrorCode errorCode)
: std::runtime_error(msg), errorCode_(errorCode){};
QuicApplicationException::QuicApplicationException(
const char* msg,
ApplicationErrorCode errorCode)
: std::runtime_error(msg), errorCode_(errorCode){};
std::string toString(LocalErrorCode code) {
switch (code) {
case LocalErrorCode::NO_ERROR:
return "No Error";
case LocalErrorCode::CONNECT_FAILED:
return "Connect failed";
case LocalErrorCode::CODEC_ERROR:
return "Codec Error";
case LocalErrorCode::STREAM_CLOSED:
return "Stream is closed";
case LocalErrorCode::STREAM_NOT_EXISTS:
return "Stream does not exist";
case LocalErrorCode::CREATING_EXISTING_STREAM:
return "Creating an existing stream";
case LocalErrorCode::SHUTTING_DOWN:
return "Shutting down";
case LocalErrorCode::RESET_CRYPTO_STREAM:
return "Reset the crypto stream";
case LocalErrorCode::CWND_OVERFLOW:
return "CWND overflow";
case LocalErrorCode::INFLIGHT_BYTES_OVERFLOW:
return "Inflight bytes overflow";
case LocalErrorCode::LOST_BYTES_OVERFLOW:
return "Lost bytes overflow";
case LocalErrorCode::NEW_VERSION_NEGOTIATED:
return "New version negotiatied";
case LocalErrorCode::INVALID_WRITE_CALLBACK:
return "Invalid write callback";
case LocalErrorCode::TLS_HANDSHAKE_FAILED:
return "TLS handshake failed";
case LocalErrorCode::APP_ERROR:
return "App error";
case LocalErrorCode::INTERNAL_ERROR:
return "Internal error";
case LocalErrorCode::TRANSPORT_ERROR:
return "Transport error";
case LocalErrorCode::INVALID_WRITE_DATA:
return "Invalid write data";
case LocalErrorCode::INVALID_STATE_TRANSITION:
return "Invalid state transition";
case LocalErrorCode::CONNECTION_CLOSED:
return "Connection closed";
case LocalErrorCode::EARLY_DATA_REJECTED:
return "Early data rejected";
case LocalErrorCode::CONNECTION_RESET:
return "Connection reset";
case LocalErrorCode::IDLE_TIMEOUT:
return "Idle timeout";
case LocalErrorCode::PACKET_NUMBER_ENCODING:
return "Packet number encoding";
case LocalErrorCode::INVALID_OPERATION:
return "Invalid operation";
case LocalErrorCode::STREAM_LIMIT_EXCEEDED:
return "Stream limit exceeded";
case LocalErrorCode::CONNECTION_ABANDONED:
return "Connection abandoned";
}
LOG(WARNING) << "toString has unhandled ErrorCode";
return "Unknown error";
}
std::string toString(TransportErrorCode code) {
switch (code) {
case TransportErrorCode::NO_ERROR:
return "No Error";
case TransportErrorCode::INTERNAL_ERROR:
return "Internal Error";
case TransportErrorCode::FLOW_CONTROL_ERROR:
return "Flow control error";
case TransportErrorCode::STREAM_LIMIT_ERROR:
return "Stream limit error";
case TransportErrorCode::STREAM_STATE_ERROR:
return "Stream State error";
case TransportErrorCode::FINAL_OFFSET_ERROR:
return "Final offset error";
case TransportErrorCode::FRAME_ENCODING_ERROR:
return "Frame format error";
case TransportErrorCode::TRANSPORT_PARAMETER_ERROR:
return "Transport parameter error";
case TransportErrorCode::VERSION_NEGOTIATION_ERROR:
return "Version negotiation error";
case TransportErrorCode::PROTOCOL_VIOLATION:
return "Protocol violation";
case TransportErrorCode::INVALID_MIGRATION:
return "Invalid migration";
case TransportErrorCode::TLS_HANDSHAKE_FAILED:
return "Handshake Failed";
case TransportErrorCode::TLS_FATAL_ALERT_GENERATED:
return "TLS Alert Sent";
case TransportErrorCode::TLS_FATAL_ALERT_RECEIVED:
return "TLS Alert Received";
}
LOG(WARNING) << "toString has unhandled ErrorCode";
return "Unknown error";
}
std::string toString(QuicErrorCode code) {
return folly::variant_match(
code,
[](ApplicationErrorCode errorCode) {
return folly::to<std::string>(errorCode);
},
[](LocalErrorCode errorCode) { return toString(errorCode); },
[](TransportErrorCode errorCode) { return toString(errorCode); });
}
std::string toString(
const std::pair<QuicErrorCode, folly::Optional<folly::StringPiece>>&
error) {
return folly::to<std::string>(
folly::variant_match(
error.first,
[](ApplicationErrorCode errorCode) {
return "ApplicationError: " + toString(errorCode) + ", ";
},
[](LocalErrorCode errorCode) {
return "LocalError: " + toString(errorCode) + ", ";
},
[](TransportErrorCode errorCode) {
return "TransportError: " + toString(errorCode) + ", ";
}),
error.second.value_or(folly::StringPiece()).toString());
}
} // namespace quic