Skip to content

Commit dd096df

Browse files
committed
p2p distributed protocol it can be used normally Now
1 parent 9800fa4 commit dd096df

File tree

11 files changed

+287
-21
lines changed

11 files changed

+287
-21
lines changed

XEngine_Source/StorageModule_APIHelp/APIHelp_Define.h

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,77 @@
1010
// Purpose: 导出定义
1111
// History:
1212
*********************************************************************/
13+
typedef struct
14+
{
15+
TCHAR tszMsgBuffer[4096];
16+
int nMsgLen;
17+
}APIHELP_LBFILEINFO;
1318
//////////////////////////////////////////////////////////////////////////
1419
// 导出函数
1520
//////////////////////////////////////////////////////////////////////////
1621
extern "C" DWORD StorageHelp_GetLastError(int* pInt_SysError = NULL);
1722
/************************************************************************/
1823
/* */
1924
/************************************************************************/
25+
/********************************************************************
26+
函数名称:APIHelp_Distributed_IsMode
27+
函数功能:判断负载模式是否为指定模式
28+
参数.一:pStl_ListMode
29+
In/Out:In
30+
类型:STL容器指针
31+
可空:N
32+
意思:输入支持的模式列表
33+
参数.二:nMode
34+
In/Out:In
35+
类型:整数型
36+
可空:N
37+
意思:输入要判断的模式
38+
返回值
39+
类型:逻辑型
40+
意思:是否成功
41+
备注:
42+
*********************************************************************/
2043
extern "C" BOOL APIHelp_Distributed_IsMode(list<int>*pStl_ListMode, int nMode);
21-
extern "C" BOOL APIHelp_Distributed_RandomAddr(list<tstring>* pStl_ListAddr, TCHAR* ptszAddr);
44+
/********************************************************************
45+
函数名称:APIHelp_Distributed_RandomAddr
46+
函数功能:随机选择一个负载的重定向服务器地址
47+
参数.一:pStl_ListAddr
48+
In/Out:In
49+
类型:STL容器指针
50+
可空:N
51+
意思:输入负载服务器列表
52+
参数.二:ptszAddr
53+
In/Out:Out
54+
类型:字符指针
55+
可空:N
56+
意思:输出获取到的负载地址
57+
返回值
58+
类型:逻辑型
59+
意思:是否成功
60+
备注:
61+
*********************************************************************/
62+
extern "C" BOOL APIHelp_Distributed_RandomAddr(list<tstring>* pStl_ListAddr, TCHAR* ptszAddr);
63+
/********************************************************************
64+
函数名称:APIHelp_Distributed_FileList
65+
函数功能:解析所有解析到的内容并且打包成指定结构
66+
参数.一:pStl_ListParse
67+
In/Out:In
68+
类型:STL容器指针
69+
可空:N
70+
意思:输入要解析的内容列表
71+
参数.二:pppSt_ListPacket
72+
In/Out:Out
73+
类型:三级指针
74+
可空:N
75+
意思:输出文件信息结构列表
76+
参数.三:pInt_ListCount
77+
In/Out:Out
78+
类型:整数型
79+
可空:N
80+
意思:输出文件列表个数
81+
返回值
82+
类型:逻辑型
83+
意思:是否成功
84+
备注:
85+
*********************************************************************/
86+
extern "C" BOOL APIHelp_Distributed_FileList(list<APIHELP_LBFILEINFO>* pStl_ListParse, XSTORAGECORE_DBFILE*** pppSt_ListPacket, int* pInt_ListCount);

XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.cpp

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,31 @@ CAPIHelp_Distributed::~CAPIHelp_Distributed()
1919
{
2020

2121
}
22+
//////////////////////////////////////////////////////////////////////////
23+
// 公有函数
24+
//////////////////////////////////////////////////////////////////////////
25+
/********************************************************************
26+
函数名称:APIHelp_Distributed_IsMode
27+
函数功能:判断负载模式是否为指定模式
28+
参数.一:pStl_ListMode
29+
In/Out:In
30+
类型:STL容器指针
31+
可空:N
32+
意思:输入支持的模式列表
33+
参数.二:nMode
34+
In/Out:In
35+
类型:整数型
36+
可空:N
37+
意思:输入要判断的模式
38+
返回值
39+
类型:逻辑型
40+
意思:是否成功
41+
备注:
42+
*********************************************************************/
2243
BOOL CAPIHelp_Distributed::APIHelp_Distributed_IsMode(list<int>* pStl_ListMode, int nMode)
2344
{
45+
APIHelp_IsErrorOccur = FALSE;
46+
2447
BOOL bFound = FALSE;
2548
list<int>::const_iterator stl_ListIterator = pStl_ListMode->begin();
2649
for (; stl_ListIterator != pStl_ListMode->end(); stl_ListIterator++)
@@ -33,8 +56,28 @@ BOOL CAPIHelp_Distributed::APIHelp_Distributed_IsMode(list<int>* pStl_ListMode,
3356
}
3457
return bFound;
3558
}
59+
/********************************************************************
60+
函数名称:APIHelp_Distributed_RandomAddr
61+
函数功能:随机选择一个负载的重定向服务器地址
62+
参数.一:pStl_ListAddr
63+
In/Out:In
64+
类型:STL容器指针
65+
可空:N
66+
意思:输入负载服务器列表
67+
参数.二:ptszAddr
68+
In/Out:Out
69+
类型:字符指针
70+
可空:N
71+
意思:输出获取到的负载地址
72+
返回值
73+
类型:逻辑型
74+
意思:是否成功
75+
备注:
76+
*********************************************************************/
3677
BOOL CAPIHelp_Distributed::APIHelp_Distributed_RandomAddr(list<tstring>* pStl_ListAddr, TCHAR* ptszAddr)
3778
{
79+
APIHelp_IsErrorOccur = FALSE;
80+
3881
BOOL bFound = FALSE;
3982
XNETHANDLE xhToken = 0;
4083

@@ -54,4 +97,106 @@ BOOL CAPIHelp_Distributed::APIHelp_Distributed_RandomAddr(list<tstring>* pStl_Li
5497
}
5598
}
5699
return bFound;
100+
}
101+
/********************************************************************
102+
函数名称:APIHelp_Distributed_FileList
103+
函数功能:解析所有解析到的内容并且打包成指定结构
104+
参数.一:pStl_ListParse
105+
In/Out:In
106+
类型:STL容器指针
107+
可空:N
108+
意思:输入要解析的内容列表
109+
参数.二:pppSt_ListPacket
110+
In/Out:Out
111+
类型:三级指针
112+
可空:N
113+
意思:输出文件信息结构列表
114+
参数.三:pInt_ListCount
115+
In/Out:Out
116+
类型:整数型
117+
可空:N
118+
意思:输出文件列表个数
119+
返回值
120+
类型:逻辑型
121+
意思:是否成功
122+
备注:
123+
*********************************************************************/
124+
BOOL CAPIHelp_Distributed::APIHelp_Distributed_FileList(list<APIHELP_LBFILEINFO>* pStl_ListParse, XSTORAGECORE_DBFILE*** pppSt_ListPacket, int* pInt_ListCount)
125+
{
126+
APIHelp_IsErrorOccur = FALSE;
127+
128+
if ((NULL == pStl_ListParse) || (NULL == pppSt_ListPacket))
129+
{
130+
APIHelp_IsErrorOccur = TRUE;
131+
APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_PARAMENT;
132+
return FALSE;
133+
}
134+
135+
BaseLib_OperatorMemory_Malloc((XPPPMEM)pppSt_ListPacket, pStl_ListParse->size(), sizeof(XSTORAGECORE_DBFILE));
136+
list<APIHELP_LBFILEINFO>::const_iterator stl_ListIterator = pStl_ListParse->begin();
137+
for (int i = 0; stl_ListIterator != pStl_ListParse->end(); stl_ListIterator++, i++)
138+
{
139+
APIHelp_Distributed_FileListParse(stl_ListIterator->tszMsgBuffer, stl_ListIterator->nMsgLen, (*pppSt_ListPacket)[i]);
140+
}
141+
*pInt_ListCount = pStl_ListParse->size();
142+
return TRUE;
143+
}
144+
//////////////////////////////////////////////////////////////////////////
145+
// 保护函数
146+
//////////////////////////////////////////////////////////////////////////
147+
/********************************************************************
148+
函数名称:APIHelp_Distributed_FileListParse
149+
函数功能:文件列表解析函数
150+
参数.一:lpszMsgBuffer
151+
In/Out:In
152+
类型:常量字符指针
153+
可空:N
154+
意思:输入要解析的JSON
155+
参数.二:nMsgLen
156+
In/Out:In
157+
类型:整数型
158+
可空:N
159+
意思:输入要解析的大小
160+
参数.三:pSt_DBFile
161+
In/Out:Out
162+
类型:数据结构指针
163+
可空:N
164+
意思:输出解析后的文件信息
165+
返回值
166+
类型:逻辑型
167+
意思:是否成功
168+
备注:
169+
*********************************************************************/
170+
BOOL CAPIHelp_Distributed::APIHelp_Distributed_FileListParse(LPCTSTR lpszMsgBuffer, int nMsgLen, XSTORAGECORE_DBFILE *pSt_DBFile)
171+
{
172+
APIHelp_IsErrorOccur = FALSE;
173+
174+
Json::Value st_JsonRoot;
175+
JSONCPP_STRING st_JsonError;
176+
Json::CharReaderBuilder st_JsonBuilder;
177+
178+
std::unique_ptr<Json::CharReader> const pSt_JsonReader(st_JsonBuilder.newCharReader());
179+
if (!pSt_JsonReader->parse(lpszMsgBuffer, lpszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError))
180+
{
181+
APIHelp_IsErrorOccur = TRUE;
182+
APIHelp_dwErrorCode = ERROR_STORAGE_MODULE_APIHELP_PARSE;
183+
return FALSE;
184+
}
185+
//查找文件列表,一般只有一个
186+
int nCount = st_JsonRoot["Count"].asInt();
187+
Json::Value st_JsonArray = st_JsonRoot["List"];
188+
189+
for (int i = 0; i < nCount; i++)
190+
{
191+
pSt_DBFile->st_ProtocolFile.nFileSize = st_JsonArray[i]["nFileSize"].asInt64();
192+
_tcscpy(pSt_DBFile->tszTableName, st_JsonArray[i]["tszTableName"].asCString());
193+
_tcscpy(pSt_DBFile->st_ProtocolFile.tszFileUser, st_JsonArray[i]["tszFileUser"].asCString());
194+
_tcscpy(pSt_DBFile->st_ProtocolFile.tszFileHash, st_JsonArray[i]["tszFileHash"].asCString());
195+
_tcscpy(pSt_DBFile->st_ProtocolFile.tszFileName, st_JsonArray[i]["tszFileName"].asCString());
196+
_tcscpy(pSt_DBFile->st_ProtocolFile.tszFilePath, st_JsonArray[i]["tszFilePath"].asCString());
197+
_tcscpy(pSt_DBFile->st_ProtocolFile.tszFileTime, st_JsonArray[i]["tszFileTime"].asCString());
198+
199+
break;
200+
}
201+
return TRUE;
57202
}

