修正了随机数发生器
This commit is contained in:
parent
e7d167d8d9
commit
68e26768fc
@ -80,7 +80,7 @@
|
||||
92C34C38220747B300AB38D3 /* sha1.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = sha1.h; path = include/sha1.h; sourceTree = "<group>"; };
|
||||
92C34C3922074B5B00AB38D3 /* rsa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = rsa.h; path = include/rsa.h; sourceTree = "<group>"; };
|
||||
92C34C3A22074B6500AB38D3 /* rsa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = rsa.cpp; path = src/rsa.cpp; sourceTree = "<group>"; };
|
||||
92C34C3C2207F37A00AB38D3 /* rng.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = rng.h; path = include/rng.h; sourceTree = "<group>"; };
|
||||
92C34C3C2207F37A00AB38D3 /* rng.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = rng.hpp; path = include/rng.hpp; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@ -130,7 +130,7 @@
|
||||
9277A14C21FD7246009C5F11 /* clock.h */,
|
||||
9277A14621FD7246009C5F11 /* cmap.h */,
|
||||
9277A14921FD7246009C5F11 /* compute.h */,
|
||||
92C34C3C2207F37A00AB38D3 /* rng.h */,
|
||||
92C34C3C2207F37A00AB38D3 /* rng.hpp */,
|
||||
92C34C38220747B300AB38D3 /* sha1.h */,
|
||||
9277A14B21FD7246009C5F11 /* cpart.h */,
|
||||
9277A14A21FD7246009C5F11 /* cthread.h */,
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "cthread.h"
|
||||
#include "sha1.h"
|
||||
#include "rsa.h"
|
||||
#include "rng.hpp"
|
||||
|
||||
namespace error{
|
||||
void printError(string error_info);
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "cthread.h"
|
||||
#include "sqlite3.h"
|
||||
#include "rsa.h"
|
||||
#include "rng.h"
|
||||
#include "rng.hpp"
|
||||
|
||||
class Server;
|
||||
|
||||
@ -31,7 +31,7 @@ struct compute_result{
|
||||
//请求数据包
|
||||
struct request {
|
||||
// 匹配id
|
||||
rng::rng64 r_id;
|
||||
uint64_t r_id;
|
||||
// 类型
|
||||
string type;
|
||||
// 数据
|
||||
@ -48,7 +48,7 @@ struct request {
|
||||
struct encrypt_post{
|
||||
// 明文部分
|
||||
// 注册客户端id
|
||||
rng::rng64 client_id;
|
||||
uint64_t client_id;
|
||||
// 目标ip
|
||||
string ip;
|
||||
// 目标端口
|
||||
@ -65,7 +65,7 @@ struct encrypt_post{
|
||||
|
||||
//回复数据包
|
||||
struct respond {
|
||||
rng::rng64 r_id;
|
||||
uint64_t r_id;
|
||||
string type;
|
||||
Byte *buff = nullptr;
|
||||
uint32_t buff_size;
|
||||
@ -90,7 +90,7 @@ public:
|
||||
//注册客户端管理
|
||||
struct client_register{
|
||||
// 客户端id
|
||||
rng::rng64 client_id;
|
||||
uint64_t client_id;
|
||||
// 通信密钥
|
||||
rng::rng128 key;
|
||||
|
||||
@ -138,6 +138,11 @@ struct server_info{
|
||||
string key;
|
||||
};
|
||||
|
||||
struct aes_key256{
|
||||
uint64_t key[4];
|
||||
aes_key256();
|
||||
};
|
||||
|
||||
//通用服务器类
|
||||
class Server{
|
||||
protected:
|
||||
|
@ -77,7 +77,7 @@ void Client::ProcessRequestListener(void){
|
||||
for(auto &lreq : req_lst){
|
||||
if(!lreq->active) continue;
|
||||
// 检查回复号与请求号是否相同
|
||||
if(!memcmp(&lreq->p_req->r_id,&pres->r_id,sizeof(rng::rng64))){
|
||||
if(lreq->p_req->r_id == pres->r_id){
|
||||
// 调用回调函数
|
||||
lreq->callback(pres,lreq->args);
|
||||
lreq->active = false;
|
||||
|
@ -342,7 +342,7 @@ int client(string instruct, vector<string> &configs, vector<string> &lconfigs, v
|
||||
public_key_class *ppbc = (public_key_class *)sqlite3_column_blob(psqlsmt, 0);
|
||||
nclt.SetPublicKey(*ppbc);
|
||||
sqlite3_finalize(psqlsmt);
|
||||
rng::rng128 key
|
||||
|
||||
// 已获得主广场服务器的密钥,进行启动客户端守护进程前的准备工作
|
||||
nclt.NewRequest(&preq, msqe_ip, msqe_port, "client-register request", "");
|
||||
nclt.NewRequestListener(preq, 30, psql, getSQEPublicKey);
|
||||
|
@ -8,6 +8,10 @@
|
||||
|
||||
#include "instruct.h"
|
||||
|
||||
// 初始化随机数引擎
|
||||
rng::rng64 rand64(rng::tsc_seed{}());
|
||||
rng::rng128 rand128({rng::tsc_seed{}(),rng::tsc_seed{}()});
|
||||
|
||||
int main(int argc, const char *argv[]){
|
||||
// 命令
|
||||
string instruct;
|
||||
|
@ -10,6 +10,11 @@
|
||||
#include "server.h"
|
||||
|
||||
extern list<clock_register> clocks_list;
|
||||
extern rng::rng64 rand64;
|
||||
extern rng::rng128 rand128;
|
||||
|
||||
|
||||
|
||||
pthread_mutex_t mutex,mutex_rp,mutex_pktreq,mutex_sndpkt;
|
||||
|
||||
void setServerClock(Server *psvr, int clicks){
|
||||
@ -438,7 +443,7 @@ SQEServer::SQEServer(int port):Server(port){
|
||||
|
||||
void SQEServer::Packet2Request(packet &pkt, request &req){
|
||||
if(pkt.type == REQUSET_TYPE){
|
||||
req.r_id = *(rng::rng64 *)pkt.buffs[0].second;
|
||||
req.r_id = *(uint64_t *)pkt.buffs[0].second;
|
||||
req.type = (const char *)pkt.buffs[1].second;
|
||||
req.data = (const char *)pkt.buffs[2].second;
|
||||
req.t_addr = Addr(*(struct sockaddr_in *)pkt.buffs[3].second);
|
||||
@ -496,7 +501,7 @@ void SQEServer::ProcessRequset(void){
|
||||
}
|
||||
|
||||
void SQEServer::Packet2Respond(packet &pkt, respond &res){
|
||||
res.r_id = *(rng::rng64 *)pkt.buffs[0].second;
|
||||
res.r_id = *(uint64_t *)pkt.buffs[0].second;
|
||||
res.t_addr.SetSockAddr(*(struct sockaddr_in *)pkt.buffs[1].second);
|
||||
res.type = (const char *)pkt.buffs[2].second;
|
||||
res.buff_size = pkt.buffs[3].first;
|
||||
@ -514,7 +519,7 @@ void SQEServer::Respond2Packet(packet &pkt, respond &res){
|
||||
}
|
||||
|
||||
request::request(){
|
||||
r_id = rng::tsc_seed{}();
|
||||
r_id = rand64();
|
||||
}
|
||||
|
||||
void respond::SetBuff(Byte *buff, uint32_t size){
|
||||
@ -552,3 +557,7 @@ void Server::ProcessSendPackets(void){
|
||||
packets_out.remove_if([](auto ppkt){return ppkt == nullptr;});
|
||||
pthread_mutex_unlock(&mutex_sndpkt);
|
||||
}
|
||||
|
||||
aes_key256::aes_key256(){
|
||||
for (int i = 0; i < 4; i++) key[i] = rand64();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user