Skip to content

Commit

Permalink
Updated to the latest version of WebSocketpp library.
Browse files Browse the repository at this point in the history
This seems to have fixed errors with ASIO: zaphoyd/websocketpp#794
  • Loading branch information
robotastic committed Jan 29, 2020
1 parent d4f08bf commit 92eab77
Show file tree
Hide file tree
Showing 34 changed files with 779 additions and 656 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Trunk Recorder ChangeLog
### Version 3.1.0
* Updated to the latest version of OP25.
* Updated P25 Recorder, P25 Trunking and SmartNet Trunking to use the double decimation technique from OP25. It should handle SDRs with a high sample rate better now.
* Made the Status Socket code an optional add. The WebSocket Library it uses is not longer being maintained and does not build on some systems.
* Updated to the latest version of the websocketpp library.

### Version 3.0.1
* Updated to the latest version of OP25. Supposed performance improvements.
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ project(Trunk-Recorder CXX C)



#add_definitions(-DWEBSOCKET_STATUS=true)
#set(WEBSOCKET_STATUS true)
add_definitions(-DWEBSOCKET_STATUS=true)
set(WEBSOCKET_STATUS true)

#select the release build type by default to get optimization flags
if(NOT CMAKE_BUILD_TYPE)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ Here are the different arguments:
- **callTimeout** - a Call will stop recording and save if it has not received anything on the control channel, after this many seconds. The default is 3.
- **logFile** - save the console output to a file. The options are *true* or *false*, without quotes. The default is *false*.
- **frequencyFormat** - the display format for frequencies to display in the console and log file. The options are *exp*, *mhz* & *hz*. The default is *exp*.
- **statusServer** - The URL for a WebSocket connect. Trunk Recorder will send JSON formatted update message to this address. HTTPS is currently not supported, but will be in the future. OpenMHz does not support this currently. [JSON format of messages](STATUS-JSON.md)
- **controlWarnRate** - Log the control channel decode rate when it falls bellow this threshold. The default is *10*. The value of *-1* will always log the decode rate.
- **statusAsString** - Show status as strings instead of numeric values The options are *true* or *false*, without quotes. The default is *false*.
- **statusAsString** - Show status as strings instead of numeric values The options are *true* or *false*, without quotes. The default is *true*.
- **statusServer** - The URL for a WebSocket connect. Trunk Recorder will send JSON formatted update message to this address. HTTPS is currently not supported, but will be in the future. OpenMHz does not support this currently. [JSON format of messages](STATUS-JSON.md)

**talkgroupsFile**

Expand Down
13 changes: 12 additions & 1 deletion lib/websocketpp/close.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ namespace status {
/// or reconnect to the same IP upon user action.
static value const try_again_later = 1013;

/// Indicates that the server was acting as a gateway or proxy and received
/// an invalid response from the upstream server. This is similar to 502
/// HTTP Status Code.
static value const bad_gateway = 1014;

/// An endpoint failed to perform a TLS handshake
/**
* Designated for use in applications expecting a status code to indicate
Expand Down Expand Up @@ -178,7 +183,7 @@ namespace status {
*/
inline bool reserved(value code) {
return ((code >= rsv_start && code <= rsv_end) ||
code == 1004 || code == 1014);
code == 1004);
}