XEngine_Source/StorageModule_APIHelp/APIHelp_Distributed/APIHelp_Distributed.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class CAPIHelp_Distributed
2020
public:
2121
BOOL APIHelp_Distributed_IsMode(list<int>* pStl_ListMode, int nMode);
2222
BOOL APIHelp_Distributed_RandomAddr(list<tstring>* pStl_ListAddr, TCHAR* ptszAddr);
23+
BOOL APIHelp_Distributed_FileList(list<APIHELP_LBFILEINFO>* pStl_ListParse, XSTORAGECORE_DBFILE*** pppSt_ListPacket, int* pInt_ListCount);
2324
protected:
25+
BOOL APIHelp_Distributed_FileListParse(LPCTSTR lpszMsgBuffer, int nMsgLen, XSTORAGECORE_DBFILE* pSt_DBFile);
2426
private:
2527
};

XEngine_Source/StorageModule_APIHelp/APIHelp_Error.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@
99
// Author: qyt
1010
// Purpose: 导出错误
1111
// History:
12-
*********************************************************************/
12+
*********************************************************************/
13+
#define ERROR_STORAGE_MODULE_APIHELP_PARAMENT 0x0030001
14+
#define ERROR_STORAGE_MODULE_APIHELP_PARSE 0x0030002

XEngine_Source/StorageModule_APIHelp/StorageModule_APIHelp.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ EXPORTS
44
StorageHelp_GetLastError
55

66
APIHelp_Distributed_IsMode
7-
APIHelp_Distributed_RandomAddr
7+
APIHelp_Distributed_RandomAddr
8+
APIHelp_Distributed_FileList

