Skip to content

Commit

Permalink
remove module name
Browse files Browse the repository at this point in the history
  • Loading branch information
ywy2090 committed Oct 19, 2024
1 parent 09698b0 commit 859ccb0
Show file tree
Hide file tree
Showing 28 changed files with 66 additions and 139 deletions.
4 changes: 2 additions & 2 deletions bcos-boostssl/bcos-boostssl/context/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include <openssl/pem.h>


#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 CONTEXT_LOG(LEVEL) BCOS_LOG(LEVEL) << "[BOOSTSSL][CTX]"
#define NODEINFO_LOG(LEVEL) BCOS_LOG(LEVEL) << "[BOOSTSSL][NODEINFO]"

namespace bcos::boostssl
{
Expand Down
6 changes: 0 additions & 6 deletions bcos-boostssl/bcos-boostssl/context/ContextBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ class ContextBuilder
public:
std::string readFileContent(boost::filesystem::path const& _file);

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

public:
std::shared_ptr<boost::asio::ssl::context> buildSslContext(
bool _server, const std::string& _configPath);
Expand All @@ -51,9 +48,6 @@ class ContextBuilder
const ContextConfig::CertConfig& _certConfig);
std::shared_ptr<boost::asio::ssl::context> buildSslContextByCertContent(
bool _server, const ContextConfig::SMCertConfig& _smCertConfig);

private:
std::string m_moduleName = "DEFAULT";
};

} // namespace bcos::boostssl::context
5 changes: 0 additions & 5 deletions bcos-boostssl/bcos-boostssl/context/ContextConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ class ContextConfig
const SMCertConfig& smCertConfig() const { return m_smCertConfig; }
void setSmCertConfig(const SMCertConfig& _smCertConfig) { m_smCertConfig = _smCertConfig; }

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


