diff --git a/.github/workflows/issue-translator.yml b/.github/workflows/issue-translator.yml new file mode 100644 index 0000000000000000000000000000000000000000..424f3d11211442ea79cb0cf77c76b9fd469787e2 --- /dev/null +++ b/.github/workflows/issue-translator.yml @@ -0,0 +1,15 @@ +name: Issue Translator +on: + issue_comment: + types: [created] + issues: + types: [opened] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: usthe/issues-translate-action@v2.7 + with: + IS_MODIFY_TITLE: true + CUSTOM_BOT_NOTE: Bot detected the issue body's language is not English, translate it automatically. \ No newline at end of file diff --git a/.github/workflows/linuxbuild.yml b/.github/workflows/linuxbuild.yml index 144dfcb16663aa2cf16f17493d41f05a600d8713..42bc927c1ea07bbc24cd15739bda29f3a9094526 100644 --- a/.github/workflows/linuxbuild.yml +++ b/.github/workflows/linuxbuild.yml @@ -3,9 +3,9 @@ name: ubuntu build workflows on: push: branches: [ "develop" ] - pull_request: - branches: [ "develop" ] - + paths: + - 'XEngine_Source/**' + - 'XEngine_Release/**' permissions: contents: read @@ -61,4 +61,10 @@ jobs: - name: test run: | cd XEngine_Release - ./XEngine_ProxyServiceApp -t \ No newline at end of file + ./XEngine_ProxyServiceApp -t + + - name: Upload folder as artifact with ubuntu + uses: actions/upload-artifact@v4 + with: + name: XEngine_ProxyServiceApp-x64-Ubuntu + path: XEngine_Release/ \ No newline at end of file diff --git a/.github/workflows/macbuild.yml b/.github/workflows/macbuild.yml index 51e9e7812dda21ebe7fcb8ca1e08de033bdc23d5..a9ba22ce0c16df69647b1c102e94dfc568200deb 100644 --- a/.github/workflows/macbuild.yml +++ b/.github/workflows/macbuild.yml @@ -3,8 +3,9 @@ name: macos build workflows on: push: branches: [ "develop" ] - pull_request: - branches: [ "develop" ] + paths: + - 'XEngine_Source/**' + - 'XEngine_Release/**' permissions: contents: read @@ -29,6 +30,7 @@ jobs: with: repository: libxengine/libxengine path: libxengine + ref: 'master' - name: sub module checkout (opensource) run: | @@ -62,3 +64,9 @@ jobs: run: | cd XEngine_Release ./XEngine_ProxyServiceApp -t + + - name: Upload folder as artifact with mac + uses: actions/upload-artifact@v4 + with: + name: XEngine_ProxyServiceApp-x64-Mac + path: XEngine_Release/ \ No newline at end of file diff --git a/.github/workflows/msbuild.yml b/.github/workflows/msbuild.yml index 6c61810cff8c697ec54945340b2ea98424f58eed..f449080fc694e80c813aa4364795ac3ecedd3caa 100644 --- a/.github/workflows/msbuild.yml +++ b/.github/workflows/msbuild.yml @@ -3,9 +3,9 @@ name: windows build workflows on: push: branches: [ "develop" ] - pull_request: - branches: [ "develop" ] - + paths: + - 'XEngine_Source/**' + - 'XEngine_Release/**' permissions: contents: read @@ -65,13 +65,27 @@ jobs: ./VSCopy_x86.bat ./XEngine_ServiceApp.exe -t shell: pwsh - - name: Conditional Step for x86 Debug - if: matrix.configuration == 'Debug' && matrix.platform == 'x86' + - name: Conditional Step for x64 Release + if: matrix.configuration == 'Release' && matrix.platform == 'x64' run: | - cp -r XEngine_Source/Debug/*.dll XEngine_Release/ - cp -r XEngine_Source/Debug/*.exe XEngine_Release/ - cp -r XEngine_Source/VSCopy_x86.bat XEngine_Release/ + cp -r XEngine_Source/x64/Release/*.dll XEngine_Release/ + cp -r XEngine_Source/x64/Release/*.exe XEngine_Release/ + cp -r XEngine_Source/VSCopy_x64.bat XEngine_Release/ cd XEngine_Release - ./VSCopy_x86.bat - ./XEngine_ServiceApp.exe -t + ./VSCopy_x64.bat shell: pwsh + + #将文件夹打包为 artifact + - name: Upload folder as artifact with x86 + if: matrix.configuration == 'Release' && matrix.platform == 'x86' + uses: actions/upload-artifact@v4 + with: + name: XEngine_ProxyServiceApp-x86-Windows + path: XEngine_Release/ + + - name: Upload folder as artifact with x64 + if: matrix.configuration == 'Release' && matrix.platform == 'x64' + uses: actions/upload-artifact@v4 + with: + name: XEngine_ProxyServiceApp-x64-Windows + path: XEngine_Release/ \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000000000000000000000000000000000..d09ba8a5ce7c930c4ed31c868be9124dae6dc629 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,94 @@ +name: release packet + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + + steps: + # 检出代码并包含标签 + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Download linuxbuild + uses: dawidd6/action-download-artifact@v6 + with: + workflow: linuxbuild.yml + workflow_conclusion: success + check_artifacts: false + skip_unpack: true + if_no_artifact_found: fail + path: ./ + - name: Download macbuild + uses: dawidd6/action-download-artifact@v6 + with: + workflow: macbuild.yml + workflow_conclusion: success + check_artifacts: false + skip_unpack: true + if_no_artifact_found: fail + path: ./ + - name: Download msbuild + uses: dawidd6/action-download-artifact@v6 + with: + workflow: msbuild.yml + workflow_conclusion: success + check_artifacts: false + skip_unpack: true + if_no_artifact_found: fail + path: ./ + + - name: Display structure of downloaded files + run: ls -al ./ + + - name: Get current version and increment X + id: versioning + run: | + # 获取最新的标签,假设标签形式为 V1.X.0.1001 + latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`) + echo "Latest tag: $latest_tag" + # 提取 X 的值并递增 + major=$(echo $latest_tag | cut -d '.' -f 1) + minor=$(echo $latest_tag | cut -d '.' -f 2) + patch=$(echo $latest_tag | cut -d '.' -f 3) + build=$(echo $latest_tag | cut -d '.' -f 4) + + new_minor=$((minor + 1)) + new_version="$major.$new_minor.$patch.$build" + echo "New version: $new_version" + echo "new_tag=$new_version" >> $GITHUB_OUTPUT + echo "prev_tag=$latest_tag" >> $GITHUB_OUTPUT + + - name: Create and push new tag + run: | + git tag ${{ steps.versioning.outputs.new_tag }} + git push origin ${{ steps.versioning.outputs.new_tag }} + + - name: Generate release notes + run: | + logs=$(git log ${{ steps.versioning.outputs.prev_tag }}..${{ steps.versioning.outputs.new_tag }} --pretty=format:"* %H - %s - %an" --no-merges) + release_notes=$(echo "$logs" | sed 's/ qyt$/ @xengine-qyt/') + echo "$release_notes" + echo "$release_notes" > release_notes.txt + + - name: Release + uses: softprops/action-gh-release@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + draft: false + prerelease: false + tag_name: ${{ steps.versioning.outputs.new_tag }} + name: XEngine_ProxyServiceApp ${{ steps.versioning.outputs.new_tag }} + body_path: release_notes.txt + files: | + ./XEngine_ProxyServiceApp-x64-Mac.zip + ./XEngine_ProxyServiceApp-x64-Ubuntu.zip + ./XEngine_ProxyServiceApp-x64-Windows.zip + ./XEngine_ProxyServiceApp-x86-Windows.zip diff --git a/CHANGELOG b/CHANGELOG index 415df748293d456fadfb4211ee3092b8389f9b76..a4cf3045245142304346ddd190746ce8ba558d7e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,29 @@ +XEngine_ProxyServer V1.10.0.1001 + +增加:WINDOWS COREDUMP支持 +增加:工作流支持 +增加:启动测试参数 +优化:启动参数解析 +修改:启动测试的时候关闭报告 +修改:forward转发的绑定修改为命名绑定,并且增加了匿名绑定支持 +修正:子模块文件件不正确的问题 +修正:MACOS下编译问题 +修正:某些时候退出崩溃 +修正:forward删除目标客户端导致的问题 +删除:getchar 函数启动的时候 + +added:crash core-dump support for windows +added:workflows +added:test start mode parameter +improved:start parameter parse +modify:disable report info when test start +modify:bind modify to named and add anonymous for forward of bind +fixed:sub module dir is incorrect +fixed:make build error on mac +fixed:crashed when exist +fixed:delete dest client for forward +delete:getchar() when test start +====================================================================================== XEngine_ProxyServer V1.9.0.1001 增加:XENGINE版本处理和退出等待功能 diff --git a/README.en.md b/README.en.md index df732360914687e7304a8f614a88685b724630cd..7d67e4d03ec4da2d8f33e783690746bde473d2ee 100644 --- a/README.en.md +++ b/README.en.md @@ -6,6 +6,9 @@ As long as the repository is not in suspended state, we will maintain and develo c c++ SOCKS5代理服务 HTTP Tunnel隧道代理服务 tcp转发服务 c c++ Socks5 Proxy Service,HTTP Tunnel Proxy Service,tcp forward service +## Notice +Starting from 2024.11.15, the compiled release version will only be released on github. + #### Software Architecture the software developed based on xengine,using c/c++ development This software is a standard proxy server that supports Socks5 and HTTP tunnel proxy diff --git a/README.md b/README.md index ac561080396ab1771ce8f2e66e3c10eef3cf9a1f..a91e83743c52d7ad84478f9ba1098652b0dcc32e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,9 @@ 本仓库有开发和主分支,如果要使用,请使用master分支下的代码 只要仓库不是在暂停状态,那么就会有人一直维护和开发,请放心使用 +## 注意 +自2024.11.15起.编译发布版本将只在github上面发布. + ## 介绍 c c++ SOCKS5代理服务 HTTP Tunnel隧道代理服务 tcp转发服务 c c++ Socks5 Proxy Service,HTTP Tunnel Proxy Service,tcp forward service diff --git a/XEngine_Docment/Docment_en.docx b/XEngine_Docment/Docment_en.docx index be69862b05b8922a85d98c673a3687e6e3e42c85..a0afb1db150c7e7c91d6d441ee6cdcff7a0c886f 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 06614d7f7afe5099396659f295d57201fa1ec119..caf213bcc68046e254ec474c3aa52b568115d28a 100644 Binary files a/XEngine_Docment/Docment_zh.docx and b/XEngine_Docment/Docment_zh.docx differ diff --git a/XEngine_Release/XEngine_Config/XEngine_Version.json b/XEngine_Release/XEngine_Config/XEngine_Version.json index 32db86b73785353547902b309a25ecc0f201f4a5..ca6ada94d41200c2b8b5ab046c7ebcd541caf0c2 100644 --- a/XEngine_Release/XEngine_Config/XEngine_Version.json +++ b/XEngine_Release/XEngine_Config/XEngine_Version.json @@ -1,5 +1,6 @@ { "XVer": [ + "1.10.0.1001 Build20241115", "1.9.0.1001 Build20240910", "1.8.0.1001 Build20240522", "1.7.1.1001 Build20240305", diff --git a/XEngine_Release/XEngine_Log/.gitignore b/XEngine_Release/XEngine_Coredump/keepfile similarity index 100% rename from XEngine_Release/XEngine_Log/.gitignore rename to XEngine_Release/XEngine_Coredump/keepfile diff --git a/XEngine_Release/XEngine_Log/keepfile b/XEngine_Release/XEngine_Log/keepfile new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/XEngine_Source/XEngine_Depend b/XEngine_Source/XEngine_Depend index a7b440b0c648f37d291ae019b67a482111e1a70b..1c1452f13720d22834e09c7e4e78042698411486 160000 --- a/XEngine_Source/XEngine_Depend +++ b/XEngine_Source/XEngine_Depend @@ -1 +1 @@ -Subproject commit a7b440b0c648f37d291ae019b67a482111e1a70b +Subproject commit 1c1452f13720d22834e09c7e4e78042698411486 diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Define.h b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Define.h index 22e402ac8d186ca4c57287b5490de93824069143..144bc92d9566c7d21462298e8ae75c6e5b0ea073 100644 --- a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Define.h +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Define.h @@ -23,7 +23,9 @@ typedef struct XENGINE_PROTOCOL_USERAUTH st_UserAuth; XCHAR tszSrcAddr[128]; XCHAR tszDstAddr[128]; + XNETHANDLE xhClient; bool bForward; + bool bAnony; }SESSION_FORWARD, * LPSESSION_FORWARD; ////////////////////////////////////////////////////////////////////////// // 导出函数 @@ -76,8 +78,8 @@ extern "C" bool ModuleSession_Forward_Insert(LPCXSTR lpszAddr, XENGINE_PROTOCOL_ *********************************************************************/ extern "C" bool ModuleSession_Forward_List(SESSION_FORWARD * **pppSt_ListUser, int* pInt_Count, LPCXSTR lpszAddr = NULL); /******************************************************************** -函数名称:ModuleSession_Forward_Bind -函数功能:绑定转发需求 +函数名称:ModuleSession_Forward_BindNamed +函数功能:命名绑定转发需求 参数.一:lpszSrcAddr In/Out:In 类型:常量字符指针 @@ -93,7 +95,31 @@ extern "C" bool ModuleSession_Forward_List(SESSION_FORWARD * **pppSt_ListUser, i 意思:是否成功 备注: *********************************************************************/ -extern "C" bool ModuleSession_Forward_Bind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr); +extern "C" bool ModuleSession_Forward_BindNamed(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr); +/******************************************************************** +函数名称:ModuleSession_Forward_BindNamed +函数功能:匿名绑定转发需求 + 参数.一:lpszSrcAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入绑定的原始地址 + 参数.二:lpszDstAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输出绑定的目标地址 + 参数.三:xhClient + In/Out:In + 类型:句柄 + 可空:N + 意思:输入绑定的客户端 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool ModuleSession_Forward_BindAnony(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr, XNETHANDLE xhClient); /******************************************************************** 函数名称:ModuleSession_Forward_Delete 函数功能:删除用户 @@ -132,7 +158,6 @@ extern "C" bool ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHAR * ptszDstAd 备注: *********************************************************************/ extern "C" bool ModuleSession_Forward_Get(LPCXSTR lpszAddr, XCHAR* ptszDstAddr = NULL); - /************************************************************************/ /* SOCK代理服务器导出函数 */ /************************************************************************/ diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.cpp b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.cpp index 5da113894655cc4fbc9284d47469b0169d9eea5f..424439c07c7ae66471f7cfa8bc065bad702b6a97 100644 --- a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.cpp +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.cpp @@ -130,8 +130,8 @@ bool CModuleSession_Forward::ModuleSession_Forward_List(SESSION_FORWARD*** pppSt return true; } /******************************************************************** -函数名称:ModuleSession_Forward_Bind -函数功能:绑定转发需求 +函数名称:ModuleSession_Forward_BindNamed +函数功能:命名绑定转发需求 参数.一:lpszSrcAddr In/Out:In 类型:常量字符指针 @@ -147,7 +147,7 @@ bool CModuleSession_Forward::ModuleSession_Forward_List(SESSION_FORWARD*** pppSt 意思:是否成功 备注: *********************************************************************/ -bool CModuleSession_Forward::ModuleSession_Forward_Bind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr) +bool CModuleSession_Forward::ModuleSession_Forward_BindNamed(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr) { Session_IsErrorOccur = false; @@ -186,6 +186,64 @@ bool CModuleSession_Forward::ModuleSession_Forward_Bind(LPCXSTR lpszSrcAddr, LPC return true; } /******************************************************************** +函数名称:ModuleSession_Forward_BindNamed +函数功能:匿名绑定转发需求 + 参数.一:lpszSrcAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入绑定的原始地址 + 参数.二:lpszDstAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输出绑定的目标地址 + 参数.三:xhClient + In/Out:In + 类型:句柄 + 可空:N + 意思:输入绑定的客户端 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CModuleSession_Forward::ModuleSession_Forward_BindAnony(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr, XNETHANDLE xhClient) +{ + Session_IsErrorOccur = false; + + if ((NULL == lpszSrcAddr) || (NULL == lpszDstAddr)) + { + Session_IsErrorOccur = true; + Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_PARAMENT; + return false; + } + st_Locker.lock_shared(); + //查找 + auto stl_MapIterator = stl_MapSession.find(lpszSrcAddr); + if (stl_MapIterator == stl_MapSession.end()) + { + Session_IsErrorOccur = true; + Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_NOTFOUND; + st_Locker.unlock_shared(); + return false; + } + //如果设置过,不允许在设置 + if (stl_MapIterator->second.bForward) + { + Session_IsErrorOccur = true; + Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_BIND; + st_Locker.unlock_shared(); + return false; + } + stl_MapIterator->second.xhClient = xhClient; + stl_MapIterator->second.bAnony = true; + stl_MapIterator->second.bForward = true; + _tcsxcpy(stl_MapIterator->second.tszDstAddr, lpszDstAddr); + st_Locker.unlock_shared(); + return true; +} +/******************************************************************** 函数名称:ModuleSession_Forward_Delete 函数功能:删除用户 参数.一:lpszAddr @@ -231,11 +289,14 @@ bool CModuleSession_Forward::ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHA _tcsxcpy(ptszDstAddr, stl_MapSrcIterator->second.tszDstAddr); } - auto stl_MapDstIterator = stl_MapSession.find(stl_MapSrcIterator->second.tszSrcAddr); - if (stl_MapDstIterator == stl_MapSession.end()) + if (!stl_MapSrcIterator->second.bAnony) { - stl_MapDstIterator->second.bForward = false; - memset(stl_MapDstIterator->second.tszDstAddr, '\0', sizeof(stl_MapDstIterator->second.tszDstAddr)); + auto stl_MapDstIterator = stl_MapSession.find(stl_MapSrcIterator->second.tszDstAddr); + if (stl_MapDstIterator == stl_MapSession.end()) + { + stl_MapDstIterator->second.bForward = false; + memset(stl_MapDstIterator->second.tszDstAddr, '\0', sizeof(stl_MapDstIterator->second.tszDstAddr)); + } } } stl_MapSession.erase(stl_MapSrcIterator); diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.h b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.h index dfc6b6821a666a325c30feec0c127770ad64987a..0a689fe8dc632eabab4e3e4761497b6ae72c84e8 100644 --- a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.h +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.h @@ -19,7 +19,8 @@ public: public: bool ModuleSession_Forward_Insert(LPCXSTR lpszAddr, XENGINE_PROTOCOL_USERAUTH* pSt_UserAuth); bool ModuleSession_Forward_List(SESSION_FORWARD*** pppSt_ListUser, int* pInt_Count, LPCXSTR lpszAddr = NULL); - bool ModuleSession_Forward_Bind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr); + bool ModuleSession_Forward_BindNamed(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr); + bool ModuleSession_Forward_BindAnony(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr, XNETHANDLE xhClient); bool ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHAR* ptszDstAddr = NULL); bool ModuleSession_Forward_Get(LPCXSTR lpszAddr, XCHAR* ptszDstAddr = NULL); private: diff --git a/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.def b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.def index 1b27ad0b9908638464220ca084e0dd19f0e0b73c..984d52fd6cc0c386775a4092b3e0b5f894e8c9ba 100644 --- a/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.def +++ b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.def @@ -14,7 +14,8 @@ EXPORTS ModuleSession_Forward_Insert ModuleSession_Forward_List - ModuleSession_Forward_Bind + ModuleSession_Forward_BindNamed + ModuleSession_Forward_BindAnony ModuleSession_Forward_Delete ModuleSession_Forward_Get diff --git a/XEngine_Source/XEngine_ModuleSession/pch.cpp b/XEngine_Source/XEngine_ModuleSession/pch.cpp index d617cfd611ad2354fa255eeffa0ca898edf8fa4c..06445061c9fd124707aa3691ccb2742ed2114f22 100644 --- a/XEngine_Source/XEngine_ModuleSession/pch.cpp +++ b/XEngine_Source/XEngine_ModuleSession/pch.cpp @@ -41,9 +41,13 @@ extern "C" bool ModuleSession_Forward_List(SESSION_FORWARD * **pppSt_ListUser, i { return m_Forward.ModuleSession_Forward_List(pppSt_ListUser, pInt_Count, lpszAddr); } -extern "C" bool ModuleSession_Forward_Bind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr) +extern "C" bool ModuleSession_Forward_BindNamed(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr) { - return m_Forward.ModuleSession_Forward_Bind(lpszSrcAddr, lpszDstAddr); + return m_Forward.ModuleSession_Forward_BindNamed(lpszSrcAddr, lpszDstAddr); +} +extern "C" bool ModuleSession_Forward_BindAnony(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr, XNETHANDLE xhClient) +{ + return m_Forward.ModuleSession_Forward_BindAnony(lpszSrcAddr, lpszDstAddr, xhClient); } extern "C" bool ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHAR * ptszDstAddr) { diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp index 9894a4cc5ae3ac2dea078a45440f009813cab6b2..877dc52c93bb1df8ce4e62f3ee00285c4b14e22e 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp @@ -35,7 +35,7 @@ bool XEngine_Configure_Parament(int argc, char** argv, XENGINE_SERVICECONFIG* pS } else if (0 == _tcsxcmp("-d", argv[i])) { - pSt_Configure->bDeamon = _ttxoi(argv[i + 1]); + pSt_Configure->bDeamon = _ttxoi(argv[++i]); } else if (0 == _tcsxcmp("-v", argv[i])) { diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.cpp index 5c81d3dd8c1adcb637c23940c0890307cccb3ada..e204a13466e6a1d00e64c61d676226453e18393a 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.cpp @@ -71,7 +71,7 @@ bool XEngine_Forward_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int n { pSt_ProtocolHdr->wReserve = 401; pSt_ProtocolHdr->unPacketSize = 0; - pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_BINDREP; + pSt_ProtocolHdr->unOperatorCode = pSt_ProtocolHdr->unOperatorCode + 1; XEngine_Network_Send(lpszClientAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,请求转发协议:%d 失败,因为没有登录"), lpszClientAddr, pSt_ProtocolHdr->unOperatorCode); return false; @@ -91,7 +91,7 @@ bool XEngine_Forward_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int n XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_CLIENT_NETTYPE_FORWARD); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,请求可用转发列表成功"), lpszClientAddr); } - else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_BINDREQ == pSt_ProtocolHdr->unOperatorCode) + else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_NAMEDREQ == pSt_ProtocolHdr->unOperatorCode) { XCHAR tszSrcAddr[128]; XCHAR tszDstAddr[128]; @@ -100,13 +100,13 @@ bool XEngine_Forward_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int n memset(tszDstAddr, '\0', sizeof(tszDstAddr)); ModuleProtocol_Parse_ForwardBind(lpszMsgBuffer, nMsgLen, tszSrcAddr, tszDstAddr); - if (!ModuleSession_Forward_Bind(lpszClientAddr, tszDstAddr)) + if (!ModuleSession_Forward_BindNamed(lpszClientAddr, tszDstAddr)) { pSt_ProtocolHdr->wReserve = 404; pSt_ProtocolHdr->unPacketSize = 0; - pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_BINDREP; + pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_NAMEDREP; XEngine_Network_Send(lpszClientAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,请求绑定转发地址:%s 失败,错误:%lX"), lpszClientAddr, tszDstAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,请求命名绑定转发地址:%s 失败,错误:%lX"), lpszClientAddr, tszDstAddr); return false; } //先告知对方要转发数据 @@ -114,11 +114,74 @@ bool XEngine_Forward_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int n pSt_ProtocolHdr->unPacketSize = 0; XEngine_Network_Send(tszDstAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); //最后返回结果 - pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_BINDREP; + pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_NAMEDREP; XEngine_Network_Send(lpszClientAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,请求绑定转发地址:%s 成功"), lpszClientAddr, tszDstAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,请求命名绑定转发地址:%s 成功"), lpszClientAddr, tszDstAddr); + } + else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_ANONYREQ == pSt_ProtocolHdr->unOperatorCode) + { + XCHAR tszSrcAddr[128]; + XCHAR tszDstAddr[128]; + + memset(tszSrcAddr, '\0', sizeof(tszSrcAddr)); + memset(tszDstAddr, '\0', sizeof(tszDstAddr)); + + ModuleProtocol_Parse_ForwardBind(lpszMsgBuffer, nMsgLen, tszSrcAddr, tszDstAddr); + //匿名绑定,请求连接 + int nPort = 0; + XNETHANDLE xhClient = 0; + BaseLib_OperatorIPAddr_SegAddr(tszDstAddr, &nPort); + if (!XClient_TCPSelect_InsertEx(xhForwardClient, &xhClient, tszDstAddr, nPort)) + { + pSt_ProtocolHdr->wReserve = 500; + pSt_ProtocolHdr->unPacketSize = 0; + pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_ANONYREP; + XEngine_Network_Send(lpszClientAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,请求匿名绑定转发地址:%s 失败,网络连接错误,错误码:%lX"), lpszClientAddr, tszDstAddr, XClient_GetLastError()); + return false; + } + if (!ModuleSession_Forward_BindAnony(lpszClientAddr, tszDstAddr, xhClient)) + { + pSt_ProtocolHdr->wReserve = 404; + pSt_ProtocolHdr->unPacketSize = 0; + pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_ANONYREP; + XEngine_Network_Send(lpszClientAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,请求匿名绑定转发地址:%s 失败,错误:%lX"), lpszClientAddr, tszDstAddr); + return false; + } + //返回结果 + pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_ANONYREP; + XEngine_Network_Send(lpszClientAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,请求匿名绑定转发地址:%s 成功"), lpszClientAddr, tszDstAddr); } } return true; +} +void CALLBACK XEngine_Forward_CBRecv(XHANDLE xhToken, XNETHANDLE xhClient, XSOCKET hSocket, ENUM_XCLIENT_SOCKET_EVENTS enTCPClientEvents, LPCXSTR lpszMsgBuffer, int nLen, XPVOID lParam) +{ + int nListCount = 0; + SESSION_FORWARD** ppSt_ClientList; + ModuleSession_Forward_List(&ppSt_ClientList, &nListCount); + for (int i = 0; i < nListCount; i++) + { + if (xhClient == ppSt_ClientList[i]->xhClient) + { + if (ENUM_XCLIENT_SOCKET_EVENT_RECV == enTCPClientEvents) + { + if (!XEngine_Network_Send(ppSt_ClientList[i]->tszSrcAddr, lpszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_FORWARD)) + { + SocketOpt_HeartBeat_ForceOutAddrEx(xhForwardHeart, ppSt_ClientList[i]->tszSrcAddr); + } + } + else if (ENUM_XCLIENT_SOCKET_EVENT_CLOSE == enTCPClientEvents) + { + //退出处理 + SocketOpt_HeartBeat_ForceOutAddrEx(xhForwardHeart, ppSt_ClientList[i]->tszSrcAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,离开服务器,客户端主动断开"), ppSt_ClientList[i]->tszSrcAddr); + } + break; + } + } + BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ClientList, nListCount); } \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.h b/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.h index cd3f47020cadd82998b1ad3a753e03a3a72ea563..092bddeb77f31d40194f4e352c0229ee11f7aba0 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.h @@ -12,4 +12,5 @@ *********************************************************************/ //任务处理相关函数,处理包的内容 XHTHREAD CALLBACK XEngine_Forward_Thread(XPVOID lParam); -bool XEngine_Forward_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr); \ No newline at end of file +bool XEngine_Forward_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr); +void CALLBACK XEngine_Forward_CBRecv(XHANDLE xhToken, XNETHANDLE xhClient, XSOCKET hSocket, ENUM_XCLIENT_SOCKET_EVENTS enTCPClientEvents, LPCXSTR lpszMsgBuffer, int nLen, XPVOID lParam); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h index f0f4e1728e76183102a4d2a26c578739945b0d41..720ba6077c62605b78ebd55c78df06e213602e89 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h @@ -11,6 +11,7 @@ #ifdef _MSC_BUILD #include #include +#include #else #include #include @@ -87,6 +88,7 @@ extern XHANDLE xhForwardSocket; extern XHANDLE xhForwardHeart; extern XHANDLE xhForwardPacket; extern XHANDLE xhForwardPool; +extern XHANDLE xhForwardClient; //配置文件 extern XENGINE_SERVICECONFIG st_ServiceConfig; @@ -144,4 +146,5 @@ typedef struct #pragma comment(lib,"XEngine_HelpComponents/HelpComponents_Packets.lib") #pragma comment(lib,"XEngine_RfcComponents/RfcComponents_ProxyProtocol.lib") #pragma comment(lib,"Ws2_32.lib") +#pragma comment(lib,"Dbghelp.lib") #endif \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp index 0d9b5d2ac10a70e01b881ffaaed809f033924c4b..5c053b5fe1325d126f9fa0880abd4076da379e8a 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp @@ -16,6 +16,7 @@ XHANDLE xhForwardSocket = NULL; XHANDLE xhForwardHeart = NULL; XHANDLE xhForwardPacket = NULL; XHANDLE xhForwardPool = NULL; +XHANDLE xhForwardClient = NULL; //配置文件 XENGINE_SERVICECONFIG st_ServiceConfig; @@ -76,12 +77,37 @@ static int ServiceApp_Deamon() #endif return 0; } +#ifdef _MSC_BUILD +LONG WINAPI Coredump_ExceptionFilter(EXCEPTION_POINTERS* pExceptionPointers) +{ + static int i = 0; + XCHAR tszFileStr[MAX_PATH] = {}; + XCHAR tszTimeStr[128] = {}; + BaseLib_OperatorTime_TimeToStr(tszTimeStr); + _xstprintf(tszFileStr, _X("./XEngine_Coredump/dumpfile_%s_%d.dmp"), tszTimeStr, i++); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_FATAL, _X("主程序:软件崩溃,写入dump:%s"), tszFileStr); + HANDLE hDumpFile = CreateFileA(tszFileStr, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (INVALID_HANDLE_VALUE != hDumpFile) + { + MINIDUMP_EXCEPTION_INFORMATION st_DumpInfo = {}; + st_DumpInfo.ExceptionPointers = pExceptionPointers; + st_DumpInfo.ThreadId = GetCurrentThreadId(); + st_DumpInfo.ClientPointers = TRUE; + // 写入 dump 文件 + MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, MiniDumpNormal, &st_DumpInfo, NULL, NULL); + CloseHandle(hDumpFile); + } + return EXCEPTION_EXECUTE_HANDLER; +} +#endif int main(int argc, char** argv) { #ifdef _MSC_BUILD WSADATA st_WSAData; WSAStartup(MAKEWORD(2, 2), &st_WSAData); + + SetUnhandledExceptionFilter(Coredump_ExceptionFilter); #endif bIsRun = true; int nRet = 0; @@ -261,6 +287,14 @@ int main(int argc, char** argv) goto XENGINE_SERVICEAPP_EXIT; } XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动Forward线程池服务成功,启动个数:%d"), st_ServiceConfig.st_XMax.nForwardThread); + //客户端 + xhForwardClient = XClient_TCPSelect_StartEx(XEngine_Forward_CBRecv); + if (NULL == xhForwardClient) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动Forward客户端服务失败,错误:%lX"), XClient_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动Forward客户端服务成功")); } else { @@ -287,7 +321,7 @@ int main(int argc, char** argv) XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("所有服务成功启动,服务运行中,XEngine版本:%s%s,服务版本:%s,发行次数:%d。。。"), BaseLib_OperatorVer_XNumberStr(), BaseLib_OperatorVer_XTypeStr(), st_ServiceConfig.st_XVer.pStl_ListVer->front().c_str(), st_ServiceConfig.st_XVer.pStl_ListVer->size()); - while (bIsRun) + while (true) { if (bIsTest) { diff --git a/XEngine_Source/XEngine_UserProtocol.h b/XEngine_Source/XEngine_UserProtocol.h index 82927328f83f183b74fd18b962314536ee58aa1c..6d0c5113bed481d652d816acd2e4450c116bab79 100644 --- a/XEngine_Source/XEngine_UserProtocol.h +++ b/XEngine_Source/XEngine_UserProtocol.h @@ -22,8 +22,10 @@ typedef enum en_XEngine_XUser_Protocol #define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LOGREP 0xE1001 #define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LISTREQ 0xE1002 //列表请求 #define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LISTREP 0xE1003 -#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_BINDREQ 0xE1004 //绑定请求 -#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_BINDREP 0xE1005 +#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_NAMEDREQ 0xE1004 //命名请求 +#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_NAMEDREP 0xE1005 +#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_ANONYREQ 0xE1006 //匿名转发 +#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_ANONYREP 0xE1007 /////////////////////////////////////////////////////////////////////////// // 导出的数据结构 ///////////////////////////////////////////////////////////////////////////