9 #include<jsoncpp/json/json.h>
25 #include<openssl/sha.h>
29 #include<sys/socket.h>
31 #include<openssl/bio.h>
32 #include<openssl/evp.h>
33 #include<openssl/buffer.h>
38 #include<condition_variable>
40 #include<unordered_map>
41 #include <openssl/ssl.h>
42 #include <openssl/err.h>
43 #include<openssl/crypto.h>
52 #include <sys/eventfd.h>
53 #include <sys/timerfd.h>
97 : capacity_(capacity_pow2),
98 mask_(capacity_pow2 - 1),
99 buffer_(capacity_pow2),
104 if (capacity_ < 2 || (capacity_ & mask_) != 0) {
106 throw std::invalid_argument(
"MPSCQueue capacity must be power of two and >= 2");
110 for (std::size_t i = 0; i < capacity_; ++i) {
111 buffer_[i].seq.store(i, std::memory_order_relaxed);
128 bool push(T&& v) noexcept(std::is_nothrow_move_constructible_v<T>) {
129 return emplace_impl(std::move(v));
132 bool push(
const T& v) noexcept(std::is_nothrow_copy_constructible_v<T>) {
133 return emplace_impl(v);
140 bool pop(T& out) noexcept(std::is_nothrow_move_assignable_v<T> &&
141 std::is_nothrow_move_constructible_v<T>)
143 Slot& slot = buffer_[head_ & mask_];
144 const std::size_t seq = slot.seq.load(std::memory_order_acquire);
145 const std::intptr_t dif =
static_cast<std::intptr_t
>(seq) - static_cast<std::intptr_t>(head_ + 1);
153 out = std::move(*slot.ptr());
160 slot.seq.store(head_ + capacity_, std::memory_order_release);
171 const std::size_t t = tail_.load(std::memory_order_relaxed);
172 const std::size_t h = head_;
173 return (t >= h) ? (t - h) : 0;
178 std::atomic<std::size_t> seq;
179 typename std::aligned_storage<sizeof(T), alignof(T)>::type storage;
180 bool has_value =
false;
182 T* ptr() noexcept {
return reinterpret_cast<T*
>(&storage); }
183 const T* ptr() const noexcept {
return reinterpret_cast<const T*
>(&storage); }
186 void construct(U&& v) noexcept(std::is_nothrow_constructible_v<T, U&&>) {
187 ::new (static_cast<void*>(&storage)) T(std::forward<U>(v));
191 void destroy() noexcept {
200 bool emplace_impl(U&& v) noexcept(std::is_nothrow_constructible_v<T, U&&>) {
201 std::size_t pos = tail_.load(std::memory_order_relaxed);
204 Slot& slot = buffer_[pos & mask_];
205 const std::size_t seq = slot.seq.load(std::memory_order_acquire);
206 const std::intptr_t dif =
static_cast<std::intptr_t
>(seq) - static_cast<std::intptr_t>(pos);
210 if (tail_.compare_exchange_weak(
212 std::memory_order_relaxed,
213 std::memory_order_relaxed))
216 slot.construct(std::forward<U>(v));
218 slot.seq.store(pos + 1, std::memory_order_release);
222 }
else if (dif < 0) {
227 pos = tail_.load(std::memory_order_relaxed);
233 const std::size_t capacity_;
234 const std::size_t mask_;
235 std::vector<Slot> buffer_;
241 std::atomic<std::size_t> tail_;
265 static bool createDir(
const std::string & ddir,
const mode_t &mode=0775);
274 static bool copy(
const std::string &sourceFile,
const std::string &objectFile);
283 static bool createFile(
const std::string &filePath,
const mode_t &mode=0666);
290 static size_t get_file_size(
const std::string &fileName);
316 FileThreadLock(
const std::string &loc,
const int &threads):loc(loc),threads(threads){};
328 static std::mutex
l1;
329 static std::unordered_map<std::string,FileThreadLock>
fl2;
338 std::vector<std::string> data;
339 std::vector<std::string> backUp;
340 char *data_binary=
nullptr;
341 char *backUp_binary=
nullptr;
345 size_t multiple_backup=0;
350 std::string fileName;
352 std::string fileNameTemp;
357 uint64_t totalLines=0;
402 bool openFile(
const std::string &fileName,
const bool &create=
true,
const int &multiple=0,
const size_t &size=0,
const mode_t &mode=0666);
408 bool closeFile(
const bool &del=
false);
470 bool unlockMemory(
const bool &rec=
false);
485 int findC(
const std::string &targetString,
const int linePos=1);
495 bool appendLineC(
const std::string &data,
const int &linePos=0);
504 bool deleteLineC(
const int &linePos=0);
521 bool chgLineC(
const std::string &data,
const int &linePos=0);
531 bool readLineC(std::string &data,
const int linePos);
541 std::string& readC(std::string &data,
const int &linePos,
const int &num);
548 std::string& readAllC(std::string &data);
564 bool readC(
char *data,
const size_t &pos,
const size_t &size);
575 bool writeC(
const char *data,
const size_t &pos,
const size_t &size);
596 int find(
const std::string &targetString,
const int linePos=1);
606 bool appendLine(
const std::string &data,
const int &linePos=0);
615 bool deleteLine(
const int &linePos=0);
632 bool chgLine(
const std::string &data,
const int &linePos=0);
642 bool readLine(std::string &data,
const int linePos);
652 std::string& read(std::string &data,
const int &linePos,
const int &num);
659 std::string& readAll(std::string &data);
675 bool read(
char *data,
const size_t &pos,
const size_t &size);
686 bool write(
const char *data,
const size_t &pos,
const size_t &size);
733 Duration(
long long a,
int b,
int c,
int d,
int e) : day(a), hour(b), min(c), sec(d), msec(e) {}
743 total = day * 24 * 60 * 60 * 1000 + hour * 60 * 60 * 1000 + min * 60 * 1000 + sec * 1000 + msec;
745 totalB = b.
day * 24 * 60 * 60 * 1000 + b.
hour * 60 * 60 * 1000 + b.
min * 60 * 1000 + b.
sec * 1000 + b.
msec;
759 total = day * 24 * 60 * 60 * 1000 + hour * 60 * 60 * 1000 + min * 60 * 1000 + sec * 1000 + msec;
761 totalB = b.
day * 24 * 60 * 60 * 1000 + b.
hour * 60 * 60 * 1000 + b.
min * 60 * 1000 + b.
sec * 1000 + b.
msec;
775 total = day * 24 * 60 * 60 * 1000 + hour * 60 * 60 * 1000 + min * 60 * 1000 + sec * 1000 + msec;
777 totalB = b.
day * 24 * 60 * 60 * 1000 + b.
hour * 60 * 60 * 1000 + b.
min * 60 * 1000 + b.
sec * 1000 + b.
msec;
791 total = day * 24 * 60 * 60 * 1000 + hour * 60 * 60 * 1000 + min * 60 * 1000 + sec * 1000 + msec;
793 totalB = b.
day * 24 * 60 * 60 * 1000 + b.
hour * 60 * 60 * 1000 + b.
min * 60 * 1000 + b.
sec * 1000 + b.
msec;
807 total = day * 24 * 60 * 60 * 1000 + hour * 60 * 60 * 1000 + min * 60 * 1000 + sec * 1000 + msec;
809 totalB = b.
day * 24 * 60 * 60 * 1000 + b.
hour * 60 * 60 * 1000 + b.
min * 60 * 1000 + b.
sec * 1000 + b.
msec;
822 long long dayy = day;
834 if (msecc / 1000 != 0)
836 secc += msecc / 1000;
837 msecc = msecc % 1000;
866 long long dayy = day;
872 msecc = dayy * 24 * 60 * 60 * 1000 + hourr * 60 * 60 * 1000 + minn * 60 * 1000 + secc * 1000 + msecc - b.
day * 24 * 60 * 60 * 1000 - b.
hour * 60 * 60 * 1000 - b.
min * 60 * 1000 - b.
sec * 1000 - b.
msec;
878 if (msecc / 1000 != 0)
880 secc += msecc / 1000;
881 msecc = msecc % 1000;
910 total = hour * 60 * 60 * 1000 + min * 60 * 1000 + sec * 1000 + msec;
911 double k = day + total / 86400000.0000;
920 total = min * 60 * 1000 + sec * 1000 + msec;
921 double k = day * 24 + hour + total / 36000000.0000;
930 total = sec * 1000 + msec;
931 double k = day * 24 * 60 + hour * 60 + min + total / 60000.0000;
941 double k = day * 24 * 60 * 60 + hour * 60 * 60 + min * 60 + sec + total / 1000.0000;
950 total = day * 24 * 60 * 60 * 1000 + hour * 60 * 60 * 1000 + min * 60 * 1000 + sec * 1000 + msec;
966 if (msec / 1000 != 0)
989 return Duration(day, hour, min, sec, msec);
1005 std::ostream&
operator<<(std::ostream &os,
const Duration &a);
1012 #define ISO8086A "yyyy-mm-ddThh:mi:ss"
1016 #define ISO8086B "yyyy-mm-ddThh:mi:ss.sss"
1030 static std::string &toPGtimeFormat();
1031 static std::chrono::system_clock::time_point strToTimePoint(
const std::string &timeStr,
const std::string &format =
ISO8086A);
1032 static std::string& timePointToStr(
const std::chrono::system_clock::time_point &tp, std::string &timeStr,
const std::string &format =
ISO8086A);
1041 static std::string& getTime(std::string &timeStr,
const std::string &format =
ISO8086A);
1050 static bool convertFormat(std::string &timeStr,
const std::string &oldFormat,
const std::string &newFormat =
ISO8086A);
1060 static Duration& calculateTime(
const std::string &time1,
const std::string &time2,
Duration &result,
const std::string &format1 =
ISO8086A,
const std::string &format2 =
ISO8086A);
1071 static std::string& calculateTime(
const std::string &time1,
const Duration &time2, std::string &result,
const std::string &am,
const std::string &format1 =
ISO8086A,
const std::string &format2 =
ISO8086A);
1081 static bool compareTime(
const std::string &time1,
const std::string &time2,
const std::string &format1 =
ISO8086A,
const std::string &format2 =
ISO8086A);
1085 std::chrono::steady_clock::time_point start;
1086 std::chrono::steady_clock::time_point end;
1127 std::string timeFormat;
1128 std::string contentFormat;
1129 std::atomic<bool> consumerGuard{
true};
1133 std::thread consumerThread;
1161 LogFile(
const size_t &logQueue_cap=8192):logQueue(logQueue_cap)
1164 consumerThread = std::thread([
this]()->
void
1166 std::string content;
1167 content.reserve(1024);
1169 content.reserve(1074);
1170 while(this->consumerGuard)
1172 while(this->logQueue.pop(content))
1174 getTime(time,timeFormat);
1175 time+=contentFormat;
1177 this->appendLine(time);
1179 std::this_thread::sleep_for(std::chrono::microseconds(500));
1193 bool openFile(
const std::string &fileName,
const std::string &timeFormat =
ISO8086A,
const std::string &contentFormat =
" ");
1209 bool closeFile(
const bool &del =
false);
1214 void writeLog(
const std::string &data);
1227 bool deleteLogByTime(
const std::string &date1 =
"1",
const std::string &date2 =
"2");
1257 static bool encryptSymmetric(
const unsigned char *before,
const size_t &length,
const unsigned char *passwd,
const unsigned char *iv,
unsigned char *after);
1268 static bool decryptSymmetric(
const unsigned char *before,
const size_t &length,
const unsigned char *passwd,
const unsigned char *iv,
unsigned char *after);
1281 static std::string& sha1(
const std::string &ori_str, std::string &result);
1294 static std::string& sha11(
const std::string &ori_str, std::string &result);
1309 static std::string& bitOutput(
char input, std::string &result);
1317 static std::string& bitOutput(
const std::string &input, std::string &result);
1326 static char& bitOutput_bit(
char input,
const int pos,
char &result);
1334 static unsigned long& bitStrToNumber(
const std::string &input,
unsigned long &result);
1344 static unsigned long& bitToNumber(
const std::string &input,
unsigned long &result);
1352 static char& toBit(
const std::string &input,
char &result);
1360 static std::string& toBit(
const std::string &input, std::string &result);
1375 static long getRandomNumber(
const long &a,
const long &b);
1382 static std::string& getRandomStr_base64(std::string &str,
const int &length);
1396 static std::string& generateMask_4(std::string &mask);
1415 static unsigned long& htonl_ntohl_64(
unsigned long &data);
1433 static std::string& getPreciesFloat(
const float &number,
const int &bit, std::string &str);
1441 static float& getPreciesFloat(
float &number,
const int &bit);
1450 static std::string& getPreciesDouble(
const double &number,
const int &bit, std::string &str);
1458 static double& getPreciesDouble(
double &number,
const int &bit);
1470 static float& getValidFloat(
float &number,
const int &bit);
1495 static size_t get_split_str(
const std::string_view& ori_str, std::string_view &str,
const std::string_view &a,
const std::string_view &b,
const size_t &pos = 0);
1506 static std::string_view& get_value_str(
const std::string_view& ori_str, std::string_view &str,
const std::string& name);
1515 static std::string_view& get_value_header(
const std::string_view& ori_str, std::string_view &str,
const std::string& name);
1525 static std::string_view& get_location_str(
const std::string_view& ori_str, std::string_view &str);
1535 static std::string_view& getLocPara(
const std::string_view &url, std::string_view &locPara);
1544 static std::string_view& getPara(
const std::string_view &url, std::string_view ¶);
1564 static size_t get_split_str(
const std::string_view& ori_str, std::string &str,
const std::string_view &a,
const std::string_view &b,
const size_t &pos = 0);
1575 static std::string& get_value_str(
const std::string& ori_str, std::string &str,
const std::string& name);
1584 static std::string& get_value_header(
const std::string& ori_str, std::string &str,
const std::string& name);
1594 static std::string& get_location_str(
const std::string& ori_str, std::string &str);
1604 static std::string& getLocPara(
const std::string &url, std::string &locPara);
1613 static std::string& getPara(
const std::string &url, std::string ¶);
1624 static std::string& getIP(
const std::string &url, std::string &IP);
1635 static int& getPort(
const std::string &url,
int &port);
1645 static std::string createHeader(
const std::string& first,
const std::string& second);
1666 template<
class... Args>
1667 static std::string
createHeader(
const std::string& first,
const std::string& second, Args... args)
1669 std::string cf = first +
": " + second +
"\r\n" + createHeader(args...);
1690 static std::string& transfer_websocket_key(std::string &str);
1706 static int& toInt(
const std::string_view&ori_str,
int &result,
const int &i = -1);
1713 static int& str16toInt(
const std::string_view&ori_str,
int &result,
const int &i=-1);
1722 static long& toLong(
const std::string_view&ori_str,
long &result,
const long &i = -1);
1731 static float& toFloat(
const std::string&ori_str,
float &result,
const float &i = -1);
1740 static double& toDouble(
const std::string&ori_str,
double &result,
const double &i = -1);
1748 static bool& toBool(
const std::string_view&ori_str,
bool &result);
1759 static std::string& strto16(
const std::string &ori_str, std::string &result);
1775 static std::string base64_encode(
const std::string &input);
1784 static std::string base64_decode(
const std::string &input);
1796 static std::string& transfer_websocket_key(std::string &str);
1810 static std::string& generateMask_4(std::string &mask);
1821 static std::string& maskCalculate(std::string &data,
const std::string &mask);
1841 static int getValue(
const std::string &oriStr,std::string& result,
const std::string &type=
"value",
const std::string &name=
"a",
const int &num=0);
1848 static std::string toString(
const Json::Value &val);
1854 static Json::Value toJsonArray(
const std::string & str);
1864 template<
class T1,
class T2>
1869 if constexpr (std::is_integral_v<T2>) {
1870 root[first] = Json::Value(static_cast<Json::Int64>(second));
1872 root[first] = second;
1874 Json::StreamWriterBuilder builder;
1875 std::string jsonString = Json::writeString(builder, root);
1889 template<
class T1,
class T2,
class... Args>
1894 if constexpr (std::is_integral_v<T2>) {
1895 root[first] = Json::Value(static_cast<Json::Int64>(second));
1897 root[first] = second;
1899 std::string kk = createJson(args...);
1900 Json::StreamWriterBuilder builder;
1901 std::string jsonString = Json::writeString(builder, root);
1902 jsonString = jsonString.erase(jsonString.length() - 2);
1904 return jsonString +
"," + kk;
1917 Json::Value root(Json::arrayValue);
1919 Json::StreamWriterBuilder builder;
1920 std::string jsonString = Json::writeString(builder, root);
1932 template<
class T,
class... Args>
1935 Json::Value root(Json::arrayValue);
1937 std::string kk = createArray(args...);
1938 Json::StreamWriterBuilder builder;
1939 std::string jsonString = Json::writeString(builder, root);
1940 jsonString = jsonString.erase(jsonString.length() - 2);
1942 return jsonString +
"," + kk;
1951 static std::string jsonAdd(
const std::string &a,
const std::string &b);
1958 static std::string& jsonFormatify(
const std::string &a, std::string &b);
1965 static std::string& jsonToUTF8(
const std::string &input, std::string &output);
2069 std::chrono::steady_clock::time_point lastTime{};
2072 std::deque<std::chrono::steady_clock::time_point>
history;
2075 double tokens = 0.0;
2076 std::chrono::steady_clock::time_point lastRefill{};
2100 std::chrono::steady_clock::time_point lastActivity{};
2128 int activeConnections = 0;
2131 std::unordered_map<int, ConnectionState>
conns;
2252 : maxConnections(maxConn), connectionTimeout(idleTimeout) {}
2296 void setPathLimit(
const std::string &path,
const int ×,
const int &secs);
2317 const int ×,
const int &secs);
2334 const std::string_view &path,
2335 const int ×,
const int &secs);
2349 void clearIP(
const std::string &ip,
const int &fd);
2364 bool connectionDetect(
const std::string &ip,
const int &fd);
2400 void banIP(
const std::string &ip,
2402 const std::string &reasonCN,
2403 const std::string &reasonEN);
2409 void unbanIP(
const std::string &ip);
2417 bool isBanned(
const std::string &ip)
const;
2423 const int ×,
const int &secs,
2424 const std::chrono::steady_clock::time_point &now);
2428 int connectionTimeout;
2431 RateLimitType requestStrategy = RateLimitType::SlidingWindow;
2434 std::unordered_map<std::string, IPInformation> table;
2435 std::unordered_map<std::string, std::pair<int,int>> pathConfig;
2438 std::unordered_map<std::string, std::chrono::steady_clock::time_point> blacklist;
2440 inline void logSecurity(
const std::string &msgCN,
const std::string &msgEN);
2479 void setFD(
const int &fd, SSL *ssl,
const bool &flag1 =
false,
const bool &flag2 =
false,
const int &sec=-1);
2494 void close(
const bool &cle =
true);
2499 void blockSet(
const int &sec = -1);
2512 bool isConnect() {
if (fd == -1)
return false;
else return true; }
2536 int sendData(
const std::string &data,
const bool &block =
true);
2560 int sendData(
const char *data,
const uint64_t &length,
const bool &block =
true);
2576 int recvDataByLength(std::string &data,
const uint64_t &length,
const int &sec = 2);
2592 int recvDataByLength(
char *data,
const uint64_t &length,
const int &sec = 2);
2605 int recvData(std::string &data,
const uint64_t &length);
2618 int recvData(
char *data,
const uint64_t &length);
2628 std::string serverIP =
"";
2629 int serverPort = -1;
2632 SSL_CTX *ctx =
nullptr;
2639 void closeAndUnCreate();
2640 bool initCTX(
const char *ca,
const char *cert =
"",
const char *key =
"",
const char *passwd =
"");
2654 TcpClient(
const bool &TLS =
false,
const char *ca =
"",
const char *cert =
"",
const char *key =
"",
const char *passwd =
"");
2661 bool connect(
const std::string &ip,
const int &port);
2675 void resetCTX(
const bool &TLS =
false,
const char *ca =
"",
const char *cert =
"",
const char *key =
"",
const char *passwd =
"");
2727 HttpClient(
const bool &TLS =
false,
const char *ca =
"",
const char *cert =
"",
const char *key =
"",
const char *passwd =
"") :
TcpClient(TLS, ca, cert, key, passwd) {}
2746 bool getRequest(
const std::string &url,
const std::string &header =
"",
const std::string &header1 =
"Connection: keep-alive",
const int &sec=-1);
2765 bool postRequest(
const std::string &url,
const std::string &body =
"",
const std::string &header =
"",
const std::string &header1 =
"Connection: keep-alive",
const int &sec=-1);
2785 bool getRequestFromFD(
const int &fd, SSL *ssl,
const std::string &url,
const std::string &header =
"",
const std::string &header1 =
"Connection: keep-alive",
const int &sec=2);
2806 bool postRequestFromFD(
const int &fd, SSL *ssl,
const std::string &url,
const std::string &body =
"",
const std::string &header =
"",
const std::string &header1 =
"Connection: keep-alive",
const int &sec=2);
2816 std::string header =
"";
2820 std::string body =
"";
2831 std::function<bool(const int &fd)> fc = [](
const int &fd)->
bool
2833 std::function<void(const int &fd)> fcEnd = [](
const int &fd)->
void
2835 std::function<bool(const int &fd)> fcTimeOut = [](
const int &fd)->
bool
2867 void setFunction(std::function<
bool(
const int &fd)> fc) { this->fc = fc; }
2875 void setEndFunction(std::function<
void(
const int &fd)> fcEnd) { this->fcEnd = fcEnd; };
2919 std::function<bool(const std::string &message, WebSocketClient &k)> fc = [](
const std::string &message,
WebSocketClient &k)->
bool
2920 {std::cout<<
"Received: "<<message<<std::endl;
return true;};
2939 WebSocketClient(
const bool &TLS =
false,
const char *ca =
"",
const char *cert =
"",
const char *key =
"",
const char *passwd =
"") :
TcpClient(TLS, ca, cert, key, passwd) {}
2959 bool connect(
const std::string &url,
const int &min = 20);
2982 bool sendMessage(
const std::string &message,
const std::string &type =
"0001");
2992 void close(
const std::string &closeCodeAndMessage,
const bool &wait =
true);
3011 void close(
const short &code = 1000,
const std::string &message =
"bye",
const bool &wait =
true);
3083 std::unordered_map<std::string,std::any>
ctx;
3102 void setFD(
const int &fd, SSL *ssl =
nullptr,
const bool &flag1 =
false,
const bool &flag2 =
true) { TcpFDHandler::setFD(fd, ssl, flag1, flag2); }
3128 bool sendBack(
const std::string &data,
const std::string &header =
"",
const std::string &code =
"200 OK",
const std::string &header1 =
"");
3142 bool sendBack(
const char *data,
const size_t &length,
const char *header=
"\0",
const char *code=
"200 OK\0",
const char *header1=
"\0",
const size_t &header_length=50);
3193 std::string message=
"";
3205 std::unordered_map<std::string,std::any>
ctx;
3239 std::unordered_map<std::string,std::any>
ctx;
3335 SSL_CTX *ctx=
nullptr;
3351 std::function<void(const int &fd)> closeFun=[](
const int &fd)->
void
3357 std::function<bool(TcpFDHandler &k,TcpInformation &inf)> globalSolveFun=[](TcpFDHandler &k,TcpInformation &inf)->
bool
3359 std::unordered_map<std::string,std::vector<std::function<int(TcpFDHandler &k,TcpInformation &inf)>>> solveFun;
3360 std::function<int(TcpFDHandler &k,TcpInformation &inf)> parseKey=[](TcpFDHandler &k,TcpInformation &inf)->
int
3361 {inf.ctx[
"key"]=inf.data;
return 1;};
3367 void epolll(
const int &evsNum);
3369 virtual void handler_netevent(
const int &fd);
3370 virtual void handler_workerevent(
const int &fd,
const int &ret);
3371 virtual void handleHeartbeat()=0;
3384 void putTask(
const std::function<
int(TcpFDHandler &k,TcpInformation &inf)> &fun,TcpFDHandler &k,TcpInformation &inf);
3466 const unsigned long long &maxFD = 1000000,
3467 const int &buffer_size = 256,
3468 const size_t &finishQueue_cap=65536,
3469 const bool &security_open =
true,
3470 const int &connectionNumLimit = 20,
3471 const int &connectionSecs = 1,
3472 const int &connectionTimes = 6,
3473 const int &requestSecs = 1,
3474 const int &requestTimes = 40,
3475 const int &checkFrequency = 60,
3476 const int &connectionTimeout = 60
3479 buffer_size(buffer_size * 1024),
3480 finishQueue(finishQueue_cap),
3481 security_open(security_open),
3482 connectionSecs(connectionSecs),
3483 connectionTimes(connectionTimes),
3484 requestSecs(requestSecs),
3485 requestTimes(requestTimes),
3486 connectionLimiter(connectionNumLimit, connectionTimeout),
3487 checkFrequency(checkFrequency)
3498 bool startListen(
const int &port,
const int &threads = 8);
3526 bool setTLS(
const char *cert,
const char *key,
const char *passwd,
const char *ca);
3566 this->securitySendBackFun = fc;
3604 const std::string &key,
3607 auto [it, inserted] = solveFun.try_emplace(key);
3608 it->second.push_back(std::move(fc));
3634 this->parseKey = parseKeyFun;
3654 virtual bool close(
const int &fd);
3658 void setCloseFun(std::function<
void(
const int &fd)> closeFun){this->closeFun=closeFun;}
3669 SSL* getSSL(
const int &fd);
3688 std::vector<std::function<int(HttpServerFDHandler &k,HttpRequestInformation &inf)>> globalSolveFun;
3692 std::vector<std::function<int(HttpServerFDHandler &k, HttpRequestInformation &inf)>>
3695 std::function<int(HttpServerFDHandler &k, HttpRequestInformation &inf)> parseKey =
3697 inf.
ctx[
"key"] = inf.loc;
3703 void handler_netevent(
const int &fd);
3704 void handler_workerevent(
const int &fd,
const int &ret);
3705 void handleHeartbeat(){}
3816 const unsigned long long &maxFD = 1000000,
3817 const int &buffer_size = 256,
3818 const size_t &finishQueue_cap=65536,
3819 const bool &security_open =
true,
3820 const int &connectionNumLimit = 10,
3821 const int &connectionSecs = 1,
3822 const int &connectionTimes = 3,
3823 const int &requestSecs = 1,
3824 const int &requestTimes = 20,
3825 const int &checkFrequency = 30,
3826 const int &connectionTimeout = 30
3878 this->securitySendBackFun = fc;
3945 const std::string &key,
3949 auto [it, inserted] = solveFun.try_emplace(key);
3950 it->second.push_back(std::move(fc));
3986 this->parseKey = parseKeyFun;
3999 return TcpServer::startListen(port, threads);
4022 void setFD(
const int &fd, SSL *ssl =
nullptr,
const bool &flag1 =
false,
const bool &flag2 =
true) { TcpFDHandler::setFD(fd, ssl, flag1, flag2); }
4060 bool sendMessage(
const std::string &msg,
const std::string &type =
"0001");
4070 std::unordered_map<int, WebSocketFDInformation> wbclientfd;
4074 std::function<bool(WebSocketFDInformation &k)> fcc =
4079 std::function<bool(WebSocketServerFDHandler &k, WebSocketFDInformation &inf)> fccc =
4083 std::function<bool(WebSocketServerFDHandler &k, WebSocketFDInformation &inf)> globalSolveFun =
4090 std::vector<std::function<int(WebSocketServerFDHandler &, WebSocketFDInformation &)>>>
4093 std::function<int(WebSocketServerFDHandler &k, WebSocketFDInformation &inf)> parseKey =
4095 inf.
ctx[
"key"] = inf.message;
4105 void handler_netevent(
const int &fd);
4106 void handler_workerevent(
const int &fd,
const int &ret);
4108 void closeAck(
const int &fd,
const std::string &closeCodeAndMessage);
4109 void closeAck(
const int &fd,
const short &code = 1000,
const std::string &message =
"bye");
4113 void handleHeartbeat();
4115 bool closeWithoutLock(
const int &fd,
const std::string &closeCodeAndMessage);
4116 bool closeWithoutLock(
const int &fd,
const short &code = 1000,
const std::string &message =
"bye");
4222 const unsigned long long &maxFD = 1000000,
4223 const int &buffer_size = 256,
4224 const size_t &finishQueue_cap=65536,
4225 const bool &security_open =
true,
4226 const int &connectionNumLimit = 5,
4227 const int &connectionSecs = 10,
4228 const int &connectionTimes = 3,
4229 const int &requestSecs = 1,
4230 const int &requestTimes = 10,
4231 const int &checkFrequency = 60,
4232 const int &connectionTimeout = 120
4284 this->securitySendBackFun = fc;
4302 this->globalSolveFun = fc;
4347 const std::string &key,
4350 auto [it, inserted] = solveFun.try_emplace(key);
4351 it->second.push_back(std::move(fc));
4362 this->parseKey = parseKeyFun;
4371 this->seca = seca * 60;
4391 bool closeFD(
const int &fd,
const std::string &closeCodeAndMessage);
4400 bool closeFD(
const int &fd,
const short &code = 1000,
const std::string &message =
"bye");
4411 const std::string &msg,
4412 const std::string &type =
"0001")
4415 k.
setFD(fd, getSSL(fd), unblock);
4428 bool close(
const int &fd);
4437 return TcpServer::startListen(port, threads);
4445 void sendMessage(
const std::string &msg,
const std::string &type =
"0001");
4478 void setFD(
const int &fd,
const bool &flag1 =
false,
const int &sec = -1,
const bool &flag2 =
false);
4483 void blockSet(
const int &sec = -1);
4501 void close(
const bool &cle =
true);
4522 int sendData(
const std::string &data,
const std::string &ip,
const int &port,
const bool &block =
true);
4543 int sendData(
const char *data,
const uint64_t &length,
const std::string &ip,
const int &port,
const bool &block =
true);
4558 int recvData(std::string &data,
const uint64_t &length, std::string &ip,
int &port);
4573 int recvData(
char *data,
const uint64_t &length, std::string &ip,
int &port);
4587 UdpClient(
const bool &flag1 =
false,
const int &sec = -1);
4593 bool createFD(
const bool &flag1 =
false,
const int &sec = -1);
4612 UdpServer(
const int &port,
const bool &flag1 =
false,
const int &sec = -1,
const bool &flag2 =
true);
4619 bool createFD(
const int &port,
const bool &flag1 =
false,
const int &sec = -1,
const bool &flag2 =
true);
4665 static void setExceptionHandling();
4675 static void setLogFile(file::LogFile *logfile =
nullptr,
const std::string &language =
"");
4682 static void init(file::LogFile *logfile =
nullptr,
const std::string &language =
"");
4704 struct semid_ds *buf;
4705 unsigned short *arry;
4730 bool init(key_t key,
unsigned short value = 1,
short sem_flg = SEM_UNDO);
4740 bool wait(
short value = -1);
4750 bool post(
short value = 1);
4777 #define MAX_PROCESS_NAME 100
4781 #define MAX_PROCESS_INF 1000
4785 #define SHARED_MEMORY_KEY 0x5095
4789 #define SHARED_MEMORY_LOCK_KEY 0x5095
4845 bool join(
const char *name,
const char *argv0 =
"",
const char *argv1 =
"",
const char *argv2 =
"");
4861 static bool HBCheck(
const int &sec);
4866 bool deleteFromHBS();
4902 template<
class... Args>
4903 static bool startProcess(
const std::string &name,
const int &sec = -1, Args ...args)
4905 std::vector<const char *> paramList={args...,
nullptr};
4915 execv(name.c_str(),
const_cast<char* const*
>(paramList.data()));
4919 for(
int ii=1;ii<=64;ii++)
4930 signal(SIGCHLD,SIG_DFL);
4937 execv(name.c_str(),
const_cast<char* const*
>(paramList.data()));
4972 template<
class Fn,
class... Args>
4973 static typename std::enable_if<!std::is_convertible<Fn, std::string>::value,
bool>::type
4985 auto f=std::bind(std::forward<Fn>(fn),std::forward<Args>(args)...);
4990 for(
int ii=1;ii<=64;ii++)
5001 signal(SIGCHLD,SIG_DFL);
5008 auto f=std::bind(std::forward<Fn>(fn),std::forward<Args>(args)...);
5025 using Task = std::function<void()>;
5063 for (
size_t i = 0; i < n; ++i) {
5064 threads_.emplace_back([
this] {
5089 std::lock_guard<std::mutex> lk(mtx_);
5090 tasks_.push(std::move(task));
5107 std::lock_guard<std::mutex> lk(mtx_);
5111 for (
auto &t : threads_)
5113 if (t.joinable()) t.join();
5134 std::unique_lock<std::mutex> lk(mtx_);
5135 cv_.wait(lk, [
this] {
5136 return stop_ || !tasks_.empty();
5138 if (stop_ && tasks_.empty())
5142 task = std::move(tasks_.front());
5150 std::vector<std::thread> threads_;
5151 std::queue<Task> tasks_;
5153 std::condition_variable cv_;
void setSecuritySendBackFun(std::function< void(HttpServerFDHandler &k, HttpRequestInformation &inf)> fc)
Set the callback invoked when an information security policy is violated.
Definition: sttnet_English.h:3873
Unified connection & request security gate (IP-level + fd-level, multi-strategy limiting + blacklist)...
Definition: sttnet_English.h:2242
std::chrono::duration< uint64_t > Seconds
Definition: sttnet_English.h:1008
bool operator>(const Duration &b)
Determine if the current time interval is greater than another time interval.
Definition: sttnet_English.h:740
int getServerPort()
Return the port of the connected client.
Definition: sttnet_English.h:2695
int fd
Low-level sockets.
Definition: sttnet_English.h:3305
SSL * getSSL()
Get the encrypted SSL handle of this object.
Definition: sttnet_English.h:2489
Definition: sttnet_English.h:2157
int checkFrequency
Definition: sttnet_English.h:3348
bool isStart()
Return the timing status of the object.
Definition: sttnet_English.h:1114
TcpFDInf * clientfd
Definition: sttnet_English.h:3326
std::string getServerIp()
Return the server ip if connected to the server.
Definition: sttnet_English.h:3027
bool unblock
Definition: sttnet_English.h:3334
int ret
Return value -2: Failure and connection closed required; -1: Failure but connection closed not requir...
Definition: sttnet_English.h:3309
void setFD(const int &fd, SSL *ssl=nullptr, const bool &flag1=false, const bool &flag2=true)
Initialize the object, pass in socket and other parameters.
Definition: sttnet_English.h:3102
TCP socket operation class.
Definition: sttnet_English.h:2455
static std::string createJson(T1 first, T2 second, Args...args)
Create a JSON string composed of multiple key-value pairs (recursive variadic template).
Definition: sttnet_English.h:1890
A structure representing a time interval, supporting granularity in days, hours, minutes, seconds, and milliseconds.
Definition: sttnet_English.h:708
void setGlobalSolveFunction(std::function< int(HttpServerFDHandler &k, HttpRequestInformation &inf)> fc)
Sets a global backup function.
Definition: sttnet_English.h:3896
WebSocket protocol operation class Only pass in the socket, then use this class for WebSocket operati...
Definition: sttnet_English.h:4012
bool isConnect()
Determine if the object has a socket bound.
Definition: sttnet_English.h:2512
Class for time operations, calculations, and timing.
Definition: sttnet_English.h:1025
int getFD()
Get the socket of this object.
Definition: sttnet_English.h:2484
void waitAndQuit(const time::Duration &t=time::Duration{0, 0, 0, 10, 10})
Start the epoll exit countdown until new messages arrive on the socket If no new messages arrive by t...
Definition: sttnet_English.h:2902
bool operator<=(const Duration &b)
Determine if the current time interval is less than or equal to another time interval.
Definition: sttnet_English.h:804
Http/HttpServer server operation class.
Definition: sttnet_English.h:3683
bool sendMessage(const int &fd, const std::string &msg, const std::string &type="0001")
Send a WebSocket message to a specific client.
Definition: sttnet_English.h:4409
void setCloseFun(std::function< void(const int &fd)> closeFun)
set function after tcp connection close
Definition: sttnet_English.h:3658
Data structure for pushing tasks into a completion queue after they are completed at the work site...
Definition: sttnet_English.h:3300
pid_t pid
Process ID.
Definition: sttnet_English.h:4799
WebSocketClient(const bool &TLS=false, const char *ca="", const char *cert="", const char *key="", const char *passwd="")
Constructor of WebSocketClient class.
Definition: sttnet_English.h:2939
Duration(long long a, int b, int c, int d, int e)
Constructor, taking days, hours, minutes, seconds, milliseconds.
Definition: sttnet_English.h:733
int getFD()
Return fd.
Definition: sttnet_English.h:4496
std::string loc
The file path.
Definition: sttnet_English.h:302
unsigned long p_buffer_now
Receives a spatial position pointer.
Definition: sttnet_English.h:3286
bool isConnect()
Return the connection status of the object.
Definition: sttnet_English.h:2700
MPSCQueue & operator=(const MPSCQueue &)=delete
std::ostream & operator<<(std::ostream &os, const Duration &a)
Output the Duration object to a stream in a readable format.
LogFile(const size_t &logQueue_cap=8192)
Constructor, initializes the consumer thread.
Definition: sttnet_English.h:1161
int sec
Seconds.
Definition: sttnet_English.h:725
~TcpServer()
Destructor of TcpServer class.
Definition: sttnet_English.h:3674
double convertToMin()
Convert the current time interval to a floating-point representation in minutes.
Definition: sttnet_English.h:927
unsigned long buffer_size
Definition: sttnet_English.h:3321
std::string getServerPort()
Return the server port if connected to the server.
Definition: sttnet_English.h:3032
unsigned long long maxFD
Definition: sttnet_English.h:3322
int serverType
Definition: sttnet_English.h:3343
#define ISO8086A
Define the macro ISO8086A as "yyyy-mm-ddThh:mi:ss".
Definition: sttnet_English.h:1012
void setTimeOutFunction(std::function< bool(const int &fd)> fcTimeOut)
Set the callback function triggered after epoll timeout Register a callback function.
Definition: sttnet_English.h:2885
Duration recoverForm(const long long &t)
Recover the standard days-hours-minutes-seconds-milliseconds format from given milliseconds.
Definition: sttnet_English.h:958
static std::string createArray(T first)
Create a JSON array string containing only one element.
Definition: sttnet_English.h:1915
std::queue< std::any > pendindQueue
Queue waiting to be processed.
Definition: sttnet_English.h:3294
Responsible for conversion between strings and numbers.
Definition: sttnet_English.h:1695
~EpollSingle()
Destructor of EpollSingle Calls eldListen to block and exit epoll.
Definition: sttnet_English.h:2907
int threads
Records how many threads are currently using the file.
Definition: sttnet_English.h:306
static std::string language
Language selection for the system's logging system, default is English.
Definition: sttnet_English.h:4651
Class responsible for process heartbeat monitoring and scheduling Used to monitor service processes a...
Definition: sttnet_English.h:4829
std::deque< std::chrono::steady_clock::time_point > history
Definition: sttnet_English.h:2072
size_t getFileSize()
Get the size of the file opened in binary mode.
Definition: sttnet_English.h:446
Definition: sttnet_English.h:2159
Tcp server class.
Definition: sttnet_English.h:3316
uint64_t connection_obj_fd
connection objection fd
Definition: sttnet_English.h:3254
stt::system::WorkerPool * workpool
Definition: sttnet_English.h:3320
static std::string createArray(T first, Args...args)
Create a JSON array string composed of multiple elements (recursive variadic template).
Definition: sttnet_English.h:1933
static std::mutex l1
Definition: sttnet_English.h:328
std::string port
Client port.
Definition: sttnet_English.h:3262
void setFunction(const std::string &key, std::function< int(WebSocketServerFDHandler &, WebSocketFDInformation &)> fc)
Register a message handler callback for a specific key.
Definition: sttnet_English.h:4346
UDP operation class Pass in the socket for UDP protocol operations.
Definition: sttnet_English.h:4463
int requestTimes
Definition: sttnet_English.h:3347
size_t getSize1()
Get the size of the file opened in binary mode in memory.
Definition: sttnet_English.h:455
static std::enable_if<!std::is_convertible< Fn, std::string >::value, bool >::type startProcess(Fn &&fn, const int &sec=-1, Args &&...args)
Create a child process through a function (with the option to restart periodically) ...
Definition: sttnet_English.h:4974
uint64_t connection_obj_fd
Definition: sttnet_English.h:3349
~File()
Destructor.
Definition: sttnet_English.h:413
HttpClient(const bool &TLS=false, const char *ca="", const char *cert="", const char *key="", const char *passwd="")
Constructor of HttpClient class.
Definition: sttnet_English.h:2727
bool push(const T &v) noexcept(std::is_nothrow_copy_constructible_v< T >)
Definition: sttnet_English.h:132
WebSocketServer server operation class.
Definition: sttnet_English.h:4067
Operation class for parsing and responding to Http/https requests Only pass in the socket...
Definition: sttnet_English.h:3092
void setGlobalSolveFunction(std::function< bool(TcpFDHandler &k, TcpInformation &inf)> fc)
Set global fallback function.
Definition: sttnet_English.h:3579
bool operator<(const Duration &b)
Determine if the current time interval is less than another time interval.
Definition: sttnet_English.h:756
bool isConnect()
Return the connection status.
Definition: sttnet_English.h:3017
Responsible for encryption, decryption, and hashing.
Definition: sttnet_English.h:1244
Responsible for floating-point precision processing.
Definition: sttnet_English.h:1421
void stop()
Stop the thread pool and wait for all threads to exit.
Definition: sttnet_English.h:5104
SSL_CTX * ctx
Definition: sttnet_English.h:3335
Responsible for conversion between binary data and strings.
Definition: sttnet_English.h:1299
class of solving json data
Definition: sttnet_English.h:1826
bool push(T &&v) noexcept(std::is_nothrow_move_constructible_v< T >)
Try push (non-blocking). Returns false if queue is full. 尝试入队(非阻塞),队列满则返回 false.
Definition: sttnet_English.h:128
~HttpServer()
Destructor.
Definition: sttnet_English.h:4005
int connectionTimes
Definition: sttnet_English.h:3345
MPSCQueue(std::size_t capacity_pow2)
Definition: sttnet_English.h:96
std::unordered_map< std::string, RateState > pathRate
Definition: sttnet_English.h:2099
Structure for process information.
Definition: sttnet_English.h:4794
static std::unordered_map< std::string, FileThreadLock > fl2
Definition: sttnet_English.h:329
std::size_t approx_size() const noexcept
Approximate size (may be inaccurate under concurrency) 近似长度(并发下可能不精确)
Definition: sttnet_English.h:170
TCP client operation class.
Definition: sttnet_English.h:2625
Responsible for HTTP string and URL parsing Including functions to extract parameters, IP, port, request header fields, etc., from URLs or request messages.
Definition: sttnet_English.h:1476
double convertToHour()
Convert the current time interval to a floating-point representation in hours.
Definition: sttnet_English.h:917
void setGetKeyFunction(std::function< int(HttpServerFDHandler &k, HttpRequestInformation &inf)> parseKeyFun)
Set the callback function used to parse the key.
Definition: sttnet_English.h:3982
csemp()
Constructor, initializes internal state.
Definition: sttnet_English.h:4718
time_t lastTime
Last heartbeat time of the process, as a timestamp.
Definition: sttnet_English.h:4803
long long day
Days.
Definition: sttnet_English.h:713
void setGetKeyFunction(std::function< int(TcpFDHandler &k, TcpInformation &inf)> parseKeyFun)
Set the callback function used to parse the key.
Definition: sttnet_English.h:3631
void setGlobalSolveFunction(std::function< bool(WebSocketServerFDHandler &, WebSocketFDInformation &)> fc)
Set the global fallback handler.
Definition: sttnet_English.h:4299
void setSecuritySendBackFun(std::function< void(TcpFDHandler &k, TcpInformation &inf)> fc)
Set the callback invoked when an information security policy is violated.
Definition: sttnet_English.h:3561
void setFunction(const std::string &key, std::function< int(TcpFDHandler &k, TcpInformation &inf)> fc)
Register a callback function for a specific key.
Definition: sttnet_English.h:3603
std::mutex lock
The lock for this file.
Definition: sttnet_English.h:310
int min
Minutes.
Definition: sttnet_English.h:721
void endListenWithSignal()
Send a signal to end epoll.
Definition: sttnet_English.h:2896
WorkerPool(size_t n)
Constructor, creates a specified number of worker threads.
Definition: sttnet_English.h:5061
void setStartFunction(std::function< bool(WebSocketServerFDHandler &, WebSocketFDInformation &)> fccc)
Set the callback invoked immediately after a WebSocket connection is established. ...
Definition: sttnet_English.h:4312
Lock-free bounded MPSC queue (Multi-Producer Single-Consumer) 无锁有界多生产者单消费者队列(环形缓冲) ...
Definition: sttnet_English.h:94
WebSocketServer(const unsigned long long &maxFD=1000000, const int &buffer_size=256, const size_t &finishQueue_cap=65536, const bool &security_open=true, const int &connectionNumLimit=5, const int &connectionSecs=10, const int &connectionTimes=3, const int &requestSecs=1, const int &requestTimes=10, const int &checkFrequency=60, const int &connectionTimeout=120)
Constructor.
Definition: sttnet_English.h:4221
double convertToSec()
Convert the current time interval to a floating-point representation in seconds.
Definition: sttnet_English.h:937
std::chrono::duration< uint64_t, std::milli > Milliseconds
Definition: sttnet_English.h:1007
std::string getUrl()
Return the url if connected to the server.
Definition: sttnet_English.h:3022
static file::LogFile * logfile
Pointer to the log file object for reading and writing logs in the system.
Definition: sttnet_English.h:4647
TLSState
Definition: sttnet_English.h:3212
static std::string createHeader(const std::string &first, const std::string &second, Args...args)
Recursively construct multiple HTTP request header fields.
Definition: sttnet_English.h:1667
time::Duration operator+(const time::Duration &b)
Add two time intervals.
Definition: sttnet_English.h:820
Listen to a single handle with epoll.
Definition: sttnet_English.h:2826
int workerEventFD
Definition: sttnet_English.h:3342
int FDStatus
Record which step the current state machine is at.
Definition: sttnet_English.h:3290
~WorkerPool()
destructor
Definition: sttnet_English.h:5075
void setSecuritySendBackFun(std::function< void(WebSocketServerFDHandler &k, WebSocketFDInformation &inf)> fc)
Set the callback invoked when an information security policy is violated.
Definition: sttnet_English.h:4279
bool sendMessage(const std::string &msg, const std::string &type="0001")
Send a websocket message.
void setFD(const int &fd, SSL *ssl=nullptr, const bool &flag1=false, const bool &flag2=true)
Initialize the object, pass in socket and other parameters.
Definition: sttnet_English.h:4022
int connectionSecs
Definition: sttnet_English.h:3344
FileThreadLock(const std::string &loc, const int &threads)
The constructor of this structure.
Definition: sttnet_English.h:316
bool operator>=(const Duration &b)
Determine if the current time interval is greater than or equal to another time interval.
Definition: sttnet_English.h:788
std::string getFileName()
Get the name of the opened file.
Definition: sttnet_English.h:428
~TcpClient()
Destructor of TcpClient, closes and releases the socket and its connection.
Definition: sttnet_English.h:2684
void setGetKeyFunction(std::function< int(WebSocketServerFDHandler &, WebSocketFDInformation &)> parseKeyFun)
Set the key parsing callback.
Definition: sttnet_English.h:4359
void setEndFunction(std::function< void(const int &fd)> fcEnd)
Set the callback function before epoll exits Register a callback function.
Definition: sttnet_English.h:2875
bool pop(T &out) noexcept(std::is_nothrow_move_assignable_v< T > &&std::is_nothrow_move_constructible_v< T >)
Try pop (single consumer). Returns false if empty. 尝试出队(单消费者),空则返回 false.
Definition: sttnet_English.h:140
Responsible for string operations related to the WebSocket protocol.
Definition: sttnet_English.h:1676
Duration getDt()
Get the last timing duration.
Definition: sttnet_English.h:1109
Data encoding/decoding, mask processing, etc.
Definition: sttnet_English.h:1764
std::function< void()> Task
Definition: sttnet_English.h:5025
~UdpServer()
Destructor, closes the socket when the object's life ends.
Definition: sttnet_English.h:4623
bool startListen(const int &port, const int &threads=8)
Start the HTTP server listening loop.
Definition: sttnet_English.h:3996
bool operator==(const Duration &b)
Determine if the current time interval is equal to another time interval.
Definition: sttnet_English.h:772
Runtime state for one limiter key (reused by multiple strategies).
Definition: sttnet_English.h:2064
char * buffer
Receives the space pointer.
Definition: sttnet_English.h:3282
A structure that records the relationship between files and threads.
Definition: sttnet_English.h:297
int status
The current fd status, used to save the processor logic.
Definition: sttnet_English.h:3266
void writeLog(const std::string &data)
Write a line of log.
void setJudgeFunction(std::function< bool(WebSocketFDInformation &)> fcc)
Set the handshake validation callback.
Definition: sttnet_English.h:4328
#define MAX_PROCESS_NAME
Define the macro MAX_PROCESS_NAME as 100, meaning the process name in process information does not ex...
Definition: sttnet_English.h:4777
Class for initializing the service system.
Definition: sttnet_English.h:4641
~UdpClient()
Destructor, closes the socket when the object's life ends.
Definition: sttnet_English.h:4597
uint64_t getFileLine()
Get the number of lines in the opened file.
Definition: sttnet_English.h:437
bool isOpen()
Check if the object has opened a file.
Definition: sttnet_English.h:418
bool isReturn()
Get the server response status.
Definition: sttnet_English.h:2812
int requestSecs
Definition: sttnet_English.h:3346
std::string_view data
Save the data received from the client.
Definition: sttnet_English.h:3270
Security and limiter state for a single connection (fd).
Definition: sttnet_English.h:2095
RateState requestRate
Definition: sttnet_English.h:2098
TLSState tls_state
tls state
Definition: sttnet_English.h:3278
Websocket client operation class.
Definition: sttnet_English.h:2915
bool isBinary()
Check if the object has opened the file in binary mode.
Definition: sttnet_English.h:423
std::string getServerIP()
Return the IP of the connected server.
Definition: sttnet_English.h:2690
void submit(Task task)
Submit a task to the thread pool.
Definition: sttnet_English.h:5086
Synchronization tool class encapsulating System V semaphores.
Definition: sttnet_English.h:4693
~MPSCQueue()
Definition: sttnet_English.h:118
RateLimitType
Rate limiting algorithm / strategy type.
Definition: sttnet_English.h:2035
Responsible for endianness conversion.
Definition: sttnet_English.h:1401
time::Duration operator-(const time::Duration &b)
Calculate the difference between two time intervals (current object minus parameter b)...
Definition: sttnet_English.h:864
~WebSocketServer()
Destructor.
Definition: sttnet_English.h:4452
TcpServer(const unsigned long long &maxFD=1000000, const int &buffer_size=256, const size_t &finishQueue_cap=65536, const bool &security_open=true, const int &connectionNumLimit=20, const int &connectionSecs=1, const int &connectionTimes=6, const int &requestSecs=1, const int &requestTimes=40, const int &checkFrequency=60, const int &connectionTimeout=60)
Constructor.
Definition: sttnet_English.h:3465
std::mutex che
Definition: sttnet_English.h:331
bool startListen(const int &port, const int &threads=8)
Start the WebSocket server.
Definition: sttnet_English.h:4434
std::string getFileName()
Get the file name opened by the object.
Definition: sttnet_English.h:1203
Udp server operation class.
Definition: sttnet_English.h:4602
double convertToDay()
Convert the current time interval to a floating-point representation in days.
Definition: sttnet_English.h:907
bool isListen()
Return epoll listening status.
Definition: sttnet_English.h:2857
Http/Https client operation class.
Definition: sttnet_English.h:2710
int fd
Socket file descriptor.
Definition: sttnet_English.h:3250
bool security_open
Definition: sttnet_English.h:3339
Static utility class for process management.
Definition: sttnet_English.h:4877
int hour
Hours.
Definition: sttnet_English.h:717
long long convertToMsec()
Convert the current time interval to total milliseconds.
Definition: sttnet_English.h:947
void setFunction(std::function< bool(const int &fd)> fc)
Set the processing function after epoll triggering Register a callback function.
Definition: sttnet_English.h:2867
Udp client operation class.
Definition: sttnet_English.h:4579
static std::string createJson(T1 first, T2 second)
Create a JSON string containing only one key-value pair.
Definition: sttnet_English.h:1865
Structure to save TCP client information.
Definition: sttnet_English.h:3245
void setFunction(const std::string &key, std::function< int(HttpServerFDHandler &k, HttpRequestInformation &inf)> fc)
Register a callback function for a specific key.
Definition: sttnet_English.h:3944
security::ConnectionLimiter connectionLimiter
Definition: sttnet_English.h:3323
std::string ip
Client IP.
Definition: sttnet_English.h:3258
bool isOpen()
Get the status of whether the log file is open.
Definition: sttnet_English.h:1198
DefenseDecision
Security decision returned by ConnectionLimiter.
Definition: sttnet_English.h:2155
void setHBTimeOutTime(const int &secb)
Set heartbeat response timeout.
Definition: sttnet_English.h:4379
ConnectionLimiter(const int &maxConn=20, const int &idleTimeout=60)
Constructor.
Definition: sttnet_English.h:2251
Log file operation class.
Definition: sttnet_English.h:1124
A class for reading and writing disk files.
Definition: sttnet_English.h:325
int msec
Milliseconds.
Definition: sttnet_English.h:729
Related to random number and string generation.
Definition: sttnet_English.h:1365
SSL * ssl
If encrypted, store the encryption handle.
Definition: sttnet_English.h:3274
bool isListen()
Return the listening status of the object.
Definition: sttnet_English.h:3664
Definition: sttnet_English.h:2158
static bool startProcess(const std::string &name, const int &sec=-1, Args...args)
Start a new process (with the option to restart periodically)
Definition: sttnet_English.h:4903
void setTimeOutTime(const int &seca)
Set heartbeat interval.
Definition: sttnet_English.h:4369
void setFunction(std::function< bool(const std::string &message, WebSocketClient &k)> fc)
Set the callback function after receiving a message from the server Register a callback function...
Definition: sttnet_English.h:2950
HttpServer(const unsigned long long &maxFD=1000000, const int &buffer_size=256, const size_t &finishQueue_cap=65536, const bool &security_open=true, const int &connectionNumLimit=10, const int &connectionSecs=1, const int &connectionTimes=3, const int &requestSecs=1, const int &requestTimes=20, const int &checkFrequency=30, const int &connectionTimeout=30)
Constructor.
Definition: sttnet_English.h:3815
system::MPSCQueue< WorkerMessage > finishQueue
Definition: sttnet_English.h:3319
Fixed-size worker thread pool.
Definition: sttnet_English.h:5051