Skip to content

Commit

Permalink
发送消息时报文异常直接退出进程
Browse files Browse the repository at this point in the history
  • Loading branch information
lanthora committed Aug 21, 2023
1 parent d986c24 commit 5b0748e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/core/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/utility/address.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 5b0748e

Please sign in to comment.