mirror of
https://github.com/Simplxss/SignerServer.git
synced 2024-11-21 00:37:53 +08:00
muti thread
This commit is contained in:
parent
d4a43b89b3
commit
ea42c03794
@ -21,7 +21,7 @@ set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
file(GLOB SOURCE_FILES "./src/*.cpp" "./src/*.asm")
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} "./include/mongoose/mongoose.c")
|
||||
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
|
||||
|
||||
if(MSVC)
|
||||
target_link_options(SignerServer PRIVATE
|
||||
|
9788
include/cpp-httplib/httplib.h
Normal file
9788
include/cpp-httplib/httplib.h
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,3 @@
|
||||
#include "server.h"
|
||||
|
||||
Server server(8080);
|
||||
Server server(1145);
|
@ -7,18 +7,14 @@
|
||||
|
||||
Sign sign;
|
||||
|
||||
// HTTP server event handler function
|
||||
void ev_handler(struct mg_connection *c, int ev, void *ev_data)
|
||||
Server::Server(int port)
|
||||
{
|
||||
if (ev == MG_EV_HTTP_MSG)
|
||||
{
|
||||
struct mg_http_message *hm = reinterpret_cast<mg_http_message *>(ev_data);
|
||||
if (mg_match(hm->uri, mg_str("/sign"), NULL))
|
||||
svr.Post("/sign", [](const httplib::Request &req, httplib::Response &res)
|
||||
{
|
||||
try
|
||||
{
|
||||
rapidjson::Document doc;
|
||||
doc.Parse(hm->body.buf, hm->body.len);
|
||||
doc.Parse(req.body.c_str(), req.body.size());
|
||||
|
||||
std::string_view cmd = doc["cmd"].GetString();
|
||||
std::string_view src = doc["src"].GetString();
|
||||
@ -38,43 +34,14 @@ void ev_handler(struct mg_connection *c, int ev, void *ev_data)
|
||||
writer.String(tokenDataHex.c_str());
|
||||
writer.EndObject();
|
||||
|
||||
mg_http_reply(c, 200, NULL, buffer.GetString());
|
||||
res.set_content(buffer.GetString(), "application/json");
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
mg_http_reply(c, 400, NULL, "400 Bad Request");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mg_http_reply(c, 404, NULL, "404 Not Found");
|
||||
}
|
||||
res.set_content("Bad Request", "text/plain");
|
||||
res.status = httplib::StatusCode::BadRequest_400;
|
||||
} });
|
||||
|
||||
// Log request
|
||||
// MG_INFO(("%.*s %.*s %lu -> %.*s %lu", hm->method.len, hm->method.buf,
|
||||
// hm->uri.len, hm->uri.buf, hm->body.len, 3, c->send.buf + 9,
|
||||
// c->send.len));
|
||||
}
|
||||
}
|
||||
|
||||
Server::Server(int port)
|
||||
{
|
||||
char url[32];
|
||||
snprintf(url, sizeof(url), "http://0.0.0.0:%d", port);
|
||||
|
||||
mg_mgr_init(&mgr); // Initialise event manager
|
||||
mg_http_listen(&mgr, url, ev_handler, NULL); // Setup listener
|
||||
|
||||
// new thread to loop
|
||||
std::thread t(&Server::Loop, this);
|
||||
t.detach();
|
||||
}
|
||||
|
||||
void Server::Loop()
|
||||
{
|
||||
for (;;)
|
||||
{ // Run an infinite event loop
|
||||
mg_mgr_poll(&mgr, 1000);
|
||||
}
|
||||
std::thread([this, port]
|
||||
{ svr.listen("0.0.0.0", port); }).detach();
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
#include "../include/mongoose/mongoose.h"
|
||||
#include "../include/cpp-httplib/httplib.h"
|
||||
|
||||
class Server
|
||||
{
|
||||
@ -6,8 +6,5 @@ public:
|
||||
Server(int port);
|
||||
|
||||
private:
|
||||
struct mg_mgr mgr; // Declare event manager
|
||||
|
||||
private:
|
||||
void Loop();
|
||||
httplib::Server svr;
|
||||
};
|
22
src/sign.cpp
22
src/sign.cpp
@ -45,7 +45,7 @@ std::map<std::string, uint64_t> addrMap = {
|
||||
{"6.9.20-17153", 0x1c73dd0}};
|
||||
#endif
|
||||
#elif defined(_LINUX_PLATFORM_)
|
||||
#define CURRENT_VERSION "3.2.7-23361"
|
||||
#define CURRENT_VERSION "3.1.2-13107"
|
||||
#if defined(_X64_ARCH_)
|
||||
std::map<std::string, uint64_t> addrMap = {
|
||||
{"3.1.2-12912", 0x33C38E0},
|
||||
@ -53,7 +53,7 @@ std::map<std::string, uint64_t> addrMap = {
|
||||
{"3.2.7-23361", 0x4C93C57}};
|
||||
#endif
|
||||
#endif
|
||||
int SignOffsets = 767; // 562 in 3.1.2-12912
|
||||
int SignOffsets = 562; // 562 in 3.1.2-12912
|
||||
int ExtraOffsets = 511;
|
||||
int TokenOffsets = 255;
|
||||
|
||||
@ -150,9 +150,9 @@ std::tuple<std::string, std::string, std::string> Sign::Call(const std::string_v
|
||||
if (SignFunction == nullptr)
|
||||
throw std::runtime_error("Sign function not initialized");
|
||||
|
||||
printf("cmd: %s\n", cmd.data());
|
||||
printf("src: %s\n", src.data());
|
||||
printf("seq: %d\n", seq);
|
||||
// printf("cmd: %s\n", cmd.data());
|
||||
// printf("src: %s\n", src.data());
|
||||
// printf("seq: %d\n", seq);
|
||||
|
||||
const std::vector<uint8_t> signArgSrc = Hex2Bin(src);
|
||||
|
||||
@ -161,15 +161,11 @@ std::tuple<std::string, std::string, std::string> Sign::Call(const std::string_v
|
||||
|
||||
SignFunction(cmd.data(), signArgSrc.data(), signArgSrc.size(), seq, signResult);
|
||||
|
||||
printf("signResult: %s\n", Bin2Hex(signResult, resultSize).c_str());
|
||||
// printf("signResult: %s\n", Bin2Hex(signResult, resultSize).c_str());
|
||||
|
||||
// 获取大小
|
||||
uint32_t signSizeU32 = *(signResult + SignOffsets);
|
||||
uint32_t extraSizeU32 = *(signResult + ExtraOffsets);
|
||||
uint32_t tokenSizeU32 = *(signResult + TokenOffsets);
|
||||
std::string signDataHex = Bin2Hex(signResult + 512, signSizeU32);
|
||||
std::string extraDataHex = Bin2Hex(signResult + 256, extraSizeU32);
|
||||
std::string tokenDataHex = Bin2Hex(signResult, tokenSizeU32);
|
||||
std::string signDataHex = Bin2Hex(signResult + 512, *(signResult + SignOffsets));
|
||||
std::string extraDataHex = Bin2Hex(signResult + 256, *(signResult + ExtraOffsets));
|
||||
std::string tokenDataHex = Bin2Hex(signResult, *(signResult + TokenOffsets));
|
||||
|
||||
return std::make_tuple(signDataHex, extraDataHex, tokenDataHex);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user