mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
add socket/security policies to translate asio -> websocketpp error codes
The reason these were added to the socket policies rather than higher up is that in some cases translating error codes requires information from headers and libraries that are not present except when certain socket policies are being used. For example, SSL/TLS related errors can only be translated using openssl, which is only pulled in with the TLS socket policy.
This commit is contained in:
@@ -229,6 +229,23 @@ protected:
|
||||
lib::error_code get_ec() const {
|
||||
return lib::error_code();
|
||||
}
|
||||
|
||||
/// Translate any security policy specific information about an error code
|
||||
/**
|
||||
* Translate_ec takes a boost error code and attempts to convert its value
|
||||
* to an appropriate websocketpp error code. The plain socket policy does
|
||||
* not presently provide any additional information so all errors will be
|
||||
* reported as the generic transport pass_through error.
|
||||
*
|
||||
* @since 0.4.0-beta1
|
||||
*
|
||||
* @param ec The error code to translate_ec
|
||||
* @return The translated error code
|
||||
*/
|
||||
lib::error_code translate_ec(boost::system::error_code ec) {
|
||||
// We don't know any more information about this error so pass through
|
||||
return make_error_code(transport::error::pass_through);
|
||||
}
|
||||
private:
|
||||
enum state {
|
||||
UNINITIALIZED = 0,
|
||||
|
||||
@@ -284,6 +284,37 @@ protected:
|
||||
void async_shutdown(socket_shutdown_handler callback) {
|
||||
m_socket->async_shutdown(callback);
|
||||
}
|
||||
|
||||
/// Translate any security policy specific information about an error code
|
||||
/**
|
||||
* Translate_ec takes a boost error code and attempts to convert its value
|
||||
* to an appropriate websocketpp error code. Any error that is determined to
|
||||
* be related to TLS but does not have a more specific websocketpp error
|
||||
* code is returned under the catch all error "tls_error".
|
||||
*
|
||||
* Non-TLS related errors are returned as the transport generic pass_through
|
||||
* error.
|
||||
*
|
||||
* @since 0.4.0-beta1
|
||||
*
|
||||
* @param ec The error code to translate_ec
|
||||
* @return The translated error code
|
||||
*/
|
||||
lib::error_code translate_ec(boost::system::error_code ec) {
|
||||
if (ec.category() == boost::asio::error::get_ssl_category()) {
|
||||
if (ERR_GET_REASON(ec.value()) == SSL_R_SHORT_READ) {
|
||||
return make_error_code(transport::error::tls_short_read);
|
||||
} else {
|
||||
// We know it is a TLS related error, but otherwise don't know
|
||||
// more. Pass through as TLS generic.
|
||||
return make_error_code(transport::error::tls_error);
|
||||
}
|
||||
} else {
|
||||
// We don't know any more information about this error so pass
|
||||
// through
|
||||
return make_error_code(transport::error::pass_through);
|
||||
}
|
||||
}
|
||||
private:
|
||||
socket_type::handshake_type get_handshake_type() {
|
||||
if (m_is_server) {
|
||||
|
||||
Reference in New Issue
Block a user