Compare commits

..
Author SHA1 Message Date
Morteza Bashsiz 698da19a8c Merge pull request #204 from MortezaBashsiz/revert-202-dev
Revert "Version 1.1.55"
2026-06-07 07:41:46 +02:00
Morteza Bashsiz 451a169756 Revert "Version 1.1.55" 2026-06-07 07:38:50 +02:00
5 changed files with 48 additions and 155 deletions

No files matched your search

+1 -1
View File
@@ -16,7 +16,7 @@ permissions:
contents: write
env:
PACKAGE_VERSION: 1.1.55
PACKAGE_VERSION: 1.1.54
jobs:
build-android:
+1 -1
View File
@@ -14,7 +14,7 @@ permissions:
contents: write
env:
PACKAGE_VERSION: 1.1.55
PACKAGE_VERSION: 1.1.54
jobs:
build:
+1 -1
View File
@@ -15,7 +15,7 @@ permissions:
contents: write
env:
PACKAGE_VERSION: 1.1.55
PACKAGE_VERSION: 1.1.54
jobs:
build-windows:
+14 -78
View File
@@ -4,8 +4,6 @@
#include <algorithm>
#include <cctype>
#include <chrono>
#include <memory>
#include <sstream>
#include <utility>
#include <vector>
@@ -95,16 +93,9 @@ bool TCPClient::enableTlsClient() {
}
}
bool TCPClient::doConnect(const std::string &dstIP,
unsigned short dstPort) {
try {
if (dstPort == 0) {
log_->write("[" + to_string(uuid_) +
"] [TCPClient doConnect] invalid destination port 0",
Log::Level::ERROR);
return false;
}
bool TCPClient::doConnect(const std::string &dstIp, unsigned short dstPort) {
try {
if (tlsEnabled_ && sslSocket_ && sslSocket_->lowest_layer().is_open()) {
return true;
}
@@ -113,15 +104,15 @@ bool TCPClient::doConnect(const std::string &dstIP,
return true;
}
log_->write("[" + to_string(uuid_) + "] [TCPClient doConnect] [DST " +
dstIP + ":" + std::to_string(dstPort) + "]",
log_->write("[" + to_string(uuid_) + "] [TCPClient doConnect] [DST " + dstIp +
":" + std::to_string(dstPort) + "]",
Log::Level::DEBUG);
boost::system::error_code error_code;
auto endpoints = resolver_.resolve(
dstIP,
std::to_string(dstPort),
auto endpoint = resolver_.resolve(
dstIp.c_str(),
std::to_string(dstPort).c_str(),
error_code);
if (error_code) {
@@ -132,90 +123,35 @@ bool TCPClient::doConnect(const std::string &dstIP,
return false;
}
auto timer = std::make_shared<boost::asio::steady_timer>(io_context_);
auto finished = std::make_shared<bool>(false);
auto connectError = std::make_shared<boost::system::error_code>();
auto closeSocket = [this]() {
boost::system::error_code ignored;
if (tlsEnabled_ && sslSocket_) {
sslSocket_->lowest_layer().cancel(ignored);
sslSocket_->lowest_layer().close(ignored);
} else {
socket_.cancel(ignored);
socket_.close(ignored);
}
};
timer->expires_after(std::chrono::seconds(5));
timer->async_wait([this, finished, closeSocket](
const boost::system::error_code &ec) {
if (ec) {
return;
}
if (!*finished) {
log_->write("[" + to_string(uuid_) +
"] [TCPClient doConnect] connect timeout",
Log::Level::ERROR);
closeSocket();
}
});
if (tlsEnabled_) {
if (!sslSocket_ || closed_ || !sslSocket_->lowest_layer().is_open()) {
sslSocket_ = std::make_unique<ssl_stream>(io_context_, sslContext_);
closed_ = false;
}
boost::asio::async_connect(
sslSocket_->lowest_layer(),
endpoints,
[finished, connectError, timer](
const boost::system::error_code &ec,
const boost::asio::ip::tcp::endpoint &) {
*connectError = ec;
*finished = true;
timer->cancel();
});
boost::asio::connect(sslSocket_->lowest_layer(), endpoint, error_code);
} else {
if (!socket_.is_open()) {
socket_ = tcp::socket(io_context_);
closed_ = false;
}
boost::asio::async_connect(
socket_,
endpoints,
[finished, connectError, timer](
const boost::system::error_code &ec,
const boost::asio::ip::tcp::endpoint &) {
*connectError = ec;
*finished = true;
timer->cancel();
});
boost::asio::connect(socket_, endpoint, error_code);
}
while (!*finished) {
io_context_.run_one();
}
io_context_.restart();
if (*connectError) {
if (error_code) {
log_->write("[" + to_string(uuid_) +
"] [TCPClient doConnect] connect error: " +
connectError->message(),
error_code.message(),
Log::Level::ERROR);
return false;
}
return true;
} catch (std::exception &error) {
log_->write("[" + to_string(uuid_) + "] [TCPClient doConnect] " +
log_->write("[" + to_string(uuid_) +
"] [TCPClient doConnect] " +
error.what(),
Log::Level::ERROR);
return false;
+31 -74
View File
@@ -1,8 +1,5 @@
#include "tcpserver.hpp"
#include <atomic>
#include <chrono>
TCPServer::TCPServer(boost::asio::io_context &io_context,
const std::shared_ptr<Config> &config,
const std::shared_ptr<Log> &log)
@@ -14,6 +11,7 @@ TCPServer::TCPServer(boost::asio::io_context &io_context,
boost::asio::ip::make_address(config->listenIp()),
config->listenPort())) {
acceptor_.set_option(boost::asio::socket_base::reuse_address(true));
startAccept();
}
@@ -30,86 +28,45 @@ void TCPServer::startAccept() {
void TCPServer::handleAccept(TCPConnection::pointer connection,
const boost::system::error_code &error) {
/*
* IMPORTANT:
* Do not wait for TLS handshake before accepting the next client.
* Bad/half-open TLS clients can otherwise occupy all io threads and
* the server looks frozen until restart.
*/
startAccept();
try {
if (error) {
if (!error) {
if (config_->runMode() == RunMode::server) {
if (config_->general().tlsEnable) {
if (!connection->initTlsServerContext()) {
log_->write("[TCPServer handleAccept] TLS server context init failed",
Log::Level::ERROR);
connection->socketShutdown();
startAccept();
return;
}
connection->tlsSocket().lowest_layer() =
std::move(connection->socket());
if (!connection->doHandshakeServer()) {
log_->write("[TCPServer handleAccept] TLS server handshake failed",
Log::Level::ERROR);
connection->socketShutdown();
startAccept();
return;
}
}
connection->startServer();
} else {
connection->startAgent();
}
} else {
log_->write("[TCPServer handleAccept] Error: " + error.message(),
Log::Level::ERROR);
return;
}
if (config_->runMode() != RunMode::server) {
connection->startAgent();
return;
}
if (!config_->general().tlsEnable) {
connection->startServer();
return;
}
if (!connection->initTlsServerContext()) {
log_->write("[TCPServer handleAccept] TLS server context init failed",
Log::Level::ERROR);
connection->socketShutdown();
return;
}
connection->tlsSocket().lowest_layer() = std::move(connection->socket());
auto done = std::make_shared<std::atomic_bool>(false);
auto timer = std::make_shared<boost::asio::steady_timer>(io_context_);
timer->expires_after(std::chrono::seconds(5));
timer->async_wait([this, connection, done](const boost::system::error_code &ec) {
if (ec) {
return;
}
if (!done->exchange(true)) {
log_->write("[TCPServer handleAccept] TLS server handshake timeout",
Log::Level::DEBUG);
connection->socketShutdown();
}
});
connection->tlsSocket().async_handshake(
boost::asio::ssl::stream_base::server,
[this, connection, timer, done](const boost::system::error_code &ec) {
timer->cancel();
if (done->exchange(true)) {
return;
}
if (ec) {
/*
* stream truncated is common when random scanners or
* non-Nipo clients hit port 443. Do not treat it as fatal.
*/
log_->write("[TCPServer handleAccept] TLS server handshake failed: " + ec.message(),
Log::Level::DEBUG);
connection->socketShutdown();
return;
}
connection->startServer();
});
} catch (const std::exception &ex) {
log_->write("[TCPServer handleAccept] Exception: " + std::string(ex.what()),
Log::Level::ERROR);
connection->socketShutdown();
} catch (...) {
log_->write("[TCPServer handleAccept] Unknown exception",
Log::Level::ERROR);
connection->socketShutdown();
}
startAccept();
}