Skip to content

Commit

Permalink
fix sdk parse domain name fail because boostssl don't support domain …
Browse files Browse the repository at this point in the history
…name
  • Loading branch information
LucasLi1024 committed Jan 29, 2024
1 parent ec0a5d6 commit 0d1de5e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
23 changes: 20 additions & 3 deletions bcos-boostssl/bcos-boostssl/websocket/WsInitializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <bcos-utilities/BoostLog.h>
#include <bcos-utilities/IOServicePool.h>
#include <bcos-utilities/ThreadPool.h>
#include <boost/system/detail/error_code.hpp>
#include <cstddef>
#include <memory>

Expand Down Expand Up @@ -130,16 +131,32 @@ 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("connected size", connectPeers ? connectPeers->size() : 0);
<< LOG_KV("connected endpoints size", connectPeers ? connectPeers->size() : 0);

if (connectPeers)
{
for (const auto& peer : *connectPeers)
{
if (!WsTools::validIP(peer.address()))
{
BOOST_THROW_EXCEPTION(InvalidParameter() << errinfo_comment(
"invalid connected peer, value: " + peer.address()));
boost::system::error_code err;

// test if the address domain name
boost::asio::ip::tcp::resolver::query qry(
peer.address(), boost::lexical_cast<std::string>(0));
resolver->resolve(qry, err);

if (err)
{
BOOST_THROW_EXCEPTION(InvalidParameter() << errinfo_comment(
"invalid connection host, ipv4/ipv6/domain name "
"support, current: " +
peer.address()));
}

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

if (!WsTools::validPort(peer.port()))
Expand Down
2 changes: 1 addition & 1 deletion bcos-boostssl/bcos-boostssl/websocket/WsTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class WsTools
return !static_cast<bool>(ec);
}

static bool validPort(uint16_t _port) { return _port > 1024; }
static bool validPort(uint16_t _port) { return _port > 0; }

static bool stringToEndPoint(const std::string& peer, NodeIPEndpoint& _endpoint);

Expand Down
2 changes: 1 addition & 1 deletion bcos-boostssl/test/unittests/websocket/WsConfigTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE(test_WsToolsTest)
BOOST_CHECK_EQUAL(WsTools::validIP("::1"), true);

BOOST_CHECK_EQUAL(WsTools::validPort(1111), true);
BOOST_CHECK_EQUAL(WsTools::validPort(10), false);
BOOST_CHECK_EQUAL(WsTools::validPort(10), true);
BOOST_CHECK_EQUAL(WsTools::validPort(65535), true);
}

Expand Down

0 comments on commit 0d1de5e

Please sign in to comment.