-
Notifications
You must be signed in to change notification settings - Fork 90
Issue #844 Add host information to log messages #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
f9317cc
f26dbd4
03dbdab
8591cfa
39ce52b
71bf39e
cbad73b
d690e70
e0fae07
7c9a453
c3941d8
afb50f6
f8c8e81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,14 +34,6 @@ namespace fc { namespace http { | |
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; | ||
|
||
|
@@ -76,14 +68,6 @@ namespace fc { namespace http { | |
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; | ||
|
||
|
@@ -116,8 +100,6 @@ namespace fc { namespace http { | |
typedef base::con_msg_manager_type con_msg_manager_type; | ||
typedef base::endpoint_msg_manager_type endpoint_msg_manager_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; | ||
|
||
|
@@ -158,8 +140,7 @@ namespace fc { namespace http { | |
|
||
virtual void send_message( const std::string& message )override | ||
{ | ||
idump((message)); | ||
//std::cerr<<"send: "<<message<<"\n"; | ||
idump( (message) ); | ||
auto ec = _ws_connection->send( message ); | ||
FC_ASSERT( !ec, "websocket send failed: ${msg}", ("msg",ec.message() ) ); | ||
} | ||
|
@@ -173,6 +154,14 @@ namespace fc { namespace http { | |
return _ws_connection->get_request_header(key); | ||
} | ||
|
||
virtual std::string get_host()override | ||
{ | ||
auto header = get_request_header("BS-Forwarded"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Header name should be configurable like @abitmore said, and absence of configured value means ignore all headers and use remote host of connection. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implemented a configurable header. Will need to adjust in bitshares-core to make use of it. |
||
if (header.length() > 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why 2? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because I love magic numbers. Perhaps you don't like 2, so I replaced it with 3. (actually replaced with !string::empty() ) |
||
return header; | ||
return _ws_connection->get_host(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will investigate. Please do not bother reviewing until I edit this comment. |
||
} | ||
|
||
T _ws_connection; | ||
}; | ||
|
||
|
@@ -198,12 +187,11 @@ namespace fc { namespace http { | |
_server_thread.async( [&](){ | ||
auto current_con = _connections.find(hdl); | ||
assert( current_con != _connections.end() ); | ||
wdump(("server")(msg->get_payload())); | ||
//std::cerr<<"recv: "<<msg->get_payload()<<"\n"; | ||
auto payload = msg->get_payload(); | ||
std::shared_ptr<websocket_connection> con = current_con->second; | ||
std::shared_ptr<websocket_connection> ws_con = current_con->second; | ||
wdump( ("server") (ws_con->get_host() ) (payload) ); | ||
++_pending_messages; | ||
auto f = fc::async([this,con,payload](){ if( _pending_messages ) --_pending_messages; con->on_message( payload ); }); | ||
auto f = fc::async([this,ws_con,payload](){ if( _pending_messages ) --_pending_messages; ws_con->on_message( payload ); }); | ||
if( _pending_messages > 100 ) | ||
f.wait(); | ||
}).wait(); | ||
|
@@ -222,11 +210,11 @@ namespace fc { namespace http { | |
auto con = _server.get_con_from_hdl(hdl); | ||
con->defer_http_response(); | ||
std::string request_body = con->get_request_body(); | ||
wdump(("server")(request_body)); | ||
wdump( ("server") (current_con->get_host()) (request_body) ); | ||
|
||
fc::async([current_con, request_body, con] { | ||
std::string response = current_con->on_http(request_body); | ||
idump((response)); | ||
idump( ("server") (current_con->get_host()) (response) ); | ||
con->set_body( response ); | ||
con->set_status( websocketpp::http::status_code::ok ); | ||
con->send_http_response(); | ||
|
@@ -334,8 +322,9 @@ namespace fc { namespace http { | |
auto current_con = _connections.find(hdl); | ||
assert( current_con != _connections.end() ); | ||
auto received = msg->get_payload(); | ||
std::shared_ptr<websocket_connection> con = current_con->second; | ||
fc::async([con,received](){ con->on_message( received ); }); | ||
std::shared_ptr<websocket_connection> ws_con = current_con->second; | ||
wdump( ("server") (ws_con->get_host()) (received) ) | ||
fc::async([ws_con,received](){ ws_con->on_message( received ); }); | ||
}).wait(); | ||
}); | ||
|
||
|
@@ -347,14 +336,14 @@ namespace fc { namespace http { | |
_on_connection( current_con ); | ||
|
||
auto con = _server.get_con_from_hdl(hdl); | ||
wdump(("server")(con->get_request_body())); | ||
wdump( ("server") (con->get_host()) (con->get_request_body()) ); | ||
auto response = current_con->on_http( con->get_request_body() ); | ||
idump((response)); | ||
idump( ("server") (current_con->get_host()) (response) ); | ||
con->set_body( response ); | ||
con->set_status( websocketpp::http::status_code::ok ); | ||
} catch ( const fc::exception& e ) | ||
{ | ||
edump((e.to_detail_string())); | ||
edump( (current_con->get_host()) (e.to_detail_string()) ); | ||
} | ||
current_con->closed(); | ||
|
||
|
@@ -428,7 +417,7 @@ namespace fc { namespace http { | |
_client.clear_access_channels( websocketpp::log::alevel::all ); | ||
_client.set_message_handler( [&]( connection_hdl hdl, message_ptr msg ){ | ||
_client_thread.async( [&](){ | ||
wdump((msg->get_payload())); | ||
wdump( (_connection->get_host()) (msg->get_payload()) ); | ||
//std::cerr<<"recv: "<<msg->get_payload()<<"\n"; | ||
auto received = msg->get_payload(); | ||
fc::async( [=](){ | ||
|
@@ -488,7 +477,7 @@ namespace fc { namespace http { | |
_client.clear_access_channels( websocketpp::log::alevel::all ); | ||
_client.set_message_handler( [&]( connection_hdl hdl, message_ptr msg ){ | ||
_client_thread.async( [&](){ | ||
wdump((msg->get_payload())); | ||
wdump( (_connection->get_host()) (msg->get_payload()) ); | ||
_connection->on_message( msg->get_payload() ); | ||
}).wait(); | ||
}); | ||
|
@@ -671,7 +660,7 @@ namespace fc { namespace http { | |
|
||
auto con = my->_client.get_connection( uri, ec ); | ||
|
||
if( ec ) FC_ASSERT( !ec, "error: ${e}", ("e",ec.message()) ); | ||
if( ec ) FC_ASSERT( !ec, "uri: ${uri} error: ${e}", ("uri", uri) ("e",ec.message()) ); | ||
|
||
my->_client.connect(con); | ||
my->_connected->wait(); | ||
|
@@ -698,7 +687,7 @@ namespace fc { namespace http { | |
|
||
auto con = smy->_client.get_connection( uri, ec ); | ||
if( ec ) | ||
FC_ASSERT( !ec, "error: ${e}", ("e",ec.message()) ); | ||
FC_ASSERT( !ec, "uri: ${uri} error: ${e}", ("uri", uri) ("e",ec.message()) ); | ||
smy->_client.connect(con); | ||
smy->_connected->wait(); | ||
return smy->_connection; | ||
|
@@ -721,7 +710,7 @@ namespace fc { namespace http { | |
auto con = my->_client.get_connection( uri, ec ); | ||
if( ec ) | ||
{ | ||
FC_ASSERT( !ec, "error: ${e}", ("e",ec.message()) ); | ||
FC_ASSERT( !ec, "uri: ${uri} error: ${e}", ("uri", uri) ("e",ec.message()) ); | ||
} | ||
my->_client.connect(con); | ||
my->_connected->wait(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at what I am doing here. I am attempting to get a "custom" header to help with the log message. This is untested code, but I would like some input to (in)validate my approach.