From a2892167f0a0253b32c0aac6ce33425b3de2a918 Mon Sep 17 00:00:00 2001 From: lanthora Date: Mon, 21 Aug 2023 07:25:28 +0000 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=E6=97=B6?= =?UTF-8?q?=E6=8A=A5=E6=96=87=E5=BC=82=E5=B8=B8=E7=9B=B4=E6=8E=A5=E9=80=80?= =?UTF-8?q?=E5=87=BA=E8=BF=9B=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/client.cc | 18 ++++++++++++++---- src/utility/address.cc | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) 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; }