private:
// is the cert path or cert file content
bool m_isCertPath = true;
Expand All @@ -79,7 +75,6 @@ class ContextConfig
// cert config for ssl
CertConfig m_certConfig;
SMCertConfig m_smCertConfig;
std::string m_moduleName = "DEFAULT";
};

} // namespace bcos::boostssl::context
5 changes: 0 additions & 5 deletions bcos-boostssl/bcos-boostssl/context/NodeInfoTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace bcos::boostssl::context
{
static std::string m_moduleName = "DEFAULT";

class NodeInfoTools
{
public:
Expand All @@ -38,9 +36,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 bcos
8 changes: 4 additions & 4 deletions bcos-boostssl/bcos-boostssl/httpserver/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
#include <boost/beast/http/vector_body.hpp>


#define HTTP_LISTEN(LEVEL) BCOS_LOG(LEVEL) << LOG_BADGE(m_moduleName) << "[HTTP][LISTEN]"
#define HTTP_SESSION(LEVEL) BCOS_LOG(LEVEL) << LOG_BADGE(m_moduleName) << "[HTTP][SESSION]"
#define HTTP_SERVER(LEVEL) BCOS_LOG(LEVEL) << LOG_BADGE(m_moduleName) << "[HTTP][SERVER]"
#define HTTP_STREAM(LEVEL) BCOS_LOG(LEVEL) << LOG_BADGE(m_moduleName) << "[HTTP][STREAM]"
#define HTTP_LISTEN(LEVEL) BCOS_LOG(LEVEL) << "[HTTP][LISTEN]"
#define HTTP_SESSION(LEVEL) BCOS_LOG(LEVEL) << "[HTTP][SESSION]"
#define HTTP_SERVER(LEVEL) BCOS_LOG(LEVEL) << "[HTTP][SERVER]"
#define HTTP_STREAM(LEVEL) BCOS_LOG(LEVEL) << "[HTTP][STREAM]"


namespace bcos::boostssl::http
Expand Down
10 changes: 5 additions & 5 deletions bcos-boostssl/bcos-boostssl/httpserver/HttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void HttpServer::onAccept(boost::beast::error_code ec, boost::asio::ip::tcp::soc
if (!useSsl)
{ // non ssl , start http session
auto httpStream = m_httpStreamFactory->buildHttpStream(
std::make_shared<boost::beast::tcp_stream>(std::move(socket)), m_moduleName);
std::make_shared<boost::beast::tcp_stream>(std::move(socket)));
buildHttpSession(httpStream, nullptr)->run();

return doAccept();
Expand Down Expand Up @@ -169,7 +169,7 @@ void HttpServer::onAccept(boost::beast::error_code ec, boost::asio::ip::tcp::soc
auto server = self.lock();
if (server)
{
auto httpStream = server->httpStreamFactory()->buildHttpStream(ss, m_moduleName);
auto httpStream = server->httpStreamFactory()->buildHttpStream(ss);
server->buildHttpSession(httpStream, nodeId)->run();
}
});
Expand All @@ -181,7 +181,7 @@ void HttpServer::onAccept(boost::beast::error_code ec, boost::asio::ip::tcp::soc
HttpSession::Ptr HttpServer::buildHttpSession(
HttpStream::Ptr _httpStream, std::shared_ptr<std::string> _nodeId)
{
auto session = std::make_shared<HttpSession>(_httpStream->moduleName());
auto session = std::make_shared<HttpSession>();

auto queue = std::make_shared<Queue>();
auto self = std::weak_ptr<HttpSession>(session);
Expand Down Expand Up @@ -227,10 +227,10 @@ HttpSession::Ptr HttpServer::buildHttpSession(
*/
HttpServer::Ptr HttpServerFactory::buildHttpServer(const std::string& _listenIP,
uint16_t _listenPort, std::shared_ptr<boost::asio::io_context> _ioc,
std::shared_ptr<boost::asio::ssl::context> _ctx, std::string _moduleName)
std::shared_ptr<boost::asio::ssl::context> _ctx)
{
// create httpserver and launch a listening port
auto server = std::make_shared<HttpServer>(_listenIP, _listenPort, std::move(_moduleName));
auto server = std::make_shared<HttpServer>(_listenIP, _listenPort);
auto acceptor = std::make_shared<boost::asio::ip::tcp::acceptor>((*_ioc));
auto httpStreamFactory = std::make_shared<HttpStreamFactory>();
server->setCtx(std::move(_ctx));
Expand Down
10 changes: 3 additions & 7 deletions bcos-boostssl/bcos-boostssl/httpserver/HttpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ class HttpServer : public std::enable_shared_from_this<HttpServer>
using Ptr = std::shared_ptr<HttpServer>;

public:
HttpServer(std::string _listenIP, uint16_t _listenPort, std::string _moduleName)
HttpServer(std::string _listenIP, uint16_t _listenPort)
: m_listenIP(std::move(_listenIP)),
m_listenPort(_listenPort),
m_moduleName(std::move(_moduleName))
m_listenPort(_listenPort)
{}

~HttpServer() { stop(); }
Expand Down Expand Up @@ -86,8 +85,6 @@ class HttpServer : public std::enable_shared_from_this<HttpServer>
bool disableSsl() const { return m_disableSsl; }
void setDisableSsl(bool _disableSsl) { m_disableSsl = _disableSsl; }

std::string moduleName() { return m_moduleName; }

void setIOServicePool(bcos::IOServicePool::Ptr _ioservicePool)
{
m_ioservicePool = std::move(_ioservicePool);
Expand All @@ -97,7 +94,6 @@ class HttpServer : public std::enable_shared_from_this<HttpServer>
std::string m_listenIP;
uint16_t m_listenPort;
bool m_disableSsl = false;
std::string m_moduleName;

HttpReqHandler m_httpReqHandler;
WsUpgradeHandler m_wsUpgradeHandler;
Expand Down Expand Up @@ -126,7 +122,7 @@ class HttpServerFactory : public std::enable_shared_from_this<HttpServerFactory>
*/
HttpServer::Ptr buildHttpServer(const std::string& _listenIP, uint16_t _listenPort,
std::shared_ptr<boost::asio::io_context> _ioc,
std::shared_ptr<boost::asio::ssl::context> _ctx, std::string _moduleName);
std::shared_ptr<boost::asio::ssl::context> _ctx);
};

} // namespace bcos::boostssl::http
9 changes: 2 additions & 7 deletions bcos-boostssl/bcos-boostssl/httpserver/HttpSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class HttpSession : public std::enable_shared_from_this<HttpSession>
using Ptr = std::shared_ptr<HttpSession>;

public:
explicit HttpSession(std::string _moduleName) : m_moduleName(std::move(_moduleName))
explicit HttpSession()
{
HTTP_SESSION(DEBUG) << LOG_KV("[NEWOBJ][HTTPSESSION]", this);

Expand Down Expand Up @@ -202,7 +202,7 @@ class HttpSession : public std::enable_shared_from_this<HttpSession>
boost::beast::http::status::ok, version, std::move(_content));
// put the response into the queue and waiting to be send
session->queue()->enqueue(resp);
BCOS_LOG(TRACE) << LOG_BADGE(session->m_moduleName) << LOG_BADGE("handleRequest")
BCOS_LOG(TRACE) << LOG_BADGE("handleRequest")
<< LOG_DESC("response")
<< LOG_KV("body", std::string_view((const char*)resp->body().data(),
resp->body().size()))
Expand Down Expand Up @@ -269,9 +269,6 @@ class HttpSession : public std::enable_shared_from_this<HttpSession>
std::shared_ptr<std::string> nodeId() { return m_nodeId; }
void setNodeId(std::shared_ptr<std::string> _nodeId) { m_nodeId = std::move(_nodeId); }

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


private:
HttpStream::Ptr m_httpStream;
Expand All @@ -286,8 +283,6 @@ class HttpSession : public std::enable_shared_from_this<HttpSession>
boost::optional<boost::beast::http::request_parser<boost::beast::http::string_body>> m_parser;

std::shared_ptr<std::string> m_nodeId;

std::string m_moduleName = "DEFAULT";
};

} // namespace bcos::boostssl::http
25 changes: 8 additions & 17 deletions bcos-boostssl/bcos-boostssl/httpserver/HttpStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,8 @@ class HttpStream
return std::string("");
}

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


