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")
|
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)
|
if(MSVC)
|
||||||
target_link_options(SignerServer PRIVATE
|
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"
|
#include "server.h"
|
||||||
|
|
||||||
Server server(8080);
|
Server server(1145);
|
@ -7,18 +7,14 @@
|
|||||||
|
|
||||||
Sign sign;
|
Sign sign;
|
||||||
|
|
||||||
// HTTP server event handler function
|
Server::Server(int port)
|
||||||
void ev_handler(struct mg_connection *c, int ev, void *ev_data)
|
|
||||||
{
|
{
|
||||||
if (ev == MG_EV_HTTP_MSG)
|
svr.Post("/sign", [](const httplib::Request &req, httplib::Response &res)
|
||||||
{
|
|
||||||
struct mg_http_message *hm = reinterpret_cast<mg_http_message *>(ev_data);
|
|
||||||
if (mg_match(hm->uri, mg_str("/sign"), NULL))
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
rapidjson::Document doc;
|
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 cmd = doc["cmd"].GetString();
|
||||||
std::string_view src = doc["src"].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.String(tokenDataHex.c_str());
|
||||||
writer.EndObject();
|
writer.EndObject();
|
||||||
|
|
||||||
mg_http_reply(c, 200, NULL, buffer.GetString());
|
res.set_content(buffer.GetString(), "application/json");
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
mg_http_reply(c, 400, NULL, "400 Bad Request");
|
res.set_content("Bad Request", "text/plain");
|
||||||
return;
|
res.status = httplib::StatusCode::BadRequest_400;
|
||||||
}
|
} });
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mg_http_reply(c, 404, NULL, "404 Not Found");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log request
|
std::thread([this, port]
|
||||||
// MG_INFO(("%.*s %.*s %lu -> %.*s %lu", hm->method.len, hm->method.buf,
|
{ svr.listen("0.0.0.0", port); }).detach();
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
#include "../include/mongoose/mongoose.h"
|
#include "../include/cpp-httplib/httplib.h"
|
||||||
|
|
||||||
class Server
|
class Server
|
||||||
{
|
{
|
||||||
@ -6,8 +6,5 @@ public:
|
|||||||
Server(int port);
|
Server(int port);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct mg_mgr mgr; // Declare event manager
|
httplib::Server svr;
|
||||||
|
|
||||||
private:
|
|
||||||
void Loop();
|
|
||||||
};
|
};
|
22
src/sign.cpp
22
src/sign.cpp
@ -45,7 +45,7 @@ std::map<std::string, uint64_t> addrMap = {
|
|||||||
{"6.9.20-17153", 0x1c73dd0}};
|
{"6.9.20-17153", 0x1c73dd0}};
|
||||||
#endif
|
#endif
|
||||||
#elif defined(_LINUX_PLATFORM_)
|
#elif defined(_LINUX_PLATFORM_)
|
||||||
#define CURRENT_VERSION "3.2.7-23361"
|
#define CURRENT_VERSION "3.1.2-13107"
|
||||||
#if defined(_X64_ARCH_)
|
#if defined(_X64_ARCH_)
|
||||||
std::map<std::string, uint64_t> addrMap = {
|
std::map<std::string, uint64_t> addrMap = {
|
||||||
{"3.1.2-12912", 0x33C38E0},
|
{"3.1.2-12912", 0x33C38E0},
|
||||||
@ -53,7 +53,7 @@ std::map<std::string, uint64_t> addrMap = {
|
|||||||
{"3.2.7-23361", 0x4C93C57}};
|
{"3.2.7-23361", 0x4C93C57}};
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
int SignOffsets = 767; // 562 in 3.1.2-12912
|
int SignOffsets = 562; // 562 in 3.1.2-12912
|
||||||
int ExtraOffsets = 511;
|
int ExtraOffsets = 511;
|
||||||
int TokenOffsets = 255;
|
int TokenOffsets = 255;
|
||||||
|
|
||||||
@ -150,9 +150,9 @@ std::tuple<std::string, std::string, std::string> Sign::Call(const std::string_v
|
|||||||
if (SignFunction == nullptr)
|
if (SignFunction == nullptr)
|
||||||
throw std::runtime_error("Sign function not initialized");
|
throw std::runtime_error("Sign function not initialized");
|
||||||
|
|
||||||
printf("cmd: %s\n", cmd.data());
|
// printf("cmd: %s\n", cmd.data());
|
||||||
printf("src: %s\n", src.data());
|
// printf("src: %s\n", src.data());
|
||||||
printf("seq: %d\n", seq);
|
// printf("seq: %d\n", seq);
|
||||||
|
|
||||||
const std::vector<uint8_t> signArgSrc = Hex2Bin(src);
|
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);
|
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());
|
||||||
|
|
||||||
// 获取大小
|
std::string signDataHex = Bin2Hex(signResult + 512, *(signResult + SignOffsets));
|
||||||
uint32_t signSizeU32 = *(signResult + SignOffsets);
|
std::string extraDataHex = Bin2Hex(signResult + 256, *(signResult + ExtraOffsets));
|
||||||
uint32_t extraSizeU32 = *(signResult + ExtraOffsets);
|
std::string tokenDataHex = Bin2Hex(signResult, *(signResult + TokenOffsets));
|
||||||
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);
|
|
||||||
|
|
||||||
return std::make_tuple(signDataHex, extraDataHex, tokenDataHex);
|
return std::make_tuple(signDataHex, extraDataHex, tokenDataHex);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user