Skip to content

Commit

Permalink
Merge pull request #107 from Shareong/main
Browse files Browse the repository at this point in the history
synchronize changes for ppcs
  • Loading branch information
Shareong committed Dec 12, 2023
2 parents 5d8fb05 + 88add5b commit b8dbda0
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 25 deletions.
2 changes: 1 addition & 1 deletion bcos-boostssl/context/NodeInfoTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ std::function<bool(bool, boost::asio::ssl::verify_context&)> NodeInfoTools::newV
(BASIC_CONSTRAINTS*)X509_get_ext_d2i(cert, NID_basic_constraints, &crit, NULL);
if (!basic)
{
NODEINFO_LOG(WARNING) << LOG_DESC("Get ca basic failed");
NODEINFO_LOG(INFO) << LOG_DESC("Get ca basic failed");
return preverified;
}

Expand Down
15 changes: 8 additions & 7 deletions bcos-boostssl/httpserver/HttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <bcos-boostssl/context/NodeInfoTools.h>
#include <bcos-boostssl/httpserver/HttpServer.h>
#include <bcos-utilities/ThreadPool.h>
#include <memory>

using namespace bcos;
using namespace bcos::boostssl;
Expand Down Expand Up @@ -114,16 +113,18 @@ void HttpServer::onAccept(boost::beast::error_code ec, boost::asio::ip::tcp::soc

boost::system::error_code sec;
auto localEndpoint = socket.local_endpoint(sec);
if(sec) {
HTTP_SERVER(WARNING) << LOG_BADGE("accept") << LOG_KV("local_endpoint error", sec)
<< LOG_KV("message", sec.message());
if (sec)
{
HTTP_SERVER(DEBUG) << LOG_BADGE("accept") << LOG_KV("local_endpoint error", sec)
<< LOG_KV("message", sec.message());
ws::WsTools::close(socket);
return doAccept();
}
auto remoteEndpoint = socket.remote_endpoint(sec);
if(sec) {
HTTP_SERVER(WARNING) << LOG_BADGE("accept") << LOG_KV("remote_endpoint error", sec)
<< LOG_KV("message", sec.message());
if (sec)
{
HTTP_SERVER(DEBUG) << LOG_BADGE("accept") << LOG_KV("remote_endpoint error", sec)
<< LOG_KV("message", sec.message());
ws::WsTools::close(socket);
return doAccept();
}
Expand Down
8 changes: 4 additions & 4 deletions bcos-boostssl/httpserver/HttpSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class HttpSession : public std::enable_shared_from_this<HttpSession>

if (ec)
{
HTTP_SESSION(WARNING) << LOG_BADGE("onRead") << LOG_DESC("close the connection")
<< LOG_KV("error", ec);
HTTP_SESSION(INFO) << LOG_BADGE("onRead") << LOG_DESC("close the connection")
<< LOG_KV("error", ec);
// return doClose();
return;
}
Expand Down Expand Up @@ -144,8 +144,8 @@ class HttpSession : public std::enable_shared_from_this<HttpSession>

if (ec)
{
HTTP_SESSION(WARNING) << LOG_BADGE("onWrite") << LOG_DESC("close the connection")
<< LOG_KV("error", ec);
HTTP_SESSION(INFO) << LOG_BADGE("onWrite") << LOG_DESC("close the connection")
<< LOG_KV("error", ec);
// return doClose();
return;
}
Expand Down
1 change: 1 addition & 0 deletions bcos-boostssl/websocket/WsConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <memory>
#include <vector>

#define HEART_BEAT_MSG_TYPE (0xFFFF)
#define MIN_HEART_BEAT_PERIOD_MS (10000)
#define MIN_RECONNECT_PERIOD_MS (10000)
#define DEFAULT_MESSAGE_TIMEOUT_MS (-1)
Expand Down
6 changes: 3 additions & 3 deletions bcos-boostssl/websocket/WsConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ void WsConnector::connectToWsServer(const std::string& _host, uint16_t _port, bo
boost::asio::ip::tcp::resolver::results_type::endpoint_type _ep) mutable {
if (_ec)
{
WEBSOCKET_CONNECTOR(WARNING)
<< LOG_BADGE("connectToWsServer") << LOG_DESC("async_connect failed")
<< LOG_KV("error", _ec.message()) << LOG_KV("endpoint", endpoint);
// WEBSOCKET_CONNECTOR(WARNING)
// << LOG_BADGE("connectToWsServer") << LOG_DESC("async_connect failed")
// << LOG_KV("error", _ec.message()) << LOG_KV("endpoint", endpoint);
_callback(_ec, "", nullptr, nullptr);
connector->erasePendingConns(endpoint);
return;
Expand Down
34 changes: 25 additions & 9 deletions bcos-boostssl/websocket/WsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ void WsService::start()
if (service)
{
service->reconnect();
// send heartbeat message
auto msg = service->messageFactory()->buildMessage();
msg->setPacketType(HEART_BEAT_MSG_TYPE);
service->broadcastMessage(std::move(msg));
}
},
m_config->reconnectPeriod(), m_config->reconnectPeriod());
Expand Down Expand Up @@ -333,6 +337,10 @@ void WsService::reconnect()

bool WsService::registerMsgHandler(uint16_t _msgType, MsgHandler _msgHandler)
{
if (_msgType == HEART_BEAT_MSG_TYPE)
{
BOOST_THROW_EXCEPTION(std::runtime_error("65535 is occupied by heartbeat message"));
}
UpgradableGuard l(x_msgTypeHandlers);
if (m_msgType2Method.count(_msgType) || !_msgHandler)
{
Expand Down Expand Up @@ -541,11 +549,19 @@ void WsService::onRecvMessage(
}
else
{
WEBSOCKET_SERVICE(WARNING)
<< LOG_BADGE("onRecvMessage") << LOG_DESC("unrecognized message type")
<< LOG_KV("type", _msg->packetType()) << LOG_KV("endpoint", _session->endPoint())
<< LOG_KV("seq", seq) << LOG_KV("data size", _msg->payload()->size())
<< LOG_KV("use_count", _session.use_count());
if (_msg->packetType() == HEART_BEAT_MSG_TYPE)
{
WEBSOCKET_SERVICE(INFO)
<< LOG_BADGE("onRecvMessage") << LOG_DESC("heartbeat message received");
}
else
{
WEBSOCKET_SERVICE(INFO)
<< LOG_BADGE("onRecvMessage") << LOG_DESC("unrecognized message type")
<< LOG_KV("type", _msg->packetType()) << LOG_KV("endpoint", _session->endPoint())
<< LOG_KV("seq", seq) << LOG_KV("data size", _msg->payload()->size())
<< LOG_KV("use_count", _session.use_count());
}
}
}

Expand Down Expand Up @@ -633,11 +649,11 @@ void WsService::asyncSendMessage(const WsSessions& _ss, std::shared_ptr<boostssl
std::shared_ptr<WsSession> _session) {
if (_error && _error->errorCode() != 0)
{
BOOST_SSL_LOG(WARNING)
BOOST_SSL_LOG(INFO)
<< LOG_BADGE(moduleName) << LOG_BADGE("asyncSendMessage")
<< LOG_DESC("callback error") << LOG_KV("endpoint", endPoint)
<< LOG_KV("errorCode", _error->errorCode())
<< LOG_KV("errorMessage", _error->errorMessage());
<< LOG_DESC("asyncSendMessage failed") << LOG_KV("endpoint", endPoint)
<< LOG_KV("code", _error->errorCode())
<< LOG_KV("message", _error->errorMessage());

if (self->respFunc)
{
Expand Down
2 changes: 1 addition & 1 deletion bcos-boostssl/websocket/WsStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class WsStream
// Note: make it config
opt.handshake_timeout = std::chrono::milliseconds(30000);
// idle time
opt.idle_timeout = std::chrono::milliseconds(10000);
opt.idle_timeout = boost::beast::websocket::stream_base::none();
// open ping/pong option
opt.keep_alive_pings = true;

Expand Down

0 comments on commit b8dbda0

Please sign in to comment.