protected:
std::atomic<bool> m_closed{false};
std::string m_moduleName = "DEFAULT";
};

// The http stream
Expand All @@ -104,10 +99,9 @@ class HttpStreamImpl : public HttpStream, public std::enable_shared_from_this<Ht
using Ptr = std::shared_ptr<HttpStreamImpl>;

public:
HttpStreamImpl(std::shared_ptr<boost::beast::tcp_stream> _stream, std::string _moduleName)
HttpStreamImpl(std::shared_ptr<boost::beast::tcp_stream> _stream)
: m_stream(_stream)
{
setModuleName(_moduleName);
HTTP_STREAM(DEBUG) << LOG_KV("[NEWOBJ][HttpStreamImpl]", this);
}
virtual ~HttpStreamImpl()
Expand All @@ -123,7 +117,7 @@ class HttpStreamImpl : public HttpStream, public std::enable_shared_from_this<Ht
{
m_closed.store(true);
auto builder = std::make_shared<ws::WsStreamDelegateBuilder>();
return builder->build(m_stream, m_moduleName);
return builder->build(m_stream);
}

virtual bool open() override
Expand Down Expand Up @@ -175,11 +169,9 @@ class HttpStreamSslImpl : public HttpStream, public std::enable_shared_from_this
using Ptr = std::shared_ptr<HttpStreamSslImpl>;

public:
HttpStreamSslImpl(std::shared_ptr<boost::beast::ssl_stream<boost::beast::tcp_stream>> _stream,
std::string _moduleName)
HttpStreamSslImpl(std::shared_ptr<boost::beast::ssl_stream<boost::beast::tcp_stream>> _stream)
: m_stream(_stream)
{
setModuleName(_moduleName);
HTTP_STREAM(DEBUG) << LOG_KV("[NEWOBJ][HttpStreamSslImpl]", this);
}

Expand All @@ -196,7 +188,7 @@ class HttpStreamSslImpl : public HttpStream, public std::enable_shared_from_this
{
m_closed.store(true);
auto builder = std::make_shared<ws::WsStreamDelegateBuilder>();
return builder->build(m_stream, m_moduleName);
return builder->build(m_stream);
}

virtual bool open() override
Expand Down Expand Up @@ -249,16 +241,15 @@ class HttpStreamFactory

public:
HttpStream::Ptr buildHttpStream(
std::shared_ptr<boost::beast::tcp_stream> _stream, std::string _moduleName)
std::shared_ptr<boost::beast::tcp_stream> _stream)
{
return std::make_shared<HttpStreamImpl>(_stream, _moduleName);
return std::make_shared<HttpStreamImpl>(_stream);
}

