diff --git a/src/core/client.cc b/src/core/client.cc index 0fbde5d6..e1b8c11e 100644 --- a/src/core/client.cc +++ b/src/core/client.cc @@ -148,7 +148,7 @@ void Client::handleWebSocketMessage() { if (message.type == WebSocketMessageType::Open) { if (!this->localAddress.empty()) { if (startTunThread()) { - spdlog::critical("Start tun thread failed"); + spdlog::critical("Start tun thread with static address failed"); break; } continue; @@ -219,7 +219,11 @@ void Client::handleTunMessage() { void Client::sendDynamicAddressMessage() { Address address; - address.cidrUpdate(this->dynamicAddress); + if (address.cidrUpdate(this->dynamicAddress)) { + spdlog::critical("Cannot send invalid dynamic address"); + Candy::shutdown(); + return; + } DynamicAddressHeader header(address.getCidr()); header.updateHash(this->password); @@ -232,7 +236,11 @@ void Client::sendDynamicAddressMessage() { void Client::sendAuthMessage() { Address address; - address.cidrUpdate(this->localAddress); + if (address.cidrUpdate(this->localAddress)) { + spdlog::critical("Cannot send invalid auth address"); + Candy::shutdown(); + return; + } AuthHeader header(address.getIp()); header.updateHash(this->password); @@ -259,7 +267,9 @@ void Client::handleDynamicAddressMessage(WebSocketMessage &message) { } this->localAddress = address.getCidr(); - startTunThread(); + if (startTunThread()) { + spdlog::critical("Start tun thread with dynamic address failed"); + } } void Client::handleForwardMessage(WebSocketMessage &message) { diff --git a/src/utility/address.cc b/src/utility/address.cc index 6620112a..026616d4 100644 --- a/src/utility/address.cc +++ b/src/utility/address.cc @@ -8,7 +8,7 @@ namespace Candy { int Address::cidrUpdate(const std::string &cidr) { std::size_t pos = cidr.find('/'); if (pos == std::string::npos) { - spdlog::error("invalid cidr format"); + spdlog::error("invalid cidr format. cidr={0}", cidr); return -1; }