diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..dd84ea7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/CHANGELOG b/CHANGELOG index dea1f60..8be4cd7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,25 @@ +XEngine_Storage V3.14.0.1001 + +增加:默认SSL的KEY文件 +增加:BT协议模块(支持解析,创建和下载BT种子) +增加:信息报告模块,可以上报信息和查询 +修改:定义http请求的类型修改为const char *类型 +修改:ssl类型现在采取默认tls了 +修改:ssl支持多类型证书了 +修改:配置文件逻辑型从int都改成bool了 +修正:读取ssl配置不正确的问题 +删除:没有使用的center相关代码 + +added:default ssl key +added:bt protocol module +added:info report module +modify:define http request type modify to const char * +modify:ssl type default only tls now +modify:ssl support multi type cert +modify:boolean type to asbool from asint for configure +fixed:read ssl configure is incorrect +delete:unused code for center +====================================================================================== XEngine_Storage V3.13.0.1001 增加:st_PermissionFlags增加新的标志位上传限制,现在上传文件也可以进行限制了 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..751bf62 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +486179@qq.com. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. diff --git a/README.en.md b/README.en.md index cc9cfb2..e1605cf 100644 --- a/README.en.md +++ b/README.en.md @@ -25,7 +25,7 @@ feature list: 8. supprot speeds contral 9. supprot task start and end proxy forwarding 10. support p2p -11. bt(planning) +11. bt protocol 12. data distributed 13. support second pass and Resumable 14. support upload and download Redirect @@ -49,15 +49,18 @@ Macos Exection:./XEngine_LINEnv.sh -i 3 #### Windows use vs open and compile,suport windows 7sp1 and above -Just Run it,use XEngine_AuthorizeApp +Just Run it,use XEngine_AuthorizeApp +if you need bt protocol support,you must install bt library by vcpkg:./vcpkg.exe install libtorrent #### Linux use makefile compile,UBUNTU22.04 x64 or RockyLinux9 x64 -Run it on the terminal +Run it on the terminal +if you need bt protocol support,you must install bt library:sudo apt install libtorrent-rasterbar-dev -y #### Macos use makefile compile,mac 13 and above -Run it on the terminal +Run it on the terminal +if you need bt protocol support,you must install bt library:brew install libtorrent-rasterbar ##### complie execute command in XEngine_Source path diff --git a/README.md b/README.md index a9993a0..52fdb73 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ c c++ file storage service 8. 支持传输速率控制 9. 支持任务开始结束代理转发 10. 支持P2P -11. BT(规划中) +11. BT协议 12. 数据分发 13. 支持秒传和断点续传 14. 支持上传和下载重定向 @@ -48,15 +48,18 @@ macos执行:./XEngine_LINEnv.sh -i 3 #### Windows 使用VS打开并且编译,支持WINDOWS 7SP1以上系统 -直接运行即可,使用XEngine_AuthorizeApp +直接运行即可,使用XEngine_AuthorizeApp +如果需要bt协议支持,需要通过vcpkg安装bt支持库:./vcpkg.exe install libtorrent #### Linux Linux使用Makefile编译,UBUNTU22.04 x64或者RockyLinux x64 -在控制台运行 +在控制台运行 +如果需要bt协议支持,需要安装bt库,比如,在ubuntu下面安装:sudo apt install libtorrent-rasterbar-dev -y #### Macos 使用makefile编译,控制台运行,需要mac 13以及以上版本 -在控制台运行 +在控制台运行 +如果需要bt协议支持,需要安装bt库,通过brew安装:brew install libtorrent-rasterbar ##### 编译命令 在XEngine_Source目录下执行命令 diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..fc80423 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,19 @@ +# Security Policy + +## Supported Versions + +Use this section to tell people about which versions of your project are +currently being supported with security updates. + +| Version | Supported | +| ------- | ------------------ | +| 2.6.x | :white_check_mark: | +| < 2.6 | :x: | + +## Reporting a Vulnerability + +Use this section to tell people how to report a vulnerability. + +Tell them where to go, how often they can expect to get an update on a +reported vulnerability, what to expect if the vulnerability is accepted or +declined, etc. diff --git a/XEngine_APPClient/APPClient_BTorrent/APPClient_BTorrent.cpp b/XEngine_APPClient/APPClient_BTorrent/APPClient_BTorrent.cpp new file mode 100644 index 0000000..151fdf0 --- /dev/null +++ b/XEngine_APPClient/APPClient_BTorrent/APPClient_BTorrent.cpp @@ -0,0 +1,200 @@ +#ifdef _MSC_BUILD +#include +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include "../../XEngine_Source/StorageModule_BTorrent/BTorrent_Define.h" +#include "../../XEngine_Source/StorageModule_BTorrent/BTorrent_Error.h" + +#ifdef _MSC_BUILD +#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") +#pragma comment(lib,"../../XEngine_Source/Debug/StorageModule_BTorrent.lib") +#endif + +//g++ -std=c++17 -Wall -g NetHelp_APPBTorrent.cpp -o AVCodec_APPPlayer.exe -L ../../XEngine_Source/StorageModule_BTorrent -lXEngine_BaseLib -lStorageModule_BTorrent + + +int BTorrent_Parse(LPCXSTR lpszFile) +{ + XNETHANDLE xhToken; + + if (!BTorrent_Parse_Init(&xhToken, lpszFile)) + { + printf("BTorrent_Parse_Init:%lX\n", BTorrent_GetLastError()); + return -1; + } + int nListCount = 0; + BTORRENT_PARSEMAP** ppSt_ParseNode; + if (!BTorrent_Parse_GetNode(xhToken, &ppSt_ParseNode, &nListCount)) + { + printf("BTorrent_Parse_GetNode:%lX\n", BTorrent_GetLastError()); + return -1; + } + for (int i = 0; i < nListCount; i++) + { + printf("BTorrent_Parse_GetNode:%d = %s\n", ppSt_ParseNode[i]->nValue, ppSt_ParseNode[i]->tszValue); + } + BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ParseNode, nListCount); + nListCount = 0; + + if (!BTorrent_Parse_GetTracker(xhToken, &ppSt_ParseNode, &nListCount)) + { + printf("BTorrent_Parse_GetTracker:%lX\n", BTorrent_GetLastError()); + return -1; + } + for (int i = 0; i < nListCount; i++) + { + printf("BTorrent_Parse_GetTracker:%d = %s\n", ppSt_ParseNode[i]->nValue, ppSt_ParseNode[i]->tszValue); + } + BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ParseNode, nListCount); + nListCount = 0; + + if (!BTorrent_Parse_GetSeeds(xhToken, &ppSt_ParseNode, &nListCount)) + { + printf("BTorrent_Parse_GetSeeds:%lX\n", BTorrent_GetLastError()); + return -1; + } + for (int i = 0; i < nListCount; i++) + { + printf("BTorrent_Parse_GetSeeds:%d = %s\n", ppSt_ParseNode[i]->nValue, ppSt_ParseNode[i]->tszValue); + } + BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ParseNode, nListCount); + nListCount = 0; + + int nPieceLen = 0; + int nPieceCount = 0; + if (!BTorrent_Parse_GetPiece(xhToken, &nPieceLen, &nPieceCount)) + { + printf("BTorrent_Parse_GetPiece:%lX\n", BTorrent_GetLastError()); + return -1; + } + printf("BTorrent_Parse_GetPiece:%d %d\n", nPieceLen, nPieceCount); + + XCHAR tszHash[4196]; + XCHAR tszCreator[4196]; + XCHAR tszComment[4196]; + + memset(tszHash, '\0', sizeof(tszHash)); + memset(tszCreator, '\0', sizeof(tszCreator)); + memset(tszComment, '\0', sizeof(tszComment)); + + if (!BTorrent_Parse_GetInfo(xhToken, tszHash, tszCreator, tszComment)) + { + printf("BTorrent_Parse_GetPiece:%lX\n", BTorrent_GetLastError()); + return -1; + } + printf("BTorrent_Parse_GetInfo:%s\n%s\n%s\n", tszHash, tszCreator, tszComment); + + XCHAR tszFile[MAX_PATH]; + memset(tszFile, '\0', MAX_PATH); + BTORRENT_FILEINFO** ppSt_FileList; + if (!BTorrent_Parse_GetFile(xhToken, tszFile, &ppSt_FileList, &nListCount)) + { + printf("BTorrent_Parse_GetFile:%lX\n", BTorrent_GetLastError()); + return -1; + } + for (int i = 0; i < nListCount; i++) + { + printf("BTorrent_Parse_GetFile:%s %s %s %s %lld %lld %lld %d %d\n", ppSt_FileList[i]->tszFileHash, ppSt_FileList[i]->tszFilePath, ppSt_FileList[i]->tszFileName, ppSt_FileList[i]->tszFileLink, ppSt_FileList[i]->nFileOffset, ppSt_FileList[i]->nFileSize, ppSt_FileList[i]->nFileTime, ppSt_FileList[i]->nFileStart, ppSt_FileList[i]->nFileEnd); + } + BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_FileList, nListCount); + + BTorrent_Parse_Destory(xhToken); + return 0; +} +int BTorrent_Creator(LPCXSTR lpszFile) +{ + XNETHANDLE xhToken; +#ifdef _MSC_BUILD + LPCXSTR lpszFileDir = _X("D:\\321"); +#else + LPCXSTR lpszFileDir = _X("./321"); +#endif + + if (!BTorrent_Creator_Init(&xhToken, lpszFileDir)) + { + printf("BTorrent_Creator_Init:%lX\n", BTorrent_GetLastError()); + return -1; + } + + BTorrent_Creator_AddTracker(xhToken, "http://wwww.xyry.org/anno"); + BTorrent_Creator_SetInfo(xhToken, "xengine", "xengine btorrent V7.11"); + + if (!BTorrent_Creator_GetTorrent(xhToken, lpszFile)) + { + printf("BTorrent_Creator_GetTorrent:%lX\n", BTorrent_GetLastError()); + return -1; + } + BTorrent_Creator_Destory(xhToken); + return 0; +} +int BTorrent_Download() +{ + XNETHANDLE xhToken; +#ifdef _MSC_BUILD + LPCXSTR lpszBTFile = _X("D:\\123.torrent"); + LPCXSTR lpszFileDir = _X("D:\\321"); +#else + LPCXSTR lpszBTFile = _X("./123.torrent"); + LPCXSTR lpszFileDir = _X("./321"); +#endif + + if (!BTorrent_DLoader_Create(&xhToken, lpszBTFile, lpszFileDir)) + { + printf("BTorrent_Creator_Init:%lX\n", BTorrent_GetLastError()); + return -1; + } + bool bRun = TRUE; + + while (1) + { + int nListCount = 0; + ENUM_BTORRENT_EVENT_TYPE** ppenEventList; + BTorrent_DLoader_Query(xhToken, &ppenEventList, &nListCount); + for (int i = 0; i < nListCount; i++) + { + if (ENUM_BTORRENT_EVENT_TYPE_STATUS == *(ppenEventList[i])) + { + BTORRENT_DLOADER st_DLStatus; + BTorrent_DLoader_GetStatus(xhToken, &st_DLStatus); + + printf("%s-%d:%lld,%lld\n", st_DLStatus.tszFileName, st_DLStatus.nDLStatus, st_DLStatus.nDLoadTotal, st_DLStatus.nDLCount); + } + else if (ENUM_BTORRENT_EVENT_TYPE_COMPLETE == *(ppenEventList[i])) + { + bRun = FALSE; + break; + } + printf("%d\n", *(ppenEventList[i])); + } + if (!bRun) + { + break; + } + std::this_thread::sleep_for(std::chrono::seconds(1)); + BaseLib_OperatorMemory_Free((XPPPMEM)&ppenEventList, nListCount); + } + + BTorrent_DLoader_Close(xhToken); + return 0; +} +int main() +{ +#ifdef _MSC_BUILD + LPCXSTR lpszFile = _X("D:\\321.torrent"); +#else + LPCXSTR lpszFile = _X("./321.torrent"); +#endif + + BTorrent_Download(); + BTorrent_Creator(lpszFile); + BTorrent_Parse(lpszFile); + + return 0; +} \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_BTorrent/APPClient_BTorrent.vcxproj b/XEngine_APPClient/APPClient_BTorrent/APPClient_BTorrent.vcxproj new file mode 100644 index 0000000..26703be --- /dev/null +++ b/XEngine_APPClient/APPClient_BTorrent/APPClient_BTorrent.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {cd6abe42-badf-4cc9-bfcf-225f922040ca} + APPClientBTorrent + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_BTorrent/APPClient_BTorrent.vcxproj.filters b/XEngine_APPClient/APPClient_BTorrent/APPClient_BTorrent.vcxproj.filters new file mode 100644 index 0000000..e64d755 --- /dev/null +++ b/XEngine_APPClient/APPClient_BTorrent/APPClient_BTorrent.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_BTorrent/APPClient_BTorrent.vcxproj.user b/XEngine_APPClient/APPClient_BTorrent/APPClient_BTorrent.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/XEngine_APPClient/APPClient_BTorrent/APPClient_BTorrent.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_APPClient/VSCopy_x64.bat b/XEngine_APPClient/VSCopy_x64.bat index 3ca9440..78e0725 100644 --- a/XEngine_APPClient/VSCopy_x64.bat +++ b/XEngine_APPClient/VSCopy_x64.bat @@ -2,10 +2,4 @@ copy /y "%XEngine_Lib64%\XEngine_BaseLib\XEngine_BaseLib.dll" "./" copy /y "%XEngine_Lib64%\XEngine_BaseLib\XEngine_Algorithm.dll" "./" copy /y "%XEngine_Lib64%\XEngine_Core\XEngine_OPenSsl.dll" "./" copy /y "%XEngine_Lib64%\XEngine_SystemSdk\XEngine_SystemApi.dll" "./" -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-x64.dll" "./" -copy /y "%XEngine_Lib64%\XEngine_NetHelp\libcurl.dll" "./" -copy /y "%XEngine_Lib64%\XEngine_NetHelp\nghttp2.dll" "./" \ No newline at end of file +copy /y "%XEngine_Lib64%\XEngine_NetHelp\NetHelp_APIClient.dll" "./" \ No newline at end of file diff --git a/XEngine_APPClient/VSCopy_x86.bat b/XEngine_APPClient/VSCopy_x86.bat index 54a3c4f..fbbc0b7 100644 --- a/XEngine_APPClient/VSCopy_x86.bat +++ b/XEngine_APPClient/VSCopy_x86.bat @@ -2,10 +2,4 @@ copy /y "%XEngine_Lib32%\XEngine_BaseLib\XEngine_BaseLib.dll" "./" copy /y "%XEngine_Lib32%\XEngine_BaseLib\XEngine_Algorithm.dll" "./" copy /y "%XEngine_Lib32%\XEngine_Core\XEngine_OPenSsl.dll" "./" copy /y "%XEngine_Lib32%\XEngine_SystemSdk\XEngine_SystemApi.dll" "./" -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_NetHelp\libcurl.dll" "./" -copy /y "%XEngine_Lib32%\XEngine_NetHelp\nghttp2.dll" "./" \ No newline at end of file +copy /y "%XEngine_Lib32%\XEngine_Client\XClient_APIHelp.dll" "./" \ No newline at end of file diff --git a/XEngine_APPClient/XEngine_APPClient.sln b/XEngine_APPClient/XEngine_APPClient.sln index ce78eac..792d142 100644 --- a/XEngine_APPClient/XEngine_APPClient.sln +++ b/XEngine_APPClient/XEngine_APPClient.sln @@ -15,6 +15,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_UPMaker", "APPCli EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_UPFile", "APPClient_UPDate\APPClient_UPFile\APPClient_UPFile.vcxproj", "{D2B84345-CE80-4E29-8A3E-6ACE68EB7ADF}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_BTorrent", "APPClient_BTorrent\APPClient_BTorrent.vcxproj", "{CD6ABE42-BADF-4CC9-BFCF-225F922040CA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -63,6 +65,14 @@ Global {D2B84345-CE80-4E29-8A3E-6ACE68EB7ADF}.Release|x64.Build.0 = Release|x64 {D2B84345-CE80-4E29-8A3E-6ACE68EB7ADF}.Release|x86.ActiveCfg = Release|Win32 {D2B84345-CE80-4E29-8A3E-6ACE68EB7ADF}.Release|x86.Build.0 = Release|Win32 + {CD6ABE42-BADF-4CC9-BFCF-225F922040CA}.Debug|x64.ActiveCfg = Debug|x64 + {CD6ABE42-BADF-4CC9-BFCF-225F922040CA}.Debug|x64.Build.0 = Debug|x64 + {CD6ABE42-BADF-4CC9-BFCF-225F922040CA}.Debug|x86.ActiveCfg = Debug|Win32 + {CD6ABE42-BADF-4CC9-BFCF-225F922040CA}.Debug|x86.Build.0 = Debug|Win32 + {CD6ABE42-BADF-4CC9-BFCF-225F922040CA}.Release|x64.ActiveCfg = Release|x64 + {CD6ABE42-BADF-4CC9-BFCF-225F922040CA}.Release|x64.Build.0 = Release|x64 + {CD6ABE42-BADF-4CC9-BFCF-225F922040CA}.Release|x86.ActiveCfg = Release|Win32 + {CD6ABE42-BADF-4CC9-BFCF-225F922040CA}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/XEngine_Docment/Docment_en.docx b/XEngine_Docment/Docment_en.docx index c4d02f8..a6cbed9 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 483211a..a7e3d47 100644 Binary files a/XEngine_Docment/Docment_zh.docx and b/XEngine_Docment/Docment_zh.docx differ diff --git a/XEngine_Release/XEngine_Cert/.gitignore b/XEngine_Release/XEngine_Cert/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/XEngine_Release/XEngine_Cert/server.crt b/XEngine_Release/XEngine_Cert/server.crt new file mode 100644 index 0000000..9b9719c --- /dev/null +++ b/XEngine_Release/XEngine_Cert/server.crt @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDZzCCAk8CFGgg0Kn03GiOunI7jMmWuJALC6YaMA0GCSqGSIb3DQEBCwUAMHAx +CzAJBgNVBAYTAkNOMRAwDgYDVQQIDAdzaWNodWFuMRAwDgYDVQQHDAdjaGVuZ2R1 +MRAwDgYDVQQKDAd4ZW5naW5lMRQwEgYDVQQLDAtzdHJlYW1tZWRpYTEVMBMGA1UE +AwwMd3d3Lnh5cnkub3JnMB4XDTI0MDMyMjAzNDExNloXDTM0MDMyMDAzNDExNlow +cDELMAkGA1UEBhMCQ04xEDAOBgNVBAgMB3NpY2h1YW4xEDAOBgNVBAcMB2NoZW5n +ZHUxEDAOBgNVBAoMB3hlbmdpbmUxFDASBgNVBAsMC3N0cmVhbW1lZGlhMRUwEwYD +VQQDDAx3d3cueHlyeS5vcmcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB +AQCYcWc5YUagKdzxma0GsHCnhZIYoy512mVHL4NGi6Xvz3eE379aLYzMQ/PYFNV+ +GqgDWDYlIsHvGthQqbixRoF47ezXPrHwnhjYsfBSU9IOJZ2iIeMXugmBduW9d8W4 +85eQ3x5HGzttILdPbgtnP52DMGu/Ev/Zi41KH0T+90MY6i1KxRLwvMN/liAUvPcO +Aydg1fNaVvpyS2iqhvb0jNC9kkK/bH4de2uTWU5t9+4ous1NBAIHZd0kLBeOTsRR +qaCiq/ADYvk/WY0pyeXPcPNhq2Fokfw2y+6gCccOEn7G6BzljzeOiCC2rIpU4bfW +6GezuR8qhFxuYxXo2Mk6DAqNAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAHQiJEFs +WsUMawg4pm0QWPHQTQ8L5976+BqZoMbmF2rAnMNaeEOMCUh0cjbZMyx+DflDCiT0 +coxWDVwbrXNB0ho7HE5RiEavgqswXtMmDg1PZ+PrcMR9EhDsVXOtY0/SIwIYU455 +x4ggiLnWm3wua2Yoj7HIaCmKGqdHKbqyCgKKrzcYTKz6dApMuvdPLy36+V4vhBA/ +sDYLQ37XHlE9iE3YBLqjoE1iWUuofFEgwlITCssEN8A3B0m9mc+O18IZ7MBir0sC +pPdqyLmfjAEyegAYBxofrOMD0nevI+/IhT4Gf1btL53rgRLd1o8wXFUwKvHEmcqY +pd3q0OEcbsBESKk= +-----END CERTIFICATE----- diff --git a/XEngine_Release/XEngine_Cert/server.csr b/XEngine_Release/XEngine_Cert/server.csr new file mode 100644 index 0000000..f330671 --- /dev/null +++ b/XEngine_Release/XEngine_Cert/server.csr @@ -0,0 +1,17 @@ +-----BEGIN CERTIFICATE REQUEST----- +MIICtTCCAZ0CAQAwcDELMAkGA1UEBhMCQ04xEDAOBgNVBAgMB3NpY2h1YW4xEDAO +BgNVBAcMB2NoZW5nZHUxEDAOBgNVBAoMB3hlbmdpbmUxFDASBgNVBAsMC3N0cmVh +bW1lZGlhMRUwEwYDVQQDDAx3d3cueHlyeS5vcmcwggEiMA0GCSqGSIb3DQEBAQUA +A4IBDwAwggEKAoIBAQCYcWc5YUagKdzxma0GsHCnhZIYoy512mVHL4NGi6Xvz3eE +379aLYzMQ/PYFNV+GqgDWDYlIsHvGthQqbixRoF47ezXPrHwnhjYsfBSU9IOJZ2i +IeMXugmBduW9d8W485eQ3x5HGzttILdPbgtnP52DMGu/Ev/Zi41KH0T+90MY6i1K +xRLwvMN/liAUvPcOAydg1fNaVvpyS2iqhvb0jNC9kkK/bH4de2uTWU5t9+4ous1N +BAIHZd0kLBeOTsRRqaCiq/ADYvk/WY0pyeXPcPNhq2Fokfw2y+6gCccOEn7G6Bzl +jzeOiCC2rIpU4bfW6GezuR8qhFxuYxXo2Mk6DAqNAgMBAAGgADANBgkqhkiG9w0B +AQsFAAOCAQEAiHMwNeWi5hJhSEEsx3iMG+Ftk19ShPIFoSZXcx1/X8IcGT99k8f9 +bKHCX4NAP/byF5M6ElkPv5FBhprNieykKfBJVzz+cZfaE6eWYI1VI0vwAjMYVdVf +zMllRfstoSO/k+NQ067XJ4NjAVoitpuKYbqbJLKODXsO3ETMbEdo4iMB9kbHQY+U +5roJdAAF4fBe7qfcBuklZ3lRl6zbhdnY3ttgljzgG08k7jXb59tu6T7LX7+gjPUj +JSLA5uIBIi9CBaCatHEdtjg82o4ZSK6Yds1Opeprwtq7/RcsB9yhitL7GO+9oF90 +XnmrLZDfJreAN2hogb6mXgjWxEqvPV28Fg== +-----END CERTIFICATE REQUEST----- diff --git a/XEngine_Release/XEngine_Cert/server.key b/XEngine_Release/XEngine_Cert/server.key new file mode 100644 index 0000000..12462ac --- /dev/null +++ b/XEngine_Release/XEngine_Cert/server.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCYcWc5YUagKdzx +ma0GsHCnhZIYoy512mVHL4NGi6Xvz3eE379aLYzMQ/PYFNV+GqgDWDYlIsHvGthQ +qbixRoF47ezXPrHwnhjYsfBSU9IOJZ2iIeMXugmBduW9d8W485eQ3x5HGzttILdP +bgtnP52DMGu/Ev/Zi41KH0T+90MY6i1KxRLwvMN/liAUvPcOAydg1fNaVvpyS2iq +hvb0jNC9kkK/bH4de2uTWU5t9+4ous1NBAIHZd0kLBeOTsRRqaCiq/ADYvk/WY0p +yeXPcPNhq2Fokfw2y+6gCccOEn7G6BzljzeOiCC2rIpU4bfW6GezuR8qhFxuYxXo +2Mk6DAqNAgMBAAECggEAAJeVOHoiVbOF1Ly+QKF7gcaw9aqQHu7/aWalqnkdFGzY +dSfe/9hNVGft4ONVERoT54mcnjqF5JTm+zguHlF+KOTW1dj11wy+uqbv54tLBOC9 +HxdG9m42wx6IhprE0LXMRe1Rpmtdn7DCTkgeG6BVW3KO2w7qzGvqVU4rYioZoolJ +1bkCFrttktbztgQDS5spl/cugGWgsW5Y2GanU11as69w+9UiL09vCRg+Ie5DiZi1 +soN2i6y75tJDpgaSCnmSri2YaG4cSiDq/cvcpyCCoQmpIfxkuZ4BaTaaPBjIQoyt +Y45PqmuDOLuIaNgllUzxHZMgRSipM11bo2ySGAigwQKBgQC+V2oh67TaNkPvZZ5U +5iSm50Dsl0CVHIteBedB4xEuLQVtA4HPU1hF3EfwGVOUX5Qqr5B3whqlVr/4Z0Th +IAl6D3F5IFD41X5kpw0ygrxyCKPrRKfQfOijAuLQ+50NpnhcOqdmkXmXEh8ZQGZn +Tqqqiry6aTviRjAqUfhe3QE0wQKBgQDNB0RiT0bvtarBxVeehzvQtw67czwvYJq7 +3lGQlTLr1IP5H6JmzD6x0f0cTz0x50N62Lg8kI6IQmQL/ixJzBhcv3alQ+4jwRRx +pf+2LA+JBYHuuEValhY4awLn0QCCsP3BjvcDe1//T0tkatPu7bEUN3sMDeoG1vT8 +Qht0tcvMzQKBgAXTeyYqptB/FLlBLQWAPeL19SDIyGtIAmQQXjHAF4iITEA3+UM1 +U+Bfi7wnqk1CV7Cuywc/Y71n2FxsHMmfR2r7CgghGxliv4mpK1g+dDIxXYMYCOLy +z9QdhH/NE9OVIt3/1ZvoHAapwVXuiLPkzoiF0p0KF5EngNXqyGVu8liBAoGBAKtH +X+R08AC/FiiMULc5qEmjM6Z7DRNTM9CwWBld2s1SmvGacNRJ2jI5B6cHt0qiNShC +Nh86cCf6tpOiQaNg4hVRSa+kgSPTX93VXDr2sf+43yPrQtz7NxLoquO4ISIM8+Ao +K8j332ls98Gq0OPwI5eNBbk7Qn92QfEe1Mr6OIgdAoGAZSnBGYuE3iAf5z0k0pz4 +i+As/Y6tDIgJf5MUBJ0aZQjDZATRqTZewasxA+YEtan0t8h2lR5U3f98KcweT4Wo +qVReotVk98rNLH94cpeIA9+bhE+FpDPvDm3LMSTDX1b8vMLukE5CWKkEiOIMBFeo +3NL4mInqVDxxZX6OItH1UOw= +-----END PRIVATE KEY----- diff --git a/XEngine_Release/XEngine_Config/XEngine_Config.json b/XEngine_Release/XEngine_Config/XEngine_Config.json index bb05b14..605150c 100644 --- a/XEngine_Release/XEngine_Config/XEngine_Config.json +++ b/XEngine_Release/XEngine_Config/XEngine_Config.json @@ -32,8 +32,8 @@ "SQLPass":"123123aa" }, "XStorage":{ - "bResumable":1, - "bUPHash":0, + "bResumable":true, + "bUPHash":false, "nHashMode":2 }, "XAuth":{ @@ -64,14 +64,19 @@ "nSDPort":15001 }, "XCert":{ - "bDLEnable":0, - "bUPEnable":0, - "bCHEnable":0, - "nSslType":0, - "tszCertChain":"./XEngine_Cert/1_www.xyry.org_bundle.crt", - "tszCertKey":"./XEngine_Cert/2_www.xyry.org.key" + "bDLEnable":false, + "bUPEnable":false, + "bCHEnable":false, + "tszCertChain":"./XEngine_Cert/server.crt", + "tszCertServer":"", + "tszCertKey":"./XEngine_Cert/server.key" + }, + "XReport":{ + "bEnable":true, + "tszAPIUrl":"http://app.xyry.org:5501/api?function=machine" }, "XVer":[ + "3.14.0.1001 Build20240418", "3.13.0.1001 Build20240301", "3.12.1.1001 Build20240104", "3.12.0.1001 Build20231025", diff --git a/XEngine_Source/Makefile b/XEngine_Source/Makefile index 19e269b..66ff408 100644 --- a/XEngine_Source/Makefile +++ b/XEngine_Source/Makefile @@ -10,11 +10,13 @@ BASE_CONFIG_PATH = ./StorageModule_Config BASE_SESSION_PATH = ./StorageModule_Session BASE_APIHELP_PATH = ./StorageModule_APIHelp BASE_PROTOCOL_PATH = ./StorageModule_Protocol +BASE_BTORRENT_PATH = ./StorageModule_BTorrent +BASE_INFOREPORT_PATH = ./StorageModule_InfoReport APPSERVICE_STORAGE_PATH = ./XEngine_StorageApp XENGINE_MODULES = libjsoncpp.so \ - libStorageModule_Database.so libStorageModule_Config.so libStorageModule_Session.so libStorageModule_APIHelp.so libStorageModule_Protocol.so \ + libStorageModule_Database.so libStorageModule_Config.so libStorageModule_Session.so libStorageModule_APIHelp.so libStorageModule_Protocol.so libStorageModule_BTorrent.so libStorageModule_InfoReport.so \ XEngine_StorageApp.exe .PHONY:MakeAll @@ -33,6 +35,10 @@ libStorageModule_APIHelp.so: make -C $(BASE_APIHELP_PATH) PLATFORM=$(PLATFORM) $(FLAGS) libStorageModule_Protocol.so: make -C $(BASE_PROTOCOL_PATH) PLATFORM=$(PLATFORM) $(FLAGS) - +libStorageModule_BTorrent.so: + make -C $(BASE_BTORRENT_PATH) PLATFORM=$(PLATFORM) $(FLAGS) +libStorageModule_InfoReport.so: + make -C $(BASE_INFOREPORT_PATH) PLATFORM=$(PLATFORM) $(FLAGS) + XEngine_StorageApp.exe: make -C $(APPSERVICE_STORAGE_PATH) PLATFORM=$(PLATFORM) $(FLAGS) diff --git a/XEngine_Source/StorageModule_BTorrent/BTorrent_Creator/BTorrent_Creator.cpp b/XEngine_Source/StorageModule_BTorrent/BTorrent_Creator/BTorrent_Creator.cpp new file mode 100644 index 0000000..aa694db --- /dev/null +++ b/XEngine_Source/StorageModule_BTorrent/BTorrent_Creator/BTorrent_Creator.cpp @@ -0,0 +1,452 @@ +#include "pch.h" +#include "BTorrent_Creator.h" +/******************************************************************** +// Created: 2023/02/02 16:26:25 +// File Name: D:\XEngine\XEngine_SourceCode\XEngine_NetHelp\NetHelp_BTorrent\BTorrent_Creator\BTorrent_Creator.cpp +// File Path: D:\XEngine\XEngine_SourceCode\XEngine_NetHelp\NetHelp_BTorrent\BTorrent_Creator +// File Base: BTorrent_Creator +// File Ext: cpp +// Project: XEngine +// Author: qyt +// Purpose: BT创建器 +// History: +*********************************************************************/ +CBTorrent_Creator::CBTorrent_Creator() +{ +} +CBTorrent_Creator::~CBTorrent_Creator() +{ +} +////////////////////////////////////////////////////////////////////////// +// 公有函数 +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +函数名称:BTorrent_Creator_Init +函数功能:初始化一个制作工具 + 参数.一:pxhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:导出一个句柄 + 参数.二:lpszBTPath + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:要制作的文件地址路径 + 参数.三:nPieceSize + In/Out:In + 类型:整数型 + 可空:N + 意思:块大小,默认16K +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_Creator::BTorrent_Creator_Init(XNETHANDLE* pxhToken, LPCXSTR lpszBTPath, int nPieceSize) +{ + BTDload_IsErrorOccur = false; + + if ((NULL == pxhToken) || (NULL == lpszBTPath)) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_CREATOR_INIT_PARAMENT; + return false; + } + //申请空间 + BTORRENT_CREATORINFO st_BTCreator; + memset(&st_BTCreator, '\0', sizeof(BTORRENT_CREATORINFO)); + + //申请内存 + st_BTCreator.pStl_ListNode = new list; + st_BTCreator.pStl_ListSeeds = new list; + st_BTCreator.pStl_ListTracker = new list; + + if ((NULL == st_BTCreator.pStl_ListNode) || (NULL == st_BTCreator.pStl_ListSeeds) || (NULL == st_BTCreator.pStl_ListTracker)) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_CREATOR_INIT_MALLOC; + return false; + } + + st_BTCreator.m_nPieceSize = nPieceSize; + _tcsxcpy(st_BTCreator.tszBTPath, lpszBTPath); + + BaseLib_OperatorHandle_Create(pxhToken); + st_Locker.lock(); + stl_MapBTCreator.insert(make_pair(*pxhToken, st_BTCreator)); + st_Locker.unlock(); + return true; +} +/******************************************************************** +函数名称:BTorrent_Creator_AddNode +函数功能:添加种子DHT节点地址 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入节点地址 + 参数.三:nIndex + In/Out:In + 类型:整数型 + 可空:N + 意思:当前索引 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_Creator::BTorrent_Creator_AddNode(XNETHANDLE xhToken, LPCXSTR lpszAddr, int nIndex) +{ + BTDload_IsErrorOccur = false; + + if (NULL == lpszAddr) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_CREATOR_NODE_PARAMENT; + return false; + } + st_Locker.lock_shared(); + unordered_map::const_iterator stl_MapIterator = stl_MapBTCreator.find(xhToken); + if (stl_MapIterator == stl_MapBTCreator.end()) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_CREATOR_NODE_NOTFOUND; + st_Locker.unlock_shared(); + return false; + } + BTORRENT_PARSEMAP st_BTInfo; + memset(&st_BTInfo, '\0', sizeof(BTORRENT_PARSEMAP)); + + st_BTInfo.nValue = nIndex; + _tcsxcpy(st_BTInfo.tszValue, lpszAddr); + stl_MapIterator->second.pStl_ListNode->push_back(st_BTInfo); + st_Locker.unlock_shared(); + return true; +} +/******************************************************************** +函数名称:BTorrent_Creator_AddTracker +函数功能:设置TRACKER服务器地址 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入地址 + 参数.三:nIndex + In/Out:In + 类型:整数型 + 可空:Y + 意思:输入服务器索引 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_Creator::BTorrent_Creator_AddTracker(XNETHANDLE xhToken, LPCXSTR lpszAddr, int nIndex) +{ + BTDload_IsErrorOccur = false; + + if (NULL == lpszAddr) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_CREATOR_TRACKER_PARAMENT; + return false; + } + st_Locker.lock_shared(); + unordered_map::const_iterator stl_MapIterator = stl_MapBTCreator.find(xhToken); + if (stl_MapIterator == stl_MapBTCreator.end()) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_CREATOR_TRACKER_NOTFOUND; + st_Locker.unlock_shared(); + return false; + } + BTORRENT_PARSEMAP st_BTInfo; + memset(&st_BTInfo, '\0', sizeof(BTORRENT_PARSEMAP)); + + st_BTInfo.nValue = nIndex; + _tcsxcpy(st_BTInfo.tszValue, lpszAddr); + stl_MapIterator->second.pStl_ListTracker->push_back(st_BTInfo); + st_Locker.unlock_shared(); + return true; +} +/******************************************************************** +函数名称:BTorrent_Creator_AddSeeds +函数功能:添加URL种子到制作器 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入地址 + 参数.三:bSingle + In/Out:In + 类型:逻辑型 + 可空:N + 意思:多种子文件还是单种子文件 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_Creator::BTorrent_Creator_AddSeeds(XNETHANDLE xhToken, LPCXSTR lpszAddr, bool bSingle) +{ + BTDload_IsErrorOccur = false; + + if (NULL == lpszAddr) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_CREATOR_SEEDS_PARAMENT; + return false; + } + st_Locker.lock_shared(); + unordered_map::const_iterator stl_MapIterator = stl_MapBTCreator.find(xhToken); + if (stl_MapIterator == stl_MapBTCreator.end()) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_CREATOR_SEEDS_NOTFOUND; + st_Locker.unlock_shared(); + return false; + } + BTORRENT_PARSEMAP st_BTInfo; + memset(&st_BTInfo, '\0', sizeof(BTORRENT_PARSEMAP)); + + st_BTInfo.nValue = bSingle; + _tcsxcpy(st_BTInfo.tszValue, lpszAddr); + stl_MapIterator->second.pStl_ListSeeds->push_back(st_BTInfo); + st_Locker.unlock_shared(); + return true; +} +/******************************************************************** +函数名称:BTorrent_Creator_SetInfo +函数功能:设置种子信息 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:lpszCreator + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入制作器名称 + 参数.三:lpszComment + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入附加信息 + 参数.四:lpszCertBuffer + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入PEM证书缓冲区 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_Creator::BTorrent_Creator_SetInfo(XNETHANDLE xhToken, LPCXSTR lpszCreator, LPCXSTR lpszComment /* = NULL */, LPCXSTR lpszCertBuffer /* = NULL */) +{ + BTDload_IsErrorOccur = false; + + if (NULL == lpszCreator) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_CREATOR_INFO_PARAMENT; + return false; + } + st_Locker.lock_shared(); + unordered_map::iterator stl_MapIterator = stl_MapBTCreator.find(xhToken); + if (stl_MapIterator == stl_MapBTCreator.end()) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_CREATOR_INFO_NOTFOUND; + st_Locker.unlock_shared(); + return false; + } + _tcsxcpy(stl_MapIterator->second.tszCreate, lpszCreator); + if (NULL != lpszComment) + { + _tcsxcpy(stl_MapIterator->second.tszComment, lpszComment); + } + if (NULL != lpszCertBuffer) + { + _tcsxcpy(stl_MapIterator->second.tszPEMCert, lpszCertBuffer); + } + st_Locker.unlock_shared(); + return true; +} +/******************************************************************** +函数名称:BTorrent_Creator_GetTorrent +函数功能:获取中心信息 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:lpszBTFile + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输出种子文件地址 + 参数.三:ptszMsgBuffer + In/Out:Out + 类型:字符指针 + 可空:Y + 意思:输出种子信息到内存 + 参数.四:pInt_MsgLen + In/Out:Out + 类型:整数型指针 + 可空:Y + 意思:输出内存大小 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_Creator::BTorrent_Creator_GetTorrent(XNETHANDLE xhToken, LPCXSTR lpszBTFile /* = NULL */, XCHAR* ptszMsgBuffer /* = NULL */, int* pInt_MsgLen /* = NULL */) +{ + BTDload_IsErrorOccur = false; + + if ((NULL == lpszBTFile) && (NULL == ptszMsgBuffer)) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_CREATOR_FILE_PARAMENT; + return false; + } + st_Locker.lock_shared(); + unordered_map::iterator stl_MapIterator = stl_MapBTCreator.find(xhToken); + if (stl_MapIterator == stl_MapBTCreator.end()) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_CREATOR_FILE_NOTFOUND; + st_Locker.unlock_shared(); + return false; + } +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT + lt::file_storage m_BTFile; + lt::create_flags_t m_BTFlags; + //种子的标示 + m_BTFlags |= lt::create_torrent::modification_time; + //解析文件 + lt::add_files(m_BTFile, stl_MapIterator->second.tszBTPath, m_BTFlags); + if (m_BTFile.num_files() <= 0) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_CREATOR_FILE_PARSE; + return false; + } + //创建BT种子,种子文件解析的数据,块大小,附加信息,种子标志 + lt::create_torrent m_BTCreator(m_BTFile, stl_MapIterator->second.m_nPieceSize, m_BTFlags); + //给创建起赋值 + m_BTCreator.set_creator(stl_MapIterator->second.tszCreate); + m_BTCreator.set_comment(stl_MapIterator->second.tszComment); + m_BTCreator.set_root_cert(stl_MapIterator->second.tszPEMCert); + //节点添加 + list::const_iterator stl_ListNodeIterator = stl_MapIterator->second.pStl_ListNode->begin(); + for (; stl_ListNodeIterator != stl_MapIterator->second.pStl_ListNode->end(); stl_MapIterator++) + { + m_BTCreator.add_node(make_pair(stl_ListNodeIterator->tszValue, stl_ListNodeIterator->nValue)); + } + //添加服务 + list::const_iterator stl_ListTrackerIterator = stl_MapIterator->second.pStl_ListTracker->begin(); + for (; stl_ListTrackerIterator != stl_MapIterator->second.pStl_ListTracker->end(); stl_ListTrackerIterator++) + { + m_BTCreator.add_tracker(stl_ListTrackerIterator->tszValue, stl_ListTrackerIterator->nValue); + } + //添加SEED服务 + list::const_iterator stl_ListSeedIterator = stl_MapIterator->second.pStl_ListSeeds->begin(); + for (; stl_ListSeedIterator != stl_MapIterator->second.pStl_ListSeeds->end(); stl_ListSeedIterator++) + { + //添加URL种子,单文件为HTTP的URL,多文件为SEED + if (stl_ListSeedIterator->nValue) + { + m_BTCreator.add_http_seed(stl_ListTrackerIterator->tszValue); + } + else + { + m_BTCreator.add_url_seed(stl_ListTrackerIterator->tszValue); + } + } + //开始打包 + std::vector stl_ListTorrent; + lt::bencode(back_inserter(stl_ListTorrent), m_BTCreator.generate()); + //写到文件 + if (NULL != lpszBTFile) + { + std::fstream m_FStream; + m_FStream.exceptions(std::ifstream::failbit); + m_FStream.open(lpszBTFile, std::ios_base::out | std::ios_base::binary); + if (!m_FStream) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_CREATOR_FILE_FAILED; + st_Locker.unlock_shared(); + return false; + } + m_FStream.write(stl_ListTorrent.data(), stl_ListTorrent.size()); + m_FStream.close(); + } + //输出到内存 + if (NULL != ptszMsgBuffer) + { + *pInt_MsgLen = stl_ListTorrent.size(); + memcpy(ptszMsgBuffer, stl_ListTorrent.data(), *pInt_MsgLen); + } +#endif + st_Locker.unlock_shared(); + + return true; +} +/******************************************************************** +函数名称:BTorrent_Creator_Destory +函数功能:销毁 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_Creator::BTorrent_Creator_Destory(XNETHANDLE xhToken) +{ + BTDload_IsErrorOccur = false; + + st_Locker.lock(); + unordered_map::iterator stl_MapIterator = stl_MapBTCreator.find(xhToken); + if (stl_MapIterator != stl_MapBTCreator.end()) + { + stl_MapIterator->second.pStl_ListNode->clear(); + stl_MapIterator->second.pStl_ListSeeds->clear(); + stl_MapIterator->second.pStl_ListTracker->clear(); + + delete stl_MapIterator->second.pStl_ListNode; + delete stl_MapIterator->second.pStl_ListSeeds; + delete stl_MapIterator->second.pStl_ListTracker; + + stl_MapIterator->second.pStl_ListNode = NULL; + stl_MapIterator->second.pStl_ListSeeds = NULL; + stl_MapIterator->second.pStl_ListTracker = NULL; + + stl_MapBTCreator.erase(stl_MapIterator); + } + st_Locker.unlock(); + return true; +} \ No newline at end of file diff --git a/XEngine_Source/StorageModule_BTorrent/BTorrent_Creator/BTorrent_Creator.h b/XEngine_Source/StorageModule_BTorrent/BTorrent_Creator/BTorrent_Creator.h new file mode 100644 index 0000000..7a6c4ec --- /dev/null +++ b/XEngine_Source/StorageModule_BTorrent/BTorrent_Creator/BTorrent_Creator.h @@ -0,0 +1,44 @@ +#pragma once +/******************************************************************** +// Created: 2023/02/02 16:25:43 +// File Name: D:\XEngine\XEngine_SourceCode\XEngine_NetHelp\NetHelp_BTorrent\BTorrent_Creator\BTorrent_Creator.h +// File Path: D:\XEngine\XEngine_SourceCode\XEngine_NetHelp\NetHelp_BTorrent\BTorrent_Creator +// File Base: BTorrent_Creator +// File Ext: h +// Project: XEngine +// Author: qyt +// Purpose: BT创建器 +// History: +*********************************************************************/ +typedef struct +{ + XCHAR tszComment[4096]; + XCHAR tszPEMCert[4096]; + XCHAR tszBTPath[MAX_PATH]; + XCHAR tszCreate[MAX_PATH]; + int m_nPieceSize; + + list* pStl_ListNode; + list* pStl_ListTracker; + list* pStl_ListSeeds; +}BTORRENT_CREATORINFO; + +class CBTorrent_Creator +{ +public: + CBTorrent_Creator(); + ~CBTorrent_Creator(); +public: + bool BTorrent_Creator_Init(XNETHANDLE* pxhToken, LPCXSTR lpszBTPath, int nPieceSize = 0); + bool BTorrent_Creator_AddNode(XNETHANDLE xhToken, LPCXSTR lpszAddr, int nIndex); + bool BTorrent_Creator_AddTracker(XNETHANDLE xhToken, LPCXSTR lpszAddr, int nIndex = 0); + bool BTorrent_Creator_AddSeeds(XNETHANDLE xhToken, LPCXSTR lpszAddr, bool bSingle = false); + bool BTorrent_Creator_SetInfo(XNETHANDLE xhToken, LPCXSTR lpszCreator, LPCXSTR lpszComment = NULL, LPCXSTR lpszCertBuffer = NULL); + bool BTorrent_Creator_GetTorrent(XNETHANDLE xhToken, LPCXSTR lpszBTFile = NULL, XCHAR* ptszMsgBuffer = NULL, int* pInt_MsgLen = NULL); + bool BTorrent_Creator_Destory(XNETHANDLE xhToken); +protected: +private: + shared_mutex st_Locker; +private: + unordered_map stl_MapBTCreator; +}; \ No newline at end of file diff --git a/XEngine_Source/StorageModule_BTorrent/BTorrent_DLoader/BTorrent_DLoader.cpp b/XEngine_Source/StorageModule_BTorrent/BTorrent_DLoader/BTorrent_DLoader.cpp new file mode 100644 index 0000000..86f380e --- /dev/null +++ b/XEngine_Source/StorageModule_BTorrent/BTorrent_DLoader/BTorrent_DLoader.cpp @@ -0,0 +1,429 @@ +#include "pch.h" +#include "BTorrent_DLoader.h" +/******************************************************************** +// Created: 2023/02/02 16:26:33 +// File Name: D:\XEngine\XEngine_SourceCode\XEngine_NetHelp\NetHelp_BTorrent\BTorrent_DLoader\BTorrent_DLoader.cpp +// File Path: D:\XEngine\XEngine_SourceCode\XEngine_NetHelp\NetHelp_BTorrent\BTorrent_DLoader +// File Base: BTorrent_DLoader +// File Ext: cpp +// Project: XEngine +// Author: qyt +// Purpose: BT下载器 +// History: +*********************************************************************/ +CBTorrent_DLoader::CBTorrent_DLoader() +{ +} +CBTorrent_DLoader::~CBTorrent_DLoader() +{ +} +////////////////////////////////////////////////////////////////////////// +// 公有函数 +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +函数名称:BTorrent_DLoader_Create +函数功能:创建一个BT下载 + 参数.一:pxhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:导出一个下载句柄 + 参数.二:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:下载的地址,可以是本地种子文件路径或者磁力链接 + 参数.三:lpszSavePath + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:要保存的地址,这个地址是一个本地文件夹.而不是文件名. + 参数.四:lpszTempFile + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:断点续传临时文件路径 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_DLoader::BTorrent_DLoader_Create(XNETHANDLE* pxhToken, LPCXSTR lpszAddr, LPCXSTR lpszSavePath, LPCXSTR lpszTempFile /* = NULL */) +{ + BTDload_IsErrorOccur = false; + + if ((NULL == pxhToken) || (NULL == lpszAddr) || (NULL == lpszSavePath)) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_DLOAD_CREATE_PARAMENT; + return false; + } +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT + //申请空间 + BTORRENT_DLOADINFO* pSt_BTDLoader = new BTORRENT_DLOADINFO; + if (NULL == pSt_BTDLoader) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_DLOAD_CREATE_MALLOC; + return false; + } + //初始化要查询的事件 + pSt_BTDLoader->m_BTSetPack.set_int(lt::settings_pack::alert_mask, lt::alert_category::error | lt::alert_category::storage | lt::alert_category::status | lt::alert_category::port_mapping); + pSt_BTDLoader->m_BTSession = std::make_shared(pSt_BTDLoader->m_BTSetPack); + + lt::add_torrent_params m_TorrentParam; + //是磁力链接还是BT种子 + LPCXSTR lpszBTType = _X("magnet:?xt=urn:"); + if (NULL == _tcsxstr(lpszAddr, lpszBTType)) + { + pSt_BTDLoader->m_BTParam.ti = std::make_shared(std::string(lpszAddr)); + } + else + { + pSt_BTDLoader->m_BTParam = lt::parse_magnet_uri(lpszAddr); + } + //如果是续传,那么判断文件是否存在! + if (NULL != lpszTempFile) + { + pSt_BTDLoader->bIsResume = true; + std::ifstream m_IFStream(lpszTempFile, std::ios_base::binary); + m_IFStream.unsetf(std::ios_base::skipws); + + std::vector stl_VecFile; + stl_VecFile = { std::istream_iterator(m_IFStream), std::istream_iterator() }; + if (stl_VecFile.size() > 0) + { + m_TorrentParam = lt::read_resume_data(stl_VecFile); + if (m_TorrentParam.info_hashes == pSt_BTDLoader->m_BTParam.info_hashes) + { + pSt_BTDLoader->m_BTParam = std::move(m_TorrentParam); + } + } + } + pSt_BTDLoader->m_BTParam.save_path = lpszSavePath; + pSt_BTDLoader->m_BTSession->async_add_torrent(std::move(pSt_BTDLoader->m_BTParam)); + //设置选项 + pSt_BTDLoader->lPClass = this; + _tcsxcpy(pSt_BTDLoader->tszAddr, lpszAddr); + _tcsxcpy(pSt_BTDLoader->tszFile, lpszSavePath); + //生成句柄 + BaseLib_OperatorHandle_Create(pxhToken); + + st_Locker.lock(); + stl_MapDLoader.insert(make_pair(*pxhToken, pSt_BTDLoader)); + st_Locker.unlock(); +#endif + return true; +} +/******************************************************************** +函数名称:BTorrent_DLoader_Query +函数功能:查询下载状态 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:pppenEventList + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出事件列表 + 参数.三:pInt_ListCount + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出列表个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_DLoader::BTorrent_DLoader_Query(XNETHANDLE xhToken, ENUM_BTORRENT_EVENT_TYPE*** pppenEventList, int* pInt_ListCount) +{ + BTDload_IsErrorOccur = false; + + if ((NULL == pppenEventList) || (NULL == pInt_ListCount)) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_DLOAD_QUERY_PARAMENT; + return false; + } + st_Locker.lock_shared(); + unordered_map::const_iterator stl_MapIterator = stl_MapDLoader.find(xhToken); + if (stl_MapIterator == stl_MapDLoader.end()) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_DLOAD_QUERY_NOTFOUND; + st_Locker.unlock_shared(); + return false; + } +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT + //投教一个状态更新请求,才能触发信号 + stl_MapIterator->second->m_BTSession->post_torrent_updates(); + //得到信号 + std::vector stl_VectorAlerts; + stl_MapIterator->second->m_BTSession->pop_alerts(&stl_VectorAlerts); + if (stl_VectorAlerts.empty()) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_DLOAD_QUERY_NONE; + st_Locker.unlock_shared(); + return false; + } + *pInt_ListCount = stl_VectorAlerts.size(); + BaseLib_OperatorMemory_Malloc((XPPPMEM)pppenEventList, stl_VectorAlerts.size(), sizeof(ENUM_BTORRENT_EVENT_TYPE)); + //轮训元素 + int i = 0; + for (lt::alert const* stl_ListElement : stl_VectorAlerts) + { + //是否接受到完成的信号 + if (lt::alert_cast(stl_ListElement)) + { + *((*pppenEventList)[i]) = ENUM_BTORRENT_EVENT_TYPE_COMPLETE; + } + //是否接受到错误的信号 + if (lt::alert_cast(stl_ListElement)) + { + //std::cout << stl_ListElement->message() << std::endl; + *((*pppenEventList)[i]) = ENUM_BTORRENT_EVENT_TYPE_ERROR; + } + //接受到临时文件保存请求,需要保存他 + if (auto m_BTDLoader = lt::alert_cast(stl_ListElement)) + { + *((*pppenEventList)[i]) = ENUM_BTORRENT_EVENT_TYPE_WRITETMP; + std::ofstream m_OSFile(stl_MapIterator->second->tszTemp, std::ios_base::binary); + m_OSFile.unsetf(std::ios_base::skipws); + auto const m_BTData = write_resume_data_buf(m_BTDLoader->params); + m_OSFile.write(m_BTData.data(), int(m_BTData.size())); + } + //接受到数据写入错误 + if (lt::alert_cast(stl_ListElement)) + { + *((*pppenEventList)[i]) = ENUM_BTORRENT_EVENT_TYPE_DATAERROR; + } + //UPNP信息 + if (lt::alert_cast(stl_ListElement)) + { + //stl_ListElement->message().c_str(); + *((*pppenEventList)[i]) = ENUM_BTORRENT_EVENT_TYPE_UPNPERROR; + } + else if (lt::alert_cast(stl_ListElement)) + { + *((*pppenEventList)[i]) = ENUM_BTORRENT_EVENT_TYPE_UPNPCOMPLETE; + } + //下载状态通知 + if (auto stl_VectorUPDate = lt::alert_cast(stl_ListElement)) + { + if (stl_VectorUPDate->status.empty()) + { + continue; + } + *((*pppenEventList)[i]) = ENUM_BTORRENT_EVENT_TYPE_STATUS; + //更新通知,查询状态 + std::vector::const_iterator stl_VectorIterator = stl_VectorUPDate->status.begin(); + for (int i = 0; stl_VectorIterator != stl_VectorUPDate->status.end(); stl_VectorIterator++, i++) + { +#if _MSC_BUILD + int nUTFLen = stl_VectorIterator->name.length(); + BaseLib_OperatorCharset_UTFToAnsi(stl_VectorIterator->name.c_str(), stl_MapIterator->second->st_DLStatus.tszFileName, &nUTFLen); + stl_MapIterator->second->st_DLStatus.nDLoadTotal = stl_VectorIterator->total; +#else + _tcsxcpy(stl_MapIterator->second->st_DLStatus.tszFileName, stl_VectorIterator->name.c_str()); + stl_MapIterator->second->st_DLStatus.nDLoadTotal = stl_VectorIterator->total_wanted; +#endif + stl_MapIterator->second->st_DLStatus.nDLCount = stl_VectorIterator->total_done; + stl_MapIterator->second->st_DLStatus.nUPCount = stl_VectorIterator->total_upload; + stl_MapIterator->second->st_DLStatus.nDLStatus = stl_VectorIterator->state; + stl_MapIterator->second->st_DLStatus.nDLoadRate = stl_VectorIterator->download_payload_rate; + stl_MapIterator->second->st_DLStatus.nDLPeers = stl_VectorIterator->num_peers; + stl_MapIterator->second->st_DLStatus.nUPPeers = stl_VectorIterator->num_seeds; + stl_MapIterator->second->st_DLStatus.nDLoadProcess = stl_VectorIterator->progress_ppm / 10000; + } + } + i++; + } +#endif + st_Locker.unlock_shared(); + return true; +} +/******************************************************************** +函数名称:BTorrent_DLoader_GetStatus +函数功能:获取下载状态 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:pSt_DLStatus + In/Out:Out + 类型:数据结构指针 + 可空:N + 意思:输出查到的下载情况 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_DLoader::BTorrent_DLoader_GetStatus(XNETHANDLE xhToken, BTORRENT_DLOADER* pSt_DLStatus) +{ + BTDload_IsErrorOccur = false; + + if (NULL == pSt_DLStatus) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_DLOAD_GETSTATUS_PARAMENT; + return false; + } + st_Locker.lock_shared(); + unordered_map::const_iterator stl_MapIterator = stl_MapDLoader.find(xhToken); + if (stl_MapIterator == stl_MapDLoader.end()) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_DLOAD_GETSTATUS_NOTFOUND; + st_Locker.unlock_shared(); + return false; + } + *pSt_DLStatus = stl_MapIterator->second->st_DLStatus; + st_Locker.unlock_shared(); + + return true; +} +/******************************************************************** +函数名称:BTorrent_DLoader_SaveResume +函数功能:触发一次临时文件保存操作 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注:每调用一次,将会触发一次事件信号,通知系统保存一次临时文件 +*********************************************************************/ +bool CBTorrent_DLoader::BTorrent_DLoader_SaveResume(XNETHANDLE xhToken) +{ + BTDload_IsErrorOccur = false; + +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT + st_Locker.lock_shared(); + unordered_map::const_iterator stl_MapIterator = stl_MapDLoader.find(xhToken); + if (stl_MapIterator != stl_MapDLoader.end()) + { + std::vector stl_VectorAlerts; + stl_MapIterator->second->m_BTSession->pop_alerts(&stl_VectorAlerts); + //轮训元素 + for (lt::alert const* stl_ListElement : stl_VectorAlerts) + { + //获得元素内容 + auto stl_ListIterator = lt::alert_cast(stl_ListElement); + stl_ListIterator->handle.save_resume_data(lt::torrent_handle::save_info_dict); + } + } + st_Locker.unlock_shared(); +#endif + return true; +} +/******************************************************************** +函数名称:BTorrent_DLoader_Close +函数功能:关闭一个种子下载器 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_DLoader::BTorrent_DLoader_Close(XNETHANDLE xhToken) +{ + BTDload_IsErrorOccur = false; + +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT + st_Locker.lock(); + unordered_map::const_iterator stl_MapIterator = stl_MapDLoader.find(xhToken); + if (stl_MapIterator != stl_MapDLoader.end()) + { + stl_MapIterator->second->m_BTSession->abort(); + } + st_Locker.unlock(); +#endif + return true; +} +/******************************************************************** +函数名称:BTorrent_DLoader_SetPause +函数功能:设置暂停或者恢复 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的 + 参数.二:bPause + In/Out:In + 类型:逻辑型 + 可空:N + 意思:假为暂停,真为恢复下载 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_DLoader::BTorrent_DLoader_SetPause(XNETHANDLE xhToken, bool bPause) +{ + BTDload_IsErrorOccur = false; + +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT + st_Locker.lock_shared(); + unordered_map::const_iterator stl_MapIterator = stl_MapDLoader.find(xhToken); + if (stl_MapIterator != stl_MapDLoader.end()) + { + if (bPause) + { + stl_MapIterator->second->m_BTSession->pause(); + } + else + { + stl_MapIterator->second->m_BTSession->resume(); + } + } + st_Locker.unlock_shared(); +#endif + return true; +} +/******************************************************************** +函数名称:BTorrent_DLoader_UPNPEnable +函数功能:启用或者关闭UPNP + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的 + 参数.二:bEnable + In/Out:In + 类型:逻辑型 + 可空:N + 意思:输入启用还是关闭UPNP +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_DLoader::BTorrent_DLoader_UPNPEnable(XNETHANDLE xhToken, bool bEnable /* = false */) +{ + BTDload_IsErrorOccur = false; + +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT + st_Locker.lock_shared(); + unordered_map::const_iterator stl_MapIterator = stl_MapDLoader.find(xhToken); + if (stl_MapIterator != stl_MapDLoader.end()) + { + stl_MapIterator->second->m_BTSetPack.set_bool(lt::settings_pack::enable_upnp, bEnable); + stl_MapIterator->second->m_BTSetPack.set_bool(lt::settings_pack::enable_natpmp, bEnable); + stl_MapIterator->second->m_BTSession->apply_settings(stl_MapIterator->second->m_BTSetPack); + } + st_Locker.unlock_shared(); +#endif + return true; +} \ No newline at end of file diff --git a/XEngine_Source/StorageModule_BTorrent/BTorrent_DLoader/BTorrent_DLoader.h b/XEngine_Source/StorageModule_BTorrent/BTorrent_DLoader/BTorrent_DLoader.h new file mode 100644 index 0000000..17d742c --- /dev/null +++ b/XEngine_Source/StorageModule_BTorrent/BTorrent_DLoader/BTorrent_DLoader.h @@ -0,0 +1,47 @@ +#pragma once +/******************************************************************** +// Created: 2023/02/02 16:25:51 +// File Name: D:\XEngine\XEngine_SourceCode\XEngine_NetHelp\NetHelp_BTorrent\BTorrent_DLoader\BTorrent_DLoader.h +// File Path: D:\XEngine\XEngine_SourceCode\XEngine_NetHelp\NetHelp_BTorrent\BTorrent_DLoader +// File Base: BTorrent_DLoader +// File Ext: h +// Project: XEngine +// Author: qyt +// Purpose: BT下载器 +// History: +*********************************************************************/ +typedef struct +{ +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT + lt::settings_pack m_BTSetPack; + lt::add_torrent_params m_BTParam; + std::shared_ptr m_BTSession; +#endif + BTORRENT_DLOADER st_DLStatus; //下载状态 + + XCHAR tszAddr[MAX_PATH]; //下载地址 + XCHAR tszFile[MAX_PATH]; //保存地址 + XCHAR tszTemp[MAX_PATH]; //临时文件 + bool bIsResume; //是否续传 + XPVOID lPClass; //指向类的指针 +}BTORRENT_DLOADINFO, * LPBTORRENT_DLOADINFO; +////////////////////////////////////////////////////////////////////////// +class CBTorrent_DLoader +{ +public: + CBTorrent_DLoader(); + ~CBTorrent_DLoader(); +public: + bool BTorrent_DLoader_Create(XNETHANDLE* pxhToken, LPCXSTR lpszAddr, LPCXSTR lpszSavePath, LPCXSTR lpszTempFile = NULL); + bool BTorrent_DLoader_Query(XNETHANDLE xhToken, ENUM_BTORRENT_EVENT_TYPE*** pppenEventList, int* pInt_ListCount); + bool BTorrent_DLoader_GetStatus(XNETHANDLE xhToken, BTORRENT_DLOADER* pSt_DLStatus); + bool BTorrent_DLoader_SaveResume(XNETHANDLE xhToken); + bool BTorrent_DLoader_Close(XNETHANDLE xhToken); +public: + bool BTorrent_DLoader_SetPause(XNETHANDLE xhToken, bool bPause); + bool BTorrent_DLoader_UPNPEnable(XNETHANDLE xhToken, bool bEnable = false); +private: + shared_mutex st_Locker; +private: + unordered_map stl_MapDLoader; +}; diff --git a/XEngine_Source/StorageModule_BTorrent/BTorrent_Define.h b/XEngine_Source/StorageModule_BTorrent/BTorrent_Define.h new file mode 100644 index 0000000..8a128bb --- /dev/null +++ b/XEngine_Source/StorageModule_BTorrent/BTorrent_Define.h @@ -0,0 +1,594 @@ +#pragma once +/******************************************************************** +// Created: 2024/03/13 14:35:22 +// File Name: D:\XEngine_Storage\XEngine_Source\StorageModule_BTorrent\BTorrent_Define.h +// File Path: D:\XEngine_Storage\XEngine_Source\StorageModule_BTorrent +// File Base: BTorrent_Define +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: BT下载导出 +// History: +*********************************************************************/ +////////////////////////////////////////////////////////////////////////// +// 导出枚举型 +////////////////////////////////////////////////////////////////////////// +typedef enum +{ + ENUM_BTORRENT_EVENT_TYPE_OTHER = 0, //其他 + ENUM_BTORRENT_EVENT_TYPE_COMPLETE = 1, //下载完成 + ENUM_BTORRENT_EVENT_TYPE_ERROR = 2, //下载错误 + ENUM_BTORRENT_EVENT_TYPE_DATAERROR = 3, //数据写入错误 + ENUM_BTORRENT_EVENT_TYPE_WRITETMP = 4, //正在写入临时文件 + ENUM_BTORRENT_EVENT_TYPE_UPNPERROR = 5, //UPNP错误信息通知 + ENUM_BTORRENT_EVENT_TYPE_UPNPCOMPLETE = 6, //UPNP端口映射完成通知 + ENUM_BTORRENT_EVENT_TYPE_STATUS = 10 //下载状态 +}ENUM_BTORRENT_EVENT_TYPE; +typedef enum +{ + ENUM_BTORRENT_DOWNLOAD_STATUS_OTHER = 0, //内部状态 + ENUM_BTORRENT_DOWNLOAD_STATUS_CHECKFILE = 1, //检查文件状态中 + ENUM_BTORRENT_DOWNLOAD_STATUS_DLMETADATA = 2, //从节点下载媒体数据中 + ENUM_BTORRENT_DOWNLOAD_STATUS_LOADING = 3, //下载中... + ENUM_BTORRENT_DOWNLOAD_STATUS_FINISH = 4, //下载完成 + ENUM_BTORRENT_DOWNLOAD_STATUS_SEEDING = 5, //做种中,下载以完成. + ENUM_BTORRENT_DOWNLOAD_STATUS_CHECKRESUME = 7 //正在进行断点续传文件检查 +}ENUM_BTORRENT_DOWNLOAD_STATUS; +////////////////////////////////////////////////////////////////////////// +// 导出数据结构 +////////////////////////////////////////////////////////////////////////// +typedef struct +{ + XCHAR tszFileName[MAX_PATH]; //文件名 + __int64x nDLoadTotal; //总大小 + __int64x nDLCount; //已下载大小 + __int64x nUPCount; //已上传大小 + int nDLStatus; //状态 = ENUM_BTORRENT_DOWNLOAD_STATUS + int nDLoadRate; //下载平均速度,字节 + int nDLoadProcess; //下载进度. % + int nDLPeers; //连接的下载节点个数 + int nUPPeers; //上传的节点个数 +}BTORRENT_DLOADER; +typedef struct +{ + XCHAR tszValue[MAX_PATH]; + int nValue; +}BTORRENT_PARSEMAP; +typedef struct +{ + XCHAR tszFileHash[MAX_PATH]; //文件HASH + XCHAR tszFilePath[MAX_PATH]; //文件路径 + XCHAR tszFileName[MAX_PATH]; //文件名称 + XCHAR tszFileLink[MAX_PATH]; //文件连接,如果有的话 + __int64x nFileOffset; //文件偏移 + __int64x nFileSize; //文件大小 + time_t nFileTime; //文件时间戳 + int nFileStart; //块索引范围 + int nFileEnd; //块索引范围 + XSHOT wFileAttr; //文件属性 +}BTORRENT_FILEINFO; +////////////////////////////////////////////////////////////////////////// +// 导出函数 +////////////////////////////////////////////////////////////////////////// +extern "C" XLONG BTorrent_GetLastError(int *pInt_SysError = NULL); +/************************************************************************/ +/* BT下载器导出函数 */ +/************************************************************************/ +/******************************************************************** +函数名称:BTorrent_DLoader_Create +函数功能:创建一个BT下载 + 参数.一:pxhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:导出一个下载句柄 + 参数.二:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:下载的地址,可以是本地种子文件路径或者磁力链接 + 参数.三:lpszSavePath + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:要保存的地址,这个地址是一个本地文件夹.而不是文件名. + 参数.四:lpszTempFile + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:断点续传临时文件路径 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_DLoader_Create(XNETHANDLE* pxhToken, LPCXSTR lpszAddr, LPCXSTR lpszSavePath, LPCXSTR lpszTempFile = NULL); +/******************************************************************** +函数名称:BTorrent_DLoader_Query +函数功能:查询下载状态 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:pppenEventList + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出事件列表 + 参数.三:pInt_ListCount + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出列表个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_DLoader_Query(XNETHANDLE xhToken, ENUM_BTORRENT_EVENT_TYPE*** pppenEventList, int* pInt_ListCount); +/******************************************************************** +函数名称:BTorrent_DLoader_GetStatus +函数功能:获取下载状态 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:pSt_DLStatus + In/Out:Out + 类型:数据结构指针 + 可空:N + 意思:输出查到的下载情况 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_DLoader_GetStatus(XNETHANDLE xhToken, BTORRENT_DLOADER * pSt_DLStatus); +/******************************************************************** +函数名称:BTorrent_DLoader_SaveResume +函数功能:触发一次临时文件保存操作 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注:每调用一次,将会触发一次事件信号,通知系统保存一次临时文件 +*********************************************************************/ +extern "C" bool BTorrent_DLoader_SaveResume(XNETHANDLE xhToken); +/******************************************************************** +函数名称:BTorrent_DLoader_Close +函数功能:关闭一个种子下载器 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_DLoader_Close(XNETHANDLE xhToken); +/******************************************************************** +函数名称:BTorrent_DLoader_SetPause +函数功能:设置暂停或者恢复 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的 + 参数.二:bPause + In/Out:In + 类型:逻辑型 + 可空:N + 意思:假为暂停,真为恢复下载 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_DLoader_SetPause(XNETHANDLE xhToken, bool bPause); +/******************************************************************** +函数名称:BTorrent_DLoader_UPNPEnable +函数功能:启用或者关闭UPNP + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的 + 参数.二:bEnable + In/Out:In + 类型:逻辑型 + 可空:N + 意思:输入启用还是关闭UPNP +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_DLoader_UPNPEnable(XNETHANDLE xhToken, bool bEnable = false); +/************************************************************************/ +/* BT解析器导出函数 */ +/************************************************************************/ +/******************************************************************** +函数名称:BTorrent_Parse_Init +函数功能:初始化一个解析器 + 参数.一:pxhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:导出一个下载句柄 + 参数.二:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:种子地址,可以是本地种子文件路径或者磁力链接 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_Parse_Init(XNETHANDLE* pxhToken, LPCXSTR lpszAddr); +/******************************************************************** +函数名称:BTorrent_Parse_GetNode +函数功能:获取节点信息 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:pppSt_Parse + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出解析到的节点列表,此参数需要BaseLib_OperatorMemory_Free释放内存 + 参数.三:pInt_ListCount + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出列表个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_Parse_GetNode(XNETHANDLE xhToken, BTORRENT_PARSEMAP*** pppSt_Parse, int* pInt_ListCount); +/******************************************************************** +函数名称:BTorrent_Parse_GetTracker +函数功能:获取TRACKER服务器列表 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:pppSt_Parse + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出解析到的列表,此参数需要BaseLib_OperatorMemory_Free释放内存 + 参数.三:pInt_ListCount + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出列表个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_Parse_GetTracker(XNETHANDLE xhToken, BTORRENT_PARSEMAP*** pppSt_Parse, int* pInt_ListCount); +/******************************************************************** +函数名称:BTorrent_Parse_GetSeeds +函数功能:获取种子列表 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:pppSt_Parse + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出解析到的列表,此参数需要BaseLib_OperatorMemory_Free释放内存 + 参数.三:pInt_ListCount + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出列表个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_Parse_GetSeeds(XNETHANDLE xhToken, BTORRENT_PARSEMAP*** pppSt_Parse, int* pInt_ListCount); +/******************************************************************** +函数名称:BTorrent_Parse_GetPiece +函数功能:获取块信息 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:pInt_PieceLen + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出块大小 + 参数.三:pInt_PieceCount + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出块个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_Parse_GetPiece(XNETHANDLE xhToken, int* pInt_PieceLen, int* pInt_PieceCount); +/******************************************************************** +函数名称:BTorrent_Parse_GetInfo +函数功能:获取块信息 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:ptszHash + In/Out:Out + 类型:字符指针 + 可空:Y + 意思:输出HASH值 + 参数.三:ptszCreator + In/Out:Out + 类型:字符指针 + 可空:Y + 意思:输出创建者 + 参数.四:ptszComment + In/Out:Out + 类型:字符指针 + 可空:Y + 意思:输出种子的注释信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_Parse_GetInfo(XNETHANDLE xhToken, XCHAR* ptszHash = NULL, XCHAR* ptszCreator = NULL, XCHAR* ptszComment = NULL); +/******************************************************************** +函数名称:BTorrent_Parse_GetMagnet +函数功能:获取种子文件的磁力链接 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:ptszMagnet + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出种子文件的磁力链接 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_Parse_GetMagnet(XNETHANDLE xhToken, XCHAR* ptszMagnet); +/******************************************************************** +函数名称:BTorrent_Parse_GetFile +函数功能:获取文件信息 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:ptszFilePath + In/Out:Out + 类型:字符指针 + 可空:N + 意思:获得保存文件路径 + 参数.三:pppSt_FileList + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出文件列表 + 参数.四:pInt_ListCount + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:获取列表个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_Parse_GetFile(XNETHANDLE xhToken, XCHAR* pszFilePath, BTORRENT_FILEINFO*** pppSt_FileList, int* pInt_ListCount); +/******************************************************************** +函数名称:BTorrent_Parse_Destory +函数功能:销毁种子解析器 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_Parse_Destory(XNETHANDLE xhToken); +/************************************************************************/ +/* BT种子制作导出函数 */ +/************************************************************************/ +/******************************************************************** +函数名称:BTorrent_Creator_Init +函数功能:初始化一个制作工具 + 参数.一:pxhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:导出一个句柄 + 参数.二:lpszBTPath + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:要制作的文件地址路径 + 参数.三:nPieceSize + In/Out:In + 类型:整数型 + 可空:N + 意思:块大小,默认16K +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_Creator_Init(XNETHANDLE* pxhToken, LPCXSTR lpszBTPath, int nPieceSize = 0); +/******************************************************************** +函数名称:BTorrent_Creator_AddNode +函数功能:添加种子DHT节点地址 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入节点地址 + 参数.三:nIndex + In/Out:In + 类型:整数型 + 可空:N + 意思:当前索引 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_Creator_AddNode(XNETHANDLE xhToken, LPCXSTR lpszAddr, int nIndex); +/******************************************************************** +函数名称:BTorrent_Creator_AddTracker +函数功能:设置TRACKER服务器地址 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入地址 + 参数.三:nIndex + In/Out:In + 类型:整数型 + 可空:Y + 意思:输入服务器索引 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_Creator_AddTracker(XNETHANDLE xhToken, LPCXSTR lpszAddr, int nIndex = 0); +/******************************************************************** +函数名称:BTorrent_Creator_AddSeeds +函数功能:添加URL种子到制作器 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入地址 + 参数.三:bSingle + In/Out:In + 类型:逻辑型 + 可空:N + 意思:多种子文件还是单种子文件 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_Creator_AddSeeds(XNETHANDLE xhToken, LPCXSTR lpszAddr, bool bSingle = false); +/******************************************************************** +函数名称:BTorrent_Creator_SetInfo +函数功能:设置种子信息 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:lpszCreator + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入制作器名称 + 参数.三:lpszComment + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入附加信息 + 参数.四:lpszCertBuffer + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入PEM证书缓冲区 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_Creator_SetInfo(XNETHANDLE xhToken, LPCXSTR lpszCreator, LPCXSTR lpszComment = NULL, LPCXSTR lpszCertBuffer = NULL); +/******************************************************************** +函数名称:BTorrent_Creator_GetTorrent +函数功能:获取中心信息 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:lpszBTFile + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输出种子文件地址 + 参数.三:ptszMsgBuffer + In/Out:Out + 类型:字符指针 + 可空:Y + 意思:输出种子信息到内存 + 参数.四:pInt_MsgLen + In/Out:Out + 类型:整数型指针 + 可空:Y + 意思:输出内存大小 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_Creator_GetTorrent(XNETHANDLE xhToken, LPCXSTR lpszBTFile = NULL, XCHAR * ptszMsgBuffer = NULL, int* pInt_MsgLen = NULL); +/******************************************************************** +函数名称:BTorrent_Creator_Destory +函数功能:销毁 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool BTorrent_Creator_Destory(XNETHANDLE xhToken); \ No newline at end of file diff --git a/XEngine_Source/StorageModule_BTorrent/BTorrent_Error.h b/XEngine_Source/StorageModule_BTorrent/BTorrent_Error.h new file mode 100644 index 0000000..73bcc22 --- /dev/null +++ b/XEngine_Source/StorageModule_BTorrent/BTorrent_Error.h @@ -0,0 +1,53 @@ +#pragma once +/******************************************************************** +// Created: 2023/02/02 16:32:18 +// File Name: D:\XEngine\XEngine_SourceCode\XEngine_NetHelp\NetHelp_BTorrent\BTorrent_Error.h +// File Path: D:\XEngine\XEngine_SourceCode\XEngine_NetHelp\NetHelp_BTorrent +// File Base: BTorrent_Error +// File Ext: h +// Project: XEngine +// Author: qyt +// Purpose: BT下载错误导出 +// History: +*********************************************************************/ +////////////////////////////////////////////////////////////////////////// +// BT下载器错误 +////////////////////////////////////////////////////////////////////////// +#define ERROR_STORAGE_MODULE_BTORRENT_DLOAD_CREATE_PARAMENT 0x0060001 //创建下载参数错误 +#define ERROR_STORAGE_MODULE_BTORRENT_DLOAD_CREATE_MALLOC 0x0060002 //创建内存失败 +#define ERROR_STORAGE_MODULE_BTORRENT_DLOAD_UPEVENT_NOTFOUND 0x0060010 //没有找到 +#define ERROR_STORAGE_MODULE_BTORRENT_DLOAD_QUERY_PARAMENT 0x0060020 //参数错误 +#define ERROR_STORAGE_MODULE_BTORRENT_DLOAD_QUERY_NOTFOUND 0x0060021 //没有找到句柄 +#define ERROR_STORAGE_MODULE_BTORRENT_DLOAD_QUERY_NONE 0x0060022 //没有事件 +#define ERROR_STORAGE_MODULE_BTORRENT_DLOAD_GETSTATUS_PARAMENT 0x0060030 //参数错误 +#define ERROR_STORAGE_MODULE_BTORRENT_DLOAD_GETSTATUS_NOTFOUND 0x0060031 //没有找到 +////////////////////////////////////////////////////////////////////////// +// BT解析器错误 +////////////////////////////////////////////////////////////////////////// +#define ERROR_STORAGE_MODULE_BTORRENT_PARSE_INIT_PARAMENT 0x0061001 //参数错误 +#define ERROR_STORAGE_MODULE_BTORRENT_PARSE_INIT_MALLOC 0x0061002 //申请内存失败 +#define ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETNODE_PARAMENT 0x0061010 //参数错误 +#define ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETNODE_NOTFOUND 0x0061011 //没有找到 +#define ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETTRACKER_PARAMENT 0x0061020 +#define ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETTRACKER_NOTFOUND 0x0061021 +#define ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETSEED_PARAMENT 0x0061030 +#define ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETSEED_NOTFOUND 0x0061031 +#define ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETFILE_PARAMENT 0x0061040 +#define ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETFILE_NOTFOUND 0x0061041 +////////////////////////////////////////////////////////////////////////// +// BT解析器错误 +////////////////////////////////////////////////////////////////////////// +#define ERROR_STORAGE_MODULE_BTORRENT_CREATOR_INIT_PARAMENT 0x0062001 //参数错误,初始化失败 +#define ERROR_STORAGE_MODULE_BTORRENT_CREATOR_INIT_MALLOC 0x0062002 //申请内存失败 +#define ERROR_STORAGE_MODULE_BTORRENT_CREATOR_NODE_PARAMENT 0x0062010 //参数错误 +#define ERROR_STORAGE_MODULE_BTORRENT_CREATOR_NODE_NOTFOUND 0x0062011 //没有找到指定句柄 +#define ERROR_STORAGE_MODULE_BTORRENT_CREATOR_TRACKER_PARAMENT 0x0062020 +#define ERROR_STORAGE_MODULE_BTORRENT_CREATOR_TRACKER_NOTFOUND 0x0062021 +#define ERROR_STORAGE_MODULE_BTORRENT_CREATOR_SEEDS_PARAMENT 0x0062030 +#define ERROR_STORAGE_MODULE_BTORRENT_CREATOR_SEEDS_NOTFOUND 0x0062031 +#define ERROR_STORAGE_MODULE_BTORRENT_CREATOR_INFO_PARAMENT 0x0062040 +#define ERROR_STORAGE_MODULE_BTORRENT_CREATOR_INFO_NOTFOUND 0x0062041 +#define ERROR_STORAGE_MODULE_BTORRENT_CREATOR_FILE_PARAMENT 0x0062050 +#define ERROR_STORAGE_MODULE_BTORRENT_CREATOR_FILE_NOTFOUND 0x0062051 +#define ERROR_STORAGE_MODULE_BTORRENT_CREATOR_FILE_FAILED 0x0062052 +#define ERROR_STORAGE_MODULE_BTORRENT_CREATOR_FILE_PARSE 0x0062003 //解析文件失败,无法继续 \ No newline at end of file diff --git a/XEngine_Source/StorageModule_BTorrent/BTorrent_Parse/BTorrent_Parse.cpp b/XEngine_Source/StorageModule_BTorrent/BTorrent_Parse/BTorrent_Parse.cpp new file mode 100644 index 0000000..bda5cc9 --- /dev/null +++ b/XEngine_Source/StorageModule_BTorrent/BTorrent_Parse/BTorrent_Parse.cpp @@ -0,0 +1,542 @@ +#include "pch.h" +#include "BTorrent_Parse.h" +/******************************************************************** +// Created: 2023/02/02 16:26:41 +// File Name: D:\XEngine\XEngine_SourceCode\XEngine_NetHelp\NetHelp_BTorrent\BTorrent_Parse\BTorrent_Parse.cpp +// File Path: D:\XEngine\XEngine_SourceCode\XEngine_NetHelp\NetHelp_BTorrent\BTorrent_Parse +// File Base: BTorrent_Parse +// File Ext: cpp +// Project: XEngine +// Author: qyt +// Purpose: 种子解析工具 +// History: +*********************************************************************/ +CBTorrent_Parse::CBTorrent_Parse() +{ +} +CBTorrent_Parse::~CBTorrent_Parse() +{ +} +////////////////////////////////////////////////////////////////////////// +// 公有函数 +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +函数名称:BTorrent_Parse_Init +函数功能:初始化一个解析器 + 参数.一:pxhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:导出一个下载句柄 + 参数.二:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:种子地址,可以是本地种子文件路径或者磁力链接 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_Parse::BTorrent_Parse_Init(XNETHANDLE* pxhToken, LPCXSTR lpszAddr) +{ + BTDload_IsErrorOccur = false; + + if ((NULL == pxhToken) || (NULL == lpszAddr)) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_PARSE_INIT_PARAMENT; + return false; + } +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT + //申请空间 + BTORRENT_PARSEINFO* pSt_BTParse = new BTORRENT_PARSEINFO; + if (NULL == pSt_BTParse) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_PARSE_INIT_MALLOC; + return false; + } + memset(pSt_BTParse,'\0',sizeof(BTORRENT_PARSEINFO)); + + LPCXSTR lpszFindStr = _X("magnet:?xt=urn:"); + if (NULL == _tcsxstr(lpszAddr, lpszFindStr)) + { + std::fstream m_FStream; + m_FStream.exceptions(std::ifstream::failbit); + m_FStream.open(lpszAddr, std::ios_base::in | std::ios_base::binary); + if (!m_FStream) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_PARSE_INIT_MALLOC; + delete pSt_BTParse; + pSt_BTParse = NULL; + return false; + } + m_FStream.seekg(0, std::ios_base::end); + size_t nSize = size_t(m_FStream.tellg()); + m_FStream.seekg(0, std::ios_base::beg); + std::vector stl_ListBuffer(nSize); + m_FStream.read(stl_ListBuffer.data(), nSize); + + int nPos = -1; + lt::error_code m_BTError; + lt::load_torrent_limits st_BTLimits; + pSt_BTParse->m_BTBNode = lt::bdecode(stl_ListBuffer, m_BTError, &nPos, st_BTLimits.max_decode_depth, st_BTLimits.max_decode_tokens); + pSt_BTParse->m_BTInfo = std::make_shared(std::move(pSt_BTParse->m_BTBNode), st_BTLimits); + } + else + { + //如果是磁力 + } + + BaseLib_OperatorHandle_Create(pxhToken); + st_Locker.lock(); + stl_MapBTParse.insert(make_pair(*pxhToken, pSt_BTParse)); + st_Locker.unlock(); +#endif + return true; +} +/******************************************************************** +函数名称:BTorrent_Parse_GetNode +函数功能:获取节点信息 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:pppSt_Parse + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出解析到的节点列表,此参数需要BaseLib_OperatorMemory_Free释放内存 + 参数.三:pInt_ListCount + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出列表个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_Parse::BTorrent_Parse_GetNode(XNETHANDLE xhToken, BTORRENT_PARSEMAP*** pppSt_Parse, int* pInt_ListCount) +{ + BTDload_IsErrorOccur = false; + + if ((NULL == pppSt_Parse) || (NULL == pInt_ListCount)) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETNODE_PARAMENT; + return false; + } + st_Locker.lock_shared(); + unordered_map::const_iterator stl_MapIterator = stl_MapBTParse.find(xhToken); + if (stl_MapIterator == stl_MapBTParse.end()) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETNODE_NOTFOUND; + st_Locker.unlock_shared(); + return false; + } +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT + *pInt_ListCount = stl_MapIterator->second->m_BTInfo->nodes().size(); + BaseLib_OperatorMemory_Malloc((XPPPMEM)pppSt_Parse, stl_MapIterator->second->m_BTInfo->nodes().size(), sizeof(BTORRENT_PARSEMAP)); + std::vector>::const_iterator stl_ListIterator = stl_MapIterator->second->m_BTInfo->nodes().begin(); + for (int i = 0; stl_ListIterator != stl_MapIterator->second->m_BTInfo->nodes().end(); stl_ListIterator++, i++) + { + (*pppSt_Parse)[i]->nValue = stl_ListIterator->second; + _tcsxcpy((*pppSt_Parse)[i]->tszValue, stl_ListIterator->first.c_str()); + } +#endif + st_Locker.unlock_shared(); + return true; +} +/******************************************************************** +函数名称:BTorrent_Parse_GetTracker +函数功能:获取TRACKER服务器列表 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:pppSt_Parse + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出解析到的列表,此参数需要BaseLib_OperatorMemory_Free释放内存 + 参数.三:pInt_ListCount + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出列表个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_Parse::BTorrent_Parse_GetTracker(XNETHANDLE xhToken, BTORRENT_PARSEMAP*** pppSt_Parse, int* pInt_ListCount) +{ + BTDload_IsErrorOccur = false; + + if ((NULL == pppSt_Parse) || (NULL == pInt_ListCount)) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETTRACKER_PARAMENT; + return false; + } + st_Locker.lock_shared(); + unordered_map::const_iterator stl_MapIterator = stl_MapBTParse.find(xhToken); + if (stl_MapIterator == stl_MapBTParse.end()) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETTRACKER_NOTFOUND; + st_Locker.unlock_shared(); + return false; + } +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT + int i = 0; + *pInt_ListCount = stl_MapIterator->second->m_BTInfo->trackers().size(); + BaseLib_OperatorMemory_Malloc((XPPPMEM)pppSt_Parse, stl_MapIterator->second->m_BTInfo->trackers().size(), sizeof(BTORRENT_PARSEMAP)); + + for (auto const& stl_ListIterator : stl_MapIterator->second->m_BTInfo->trackers()) + { + (*pppSt_Parse)[i]->nValue = stl_ListIterator.tier; + _tcsxcpy((*pppSt_Parse)[i]->tszValue, stl_ListIterator.url.c_str()); + i++; + } +#endif + st_Locker.unlock_shared(); + return true; +} +/******************************************************************** +函数名称:BTorrent_Parse_GetSeeds +函数功能:获取种子列表 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:pppSt_Parse + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出解析到的列表,此参数需要BaseLib_OperatorMemory_Free释放内存 + 参数.三:pInt_ListCount + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出列表个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_Parse::BTorrent_Parse_GetSeeds(XNETHANDLE xhToken, BTORRENT_PARSEMAP*** pppSt_Parse, int* pInt_ListCount) +{ + BTDload_IsErrorOccur = false; + + if ((NULL == pppSt_Parse) || (NULL == pInt_ListCount)) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETSEED_PARAMENT; + return false; + } + st_Locker.lock_shared(); + unordered_map::const_iterator stl_MapIterator = stl_MapBTParse.find(xhToken); + if (stl_MapIterator == stl_MapBTParse.end()) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETSEED_NOTFOUND; + st_Locker.unlock_shared(); + return false; + } +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT + int i = 0; + *pInt_ListCount = stl_MapIterator->second->m_BTInfo->web_seeds().size(); + BaseLib_OperatorMemory_Malloc((XPPPMEM)pppSt_Parse, stl_MapIterator->second->m_BTInfo->web_seeds().size(), sizeof(BTORRENT_PARSEMAP)); + + for (auto const& stl_ListIterator : stl_MapIterator->second->m_BTInfo->web_seeds()) + { + (*pppSt_Parse)[i]->nValue = stl_ListIterator.type; + _tcsxcpy((*pppSt_Parse)[i]->tszValue, stl_ListIterator.url.c_str()); + i++; + } +#endif + st_Locker.unlock_shared(); + return true; +} +/******************************************************************** +函数名称:BTorrent_Parse_GetPiece +函数功能:获取块信息 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:pInt_PieceLen + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出块大小 + 参数.三:pInt_PieceCount + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出块个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_Parse::BTorrent_Parse_GetPiece(XNETHANDLE xhToken, int* pInt_PieceLen, int* pInt_PieceCount) +{ + BTDload_IsErrorOccur = false; + + if ((NULL == pInt_PieceLen) || (NULL == pInt_PieceCount)) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETSEED_PARAMENT; + return false; + } + st_Locker.lock_shared(); + unordered_map::const_iterator stl_MapIterator = stl_MapBTParse.find(xhToken); + if (stl_MapIterator == stl_MapBTParse.end()) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETSEED_PARAMENT; + st_Locker.unlock_shared(); + return false; + } +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT + *pInt_PieceLen = stl_MapIterator->second->m_BTInfo->piece_length(); + *pInt_PieceCount = stl_MapIterator->second->m_BTInfo->num_pieces(); +#endif + st_Locker.unlock_shared(); + return true; +} +/******************************************************************** +函数名称:BTorrent_Parse_GetInfo +函数功能:获取块信息 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:ptszHash + In/Out:Out + 类型:字符指针 + 可空:Y + 意思:输出HASH值 + 参数.三:ptszCreator + In/Out:Out + 类型:字符指针 + 可空:Y + 意思:输出创建者 + 参数.四:ptszComment + In/Out:Out + 类型:字符指针 + 可空:Y + 意思:输出种子的注释信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_Parse::BTorrent_Parse_GetInfo(XNETHANDLE xhToken, XCHAR* ptszHash /* = NULL */, XCHAR* ptszCreator /* = NULL */, XCHAR* ptszComment /* = NULL */) +{ + BTDload_IsErrorOccur = false; + +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT + st_Locker.lock_shared(); + unordered_map::const_iterator stl_MapIterator = stl_MapBTParse.find(xhToken); + if (stl_MapIterator != stl_MapBTParse.end()) + { + if (NULL != ptszHash) + { + _tcsxcpy(ptszHash, stl_MapIterator->second->m_BTInfo->info_hash().to_string().c_str()); + } + if (NULL != ptszCreator) + { + _tcsxcpy(ptszCreator, stl_MapIterator->second->m_BTInfo->creator().c_str()); + } + if (NULL != ptszComment) + { + _tcsxcpy(ptszComment, stl_MapIterator->second->m_BTInfo->comment().c_str()); + } + } + st_Locker.unlock_shared(); +#endif + return true; +} +/******************************************************************** +函数名称:BTorrent_Parse_GetMagnet +函数功能:获取种子文件的磁力链接 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:ptszMagnet + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出种子文件的磁力链接 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_Parse::BTorrent_Parse_GetMagnet(XNETHANDLE xhToken, XCHAR* ptszMagnet) +{ + BTDload_IsErrorOccur = false; + +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT + st_Locker.lock_shared(); + unordered_map::const_iterator stl_MapIterator = stl_MapBTParse.find(xhToken); + if (stl_MapIterator != stl_MapBTParse.end()) + { + _tcsxcpy(ptszMagnet, make_magnet_uri(*stl_MapIterator->second->m_BTInfo).c_str()); + } + st_Locker.unlock_shared(); +#endif + return true; +} +/******************************************************************** +函数名称:BTorrent_Parse_GetFile +函数功能:获取文件信息 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 + 参数.二:ptszFilePath + In/Out:Out + 类型:字符指针 + 可空:N + 意思:获得保存文件路径 + 参数.三:pppSt_FileList + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出文件列表 + 参数.四:pInt_ListCount + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:获取列表个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_Parse::BTorrent_Parse_GetFile(XNETHANDLE xhToken, XCHAR* ptszFilePath, BTORRENT_FILEINFO*** pppSt_FileList, int* pInt_ListCount) +{ + BTDload_IsErrorOccur = false; + + if ((NULL == ptszFilePath) || (NULL == pppSt_FileList) || (NULL == pInt_ListCount)) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETFILE_PARAMENT; + return false; + } + st_Locker.lock_shared(); + unordered_map::const_iterator stl_MapIterator = stl_MapBTParse.find(xhToken); + if (stl_MapIterator == stl_MapBTParse.end()) + { + BTDload_IsErrorOccur = true; + BTDload_dwErrorCode = ERROR_STORAGE_MODULE_BTORRENT_PARSE_GETFILE_NOTFOUND; + st_Locker.unlock_shared(); + return false; + } +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT + int nUTFLen = stl_MapIterator->second->m_BTInfo->name().length(); + BaseLib_OperatorCharset_UTFToAnsi(stl_MapIterator->second->m_BTInfo->name().c_str(), ptszFilePath, &nUTFLen); + + *pInt_ListCount = stl_MapIterator->second->m_BTInfo->num_files(); + BaseLib_OperatorMemory_Malloc((XPPPMEM)pppSt_FileList, stl_MapIterator->second->m_BTInfo->num_files(), sizeof(BTORRENT_FILEINFO)); + + lt::file_storage const& m_FileStorage = stl_MapIterator->second->m_BTInfo->files(); + int i = 0; + for (auto const stl_ListIterator : m_FileStorage.file_range()) + { + auto const nPieceStart = m_FileStorage.map_file(stl_ListIterator, 0, 0).piece; + auto const nPieceEnd = m_FileStorage.map_file(stl_ListIterator, max(int64_t(m_FileStorage.file_size(stl_ListIterator)) - 1, int64_t(0)), 0).piece; + auto const nFileFlags = m_FileStorage.file_flags(stl_ListIterator); + //判断是否有HASH值 + if (!m_FileStorage.hash(stl_ListIterator).is_all_zeros()) + { + _tcsxcpy((*pppSt_FileList)[i]->tszFileHash, m_FileStorage.hash(stl_ListIterator).to_string().c_str()); + } +#ifdef _MSC_BUILD + nUTFLen = m_FileStorage.file_path(stl_ListIterator).length(); + BaseLib_OperatorCharset_UTFToAnsi(m_FileStorage.file_path(stl_ListIterator).c_str(), (*pppSt_FileList)[i]->tszFilePath, &nUTFLen); + nUTFLen = m_FileStorage.file_name(stl_ListIterator).size(); + BaseLib_OperatorCharset_UTFToAnsi(m_FileStorage.file_name(stl_ListIterator).data(), (*pppSt_FileList)[i]->tszFileName, &nUTFLen); +#else + _tcsxcpy((*pppSt_FileList)[i]->tszFilePath, m_FileStorage.file_path(stl_ListIterator).c_str()); + _tcsxcpy((*pppSt_FileList)[i]->tszFileName, m_FileStorage.file_name(stl_ListIterator).data()); +#endif + (*pppSt_FileList)[i]->nFileOffset = m_FileStorage.file_offset(stl_ListIterator); + (*pppSt_FileList)[i]->nFileSize = m_FileStorage.file_size(stl_ListIterator); + (*pppSt_FileList)[i]->nFileTime = m_FileStorage.mtime(stl_ListIterator); + (*pppSt_FileList)[i]->nFileStart = static_cast(nPieceStart); + (*pppSt_FileList)[i]->nFileEnd = static_cast(nPieceEnd); + + if (nFileFlags & lt::file_storage::flag_pad_file) + { + (*pppSt_FileList)[i]->wFileAttr = (*pppSt_FileList)[i]->wFileAttr | (1 << 3); + } + if (nFileFlags & lt::file_storage::flag_executable) + { + (*pppSt_FileList)[i]->wFileAttr = (*pppSt_FileList)[i]->wFileAttr | (1 << 2); + } + if (nFileFlags & lt::file_storage::flag_hidden) + { + (*pppSt_FileList)[i]->wFileAttr = (*pppSt_FileList)[i]->wFileAttr | (1 << 1); + } + if (nFileFlags & lt::file_storage::flag_symlink) + { + (*pppSt_FileList)[i]->wFileAttr = (*pppSt_FileList)[i]->wFileAttr | (1 << 0); + } + if (nFileFlags & lt::file_storage::flag_symlink) + { + _tcsxcpy((*pppSt_FileList)[i]->tszFileLink, m_FileStorage.symlink(stl_ListIterator).c_str()); + } + i++; + } +#endif + st_Locker.unlock_shared(); + return true; +} +/******************************************************************** +函数名称:BTorrent_Parse_Destory +函数功能:销毁种子解析器 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要操作的句柄 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CBTorrent_Parse::BTorrent_Parse_Destory(XNETHANDLE xhToken) +{ + BTDload_IsErrorOccur = false; + + st_Locker.lock(); + unordered_map::iterator stl_MapIterator = stl_MapBTParse.find(xhToken); + if (stl_MapIterator != stl_MapBTParse.end()) + { + delete stl_MapIterator->second; + stl_MapIterator->second = NULL; + stl_MapBTParse.erase(stl_MapIterator); + } + st_Locker.unlock(); + return true; +} +////////////////////////////////////////////////////////////////////////// +// 保护函数 +////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/XEngine_Source/StorageModule_BTorrent/BTorrent_Parse/BTorrent_Parse.h b/XEngine_Source/StorageModule_BTorrent/BTorrent_Parse/BTorrent_Parse.h new file mode 100644 index 0000000..1542dc8 --- /dev/null +++ b/XEngine_Source/StorageModule_BTorrent/BTorrent_Parse/BTorrent_Parse.h @@ -0,0 +1,41 @@ +#pragma once +/******************************************************************** +// Created: 2023/02/02 16:25:58 +// File Name: D:\XEngine\XEngine_SourceCode\XEngine_NetHelp\NetHelp_BTorrent\BTorrent_Parse\BTorrent_Parse.h +// File Path: D:\XEngine\XEngine_SourceCode\XEngine_NetHelp\NetHelp_BTorrent\BTorrent_Parse +// File Base: BTorrent_Parse +// File Ext: h +// Project: XEngine +// Author: qyt +// Purpose: 种子解析工具 +// History: +*********************************************************************/ +typedef struct +{ +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT + lt::bdecode_node m_BTBNode; + shared_ptr m_BTInfo; +#endif +}BTORRENT_PARSEINFO; + +class CBTorrent_Parse +{ +public: + CBTorrent_Parse(); + ~CBTorrent_Parse(); +public: + bool BTorrent_Parse_Init(XNETHANDLE* pxhToken, LPCXSTR lpszAddr); + bool BTorrent_Parse_GetNode(XNETHANDLE xhToken, BTORRENT_PARSEMAP*** pppSt_Parse, int* pInt_ListCount); + bool BTorrent_Parse_GetTracker(XNETHANDLE xhToken, BTORRENT_PARSEMAP*** pppSt_Parse, int* pInt_ListCount); + bool BTorrent_Parse_GetSeeds(XNETHANDLE xhToken, BTORRENT_PARSEMAP*** pppSt_Parse, int* pInt_ListCount); + bool BTorrent_Parse_GetPiece(XNETHANDLE xhToken, int* pInt_PieceLen, int* pInt_PieceCount); + bool BTorrent_Parse_GetInfo(XNETHANDLE xhToken, XCHAR* ptszHash = NULL, XCHAR* ptszCreator = NULL, XCHAR* ptszComment = NULL); + bool BTorrent_Parse_GetMagnet(XNETHANDLE xhToken, XCHAR* ptszMagnet); + bool BTorrent_Parse_GetFile(XNETHANDLE xhToken, XCHAR* ptszFilePath, BTORRENT_FILEINFO*** pppSt_FileList, int* pInt_ListCount); + bool BTorrent_Parse_Destory(XNETHANDLE xhToken); +protected: +private: + shared_mutex st_Locker; +private: + unordered_map stl_MapBTParse; +}; \ No newline at end of file diff --git a/XEngine_Source/StorageModule_BTorrent/Makefile b/XEngine_Source/StorageModule_BTorrent/Makefile new file mode 100644 index 0000000..cd7f043 --- /dev/null +++ b/XEngine_Source/StorageModule_BTorrent/Makefile @@ -0,0 +1,78 @@ +CC = g++ -Wall -std=c++17 -fPIC +PLATFORM = linux +PLATVER = +PLATDIR = +FILEEXT = +LIBFLAG = +RELEASE = 0 +UNICODE = 0 +LOADHDR = -I ./ +LIB = -lXEngine_BaseLib +LIBEX = +LOADSO = +OBJECTS = BTorrent_Creator.o BTorrent_DLoader.o BTorrent_Parse.o pch.o + +MACRO_VALUE := $(shell gcc -E -dM ../XStorage_BuildSwitch.h | grep _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT | cut -d ' ' -f 3) + +ifeq ($(MACRO_VALUE),1) + LIB += -ltorrent-rasterbar +endif + +ifeq ($(PLATFORM),linux) + ifeq (/etc/redhat-release,$(wildcard /etc/redhat-release)) + PLATVER = -D __CENTOS__ + PLATDIR = XEngine_Linux/Centos + else + PLATVER = -D __UBUNTU__ + PLATDIR = XEngine_Linux/Ubuntu + endif + FILEEXT = so + LIBFLAG = -shared + LIBEX = -lpthread -lrt -ldl + LOADBIN = -Wl,-rpath=../XEngine_BaseLib,--disable-new-dtags +else ifeq ($(PLATFORM),mac) + CC += -Wno-deprecated-declarations + PLATVER = -D __MACOS__ + PLATDIR = XEngine_Mac + FILEEXT = dylib + LIBFLAG = -dynamiclib + LIBEX = -lpthread -ldl + LOADBIN = -Wl,-rpath,@loader_path/../XEngine_BaseLib/ +endif + +ifeq ($(RELEASE),1) +FLAGS = -c +DEBUG = +else +FLAGS = -c -lc_p +DEBUG = -g -pg +endif + +ifeq ($(UNICODE),1) +UNICODE = -D _UNICODE +else +UNICODE = +endif + +all:$(OBJECTS) + $(CC) $(DEBUG) $(OBJECTS) -o libStorageModule_BTorrent.$(FILEEXT) $(LIBFLAG) $(LIB) $(LIBEX) $(LOADSO) $(LOADBIN) + +BTorrent_Creator.o:./BTorrent_Creator/BTorrent_Creator.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./BTorrent_Creator/BTorrent_Creator.cpp +BTorrent_DLoader.o:./BTorrent_DLoader/BTorrent_DLoader.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./BTorrent_DLoader/BTorrent_DLoader.cpp +BTorrent_Parse.o:./BTorrent_Parse/BTorrent_Parse.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./BTorrent_Parse/BTorrent_Parse.cpp + +pch.o:./pch.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./pch.cpp + +InstallAll:InstallSo +InstallSo:./libStorageModule_BTorrent.$(FILEEXT) + cp ./libStorageModule_BTorrent.$(FILEEXT) ../../XEngine_Release/libStorageModule_BTorrent.$(FILEEXT) + +CleanAll:CleanObj CleanMk +CleanObj: + rm *.o +CleanMk: + rm *.$(FILEEXT) diff --git a/XEngine_Source/StorageModule_BTorrent/StorageModule_BTorrent.def b/XEngine_Source/StorageModule_BTorrent/StorageModule_BTorrent.def new file mode 100644 index 0000000..446ead2 --- /dev/null +++ b/XEngine_Source/StorageModule_BTorrent/StorageModule_BTorrent.def @@ -0,0 +1,30 @@ +LIBRARY + +EXPORTS + BTorrent_GetLastError + + BTorrent_DLoader_Create + BTorrent_DLoader_Query + BTorrent_DLoader_GetStatus + BTorrent_DLoader_SaveResume + BTorrent_DLoader_Close + BTorrent_DLoader_SetPause + BTorrent_DLoader_UPNPEnable + + BTorrent_Parse_Init + BTorrent_Parse_GetNode + BTorrent_Parse_GetTracker + BTorrent_Parse_GetSeeds + BTorrent_Parse_GetPiece + BTorrent_Parse_GetInfo + BTorrent_Parse_GetMagnet + BTorrent_Parse_GetFile + BTorrent_Parse_Destory + + BTorrent_Creator_Init + BTorrent_Creator_AddNode + BTorrent_Creator_AddTracker + BTorrent_Creator_AddSeeds + BTorrent_Creator_SetInfo + BTorrent_Creator_GetTorrent + BTorrent_Creator_Destory \ No newline at end of file diff --git a/XEngine_Source/StorageModule_BTorrent/StorageModule_BTorrent.vcxproj b/XEngine_Source/StorageModule_BTorrent/StorageModule_BTorrent.vcxproj new file mode 100644 index 0000000..a650105 --- /dev/null +++ b/XEngine_Source/StorageModule_BTorrent/StorageModule_BTorrent.vcxproj @@ -0,0 +1,188 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {ffbc453d-b12c-4c3f-86ea-fc569e0566e7} + StorageModuleBTorrent + 10.0 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + $(XEngine_Include);../XEngine_ThirdPart/jsoncpp;$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) + + + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) + + + + Level3 + true + WIN32;_DEBUG;STORAGEMODULEBTORRENT_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + StorageModule_BTorrent.def + + + + + Level3 + true + true + true + WIN32;NDEBUG;STORAGEMODULEBTORRENT_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + StorageModule_BTorrent.def + + + + + Level3 + true + _DEBUG;STORAGEMODULEBTORRENT_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + StorageModule_BTorrent.def + + + + + Level3 + true + true + true + NDEBUG;STORAGEMODULEBTORRENT_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + StorageModule_BTorrent.def + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/XEngine_Source/StorageModule_BTorrent/StorageModule_BTorrent.vcxproj.filters b/XEngine_Source/StorageModule_BTorrent/StorageModule_BTorrent.vcxproj.filters new file mode 100644 index 0000000..7e4bc42 --- /dev/null +++ b/XEngine_Source/StorageModule_BTorrent/StorageModule_BTorrent.vcxproj.filters @@ -0,0 +1,80 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {79772978-bcff-43f0-94d7-b50cf592615b} + + + {4a4a894a-459f-4e57-9c90-f47ea334bd37} + + + {3426ff10-d6f5-43bc-a29c-b13cc5c4123d} + + + {29ee657e-c097-4d3f-8ee9-4ef8f42cd864} + + + {2580a750-e481-481a-8ed0-9e30298d1c9f} + + + {bdb070b4-b17a-4323-8b70-7108dd30b967} + + + + + 头文件 + + + 头文件 + + + 头文件\BTorrent_Creator + + + 头文件\BTorrent_DLoader + + + 头文件\BTorrent_Parse + + + 头文件 + + + 头文件 + + + + + 源文件 + + + 源文件 + + + 源文件\BTorrent_Creator + + + 源文件\BTorrent_DLoader + + + 源文件\BTorrent_Parse + + + + + 源文件 + + + \ No newline at end of file diff --git a/XEngine_Source/StorageModule_BTorrent/StorageModule_BTorrent.vcxproj.user b/XEngine_Source/StorageModule_BTorrent/StorageModule_BTorrent.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/XEngine_Source/StorageModule_BTorrent/StorageModule_BTorrent.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_Source/StorageModule_BTorrent/dllmain.cpp b/XEngine_Source/StorageModule_BTorrent/dllmain.cpp new file mode 100644 index 0000000..0745b19 --- /dev/null +++ b/XEngine_Source/StorageModule_BTorrent/dllmain.cpp @@ -0,0 +1,19 @@ +// dllmain.cpp : 定义 DLL 应用程序的入口点。 +#include "pch.h" + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return true; +} + diff --git a/XEngine_Source/StorageModule_BTorrent/framework.h b/XEngine_Source/StorageModule_BTorrent/framework.h new file mode 100644 index 0000000..80cbbc9 --- /dev/null +++ b/XEngine_Source/StorageModule_BTorrent/framework.h @@ -0,0 +1,5 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 +// Windows 头文件 +#include diff --git a/XEngine_Source/StorageModule_BTorrent/pch.cpp b/XEngine_Source/StorageModule_BTorrent/pch.cpp new file mode 100644 index 0000000..c20cc31 --- /dev/null +++ b/XEngine_Source/StorageModule_BTorrent/pch.cpp @@ -0,0 +1,133 @@ +#include "pch.h" +#include "BTorrent_DLoader/BTorrent_DLoader.h" +#include "BTorrent_Parse/BTorrent_Parse.h" +#include "BTorrent_Creator/BTorrent_Creator.h" +/******************************************************************** +// Created: 2023/02/02 16:28:57 +// File Name: D:\XEngine\XEngine_SourceCode\XEngine_NetHelp\NetHelp_BTorrent\pch.cpp +// File Path: D:\XEngine\XEngine_SourceCode\XEngine_NetHelp\NetHelp_BTorrent +// File Base: pch +// File Ext: cpp +// Project: XEngine +// Author: qyt +// Purpose: 导出实现 +// History: +*********************************************************************/ +bool BTDload_IsErrorOccur = false; +XLONG BTDload_dwErrorCode = 0; +////////////////////////////////////////////////////////////////////////// +CBTorrent_DLoader m_BTDLoader; +CBTorrent_Parse m_BTParse; +CBTorrent_Creator m_BTCreator; +////////////////////////////////////////////////////////////////////////// +// 导出函数实现 +////////////////////////////////////////////////////////////////////////// +extern "C" XLONG BTorrent_GetLastError(int* pInt_SysError) +{ + if (NULL != pInt_SysError) + { + *pInt_SysError = errno; + } + return BTDload_dwErrorCode; +} +/************************************************************************/ +/* BT下载器导出函数 */ +/************************************************************************/ +extern "C" bool BTorrent_DLoader_Create(XNETHANDLE * pxhToken, LPCXSTR lpszAddr, LPCXSTR lpszSavePath, LPCXSTR lpszTempFile) +{ + return m_BTDLoader.BTorrent_DLoader_Create(pxhToken, lpszAddr, lpszSavePath, lpszTempFile); +} +extern "C" bool BTorrent_DLoader_Query(XNETHANDLE xhToken, ENUM_BTORRENT_EVENT_TYPE * **pppenEventList, int* pInt_ListCount) +{ + return m_BTDLoader.BTorrent_DLoader_Query(xhToken, pppenEventList, pInt_ListCount); +} +extern "C" bool BTorrent_DLoader_GetStatus(XNETHANDLE xhToken, BTORRENT_DLOADER * pSt_DLStatus) +{ + return m_BTDLoader.BTorrent_DLoader_GetStatus(xhToken, pSt_DLStatus); +} +extern "C" bool BTorrent_DLoader_SaveResume(XNETHANDLE xhToken) +{ + return m_BTDLoader.BTorrent_DLoader_SaveResume(xhToken); +} +extern "C" bool BTorrent_DLoader_Close(XNETHANDLE xhToken) +{ + return m_BTDLoader.BTorrent_DLoader_Close(xhToken); +} +extern "C" bool BTorrent_DLoader_SetPause(XNETHANDLE xhToken, bool bPause) +{ + return m_BTDLoader.BTorrent_DLoader_SetPause(xhToken, bPause); +} +extern "C" bool BTorrent_DLoader_UPNPEnable(XNETHANDLE xhToken, bool bEnable) +{ + return m_BTDLoader.BTorrent_DLoader_UPNPEnable(xhToken, bEnable); +} +/************************************************************************/ +/* BT解析器导出函数 */ +/************************************************************************/ +extern "C" bool BTorrent_Parse_Init(XNETHANDLE * pxhToken, LPCXSTR lpszAddr) +{ + return m_BTParse.BTorrent_Parse_Init(pxhToken, lpszAddr); +} +extern "C" bool BTorrent_Parse_GetNode(XNETHANDLE xhToken, BTORRENT_PARSEMAP * **pppSt_Parse, int* pInt_ListCount) +{ + return m_BTParse.BTorrent_Parse_GetNode(xhToken, pppSt_Parse, pInt_ListCount); +} +extern "C" bool BTorrent_Parse_GetTracker(XNETHANDLE xhToken, BTORRENT_PARSEMAP * **pppSt_Parse, int* pInt_ListCount) +{ + return m_BTParse.BTorrent_Parse_GetTracker(xhToken, pppSt_Parse, pInt_ListCount); +} +extern "C" bool BTorrent_Parse_GetSeeds(XNETHANDLE xhToken, BTORRENT_PARSEMAP * **pppSt_Parse, int* pInt_ListCount) +{ + return m_BTParse.BTorrent_Parse_GetSeeds(xhToken, pppSt_Parse, pInt_ListCount); +} +extern "C" bool BTorrent_Parse_GetPiece(XNETHANDLE xhToken, int* pInt_PieceLen, int* pInt_PieceCount) +{ + return m_BTParse.BTorrent_Parse_GetPiece(xhToken, pInt_PieceLen, pInt_PieceCount); +} +extern "C" bool BTorrent_Parse_GetInfo(XNETHANDLE xhToken, XCHAR * ptszHash, XCHAR * ptszCreator, XCHAR * ptszComment) +{ + return m_BTParse.BTorrent_Parse_GetInfo(xhToken, ptszHash, ptszCreator, ptszComment); +} +extern "C" bool BTorrent_Parse_GetMagnet(XNETHANDLE xhToken, XCHAR * ptszMagnet) +{ + return m_BTParse.BTorrent_Parse_GetMagnet(xhToken, ptszMagnet); +} +extern "C" bool BTorrent_Parse_GetFile(XNETHANDLE xhToken, XCHAR * pszFilePath, BTORRENT_FILEINFO * **pppSt_FileList, int* pInt_ListCount) +{ + return m_BTParse.BTorrent_Parse_GetFile(xhToken, pszFilePath, pppSt_FileList, pInt_ListCount); +} +extern "C" bool BTorrent_Parse_Destory(XNETHANDLE xhToken) +{ + return m_BTParse.BTorrent_Parse_Destory(xhToken); +} +/************************************************************************/ +/* BT种子制作导出函数 */ +/************************************************************************/ +extern "C" bool BTorrent_Creator_Init(XNETHANDLE * pxhToken, LPCXSTR lpszBTPath, int nPieceSize) +{ + return m_BTCreator.BTorrent_Creator_Init(pxhToken, lpszBTPath, nPieceSize); +} +extern "C" bool BTorrent_Creator_AddNode(XNETHANDLE xhToken, LPCXSTR lpszAddr, int nIndex) +{ + return m_BTCreator.BTorrent_Creator_AddNode(xhToken, lpszAddr, nIndex); +} +extern "C" bool BTorrent_Creator_AddTracker(XNETHANDLE xhToken, LPCXSTR lpszAddr, int nIndex) +{ + return m_BTCreator.BTorrent_Creator_AddTracker(xhToken, lpszAddr, nIndex); +} +extern "C" bool BTorrent_Creator_AddSeeds(XNETHANDLE xhToken, LPCXSTR lpszAddr, bool bSingle) +{ + return m_BTCreator.BTorrent_Creator_AddSeeds(xhToken, lpszAddr, bSingle); +} +extern "C" bool BTorrent_Creator_SetInfo(XNETHANDLE xhToken, LPCXSTR lpszCreator, LPCXSTR lpszComment, LPCXSTR lpszCertBuffer) +{ + return m_BTCreator.BTorrent_Creator_SetInfo(xhToken, lpszCreator, lpszComment, lpszCertBuffer); +} +extern "C" bool BTorrent_Creator_GetTorrent(XNETHANDLE xhToken, LPCXSTR lpszBTFile, XCHAR * ptszMsgBuffer, int* pInt_MsgLen) +{ + return m_BTCreator.BTorrent_Creator_GetTorrent(xhToken, lpszBTFile, ptszMsgBuffer, pInt_MsgLen); +} +extern "C" bool BTorrent_Creator_Destory(XNETHANDLE xhToken) +{ + return m_BTCreator.BTorrent_Creator_Destory(xhToken); +} \ No newline at end of file diff --git a/XEngine_Source/StorageModule_BTorrent/pch.h b/XEngine_Source/StorageModule_BTorrent/pch.h new file mode 100644 index 0000000..e45d76b --- /dev/null +++ b/XEngine_Source/StorageModule_BTorrent/pch.h @@ -0,0 +1,61 @@ +// pch.h: 这是预编译标头文件。 +// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 +// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 +// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 +// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 + +#ifndef PCH_H +#define PCH_H + +#ifdef _MSC_BUILD +// 添加要在此处预编译的标头 +#include "framework.h" +#include +#endif +#endif //PCH_H +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if 1 == _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif +using namespace std; +#include +#include +#include +#include +#include "../XStorage_BuildSwitch.h" +#include "BTorrent_Define.h" +#include "BTorrent_Error.h" +////////////////////////////////////////////////////////////////////////// +// 用户不用关心的数据 +////////////////////////////////////////////////////////////////////////// +extern bool BTDload_IsErrorOccur; +extern XLONG BTDload_dwErrorCode; + + +#ifdef _MSC_BUILD +#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") +#endif \ No newline at end of file diff --git a/XEngine_Source/StorageModule_Config/Config_Define.h b/XEngine_Source/StorageModule_Config/Config_Define.h index 97fbf5a..378b960 100644 --- a/XEngine_Source/StorageModule_Config/Config_Define.h +++ b/XEngine_Source/StorageModule_Config/Config_Define.h @@ -97,12 +97,17 @@ typedef struct tag_XEngine_ServerConfig struct { XCHAR tszCertChain[MAX_PATH]; + XCHAR tszCertServer[MAX_PATH]; XCHAR tszCertKey[MAX_PATH]; - int nSslType; bool bDLEnable; bool bUPEnable; bool bCHEnable; }st_XCert; + struct + { + XCHAR tszAPIUrl[MAX_PATH]; + bool bEnable; + }st_XReport; struct { list *pStl_ListStorage; diff --git a/XEngine_Source/StorageModule_Config/Config_Error.h b/XEngine_Source/StorageModule_Config/Config_Error.h index 0c5ec43..7c0b4f1 100644 --- a/XEngine_Source/StorageModule_Config/Config_Error.h +++ b/XEngine_Source/StorageModule_Config/Config_Error.h @@ -25,6 +25,7 @@ #define ERROR_XENGINE_BLOGIC_CONFIG_JSON_P2XP 0x002000A #define ERROR_XENGINE_BLOGIC_CONFIG_JSON_CERT 0x002000B #define ERROR_XENGINE_BLOGIC_CONFIG_JSON_XAUTH 0x002000C +#define ERROR_XENGINE_BLOGIC_CONFIG_JSON_CREPORT 0x002000D #define ERROR_XENGINE_BLOGIC_CONFIG_JSON_LBDISTRIBUTED 0x0020010 #define ERROR_XENGINE_BLOGIC_CONFIG_JSON_LBLOCATION 0x0020011 diff --git a/XEngine_Source/StorageModule_Config/Config_Json/Config_Json.cpp b/XEngine_Source/StorageModule_Config/Config_Json/Config_Json.cpp index 3ea9ffa..1841a7c 100644 --- a/XEngine_Source/StorageModule_Config/Config_Json/Config_Json.cpp +++ b/XEngine_Source/StorageModule_Config/Config_Json/Config_Json.cpp @@ -147,8 +147,8 @@ bool CConfig_Json::Config_Json_File(LPCXSTR lpszConfigFile, XENGINE_SERVERCONFIG } Json::Value st_JsonXStorage = st_JsonRoot["XStorage"]; pSt_ServerConfig->st_XStorage.nHashMode = st_JsonXStorage["nHashMode"].asInt(); - pSt_ServerConfig->st_XStorage.bUPHash = st_JsonXStorage["bUPHash"].asInt(); - pSt_ServerConfig->st_XStorage.bResumable = st_JsonXStorage["bResumable"].asInt(); + pSt_ServerConfig->st_XStorage.bUPHash = st_JsonXStorage["bUPHash"].asBool(); + pSt_ServerConfig->st_XStorage.bResumable = st_JsonXStorage["bResumable"].asBool(); if (st_JsonRoot["XProxy"].empty() || (6 != st_JsonRoot["XProxy"].size())) { @@ -209,18 +209,31 @@ bool CConfig_Json::Config_Json_File(LPCXSTR lpszConfigFile, XENGINE_SERVERCONFIG return false; } Json::Value st_JsonCert = st_JsonRoot["XCert"]; - pSt_ServerConfig->st_XCert.bDLEnable = st_JsonCert["bDLEnable"].asInt(); - pSt_ServerConfig->st_XCert.bUPEnable = st_JsonCert["bUPEnable"].asInt(); - pSt_ServerConfig->st_XCert.bCHEnable = st_JsonCert["bCHEnable"].asInt(); - pSt_ServerConfig->st_XCert.nSslType = st_JsonCert["nSslType"].asInt(); - if (!st_JsonP2xp["tszCertChain"].isNull()) + pSt_ServerConfig->st_XCert.bDLEnable = st_JsonCert["bDLEnable"].asBool(); + pSt_ServerConfig->st_XCert.bUPEnable = st_JsonCert["bUPEnable"].asBool(); + pSt_ServerConfig->st_XCert.bCHEnable = st_JsonCert["bCHEnable"].asBool(); + if (!st_JsonCert["tszCertChain"].isNull()) { - _tcsxcpy(pSt_ServerConfig->st_XCert.tszCertChain, st_JsonP2xp["tszCertChain"].asCString()); + _tcsxcpy(pSt_ServerConfig->st_XCert.tszCertChain, st_JsonCert["tszCertChain"].asCString()); } - if (!st_JsonP2xp["tszCertKey"].isNull()) + if (!st_JsonCert["tszCertServer"].isNull()) { - _tcsxcpy(pSt_ServerConfig->st_XCert.tszCertKey, st_JsonP2xp["tszCertKey"].asCString()); + _tcsxcpy(pSt_ServerConfig->st_XCert.tszCertServer, st_JsonCert["tszCertServer"].asCString()); } + if (!st_JsonCert["tszCertKey"].isNull()) + { + _tcsxcpy(pSt_ServerConfig->st_XCert.tszCertKey, st_JsonCert["tszCertKey"].asCString()); + } + + if (st_JsonRoot["XReport"].empty() || (2 != st_JsonRoot["XReport"].size())) + { + Config_IsErrorOccur = true; + Config_dwErrorCode = ERROR_XENGINE_BLOGIC_CONFIG_JSON_CREPORT; + return false; + } + Json::Value st_JsonReport = st_JsonRoot["XReport"]; + pSt_ServerConfig->st_XReport.bEnable = st_JsonReport["bEnable"].asBool(); + _tcsxcpy(pSt_ServerConfig->st_XReport.tszAPIUrl, st_JsonReport["tszAPIUrl"].asCString()); if (st_JsonRoot["XVer"].empty()) { diff --git a/XEngine_Source/StorageModule_InfoReport/InfoReport_APIMachine/InfoReport_APIMachine.cpp b/XEngine_Source/StorageModule_InfoReport/InfoReport_APIMachine/InfoReport_APIMachine.cpp new file mode 100644 index 0000000..410bbbe --- /dev/null +++ b/XEngine_Source/StorageModule_InfoReport/InfoReport_APIMachine/InfoReport_APIMachine.cpp @@ -0,0 +1,235 @@ +#include "pch.h" +#include "InfoReport_APIMachine.h" +/******************************************************************** +// Created: 2024/04/15 14:54:19 +// File Name: D:\XEngine_Storage\XEngine_Source\StorageModule_InfoReport\InfoReport_APIMachine\InfoReport_APIMachine.cpp +// File Path: D:\XEngine_Storage\XEngine_Source\StorageModule_InfoReport\InfoReport_APIMachine +// File Base: InfoReport_APIMachine +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 信息收集报告类 +// History: +*********************************************************************/ +CInfoReport_APIMachine::CInfoReport_APIMachine() +{ + +} +CInfoReport_APIMachine::~CInfoReport_APIMachine() +{ + +} +////////////////////////////////////////////////////////////////////////// +// 公有函数 +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +函数名称:InfoReport_APIMachine_Send +函数功能:发送一条信息报告给API服务器 + 参数.一:lpszAPIUrl + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入请求地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注:lpszAPIUrl = _X("http://127.0.0.1:5501/api?function=machine"); +*********************************************************************/ +bool CInfoReport_APIMachine::InfoReport_APIMachine_Send(LPCXSTR lpszAPIUrl) +{ + InfoReport_IsErrorOccur = false; + + if (NULL == lpszAPIUrl) + { + InfoReport_IsErrorOccur = true; + InfoReport_dwErrorCode = ERROR_XENGINE_STORAGE_INFOREPORT_PARAMENT; + return false; + } + int nLen = 0; + int nCode = 0; + + XCHAR tszAPIUrl[MAX_PATH] = {}; + XCHAR tszOSName[128] = {}; + XCHAR tszOSVersion[128] = {}; + XCHAR tszOSBuild[128] = {}; + XCHAR tszComputerName[128] = {}; + XLONG nOSArch = 0; + + XCLIENT_APIHTTP st_HTTPParam = {}; + SYSTEMAPI_SERIAL_INFOMATION st_SDKSerial = {}; + + _xstprintf(tszAPIUrl, _X("%s¶ms1=0"), lpszAPIUrl); + + SystemApi_System_GetSystemVer(tszOSName, tszOSVersion, tszOSBuild, &nOSArch); + SystemApi_System_GetSysName(NULL, tszComputerName); + SystemApi_HardWare_GetSerial(&st_SDKSerial); + + Json::Value st_JsonRoot; + JSONCPP_STRING st_JsonError; + Json::StreamWriterBuilder st_JsonBuilder; + Json::CharReaderBuilder st_JsonReader; + + XCHAR tszMachineText[1024] = {}; + InfoReport_APIMachine_GetText(tszMachineText); + + st_JsonRoot["tszMachineName"] = tszOSName; + st_JsonRoot["tszMachineCode"] = st_SDKSerial.tszSystemSerial; + st_JsonRoot["tszMachineSystem"] = tszComputerName; + st_JsonRoot["tszMachineText"] = tszMachineText; + + st_JsonBuilder["emitUTF8"] = true; + + XCHAR* ptszMsgBuffer = NULL; + st_HTTPParam.nTimeConnect = 2000; + if (!APIClient_Http_Request(_X("POST"), tszAPIUrl, Json::writeString(st_JsonBuilder, st_JsonRoot).c_str(), &nCode, &ptszMsgBuffer, &nLen, NULL, NULL, &st_HTTPParam)) + { + InfoReport_IsErrorOccur = true; + InfoReport_dwErrorCode = APIClient_GetLastError(); + return false; + } + st_JsonRoot.clear(); + //开始解析配置文件 + std::unique_ptr const pSt_JsonReader(st_JsonReader.newCharReader()); + if (!pSt_JsonReader->parse(ptszMsgBuffer, ptszMsgBuffer + nLen, &st_JsonRoot, &st_JsonError)) + { + InfoReport_IsErrorOccur = true; + InfoReport_dwErrorCode = ERROR_XENGINE_STORAGE_INFOREPORT_PARSE; + return false; + } + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + + if (0 != st_JsonRoot["code"].asInt()) + { + InfoReport_IsErrorOccur = true; + InfoReport_dwErrorCode = ERROR_XENGINE_STORAGE_INFOREPORT_CODE; + return false; + } + + return true; +} +/******************************************************************** +函数名称:InfoReport_APIMachine_GetTime +函数功能:获取报告次数 + 参数.一:lpszAPIUrl + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入请求地址 + 参数.二:pInt_TimeNumber + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出报告次数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CInfoReport_APIMachine::InfoReport_APIMachine_GetTime(LPCXSTR lpszAPIUrl, __int64x* pInt_TimeNumber) +{ + InfoReport_IsErrorOccur = false; + + if (NULL == lpszAPIUrl) + { + InfoReport_IsErrorOccur = true; + InfoReport_dwErrorCode = ERROR_XENGINE_STORAGE_INFOREPORT_PARAMENT; + return false; + } + int nLen = 0; + int nCode = 0; + XCHAR tszAPIUrl[MAX_PATH] = {}; + XCLIENT_APIHTTP st_HTTPParam = {}; + SYSTEMAPI_SERIAL_INFOMATION st_SDKSerial = {}; + + _xstprintf(tszAPIUrl, _X("%s¶ms1=2"), lpszAPIUrl); + + SystemApi_HardWare_GetSerial(&st_SDKSerial); + + Json::Value st_JsonRoot; + JSONCPP_STRING st_JsonError; + Json::StreamWriterBuilder st_JsonBuilder; + Json::CharReaderBuilder st_JsonReader; + + st_JsonRoot["tszMachineCode"] = st_SDKSerial.tszSystemSerial; + st_JsonBuilder["emitUTF8"] = true; + + XCHAR* ptszMsgBuffer = NULL; + st_HTTPParam.nTimeConnect = 2000; + if (!APIClient_Http_Request(_X("POST"), tszAPIUrl, Json::writeString(st_JsonBuilder, st_JsonRoot).c_str(), &nCode, &ptszMsgBuffer, &nLen, NULL, NULL, &st_HTTPParam)) + { + InfoReport_IsErrorOccur = true; + InfoReport_dwErrorCode = APIClient_GetLastError(); + return false; + } + st_JsonRoot.clear(); + //开始解析配置文件 + std::unique_ptr const pSt_JsonReader(st_JsonReader.newCharReader()); + if (!pSt_JsonReader->parse(ptszMsgBuffer, ptszMsgBuffer + nLen, &st_JsonRoot, &st_JsonError)) + { + InfoReport_IsErrorOccur = true; + InfoReport_dwErrorCode = ERROR_XENGINE_STORAGE_INFOREPORT_PARSE; + return false; + } + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + + if (0 != st_JsonRoot["code"].asInt()) + { + InfoReport_IsErrorOccur = true; + InfoReport_dwErrorCode = ERROR_XENGINE_STORAGE_INFOREPORT_CODE; + return false; + } + Json::Value st_JsonObject = st_JsonRoot["data"]; + //老版本 + if (st_JsonObject.isArray()) + { + InfoReport_IsErrorOccur = true; + InfoReport_dwErrorCode = ERROR_XENGINE_STORAGE_INFOREPORT_VERSION; + return false; + } + *pInt_TimeNumber = st_JsonObject["nTimeNumber"].asInt64(); + return true; +} +////////////////////////////////////////////////////////////////////////// +// 保护函数 +////////////////////////////////////////////////////////////////////////// +bool CInfoReport_APIMachine::InfoReport_APIMachine_GetText(XCHAR* ptszMSGBuffer) +{ + InfoReport_IsErrorOccur = false; + + XCHAR tszOSName[128] = {}; + XCHAR tszOSVersion[128] = {}; + XCHAR tszOSBuild[128] = {}; + XLONG nOSArch = 0; + int nProcessCount = 0; + SYSTEMAPI_CPU_INFOMATION st_CPUInfo = {}; + SYSTEMAPI_MEMORY_INFOMATION st_MemoryInfo = {}; + + Json::Value st_JsonRoot; + Json::Value st_JsonCPUObject; + Json::Value st_JsonOSObject; + Json::Value st_JsonMEMObject; + Json::StreamWriterBuilder st_JsonBuilder; + + SystemApi_System_GetSystemVer(tszOSName, tszOSVersion, tszOSBuild, &nOSArch); + SystemApi_HardWare_GetCpuInfomation(&st_CPUInfo); + SystemApi_System_GetMemoryUsage(&st_MemoryInfo, XENGINE_SYSTEMSDK_API_SYSTEM_SIZE_MB); + SystemApi_System_GetProcessCount(&nProcessCount); + + st_JsonCPUObject["nCPUNumber"] = st_CPUInfo.nCpuNumber; + st_JsonCPUObject["nCPUSpeed"] = st_CPUInfo.nCpuSpeed; + + st_JsonOSObject["OSArch"] = (Json::Value::Int)nOSArch; + st_JsonOSObject["OSVersion"] = tszOSVersion; + st_JsonOSObject["tszOSBuild"] = tszOSBuild; + + st_JsonMEMObject["nTotal"] = (Json::Value::UInt64)st_MemoryInfo.dwMemory_Total; + st_JsonMEMObject["nFree"] = (Json::Value::UInt64)st_MemoryInfo.dwMemory_Free; + + st_JsonRoot["nProcessCount"] = nProcessCount; + st_JsonRoot["st_CPUObject"] = st_JsonCPUObject; + st_JsonRoot["st_OSObject"] = st_JsonOSObject; + st_JsonRoot["st_MEMObject"] = st_JsonMEMObject; + + _tcsxcpy(ptszMSGBuffer, st_JsonRoot.toStyledString().c_str()); + return true; +} \ No newline at end of file diff --git a/XEngine_Source/StorageModule_InfoReport/InfoReport_APIMachine/InfoReport_APIMachine.h b/XEngine_Source/StorageModule_InfoReport/InfoReport_APIMachine/InfoReport_APIMachine.h new file mode 100644 index 0000000..68a8507 --- /dev/null +++ b/XEngine_Source/StorageModule_InfoReport/InfoReport_APIMachine/InfoReport_APIMachine.h @@ -0,0 +1,24 @@ +#pragma once +/******************************************************************** +// Created: 2024/04/15 14:54:08 +// File Name: D:\XEngine_Storage\XEngine_Source\StorageModule_InfoReport\InfoReport_APIMachine\InfoReport_APIMachine.h +// File Path: D:\XEngine_Storage\XEngine_Source\StorageModule_InfoReport\InfoReport_APIMachine +// File Base: InfoReport_APIMachine +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 信息收集报告类 +// History: +*********************************************************************/ + +class CInfoReport_APIMachine +{ +public: + CInfoReport_APIMachine(); + ~CInfoReport_APIMachine(); +public: + bool InfoReport_APIMachine_Send(LPCXSTR lpszAPIUrl); + bool InfoReport_APIMachine_GetTime(LPCXSTR lpszAPIUrl, __int64x* pInt_TimeNumber); +protected: + bool InfoReport_APIMachine_GetText(XCHAR *ptszMSGBuffer); +}; diff --git a/XEngine_Source/StorageModule_InfoReport/InfoReport_Define.h b/XEngine_Source/StorageModule_InfoReport/InfoReport_Define.h new file mode 100644 index 0000000..40f37fc --- /dev/null +++ b/XEngine_Source/StorageModule_InfoReport/InfoReport_Define.h @@ -0,0 +1,52 @@ +#pragma once +/******************************************************************** +// Created: 2024/04/15 15:39:50 +// File Name: D:\XEngine_Storage\XEngine_Source\StorageModule_InfoReport\InfoReport_Define.h +// File Path: D:\XEngine_Storage\XEngine_Source\StorageModule_InfoReport +// File Base: InfoReport_Define +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 信息报告导出定义 +// History: +*********************************************************************/ +////////////////////////////////////////////////////////////////////////// +// 导出函数 +////////////////////////////////////////////////////////////////////////// +extern "C" XLONG InfoReport_GetLastError(int *pInt_ErrorCode = NULL); +/************************************************************************/ +/* APIMachine报告 */ +/************************************************************************/ +/******************************************************************** +函数名称:InfoReport_APIMachine_Send +函数功能:发送一条信息报告给API服务器 + 参数.一:lpszAPIUrl + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入请求地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注:lpszAPIUrl = _X("http://127.0.0.1:5501/api?function=machine¶ms1=0"); +*********************************************************************/ +extern "C" bool InfoReport_APIMachine_Send(LPCXSTR lpszAPIUrl); +/******************************************************************** +函数名称:InfoReport_APIMachine_GetTime +函数功能:获取报告次数 + 参数.一:lpszAPIUrl + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入请求地址 + 参数.二:pInt_TimeNumber + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出报告次数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool InfoReport_APIMachine_GetTime(LPCXSTR lpszAPIUrl, __int64x* pInt_TimeNumber); \ No newline at end of file diff --git a/XEngine_Source/StorageModule_InfoReport/InfoReport_Error.h b/XEngine_Source/StorageModule_InfoReport/InfoReport_Error.h new file mode 100644 index 0000000..92b40d1 --- /dev/null +++ b/XEngine_Source/StorageModule_InfoReport/InfoReport_Error.h @@ -0,0 +1,16 @@ +#pragma once +/******************************************************************** +// Created: 2024/04/15 15:41:43 +// File Name: D:\XEngine_Storage\XEngine_Source\StorageModule_InfoReport\InfoReport_Error.h +// File Path: D:\XEngine_Storage\XEngine_Source\StorageModule_InfoReport +// File Base: InfoReport_Error +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 信息报告错误码 +// History: +*********************************************************************/ +#define ERROR_XENGINE_STORAGE_INFOREPORT_PARAMENT 0x01A0001 +#define ERROR_XENGINE_STORAGE_INFOREPORT_PARSE 0x01A0002 +#define ERROR_XENGINE_STORAGE_INFOREPORT_CODE 0x01A0003 +#define ERROR_XENGINE_STORAGE_INFOREPORT_VERSION 0x01A0004 \ No newline at end of file diff --git a/XEngine_Source/StorageModule_InfoReport/StorageModule_InfoReport.def b/XEngine_Source/StorageModule_InfoReport/StorageModule_InfoReport.def new file mode 100644 index 0000000..a559d82 --- /dev/null +++ b/XEngine_Source/StorageModule_InfoReport/StorageModule_InfoReport.def @@ -0,0 +1,7 @@ +LIBRARY + +EXPORTS + InfoReport_GetLastError + + InfoReport_APIMachine_Send + InfoReport_APIMachine_GetTime \ No newline at end of file diff --git a/XEngine_Source/StorageModule_InfoReport/StorageModule_InfoReport.vcxproj b/XEngine_Source/StorageModule_InfoReport/StorageModule_InfoReport.vcxproj new file mode 100644 index 0000000..f8f2b07 --- /dev/null +++ b/XEngine_Source/StorageModule_InfoReport/StorageModule_InfoReport.vcxproj @@ -0,0 +1,184 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {6754838e-7dc4-4c57-8c80-522da04e9284} + StorageModuleInfoReport + 10.0 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + $(XEngine_Include);../XEngine_ThirdPart/jsoncpp;$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + $(XEngine_Include);../XEngine_ThirdPart/jsoncpp;$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + $(XEngine_Include);../XEngine_ThirdPart/jsoncpp;$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) + + + $(XEngine_Include);../XEngine_ThirdPart/jsoncpp;$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) + + + + Level3 + true + WIN32;_DEBUG;STORAGEMODULEINFOREPORT_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + StorageModule_InfoReport.def + + + + + Level3 + true + true + true + WIN32;NDEBUG;STORAGEMODULEINFOREPORT_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + StorageModule_InfoReport.def + + + + + Level3 + true + _DEBUG;STORAGEMODULEINFOREPORT_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + StorageModule_InfoReport.def + + + + + Level3 + true + true + true + NDEBUG;STORAGEMODULEINFOREPORT_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + StorageModule_InfoReport.def + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/XEngine_Source/StorageModule_InfoReport/StorageModule_InfoReport.vcxproj.filters b/XEngine_Source/StorageModule_InfoReport/StorageModule_InfoReport.vcxproj.filters new file mode 100644 index 0000000..e184052 --- /dev/null +++ b/XEngine_Source/StorageModule_InfoReport/StorageModule_InfoReport.vcxproj.filters @@ -0,0 +1,56 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {05d03df8-14e3-492d-8776-bac05f15c5f7} + + + {c45d0b60-0d3e-4575-9143-a77f9ff0b539} + + + + + 头文件 + + + 头文件 + + + 头文件\InfoReport_APIMachine + + + 头文件 + + + 头文件 + + + + + 源文件 + + + 源文件 + + + 源文件\InfoReport_APIMachine + + + + + 源文件 + + + \ No newline at end of file diff --git a/XEngine_Source/StorageModule_InfoReport/StorageModule_InfoReport.vcxproj.user b/XEngine_Source/StorageModule_InfoReport/StorageModule_InfoReport.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/XEngine_Source/StorageModule_InfoReport/StorageModule_InfoReport.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_Source/StorageModule_InfoReport/dllmain.cpp b/XEngine_Source/StorageModule_InfoReport/dllmain.cpp new file mode 100644 index 0000000..daed8c8 --- /dev/null +++ b/XEngine_Source/StorageModule_InfoReport/dllmain.cpp @@ -0,0 +1,19 @@ +// dllmain.cpp : 定义 DLL 应用程序的入口点。 +#include "pch.h" + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + diff --git a/XEngine_Source/StorageModule_InfoReport/framework.h b/XEngine_Source/StorageModule_InfoReport/framework.h new file mode 100644 index 0000000..80cbbc9 --- /dev/null +++ b/XEngine_Source/StorageModule_InfoReport/framework.h @@ -0,0 +1,5 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 +// Windows 头文件 +#include diff --git a/XEngine_Source/StorageModule_InfoReport/pch.cpp b/XEngine_Source/StorageModule_InfoReport/pch.cpp new file mode 100644 index 0000000..3f1e3ba --- /dev/null +++ b/XEngine_Source/StorageModule_InfoReport/pch.cpp @@ -0,0 +1,39 @@ +#include "pch.h" +#include "InfoReport_APIMachine/InfoReport_APIMachine.h" +/******************************************************************** +// Created: 2024/04/15 15:40:22 +// File Name: D:\XEngine_Storage\XEngine_Source\StorageModule_InfoReport\pch.cpp +// File Path: D:\XEngine_Storage\XEngine_Source\StorageModule_InfoReport +// File Base: pch +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 信息报告导出实现 +// History: +*********************************************************************/ +bool InfoReport_IsErrorOccur = false; +XLONG InfoReport_dwErrorCode = 0; +////////////////////////////////////////////////////////////////////////// +CInfoReport_APIMachine m_APIMachine; +////////////////////////////////////////////////////////////////////////// +// 导出函数 +////////////////////////////////////////////////////////////////////////// +extern "C" XLONG InfoReport_GetLastError(int* pInt_ErrorCode) +{ + if (NULL != pInt_ErrorCode) + { + *pInt_ErrorCode = errno; + } + return InfoReport_dwErrorCode; +} +/************************************************************************/ +/* APIMachine报告 */ +/************************************************************************/ +extern "C" bool InfoReport_APIMachine_Send(LPCXSTR lpszAPIUrl) +{ + return m_APIMachine.InfoReport_APIMachine_Send(lpszAPIUrl); +} +extern "C" bool InfoReport_APIMachine_GetTime(LPCXSTR lpszAPIUrl, __int64x * pInt_TimeNumber) +{ + return m_APIMachine.InfoReport_APIMachine_GetTime(lpszAPIUrl, pInt_TimeNumber); +} \ No newline at end of file diff --git a/XEngine_Source/StorageModule_InfoReport/pch.h b/XEngine_Source/StorageModule_InfoReport/pch.h new file mode 100644 index 0000000..f21626a --- /dev/null +++ b/XEngine_Source/StorageModule_InfoReport/pch.h @@ -0,0 +1,69 @@ +// pch.h: 这是预编译标头文件。 +// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 +// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 +// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 +// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 + +#ifndef PCH_H +#define PCH_H + +// 添加要在此处预编译的标头 +#ifdef _MSC_BUILD +#include "framework.h" +#include +#else +#include +#include +#include +#endif +#endif //PCH_H +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "InfoReport_Define.h" +#include "InfoReport_Error.h" +/******************************************************************** +// Created: 2024/04/15 14:57:19 +// File Name: D:\XEngine_Storage\XEngine_Source\StorageModule_InfoReport\pch.h +// File Path: D:\XEngine_Storage\XEngine_Source\StorageModule_InfoReport +// File Base: pch +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 公用头 +// History: +*********************************************************************/ +extern bool InfoReport_IsErrorOccur; +extern XLONG InfoReport_dwErrorCode; + +#ifdef _MSC_BUILD +#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib") +#pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi") +#pragma comment(lib,"XEngine_Client/XClient_APIHelp") +#ifdef _DEBUG +#ifdef _WIN64 +#pragma comment(lib,"../x64/Debug/jsoncpp") +#else +#pragma comment(lib,"../Debug/jsoncpp") +#endif +#else +#ifdef _WIN64 +#pragma comment(lib,"../x64/Release/jsoncpp") +#else +#pragma comment(lib,"../Release/jsoncpp") +#endif +#endif +#endif \ No newline at end of file diff --git a/XEngine_Source/XEngine_StorageApp.sln b/XEngine_Source/XEngine_StorageApp.sln index e860b62..5de2fa3 100644 --- a/XEngine_Source/XEngine_StorageApp.sln +++ b/XEngine_Source/XEngine_StorageApp.sln @@ -13,6 +13,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StorageModule_APIHelp", "St EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "XStorage_Include", "XStorage_Include", "{B8417D60-3B19-45BC-8D8B-173E24E32B35}" ProjectSection(SolutionItems) = preProject + XStorage_BuildSwitch.h = XStorage_BuildSwitch.h XStorage_Protocol.h = XStorage_Protocol.h EndProjectSection EndProject @@ -24,6 +25,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jsoncpp", "XEngine_ThirdPar EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StorageModule_Database", "StorageModule_Database\StorageModule_Database.vcxproj", "{8B90FA35-1D93-4174-BF1C-926D52F0C67F}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StorageModule_BTorrent", "StorageModule_BTorrent\StorageModule_BTorrent.vcxproj", "{FFBC453D-B12C-4C3F-86EA-FC569E0566E7}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StorageModule_InfoReport", "StorageModule_InfoReport\StorageModule_InfoReport.vcxproj", "{6754838E-7DC4-4C57-8C80-522DA04E9284}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -88,6 +93,22 @@ Global {8B90FA35-1D93-4174-BF1C-926D52F0C67F}.Release|x64.Build.0 = Release|x64 {8B90FA35-1D93-4174-BF1C-926D52F0C67F}.Release|x86.ActiveCfg = Release|Win32 {8B90FA35-1D93-4174-BF1C-926D52F0C67F}.Release|x86.Build.0 = Release|Win32 + {FFBC453D-B12C-4C3F-86EA-FC569E0566E7}.Debug|x64.ActiveCfg = Debug|x64 + {FFBC453D-B12C-4C3F-86EA-FC569E0566E7}.Debug|x64.Build.0 = Debug|x64 + {FFBC453D-B12C-4C3F-86EA-FC569E0566E7}.Debug|x86.ActiveCfg = Debug|Win32 + {FFBC453D-B12C-4C3F-86EA-FC569E0566E7}.Debug|x86.Build.0 = Debug|Win32 + {FFBC453D-B12C-4C3F-86EA-FC569E0566E7}.Release|x64.ActiveCfg = Release|x64 + {FFBC453D-B12C-4C3F-86EA-FC569E0566E7}.Release|x64.Build.0 = Release|x64 + {FFBC453D-B12C-4C3F-86EA-FC569E0566E7}.Release|x86.ActiveCfg = Release|Win32 + {FFBC453D-B12C-4C3F-86EA-FC569E0566E7}.Release|x86.Build.0 = Release|Win32 + {6754838E-7DC4-4C57-8C80-522DA04E9284}.Debug|x64.ActiveCfg = Debug|x64 + {6754838E-7DC4-4C57-8C80-522DA04E9284}.Debug|x64.Build.0 = Debug|x64 + {6754838E-7DC4-4C57-8C80-522DA04E9284}.Debug|x86.ActiveCfg = Debug|Win32 + {6754838E-7DC4-4C57-8C80-522DA04E9284}.Debug|x86.Build.0 = Debug|Win32 + {6754838E-7DC4-4C57-8C80-522DA04E9284}.Release|x64.ActiveCfg = Release|x64 + {6754838E-7DC4-4C57-8C80-522DA04E9284}.Release|x64.Build.0 = Release|x64 + {6754838E-7DC4-4C57-8C80-522DA04E9284}.Release|x86.ActiveCfg = Release|Win32 + {6754838E-7DC4-4C57-8C80-522DA04E9284}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/XEngine_Source/XEngine_StorageApp/Makefile b/XEngine_Source/XEngine_StorageApp/Makefile index 65c3176..89d808a 100644 --- a/XEngine_Source/XEngine_StorageApp/Makefile +++ b/XEngine_Source/XEngine_StorageApp/Makefile @@ -5,9 +5,9 @@ PLATDIR = RELEASE = 0 UNICODE = 0 LOADHDR = -I ./ -I ../XEngine_ThirdPart/jsoncpp -LOADSO = -L ../StorageModule_Database -L ../StorageModule_Config -L ../StorageModule_Session -L ../StorageModule_APIHelp -L ../StorageModule_Protocol -L ../XEngine_ThirdPart/jsoncpp +LOADSO = -L ../StorageModule_Database -L ../StorageModule_Config -L ../StorageModule_Session -L ../StorageModule_APIHelp -L ../StorageModule_Protocol -L ../StorageModule_BTorrent -L ../StorageModule_InfoReport -L ../XEngine_ThirdPart/jsoncpp LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_ManagePool -lXEngine_OPenSsl -lXClient_APIHelp -lXEngine_ProcFile -lXEngine_SystemApi -lHelpComponents_XLog -lHelpComponents_Packets -lRfcComponents_HttpProtocol \ - -lStorageModule_Database -lStorageModule_Config -lStorageModule_Session -lStorageModule_APIHelp -lStorageModule_Protocol \ + -lStorageModule_Database -lStorageModule_Config -lStorageModule_Session -lStorageModule_APIHelp -lStorageModule_Protocol -lStorageModule_BTorrent -lStorageModule_InfoReport \ -ljsoncpp LIBEX = OBJECTS = StorageApp_Config.o StorageApp_Download.o StorageApp_Network.o StorageApp_Center.o StorageApp_UPLoader.o Storage_TaskPass.o Storage_TaskManage.o Storage_TaskP2p.o XEngine_StorageApp.o diff --git a/XEngine_Source/XEngine_StorageApp/StorageApp_Center.cpp b/XEngine_Source/XEngine_StorageApp/StorageApp_Center.cpp index 8d088f0..db30b2e 100644 --- a/XEngine_Source/XEngine_StorageApp/StorageApp_Center.cpp +++ b/XEngine_Source/XEngine_StorageApp/StorageApp_Center.cpp @@ -57,6 +57,8 @@ bool XEngine_Task_HttpCenter(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int LPCXSTR lpszMethodPost = _X("POST"); LPCXSTR lpszMethodOption = _X("OPTIONS"); + LPCXSTR lpszMethodPass = _X("Pass"); + LPCXSTR lpszMehtodManage = _X("Manage"); if (st_ServiceCfg.st_XAuth.bCHAuth) { @@ -127,11 +129,11 @@ bool XEngine_Task_HttpCenter(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int return false; } //通知类型.用于多服务器 - if (0 == _tcsxnicmp(XENGINE_STORAGE_APP_TASK_PASS, tszAPIMethod, _tcsxlen(XENGINE_STORAGE_APP_TASK_PASS))) + if (0 == _tcsxnicmp(lpszMethodPass, tszAPIMethod, _tcsxlen(lpszMethodPass))) { XEngine_Task_Pass(tszAPIName, lpszClientAddr, lpszMsgBuffer, nMsgLen, pSt_HTTPParam, pptszListHdr, nHdrCount); } - else if (0 == _tcsxnicmp(XENGINE_STORAGE_APP_TASK_MANAGE, tszAPIMethod, _tcsxlen(XENGINE_STORAGE_APP_TASK_MANAGE))) + else if (0 == _tcsxnicmp(lpszMehtodManage, tszAPIMethod, _tcsxlen(lpszMehtodManage))) { XEngine_Task_Manage(tszAPIName, lpszClientAddr, lpszMsgBuffer, nMsgLen, pSt_HTTPParam, pptszListHdr, nHdrCount); } diff --git a/XEngine_Source/XEngine_StorageApp/StorageApp_Center.h b/XEngine_Source/XEngine_StorageApp/StorageApp_Center.h index e1bd7fd..9ce548a 100644 --- a/XEngine_Source/XEngine_StorageApp/StorageApp_Center.h +++ b/XEngine_Source/XEngine_StorageApp/StorageApp_Center.h @@ -1,11 +1,14 @@ #pragma once -#define XENGINE_STORAGE_APP_TASK_PASS _X("Pass") -#define XENGINE_STORAGE_APP_TASK_MANAGE _X("Manage") - -#define XENGINE_STORAGE_APP_METHOD_CONFIG _X("Config") -#define XENGINE_STORAGE_APP_METHOD_UPFILE _X("UPFile") -#define XENGINE_STORAGE_APP_METHOD_DLFILE _X("DLFile") - +/******************************************************************** +// Created: 2024/04/16 10:43:39 +// File Name: D:\XEngine_Storage\XEngine_Source\XEngine_StorageApp\StorageApp_Center.h +// File Path: D:\XEngine_Storage\XEngine_Source\XEngine_StorageApp +// File Base: StorageApp_Center +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: HTTP管理服务处理类 +// History: +*********************************************************************/ XHTHREAD CALLBACK XEngine_Center_HTTPThread(XPVOID lParam); -bool XEngine_Task_HttpCenter_APIList(LPCXSTR lpszUrlName, XCHAR* ptszAPIVersion, XCHAR* ptszAPIMethod, XCHAR* ptszAPIName); bool XEngine_Task_HttpCenter(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen, RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam, XCHAR** pptszListHdr, int nHdrCount); \ No newline at end of file diff --git a/XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h b/XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h index 74f2655..c5f7a56 100644 --- a/XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h +++ b/XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h @@ -60,6 +60,8 @@ using namespace std; #include "../StorageModule_Protocol/StorageProtocol_Error.h" #include "../StorageModule_APIHelp/APIHelp_Define.h" #include "../StorageModule_APIHelp/APIHelp_Error.h" +#include "../StorageModule_InfoReport/InfoReport_Define.h" +#include "../StorageModule_InfoReport/InfoReport_Error.h" #define STORAGE_LEAVETYPE_HEARTBEAT 1 #define STORAGE_LEAVETYPE_BYSELF 2 @@ -126,12 +128,14 @@ extern XENGINE_LBCONFIG st_LoadbalanceCfg; #pragma comment(lib,"../x64/Debug/StorageModule_APIHelp.lib") #pragma comment(lib,"../x64/Debug/StorageModule_Protocol.lib") #pragma comment(lib,"../x64/Debug/StorageModule_Database.lib") +#pragma comment(lib,"../x64/Debug/StorageModule_InfoReport.lib") #else #pragma comment(lib,"../x64/Release/StorageModule_Session.lib") #pragma comment(lib,"../x64/Release/StorageModule_Config.lib") #pragma comment(lib,"../x64/Release/StorageModule_APIHelp.lib") #pragma comment(lib,"../x64/Release/StorageModule_Protocol.lib") #pragma comment(lib,"../x64/Release/StorageModule_Database.lib") +#pragma comment(lib,"../x64/Release/StorageModule_InfoReport.lib") #endif #else #ifdef _DEBUG @@ -140,12 +144,14 @@ extern XENGINE_LBCONFIG st_LoadbalanceCfg; #pragma comment(lib,"../Debug/StorageModule_APIHelp.lib") #pragma comment(lib,"../Debug/StorageModule_Protocol.lib") #pragma comment(lib,"../Debug/StorageModule_Database.lib") +#pragma comment(lib,"../Debug/StorageModule_InfoReport.lib") #else #pragma comment(lib,"../Release/StorageModule_Session.lib") #pragma comment(lib,"../Release/StorageModule_Config.lib") #pragma comment(lib,"../Release/StorageModule_APIHelp.lib") #pragma comment(lib,"../Release/StorageModule_Protocol.lib") #pragma comment(lib,"../Release/StorageModule_Database.lib") +#pragma comment(lib,"../Release/StorageModule_InfoReport.lib") #endif #endif #endif \ No newline at end of file diff --git a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskManage.cpp b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskManage.cpp index 7dfce13..6c0f2b3 100644 --- a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskManage.cpp +++ b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskManage.cpp @@ -6,6 +6,12 @@ bool XEngine_Task_Manage(LPCXSTR lpszAPIName, LPCXSTR lpszClientAddr, LPCXSTR lp int nRVLen = 10240; XCHAR tszSDBuffer[10240]; XCHAR tszRVBuffer[10240]; + LPCXSTR lpszAPIConfig = _X("Config"); + LPCXSTR lpszAPIInsert = _X("Insert"); + LPCXSTR lpszAPIDelete = _X("Delete"); + LPCXSTR lpszAPIQuery = _X("Query"); + LPCXSTR lpszAPIDir = _X("Dir"); + LPCXSTR lpszAPITask = _X("Task"); RFCCOMPONENTS_HTTP_HDRPARAM st_HDRParam; memset(tszSDBuffer, '\0', sizeof(tszSDBuffer)); @@ -14,14 +20,14 @@ bool XEngine_Task_Manage(LPCXSTR lpszAPIName, LPCXSTR lpszClientAddr, LPCXSTR lp st_HDRParam.bIsClose = true; st_HDRParam.nHttpCode = 200; - if (0 == _tcsxnicmp(XENGINE_STORAGE_APP_METHOD_CONFIG, lpszAPIName, _tcsxlen(XENGINE_STORAGE_APP_METHOD_CONFIG))) + if (0 == _tcsxnicmp(lpszAPIConfig, lpszAPIName, _tcsxlen(lpszAPIConfig))) { StorageApp_Config_Parament(0, NULL); HttpProtocol_Server_SendMsgEx(xhCenterHttp, tszSDBuffer, &nSDLen, &st_HDRParam); XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("业务客户端:%s,处理用户重载配置文件成功"), lpszClientAddr); } - else if (0 == _tcsxnicmp(XENGINE_STORAGE_APP_METHOD_QUERY, lpszAPIName, _tcsxlen(XENGINE_STORAGE_APP_METHOD_QUERY))) + else if (0 == _tcsxnicmp(lpszAPIQuery, lpszAPIName, _tcsxlen(lpszAPIQuery))) { //查询文件列表 int nMode = 0; @@ -160,7 +166,7 @@ bool XEngine_Task_Manage(LPCXSTR lpszAPIName, LPCXSTR lpszClientAddr, LPCXSTR lp stl_ListFile.clear(); } } - else if (0 == _tcsxnicmp(XENGINE_STORAGE_APP_METHOD_INSERT, lpszAPIName, _tcsxlen(XENGINE_STORAGE_APP_METHOD_INSERT))) + else if (0 == _tcsxnicmp(lpszAPIInsert, lpszAPIName, _tcsxlen(lpszAPIInsert))) { int nListCount = 0; XSTORAGECORE_DBFILE** ppSt_DBFile; @@ -200,7 +206,7 @@ bool XEngine_Task_Manage(LPCXSTR lpszAPIName, LPCXSTR lpszClientAddr, LPCXSTR lp XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_DBFile, nListCount); } - else if (0 == _tcsxnicmp(XENGINE_STORAGE_APP_METHOD_DELETE, lpszAPIName, _tcsxlen(XENGINE_STORAGE_APP_METHOD_DELETE))) + else if (0 == _tcsxnicmp(lpszAPIDelete, lpszAPIName, _tcsxlen(lpszAPIDelete))) { int nListCount = 0; XSTORAGECORE_DBFILE** ppSt_DBFile; @@ -275,7 +281,7 @@ bool XEngine_Task_Manage(LPCXSTR lpszAPIName, LPCXSTR lpszClientAddr, LPCXSTR lp XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_DBFile, nListCount); } - else if (0 == _tcsxnicmp(XENGINE_STORAGE_APP_METHOD_DIR, lpszAPIName, _tcsxlen(XENGINE_STORAGE_APP_METHOD_DIR))) + else if (0 == _tcsxnicmp(lpszAPIDir, lpszAPIName, _tcsxlen(lpszAPIDir))) { int nOPCode = 0; int nListCount = 0; @@ -368,7 +374,7 @@ bool XEngine_Task_Manage(LPCXSTR lpszAPIName, LPCXSTR lpszClientAddr, LPCXSTR lp XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("业务客户端:%s,请求删除文件夹:%s,成功"), lpszClientAddr, tszRealDir); } } - else if (0 == _tcsxnicmp(XENGINE_STORAGE_APP_METHOD_TASK, lpszAPIName, _tcsxlen(XENGINE_STORAGE_APP_METHOD_TASK))) + else if (0 == _tcsxnicmp(lpszAPITask, lpszAPIName, _tcsxlen(lpszAPITask))) { int nDLCount = 0; int nUPCount = 0; diff --git a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskManage.h b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskManage.h index 99d9f05..dd5b8f0 100644 --- a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskManage.h +++ b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskManage.h @@ -1,9 +1,3 @@ #pragma once -#define XENGINE_STORAGE_APP_METHOD_INSERT _X("Insert") -#define XENGINE_STORAGE_APP_METHOD_DELETE _X("Delete") -#define XENGINE_STORAGE_APP_METHOD_QUERY _X("Query") -#define XENGINE_STORAGE_APP_METHOD_DIR _X("Dir") -#define XENGINE_STORAGE_APP_METHOD_TASK _X("Task") - bool XEngine_Task_Manage(LPCXSTR lpszAPIName, LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen, RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam, XCHAR** pptszListHdr, int nHdrCount); \ No newline at end of file diff --git a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskPass.cpp b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskPass.cpp index 7049266..8fd0d24 100644 --- a/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskPass.cpp +++ b/XEngine_Source/XEngine_StorageApp/Storage_APPTask/Storage_TaskPass.cpp @@ -4,6 +4,8 @@ bool XEngine_Task_Pass(LPCXSTR lpszAPIName, LPCXSTR lpszClientAddr, LPCXSTR lpsz { int nSDLen = 2048; XCHAR tszSDBuffer[2048]; + LPCXSTR lpszAPIUPFile = _X("UPFile"); + LPCXSTR lpszAPIDLFile = _X("DLFile"); RFCCOMPONENTS_HTTP_HDRPARAM st_HDRParam; memset(tszSDBuffer, '\0', sizeof(tszSDBuffer)); @@ -12,7 +14,7 @@ bool XEngine_Task_Pass(LPCXSTR lpszAPIName, LPCXSTR lpszClientAddr, LPCXSTR lpsz st_HDRParam.bIsClose = true; st_HDRParam.nHttpCode = 200; //下载 - if (0 == _tcsxnicmp(XENGINE_STORAGE_APP_METHOD_UPFILE, lpszAPIName, _tcsxlen(XENGINE_STORAGE_APP_METHOD_UPFILE))) + if (0 == _tcsxnicmp(lpszAPIUPFile, lpszAPIName, _tcsxlen(lpszAPIUPFile))) { XCHAR tszClientAddr[128]; XSTORAGECORE_DBFILE st_DBFile; @@ -24,7 +26,7 @@ bool XEngine_Task_Pass(LPCXSTR lpszAPIName, LPCXSTR lpszClientAddr, LPCXSTR lpsz XEngine_Net_SendMsg(lpszClientAddr, tszSDBuffer, nSDLen, STORAGE_NETTYPE_HTTPCENTER); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("业务客户端:%s,请求的上传文件通知协议成功,Bucket:%s,文件名:%s,大小:%d"), lpszClientAddr, st_DBFile.tszBuckKey, st_DBFile.st_ProtocolFile.tszFileName, st_DBFile.st_ProtocolFile.nFileSize); } - else if (0 == _tcsxnicmp(XENGINE_STORAGE_APP_METHOD_DLFILE, lpszAPIName, _tcsxlen(XENGINE_STORAGE_APP_METHOD_DLFILE))) + else if (0 == _tcsxnicmp(lpszAPIDLFile, lpszAPIName, _tcsxlen(lpszAPIDLFile))) { __int64x nFileSize = 0; XCHAR tszPathKey[MAX_PATH]; diff --git a/XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.cpp b/XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.cpp index 05a2c47..7517e75 100644 --- a/XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.cpp +++ b/XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.cpp @@ -241,13 +241,20 @@ int main(int argc, char** argv) if (st_ServiceCfg.st_XCert.bDLEnable) { - xhDLSsl = OPenSsl_Server_InitEx(st_ServiceCfg.st_XCert.tszCertChain, NULL, st_ServiceCfg.st_XCert.tszCertKey, false, false, (ENUM_XENGINE_OPENSSL_PROTOCOL)st_ServiceCfg.st_XCert.nSslType); + if (_tcsxlen(st_ServiceCfg.st_XCert.tszCertServer) > 0) + { + xhDLSsl = OPenSsl_Server_InitEx(st_ServiceCfg.st_XCert.tszCertChain, st_ServiceCfg.st_XCert.tszCertServer, st_ServiceCfg.st_XCert.tszCertKey, false, false, XENGINE_OPENSSL_PROTOCOL_TLS_SERVER); + } + else + { + xhDLSsl = OPenSsl_Server_InitEx(st_ServiceCfg.st_XCert.tszCertChain, NULL, st_ServiceCfg.st_XCert.tszCertKey, false, false, XENGINE_OPENSSL_PROTOCOL_TLS_SERVER); + } if (NULL == xhDLSsl) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,启动下载SSL服务失败,错误:%lX"), Session_GetLastError()); goto XENGINE_EXITAPP; } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动下载SSL服务成功,证书链:%s,证书Key:%s,验证模式:%d"), st_ServiceCfg.st_XCert.tszCertChain, st_ServiceCfg.st_XCert.tszCertKey, st_ServiceCfg.st_XCert.nSslType); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动下载SSL服务成功,证书链:%s,证书Key:%s"), st_ServiceCfg.st_XCert.tszCertChain, st_ServiceCfg.st_XCert.tszCertKey); } else { @@ -301,13 +308,20 @@ int main(int argc, char** argv) if (st_ServiceCfg.st_XCert.bUPEnable) { - xhUPSsl = OPenSsl_Server_InitEx(st_ServiceCfg.st_XCert.tszCertChain, NULL, st_ServiceCfg.st_XCert.tszCertKey, false, false, (ENUM_XENGINE_OPENSSL_PROTOCOL)st_ServiceCfg.st_XCert.nSslType); + if (_tcsxlen(st_ServiceCfg.st_XCert.tszCertServer) > 0) + { + xhUPSsl = OPenSsl_Server_InitEx(st_ServiceCfg.st_XCert.tszCertChain, st_ServiceCfg.st_XCert.tszCertServer, st_ServiceCfg.st_XCert.tszCertKey, false, false, XENGINE_OPENSSL_PROTOCOL_TLS_SERVER); + } + else + { + xhUPSsl = OPenSsl_Server_InitEx(st_ServiceCfg.st_XCert.tszCertChain, NULL, st_ServiceCfg.st_XCert.tszCertKey, false, false, XENGINE_OPENSSL_PROTOCOL_TLS_SERVER); + } if (NULL == xhUPSsl) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,启动上传SSL服务失败,错误:%lX"), Session_GetLastError()); goto XENGINE_EXITAPP; } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动上传SSL服务成功,证书链:%s,证书Key:%s,验证模式:%d"), st_ServiceCfg.st_XCert.tszCertChain, st_ServiceCfg.st_XCert.tszCertKey, st_ServiceCfg.st_XCert.nSslType); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动上传SSL服务成功,证书链:%s,证书Key:%s"), st_ServiceCfg.st_XCert.tszCertChain, st_ServiceCfg.st_XCert.tszCertKey); } else { @@ -354,13 +368,20 @@ int main(int argc, char** argv) if (st_ServiceCfg.st_XCert.bCHEnable) { - xhCHSsl = OPenSsl_Server_InitEx(st_ServiceCfg.st_XCert.tszCertChain, NULL, st_ServiceCfg.st_XCert.tszCertKey, false, false, (ENUM_XENGINE_OPENSSL_PROTOCOL)st_ServiceCfg.st_XCert.nSslType); + if (_tcsxlen(st_ServiceCfg.st_XCert.tszCertServer) > 0) + { + xhCHSsl = OPenSsl_Server_InitEx(st_ServiceCfg.st_XCert.tszCertChain, st_ServiceCfg.st_XCert.tszCertServer, st_ServiceCfg.st_XCert.tszCertKey, false, false, XENGINE_OPENSSL_PROTOCOL_TLS_SERVER); + } + else + { + xhCHSsl = OPenSsl_Server_InitEx(st_ServiceCfg.st_XCert.tszCertChain, NULL, st_ServiceCfg.st_XCert.tszCertKey, false, false, XENGINE_OPENSSL_PROTOCOL_TLS_SERVER); + } if (NULL == xhCHSsl) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,启动业务SSL服务失败,错误:%lX"), Session_GetLastError()); goto XENGINE_EXITAPP; } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动业务SSL服务成功,证书链:%s,证书Key:%s,验证模式:%d"), st_ServiceCfg.st_XCert.tszCertChain, st_ServiceCfg.st_XCert.tszCertKey, st_ServiceCfg.st_XCert.nSslType); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动业务SSL服务成功,证书链:%s,证书Key:%s"), st_ServiceCfg.st_XCert.tszCertChain, st_ServiceCfg.st_XCert.tszCertKey); } else { @@ -422,6 +443,22 @@ int main(int argc, char** argv) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,P2P存储服务配置为不启动")); } + //发送信息报告 + if (st_ServiceCfg.st_XReport.bEnable) + { + if (InfoReport_APIMachine_Send(st_ServiceCfg.st_XReport.tszAPIUrl)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动信息报告给API服务器:%s 成功"), st_ServiceCfg.st_XReport.tszAPIUrl); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,启动信息报告给API服务器:%s 失败,错误:%lX"), st_ServiceCfg.st_XReport.tszAPIUrl, InfoReport_GetLastError()); + } + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,信息报告给API服务器没有启用")); + } XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("所有服务成功启动,存储中心服务运行中,发行版本次数:%d,XEngine版本:%s%s 当前运行版本:%s。。。"), st_ServiceCfg.st_XVer.pStl_ListStorage->size(), BaseLib_OperatorVer_XNumberStr(), BaseLib_OperatorVer_XTypeStr(), st_ServiceCfg.st_XVer.pStl_ListStorage->front().c_str()); diff --git a/XEngine_Source/XStorage_BuildSwitch.h b/XEngine_Source/XStorage_BuildSwitch.h new file mode 100644 index 0000000..fecb0d4 --- /dev/null +++ b/XEngine_Source/XStorage_BuildSwitch.h @@ -0,0 +1,13 @@ +#pragma once +/******************************************************************** +// Created: 2024/03/13 14:31:44 +// File Name: D:\XEngine_Storage\XEngine_Source\XStorage_BuildSwitch.h +// File Path: D:\XEngine_Storage\XEngine_Source +// File Base: XStorage_BuildSwitch +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 存储服务开关编译选项 +// History: +*********************************************************************/ +#define _XENGIEN_STORAGE_BUILDSWITCH_BTORRENT 0 //BT支持 \ No newline at end of file