Compare commits

...
3 Commits
Author SHA1 Message Date
Morteza Bashsiz 67c43de80d implement pullTimeout
Add configurable
```
  # pullTimeout: unsigned short
  # Defines the timeout for I/O Operation in milliseconds.
  #   Useful to expire serverside read timer.
  pullTimeout: 50
```
Higher number helps when your network is slower
2026-06-01 15:53:38 +02:00
Morteza Bashsiz ab4580920f implement pullTimeout (#178) 2026-06-01 15:47:15 +02:00
Morteza Bashsiz c0942c4015 Implement Random fakeUrl
* implement random fakeUrl
2026-05-31 23:06:14 +02:00
8 changed files with 62 additions and 20 deletions

No files matched your search

+1 -1
View File
@@ -149,7 +149,7 @@ void AgentHandler::handle() {
}
std::string AgentHandler::relayHostHeader(const std::shared_ptr<Config> &config) {
std::string hostHeader = config->general().fakeUrl;
std::string hostHeader = config->randomFakeUrl();
auto pos = hostHeader.find("://");
if (pos != std::string::npos) hostHeader = hostHeader.substr(pos + 3);
pos = hostHeader.find('/');
+32 -4
View File
@@ -9,10 +9,11 @@ Config::Config(const RunMode &mode, const std::string &filePath)
listenIp_("127.0.0.1"),
listenPort_(0),
general_({configYaml_["general"]["token"].as<std::string>(),
configYaml_["general"]["fakeUrl"].as<std::string>(),
configYaml_["general"]["fakeUrls"].as<std::vector<std::string>>(),
configYaml_["general"]["methods"].as<std::vector<std::string>>(),
configYaml_["general"]["endPoints"].as<std::vector<std::string>>(),
configYaml_["general"]["timeout"].as<unsigned short>(),
configYaml_["general"]["pullTimeout"].as<unsigned short>(),
configYaml_["general"]["tunnelEnable"].as<bool>(false),
configYaml_["general"]["connectionReuse"].as<bool>(false),
configYaml_["general"]["tlsEnable"].as<bool>(false),
@@ -72,7 +73,17 @@ std::string Config::toString() const {
ss << "\nConfig :\n"
<< " General :\n"
<< " token: " << general_.token << "\n"
<< " fakeUrl: " << general_.fakeUrl << "\n"
<< " fakeUrls: ";
for (std::size_t i = 0; i < general_.fakeUrls.size(); ++i) {
ss << general_.fakeUrls[i];
if (i != general_.fakeUrls.size() - 1) {
ss << ", ";
}
}
ss << "\n"
<< " methods: ";
for (std::size_t i = 0; i < general_.methods.size(); ++i) {
@@ -96,6 +107,7 @@ std::string Config::toString() const {
ss << "\n"
<< " timeout: " << general_.timeout << "\n"
<< " pullTimeout: " << general_.pullTimeout << "\n"
<< " tunnelEnable: " << std::boolalpha << general_.tunnelEnable << "\n"
<< " connectionReuse: " << std::boolalpha << general_.connectionReuse << "\n"
<< " tlsEnable: " << std::boolalpha << general_.tlsEnable << "\n"
@@ -198,11 +210,27 @@ std::string Config::modeToString() const {
}
}
std::string Config::randomFakeUrl() const {
std::lock_guard<std::mutex> lock(configMutex_);
if (general_.fakeUrls.empty()) {
return "www.google.com";
}
static thread_local std::mt19937 generator{std::random_device{}()};
std::uniform_int_distribution<std::size_t> distribution(
0,
general_.fakeUrls.size() - 1);
return general_.fakeUrls[distribution(generator)];
}
std::string Config::randomMethod() const {
std::lock_guard<std::mutex> lock(configMutex_);
if (general_.methods.empty()) {
return "GET";// fallback
return "GET";
}
static thread_local std::mt19937 generator{std::random_device{}()};
@@ -218,7 +246,7 @@ std::string Config::randomEndPoint() const {
std::lock_guard<std::mutex> lock(configMutex_);
if (general_.endPoints.empty()) {
return "api";// fallback
return "api";
}
static thread_local std::mt19937 generator{std::random_device{}()};
+4 -1
View File
@@ -20,10 +20,11 @@ class Config : private Uncopyable {
private:
struct General {
std::string token;
std::string fakeUrl;
std::vector<std::string> fakeUrls;
std::vector<std::string> methods;
std::vector<std::string> endPoints;
unsigned short timeout;
unsigned short pullTimeout;
bool tunnelEnable;
bool connectionReuse;
bool tlsEnable;
@@ -107,6 +108,8 @@ public:
std::string toString() const;
std::string randomFakeUrl() const;
std::string randomMethod() const;
std::string randomEndPoint() const;
+2 -1
View File
@@ -325,10 +325,11 @@ inline BoolStr validateConfig(int argc, const char *argv[]) {
try {
configYaml["general"]["token"].as<std::string>();
configYaml["general"]["fakeUrl"].as<std::string>();
configYaml["general"]["fakeUrls"].as<std::vector<std::string>>();
configYaml["general"]["methods"].as<std::vector<std::string>>();
configYaml["general"]["endPoints"].as<std::vector<std::string>>();
configYaml["general"]["timeout"].as<unsigned short>();
configYaml["general"]["pullTimeout"].as<unsigned short>();
configYaml["general"]["tunnelEnable"].as<bool>();
} catch (const std::exception &e) {
result.message = std::string("Error in 'general' block: ") + e.what() + "\n";
+6 -4
View File
@@ -156,10 +156,11 @@ bool HTTP::parseTls() {
}
const std::string HTTP::genHttpPostReqString(const std::string &body) const {
auto fakeUrl = config_->randomFakeUrl();
return std::string(config_->randomMethod() + " " +
config_->general().fakeUrl + " HTTP/" +
fakeUrl + " HTTP/" +
config_->agent().httpVersion + "\r\n") +
"Host: " + config_->general().fakeUrl + "\r\n" +
"Host: " + fakeUrl + "\r\n" +
"User-Agent: " + config_->agent().userAgent + "\r\n" +
"Accept: */*\r\n" + "Connection: keep-alive\r\n" +
"Content-Length: " + std::to_string(body.length()) + "\r\n" +
@@ -167,10 +168,11 @@ const std::string HTTP::genHttpPostReqString(const std::string &body) const {
}
const std::string HTTP::genHttpRestPostReqString() const {
auto fakeUrl = config_->randomFakeUrl();
return std::string(config_->randomMethod() + " " +
config_->general().fakeUrl + " HTTP/" +
fakeUrl + " HTTP/" +
config_->agent().httpVersion + "\r\n") +
"Host: " + config_->general().fakeUrl + "\r\n" +
"Host: " + fakeUrl + "\r\n" +
"User-Agent: " + config_->agent().userAgent + "\r\n" +
"Accept: */*\r\n" + "Connection: keep-alive\r\n" +
"Rest: yes\r\n" + "COMP\r\n\r\n";
+1 -1
View File
@@ -160,7 +160,7 @@ bool TCPClient::doHandshakeClient() {
try {
if (!tlsEnabled_ || !sslSocket_) return true;
std::string sniHost = config_->general().fakeUrl;
std::string sniHost = config_->randomFakeUrl();
if (!sniHost.empty()) {
auto pos = sniHost.find("://");
+2 -2
View File
@@ -390,7 +390,7 @@ void TCPConnection::handleReadServer(const boost::system::error_code &error, siz
}
std::string TCPConnection::makeRelayHostHeader() const {
std::string hostHeader = config_->general().fakeUrl;
std::string hostHeader = config_->randomFakeUrl();
auto pos = hostHeader.find("://");
if (pos != std::string::npos) hostHeader = hostHeader.substr(pos + 3);
@@ -512,7 +512,7 @@ void TCPConnection::startTunnelPollServer() {
pollInProgress_ = true;
pollTimer_.expires_after(std::chrono::milliseconds(10));
pollTimer_.expires_after(std::chrono::milliseconds(config_->general().pullTimeout));
pollTimer_.async_wait(
boost::asio::bind_executor(
strand_,
+14 -6
View File
@@ -3,15 +3,19 @@
general:
# token: 32 bytes of string. this will be used on agent and server side to encryption
token: "af445adb-2434-4975-9445-2c1b2231"
# fakeUrl: string
# Defines the fake url between agent and server
fakeUrl: "www.google.com"
# fakeUrls:
# Defines the list of fake urls between agent and server
fakeUrls:
- nipo.ciron.net
- sudoer.ir
- sudoer.net
- google.com
- cloudflare.com
# methods:
# Defines the list of using methods
# you like to send requests from agent to server
# Program will choose randomly from this list
methods:
- HEAD
- GET
- POST
- PUT
@@ -29,6 +33,10 @@ general:
# Defines the timeout for I/O Operation in seconds. 0 indicates no timeout.
# Useful to automatically close stalled connections.
timeout: 10
# pullTimeout: unsigned short
# Defines the timeout for I/O Operation in milliseconds.
# Useful to expire serverside read timer.
pullTimeout: 50
# tunnelEnable: bool
# Defines the connection mode between agent and server. If enabled then the traffic
# will be TCP/TLS tunnel like.
@@ -36,7 +44,7 @@ general:
# connectionReuse: bool
# If false then it will use same connection between agent and server to handle client request
# If true then it will create new connection for each request between agent and server
connectionReuse: false
connectionReuse: true
# tlsEnable: bool
# It enables or disables tls between agent and server
tlsEnable: false
@@ -76,7 +84,7 @@ agent:
# listenPort: the port number which will be used on agent
listenPort: 8080
# serverIp: IPv4 of the nipoServer
serverIp: "127.0.0.1"
serverIp: "127.0.0.10"
# serverPort: port number of the nipoServer
serverPort: 80
# httpVersion: This version will be used between agent and server