Skip to content

Commit

Permalink
remove static modelName
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Oct 22, 2024
1 parent 6b09c39 commit 01453fd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bcos-boostssl/context/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


#define CONTEXT_LOG(LEVEL) BCOS_LOG(LEVEL) << LOG_BADGE(m_moduleName) << "[BOOSTSSL][CTX]"
#define NODEINFO_LOG(LEVEL) BCOS_LOG(LEVEL) << LOG_BADGE(m_moduleName) << "[BOOSTSSL][NODEINFO]"
#define NODEINFO_LOG(LEVEL) BCOS_LOG(LEVEL) << "[BOOSTSSL][NODEINFO]"

namespace bcos
{ // namespace bcos
Expand Down
5 changes: 0 additions & 5 deletions bcos-boostssl/context/NodeInfoTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ namespace boostssl
{
namespace context
{
static std::string m_moduleName = "DEFAULT";

class NodeInfoTools
{
public:
Expand All @@ -42,9 +40,6 @@ class NodeInfoTools

static std::function<bool(bool, boost::asio::ssl::verify_context&)> newVerifyCallback(
std::shared_ptr<std::string> nodeIDOut);

static std::string moduleName() { return m_moduleName; }
static void setModuleName(std::string _moduleName) { m_moduleName = _moduleName; }
};

} // namespace context
Expand Down
5 changes: 2 additions & 3 deletions bcos-boostssl/websocket/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <boost/beast/websocket.hpp>

#define BOOST_SSL_LOG(LEVEL) BCOS_LOG(LEVEL) << "[BOOSTSSL]"
#define WEBSOCKET_TOOL(LEVEL) BCOS_LOG(LEVEL) << LOG_BADGE(m_moduleName) << "[WS][TOOL]"
#define WEBSOCKET_TOOL(LEVEL) BCOS_LOG(LEVEL) << "[WS][TOOL]"
#define WEBSOCKET_CONNECTOR(LEVEL) BCOS_LOG(LEVEL) << LOG_BADGE(m_moduleName) << "[WS][CONNECTOR]"
#define WEBSOCKET_VERSION(LEVEL) BCOS_LOG(LEVEL) << LOG_BADGE(m_moduleName) << "[WS][VERSION]"
#define WEBSOCKET_SESSION(LEVEL) BCOS_LOG(LEVEL) << LOG_BADGE(m_moduleName) << "[WS][SESSION]"
Expand All @@ -36,8 +36,7 @@
#define WEBSOCKET_STREAM(LEVEL) BCOS_LOG(LEVEL) << LOG_BADGE(m_moduleName) << "[WS][STREAM]"
#define WEBSOCKET_SSL_STREAM(LEVEL) \
BCOS_LOG(LEVEL) << LOG_BADGE(m_moduleName) << "[WS][SSL][STREAM]"
#define WEBSOCKET_INITIALIZER(LEVEL) \
BCOS_LOG(LEVEL) << LOG_BADGE(m_moduleName) << "[WS][INITIALIZER]"
#define WEBSOCKET_INITIALIZER(LEVEL) BCOS_LOG(LEVEL) << "[WS][INITIALIZER]"

namespace bcos
{
Expand Down
22 changes: 12 additions & 10 deletions bcos-boostssl/websocket/WsInitializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ using namespace bcos::boostssl::http;
void WsInitializer::initWsService(WsService::Ptr _wsService)
{
std::shared_ptr<WsConfig> _config = m_config;
std::string m_moduleName = _config->moduleName();
auto messageFactory = m_messageFactory;
if (!messageFactory)
{
Expand Down Expand Up @@ -76,9 +75,7 @@ void WsInitializer::initWsService(WsService::Ptr _wsService)
auto threadPool = std::make_shared<ThreadPool>("t_ws_pool", threadPoolSize);

// init module_name for log
WsTools::setModuleName(m_moduleName);
NodeInfoTools::setModuleName(m_moduleName);
connector->setModuleName(m_moduleName);
connector->setModuleName(_config->moduleName());

std::shared_ptr<boost::asio::ssl::context> srvCtx = nullptr;
std::shared_ptr<boost::asio::ssl::context> clientCtx = nullptr;
Expand All @@ -87,8 +84,8 @@ void WsInitializer::initWsService(WsService::Ptr _wsService)
auto contextBuilder = std::make_shared<ContextBuilder>();

// init module_name for log
contextBuilder->setModuleName(m_moduleName);
_config->contextConfig()->setModuleName(m_moduleName);
contextBuilder->setModuleName(_config->moduleName());
_config->contextConfig()->setModuleName(_config->moduleName());

srvCtx = contextBuilder->buildSslContext(true, *_config->contextConfig());
clientCtx = contextBuilder->buildSslContext(false, *_config->contextConfig());
Expand All @@ -97,7 +94,8 @@ void WsInitializer::initWsService(WsService::Ptr _wsService)
if (_config->asServer())
{
WEBSOCKET_INITIALIZER(INFO)
<< LOG_BADGE("initWsService") << LOG_DESC("start websocket service as server");
<< LOG_BADGE("initWsService") << LOG_DESC("start websocket service as server")
<< LOG_KV("module", _config->moduleName());

if (!WsTools::validIP(_config->listenIP()))
{
Expand All @@ -114,7 +112,7 @@ void WsInitializer::initWsService(WsService::Ptr _wsService)

auto httpServerFactory = std::make_shared<HttpServerFactory>();
auto httpServer = httpServerFactory->buildHttpServer(_config->listenIP(),
_config->listenPort(), ioServicePool->getIOService(), srvCtx, m_moduleName);
_config->listenPort(), ioServicePool->getIOService(), srvCtx, _config->moduleName());
httpServer->setIOServicePool(ioServicePool);
httpServer->setDisableSsl(_config->disableSsl());
httpServer->setThreadPool(threadPool);
Expand All @@ -139,6 +137,7 @@ void WsInitializer::initWsService(WsService::Ptr _wsService)
auto connectPeers = _config->connectPeers();
WEBSOCKET_INITIALIZER(INFO)
<< LOG_BADGE("initWsService") << LOG_DESC("start websocket service as client")
<< LOG_KV("module", _config->moduleName())
<< LOG_KV("connected endpoints size", connectPeers ? connectPeers->size() : 0);

if (connectPeers)
Expand All @@ -164,6 +163,7 @@ void WsInitializer::initWsService(WsService::Ptr _wsService)

WEBSOCKET_INITIALIZER(INFO)
<< LOG_BADGE("initWsService") << LOG_DESC("domain name has been set")
<< LOG_KV("module", _config->moduleName())
<< LOG_KV("host", peer.address());
}

Expand All @@ -181,7 +181,8 @@ void WsInitializer::initWsService(WsService::Ptr _wsService)
else
{
WEBSOCKET_INITIALIZER(WARNING)
<< LOG_BADGE("initWsService") << LOG_DESC("there has no connected server config");
<< LOG_BADGE("initWsService") << LOG_DESC("there has no connected server config")
<< LOG_KV("module", _config->moduleName());
}
}

Expand All @@ -196,7 +197,8 @@ void WsInitializer::initWsService(WsService::Ptr _wsService)

WEBSOCKET_INITIALIZER(INFO)
<< LOG_BADGE("initWsService") << LOG_DESC("initializer for websocket service")
<< LOG_KV("listenIP", _config->listenIP()) << LOG_KV("listenPort", _config->listenPort())
<< LOG_KV("module", _config->moduleName()) << LOG_KV("listenIP", _config->listenIP())
<< LOG_KV("listenPort", _config->listenPort())
<< LOG_KV("disableSsl", _config->disableSsl()) << LOG_KV("server", _config->asServer())
<< LOG_KV("client", _config->asClient())
<< LOG_KV("threadPoolSize", _config->threadPoolSize())
Expand Down
4 changes: 0 additions & 4 deletions bcos-boostssl/websocket/WsTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ namespace boostssl
{
namespace ws
{
static std::string m_moduleName = "DEFAULT";
class WsTools
{
public:
Expand All @@ -54,9 +53,6 @@ class WsTools
static bool stringToEndPoint(const std::string& peer, NodeIPEndpoint& _endpoint);

static void close(boost::asio::ip::tcp::socket& skt);

static std::string moduleName() { return m_moduleName; }
static void setModuleName(std::string _moduleName) { m_moduleName = _moduleName; }
};
} // namespace ws
} // namespace boostssl
Expand Down

0 comments on commit 01453fd

Please sign in to comment.