/// First value in range that is always invalid on the wire
Expand Down Expand Up @@ -248,6 +253,12 @@ namespace status {
return "Extension required";
case internal_endpoint_error:
return "Internal endpoint error";
case service_restart:
return "Service restart";
case try_again_later:
return "Try again later";
case bad_gateway:
return "Bad gateway";
case tls_handshake:
return "TLS handshake failure";
case subprotocol_error:
Expand Down
16 changes: 13 additions & 3 deletions lib/websocketpp/common/asio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,19 @@ namespace lib {
bool is_neg(T duration) {
return duration.count() < 0;
}
inline lib::chrono::milliseconds milliseconds(long duration) {
return lib::chrono::milliseconds(duration);
}

// If boost believes it has std::chrono available it will use it
// so we should also use it for things that relate to boost, even
// if the library would otherwise use boost::chrono.
#if defined(BOOST_ASIO_HAS_STD_CHRONO)
inline std::chrono::milliseconds milliseconds(long duration) {
return std::chrono::milliseconds(duration);
}
#else
inline lib::chrono::milliseconds milliseconds(long duration) {
return lib::chrono::milliseconds(duration);
}
#endif
#else
// Using boost::asio <1.49 we pretend a deadline timer is a steady
// timer and wrap the negative detection and duration conversion
Expand Down
1 change: 0 additions & 1 deletion lib/websocketpp/common/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ namespace lib {
#ifdef _WEBSOCKETPP_CPP11_MEMORY_
using std::shared_ptr;
using std::weak_ptr;
using std::auto_ptr;
using std::enable_shared_from_this;
using std::static_pointer_cast;
using std::make_shared;
Expand Down
8 changes: 6 additions & 2 deletions lib/websocketpp/common/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@
#endif
#endif

#ifdef _WEBSOCKETPP_CPP11_THREAD_
#if defined(_WEBSOCKETPP_MINGW_THREAD_)
#include <mingw-threads/mingw.thread.h>
#include <mingw-threads/mingw.mutex.h>
#include <mingw-threads/mingw.condition_variable.h>
#elif defined(_WEBSOCKETPP_CPP11_THREAD_)
#include <thread>
#include <mutex>
#include <condition_variable>
Expand All @@ -64,7 +68,7 @@
namespace websocketpp {
namespace lib {

#ifdef _WEBSOCKETPP_CPP11_THREAD_
#if defined(_WEBSOCKETPP_CPP11_THREAD_) || defined(_WEBSOCKETPP_MINGW_THREAD_)
using std::mutex;
using std::lock_guard;
using std::thread;
Expand Down
14 changes: 13 additions & 1 deletion lib/websocketpp/config/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

// Loggers
#include <websocketpp/logger/basic.hpp>
#include <websocketpp/logger/levels.hpp>

// RNG
#include <websocketpp/random/none.hpp>
Expand Down Expand Up @@ -188,7 +189,18 @@ struct core {
static const websocketpp::log::level alog_level =
websocketpp::log::alevel::all ^ websocketpp::log::alevel::devel;

///
/// Size of the per-connection read buffer
/**
* Each connection has an internal buffer of this size. A larger value will
* result in fewer trips through the library and less CPU overhead at the
* expense of increased memory usage per connection.
*
* If your application primarily deals in very large messages you may want
* to try setting this value higher.
*
* If your application has a lot of connections or primarily deals in small
* messages you may want to try setting this smaller.
*/
static const size_t connection_read_buffer_size = 16384;

/// Drop connections immediately on protocol error.
Expand Down
21 changes: 6 additions & 15 deletions lib/websocketpp/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ class connection
};
public:

explicit connection(bool p_is_server, std::string const & ua, alog_type& alog,
elog_type& elog, rng_type & rng)
explicit connection(bool p_is_server, std::string const & ua, const lib::shared_ptr<alog_type>& alog,
const lib::shared_ptr<elog_type>& elog, rng_type & rng)
: transport_con_type(p_is_server, alog, elog)
, m_handle_read_frame(lib::bind(
&type::handle_read_frame,
Expand Down Expand Up @@ -329,7 +329,7 @@ class connection
, m_http_state(session::http_state::init)
, m_was_clean(false)
{
m_alog.write(log::alevel::devel,"connection constructor");
m_alog->write(log::alevel::devel,"connection constructor");
}

/// Get a shared pointer to this component
Expand Down Expand Up @@ -1486,7 +1486,7 @@ class connection
void log_err(log::level l, char const * msg, error_type const & ec) {
std::stringstream s;
s << msg << " error: " << ec << " (" << ec.message() << ")";
m_elog.write(l, s.str());
m_elog->write(l, s.str());
}

// internal handler functions
Expand Down Expand Up @@ -1603,8 +1603,8 @@ class connection
std::vector<std::string> m_requested_subprotocols;

bool const m_is_server;
alog_type& m_alog;
elog_type& m_elog;
const lib::shared_ptr<alog_type> m_alog;
const lib::shared_ptr<elog_type> m_elog;

rng_type & m_rng;

Expand Down Expand Up @@ -1633,15 +1633,6 @@ class connection
session::http_state::value m_http_state;

bool m_was_clean;

/// Whether or not this endpoint initiated the closing handshake.
bool m_closed_by_me;

/// ???
bool m_failed_by_me;

/// Whether or not this endpoint initiated the drop of the TCP connection
bool m_dropped_by_me;
};

} // namespace websocketpp
Expand Down
48 changes: 24 additions & 24 deletions lib/websocketpp/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class endpoint : public config::transport_type, public config::endpoint_base {
//friend connection;

explicit endpoint(bool p_is_server)
: m_alog(config::alog_level, log::channel_type_hint::access)
, m_elog(config::elog_level, log::channel_type_hint::error)
: m_alog(new alog_type(config::alog_level, log::channel_type_hint::access))
, m_elog(new elog_type(config::elog_level, log::channel_type_hint::error))
, m_user_agent(::websocketpp::user_agent)
, m_open_handshake_timeout_dur(config::timeout_open_handshake)
, m_close_handshake_timeout_dur(config::timeout_close_handshake)
Expand All @@ -99,12 +99,12 @@ class endpoint : public config::transport_type, public config::endpoint_base {
, m_max_http_body_size(config::max_http_body_size)
, m_is_server(p_is_server)
{
m_alog.set_channels(config::alog_level);
m_elog.set_channels(config::elog_level);
m_alog->set_channels(config::alog_level);
m_elog->set_channels(config::elog_level);

m_alog.write(log::alevel::devel, "endpoint constructor");
m_alog->write(log::alevel::devel, "endpoint constructor");

transport_type::init_logging(&m_alog, &m_elog);
transport_type::init_logging(m_alog, m_elog);
}


Expand Down Expand Up @@ -218,7 +218,7 @@ class endpoint : public config::transport_type, public config::endpoint_base {
* @param channels The channel value(s) to set
*/
void set_access_channels(log::level channels) {
m_alog.set_channels(channels);
m_alog->set_channels(channels);
}

/// Clear Access logging channels
Expand All @@ -229,7 +229,7 @@ class endpoint : public config::transport_type, public config::endpoint_base {
* @param channels The channel value(s) to clear
*/
void clear_access_channels(log::level channels) {
m_alog.clear_channels(channels);
m_alog->clear_channels(channels);
}

/// Set Error logging channel
Expand All @@ -240,7 +240,7 @@ class endpoint : public config::transport_type, public config::endpoint_base {
* @param channels The channel value(s) to set
*/
void set_error_channels(log::level channels) {
m_elog.set_channels(channels);
m_elog->set_channels(channels);
}

/// Clear Error logging channels
Expand All @@ -251,76 +251,76 @@ class endpoint : public config::transport_type, public config::endpoint_base {
* @param channels The channel value(s) to clear
*/
void clear_error_channels(log::level channels) {
m_elog.clear_channels(channels);
m_elog->clear_channels(channels);
}

/// Get reference to access logger
/**
* @return A reference to the access logger
*/
alog_type & get_alog() {
return m_alog;
return *m_alog;
}

/// Get reference to error logger
/**
* @return A reference to the error logger
*/
elog_type & get_elog() {
return m_elog;
return *m_elog;
}

/*************************/
/* Set Handler functions */
/*************************/

void set_open_handler(open_handler h) {
m_alog.write(log::alevel::devel,"set_open_handler");
m_alog->write(log::alevel::devel,"set_open_handler");
scoped_lock_type guard(m_mutex);
m_open_handler = h;
}
void set_close_handler(close_handler h) {
m_alog.write(log::alevel::devel,"set_close_handler");
m_alog->write(log::alevel::devel,"set_close_handler");
scoped_lock_type guard(m_mutex);
m_close_handler = h;
}
void set_fail_handler(fail_handler h) {
m_alog.write(log::alevel::devel,"set_fail_handler");
m_alog->write(log::alevel::devel,"set_fail_handler");
scoped_lock_type guard(m_mutex);
m_fail_handler = h;
}
void set_ping_handler(ping_handler h) {
m_alog.write(log::alevel::devel,"set_ping_handler");
m_alog->write(log::alevel::devel,"set_ping_handler");
scoped_lock_type guard(m_mutex);
m_ping_handler = h;
}
void set_pong_handler(pong_handler h) {
m_alog.write(log::alevel::devel,"set_pong_handler");
m_alog->write(log::alevel::devel,"set_pong_handler");
scoped_lock_type guard(m_mutex);
m_pong_handler = h;
}
void set_pong_timeout_handler(pong_timeout_handler h) {
m_alog.write(log::alevel::devel,"set_pong_timeout_handler");
m_alog->write(log::alevel::devel,"set_pong_timeout_handler");
scoped_lock_type guard(m_mutex);
m_pong_timeout_handler = h;
}
void set_interrupt_handler(interrupt_handler h) {
m_alog.write(log::alevel::devel,"set_interrupt_handler");
m_alog->write(log::alevel::devel,"set_interrupt_handler");
scoped_lock_type guard(m_mutex);
m_interrupt_handler = h;
}
void set_http_handler(http_handler h) {
m_alog.write(log::alevel::devel,"set_http_handler");
m_alog->write(log::alevel::devel,"set_http_handler");
scoped_lock_type guard(m_mutex);
m_http_handler = h;
}
void set_validate_handler(validate_handler h) {
m_alog.write(log::alevel::devel,"set_validate_handler");
m_alog->write(log::alevel::devel,"set_validate_handler");
scoped_lock_type guard(m_mutex);
m_validate_handler = h;
}
void set_message_handler(message_handler h) {
m_alog.write(log::alevel::devel,"set_message_handler");
m_alog->write(log::alevel::devel,"set_message_handler");
scoped_lock_type guard(m_mutex);
m_message_handler = h;
}
Expand Down Expand Up @@ -661,8 +661,8 @@ class endpoint : public config::transport_type, public config::endpoint_base {
protected:
connection_ptr create_connection();

alog_type m_alog;
elog_type m_elog;
lib::shared_ptr<alog_type> m_alog;
lib::shared_ptr<elog_type> m_elog;
private:
// dynamic settings
std::string m_user_agent;
Expand Down
1 change: 1 addition & 0 deletions lib/websocketpp/extensions/permessage_deflate/disabled.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define WEBSOCKETPP_EXTENSION_PERMESSAGE_DEFLATE_DISABLED_HPP

#include <websocketpp/common/cpp11.hpp>
#include <websocketpp/common/stdint.hpp>
#include <websocketpp/common/system_error.hpp>

#include <websocketpp/http/constants.hpp>
Expand Down
Loading

0 comments on commit 92eab77

Please sign in to comment.