Skip to content

Commit

Permalink
Update the websocketpp library and change the configuration options w…
Browse files Browse the repository at this point in the history
…e pass

when creating the websocket servers to enable deflate compression on
websocket frames.  This is relevant to cryptonomex/graphene#540 because
the spammed data is higly compressible.  In my tests, it reduces bandwidth
for a single idle node by a factor of ~16, from 577kbps down to 36kbps.
This doesn't require any changes to the wallets, simply upgrading the
public servers will begin sending compressed data to all clients that
support it.
Note: this commit adds a dependency on zlib for non-apple platforms
(it was already required on apple)
  • Loading branch information
emfrias committed Mar 3, 2016
1 parent 3841916 commit d5370fc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 54 deletions.
19 changes: 11 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ find_package(OpenSSL REQUIRED)

set( CMAKE_FIND_LIBRARY_SUFFIXES ${ORIGINAL_LIB_SUFFIXES} )

# We are now building in support for deflate compression into our websockets layer by default,
# which requires zlib. Aside from that, all of fc compiles without zlib, so this could be
# made optional without much effort
# (important exception, apple: as of 10.10 yosemite, the OpenSSL static libraries shipped with
# os x have a dependency on zlib)
# On a side note, fc's fc::zlib_compress() function uses a separate implementation of zlib
# from the miniz library. If we're comfortable requiring an external zlib, we can
# reimplement fc::zlib_compress() to call the real zlib, and remove miniz.c from our
# repository.
find_package( ZLIB REQUIRED )

option( UNITY_BUILD OFF )

set( fc_sources
Expand Down Expand Up @@ -473,14 +484,6 @@ if(WIN32)

endif(WIN32)

IF(APPLE)
# As of 10.10 yosemite, the OpenSSL static libraries shipped with os x have a dependency
# on zlib, so any time you link in openssl you also need to link zlib. . We really want to detect whether openssl was configured with the --no-zlib
# option or not when it was built, but that's difficult to do in practice, so we
# just always try to link it in on mac.
find_package( ZLIB REQUIRED )
ENDIF(APPLE)

SET(OPENSSL_CONF_TARGET )
IF(DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
SET (OPENSSL_CONF_TARGET ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
Expand Down
62 changes: 17 additions & 45 deletions src/network/http/websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <websocketpp/config/asio.hpp>
#include <websocketpp/server.hpp>
#include <websocketpp/config/asio_client.hpp>
#include <websocketpp/extensions/permessage_deflate/enabled.hpp>
#include <websocketpp/client.hpp>
#include <websocketpp/logger/stub.hpp>

Expand Down Expand Up @@ -61,47 +62,12 @@ namespace fc { namespace http {
transport_type;

static const long timeout_open_handshake = 0;
};
struct asio_tls_with_stub_log : public websocketpp::config::asio_tls {

typedef asio_with_stub_log type;
typedef asio_tls base;

typedef base::concurrency_type concurrency_type;

typedef base::request_type request_type;
typedef base::response_type response_type;

typedef base::message_type message_type;
typedef base::con_msg_manager_type con_msg_manager_type;
typedef base::endpoint_msg_manager_type endpoint_msg_manager_type;

/// Custom Logging policies
/*typedef websocketpp::log::syslog<concurrency_type,
websocketpp::log::elevel> elog_type;
typedef websocketpp::log::syslog<concurrency_type,
websocketpp::log::alevel> alog_type;
*/
//typedef base::alog_type alog_type;
//typedef base::elog_type elog_type;
typedef websocketpp::log::stub elog_type;
typedef websocketpp::log::stub alog_type;

typedef base::rng_type rng_type;
/// permessage_compress extension
struct permessage_deflate_config {};

struct transport_config : public base::transport_config {
typedef type::concurrency_type concurrency_type;
typedef type::alog_type alog_type;
typedef type::elog_type elog_type;
typedef type::request_type request_type;
typedef type::response_type response_type;
typedef websocketpp::transport::asio::tls_socket::endpoint socket_type;
};

typedef websocketpp::transport::asio::endpoint<transport_config>
transport_type;

static const long timeout_open_handshake = 0;
typedef websocketpp::extensions::permessage_deflate::enabled
<permessage_deflate_config> permessage_deflate_type;
};
struct asio_tls_stub_log : public websocketpp::config::asio_tls {
typedef asio_tls_stub_log type;
Expand All @@ -124,16 +90,22 @@ namespace fc { namespace http {
typedef base::rng_type rng_type;

struct transport_config : public base::transport_config {
typedef type::concurrency_type concurrency_type;
typedef type::alog_type alog_type;
typedef type::elog_type elog_type;
typedef type::request_type request_type;
typedef type::response_type response_type;
typedef websocketpp::transport::asio::tls_socket::endpoint socket_type;
typedef type::concurrency_type concurrency_type;
typedef type::alog_type alog_type;
typedef type::elog_type elog_type;
typedef type::request_type request_type;
typedef type::response_type response_type;
typedef websocketpp::transport::asio::tls_socket::endpoint socket_type;
};

typedef websocketpp::transport::asio::endpoint<transport_config>
transport_type;

/// permessage_compress extension
struct permessage_deflate_config {};

typedef websocketpp::extensions::permessage_deflate::enabled
<permessage_deflate_config> permessage_deflate_type;
};


Expand Down
2 changes: 1 addition & 1 deletion vendor/websocketpp
Submodule websocketpp updated 122 files

0 comments on commit d5370fc

Please sign in to comment.