Skip to content

Commit

Permalink
Merge pull request #133 from MortezaBashsiz/morteza/http1.1
Browse files Browse the repository at this point in the history
Morteza/http1.1
  • Loading branch information
MortezaBashsiz authored Jan 21, 2025
2 parents 5f3e676 + fd16b00 commit 4c22654
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 37 deletions.
2 changes: 0 additions & 2 deletions core/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Config::Config(const RunMode &mode, const std::string &filePath)
configYaml_["general"]["method"].as<std::string>(),
configYaml_["general"]["timeWait"].as<unsigned int>(),
configYaml_["general"]["timeout"].as<unsigned short>(),
configYaml_["general"]["repeatWait"].as<unsigned short>(),
configYaml_["general"]["chunkHeader"].as<std::string>()}),
log_({configYaml_["log"]["logLevel"].as<std::string>(),
configYaml_["log"]["logFile"].as<std::string>()}),
Expand Down Expand Up @@ -89,7 +88,6 @@ std::string Config::toString() const {
<< " method: " << general_.method << "\n"
<< " timeWait: " << general_.timeWait << "\n"
<< " timeout: " << general_.timeout << "\n"
<< " repeatWait: " << general_.repeatWait << "\n"
<< " chunkHeader: " << general_.chunkHeader << "\n"
<< " Log :\n"
<< " logLevel: " << log_.level << "\n"
Expand Down
1 change: 0 additions & 1 deletion core/src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Config : private Uncopyable {
std::string method;
unsigned int timeWait;
unsigned short timeout;
unsigned short repeatWait;
std::string chunkHeader;
};

Expand Down
1 change: 0 additions & 1 deletion core/src/general.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ inline BoolStr validateConfig(int argc, const char *argv[]) {
configYaml["general"]["method"].as<std::string>();
configYaml["general"]["timeWait"].as<unsigned int>();
configYaml["general"]["timeout"].as<unsigned short>();
configYaml["general"]["repeatWait"].as<unsigned short>();
configYaml["general"]["chunkHeader"].as<std::string>();
} catch (const std::exception &e) {
result.message = std::string("Error in 'general' block: ") + e.what() + "\n";
Expand Down
35 changes: 8 additions & 27 deletions core/src/tcpconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,41 +134,22 @@ void TCPConnection::handleReadAgent(const boost::system::error_code &error, size
}
}

boost::asio::deadline_timer timer{io_context_};
boost::asio::steady_timer timer(io_context_);
resetTimeout();
timer.expires_after(std::chrono::milliseconds(config_->general().timeWait));
timer.wait();
std::string bufStr{hexStreambufToStr(readBuffer_)};
boost::system::error_code errorIn;

if (bufStr == "43") {
boost::asio::read_until(socket_, readBuffer_, "\r\n",
errorIn);
} else {
boost::asio::streambuf tempTempBuff;
boost::asio::read(socket_, readBuffer_, boost::asio::transfer_exactly(2),
errorIn);
boost::asio::read(socket_, tempTempBuff, boost::asio::transfer_exactly(2),
errorIn);
unsigned int readSize{hexToInt(hexStreambufToStr(tempTempBuff))};
moveStreambuf(tempTempBuff, readBuffer_);
boost::asio::read(socket_, readBuffer_, boost::asio::transfer_exactly(readSize),
errorIn);
timer.expires_from_now(
boost::posix_time::milliseconds(config_->general().timeWait));
timer.wait();
if (socket_.available() > 0) {
for (auto i = 0; i <= config_->general().repeatWait; i++) {
if (socket_.available() == 0)
break;
boost::asio::streambuf tempTempBuff;
boost::asio::read(socket_, readBuffer_, boost::asio::transfer_exactly(3),
errorIn);
boost::asio::read(socket_, tempTempBuff, boost::asio::transfer_exactly(2),
errorIn);
unsigned int readSize{hexToInt(hexStreambufToStr(tempTempBuff))};
moveStreambuf(tempTempBuff, readBuffer_);
boost::asio::read(socket_, readBuffer_, boost::asio::transfer_exactly(readSize),
errorIn);
}
while (socket_.available() > 0) {
boost::asio::read(socket_, readBuffer_, boost::asio::transfer_at_least(1),
errorIn);
timer.expires_after(std::chrono::milliseconds(config_->general().timeWait));
timer.wait();
}
}

Expand Down
8 changes: 2 additions & 6 deletions nipovpn/etc/nipovpn/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,19 @@ general:
# timeWait: unsigned int(0-4,294,967,295)
# Defines the time wait between each repeat to read from socket.
# This directive will be useful when you expect to read very long stream from socket
timeWait: 50
timeWait: 25
# timeout: unsigned short
# Defines the timeout for I/O Operation in seconds. 0 indicates no timeout.
# Useful to automatically close stalled connections.
timeout: 10
# repeatWait: unsigned short(1-65,635)
# Defines the loop count which will try to repeat read from socket.
# Same as timeWait
repeatWait: 5
# chunkHeader: String
# Defines the chunk header that you want to inform Agent/Server if it is end or not.
chunkHeader: "END"

# This block is to define log directives
log:
# logLevel: "INFO|TRACE|DEBUG"
logLevel: "TRACE"
logLevel: "DEBUG"
# logFile: "/var/log/nipo/nipo.log"
# Path of log file
logFile: "/var/log/nipovpn/nipovpn.log"
Expand Down

0 comments on commit 4c22654

Please sign in to comment.