XEngine_Source/StorageModule_APIHelp/pch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,8 @@ extern "C" BOOL APIHelp_Distributed_IsMode(list<int>*pStl_ListMode, int nMode)
3636
extern "C" BOOL APIHelp_Distributed_RandomAddr(list<tstring>*pStl_ListAddr, TCHAR * ptszAddr)
3737
{
3838
return m_APIDistributed.APIHelp_Distributed_RandomAddr(pStl_ListAddr, ptszAddr);
39+
}
40+
extern "C" BOOL APIHelp_Distributed_FileList(list<APIHELP_LBFILEINFO>*pStl_ListParse, XSTORAGECORE_DBFILE * **pppSt_ListPacket, int* pInt_ListCount)
41+
{
42+
return m_APIDistributed.APIHelp_Distributed_FileList(pStl_ListParse, pppSt_ListPacket, pInt_ListCount);
3943
}

XEngine_Source/StorageModule_APIHelp/pch.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,29 @@
1111
// 添加要在此处预编译的标头
1212
#include "framework.h"
1313
#include <tchar.h>
14+
#include <json/json.h>
15+
#else
16+
#ifdef _CENTOS
17+
#include <json/json.h>
18+
#else
19+
#include <jsoncpp/json/json.h>
20+
#endif
1421
#endif
15-
1622
#endif //PCH_H
1723
#include <string.h>
1824
#include <list>
1925
#include <string>
2026
using namespace std;
2127
#include <XEngine_Include/XEngine_CommHdr.h>
2228
#include <XEngine_Include/XEngine_Types.h>
29+
#include <XEngine_Include/XEngine_ProtocolHdr.h>
2330
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Define.h>
2431
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Error.h>
32+
#include <XEngine_Include/XEngine_HelpComponents/DataBase_Define.h>
33+
#include <XEngine_Include/XEngine_HelpComponents/DataBase_Error.h>
34+
#include "../XEngine_StorageComponents/XStorage_SQLPacket/SQLPacket_Define.h"
35+
#include "APIHelp_Define.h"
36+
#include "APIHelp_Error.h"
2537
/********************************************************************
2638
// Created: 2021/07/08 16:41:05
2739
// File Name: D:\XEngine_Storage\XEngine_Source\StorageModule_APIHelp\pch.h

XEngine_Source/StorageModule_Config/Config_Define.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ typedef struct tag_XEngine_ServerConfig
9090
struct
9191
{
9292
BOOL bBroad;
93+
int nTime;
9394
int nSDPort;
9495
int nRVPort;
9596
TCHAR tszQQWryFile[MAX_PATH];

XEngine_Source/StorageModule_Config/Config_Json/Config_Json.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,15 @@ BOOL CConfig_Json::Config_Json_File(LPCTSTR lpszConfigFile,XENGINE_SERVERCONFIG
165165
pSt_ServerConfig->st_XLimit.nMaxDNLoader = st_JsonXLimit["nMaxDNLoad"].asInt64();
166166
pSt_ServerConfig->st_XLimit.nMaxUPLoader = st_JsonXLimit["nMaxUPLoad"].asInt64();
167167

168-
if (st_JsonRoot["XP2xp"].empty() || (4 != st_JsonRoot["XP2xp"].size()))
168+
if (st_JsonRoot["XP2xp"].empty() || (5 != st_JsonRoot["XP2xp"].size()))
169169
{
170170
Config_IsErrorOccur = TRUE;
171171
Config_dwErrorCode = ERROR_XENGINE_BLOGIC_CONFIG_JSON_P2XP;
172172
return FALSE;
173173
}
174174
Json::Value st_JsonP2xp = st_JsonRoot["XP2xp"];
175175
pSt_ServerConfig->st_P2xp.bBroad = st_JsonP2xp["bBroad"].asInt();
176+
pSt_ServerConfig->st_P2xp.nTime = st_JsonP2xp["nTime"].asInt();
176177
pSt_ServerConfig->st_P2xp.nRVPort = st_JsonP2xp["nRVPort"].asInt();
177178
pSt_ServerConfig->st_P2xp.nSDPort = st_JsonP2xp["nSDPort"].asInt();
178179
_tcscpy(pSt_ServerConfig->st_P2xp.tszQQWryFile, st_JsonP2xp["tszQQWryFile"].asCString());

0 commit comments

Comments
 (0)