diff --git a/CHANGELOG b/CHANGELOG index e190b7c6bbc7a72709d17a00df656422ee27bb12..b137cf0491485da22cc39ffe6a13804574516d99 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,23 @@ +XEngine_Storage V3.12.0.1001 + +增加:为P2P启用内存数据库支持 +修改:为P2P功能单独启用配置选项 +修改:http验证回调发送数据字段被填充了 +修改:WINDOWS宏定义 +修正:重载配置的错误 +修正:数据库时间处理不正确 +删除:业务分布式功能被删除 +删除:没有使用的配置代码 + +added:memory database supported for p2p +modify:The configuration for enabling P2P is set up as a separate project. +modify:http authorize callback send len is useful +modify:windows macro define name +fixed:reload configure is incorrent +fixed:database thread time is incorrent +delete:center Distributed function,it is useless +delete:unuse configure field +====================================================================================== XEngine_Storage V3.11.1.1001 更新:匹配XEngine V8.15版本 diff --git a/LICENSE b/LICENSE index 65c5ca88a67c30becee01c5a8816d964b03862f9..b4ec123c7313a054e56de689760a16051ac745b7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,165 +1,21 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. +MIT License + +Copyright (c) 2023 XEngine:www.xyry.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.en.md b/README.en.md index 768dcaed84f763410529a1f2c580151b59294dab..f7e0fa3cb14080807d46b997ef73fd4b7623e729 100644 --- a/README.en.md +++ b/README.en.md @@ -9,7 +9,7 @@ c c++ file storage service This is an api gateway for uploading and downloading. The service is for users who have business needs for upload and download services (such as developers who need to upload and download servers). This server is more inclined to storestorage transfer and API Manage interface,the service can be used upload and download management and network file shared and software update service. -best storage service for http,batter than nginx and more convenient to manage,more concise code. On going maintenance +best storage service for http,more concise code. On going maintenance ## Software feature The purpose of development and implementation based on libXEngine is a cross-platform network storage service @@ -120,7 +120,9 @@ Port:HTTP Center Port 5100,Download 5101,UPLoad 5102 4. New Pull Request ## Follow us -If you think this software is helpful to you, please give us a START +If you think this software is helpful to you, please give us a START +and wechat qr scan to follow us +![qrcode](https://www.xyry.org/qrcode.jpg) ## post issues diff --git a/README.md b/README.md index cd0f8b48f2ebd54a16f2c5e8d38dd901b9a70aaf..ce1b3164ddaf39105bf1180b3616c799c1516009 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ c c++ file storage service 这是一个上传下载服务API网关,不是文件同步服务,也不是云存储. 这个服务的主要目的是为了给有上传下载服务业务需求的用户使用(比如需要开发上传下载服务的开发人员). 此服务器更偏向于存储传输与API接口管理,此服务可以用于上传下载的管理,网络文件共享或者软件更新服务. -目前最好的HTTP存储服务,比NGINX更优秀,更方便管理,代码更简洁.持续维护中... +目前最好的HTTP存储服务,更方便管理,代码更简洁.持续维护中... ## 软件特性 基于libXEngine开发并实现的一套简洁高性能跨平台网络存储服务 @@ -120,7 +120,10 @@ jsoncpp模块在使用的时候编译运行时库选择必须一致.否则会崩 4. 新建 Pull Request ## 关注我们 -如果你觉得这个软件对你有帮助,请你给我们一个START吧 + +如果你觉得这个软件对你有帮助,请你给我们一个START吧   +也可以通过微信关注我们   +![qrcode](https://www.xyry.org/qrcode.jpg) ## 提交问题 diff --git a/XEngine_APPClient/APPClient_Download/APPClient_Download.cpp b/XEngine_APPClient/APPClient_Download/APPClient_Download.cpp index dbbb47ee494ca14d87b0eac38580330137b66492..01c8e26d6260e6a7b5094634b648df7ac7330fe0 100644 --- a/XEngine_APPClient/APPClient_Download/APPClient_Download.cpp +++ b/XEngine_APPClient/APPClient_Download/APPClient_Download.cpp @@ -48,17 +48,15 @@ typedef struct void P2PParse_List(LPCXSTR lpszMsgBuffer, int nMsgLen, list* pStl_ListFile) { Json::Value st_JsonRoot; - Json::CharReaderBuilder st_JsonBuild; - Json::CharReader* pSt_JsonReader(st_JsonBuild.newCharReader()); - JSONCPP_STRING st_JsonError; + Json::CharReaderBuilder st_JsonBuilder; + + std::unique_ptr const pSt_JsonReader(st_JsonBuilder.newCharReader()); //解析JSON if (!pSt_JsonReader->parse(lpszMsgBuffer, lpszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError)) { return; } - delete pSt_JsonReader; - pSt_JsonReader = NULL; int nCount = st_JsonRoot["Count"].asInt(); Json::Value st_JsonArray = st_JsonRoot["List"]; @@ -174,7 +172,7 @@ int main() st_JsonRoot["nMode"] = 1; //使用P2P下载 st_JsonRoot["lpszBuckKey"] = "storagekey2"; //st_JsonRoot["lpszFileName"] = "qq.exe"; - st_JsonRoot["lpszFileHash"] = "781E5E245D69B566979B86E28D23F2C7"; + st_JsonRoot["lpszFileHash"] = "E50A10E2C9414F0397FF85393A6F68C9"; if (!APIClient_Http_Request(_X("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), &nHTTPCode, &ptszMsgBody, &nBodyLen)) { @@ -185,6 +183,10 @@ int main() list stl_ListFile; P2PParse_List(ptszMsgBody, nBodyLen, &stl_ListFile); + if (stl_ListFile.empty()) + { + return -1; + } //创建稀疏文件(一个空白的文件) if (!SystemApi_File_CreateSparseFile(lpszFile, stl_ListFile.front().st_ProtocolFile.nFileSize)) { diff --git a/XEngine_APPClient/VSCopy_x64.bat b/XEngine_APPClient/VSCopy_x64.bat index 9d38da458a2f805fb7ab776fa5ac9c6ba831eba7..3ca94406858caace7509c88931636f16410b18e6 100644 --- a/XEngine_APPClient/VSCopy_x64.bat +++ b/XEngine_APPClient/VSCopy_x64.bat @@ -6,6 +6,6 @@ copy /y "%XEngine_Lib64%\XEngine_NetHelp\NetHelp_APIClient.dll" "./" copy /y "%XEngine_Lib64%\XEngine_HelpComponents\zlib1.dll" "./" copy /y "%XEngine_Lib64%\XEngine_LibEx\libcrypto-3-x64.dll" "./" -copy /y "%XEngine_Lib64%\XEngine_LibEx\libssl-3.dll-x64" "./" -copy /y "%XEngine_Lib64%\XEngine_LibEx\libcurl.dll" "./" -copy /y "%XEngine_Lib64%\XEngine_LibEx\nghttp2.dll" "./" \ No newline at end of file +copy /y "%XEngine_Lib64%\XEngine_LibEx\libssl-3-x64.dll" "./" +copy /y "%XEngine_Lib64%\XEngine_NetHelp\libcurl.dll" "./" +copy /y "%XEngine_Lib64%\XEngine_NetHelp\nghttp2.dll" "./" \ No newline at end of file diff --git a/XEngine_APPClient/VSCopy_x86.bat b/XEngine_APPClient/VSCopy_x86.bat index ef18a425c62a7eb4d5198c04ed26f2ee8b895168..54a3c4fa1df4f5843c7c629f5a56d385846ee49a 100644 --- a/XEngine_APPClient/VSCopy_x86.bat +++ b/XEngine_APPClient/VSCopy_x86.bat @@ -7,5 +7,5 @@ copy /y "%XEngine_Lib32%\XEngine_NetHelp\NetHelp_APIClient.dll" "./" copy /y "%XEngine_Lib32%\XEngine_HelpComponents\zlib1.dll" "./" copy /y "%XEngine_Lib32%\XEngine_LibEx\libcrypto-3.dll" "./" copy /y "%XEngine_Lib32%\XEngine_LibEx\libssl-3.dll" "./" -copy /y "%XEngine_Lib32%\XEngine_LibEx\libcurl.dll" "./" -copy /y "%XEngine_Lib32%\XEngine_LibEx\nghttp2.dll" "./" \ No newline at end of file +copy /y "%XEngine_Lib32%\XEngine_NetHelp\libcurl.dll" "./" +copy /y "%XEngine_Lib32%\XEngine_NetHelp\nghttp2.dll" "./" \ No newline at end of file diff --git a/XEngine_Docment/Docment_en.docx b/XEngine_Docment/Docment_en.docx index 703d40c2d4df6f9510d83679606e06fabdca6191..607dafb0f4791e59ff79ed9184a78fb510b958a5 100644 Binary files a/XEngine_Docment/Docment_en.docx and b/XEngine_Docment/Docment_en.docx differ diff --git a/XEngine_Docment/Docment_zh.docx b/XEngine_Docment/Docment_zh.docx index 1c58545f12c75478a4620444e02aea4ccdf8d4b3..1374ba477e7e879fc869361ed8cb7ca48a7ac6dd 100644 Binary files a/XEngine_Docment/Docment_zh.docx and b/XEngine_Docment/Docment_zh.docx differ diff --git a/XEngine_Release/XEngine_Config/XEngine_Config.json b/XEngine_Release/XEngine_Config/XEngine_Config.json index a5ab64faa340426eb94a9af28a1fff52ca01267a..1823db68596d13b99d6c3412b6ad677342e3b449 100644 --- a/XEngine_Release/XEngine_Config/XEngine_Config.json +++ b/XEngine_Release/XEngine_Config/XEngine_Config.json @@ -1,5 +1,5 @@ { - "tszIPAddr":"192.168.1.8", + "tszIPAddr":"10.0.1.88", "bDeamon":0, "nCenterPort":5100, "nStorageDLPort":5101, @@ -39,7 +39,7 @@ "XAuth":{ "bUPAuth":false, "bDLAuth":false, - "bCHAuth":true, + "bCHAuth":false, "tszUserList":"./XEngine_Config/UserList.txt" }, "XProxy":{ @@ -58,6 +58,7 @@ "nMaxDNConnect":2 }, "XP2xp":{ + "bEnable":true, "nTime":2, "nRVPort":15000, "nSDPort":15001 @@ -71,6 +72,7 @@ "tszCertKey":"./XEngine_Cert/2_www.xyry.org.key" }, "XVer":[ + "3.12.0.1001 Build20231025", "3.11.1.1001 Build20230804", "3.11.0.1001 Build20230421", "3.10.0.1001 Build20230210", diff --git a/XEngine_Release/XEngine_Config/XEngine_LBConfig.json b/XEngine_Release/XEngine_Config/XEngine_LBConfig.json index 002a5633e7042874032a196fe732a3046254e1d5..991fc3a40ccd0a6d7986d3e54682473b5b9dbc88 100644 --- a/XEngine_Release/XEngine_Config/XEngine_LBConfig.json +++ b/XEngine_Release/XEngine_Config/XEngine_LBConfig.json @@ -1,21 +1,15 @@ { - "bDistributed":1, "LBDistributed":{ - "nCenterMode":0, "nUPLoadMode":0, "nDownldMode":0, "nStorageMode":0 }, "LBLocation":{ - "nCenterMode":0, "nUPLoadMode":1, "nDownldMode":0, "nStorageMode":0 }, "LoadBalance":{ - "CenterAddr":[ - "http://192.168.1.9:5100" - ], "DownloadAddr":[ "http://192.168.1.9:5010" ], diff --git a/XEngine_Source/StorageModule_APIHelp/pch.h b/XEngine_Source/StorageModule_APIHelp/pch.h index 13ab8a76594503ec432bea3c2c8f91ccfb0dba6b..46988c674b36f27c9c4bea03863acc3413247ee6 100644 --- a/XEngine_Source/StorageModule_APIHelp/pch.h +++ b/XEngine_Source/StorageModule_APIHelp/pch.h @@ -7,7 +7,7 @@ #ifndef PCH_H #define PCH_H -#ifdef _WINDOWS +#ifdef _MSC_BUILD // 添加要在此处预编译的标头 #include "framework.h" #include @@ -59,7 +59,7 @@ using namespace std; extern bool APIHelp_IsErrorOccur; extern XLONG APIHelp_dwErrorCode; -#ifdef _WINDOWS +#ifdef _MSC_BUILD #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib") #pragma comment(lib,"XEngine_Core/XEngine_OPenSsl") #pragma comment(lib,"XEngine_RfcComponents/RfcComponents_HttpProtocol") diff --git a/XEngine_Source/StorageModule_Config/Config_Define.h b/XEngine_Source/StorageModule_Config/Config_Define.h index 48250113b8fd5d138f8a9b238e776c2f221e0676..68cdcee88baedb46c338b60ef1883a29e29ad724 100644 --- a/XEngine_Source/StorageModule_Config/Config_Define.h +++ b/XEngine_Source/StorageModule_Config/Config_Define.h @@ -89,6 +89,7 @@ typedef struct tag_XEngine_ServerConfig }st_XLimit; struct { + bool bEnable; int nTime; int nSDPort; int nRVPort; @@ -124,24 +125,20 @@ typedef struct }XENGINE_STORAGEBUCKET; typedef struct { - bool bDistributed; struct { - int nCenterMode; int nUPLoadMode; int nDownldMode; int nStorageMode; }st_LBDistributed; struct { - int nCenterMode; int nUPLoadMode; int nDownldMode; int nStorageMode; }st_LBLocation; struct { - list* pStl_ListCenter; list* pStl_ListDownload; list* pStl_ListUPLoader; list* pStl_ListBucket; diff --git a/XEngine_Source/StorageModule_Config/Config_Json/Config_Json.cpp b/XEngine_Source/StorageModule_Config/Config_Json/Config_Json.cpp index b788020ed3e84fc3bf544b24aac3234d030102bb..6d68867b4ce373ccd57f207a7c501e552089a49c 100644 --- a/XEngine_Source/StorageModule_Config/Config_Json/Config_Json.cpp +++ b/XEngine_Source/StorageModule_Config/Config_Json/Config_Json.cpp @@ -189,13 +189,15 @@ bool CConfig_Json::Config_Json_File(LPCXSTR lpszConfigFile, XENGINE_SERVERCONFIG pSt_ServerConfig->st_XLimit.nMaxUPConnect = st_JsonXLimit["nMaxUPConnect"].asInt(); pSt_ServerConfig->st_XLimit.nMaxDNConnect = st_JsonXLimit["nMaxDNConnect"].asInt(); - if (st_JsonRoot["XP2xp"].empty() || (3 != st_JsonRoot["XP2xp"].size())) + if (st_JsonRoot["XP2xp"].empty() || (4 != st_JsonRoot["XP2xp"].size())) { Config_IsErrorOccur = true; Config_dwErrorCode = ERROR_XENGINE_BLOGIC_CONFIG_JSON_P2XP; return false; } Json::Value st_JsonP2xp = st_JsonRoot["XP2xp"]; + + pSt_ServerConfig->st_P2xp.bEnable = st_JsonP2xp["bEnable"].asBool(); pSt_ServerConfig->st_P2xp.nTime = st_JsonP2xp["nTime"].asInt(); pSt_ServerConfig->st_P2xp.nSDPort = st_JsonP2xp["nSDPort"].asInt(); pSt_ServerConfig->st_P2xp.nRVPort = st_JsonP2xp["nRVPort"].asInt(); @@ -294,33 +296,30 @@ bool CConfig_Json::Config_Json_LoadBalance(LPCXSTR lpszConfigFile, XENGINE_LBCON Config_dwErrorCode = ERROR_XENGINE_BLOGIC_CONFIG_JSON_PARSE; return false; } - pSt_ServerConfig->bDistributed = st_JsonRoot["bDistributed"].asInt(); - if (st_JsonRoot["LBDistributed"].empty() || (4 != st_JsonRoot["LBDistributed"].size())) + if (st_JsonRoot["LBDistributed"].empty() || (3 != st_JsonRoot["LBDistributed"].size())) { Config_IsErrorOccur = true; Config_dwErrorCode = ERROR_XENGINE_BLOGIC_CONFIG_JSON_LBDISTRIBUTED; return false; } Json::Value st_JsonLBDistributed = st_JsonRoot["LBDistributed"]; - pSt_ServerConfig->st_LBDistributed.nCenterMode = st_JsonLBDistributed["nCenterMode"].asInt(); pSt_ServerConfig->st_LBDistributed.nUPLoadMode = st_JsonLBDistributed["nUPLoadMode"].asInt(); pSt_ServerConfig->st_LBDistributed.nDownldMode = st_JsonLBDistributed["nDownldMode"].asInt(); pSt_ServerConfig->st_LBDistributed.nStorageMode = st_JsonLBDistributed["nStorageMode"].asInt(); - if (st_JsonRoot["LBLocation"].empty() || (4 != st_JsonRoot["LBLocation"].size())) + if (st_JsonRoot["LBLocation"].empty() || (3 != st_JsonRoot["LBLocation"].size())) { Config_IsErrorOccur = true; Config_dwErrorCode = ERROR_XENGINE_BLOGIC_CONFIG_JSON_LBLOCATION; return false; } Json::Value st_JsonLBLocation = st_JsonRoot["LBLocation"]; - pSt_ServerConfig->st_LBLocation.nCenterMode = st_JsonLBLocation["nCenterMode"].asInt(); pSt_ServerConfig->st_LBLocation.nUPLoadMode = st_JsonLBLocation["nUPLoadMode"].asInt(); pSt_ServerConfig->st_LBLocation.nDownldMode = st_JsonLBLocation["nDownldMode"].asInt(); pSt_ServerConfig->st_LBLocation.nStorageMode = st_JsonLBLocation["nStorageMode"].asInt(); - if (st_JsonRoot["LoadBalance"].empty() || (4 != st_JsonRoot["LoadBalance"].size())) + if (st_JsonRoot["LoadBalance"].empty() || (3 != st_JsonRoot["LoadBalance"].size())) { Config_IsErrorOccur = true; Config_dwErrorCode = ERROR_XENGINE_BLOGIC_CONFIG_JSON_LAODBALANCE; @@ -328,12 +327,6 @@ bool CConfig_Json::Config_Json_LoadBalance(LPCXSTR lpszConfigFile, XENGINE_LBCON } Json::Value st_JsonLoadBalance = st_JsonRoot["LoadBalance"]; - pSt_ServerConfig->st_LoadBalance.pStl_ListCenter = new list; - for (unsigned int i = 0; i < st_JsonLoadBalance["CenterAddr"].size(); i++) - { - pSt_ServerConfig->st_LoadBalance.pStl_ListCenter->push_back(st_JsonLoadBalance["CenterAddr"][i].asCString()); - } - pSt_ServerConfig->st_LoadBalance.pStl_ListDownload = new list; for (unsigned int i = 0; i < st_JsonLoadBalance["DownloadAddr"].size(); i++) { diff --git a/XEngine_Source/StorageModule_Config/pch.h b/XEngine_Source/StorageModule_Config/pch.h index 2305a5746651e0d30b40ab70af085fc9d057b1ef..07650691d9563f0ec8a0bae553550fbfdab0b625 100644 --- a/XEngine_Source/StorageModule_Config/pch.h +++ b/XEngine_Source/StorageModule_Config/pch.h @@ -7,7 +7,7 @@ #ifndef PCH_H #define PCH_H -#ifdef _WINDOWS +#ifdef _MSC_BUILD // 添加要在此处预编译的标头 #include "framework.h" #include @@ -40,7 +40,7 @@ using namespace std; extern bool Config_IsErrorOccur; extern XLONG Config_dwErrorCode; -#ifdef _WINDOWS +#ifdef _MSC_BUILD #ifdef _DEBUG #ifdef _WIN64 #pragma comment(lib,"../x64/Debug/jsoncpp") diff --git a/XEngine_Source/StorageModule_Database/Database_Define.h b/XEngine_Source/StorageModule_Database/Database_Define.h index 27e14a5d8fc3d31f889cf28efc186b91593c2be7..54d3276fb73798d6b5bbcf722f55226b85d2c93f 100644 --- a/XEngine_Source/StorageModule_Database/Database_Define.h +++ b/XEngine_Source/StorageModule_Database/Database_Define.h @@ -278,4 +278,107 @@ extern "C" bool Database_File_FileDelete(LPCXSTR lpszBuckKey = NULL, LPCXSTR lps 意思:是否成功 备注:返回假可能没有查找到,这条记录不存在.参数lpszFile和lpszMD5不能全为空 *********************************************************************/ -extern "C" bool Database_File_FileQuery(XSTORAGECORE_DBFILE * **pppSt_ListFile, int* pInt_ListCount, LPCXSTR lpszTimeStart = NULL, LPCXSTR lpszTimeEnd = NULL, LPCXSTR lpszBuckKey = NULL, LPCXSTR lpszFilePath = NULL, LPCXSTR lpszFileName = NULL, LPCXSTR lpszHash = NULL, LPCXSTR lpszTableName = NULL); \ No newline at end of file +extern "C" bool Database_File_FileQuery(XSTORAGECORE_DBFILE * **pppSt_ListFile, int* pInt_ListCount, LPCXSTR lpszTimeStart = NULL, LPCXSTR lpszTimeEnd = NULL, LPCXSTR lpszBuckKey = NULL, LPCXSTR lpszFilePath = NULL, LPCXSTR lpszFileName = NULL, LPCXSTR lpszHash = NULL, LPCXSTR lpszTableName = NULL); +/************************************************************************/ +/* 导出的内存数据库函数 */ +/************************************************************************/ +/******************************************************************** +函数名称:Database_Memory_Init +函数功能:初始化存储服务数据库管理器 + 参数.一:pStl_ListBucket + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:BUCKET列表 + 参数.二:nHashMode + In/Out:In + 类型:整数型 + 可空:N + 意思:文件HASH方法 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_Memory_Init(list* pStl_ListBucket, int nHashMode); +/******************************************************************** +函数名称:Database_Memory_Destory +函数功能:销毁数据库管理器 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_Memory_Destory(); +/******************************************************************** +函数名称:Database_Memory_FileInsert +函数功能:插入一个文件数据到数据库中 + 参数.一:pSt_DBManage + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:要插入的数据信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注:这个结构所有值都必须填充 +*********************************************************************/ +extern "C" bool Database_Memory_FileInsert(XSTORAGECORE_DBFILE* pSt_DBManage); +/******************************************************************** +函数名称:Database_Memory_FileDelete +函数功能:删除一个数据库文件信息 + 参数.一:lpszFilePath + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:要删除的文件路径 + 参数.二:lpszFileName + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:要删除的文件名称 + 参数.三:lpszHash + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:要删除的文件HASH +返回值 + 类型:逻辑型 + 意思:是否成功 +备注:参数不能全为空,不会删除文件 +*********************************************************************/ +extern "C" bool Database_Memory_FileDelete(LPCXSTR lpszFilePath = NULL, LPCXSTR lpszFileName = NULL, LPCXSTR lpszHash = NULL); +/******************************************************************** +函数名称:Database_Memory_FileQuery +函数功能:查询文件信息 + 参数.一:pppSt_ListFile + In/Out:Out + 类型:三级指针 + 可空:N + 意思:导出查询到的文件列表,此函数需要调用基础库的内存释放函数 + 参数.二:pInt_ListCount + In/Out:Out + 类型:三级指针 + 可空:N + 意思:导出文件个数 + 参数.三:lpszBucketName + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:要查询的BUCKET名称 + 参数.四:lpszFileName + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:要查询的名称 + 参数.五:lpszHash + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:要查询的文件HASH +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_Memory_FileQuery(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCXSTR lpszBucketName, LPCXSTR lpszFileName, LPCXSTR lpszHash); \ No newline at end of file diff --git a/XEngine_Source/StorageModule_Database/Database_File/Database_File.cpp b/XEngine_Source/StorageModule_Database/Database_File/Database_File.cpp index 326f6be291a59b7829906bbe13ee2f8450501aa2..11a05d4ed08ee3c727940f91d3255660c911aed4 100644 --- a/XEngine_Source/StorageModule_Database/Database_File/Database_File.cpp +++ b/XEngine_Source/StorageModule_Database/Database_File/Database_File.cpp @@ -634,13 +634,14 @@ XHTHREAD CDatabase_File::Database_File_Thread(XPVOID lParam) while (pClass_This->bIsRun) { + nTimeEnd = time(NULL); if ((nTimeEnd - nTimeStart) > nTime) { + nTimeStart = nTimeEnd; pClass_This->Database_File_TimeDel(); pClass_This->Database_File_CreateTable(); } - nTimeEnd = time(NULL); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); } return 0; } \ No newline at end of file diff --git a/XEngine_Source/StorageModule_Database/Database_Memory/Database_Memory.cpp b/XEngine_Source/StorageModule_Database/Database_Memory/Database_Memory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9de409921bf209b9fea71bfda2ccf4b295c6ebd7 --- /dev/null +++ b/XEngine_Source/StorageModule_Database/Database_Memory/Database_Memory.cpp @@ -0,0 +1,343 @@ +#include "pch.h" +#include "Database_Memory.h" +/******************************************************************** +// Created: 2023/10/20 10:12:03 +// File Name: D:\XEngine_Storage\XEngine_Source\StorageModule_Database\Database_Memory\Database_Memory.cpp +// File Path: D:\XEngine_Storage\XEngine_Source\StorageModule_Database\Database_Memory +// File Base: Database_Memory +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 内存数据库管理器 +// History: +*********************************************************************/ +CDatabase_Memory::CDatabase_Memory() +{ +} +CDatabase_Memory::~CDatabase_Memory() +{ +} +////////////////////////////////////////////////////////////////////////// +// 公有函数 +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +函数名称:Database_Memory_Init +函数功能:初始化存储服务数据库管理器 + 参数.一:pStl_ListBucket + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:BUCKET列表 + 参数.二:nHashMode + In/Out:In + 类型:整数型 + 可空:N + 意思:文件HASH方法 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CDatabase_Memory::Database_Memory_Init(list* pStl_ListBucket, int nHashMode) +{ + Database_IsErrorOccur = false; + + m_bIsRun = true; + st_Locker = make_unique(); + pSTDThread = make_unique(Database_Memory_Thread, this); + if (!pSTDThread->joinable()) + { + Database_IsErrorOccur = true; + Database_dwErrorCode = ERROR_XENGINE_XSTROGE_CORE_DB_INIT_THREAD; + return false; + } + m_nHashMode = nHashMode; + stl_ListBucket = *pStl_ListBucket; + return true; +} +/******************************************************************** +函数名称:Database_Memory_Destory +函数功能:销毁数据库管理器 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CDatabase_Memory::Database_Memory_Destory() +{ + Database_IsErrorOccur = false; + + if (!m_bIsRun) + { + return true; + } + m_bIsRun = false; + + if (NULL != pSTDThread) + { + if (pSTDThread->joinable()) + { + pSTDThread->join(); + } + } + stl_ListBucket.clear(); + return true; +} +/******************************************************************** +函数名称:Database_Memory_FileInsert +函数功能:插入一个文件数据到数据库中 + 参数.一:pSt_DBManage + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:要插入的数据信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注:这个结构所有值都必须填充 +*********************************************************************/ +bool CDatabase_Memory::Database_Memory_FileInsert(XSTORAGECORE_DBFILE *pSt_DBManage) +{ + Database_IsErrorOccur = false; + + if (NULL == pSt_DBManage) + { + Database_IsErrorOccur = true; + Database_dwErrorCode = ERROR_XENGINE_XSTROGE_CORE_DB_INSERTFILE_PARAMENT; + return false; + } + + st_Locker->lock(); + stl_ListFile.push_back(*pSt_DBManage); + st_Locker->unlock(); + return true; +} +/******************************************************************** +函数名称:Database_Memory_FileDelete +函数功能:删除一个数据库文件信息 + 参数.一:lpszFilePath + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:要删除的文件路径 + 参数.二:lpszFileName + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:要删除的文件名称 + 参数.三:lpszHash + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:要删除的文件HASH +返回值 + 类型:逻辑型 + 意思:是否成功 +备注:参数不能全为空,不会删除文件 +*********************************************************************/ +bool CDatabase_Memory::Database_Memory_FileDelete(LPCXSTR lpszFilePath /* = NULL */, LPCXSTR lpszFileName /* = NULL */, LPCXSTR lpszHash /* = NULL */) +{ + Database_IsErrorOccur = false; + + if ((NULL == lpszFileName) && (NULL == lpszHash)) + { + Database_IsErrorOccur = true; + Database_dwErrorCode = ERROR_XENGINE_XSTROGE_CORE_DB_DELETEFILE_PARAMENT; + return false; + } + st_Locker->lock(); + auto stl_ListIterator = stl_ListFile.begin(); + for (; stl_ListIterator != stl_ListFile.end(); stl_ListIterator++) + { + if (NULL != lpszHash) + { + if (0 == _tcsxnicmp(lpszHash, stl_ListIterator->st_ProtocolFile.tszFileHash, _tcsxlen(lpszHash))) + { + stl_ListFile.erase(stl_ListIterator); + break; + } + } + else if (NULL != lpszFileName) + { + if (0 == _tcsxnicmp(lpszFilePath, stl_ListIterator->st_ProtocolFile.tszFilePath, _tcsxlen(lpszFilePath)) && 0 == _tcsxnicmp(lpszFileName, stl_ListIterator->st_ProtocolFile.tszFileName, _tcsxlen(lpszFileName))) + { + stl_ListFile.erase(stl_ListIterator); + break; + } + } + } + st_Locker->unlock(); + return true; +} +/******************************************************************** +函数名称:Database_Memory_FileQuery +函数功能:查询文件信息 + 参数.一:pppSt_ListFile + In/Out:Out + 类型:三级指针 + 可空:N + 意思:导出查询到的文件列表,此函数需要调用基础库的内存释放函数 + 参数.二:pInt_ListCount + In/Out:Out + 类型:三级指针 + 可空:N + 意思:导出文件个数 + 参数.三:lpszBucketName + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:要查询的BUCKET名称 + 参数.四:lpszFileName + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:要查询的名称 + 参数.五:lpszHash + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:要查询的文件HASH +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CDatabase_Memory::Database_Memory_FileQuery(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCXSTR lpszBucketName, LPCXSTR lpszFileName, LPCXSTR lpszHash) +{ + Database_IsErrorOccur = false; + + bool bFound = false; + st_Locker->lock_shared(); + auto stl_ListIterator = stl_ListFile.begin(); + for (; stl_ListIterator != stl_ListFile.end(); stl_ListIterator++) + { + if (_tcsxlen(lpszHash) > 0) + { + if (0 == _tcsxnicmp(lpszHash, stl_ListIterator->st_ProtocolFile.tszFileHash, _tcsxlen(lpszHash))) + { + if (_tcsxlen(lpszBucketName) > 0) + { + if (0 == _tcsxnicmp(lpszBucketName, stl_ListIterator->tszBuckKey, _tcsxlen(lpszBucketName))) + { + bFound = true; + break; + } + } + else + { + bFound = true; + break; + } + } + } + else if (_tcsxlen(lpszFileName) > 0) + { + if (0 == _tcsxnicmp(lpszFileName, stl_ListIterator->st_ProtocolFile.tszFileName, _tcsxlen(lpszFileName))) + { + if (_tcsxlen(lpszBucketName) > 0) + { + if (0 == _tcsxnicmp(lpszBucketName, stl_ListIterator->tszBuckKey, _tcsxlen(lpszBucketName))) + { + bFound = true; + break; + } + } + else + { + bFound = true; + break; + } + } + } + } + st_Locker->unlock_shared(); + + if (bFound) + { + *pInt_ListCount = 1; + BaseLib_OperatorMemory_Malloc((XPPPMEM)pppSt_ListFile, 1, sizeof(XSTORAGECORE_DBFILE)); + + *(*pppSt_ListFile)[0] = *stl_ListIterator; + } + return true; +} +////////////////////////////////////////////////////////////////////////// +// 保护函数 +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +函数名称:Database_Memory_TimeDel +函数功能:删除过期日期表数据 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CDatabase_Memory::Database_Memory_Flush() +{ + Database_IsErrorOccur = false; + + st_Locker->lock(); + stl_ListFile.clear(); //fixme:improved find + for (auto stl_ListIterator = stl_ListBucket.begin(); stl_ListIterator != stl_ListBucket.end(); stl_ListIterator++) + { + int nListCount = 0; + XCHAR** pptszListFile; + XCHAR tszFoundDir[MAX_PATH]; + + memset(tszFoundDir, '\0', MAX_PATH); + _tcsxcpy(tszFoundDir, stl_ListIterator->tszFilePath); + _tcsxcat(tszFoundDir, _X("/*")); + + SystemApi_File_EnumFile(tszFoundDir, &pptszListFile, &nListCount, NULL, NULL, true, 1); + for (int i = 0; i < nListCount; i++) + { + int nHashLen = 0; + struct _xtstat st_FileStatus; + + XBYTE tszHashStr[MAX_PATH]; + XSTORAGECORE_DBFILE st_DBFile; + + memset(tszHashStr, '\0', MAX_PATH); + memset(&st_DBFile, '\0', sizeof(XSTORAGECORE_DBFILE)); + + _xtstat(pptszListFile[i], &st_FileStatus); + if (st_FileStatus.st_size > 0) + { + st_DBFile.st_ProtocolFile.nFileSize = st_FileStatus.st_size; + OPenSsl_Api_Digest(pptszListFile[i], tszHashStr, &nHashLen, true, m_nHashMode); + BaseLib_OperatorString_StrToHex((char*)tszHashStr, nHashLen, st_DBFile.st_ProtocolFile.tszFileHash); + BaseLib_OperatorString_GetFileAndPath(pptszListFile[i], st_DBFile.st_ProtocolFile.tszFilePath, st_DBFile.st_ProtocolFile.tszFileName); + _tcsxcpy(st_DBFile.tszBuckKey, stl_ListIterator->tszBuckKey); + + stl_ListFile.push_back(st_DBFile); + } + } + BaseLib_OperatorMemory_Free((XPPPMEM)&pptszListFile, nListCount); + } + st_Locker->unlock(); + return true; +} +////////////////////////////////////////////////////////////////////////// +// 线程函数 +////////////////////////////////////////////////////////////////////////// +XHTHREAD CDatabase_Memory::Database_Memory_Thread(XPVOID lParam) +{ + CDatabase_Memory *pClass_This = (CDatabase_Memory *)lParam; + time_t nTimeStart = time(NULL); + time_t nTimeEnd = 0; + int nTime = 60 * 60; + + pClass_This->Database_Memory_Flush();//优先刷新 + + while (pClass_This->m_bIsRun) + { + nTimeEnd = time(NULL); + if ((nTimeEnd - nTimeStart) > nTime) + { + nTimeStart = nTimeEnd; + pClass_This->Database_Memory_Flush(); + } + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + return 0; +} \ No newline at end of file diff --git a/XEngine_Source/StorageModule_Database/Database_Memory/Database_Memory.h b/XEngine_Source/StorageModule_Database/Database_Memory/Database_Memory.h new file mode 100644 index 0000000000000000000000000000000000000000..c0363d2594ee4b9497855d53adbce06d96059e29 --- /dev/null +++ b/XEngine_Source/StorageModule_Database/Database_Memory/Database_Memory.h @@ -0,0 +1,38 @@ +#pragma once +/******************************************************************** +// Created: 2023/10/20 09:58:29 +// File Name: D:\XEngine_Storage\XEngine_Source\StorageModule_Database\Database_Memory\Database_Memory.h +// File Path: D:\XEngine_Storage\XEngine_Source\StorageModule_Database\Database_Memory +// File Base: Database_Memory +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 内存数据库管理器 +// History: +*********************************************************************/ + +class CDatabase_Memory +{ +public: + CDatabase_Memory(); + ~CDatabase_Memory(); +public: + bool Database_Memory_Init(list* pStl_ListBucket, int nHashMode); + bool Database_Memory_Destory(); + bool Database_Memory_FileInsert(XSTORAGECORE_DBFILE *pSt_DBManage); + bool Database_Memory_FileDelete(LPCXSTR lpszFilePath = NULL, LPCXSTR lpszFileName = NULL, LPCXSTR lpszHash = NULL); + bool Database_Memory_FileQuery(XSTORAGECORE_DBFILE*** pppSt_ListFile, int* pInt_ListCount, LPCXSTR lpszBucketName, LPCXSTR lpszFileName, LPCXSTR lpszHash); +protected: + bool Database_Memory_Flush(); +protected: + static XHTHREAD Database_Memory_Thread(XPVOID lParam); +private: + bool m_bIsRun = false; + int m_nHashMode = 0; +private: + unique_ptr st_Locker; + unique_ptr pSTDThread; +private: + list stl_ListFile; + list stl_ListBucket; +}; diff --git a/XEngine_Source/StorageModule_Database/Makefile b/XEngine_Source/StorageModule_Database/Makefile index dc651e8b94aebab0d58a665d29dd666879c4be1f..6ad1d1a1c8f6f10c8e881ed412624ac6e132506a 100644 --- a/XEngine_Source/StorageModule_Database/Makefile +++ b/XEngine_Source/StorageModule_Database/Makefile @@ -10,7 +10,7 @@ LOADHDR = -I ./ -I ../XEngine_ThirdPart/jsoncpp LOADSO = -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_HelpComponents LIB = -lXEngine_BaseLib -lHelpComponents_DataBase LIBEX = -OBJECTS = Database_File.o Database_Help.o pch.o +OBJECTS = Database_File.o Database_Memory.o Database_Help.o pch.o ifeq ($(RELEASE),1) FLAGS = -c @@ -53,6 +53,8 @@ all:$(OBJECTS) Database_File.o:./Database_File/Database_File.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./Database_File/Database_File.cpp +Database_Memory.o:./Database_Memory/Database_Memory.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./Database_Memory/Database_Memory.cpp Database_Help.o:./Database_Help/Database_Help.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./Database_Help/Database_Help.cpp diff --git a/XEngine_Source/StorageModule_Database/StorageModule_Database.def b/XEngine_Source/StorageModule_Database/StorageModule_Database.def index 98f47709639b8ce2a0d702d3cc3e688bdbc1ded0..110424da43c6ce84ca06ca5e3c38d1bd22fb37b5 100644 --- a/XEngine_Source/StorageModule_Database/StorageModule_Database.def +++ b/XEngine_Source/StorageModule_Database/StorageModule_Database.def @@ -11,4 +11,10 @@ EXPORTS Database_File_Destory Database_File_FileInsert Database_File_FileDelete - Database_File_FileQuery \ No newline at end of file + Database_File_FileQuery + + Database_Memory_Init + Database_Memory_Destory + Database_Memory_FileInsert + Database_Memory_FileDelete + Database_Memory_FileQuery \ No newline at end of file diff --git a/XEngine_Source/StorageModule_Database/StorageModule_Database.vcxproj b/XEngine_Source/StorageModule_Database/StorageModule_Database.vcxproj index 6623b10dfd2cddb5aec73757673f18164fbbe74c..698ec5020d388d2ff31ca5817b0643b993dbc7f5 100644 --- a/XEngine_Source/StorageModule_Database/StorageModule_Database.vcxproj +++ b/XEngine_Source/StorageModule_Database/StorageModule_Database.vcxproj @@ -167,12 +167,14 @@ + + Create diff --git a/XEngine_Source/StorageModule_Database/StorageModule_Database.vcxproj.filters b/XEngine_Source/StorageModule_Database/StorageModule_Database.vcxproj.filters index 2d16b75a964744a932a28d20681d69d8c727b1dc..fbf07df3c1f7d8383236a3e7a6191fe09be2b768 100644 --- a/XEngine_Source/StorageModule_Database/StorageModule_Database.vcxproj.filters +++ b/XEngine_Source/StorageModule_Database/StorageModule_Database.vcxproj.filters @@ -25,6 +25,12 @@ {ebe3a727-0fc0-47ee-bcfe-c5de217ca9a9} + + {73acae46-9b4e-49e4-8d3a-b82e4fdb28b1} + + + {cc364565-bd16-4d4a-97ce-205b348d3145} + @@ -45,6 +51,9 @@ 头文件\Database_Help + + 头文件\Database_Memory + @@ -59,6 +68,9 @@ 源文件\Database_Help + + 源文件\Database_Memory + diff --git a/XEngine_Source/StorageModule_Database/pch.cpp b/XEngine_Source/StorageModule_Database/pch.cpp index 2d97e0a3a56209e084f71698c0f4eb0c0e416d2e..1a6b3c9f336da2e026efae938c15749330f68d6d 100644 --- a/XEngine_Source/StorageModule_Database/pch.cpp +++ b/XEngine_Source/StorageModule_Database/pch.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "Database_Help/Database_Help.h" #include "Database_File/Database_File.h" +#include "Database_Memory/Database_Memory.h" /******************************************************************** // Created: 2022/03/29 14:22:29 // File Name: D:\XEngine_Storage\XEngine_Source\StorageModule_Database\pch.cpp @@ -17,6 +18,7 @@ XLONG Database_dwErrorCode = 0; ////////////////////////////////////////////////////////////////////////// CDatabase_Help m_SQLHelp; CDatabase_File m_SQLFile; +CDatabase_Memory m_SQLMemory; ////////////////////////////////////////////////////////////////////////// /// 导出的函数 ////////////////////////////////////////////////////////////////////////// @@ -65,4 +67,27 @@ extern "C" bool Database_File_FileDelete(LPCXSTR lpszBuckKey, LPCXSTR lpszFilePa extern "C" bool Database_File_FileQuery(XSTORAGECORE_DBFILE * **pppSt_ListFile, int* pInt_ListCount, LPCXSTR lpszTimeStart, LPCXSTR lpszTimeEnd, LPCXSTR lpszBuckKey, LPCXSTR lpszFilePath, LPCXSTR lpszFileName, LPCXSTR lpszHash, LPCXSTR lpszTableName) { return m_SQLFile.Database_File_FileQuery(pppSt_ListFile, pInt_ListCount, lpszTimeStart, lpszTimeEnd, lpszBuckKey, lpszFilePath, lpszFileName, lpszHash, lpszTableName); +} +/************************************************************************/ +/* 导出的内存数据库函数 */ +/************************************************************************/ +extern "C" bool Database_Memory_Init(list*pStl_ListBucket, int nHashMode) +{ + return m_SQLMemory.Database_Memory_Init(pStl_ListBucket, nHashMode); +} +extern "C" bool Database_Memory_Destory() +{ + return m_SQLMemory.Database_Memory_Destory(); +} +extern "C" bool Database_Memory_FileInsert(XSTORAGECORE_DBFILE * pSt_DBManage) +{ + return m_SQLMemory.Database_Memory_FileInsert(pSt_DBManage); +} +extern "C" bool Database_Memory_FileDelete(LPCXSTR lpszFilePath, LPCXSTR lpszFileName, LPCXSTR lpszHash) +{ + return m_SQLMemory.Database_Memory_FileDelete(lpszFilePath, lpszFileName, lpszHash); +} +extern "C" bool Database_Memory_FileQuery(XSTORAGECORE_DBFILE * **pppSt_ListFile, int* pInt_ListCount, LPCXSTR lpszBucketName, LPCXSTR lpszFileName, LPCXSTR lpszHash) +{ + return m_SQLMemory.Database_Memory_FileQuery(pppSt_ListFile, pInt_ListCount, lpszBucketName, lpszFileName, lpszHash); } \ No newline at end of file diff --git a/XEngine_Source/StorageModule_Database/pch.h b/XEngine_Source/StorageModule_Database/pch.h index ebc1754da2d8ab87e37c6dc7976567d25f12b653..f5a05ef441d9106bd31eb458f6c5e36012bf24de 100644 --- a/XEngine_Source/StorageModule_Database/pch.h +++ b/XEngine_Source/StorageModule_Database/pch.h @@ -7,7 +7,7 @@ #ifndef PCH_H #define PCH_H -#ifdef _WINDOWS +#ifdef _MSC_BUILD // 添加要在此处预编译的标头 #include "framework.h" #include @@ -16,13 +16,16 @@ #include #include #else +#include +#include +#include +#include +#endif +#endif //PCH_H #include #include #include #include -#include -#endif -#endif //PCH_H #include #include #include @@ -36,9 +39,16 @@ using namespace std; #include #include #include +#include +#include #include #include +#include +#include +#include #include "../XStorage_Protocol.h" +#include "../StorageModule_Config/Config_Define.h" +#include "../StorageModule_Config/Config_Error.h" #include "Database_Define.h" #include "Database_Error.h" /******************************************************************** @@ -55,7 +65,9 @@ using namespace std; extern bool Database_IsErrorOccur; extern XLONG Database_dwErrorCode; -#ifdef _WINDOWS +#ifdef _MSC_BUILD #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") +#pragma comment(lib,"XEngine_Core/XEngine_OPenSsl.lib") #pragma comment(lib,"XEngine_HelpComponents/HelpComponents_DataBase.lib") +#pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi.lib") #endif diff --git a/XEngine_Source/StorageModule_Protocol/pch.h b/XEngine_Source/StorageModule_Protocol/pch.h index 4f07d69f07127cb651825fd505ed9ba8af864f1b..28312389ff9f5ed00f925cb5d84c5c49dd95ed61 100644 --- a/XEngine_Source/StorageModule_Protocol/pch.h +++ b/XEngine_Source/StorageModule_Protocol/pch.h @@ -7,7 +7,7 @@ #ifndef PCH_H #define PCH_H -#ifdef _WINDOWS +#ifdef _MSC_BUILD // 添加要在此处预编译的标头 #include "framework.h" #include @@ -36,6 +36,8 @@ using namespace std; #include #include #include "../XStorage_Protocol.h" +#include "../StorageModule_Config/Config_Define.h" +#include "../StorageModule_Config/Config_Error.h" #include "../StorageModule_Session/Session_Define.h" #include "../StorageModule_Database/Database_Define.h" #include "StorageProtocol_Define.h" @@ -54,7 +56,7 @@ using namespace std; extern bool Protocol_IsErrorOccur; extern XLONG Protocol_dwErrorCode; -#ifdef _WINDOWS +#ifdef _MSC_BUILD #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") #ifdef _DEBUG #ifdef _WIN64 diff --git a/XEngine_Source/StorageModule_Session/pch.h b/XEngine_Source/StorageModule_Session/pch.h index 11a2aec640d73892618f878f7b873021b64eb69a..2b1f5b33d22c113a3377effd7989f8b26191eb99 100644 --- a/XEngine_Source/StorageModule_Session/pch.h +++ b/XEngine_Source/StorageModule_Session/pch.h @@ -7,7 +7,7 @@ #ifndef PCH_H #define PCH_H -#ifdef _WINDOWS +#ifdef _MSC_BUILD // 添加要在此处预编译的标头 #include "framework.h" #include @@ -49,6 +49,6 @@ using namespace std; extern bool Session_IsErrorOccur; extern XLONG Session_dwErrorCode; -#ifdef _WINDOWS +#ifdef _MSC_BUILD #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") #endif \ No newline at end of file diff --git a/XEngine_Source/XEngine_StorageApp/StorageApp_Center.cpp b/XEngine_Source/XEngine_StorageApp/StorageApp_Center.cpp index 6fa42982ee4e578cc37215708586810c430db63b..8d088f0bcaa6e3e9f61ea72caf30e51aea9f2544 100644 --- a/XEngine_Source/XEngine_StorageApp/StorageApp_Center.cpp +++ b/XEngine_Source/XEngine_StorageApp/StorageApp_Center.cpp @@ -78,12 +78,11 @@ bool XEngine_Task_HttpCenter(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int } if (st_ServiceCfg.st_XProxy.bAuthPass) { - int nBLen = 0; int nResponseCode = 0; XCHAR* ptszBody = NULL; Protocol_StoragePacket_BasicAuth(pSt_HTTPParam->tszHttpMethod, pSt_HTTPParam->tszHttpUri, lpszClientAddr, tszUserName, tszUserPass, tszSDBuffer, &nSDLen); - APIClient_Http_Request(_X("POST"), st_ServiceCfg.st_XProxy.tszAuthPass, tszSDBuffer, &nResponseCode, &ptszBody, &nBLen); + APIClient_Http_Request(_X("POST"), st_ServiceCfg.st_XProxy.tszAuthPass, tszSDBuffer, &nResponseCode, &ptszBody, &nSDLen); if (200 != nResponseCode) { st_HDRParam.bIsClose = true; @@ -117,27 +116,6 @@ bool XEngine_Task_HttpCenter(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int if (0 == _tcsxnicmp(lpszMethodPost, pSt_HTTPParam->tszHttpMethod, _tcsxlen(lpszMethodPost))) { - //使用重定向? - if (st_LoadbalanceCfg.st_LBDistributed.nCenterMode > 0) - { - XCHAR tszHdrBuffer[1024]; - XCHAR tszStorageAddr[128]; - - memset(tszHdrBuffer, '\0', sizeof(tszHdrBuffer)); - memset(tszStorageAddr, '\0', sizeof(tszStorageAddr)); - - st_HDRParam.bIsClose = true; - st_HDRParam.nHttpCode = 302; - - APIHelp_Distributed_RandomAddr(st_LoadbalanceCfg.st_LoadBalance.pStl_ListCenter, tszStorageAddr, st_LoadbalanceCfg.st_LBDistributed.nCenterMode); - _xstprintf(tszHdrBuffer, _X("Location: %s%s\r\n"), tszStorageAddr, pSt_HTTPParam->tszHttpUri); - - HttpProtocol_Server_SendMsgEx(xhDLHttp, tszSDBuffer, &nSDLen, &st_HDRParam, NULL, 0, tszHdrBuffer); - XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPUPLOADER); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("业务客户端:%s,请求的函数被要求重定向到:%s%s"), lpszClientAddr, tszStorageAddr, pSt_HTTPParam->tszHttpUri); - return true; - } - if (!HttpProtocol_ServerHelp_GetUrlApi(pSt_HTTPParam->tszHttpUri, tszAPIVersion, tszAPIMethod, tszAPIName)) { st_HDRParam.bIsClose = true; diff --git a/XEngine_Source/XEngine_StorageApp/StorageApp_Config.cpp b/XEngine_Source/XEngine_StorageApp/StorageApp_Config.cpp index 6418856384a0b4baea2ca7f4a6382b7a55333dcb..5a44b836e3bca1a178a924ba434cd05caddae3be 100644 --- a/XEngine_Source/XEngine_StorageApp/StorageApp_Config.cpp +++ b/XEngine_Source/XEngine_StorageApp/StorageApp_Config.cpp @@ -5,6 +5,30 @@ bool StorageApp_Config_Parament(int argc,char **argv) LPCXSTR lpszBaseCfg = _X("./XEngine_Config/XEngine_Config.json"); LPCXSTR lpszLoadCfg = _X("./XEngine_Config/XEngine_LBConfig.json"); + if (NULL != st_ServiceCfg.st_XVer.pStl_ListStorage) + { + delete st_ServiceCfg.st_XVer.pStl_ListStorage; + st_ServiceCfg.st_XVer.pStl_ListStorage = NULL; + } + if (NULL != st_LoadbalanceCfg.st_LoadBalance.pStl_ListBucket) + { + delete st_LoadbalanceCfg.st_LoadBalance.pStl_ListBucket; + st_LoadbalanceCfg.st_LoadBalance.pStl_ListBucket = NULL; + } + if (NULL != st_LoadbalanceCfg.st_LoadBalance.pStl_ListDownload) + { + delete st_LoadbalanceCfg.st_LoadBalance.pStl_ListDownload; + st_LoadbalanceCfg.st_LoadBalance.pStl_ListDownload = NULL; + } + if (NULL != st_LoadbalanceCfg.st_LoadBalance.pStl_ListUPLoader) + { + delete st_LoadbalanceCfg.st_LoadBalance.pStl_ListUPLoader; + st_LoadbalanceCfg.st_LoadBalance.pStl_ListUPLoader = NULL; + } + + memset(&st_ServiceCfg, '\0', sizeof(XENGINE_SERVERCONFIG)); + memset(&st_LoadbalanceCfg, '\0', sizeof(XENGINE_LBCONFIG)); + if (!Config_Json_File(lpszBaseCfg, &st_ServiceCfg)) { printf("解析配置文件失败,Config_Json_File:%lX\n",Config_GetLastError()); diff --git a/XEngine_Source/XEngine_StorageApp/StorageApp_Download.cpp b/XEngine_Source/XEngine_StorageApp/StorageApp_Download.cpp index c5284ff2ddd5c75bf40996dd432571b7be00eaf5..83f8dc600df8eaab5aa6ec8c829bab8e687ce717 100644 --- a/XEngine_Source/XEngine_StorageApp/StorageApp_Download.cpp +++ b/XEngine_Source/XEngine_StorageApp/StorageApp_Download.cpp @@ -176,13 +176,12 @@ bool XEngine_Task_HttpDownload(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, in } if (st_ServiceCfg.st_XProxy.bAuthPass) { - int nBLen = 0; int nCode = 0; int nResponseCode = 0; XCHAR* ptszBody = NULL; Protocol_StoragePacket_BasicAuth(pSt_HTTPParam->tszHttpMethod, pSt_HTTPParam->tszHttpUri, lpszClientAddr, tszUserName, tszUserPass, tszSDBuffer, &nSDLen); - APIClient_Http_Request(_X("POST"), st_ServiceCfg.st_XProxy.tszAuthPass, tszSDBuffer, &nResponseCode, &ptszBody, &nBLen); + APIClient_Http_Request(_X("POST"), st_ServiceCfg.st_XProxy.tszAuthPass, tszSDBuffer, &nResponseCode, &ptszBody, &nSDLen); if (200 != nResponseCode) { st_HDRParam.bIsClose = true; diff --git a/XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h b/XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h index ec5307a40150660b756ec25f4a4930a22d81cdc3..97f4294ac634d3d2bb8521493f306916d2a1065a 100644 --- a/XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h +++ b/XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h @@ -48,14 +48,14 @@ using namespace std; #include #include #include "../XStorage_Protocol.h" +#include "../StorageModule_Config/Config_Define.h" +#include "../StorageModule_Config/Config_Error.h" #include "../StorageModule_Session/Session_Define.h" #include "../StorageModule_Session/Session_Error.h" #include "../StorageModule_Database/Database_Define.h" #include "../StorageModule_Database/Database_Error.h" #include "../StorageModule_Protocol/StorageProtocol_Define.h" #include "../StorageModule_Protocol/StorageProtocol_Error.h" -#include "../StorageModule_Config/Config_Define.h" -#include "../StorageModule_Config/Config_Error.h" #include "../StorageModule_APIHelp/APIHelp_Define.h" #include "../StorageModule_APIHelp/APIHelp_Error.h" @@ -105,7 +105,7 @@ extern XENGINE_LBCONFIG st_LoadbalanceCfg; #include "Storage_APPTask/Storage_TaskP2p.h" #include "Storage_APPTask/Storage_TaskManage.h" -#ifdef _WINDOWS +#ifdef _MSC_BUILD #pragma comment(lib,"Ws2_32.lib") #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") #pragma comment(lib,"XEngine_BaseLib/XEngine_Algorithm.lib") diff --git a/XEngine_Source/XEngine_StorageApp/StorageApp_UPLoader.cpp b/XEngine_Source/XEngine_StorageApp/StorageApp_UPLoader.cpp index 3d4d748460918e896c21cb0301416833e47379c0..47dc767fb157314e9a94084098c1da53a4dcdb5e 100644 --- a/XEngine_Source/XEngine_StorageApp/StorageApp_UPLoader.cpp +++ b/XEngine_Source/XEngine_StorageApp/StorageApp_UPLoader.cpp @@ -97,12 +97,11 @@ bool XEngine_Task_HttpUPLoader(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, in } if (st_ServiceCfg.st_XProxy.bAuthPass) { - int nBLen = 0; int nResponseCode = 0; XCHAR* ptszBody = NULL; Protocol_StoragePacket_BasicAuth(pSt_HTTPParam->tszHttpMethod, pSt_HTTPParam->tszHttpUri, lpszClientAddr, tszUserName, tszUserPass, tszSDBuffer, &nSDLen); - APIClient_Http_Request(_X("POST"), st_ServiceCfg.st_XProxy.tszAuthPass, tszSDBuffer, &nResponseCode, &ptszBody, &nBLen); + APIClient_Http_Request(_X("POST"), st_ServiceCfg.st_XProxy.tszAuthPass, tszSDBuffer, &nResponseCode, &ptszBody, &nSDLen); if (200 != nResponseCode) { st_HDRParam.bIsClose = true; diff --git a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskP2p.cpp b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskP2p.cpp index 0fb967f9915ffecfd1e9e48114f0bbf8383eb399..54eb517e196970bd520e8641227234ff604e6045 100644 --- a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskP2p.cpp +++ b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskP2p.cpp @@ -30,7 +30,7 @@ XHTHREAD XEngine_Task_P2PThread() //查询文件是否存在数据库,不存在不关心 int nListCount = 0; XSTORAGECORE_DBFILE** pppSt_ListFile; - Database_File_FileQuery(&pppSt_ListFile, &nListCount, tszTimeStart, tszTimeEnd, tszBuckKey, NULL, tszFileName, tszFileHash); + Database_Memory_FileQuery(&pppSt_ListFile, &nListCount, tszBuckKey, tszFileName, tszFileHash); if (nListCount > 0) { _xstprintf(pppSt_ListFile[0]->tszTableName, _X("%s:%d"), st_ServiceCfg.tszIPAddr, st_ServiceCfg.nStorageDLPort); diff --git a/XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.cpp b/XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.cpp index cc080fe3e4ce1190eb884dc40c245d99df597da7..05a2c47ec7d7d4e811170d4a1713da8336dc49bb 100644 --- a/XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.cpp +++ b/XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.cpp @@ -63,6 +63,7 @@ void ServiceApp_Stop(int signo) Session_DLStroage_Destory(); Session_UPStroage_Destory(); Database_File_Destory(); + Database_Memory_Destory(); if (NULL != pSTDThread) { @@ -74,7 +75,7 @@ void ServiceApp_Stop(int signo) } static int ServiceApp_Deamon(int wait) { -#ifndef _WINDOWS +#ifndef _MSC_BUILD pid_t pid = 0; int status; pid = fork(); @@ -105,10 +106,7 @@ static int ServiceApp_Deamon(int wait) int main(int argc, char** argv) { -#if (XENGINE_VERSION_KERNEL < 7) && (XENGINE_VERSION_MAIN < 24) - printf("XEngine版本过低,无法继续\n"); -#endif -#ifdef _WINDOWS +#ifdef _MSC_BUILD WSADATA st_WSAData; WSAStartup(MAKEWORD(2, 2), &st_WSAData); #endif @@ -136,7 +134,7 @@ int main(int argc, char** argv) XCHAR tszAddr[128]; memset(tszAddr, '\0', sizeof(tszAddr)); - _xstprintf(tszAddr, _X("Http://127.0.0.1:%d/Api/Manage/Config"), st_ServiceCfg.nCenterPort); + _xstprintf(tszAddr, _X("http://127.0.0.1:%d/Api/Manage/Config"), st_ServiceCfg.nCenterPort); APIClient_Http_Request(_X("POST"), tszAddr); return 0; } @@ -397,8 +395,15 @@ int main(int argc, char** argv) XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动HTTP业务任务处理线程池成功,线程池个数:%d"), st_ServiceCfg.st_XMax.nCenterThread); } //只有使用了数据库,才启用P2P - if (st_ServiceCfg.st_XSql.bEnable) + if (st_ServiceCfg.st_P2xp.bEnable) { + if (!Database_Memory_Init(st_LoadbalanceCfg.st_LoadBalance.pStl_ListBucket, st_ServiceCfg.st_XStorage.nHashMode)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,启动P2P内存数据库失败,错误:%lX"), Database_GetLastError()); + goto XENGINE_EXITAPP; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动P2P内存数据库成功")); + if (!NetCore_BroadCast_Create(&hBroadSocket, st_ServiceCfg.st_P2xp.nRVPort)) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,启动P2P存储广播服务失败,错误:%d"), errno); @@ -459,6 +464,7 @@ XENGINE_EXITAPP: Session_DLStroage_Destory(); Session_UPStroage_Destory(); Database_File_Destory(); + Database_Memory_Destory(); if (NULL != pSTDThread) { @@ -466,7 +472,7 @@ XENGINE_EXITAPP: pSTDThread->join(); } } -#ifdef _WINDOWS +#ifdef _MSC_BUILD WSACleanup(); #endif return 0;