HttpStream::Ptr buildHttpStream(
std::shared_ptr<boost::beast::ssl_stream<boost::beast::tcp_stream>> _stream,
std::string _moduleName)
std::shared_ptr<boost::beast::ssl_stream<boost::beast::tcp_stream>> _stream)
{
return std::make_shared<HttpStreamSslImpl>(_stream, _moduleName);
return std::make_shared<HttpStreamSslImpl>(_stream);
}
};
} // namespace bcos
16 changes: 8 additions & 8 deletions bcos-boostssl/bcos-boostssl/websocket/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
#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_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]"
#define WEBSOCKET_TOOL(LEVEL) BCOS_LOG(LEVEL) << "[WS][TOOL]"
#define WEBSOCKET_CONNECTOR(LEVEL) BCOS_LOG(LEVEL) << "[WS][CONNECTOR]"
#define WEBSOCKET_VERSION(LEVEL) BCOS_LOG(LEVEL) << "[WS][VERSION]"
#define WEBSOCKET_SESSION(LEVEL) BCOS_LOG(LEVEL) << "[WS][SESSION]"
#define WEBSOCKET_MESSAGE(LEVEL) BCOS_LOG(LEVEL) << "[WS][MESSAGE]"
#define WEBSOCKET_SERVICE(LEVEL) BCOS_LOG(LEVEL) << LOG_BADGE(m_moduleName) << "[WS][SERVICE]"
#define WEBSOCKET_STREAM(LEVEL) BCOS_LOG(LEVEL) << LOG_BADGE(m_moduleName) << "[WS][STREAM]"
#define WEBSOCKET_SERVICE(LEVEL) BCOS_LOG(LEVEL) << "[WS][SERVICE]"
#define WEBSOCKET_STREAM(LEVEL) BCOS_LOG(LEVEL) << "[WS][STREAM]"
#define WEBSOCKET_SSL_STREAM(LEVEL) \
BCOS_LOG(LEVEL) << LOG_BADGE(m_moduleName) << "[WS][SSL][STREAM]"
BCOS_LOG(LEVEL) << "[WS][SSL][STREAM]"
#define WEBSOCKET_INITIALIZER(LEVEL) \
BCOS_LOG(LEVEL) << LOG_BADGE(m_moduleName) << "[WS][INITIALIZER]"
BCOS_LOG(LEVEL) << "[WS][INITIALIZER]"

namespace bcos::boostssl::ws
{
Expand Down
5 changes: 0 additions & 5 deletions bcos-boostssl/bcos-boostssl/websocket/WsConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ class WsConfig
// the max message to be send or read
uint32_t m_maxMsgSize{DEFAULT_MAX_MESSAGE_SIZE};

std::string m_moduleName = "DEFAULT";

public:
void setModel(WsModel _model) { m_model = _model; }
WsModel model() const { return m_model; }
Expand Down Expand Up @@ -143,8 +141,5 @@ class WsConfig
{
m_contextConfig = std::move(_contextConfig);
}

std::string moduleName() { return m_moduleName; }
void setModuleName(std::string _moduleName) { m_moduleName = std::move(_moduleName); }
};
} // namespace bcos::boostssl::ws
2 changes: 1 addition & 1 deletion bcos-boostssl/bcos-boostssl/websocket/WsConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void WsConnector::connectToWsServer(const std::string& _host, uint16_t _port, bo
<< LOG_KV("endpoint", endpoint);

auto wsStreamDelegate =
builder->build(_disableSsl, ctx, rawStream, m_moduleName);
builder->build(_disableSsl, ctx, rawStream);

std::shared_ptr<std::string> nodeId = std::make_shared<std::string>();
wsStreamDelegate->setVerifyCallback(
Expand Down
6 changes: 1 addition & 5 deletions bcos-boostssl/bcos-boostssl/websocket/WsConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,14 @@ class WsConnector : public std::enable_shared_from_this<WsConnector>
}
std::shared_ptr<WsStreamDelegateBuilder> builder() const { return m_builder; }

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

private:
std::shared_ptr<WsStreamDelegateBuilder> m_builder;
std::shared_ptr<boost::asio::ip::tcp::resolver> m_resolver;
std::shared_ptr<boost::asio::ssl::context> m_ctx;

mutable std::mutex x_pendingConns;
std::set<std::string> m_pendingConns;

std::string m_moduleName = "DEFAULT";

IOServicePool::Ptr m_ioservicePool;
};
} // namespace bcos::boostssl::ws
14 changes: 3 additions & 11 deletions bcos-boostssl/bcos-boostssl/websocket/WsInitializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ 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 All @@ -68,21 +68,12 @@ void WsInitializer::initWsService(WsService::Ptr _wsService)

auto builder = std::make_shared<WsStreamDelegateBuilder>();

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

std::shared_ptr<boost::asio::ssl::context> srvCtx = nullptr;
std::shared_ptr<boost::asio::ssl::context> clientCtx = nullptr;
if (!_config->disableSsl())
{
auto contextBuilder = std::make_shared<ContextBuilder>();

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

srvCtx = contextBuilder->buildSslContext(true, *_config->contextConfig());
clientCtx = contextBuilder->buildSslContext(false, *_config->contextConfig());
}
Expand All @@ -107,7 +98,8 @@ 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);

httpServer->setIOServicePool(ioServicePool);
httpServer->setDisableSsl(_config->disableSsl());
httpServer->setWsUpgradeHandler(
Expand Down
Loading

0 comments on commit 859ccb0

Please sign in to comment.