diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..1716d18 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,62 @@ +name: CodeQL Advanced + +on: + push: + branches: + - 'develop' + paths: + - 'XEngine_Source/**' + - 'XEngine_Release/**' + - '.github/**' + +jobs: + analyze: + runs-on: ubuntu-24.04 + permissions: + security-events: write + packages: read + actions: read + contents: read + + strategy: + fail-fast: false + matrix: + include: + - language: c-cpp + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: 'develop' + + - name: Checkout dependency repository (xengine) + uses: actions/checkout@v4 + with: + repository: libxengine/libxengine + path: libxengine + + - name: sub module checkout (opensource) + run: | + git submodule init + git submodule update + + - name: Set up Dependency Environment + run: | + cd libxengine + chmod +x ./XEngine_LINEnv.sh + sudo ./XEngine_LINEnv.sh -i 3 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + + - name: make + run: | + cd XEngine_Source + make + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{ matrix.language }}" diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml new file mode 100644 index 0000000..279b03f --- /dev/null +++ b/.github/workflows/cppcheck.yml @@ -0,0 +1,35 @@ +name: cpp check workflows + +on: + push: + branches: + - 'develop' + paths: + - 'XEngine_Source/**' + - 'XEngine_Release/**' + - '.github/**' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout main repository code + uses: actions/checkout@v4 + with: + ref: 'develop' + + - name: Create static_analysis directory + run: mkdir -p static_analysis + + - name: Run Cppcheck + run: | + sudo apt-get install -y cppcheck + cppcheck --enable=all --language=c++ --std=c++20 ./XEngine_Source/ --output-file=static_analysis/log.xml --xml + continue-on-error: true + + - name: Upload Cppcheck Results + uses: actions/upload-artifact@v4 + with: + name: cppcheck_results + path: static_analysis/log.xml \ No newline at end of file diff --git a/.github/workflows/macbuild.yml b/.github/workflows/macbuild.yml index a9ba22c..9b86023 100644 --- a/.github/workflows/macbuild.yml +++ b/.github/workflows/macbuild.yml @@ -2,13 +2,12 @@ name: macos build workflows on: push: - branches: [ "develop" ] + branches: + - 'develop' paths: - 'XEngine_Source/**' - 'XEngine_Release/**' - -permissions: - contents: read + - '.github/**' jobs: build: @@ -16,6 +15,7 @@ jobs: matrix: include: - os: macos-13 + - os: macos-14 runs-on: ${{ matrix.os }} steps: @@ -30,7 +30,6 @@ jobs: with: repository: libxengine/libxengine path: libxengine - ref: 'master' - name: sub module checkout (opensource) run: | @@ -40,14 +39,30 @@ jobs: - name: brew install run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - # 设置依赖库的环境变量 - - name: Set up Dependency Environment Variables + - name: Set up Dependency x86_64 Environment + if: matrix.os == 'macos-13' run: | cd libxengine chmod 777 * ./XEngine_LINEnv.sh -i 3 - cd .. - #编译 + - name: Set up Dependency Arm64 Environment + if: matrix.os == 'macos-14' + run: | + cd libxengine + chmod 777 * + ./XEngine_LINEnv.sh -i 0 + + latest_tag=$(git ls-remote --tags --sort="v:refname" https://github.com/libxengine/libxengine.git | awk '{print $2}' | sed 's/refs\/tags\///' | tail -n 1) + + wget https://github.com/libxengine/libxengine/releases/download/$latest_tag/XEngine_Mac_Arm64.zip + unzip ./XEngine_Mac_Arm64.zip -d ./XEngine_Mac_Arm64 + cd XEngine_Mac_Arm64 + + sudo mkdir -p /usr/local/include + sudo mkdir -p /usr/local/lib + sudo cp -rf ./XEngine_Include /usr/local/include + sudo find ./XEngine_Mac -name "*.dylib" -exec cp {} /usr/local/lib \; + - name: make debug run: | cd XEngine_Source @@ -65,8 +80,15 @@ jobs: cd XEngine_Release ./XEngine_ProxyServiceApp -t - - name: Upload folder as artifact with mac + - name: Upload folder as artifact with mac x64 + if: matrix.os == 'macos-13' + uses: actions/upload-artifact@v4 + with: + name: XEngine_ProxyServiceApp-x86_64-Mac + path: XEngine_Release/ + - name: Upload folder as artifact with mac arm + if: matrix.os == 'macos-14' uses: actions/upload-artifact@v4 with: - name: XEngine_ProxyServiceApp-x64-Mac + name: XEngine_ProxyServiceApp-Arm64-Mac path: XEngine_Release/ \ No newline at end of file diff --git a/.github/workflows/msbuild.yml b/.github/workflows/msbuild.yml index f449080..3437421 100644 --- a/.github/workflows/msbuild.yml +++ b/.github/workflows/msbuild.yml @@ -2,17 +2,16 @@ name: windows build workflows on: push: - branches: [ "develop" ] + branches: + - 'develop' paths: - 'XEngine_Source/**' - 'XEngine_Release/**' -permissions: - contents: read + - '.github/**' jobs: build: strategy: - # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. fail-fast: false matrix: configuration: [Debug ,Release] @@ -32,7 +31,7 @@ jobs: uses: actions/checkout@v4 with: repository: libxengine/libxengine - path: xengine + path: libxengine - name: sub module checkout (opensource) run: | @@ -40,21 +39,33 @@ jobs: git submodule update shell: pwsh - # 设置依赖库的环境变量 - - name: Set up Dependency Environment Variables + - name: Set up Dependency x86_64 Environment + if: matrix.platform == 'x64' run: | - echo "XENGINE_INCLUDE=${{ github.workspace }}/xengine" | Out-File -FilePath $env:GITHUB_ENV -Append - echo "XENGINE_LIB32=${{ github.workspace }}/xengine/XEngine_Windows/x86" | Out-File -FilePath $env:GITHUB_ENV -Append - echo "XENGINE_LIB64=${{ github.workspace }}/xengine/XEngine_Windows/x64" | Out-File -FilePath $env:GITHUB_ENV -Append + echo "XENGINE_INCLUDE=${{ github.workspace }}/libxengine" | Out-File -FilePath $env:GITHUB_ENV -Append + echo "XENGINE_LIB64=${{ github.workspace }}/libxengine/XEngine_Windows" | Out-File -FilePath $env:GITHUB_ENV -Append + shell: pwsh + - name: Set up Dependency x86_32 Environment + if: matrix.platform == 'x86' + run: | + $response = Invoke-RestMethod -Uri "https://api.github.com/repos/libxengine/libxengine/releases/latest" -Headers @{"Accept"="application/vnd.github.v3+json"} + $latest_tag = $response.tag_name + Write-Host "Latest Tag: $latest_tag" + + $url = "https://github.com/libxengine/libxengine/releases/download/$latest_tag/XEngine_Windows_x86-32.zip" + Invoke-WebRequest -Uri $url -OutFile "XEngine_Windows_x86-32.zip" + Expand-Archive -Path ./XEngine_Windows_x86-32.zip -DestinationPath ./XEngine_Windows -Force + + echo "XENGINE_INCLUDE=${{ github.workspace }}/XEngine_Windows" | Out-File -FilePath $env:GITHUB_ENV -Append + echo "XENGINE_LIB32=${{ github.workspace }}/XEngine_Windows/XEngine_Windows" | Out-File -FilePath $env:GITHUB_ENV -Append shell: pwsh - # 配置 MSBuild 的路径,准备构建 VC++ 项目 - name: Setup MSBuild uses: microsoft/setup-msbuild@v2 - #编译 + - name: Build Solution run: msbuild XEngine_Source/XEngine.sln /p:Configuration=${{ matrix.configuration }} /p:Platform=${{ matrix.platform }} - #测试 + - name: Conditional Step for x86 Release if: matrix.configuration == 'Release' && matrix.platform == 'x86' run: | @@ -74,18 +85,17 @@ jobs: cd XEngine_Release ./VSCopy_x64.bat shell: pwsh - - #将文件夹打包为 artifact + - name: Upload folder as artifact with x86 - if: matrix.configuration == 'Release' && matrix.platform == 'x86' + if: matrix.configuration == 'Release' && matrix.platform == 'x64' uses: actions/upload-artifact@v4 with: - name: XEngine_ProxyServiceApp-x86-Windows + name: XEngine_ProxyServiceApp-x86_32-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 + name: XEngine_ProxyServiceApp-x86_64-Windows path: XEngine_Release/ \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 57e4913..d557be6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,10 +17,10 @@ jobs: ref: 'develop' fetch-depth: 0 - - name: Download linuxbuild + - name: Download ubuntubuild uses: dawidd6/action-download-artifact@v6 with: - workflow: linuxbuild.yml + workflow: ubuntubuild.yml workflow_conclusion: success check_artifacts: false skip_unpack: true diff --git a/.github/workflows/linuxbuild.yml b/.github/workflows/ubuntubuild.yml similarity index 50% rename from .github/workflows/linuxbuild.yml rename to .github/workflows/ubuntubuild.yml index 42bc927..9859e2c 100644 --- a/.github/workflows/linuxbuild.yml +++ b/.github/workflows/ubuntubuild.yml @@ -2,22 +2,21 @@ name: ubuntu build workflows on: push: - branches: [ "develop" ] + branches: + - 'develop' paths: - 'XEngine_Source/**' - 'XEngine_Release/**' -permissions: - contents: read + - '.github/**' jobs: build: strategy: - # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. fail-fast: false matrix: include: - os: ubuntu-22.04 - #- os: ubuntu-24.04 + - os: ubuntu-24.04 runs-on: ${{ matrix.os }} steps: @@ -39,14 +38,28 @@ jobs: git submodule init git submodule update - # 设置依赖库的环境变量 - - name: Set up Dependency Environment Variables + - name: Set up Dependency ubuntu24.04 Environment + if: matrix.os == 'ubuntu-24.04' run: | cd libxengine chmod 777 * sudo ./XEngine_LINEnv.sh -i 3 - cd .. - #编译 + - name: Set up Dependency ubuntu22.04 Environment + if: matrix.os == 'ubuntu-22.04' + run: | + cd libxengine + chmod 777 * + sudo ./XEngine_LINEnv.sh -i 0 + + latest_tag=$(curl -s https://api.github.com/repos/libxengine/libxengine/releases/latest | jq -r .tag_name) + wget https://github.com/libxengine/libxengine/releases/download/$latest_tag/XEngine_UBuntu_22.04_x86-64.zip + unzip ./XEngine_UBuntu_22.04_x86-64.zip -d ./XEngine_UBuntu_22.04_x86-64 + cd XEngine_UBuntu_22.04_x86-64 + + sudo cp -rf ./XEngine_Include /usr/local/include + sudo find ./XEngine_Linux -name "*.so" -exec cp {} /usr/local/lib \; + sudo ldconfig + - name: make run: | cd XEngine_Source @@ -63,8 +76,15 @@ jobs: cd XEngine_Release ./XEngine_ProxyServiceApp -t - - name: Upload folder as artifact with ubuntu + - name: Upload folder as artifact with ubuntu22.04 + if: matrix.os == 'ubuntu-22.04' + uses: actions/upload-artifact@v4 + with: + name: XEngine_ProxyServiceApp-x86_64-Ubuntu-22.04 + path: XEngine_Release/ + - name: Upload folder as artifact with ubuntu24.04 + if: matrix.os == 'ubuntu-24.04' uses: actions/upload-artifact@v4 with: - name: XEngine_ProxyServiceApp-x64-Ubuntu + name: XEngine_ProxyServiceApp-x86_64-Ubuntu-24.04 path: XEngine_Release/ \ No newline at end of file diff --git a/CHANGELOG b/CHANGELOG index a4cf304..8e969be 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,31 @@ +XEngine_ProxyServer V1.11.0.1001 + +增加:全代理转发模式支持 +增加:设置日志级别参数支持 +更新:依赖库 +更新:匹配XEngineV9版本 +更新:VS2022字符集从ANSI修改为UNICODE +更新:编译器版本升级到C++20,C17 +修改:转发获取客户端类型 +修改:配置参数名称 +修正:打印乱码的问题 +修正:转发支持客户端没有正确释放的问题 +修正:日志级别和日志类型错误的问题 +删除:XEngine的版本判断代码 + +added:full proxy forward supported +added:set log level for parameter +update:depend library +update:match xengine v9 +update:character set modify to unicode from ansi on vs2022 +update:compiler version to c++20 and c17 +modify:get client info for forward get function +modify:configure field name +fixed:print Garbled characters +fixed:forward not free client when destroy +fixed:log level and type is incorrect +delete:xengine version judgment +====================================================================================== XEngine_ProxyServer V1.10.0.1001 增加:WINDOWS COREDUMP支持 diff --git a/README.en.md b/README.en.md index 7d67e4d..b57c461 100644 --- a/README.en.md +++ b/README.en.md @@ -1,13 +1,14 @@ +[中文](README.md) || [English](README.en.md) # XEngine_ProxyServer we have a development and a master branch. If you want to use it, please use the code under the master branch As long as the repository is not in suspended state, we will maintain and develop it all the time, please use it with confidence #### Description -c c++ SOCKS5代理服务 HTTP Tunnel隧道代理服务 tcp转发服务 -c c++ Socks5 Proxy Service,HTTP Tunnel Proxy Service,tcp forward service +c c++ SOCKS5代理服务,HTTP Tunnel隧道代理服务,tcp转发服务,负载代理转发 +c c++ Socks5 Proxy Service,HTTP Tunnel Proxy Service,tcp forward service,proxy forward service ## Notice -Starting from 2024.11.15, the compiled release version will only be released on github. +the compiled release version will only be released on github. #### Software Architecture the software developed based on xengine,using c/c++ development @@ -17,22 +18,23 @@ This software is a standard proxy server that supports Socks5 and HTTP tunnel pr this software support following features 1. SOCKS5 proxy 2. Tunnel proxy -3. TCP forward proxy +3. TCP forward proxy(forward) 4. operator log 5. encrypt Communication(planning) 6. load balanc(planning) 7. custom cert proxy protocol(planning) 8. multilevel proxy(planning) +9. lb proxy(proxy) ## install #### XEngine Evn -you must install XEngine,need V8.15 or above,install XEngine can be refer to xengine Readme docment -GITEE:https://gitee.com/xyry/libxengine -GITHUB:https://github.com/libxengine/xengine +you must install XEngine,need V9.x or above,install XEngine can be refer to xengine Readme docment +GITEE:https://gitee.com/libxengine/libxengine +GITHUB:https://github.com/libxengine/libxengine ##### fast to deployment -git clone https://gitee.com/xyry/libxengine.git or git clone https://github.com/libxengine/xengine.git +git clone https://gitee.com/libxengine/libxengine.git or git clone https://github.com/libxengine/libxengine.git window Exection XEngine_WINEnv.bat Linux Exection:sudo ./XEngine_LINEnv.sh -i 3 Macos Exection:./XEngine_LINEnv.sh -i 3 @@ -44,7 +46,7 @@ git submodule update #### Windows use vs open and compile,suport windows 7sp1 and above -Just Run it,use XEngine_AuthorizeApp +Just Run it #### Linux use makefile compile,UBUNTU22.04 x64 or RockyLinux9 x64 @@ -82,7 +84,7 @@ Refer to Linux You can refer to the document under the docment directory. It contains API protocol and service description. ## Test Server Address -Address:app.xyry.org +Address:app.libxengine.com Port:Socks5 5400,HTTP Tunnel 5401,Forward 5402 ## Participate in contribution diff --git a/README.md b/README.md index a91e837..1296815 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ 只要仓库不是在暂停状态,那么就会有人一直维护和开发,请放心使用 ## 注意 -自2024.11.15起.编译发布版本将只在github上面发布. +编译发布版本将只在github上面发布. ## 介绍 -c c++ SOCKS5代理服务 HTTP Tunnel隧道代理服务 tcp转发服务 -c c++ Socks5 Proxy Service,HTTP Tunnel Proxy Service,tcp forward service +c c++ SOCKS5代理服务,HTTP Tunnel隧道代理服务,tcp转发服务,负载代理转发 +c c++ Socks5 Proxy Service,HTTP Tunnel Proxy Service,tcp forward service,proxy forward service ## 软件架构 此软件基于XEngine开发.采用C/C++作为开发语言 @@ -17,22 +17,23 @@ c c++ Socks5 Proxy Service,HTTP Tunnel Proxy Service,tcp forward service 此软件支持以下特性 1. SOCKS5代理 2. Tunnel代理 -3. TCP数据转发服务 +3. TCP数据转发服务(forward) 4. 操作日志 5. 加密通信(planning) 6. 负载均衡(planning) 7. 自定义证书代理协议(planning) 8. 多级代理(planning) +9. 全负载代理(proxy) ## 安装教程 #### XEngine环境 -必须安装XEngine,版本需要V8.15或者以上版本,安装XEngine可以参考其Readme文档 -GITEE:https://gitee.com/xyry/libxengine -GITHUB:https://github.com/libxengine/xengine +必须安装XEngine,版本需要V9.x或者以上版本,安装XEngine可以参考其Readme文档 +GITEE:https://gitee.com/libxengine/libxengine +GITHUB:https://github.com/libxengine/libxengine ###### 快速部署 -git clone https://gitee.com/xyry/libxengine.git 或者 git clone https://github.com/libxengine/xengine.git +git clone https://gitee.com/libxengine/libxengine.git 或者 git clone https://github.com/libxengine/libxengine.git window执行XEngine_WINEnv.bat 脚本. Linux执行:sudo ./XEngine_LINEnv.sh -i 3 macos执行:./XEngine_LINEnv.sh -i 3 @@ -45,7 +46,7 @@ git submodule update #### Windows 使用VS打开并且编译,支持WINDOWS 7SP1以上系统 -直接运行即可,使用XEngine_AuthorizeApp +直接运行即可 #### Linux Linux使用Makefile编译,UBUNTU22.04 x64或者RockyLinux9 x64 @@ -86,7 +87,7 @@ make FLAGS=CleanAll 清理编译 你可以参考docment目录下的文档.里面包含了API协议和服务说明. ## 测试服务器 -地址:app.xyry.org +地址:app.libxengine.com 端口:Socks5 5400,HTTP Tunnel 5401,Forward 5402 ## 参与贡献 diff --git a/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.cpp b/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.cpp index 47247cc..c6282a8 100644 --- a/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.cpp +++ b/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.cpp @@ -5,7 +5,11 @@ #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") #pragma comment(lib,"XEngine_Client/XClient_Socket.lib") #pragma comment(lib,"XEngine_RfcComponents/RfcComponents_ProxyProtocol") -#pragma comment(lib,"../../XEngine_Source//Debug/jsoncpp") +#ifdef _WIN64 +#pragma comment(lib,"../../XEngine_Source/x64/Debug/jsoncpp") +#else +#pragma comment(lib,"../../XEngine_Source/Debug/jsoncpp") +#endif #endif #include #include @@ -26,7 +30,7 @@ //需要优先配置XEngine //WINDOWS支持VS2022 x86 debug 编译调试 //linux使用下面的命令编译 -//g++ -std=c++17 -Wall -g APPClient_ForwardExample.cpp -o APPClient_ForwardExample.exe -I ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -L ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -lXEngine_BaseLib -lXClient_Socket -lRfcComponents_ProxyProtocol -ljsoncpp +//g++ -std=c++20 -Wall -g APPClient_ForwardExample.cpp -o APPClient_ForwardExample.exe -I ../../XEngine_Source/XEngine_Depend/XEngine_Module/jsoncpp -L ../../XEngine_Source/XEngine_Depend/XEngine_Module/jsoncpp -lXEngine_BaseLib -lXClient_Socket -lRfcComponents_ProxyProtocol -ljsoncpp int main(int argc, char** argv) { @@ -79,7 +83,7 @@ int main(int argc, char** argv) printf("接受数据失败!\n"); return 0; } - BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + BaseLib_Memory_FreeCStyle((XPPMEM)&ptszMsgBuffer); //列举 st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER; st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL; @@ -109,7 +113,7 @@ int main(int argc, char** argv) { return false; } - BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + BaseLib_Memory_FreeCStyle((XPPMEM)&ptszMsgBuffer); if (st_JsonAddr["Count"].asInt() > 0) { //请求绑定 @@ -123,7 +127,7 @@ int main(int argc, char** argv) st_ProtocolHdr.byVersion = 0; st_ProtocolHdr.unPacketSize = st_JsonRoot.toStyledString().length(); st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_USER_FORWARD; - st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_BINDREQ; + st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_NAMEDREQ; if (!XClient_TCPSelect_SendMsg(m_Socket, (LPCXSTR)&st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR))) { printf("发送失败!\n"); @@ -140,7 +144,7 @@ int main(int argc, char** argv) printf("接受数据失败!\n"); return 0; } - BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + BaseLib_Memory_FreeCStyle((XPPMEM)&ptszMsgBuffer); //成功后发送数据 for (int i = 0; i < 10; i++) { @@ -172,12 +176,12 @@ int main(int argc, char** argv) if (XClient_TCPSelect_RecvPkt(m_Socket, &ptszMsgBuffer, &nMsgLen, &st_ProtocolHdr)) { //收到转发请求 - if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_BINDREQ == st_ProtocolHdr.unOperatorCode) + if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_NAMEDREQ == st_ProtocolHdr.unOperatorCode) { bGet = true; printf("get forward\n"); } - BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + BaseLib_Memory_FreeCStyle((XPPMEM)&ptszMsgBuffer); } } } diff --git a/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.vcxproj b/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.vcxproj index 7224528..26cfb62 100644 --- a/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.vcxproj +++ b/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.vcxproj @@ -71,9 +71,13 @@ - $(XEngine_Include);../../XEngine_Source/XEngine_ThirdPart/jsoncpp;$(IncludePath) + $(XEngine_Include);../../XEngine_Source/XEngine_Depend/XEngine_Module/jsoncpp;$(IncludePath) $(XEngine_Lib32);$(LibraryPath) + + $(XEngine_Include);../../XEngine_Source/XEngine_Depend/XEngine_Module/jsoncpp;$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) + Level3 @@ -106,7 +110,7 @@ Level3 true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + _DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true diff --git a/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj b/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj index 5c0ebb1..efc974a 100644 --- a/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj +++ b/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj @@ -80,6 +80,8 @@ true + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) false diff --git a/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.cpp b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.cpp index 4e39b0c..c308164 100644 --- a/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.cpp +++ b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.cpp @@ -23,7 +23,7 @@ //需要优先配置XEngine //WINDOWS支持VS2022 x86 debug 编译调试 //linux使用下面的命令编译 -//g++ -std=c++17 -Wall -g APPClient_TunnelExample.cpp -o APPClient_TunnelExample.exe -lXEngine_BaseLib -lXClient_Socket -lRfcComponents_ProxyProtocol +//g++ -std=c++20 -Wall -g APPClient_TunnelExample.cpp -o APPClient_TunnelExample.exe -lXEngine_BaseLib -lXClient_Socket -lRfcComponents_ProxyProtocol int main(int argc, char** argv) { #ifdef _MSC_BUILD diff --git a/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj index fb17144..44d08b2 100644 --- a/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj +++ b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj @@ -80,6 +80,8 @@ true + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) false diff --git a/XEngine_APPClient/VSCopy_x64.bat b/XEngine_APPClient/VSCopy_x64.bat new file mode 100644 index 0000000..80d6a7a --- /dev/null +++ b/XEngine_APPClient/VSCopy_x64.bat @@ -0,0 +1,4 @@ +copy /y "%XEngine_Lib64%\XEngine_BaseLib\XEngine_BaseLib.dll" "./" +copy /y "%XEngine_Lib64%\XEngine_BaseLib\XEngine_Algorithm.dll" "./" +copy /y "%XEngine_Lib64%\XEngine_Client\XClient_Socket.dll" "./" +copy /y "%XEngine_Lib64%\XEngine_RfcComponents\RfcComponents_ProxyProtocol.dll" "./" \ No newline at end of file diff --git a/XEngine_APPClient/VSCopy.bat b/XEngine_APPClient/VSCopy_x86.bat similarity index 100% rename from XEngine_APPClient/VSCopy.bat rename to XEngine_APPClient/VSCopy_x86.bat diff --git a/XEngine_Docment/Docment_en.docx b/XEngine_Docment/Docment_en.docx index a0afb1d..e23c4c8 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 caf213b..37f84a6 100644 Binary files a/XEngine_Docment/Docment_zh.docx and b/XEngine_Docment/Docment_zh.docx differ diff --git a/XEngine_Release/XEngine_Config/XEngine_Config.json b/XEngine_Release/XEngine_Config/XEngine_Config.json index 0850df7..1bd949f 100644 --- a/XEngine_Release/XEngine_Config/XEngine_Config.json +++ b/XEngine_Release/XEngine_Config/XEngine_Config.json @@ -1,9 +1,10 @@ { "tszIPAddr": "192.168.1.12", - "bDeamon": 0, + "bDeamon": false, "nSocksPort": 5400, "nTunnelPort": 5401, "nForwardPort": 5402, + "nProxyPort": 5403, "XMax": { "nMaxClient": 10000, "nMaxQueue": 10000, @@ -12,19 +13,25 @@ }, "XTime": { "nTimeCheck": 3, - "nSocksTimeOut": 5, - "nTunnelTimeOut": 5, - "nForwardTimeOut": 5 + "nSocksTimeout": 5, + "nTunnelTimeout": 5, + "nForwardTimeout": 5, + "nProxyTimeout": 5 }, "XLog": { "MaxSize": 1024000, "MaxCount": 10, - "LogLeave": 17, + "LogLeave": 32, + "LogType": 17, "tszLogFile": "./XEngine_Log/XEngine_ProxyServiceApp.log" }, "XReport":{ "bEnable":true, "tszAPIUrl":"http://app.xyry.org:5501/api?function=machine", "tszServiceName":"XEngine_ProxyServer" + }, + "XProxy": { + "bEnable": false, + "tszIPAddr": "10.0.2.6:5001" } } \ No newline at end of file diff --git a/XEngine_Release/XEngine_Config/XEngine_Version.json b/XEngine_Release/XEngine_Config/XEngine_Version.json index ca6ada9..9cf6e52 100644 --- a/XEngine_Release/XEngine_Config/XEngine_Version.json +++ b/XEngine_Release/XEngine_Config/XEngine_Version.json @@ -1,5 +1,6 @@ { "XVer": [ + "1.11.0.1001 Build20250121", "1.10.0.1001 Build20241115", "1.9.0.1001 Build20240910", "1.8.0.1001 Build20240522", diff --git a/XEngine_Source/VSCopy_Debug.bat b/XEngine_Source/VSCopy_Debug.bat index 8337251..130c6b7 100644 --- a/XEngine_Source/VSCopy_Debug.bat +++ b/XEngine_Source/VSCopy_Debug.bat @@ -1,7 +1,7 @@ copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_BaseLib.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_Algorithm.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_Core.dll" "./" -copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_OPenSsl.dll" "./" +copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_Cryption.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_ManagePool.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\XClient_Socket.dll" "./ @@ -9,6 +9,7 @@ copy /y "D:\XEngine\XEngine_SourceCode\Debug\XClient_APIHelp.dll" "./ copy /y "D:\XEngine\XEngine_SourceCode\Debug\NetHelp_APIHelp.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\NetHelp_XSocket.dll" "./" +copy /y "D:\XEngine\XEngine_SourceCode\Debug\NetHelp_APIAddr.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\HelpComponents_XLog.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\HelpComponents_Packets.dll" "./" diff --git a/XEngine_Source/VSCopy_x64.bat b/XEngine_Source/VSCopy_x64.bat index 9a90546..d88263a 100644 --- a/XEngine_Source/VSCopy_x64.bat +++ b/XEngine_Source/VSCopy_x64.bat @@ -1,13 +1,14 @@ 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_Core.dll" "./" -copy /y "%XEngine_Lib64%\XEngine_Core\XEngine_OPenSsl.dll" "./" +copy /y "%XEngine_Lib64%\XEngine_Core\XEngine_Cryption.dll" "./" copy /y "%XEngine_Lib64%\XEngine_Core\XEngine_ManagePool.dll" "./" copy /y "%XEngine_Lib64%\XEngine_Client\XClient_Socket.dll" "./" copy /y "%XEngine_Lib64%\XEngine_Client\XClient_APIHelp.dll" "./" copy /y "%XEngine_Lib64%\XEngine_NetHelp\NetHelp_APIHelp.dll" "./" +copy /y "%XEngine_Lib64%\XEngine_NetHelp\NetHelp_APIAddr.dll" "./" copy /y "%XEngine_Lib64%\XEngine_NetHelp\NetHelp_XSocket.dll" "./" copy /y "%XEngine_Lib64%\XEngine_HelpComponents\HelpComponents_XLog.dll" "./" diff --git a/XEngine_Source/VSCopy_x86.bat b/XEngine_Source/VSCopy_x86.bat index 122dbee..8fe09eb 100644 --- a/XEngine_Source/VSCopy_x86.bat +++ b/XEngine_Source/VSCopy_x86.bat @@ -1,11 +1,12 @@ 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_Core.dll" "./" -copy /y "%XEngine_Lib32%\XEngine_Core\XEngine_OPenSsl.dll" "./" +copy /y "%XEngine_Lib32%\XEngine_Core\XEngine_Cryption.dll" "./" copy /y "%XEngine_Lib32%\XEngine_Core\XEngine_ManagePool.dll" "./" copy /y "%XEngine_Lib32%\XEngine_Client\XClient_Socket.dll" "./" copy /y "%XEngine_Lib32%\XEngine_Client\XClient_APIHelp.dll" "./" +copy /y "%XEngine_Lib32%\XEngine_NetHelp\NetHelp_APIAddr.dll" "./" copy /y "%XEngine_Lib32%\XEngine_NetHelp\NetHelp_APIHelp.dll" "./" copy /y "%XEngine_Lib32%\XEngine_NetHelp\NetHelp_XSocket.dll" "./" diff --git a/XEngine_Source/XEngine_Depend b/XEngine_Source/XEngine_Depend index 1c1452f..bcf8d94 160000 --- a/XEngine_Source/XEngine_Depend +++ b/XEngine_Source/XEngine_Depend @@ -1 +1 @@ -Subproject commit 1c1452f13720d22834e09c7e4e78042698411486 +Subproject commit bcf8d946890a2f2fb39eec16e64a634a8ece52c7 diff --git a/XEngine_Source/XEngine_ModuleAuthorize/Makefile b/XEngine_Source/XEngine_ModuleAuthorize/Makefile index 7cc9377..ccadc88 100644 --- a/XEngine_Source/XEngine_ModuleAuthorize/Makefile +++ b/XEngine_Source/XEngine_ModuleAuthorize/Makefile @@ -1,4 +1,4 @@ -CC = g++ -Wall -std=c++17 -fPIC +CC = g++ -Wall -std=c++20 -fPIC PLATFORM = linux PLATVER = PLATDIR = diff --git a/XEngine_Source/XEngine_ModuleConfigure/Makefile b/XEngine_Source/XEngine_ModuleConfigure/Makefile index 9c885c3..55722b1 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/Makefile +++ b/XEngine_Source/XEngine_ModuleConfigure/Makefile @@ -1,4 +1,4 @@ -CC = g++ -Wall -std=c++17 -fPIC +CC = g++ -Wall -std=c++20 -fPIC PLATFORM = linux PLATVER = PLATDIR = diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h index dd7e5d0..e24ef5b 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h @@ -20,6 +20,7 @@ typedef struct tag_XEngine_ServiceConfig int nSocksPort; //Socks端口,<=0不启用 int nTunnelPort; //Tunnel服务端口 int nForwardPort; //数据转发端口 + int nProxyPort; //全代理转发 struct { int nMaxClient; //最大客户端个数 @@ -30,9 +31,10 @@ typedef struct tag_XEngine_ServiceConfig struct { int nTimeCheck; //检测次数 - int nSocksTimeOut; //TCP超时时间 - int nTunnelTimeOut; //HTTP超时时间 - int nForwardTimeOut; //转发超时时间 + int nSocksTimeout; //TCP超时时间 + int nTunnelTimeout; //HTTP超时时间 + int nForwardTimeout; //转发超时时间 + int nProxyTimeout; //代理超时时间 }st_XTime; //次数*时间=超时 struct { @@ -40,6 +42,7 @@ typedef struct tag_XEngine_ServiceConfig int nMaxSize; //最大日志大小 int nMaxCount; //最大日志个数 int nLogLeave; //日志等级 + int nLogType; //日志类型 }st_XLog; struct { @@ -47,6 +50,11 @@ typedef struct tag_XEngine_ServiceConfig XCHAR tszAPIUrl[MAX_PATH]; XCHAR tszServiceName[128]; }st_XReport; + struct + { + XCHAR tszIPAddr[128]; + bool bEnable; + }st_XProxy; struct { list* pStl_ListVer; diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h index 9215046..714f03b 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h @@ -17,4 +17,5 @@ #define ERROR_MODULE_CONFIGURE_JSON_XTIME 0xA0005 //读取XTIME配置失败 #define ERROR_MODULE_CONFIGURE_JSON_XLOG 0xA0006 //读取XLOG配置失败 #define ERROR_MODULE_CONFIGURE_JSON_XVER 0xA0008 //没有版本配置 -#define ERROR_MODULE_CONFIGURE_JSON_XREPORT 0xA0009 //没有报告配置 \ No newline at end of file +#define ERROR_MODULE_CONFIGURE_JSON_XREPORT 0xA0009 //没有报告配置 +#define ERROR_MODULE_CONFIGURE_JSON_XPROXY 0xA0010 //没有代理配置 \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp index 76d4f6b..4a78c07 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp @@ -82,10 +82,11 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE return false; } _tcsxcpy(pSt_ServerConfig->tszIPAddr, st_JsonRoot["tszIPAddr"].asCString()); - pSt_ServerConfig->bDeamon = st_JsonRoot["bDeamon"].asInt(); + pSt_ServerConfig->bDeamon = st_JsonRoot["bDeamon"].asBool(); pSt_ServerConfig->nSocksPort = st_JsonRoot["nSocksPort"].asInt(); pSt_ServerConfig->nTunnelPort = st_JsonRoot["nTunnelPort"].asInt(); pSt_ServerConfig->nForwardPort = st_JsonRoot["nForwardPort"].asInt(); + pSt_ServerConfig->nProxyPort = st_JsonRoot["nProxyPort"].asInt(); if (st_JsonRoot["XMax"].empty() || (4 != st_JsonRoot["XMax"].size())) { @@ -99,7 +100,7 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE pSt_ServerConfig->st_XMax.nIOThread = st_JsonXMax["nIOThread"].asInt(); pSt_ServerConfig->st_XMax.nForwardThread = st_JsonXMax["nForwardThread"].asInt(); - if (st_JsonRoot["XTime"].empty() || (4 != st_JsonRoot["XTime"].size())) + if (st_JsonRoot["XTime"].empty() || (5 != st_JsonRoot["XTime"].size())) { Config_IsErrorOccur = true; Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XTIME; @@ -107,11 +108,12 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE } Json::Value st_JsonXTime = st_JsonRoot["XTime"]; pSt_ServerConfig->st_XTime.nTimeCheck = st_JsonXTime["nTimeCheck"].asInt(); - pSt_ServerConfig->st_XTime.nSocksTimeOut = st_JsonXTime["nSocksTimeOut"].asInt(); - pSt_ServerConfig->st_XTime.nTunnelTimeOut = st_JsonXTime["nTunnelTimeOut"].asInt(); - pSt_ServerConfig->st_XTime.nForwardTimeOut = st_JsonXTime["nForwardTimeOut"].asInt(); + pSt_ServerConfig->st_XTime.nSocksTimeout = st_JsonXTime["nSocksTimeout"].asInt(); + pSt_ServerConfig->st_XTime.nTunnelTimeout = st_JsonXTime["nTunnelTimeout"].asInt(); + pSt_ServerConfig->st_XTime.nForwardTimeout = st_JsonXTime["nForwardTimeout"].asInt(); + pSt_ServerConfig->st_XTime.nProxyTimeout = st_JsonXTime["nProxyTimeout"].asInt(); - if (st_JsonRoot["XLog"].empty() || (4 != st_JsonRoot["XLog"].size())) + if (st_JsonRoot["XLog"].empty() || (5 != st_JsonRoot["XLog"].size())) { Config_IsErrorOccur = true; Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XLOG; @@ -121,6 +123,7 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE pSt_ServerConfig->st_XLog.nMaxSize = st_JsonXLog["MaxSize"].asInt(); pSt_ServerConfig->st_XLog.nMaxCount = st_JsonXLog["MaxCount"].asInt(); pSt_ServerConfig->st_XLog.nLogLeave = st_JsonXLog["LogLeave"].asInt(); + pSt_ServerConfig->st_XLog.nLogType = st_JsonXLog["LogType"].asInt(); _tcsxcpy(pSt_ServerConfig->st_XLog.tszLogFile, st_JsonXLog["tszLogFile"].asCString()); if (st_JsonRoot["XReport"].empty() || (3 != st_JsonRoot["XReport"].size())) @@ -135,6 +138,16 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE _tcsxcpy(pSt_ServerConfig->st_XReport.tszAPIUrl, st_JsonXReport["tszAPIUrl"].asCString()); _tcsxcpy(pSt_ServerConfig->st_XReport.tszServiceName, st_JsonXReport["tszServiceName"].asCString()); + if (st_JsonRoot["XProxy"].empty() || (2 != st_JsonRoot["XProxy"].size())) + { + Config_IsErrorOccur = true; + Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XPROXY; + return false; + } + Json::Value st_JsonXProxy = st_JsonRoot["XProxy"]; + pSt_ServerConfig->st_XProxy.bEnable = st_JsonXProxy["bEnable"].asBool(); + _tcsxcpy(pSt_ServerConfig->st_XProxy.tszIPAddr, st_JsonXProxy["tszIPAddr"].asCString()); + return true; } /******************************************************************** diff --git a/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj b/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj index a9a2b7e..dbae19b 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj +++ b/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj @@ -30,27 +30,27 @@ DynamicLibrary true v143 - MultiByte + Unicode DynamicLibrary false v143 true - MultiByte + Unicode DynamicLibrary true v143 - MultiByte + Unicode DynamicLibrary false v143 true - MultiByte + Unicode @@ -99,6 +99,8 @@ Use pch.h 4819 + stdcpp20 + stdc17 Windows @@ -119,6 +121,9 @@ pch.h MultiThreaded 4819 + stdcpp20 + stdc17 + /utf-8 %(AdditionalOptions) Windows @@ -137,6 +142,8 @@ true Use pch.h + stdcpp20 + stdc17 Windows @@ -157,6 +164,9 @@ pch.h MultiThreaded 4819 + stdcpp20 + stdc17 + /utf-8 %(AdditionalOptions) Windows diff --git a/XEngine_Source/XEngine_ModuleProtocol/Makefile b/XEngine_Source/XEngine_ModuleProtocol/Makefile index 5d886d6..57f3232 100644 --- a/XEngine_Source/XEngine_ModuleProtocol/Makefile +++ b/XEngine_Source/XEngine_ModuleProtocol/Makefile @@ -1,4 +1,4 @@ -CC = g++ -Wall -std=c++17 -fPIC +CC = g++ -Wall -std=c++20 -fPIC PLATFORM = linux PLATVER = PLATDIR = diff --git a/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.vcxproj b/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.vcxproj index 9a4e9be..644902c 100644 --- a/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.vcxproj +++ b/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.vcxproj @@ -30,27 +30,27 @@ DynamicLibrary true v143 - MultiByte + Unicode DynamicLibrary false v143 true - MultiByte + Unicode DynamicLibrary true v143 - MultiByte + Unicode DynamicLibrary false v143 true - MultiByte + Unicode @@ -92,6 +92,8 @@ true Use pch.h + stdcpp20 + stdc17 Windows @@ -110,6 +112,9 @@ true Use pch.h + stdcpp20 + stdc17 + /utf-8 %(AdditionalOptions) Windows @@ -128,6 +133,8 @@ true Use pch.h + stdcpp20 + stdc17 Windows @@ -146,6 +153,9 @@ true Use pch.h + stdcpp20 + stdc17 + /utf-8 %(AdditionalOptions) Windows diff --git a/XEngine_Source/XEngine_ModuleSession/Makefile b/XEngine_Source/XEngine_ModuleSession/Makefile index b8b88c8..6f3b379 100644 --- a/XEngine_Source/XEngine_ModuleSession/Makefile +++ b/XEngine_Source/XEngine_ModuleSession/Makefile @@ -1,4 +1,4 @@ -CC = g++ -Wall -std=c++17 -fPIC +CC = g++ -Wall -std=c++20 -fPIC PLATFORM = linux PLATVER = PLATDIR = @@ -10,7 +10,7 @@ LOADHDR = -I ./ -I ../XEngine_ThirdPart/jsoncpp LOADSO = LIB = -lXEngine_BaseLib -lXEngine_Algorithm LIBEX = -OBJECTS = ModuleSession_Forward.o ModuleSession_Socks.o ModuleSession_Tunnel.o pch.o +OBJECTS = ModuleSession_Forward.o ModuleSession_Socks.o ModuleSession_Tunnel.o ModuleSession_Proxy.o pch.o ifeq ($(RELEASE),1) FLAGS = -c @@ -63,6 +63,8 @@ ModuleSession_Socks.o:./ModuleSession_Socks/ModuleSession_Socks.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./ModuleSession_Socks/ModuleSession_Socks.cpp ModuleSession_Tunnel.o:./ModuleSession_Tunnel/ModuleSession_Tunnel.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./ModuleSession_Tunnel/ModuleSession_Tunnel.cpp +ModuleSession_Proxy.o:./ModuleSession_Proxy/ModuleSession_Proxy.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./ModuleSession_Proxy/ModuleSession_Proxy.cpp pch.o:./pch.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./pch.cpp diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Define.h b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Define.h index 144bc92..4c3ac2d 100644 --- a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Define.h +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Define.h @@ -147,17 +147,17 @@ extern "C" bool ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHAR * ptszDstAd 类型:常量字符指针 可空:N 意思:输入要操作的客户端 - 参数.二:ptszDstAddr + 参数.二:pSt_ForwardClinet In/Out:Out - 类型:字符指针 + 类型:数据结构指针 可空:Y - 意思:输出对端地址 + 意思:输出信息 返回值 类型:逻辑型 意思:是否成功 备注: *********************************************************************/ -extern "C" bool ModuleSession_Forward_Get(LPCXSTR lpszAddr, XCHAR* ptszDstAddr = NULL); +extern "C" bool ModuleSession_Forward_Get(LPCXSTR lpszAddr, SESSION_FORWARD* pSt_ForwardClinet = NULL); /************************************************************************/ /* SOCK代理服务器导出函数 */ /************************************************************************/ @@ -473,4 +473,107 @@ extern "C" bool ModuleSession_Tunnel_Packet(LPCXSTR lpszClientID, LPCXSTR lpszMs 意思:是否成功 备注: *********************************************************************/ -extern "C" bool ModuleSession_Tunnel_List(XCHAR*** ppptszClientList, int* pInt_ListCount); \ No newline at end of file +extern "C" bool ModuleSession_Tunnel_List(XCHAR*** ppptszClientList, int* pInt_ListCount); +/************************************************************************/ +/* 全转发代理服务 */ +/************************************************************************/ +/******************************************************************** +函数名称:ModuleSession_Proxy_Insert +函数功能:插入一条记录到会话中 + 参数.一:lpszSrcIPAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要插入的源客户端 + 参数.二:lpszDstIPAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要插入的目标客户端 + 参数.三:xhClient + In/Out:In + 类型:句柄 + 可空:N + 意思:输入客户端句柄 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool ModuleSession_Proxy_Insert(LPCXSTR lpszSrcIPAddr, LPCXSTR lpszDstIPAddr, XNETHANDLE xhClient); +/******************************************************************** +函数名称:ModuleSession_Proxy_GetForAddr +函数功能:通过地址获取客户端信息 + 参数.一:lpszIPAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要获取的客户端 + 参数.二:pSt_ProxyInfo + In/Out:Out + 类型:数据结构指针 + 可空:N + 意思:输出获取到的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool ModuleSession_Proxy_GetForAddr(LPCXSTR lpszIPAddr, SESSION_FORWARD* pSt_ProxyInfo); +/******************************************************************** +函数名称:ModuleSession_Proxy_GetForToken +函数功能:通过TOKEN获取客户端信息 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要获取的客户端 + 参数.二:pSt_ProxyInfo + In/Out:Out + 类型:数据结构指针 + 可空:N + 意思:输出获取到的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool ModuleSession_Proxy_GetForToken(XNETHANDLE xhToken, SESSION_FORWARD* pSt_ProxyInfo); +/******************************************************************** +函数名称:ModuleSession_Proxy_List +函数功能:获取列表 + 参数.一:pppSt_ListUser + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出列表 + 参数.二:pInt_Count + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出列表个数 + 参数.三:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入忽略地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool ModuleSession_Proxy_List(SESSION_FORWARD*** pppSt_ListUser, int* pInt_Count, LPCXSTR lpszAddr = NULL); +/******************************************************************** +函数名称:ModuleSession_Proxy_Delete +函数功能:删除用户 + 参数.一:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要删除的客户端 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool ModuleSession_Proxy_Delete(LPCXSTR lpszIPAddr); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Error.h b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Error.h index 04718cf..60cb656 100644 --- a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Error.h +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Error.h @@ -32,4 +32,9 @@ #define ERROR_MODULE_SESSION_TUNNEL_PARAMENT 0xC2001 //参数错误 #define ERROR_MODULE_SESSION_TUNNEL_MALLOC 0xC2002 //申请内存失败 #define ERROR_MODULE_SESSION_TUNNEL_NOTFOUND 0xC2003 //没有找到 -#define ERROR_MODULE_SESSION_TUNNEL_NOTSET 0xC2004 //没有设置内容 \ No newline at end of file +#define ERROR_MODULE_SESSION_TUNNEL_NOTSET 0xC2004 //没有设置内容 +/************************************************************************/ +/* 全转发代理服务错误 */ +/************************************************************************/ +#define ERROR_MODULE_SESSION_PROXY_PARAMENT 0xC3001 //参数错误 +#define ERROR_MODULE_SESSION_PROXY_NOTFOUND 0xC3002 //没有找到 \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.cpp b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.cpp index 424439c..05fedc5 100644 --- a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.cpp +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.cpp @@ -57,7 +57,7 @@ bool CModuleSession_Forward::ModuleSession_Forward_Insert(LPCXSTR lpszAddr, XENG memcpy(&st_Forward.st_UserAuth, pSt_UserAuth, sizeof(XENGINE_PROTOCOL_USERAUTH)); st_Locker.lock(); - unordered_map::const_iterator stl_MapIterator = stl_MapSession.find(lpszAddr); + unordered_map::const_iterator stl_MapIterator = stl_MapSession.find(lpszAddr); if (stl_MapIterator != stl_MapSession.end()) { Session_IsErrorOccur = true; @@ -112,7 +112,7 @@ bool CModuleSession_Forward::ModuleSession_Forward_List(SESSION_FORWARD*** pppSt { *pInt_Count = stl_MapSession.size() - 1; //减去自己 } - BaseLib_OperatorMemory_Malloc((XPPPMEM)pppSt_ListUser, *pInt_Count, sizeof(SESSION_FORWARD)); + BaseLib_Memory_Malloc((XPPPMEM)pppSt_ListUser, *pInt_Count, sizeof(SESSION_FORWARD)); //遍历 auto stl_MapIterator = stl_MapSession.begin(); for (int i = 0; stl_MapIterator != stl_MapSession.end(); stl_MapIterator++, i++) @@ -311,21 +311,21 @@ bool CModuleSession_Forward::ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHA 类型:常量字符指针 可空:N 意思:输入要操作的客户端 - 参数.二:ptszDstAddr + 参数.二:pSt_ForwardClinet In/Out:Out - 类型:字符指针 + 类型:数据结构指针 可空:Y - 意思:输出对端地址 + 意思:输出信息 返回值 类型:逻辑型 意思:是否成功 备注: *********************************************************************/ -bool CModuleSession_Forward::ModuleSession_Forward_Get(LPCXSTR lpszAddr, XCHAR* ptszDstAddr) +bool CModuleSession_Forward::ModuleSession_Forward_Get(LPCXSTR lpszAddr, SESSION_FORWARD* pSt_ForwardClinet) { Session_IsErrorOccur = false; - if ((NULL == lpszAddr) || (NULL == ptszDstAddr)) + if ((NULL == lpszAddr)) { Session_IsErrorOccur = true; Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_PARAMENT; @@ -341,7 +341,7 @@ bool CModuleSession_Forward::ModuleSession_Forward_Get(LPCXSTR lpszAddr, XCHAR* st_Locker.unlock_shared(); return false; } - if (NULL == ptszDstAddr) + if (NULL == pSt_ForwardClinet) { st_Locker.unlock_shared(); return true; @@ -354,7 +354,7 @@ bool CModuleSession_Forward::ModuleSession_Forward_Get(LPCXSTR lpszAddr, XCHAR* st_Locker.unlock_shared(); return false; } - _tcsxcpy(ptszDstAddr, stl_MapIterator->second.tszDstAddr); + *pSt_ForwardClinet = stl_MapIterator->second; st_Locker.unlock_shared(); return true; } \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.h b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.h index 0a689fe..9e31c5e 100644 --- a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.h +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.h @@ -22,9 +22,9 @@ class CModuleSession_Forward 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); + bool ModuleSession_Forward_Get(LPCXSTR lpszAddr, SESSION_FORWARD *pSt_ForwardClinet = NULL); private: shared_mutex st_Locker; private: - unordered_map stl_MapSession; + unordered_map stl_MapSession; }; \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Proxy/ModuleSession_Proxy.cpp b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Proxy/ModuleSession_Proxy.cpp new file mode 100644 index 0000000..008d2e2 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Proxy/ModuleSession_Proxy.cpp @@ -0,0 +1,247 @@ +#include "pch.h" +#include "ModuleSession_Proxy.h" +/******************************************************************** +// Created: 2025/01/20 11:13:37 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleSession\ModuleSession_Proxy\ModuleSession_Proxy.cpp +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleSession\ModuleSession_Proxy +// File Base: ModuleSession_Proxy +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 全代理转发 +// History: +*********************************************************************/ +CModuleSession_Proxy::CModuleSession_Proxy() +{ + +} +CModuleSession_Proxy::~CModuleSession_Proxy() +{ + +} +////////////////////////////////////////////////////////////////////////// +// 公用函数 +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +函数名称:ModuleSession_Proxy_Insert +函数功能:插入一条记录到会话中 + 参数.一:lpszSrcIPAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要插入的源客户端 + 参数.二:lpszDstIPAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要插入的目标客户端 + 参数.三:xhClient + In/Out:In + 类型:句柄 + 可空:N + 意思:输入客户端句柄 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CModuleSession_Proxy::ModuleSession_Proxy_Insert(LPCXSTR lpszSrcIPAddr, LPCXSTR lpszDstIPAddr, XNETHANDLE xhClient) +{ + Session_IsErrorOccur = false; + + if (NULL == lpszSrcIPAddr || NULL == lpszDstIPAddr) + { + Session_IsErrorOccur = true; + Session_dwErrorCode = ERROR_MODULE_SESSION_PROXY_PARAMENT; + return false; + } + SESSION_FORWARD st_ProxyClient = {}; + + st_ProxyClient.xhClient = xhClient; + _tcsxcpy(st_ProxyClient.tszSrcAddr, lpszSrcIPAddr); + _tcsxcpy(st_ProxyClient.tszDstAddr, lpszDstIPAddr); + + st_Locker.lock(); + unordered_map::const_iterator stl_MapIterator = stl_MapSession.find(lpszSrcIPAddr); + if (stl_MapIterator != stl_MapSession.end()) + { + Session_IsErrorOccur = true; + Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_EXIST; + st_Locker.unlock(); + return false; + } + stl_MapSession.insert(make_pair(lpszSrcIPAddr, st_ProxyClient)); + st_Locker.unlock(); + return true; +} +/******************************************************************** +函数名称:ModuleSession_Proxy_GetForAddr +函数功能:通过地址获取客户端信息 + 参数.一:lpszIPAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要获取的客户端 + 参数.二:pSt_ProxyInfo + In/Out:Out + 类型:数据结构指针 + 可空:N + 意思:输出获取到的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CModuleSession_Proxy::ModuleSession_Proxy_GetForAddr(LPCXSTR lpszIPAddr, SESSION_FORWARD* pSt_ProxyInfo) +{ + Session_IsErrorOccur = false; + + if (NULL == lpszIPAddr) + { + Session_IsErrorOccur = true; + Session_dwErrorCode = ERROR_MODULE_SESSION_PROXY_PARAMENT; + return false; + } + st_Locker.lock_shared(); + auto stl_MapIterator = stl_MapSession.find(lpszIPAddr); + if (stl_MapIterator == stl_MapSession.end()) + { + Session_IsErrorOccur = true; + Session_dwErrorCode = ERROR_MODULE_SESSION_PROXY_NOTFOUND; + st_Locker.unlock_shared(); + return false; + } + *pSt_ProxyInfo = stl_MapIterator->second; + st_Locker.unlock_shared(); + return true; +} +/******************************************************************** +函数名称:ModuleSession_Proxy_GetForToken +函数功能:通过TOKEN获取客户端信息 + 参数.一:xhToken + In/Out:In + 类型:句柄 + 可空:N + 意思:输入要获取的客户端 + 参数.二:pSt_ProxyInfo + In/Out:Out + 类型:数据结构指针 + 可空:N + 意思:输出获取到的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CModuleSession_Proxy::ModuleSession_Proxy_GetForToken(XNETHANDLE xhToken, SESSION_FORWARD* pSt_ProxyInfo) +{ + Session_IsErrorOccur = false; + + st_Locker.lock_shared(); + bool bFound = false; + auto stl_MapIterator = stl_MapSession.begin(); + for (; stl_MapIterator != stl_MapSession.end(); stl_MapIterator++) + { + if (xhToken == stl_MapIterator->second.xhClient) + { + bFound = true; + *pSt_ProxyInfo = stl_MapIterator->second; + break; + } + } + if (!bFound) + { + Session_IsErrorOccur = true; + Session_dwErrorCode = ERROR_MODULE_SESSION_PROXY_NOTFOUND; + st_Locker.unlock_shared(); + return false; + } + st_Locker.unlock_shared(); + return true; +} +/******************************************************************** +函数名称:ModuleSession_Proxy_List +函数功能:获取列表 + 参数.一:pppSt_ListUser + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出列表 + 参数.二:pInt_Count + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出列表个数 + 参数.三:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入忽略地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CModuleSession_Proxy::ModuleSession_Proxy_List(SESSION_FORWARD*** pppSt_ListUser, int* pInt_Count, LPCXSTR lpszAddr /* = NULL */) +{ + Session_IsErrorOccur = false; + + if (NULL == pInt_Count) + { + Session_IsErrorOccur = true; + Session_dwErrorCode = ERROR_MODULE_SESSION_PROXY_PARAMENT; + return false; + } + st_Locker.lock_shared(); + + if (NULL == lpszAddr) + { + *pInt_Count = stl_MapSession.size(); + } + else + { + *pInt_Count = stl_MapSession.size() - 1; //减去自己 + } + BaseLib_Memory_Malloc((XPPPMEM)pppSt_ListUser, *pInt_Count, sizeof(SESSION_FORWARD)); + //遍历 + auto stl_MapIterator = stl_MapSession.begin(); + for (int i = 0; stl_MapIterator != stl_MapSession.end(); stl_MapIterator++, i++) + { + if (NULL != lpszAddr) + { + if (0 == _tcsxncmp(lpszAddr, stl_MapIterator->first.c_str(), _tcsxlen(lpszAddr))) + { + continue; + } + } + *(*pppSt_ListUser)[i] = stl_MapIterator->second; + } + st_Locker.unlock_shared(); + return true; +} +/******************************************************************** +函数名称:ModuleSession_Proxy_Delete +函数功能:删除用户 + 参数.一:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要删除的客户端 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CModuleSession_Proxy::ModuleSession_Proxy_Delete(LPCXSTR lpszIPAddr) +{ + Session_IsErrorOccur = false; + + st_Locker.lock(); + auto stl_MapSrcIterator = stl_MapSession.find(lpszIPAddr); + if (stl_MapSrcIterator != stl_MapSession.end()) + { + stl_MapSession.erase(stl_MapSrcIterator); + } + st_Locker.unlock(); + return true; +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Proxy/ModuleSession_Proxy.h b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Proxy/ModuleSession_Proxy.h new file mode 100644 index 0000000..6c7d7f6 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Proxy/ModuleSession_Proxy.h @@ -0,0 +1,34 @@ +#pragma once +/******************************************************************** +// Created: 2025/01/20 11:13:18 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleSession\ModuleSession_Proxy\ModuleSession_Proxy.h +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleSession\ModuleSession_Proxy +// File Base: ModuleSession_Proxy +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 全代理转发 +// History: +*********************************************************************/ +typedef struct +{ + XCHAR tszIPAddr[128]; + XSOCKET hSocket; +}SESSION_PROXYCLIENT; + +class CModuleSession_Proxy +{ +public: + CModuleSession_Proxy(); + ~CModuleSession_Proxy(); +public: + bool ModuleSession_Proxy_Insert(LPCXSTR lpszSrcIPAddr, LPCXSTR lpszDstIPAddr, XNETHANDLE xhClient); + bool ModuleSession_Proxy_GetForAddr(LPCXSTR lpszIPAddr, SESSION_FORWARD* pSt_ProxyInfo); + bool ModuleSession_Proxy_GetForToken(XNETHANDLE xhToken, SESSION_FORWARD* pSt_ProxyInfo); + bool ModuleSession_Proxy_List(SESSION_FORWARD*** pppSt_ListUser, int* pInt_Count, LPCXSTR lpszAddr = NULL); + bool ModuleSession_Proxy_Delete(LPCXSTR lpszIPAddr); +private: + shared_mutex st_Locker; +private: + unordered_map stl_MapSession; +}; \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Socks/ModuleSession_Socks.cpp b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Socks/ModuleSession_Socks.cpp index 7c1787c..a546625 100644 --- a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Socks/ModuleSession_Socks.cpp +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Socks/ModuleSession_Socks.cpp @@ -78,7 +78,7 @@ bool CModuleSession_Socks::ModuleSession_Socks_Delete(LPCXSTR lpszClientID) Session_IsErrorOccur = false; st_Locker.lock(); - unordered_map::const_iterator stl_MapIterator = stl_MapClients.find(lpszClientID); + unordered_map::const_iterator stl_MapIterator = stl_MapClients.find(lpszClientID); if (stl_MapIterator != stl_MapClients.end()) { if (NULL != stl_MapIterator->second->lParam) @@ -125,7 +125,7 @@ bool CModuleSession_Socks::ModuleSession_Socks_SetInfo(LPCXSTR lpszClientID, XPV return false; } st_Locker.lock(); - unordered_map::const_iterator stl_MapIterator = stl_MapClients.find(lpszClientID); + unordered_map::const_iterator stl_MapIterator = stl_MapClients.find(lpszClientID); if (stl_MapIterator == stl_MapClients.end()) { Session_IsErrorOccur = true; @@ -195,7 +195,7 @@ bool CModuleSession_Socks::ModuleSession_Socks_GetInfo(LPCXSTR lpszClientID, XPV return false; } st_Locker.lock_shared(); - unordered_map::const_iterator stl_MapIterator = stl_MapClients.find(lpszClientID); + unordered_map::const_iterator stl_MapIterator = stl_MapClients.find(lpszClientID); if (stl_MapIterator == stl_MapClients.end()) { Session_IsErrorOccur = true; @@ -249,9 +249,9 @@ bool CModuleSession_Socks::ModuleSession_Socks_GetList(XPPPMEM xpppMem, int* pIn st_Locker.lock_shared(); *pInt_Count = stl_MapClients.size(); - BaseLib_OperatorMemory_Malloc(xpppMem, *pInt_Count, nSize); + BaseLib_Memory_Malloc(xpppMem, *pInt_Count, nSize); - unordered_map::const_iterator stl_MapIterator = stl_MapClients.begin(); + unordered_map::const_iterator stl_MapIterator = stl_MapClients.begin(); for (int i = 0; stl_MapIterator != stl_MapClients.end(); stl_MapIterator++, i++) { //是否设置有值 @@ -293,7 +293,7 @@ bool CModuleSession_Socks::ModuleSession_Socks_GetStatus(LPCXSTR lpszClientID, E return false; } st_Locker.lock_shared(); - unordered_map::const_iterator stl_MapIterator = stl_MapClients.find(lpszClientID); + unordered_map::const_iterator stl_MapIterator = stl_MapClients.find(lpszClientID); if (stl_MapIterator == stl_MapClients.end()) { Session_IsErrorOccur = true; @@ -334,7 +334,7 @@ bool CModuleSession_Socks::ModuleSession_Socks_SetStatus(LPCXSTR lpszClientID, E return false; } st_Locker.lock_shared(); - unordered_map::const_iterator stl_MapIterator = stl_MapClients.find(lpszClientID); + unordered_map::const_iterator stl_MapIterator = stl_MapClients.find(lpszClientID); if (stl_MapIterator == stl_MapClients.end()) { Session_IsErrorOccur = true; @@ -379,7 +379,7 @@ bool CModuleSession_Socks::ModuleSession_Socks_List(XCHAR*** ppptszClientList, i *pInt_ListCount = stl_MapClients.size(); if (NULL != ppptszClientList) { - BaseLib_OperatorMemory_Malloc((XPPPMEM)ppptszClientList, stl_MapClients.size(), 128); + BaseLib_Memory_Malloc((XPPPMEM)ppptszClientList, stl_MapClients.size(), 128); auto stl_MapIterator = stl_MapClients.begin(); for (int i = 0; stl_MapIterator != stl_MapClients.end(); stl_MapIterator++) { diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Socks/ModuleSession_Socks.h b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Socks/ModuleSession_Socks.h index 4109038..6c97be0 100644 --- a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Socks/ModuleSession_Socks.h +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Socks/ModuleSession_Socks.h @@ -41,5 +41,5 @@ class CModuleSession_Socks private: shared_mutex st_Locker; private: - unordered_map stl_MapClients; + unordered_map stl_MapClients; }; diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Tunnel/ModuleSession_Tunnel.cpp b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Tunnel/ModuleSession_Tunnel.cpp index 50d96df..718d401 100644 --- a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Tunnel/ModuleSession_Tunnel.cpp +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Tunnel/ModuleSession_Tunnel.cpp @@ -53,7 +53,7 @@ bool CModuleSession_Tunnel::ModuleSession_Tunnel_Create(LPCXSTR lpszClientID) } memset(pSt_TunnelInfo, '\0', sizeof(PROXYTUNNEL_CLIENTINFO)); - pSt_TunnelInfo->pStl_ListField = new list; + pSt_TunnelInfo->pStl_ListField = new list; if (NULL == pSt_TunnelInfo->pStl_ListField) { Session_IsErrorOccur = true; @@ -85,7 +85,7 @@ bool CModuleSession_Tunnel::ModuleSession_Tunnel_Delete(LPCXSTR lpszClientID) Session_IsErrorOccur = false; st_Locker.lock(); - unordered_map::const_iterator stl_MapIterator = stl_MapClient.find(lpszClientID); + unordered_map::const_iterator stl_MapIterator = stl_MapClient.find(lpszClientID); if (stl_MapIterator != stl_MapClient.end()) { if (NULL != stl_MapIterator->second->lParam) @@ -137,7 +137,7 @@ bool CModuleSession_Tunnel::ModuleSession_Tunnel_SetInfo(LPCXSTR lpszClientID, X return false; } st_Locker.lock_shared(); - unordered_map::const_iterator stl_MapIterator = stl_MapClient.find(lpszClientID); + unordered_map::const_iterator stl_MapIterator = stl_MapClient.find(lpszClientID); if (stl_MapIterator == stl_MapClient.end()) { Session_IsErrorOccur = true; @@ -206,7 +206,7 @@ bool CModuleSession_Tunnel::ModuleSession_Tunnel_GetInfo(LPCXSTR lpszClientID, X return false; } st_Locker.lock_shared(); - unordered_map::const_iterator stl_MapIterator = stl_MapClient.find(lpszClientID); + unordered_map::const_iterator stl_MapIterator = stl_MapClient.find(lpszClientID); if (stl_MapIterator == stl_MapClient.end()) { Session_IsErrorOccur = true; @@ -261,8 +261,8 @@ bool CModuleSession_Tunnel::ModuleSession_Tunnel_GetList(XPPPMEM xpppMem, int* p st_Locker.lock_shared(); *pInt_Count = stl_MapClient.size(); - BaseLib_OperatorMemory_Malloc(xpppMem, *pInt_Count, nSize); - unordered_map::const_iterator stl_MapIterator = stl_MapClient.begin(); + BaseLib_Memory_Malloc(xpppMem, *pInt_Count, nSize); + unordered_map::const_iterator stl_MapIterator = stl_MapClient.begin(); for (int i = 0; stl_MapIterator != stl_MapClient.end(); stl_MapIterator++, i++) { //是否设置有值 @@ -323,7 +323,7 @@ bool CModuleSession_Tunnel::ModuleSession_Tunnel_Packet(LPCXSTR lpszClientID, LP return false; } st_Locker.lock_shared(); - unordered_map::const_iterator stl_MapIterator = stl_MapClient.find(lpszClientID); + unordered_map::const_iterator stl_MapIterator = stl_MapClient.find(lpszClientID); if (stl_MapIterator == stl_MapClient.end()) { Session_IsErrorOccur = true; @@ -375,7 +375,7 @@ bool CModuleSession_Tunnel::ModuleSession_Tunnel_List(XCHAR*** ppptszClientList, *pInt_ListCount = stl_MapClient.size(); if (NULL != ppptszClientList) { - BaseLib_OperatorMemory_Malloc((XPPPMEM)ppptszClientList, stl_MapClient.size(), 128); + BaseLib_Memory_Malloc((XPPPMEM)ppptszClientList, stl_MapClient.size(), 128); auto stl_MapIterator = stl_MapClient.begin(); for (int i = 0; stl_MapIterator != stl_MapClient.end(); stl_MapIterator++) { diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Tunnel/ModuleSession_Tunnel.h b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Tunnel/ModuleSession_Tunnel.h index 26279c7..bb5eeaa 100644 --- a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Tunnel/ModuleSession_Tunnel.h +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Tunnel/ModuleSession_Tunnel.h @@ -17,7 +17,7 @@ typedef struct int nHdrLen; //HTTP头大小 int nPosLen; //HTTP当前大小 int nCtmLen; //自定义内容大小 - list* pStl_ListField; //HTTP字段 + list* pStl_ListField; //HTTP字段 XPVOID lParam; }PROXYTUNNEL_CLIENTINFO,*LPPROXYTUNNEL_CLIENTINFO; @@ -38,5 +38,5 @@ class CModuleSession_Tunnel private: shared_mutex st_Locker; private: - unordered_map stl_MapClient; + unordered_map stl_MapClient; }; diff --git a/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.def b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.def index 984d52f..2a603cd 100644 --- a/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.def +++ b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.def @@ -25,4 +25,10 @@ EXPORTS ModuleSession_Tunnel_GetInfo ModuleSession_Tunnel_GetList ModuleSession_Tunnel_Packet - ModuleSession_Tunnel_List \ No newline at end of file + ModuleSession_Tunnel_List + + ModuleSession_Proxy_Insert + ModuleSession_Proxy_GetForAddr + ModuleSession_Proxy_GetForToken + ModuleSession_Proxy_List + ModuleSession_Proxy_Delete \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.vcxproj b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.vcxproj index e003ac7..643e738 100644 --- a/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.vcxproj +++ b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.vcxproj @@ -30,27 +30,27 @@ DynamicLibrary true v143 - MultiByte + Unicode DynamicLibrary false v143 true - MultiByte + Unicode DynamicLibrary true v143 - MultiByte + Unicode DynamicLibrary false v143 true - MultiByte + Unicode @@ -94,6 +94,8 @@ true Use pch.h + stdcpp20 + stdc17 Windows @@ -112,6 +114,9 @@ true Use pch.h + stdcpp20 + stdc17 + /utf-8 %(AdditionalOptions) Windows @@ -130,6 +135,8 @@ true Use pch.h + stdcpp20 + stdc17 Windows @@ -148,6 +155,9 @@ true Use pch.h + stdcpp20 + stdc17 + /utf-8 %(AdditionalOptions) Windows @@ -163,6 +173,7 @@ + @@ -170,6 +181,7 @@ + diff --git a/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.vcxproj.filters b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.vcxproj.filters index da05120..b7e6185 100644 --- a/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.vcxproj.filters +++ b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.vcxproj.filters @@ -31,6 +31,12 @@ {de4957ba-1faf-41f0-9058-9f219c803ddf} + + {41572a49-c102-48df-9347-b3eeb5128a7e} + + + {400cf379-58e3-4e86-908b-30d26dcc792a} + @@ -54,6 +60,9 @@ 头文件\ModuleSession_Tunnel + + 头文件\ModuleSession_Proxy + @@ -71,6 +80,9 @@ 源文件\ModuleSession_Tunnel + + 源文件\ModuleSession_Proxy + diff --git a/XEngine_Source/XEngine_ModuleSession/pch.cpp b/XEngine_Source/XEngine_ModuleSession/pch.cpp index 0644506..f45db1d 100644 --- a/XEngine_Source/XEngine_ModuleSession/pch.cpp +++ b/XEngine_Source/XEngine_ModuleSession/pch.cpp @@ -2,6 +2,7 @@ #include "ModuleSession_Forward/ModuleSession_Forward.h" #include "ModuleSession_Socks/ModuleSession_Socks.h" #include "ModuleSession_Tunnel/ModuleSession_Tunnel.h" +#include "ModuleSession_Proxy/ModuleSession_Proxy.h" /******************************************************************** // Created: 2022/06/08 10:10:52 // File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleSession\pch.cpp @@ -19,6 +20,7 @@ XLONG Session_dwErrorCode = 0; CModuleSession_Forward m_Forward; CModuleSession_Socks m_Socks; CModuleSession_Tunnel m_Tunnel; +CModuleSession_Proxy m_Proxy; ////////////////////////////////////////////////////////////////////////// // 导出函数 ////////////////////////////////////////////////////////////////////////// @@ -53,9 +55,9 @@ extern "C" bool ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHAR * ptszDstAd { return m_Forward.ModuleSession_Forward_Delete(lpszAddr, ptszDstAddr); } -extern "C" bool ModuleSession_Forward_Get(LPCXSTR lpszAddr, XCHAR * ptszDstAddr) +extern "C" bool ModuleSession_Forward_Get(LPCXSTR lpszAddr, SESSION_FORWARD* pSt_ForwardClinet) { - return m_Forward.ModuleSession_Forward_Get(lpszAddr, ptszDstAddr); + return m_Forward.ModuleSession_Forward_Get(lpszAddr, pSt_ForwardClinet); } /************************************************************************/ /* SOCK代理服务器导出函数 */ @@ -122,4 +124,27 @@ extern "C" bool ModuleSession_Tunnel_Packet(LPCXSTR lpszClientID, LPCXSTR lpszMs extern "C" bool ModuleSession_Tunnel_List(XCHAR*** ppptszClientList, int* pInt_ListCount) { return m_Tunnel.ModuleSession_Tunnel_List(ppptszClientList, pInt_ListCount); +} +/************************************************************************/ +/* 全转发代理服务 */ +/************************************************************************/ +extern "C" bool ModuleSession_Proxy_Insert(LPCXSTR lpszSrcIPAddr, LPCXSTR lpszDstIPAddr, XNETHANDLE xhClient) +{ + return m_Proxy.ModuleSession_Proxy_Insert(lpszSrcIPAddr, lpszDstIPAddr, xhClient); +} +extern "C" bool ModuleSession_Proxy_GetForAddr(LPCXSTR lpszIPAddr, SESSION_FORWARD* pSt_ProxyInfo) +{ + return m_Proxy.ModuleSession_Proxy_GetForAddr(lpszIPAddr, pSt_ProxyInfo); +} +extern "C" bool ModuleSession_Proxy_GetForToken(XNETHANDLE xhToken, SESSION_FORWARD* pSt_ProxyInfo) +{ + return m_Proxy.ModuleSession_Proxy_GetForToken(xhToken, pSt_ProxyInfo); +} +extern "C" bool ModuleSession_Proxy_List(SESSION_FORWARD*** pppSt_ListUser, int* pInt_Count, LPCXSTR lpszAddr) +{ + return m_Proxy.ModuleSession_Proxy_List(pppSt_ListUser, pInt_Count, lpszAddr); +} +extern "C" bool ModuleSession_Proxy_Delete(LPCXSTR lpszIPAddr) +{ + return m_Proxy.ModuleSession_Proxy_Delete(lpszIPAddr); } \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/pch.h b/XEngine_Source/XEngine_ModuleSession/pch.h index 365e4c8..d9ee2ba 100644 --- a/XEngine_Source/XEngine_ModuleSession/pch.h +++ b/XEngine_Source/XEngine_ModuleSession/pch.h @@ -42,12 +42,6 @@ using namespace std; extern bool Session_IsErrorOccur; extern XLONG Session_dwErrorCode; -#ifdef _UNICODE -typedef std::wstring tstring; -#else -typedef std::string tstring; -#endif - #ifdef _MSC_BUILD #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib") #pragma comment(lib,"XEngine_BaseLib/XEngine_Algorithm") diff --git a/XEngine_Source/XEngine_ServiceApp/Makefile b/XEngine_Source/XEngine_ServiceApp/Makefile index 833e916..65f63e5 100644 --- a/XEngine_Source/XEngine_ServiceApp/Makefile +++ b/XEngine_Source/XEngine_ServiceApp/Makefile @@ -1,4 +1,4 @@ -CC = g++ -Wall -std=c++17 +CC = g++ -Wall -std=c++20 PLATFORM = linux PLATVER = PLATDIR = @@ -7,11 +7,11 @@ UNICODE = 0 LOADHDR = -I ./ -I ../XEngine_Depend/XEngine_Module/jsoncpp LOADSO = -L ../XEngine_ModuleConfigure -L ../XEngine_ModuleSession -L ../XEngine_ModuleProtocol \ -L ../XEngine_Depend/XEngine_Module/jsoncpp -L ../XEngine_Depend/XEngine_Module/XEngine_InfoReport -LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_OPenSsl -lXEngine_ManagePool -lXClient_Socket -lXClient_APIHelp -lHelpComponents_XLog -lHelpComponents_Packets -lRfcComponents_ProxyProtocol -lNetHelp_APIHelp -lNetHelp_XSocket \ +LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_Cryption -lXEngine_ManagePool -lXClient_Socket -lXClient_APIHelp -lHelpComponents_XLog -lHelpComponents_Packets -lRfcComponents_ProxyProtocol -lNetHelp_APIHelp -lNetHelp_APIAddr -lNetHelp_XSocket \ -lXEngine_ModuleConfigure -lXEngine_ModuleSession -lXEngine_ModuleProtocol \ -ljsoncpp -lXEngine_InfoReport LIBEX = -OBJECTS = XEngine_Configure.o XEngine_Network.o XEngine_SocksTask.o XEngine_TunnelTask.o XEngine_ForwardTask.o XEngine_ServiceApp.o +OBJECTS = XEngine_Configure.o XEngine_Network.o XEngine_SocksTask.o XEngine_TunnelTask.o XEngine_ForwardTask.o XEngine_ProxyTask.o XEngine_ServiceApp.o ifeq ($(RELEASE),1) FLAGS = -c @@ -63,6 +63,8 @@ XEngine_TunnelTask.o:./XEngine_TunnelTask.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./XEngine_TunnelTask.cpp XEngine_ForwardTask.o:./XEngine_ForwardTask.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./XEngine_ForwardTask.cpp +XEngine_ProxyTask.o:./XEngine_ProxyTask.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./XEngine_ProxyTask.cpp XEngine_ServiceApp.o:./XEngine_ServiceApp.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(PLATVER) $(LOADHDR) ./XEngine_ServiceApp.cpp diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp index 877dc52..1a5c922 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp @@ -37,6 +37,10 @@ bool XEngine_Configure_Parament(int argc, char** argv, XENGINE_SERVICECONFIG* pS { pSt_Configure->bDeamon = _ttxoi(argv[++i]); } + else if (0 == _tcsxcmp("-l", argv[i])) + { + pSt_Configure->st_XLog.nLogLeave = _ttxoi(argv[++i]); + } else if (0 == _tcsxcmp("-v", argv[i])) { string m_StrVersion = st_ServiceConfig.st_XVer.pStl_ListVer->front(); diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.cpp index e204a13..bb883d9 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.cpp @@ -34,10 +34,10 @@ XHTHREAD CALLBACK XEngine_Forward_Thread(XPVOID lParam) if (HelpComponents_Datas_GetMemoryEx(xhForwardPacket, ppSt_ListClient[i]->tszClientAddr, &ptszMsgBuffer, &nMsgLen, &st_ProtocolHdr)) { XEngine_Forward_Handle(ppSt_ListClient[i]->tszClientAddr, ptszMsgBuffer, nMsgLen, &st_ProtocolHdr); - BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + BaseLib_Memory_FreeCStyle((XPPMEM)&ptszMsgBuffer); } } - BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListClient, nListCount); + BaseLib_Memory_Free((XPPPMEM)&ppSt_ListClient, nListCount); } return 0; } @@ -87,7 +87,7 @@ bool XEngine_Forward_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int n pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LISTREP; ModuleSession_Forward_List(&ppSt_ListUser, &nListCount, lpszClientAddr); ModuleProtocol_Packet_ForwardList(tszSDBuffer, &nSDLen, pSt_ProtocolHdr, &ppSt_ListUser, nListCount); - BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListUser, nListCount); + BaseLib_Memory_Free((XPPPMEM)&ppSt_ListUser, nListCount); XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_CLIENT_NETTYPE_FORWARD); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,请求可用转发列表成功"), lpszClientAddr); } @@ -130,7 +130,7 @@ bool XEngine_Forward_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int n //匿名绑定,请求连接 int nPort = 0; XNETHANDLE xhClient = 0; - BaseLib_OperatorIPAddr_SegAddr(tszDstAddr, &nPort); + APIAddr_IPAddr_SegAddr(tszDstAddr, &nPort); if (!XClient_TCPSelect_InsertEx(xhForwardClient, &xhClient, tszDstAddr, nPort)) { pSt_ProtocolHdr->wReserve = 500; @@ -183,5 +183,5 @@ void CALLBACK XEngine_Forward_CBRecv(XHANDLE xhToken, XNETHANDLE xhClient, XSOCK break; } } - BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ClientList, nListCount); + BaseLib_Memory_Free((XPPPMEM)&ppSt_ClientList, nListCount); } \ 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 720ba60..c533f31 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -31,12 +32,14 @@ using namespace std; #include #include #include -#include -#include +#include +#include #include #include #include #include +#include +#include #include #include #include @@ -61,6 +64,7 @@ using namespace std; #include "XEngine_SocksTask.h" #include "XEngine_TunnelTask.h" #include "XEngine_ForwardTask.h" +#include "XEngine_ProxyTask.h" /******************************************************************** // Created: 2021/12/02 16:34:41 // File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp\XEngine_Hdr.h @@ -89,6 +93,10 @@ extern XHANDLE xhForwardHeart; extern XHANDLE xhForwardPacket; extern XHANDLE xhForwardPool; extern XHANDLE xhForwardClient; +//代理转发服务器 +extern XHANDLE xhProxySocket; +extern XHANDLE xhProxyHeart; +extern XHANDLE xhProxyClient; //配置文件 extern XENGINE_SERVICECONFIG st_ServiceConfig; @@ -96,6 +104,7 @@ extern XENGINE_SERVICECONFIG st_ServiceConfig; #define XENGINE_CLIENT_NETTYPE_SOCKS 1 #define XENGINE_CLIENT_NETTYPE_TUNNEL 2 #define XENGINE_CLIENT_NETTYPE_FORWARD 3 +#define XENGINE_CLIENT_NETTYPE_PROXY 4 //关闭模式 #define XENGINE_CLIENT_CLOSE_NETWORK 1 #define XENGINE_CLIENT_CLOSE_HEARTBEAT 2 @@ -138,9 +147,10 @@ typedef struct #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") #pragma comment(lib,"XEngine_Core/XEngine_Core.lib") #pragma comment(lib,"XEngine_Core/XEngine_ManagePool.lib") -#pragma comment(lib,"XEngine_Core/XEngine_OPenSsl.lib") +#pragma comment(lib,"XEngine_Core/XEngine_Cryption.lib") #pragma comment(lib,"XEngine_Client/XClient_Socket.lib") #pragma comment(lib,"XEngine_NetHelp/NetHelp_APIHelp.lib") +#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIAddr.lib") #pragma comment(lib,"XEngine_NetHelp/NetHelp_XSocket.lib") #pragma comment(lib,"XEngine_HelpComponents/HelpComponents_XLog.lib") #pragma comment(lib,"XEngine_HelpComponents/HelpComponents_Packets.lib") diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp index c6884e0..4f08c12 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp @@ -68,13 +68,11 @@ bool CALLBACK Network_Callback_ForwardLogin(LPCXSTR lpszClientAddr, XSOCKET hSoc } void CALLBACK Network_Callback_ForwardRecv(LPCXSTR lpszClientAddr, XSOCKET hSocket, LPCXSTR lpszRecvMsg, int nMsgLen, XPVOID lParam) { - XCHAR tszDstAddr[128]; - memset(tszDstAddr, '\0', sizeof(tszDstAddr)); - - if (ModuleSession_Forward_Get(lpszClientAddr, tszDstAddr)) + SESSION_FORWARD st_ForwardClinet = {}; + if (ModuleSession_Forward_Get(lpszClientAddr, &st_ForwardClinet)) { //如果有转发,直接转发 - XEngine_Network_Send(tszDstAddr, lpszRecvMsg, nMsgLen, XENGINE_CLIENT_NETTYPE_FORWARD); + XEngine_Network_Send(st_ForwardClinet.tszDstAddr, lpszRecvMsg, nMsgLen, XENGINE_CLIENT_NETTYPE_FORWARD); } else { @@ -95,6 +93,23 @@ void CALLBACK Network_Callback_ForwardHeart(LPCXSTR lpszClientAddr, XSOCKET hSoc { XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_FORWARD, XENGINE_CLIENT_CLOSE_HEARTBEAT); } +//////////////////////////////////////////////////////////////////////////Forward相关 +bool CALLBACK Network_Callback_ProxyLogin(LPCXSTR lpszClientAddr, XSOCKET hSocket, XPVOID lParam) +{ + return XEngine_Proxy_Connect(lpszClientAddr); +} +void CALLBACK Network_Callback_ProxyRecv(LPCXSTR lpszClientAddr, XSOCKET hSocket, LPCXSTR lpszRecvMsg, int nMsgLen, XPVOID lParam) +{ + XEngine_Proxy_Recvmsg(lpszClientAddr, lpszRecvMsg, nMsgLen); +} +void CALLBACK Network_Callback_ProxyLeave(LPCXSTR lpszClientAddr, XSOCKET hSocket, XPVOID lParam) +{ + XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_PROXY, XENGINE_CLIENT_CLOSE_NETWORK); +} +void CALLBACK Network_Callback_ProxyHeart(LPCXSTR lpszClientAddr, XSOCKET hSocket, int nStatus, XPVOID lParam) +{ + XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_PROXY, XENGINE_CLIENT_CLOSE_HEARTBEAT); +} //////////////////////////////////////////////////////////////////////////网络IO关闭操作 void XEngine_Network_Close(LPCXSTR lpszClientAddr, int nIPProto, int nCloseType) { @@ -128,7 +143,7 @@ void XEngine_Network_Close(LPCXSTR lpszClientAddr, int nIPProto, int nCloseType) break; } } - BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ClientList, nListCount); + BaseLib_Memory_Free((XPPPMEM)&ppSt_ClientList, nListCount); ModuleSession_Socks_Delete(lpszClientAddr); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("SOCKS客户端:%s,离开服务器,离开类型;%d"), lpszClientAddr, nCloseType); } @@ -159,7 +174,7 @@ void XEngine_Network_Close(LPCXSTR lpszClientAddr, int nIPProto, int nCloseType) break; } } - BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ClientList, nListCount); + BaseLib_Memory_Free((XPPPMEM)&ppSt_ClientList, nListCount); ModuleSession_Tunnel_Delete(lpszClientAddr); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Tunnel客户端:%s,离开服务器,离开类型;%d"), lpszClientAddr, nCloseType); } @@ -178,10 +193,39 @@ void XEngine_Network_Close(LPCXSTR lpszClientAddr, int nIPProto, int nCloseType) SocketOpt_HeartBeat_DeleteAddrEx(xhForwardHeart, lpszClientAddr); NetCore_TCPXCore_CloseForClientEx(xhForwardSocket, lpszClientAddr); } + SESSION_FORWARD st_ForwardInfo = {}; + if (ModuleSession_Forward_Get(lpszClientAddr, &st_ForwardInfo)) + { + XClient_TCPSelect_DeleteEx(xhForwardClient, st_ForwardInfo.xhClient); + } + ModuleSession_Proxy_Delete(lpszClientAddr); HelpComponents_Datas_DeleteEx(xhForwardPacket, lpszClientAddr); ModuleSession_Forward_Delete(lpszClientAddr); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,离开服务器,离开类型;%d"), lpszClientAddr, nCloseType); } + else if (XENGINE_CLIENT_NETTYPE_PROXY == nIPProto) + { + if (XENGINE_CLIENT_CLOSE_NETWORK == nCloseType) + { + SocketOpt_HeartBeat_DeleteAddrEx(xhProxyHeart, lpszClientAddr); + } + else if (XENGINE_CLIENT_CLOSE_HEARTBEAT == nCloseType) + { + NetCore_TCPXCore_CloseForClientEx(xhProxySocket, lpszClientAddr); + } + else + { + SocketOpt_HeartBeat_DeleteAddrEx(xhProxyHeart, lpszClientAddr); + NetCore_TCPXCore_CloseForClientEx(xhProxySocket, lpszClientAddr); + } + SESSION_FORWARD st_ProxyInfo = {}; + if (ModuleSession_Proxy_GetForAddr(lpszClientAddr, &st_ProxyInfo)) + { + XClient_TCPSelect_DeleteEx(xhProxyClient, st_ProxyInfo.xhClient); + } + ModuleSession_Proxy_Delete(lpszClientAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Proxy客户端:%s,离开服务器,离开类型;%d"), lpszClientAddr, nCloseType); + } else { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("未知客户端:%s,离开服务器"), lpszClientAddr); @@ -220,6 +264,15 @@ bool XEngine_Network_Send(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMs } SocketOpt_HeartBeat_ActiveAddrEx(xhForwardHeart, lpszClientAddr); } + else if (XENGINE_CLIENT_NETTYPE_PROXY == nIPProto) + { + if (!NetCore_TCPXCore_SendEx(xhProxySocket, lpszClientAddr, lpszMsgBuffer, nMsgLen, 1, 1)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("Proxy客户端:%s,发送数据失败,错误:%lX"), lpszClientAddr, NetCore_GetLastError()); + return false; + } + SocketOpt_HeartBeat_ActiveAddrEx(xhProxyHeart, lpszClientAddr); + } else { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("未知客户端:%s,发送数据给失败,错误:%lX"), lpszClientAddr, NetCore_GetLastError()); diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h index 654f09e..948aa06 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h @@ -25,6 +25,11 @@ bool CALLBACK Network_Callback_ForwardLogin(LPCXSTR lpszClientAddr, XSOCKET hSoc void CALLBACK Network_Callback_ForwardRecv(LPCXSTR lpszClientAddr, XSOCKET hSocket, LPCXSTR lpszRecvMsg, int nMsgLen, XPVOID lParam); void CALLBACK Network_Callback_ForwardLeave(LPCXSTR lpszClientAddr, XSOCKET hSocket, XPVOID lParam); void CALLBACK Network_Callback_ForwardHeart(LPCXSTR lpszClientAddr, XSOCKET hSocket, int nStatus, XPVOID lParam); +//Forward相关 +bool CALLBACK Network_Callback_ProxyLogin(LPCXSTR lpszClientAddr, XSOCKET hSocket, XPVOID lParam); +void CALLBACK Network_Callback_ProxyRecv(LPCXSTR lpszClientAddr, XSOCKET hSocket, LPCXSTR lpszRecvMsg, int nMsgLen, XPVOID lParam); +void CALLBACK Network_Callback_ProxyLeave(LPCXSTR lpszClientAddr, XSOCKET hSocket, XPVOID lParam); +void CALLBACK Network_Callback_ProxyHeart(LPCXSTR lpszClientAddr, XSOCKET hSocket, int nStatus, XPVOID lParam); //关闭与发送 void XEngine_Network_Close(LPCXSTR lpszClientAddr, int nIPProto, int nCloseType); bool XEngine_Network_Send(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen, int nIPProto); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ProxyTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_ProxyTask.cpp new file mode 100644 index 0000000..8d50cac --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ProxyTask.cpp @@ -0,0 +1,59 @@ +#include "XEngine_Hdr.h" +/******************************************************************** +// Created: 2025/01/20 10:59:05 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ServiceApp\XEngine_ProxyTask.cpp +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ServiceApp +// File Base: XEngine_ProxyTask +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 代理服务协议 +// History: +*********************************************************************/ +void CALLBACK XEngine_Proxy_CBRecv(XHANDLE xhToken, XNETHANDLE xhClient, XSOCKET hSocket, ENUM_XCLIENT_SOCKET_EVENTS enTCPClientEvents, LPCXSTR lpszMsgBuffer, int nMsgLen, XPVOID lParam) +{ + SESSION_FORWARD st_ProxyInfo = {}; + if (!ModuleSession_Proxy_GetForToken(xhClient, &st_ProxyInfo)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("Proxy客户端:%lld,获取转发地址信息失败,原始地址:%s,目标地址:%s,错误码:%lX"), xhClient, st_ProxyInfo.tszSrcAddr, st_ProxyInfo.tszDstAddr, ModuleSession_GetLastError()); + return; + } + XEngine_Network_Send(st_ProxyInfo.tszSrcAddr, lpszMsgBuffer, nMsgLen, XENGINE_CLIENT_NETTYPE_PROXY); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_DEBUG, _X("Proxy客户端:%lld,转发数据成功,原始地址:%s,目标地址:%s,大小:%d"), xhClient, st_ProxyInfo.tszSrcAddr, st_ProxyInfo.tszDstAddr, nMsgLen); +} + +bool XEngine_Proxy_Connect(LPCXSTR lpszClientAddr) +{ + int nPort = 0; + XNETHANDLE xhClient = 0; + XCHAR tszIPAddr[128] = {}; + + _tcsxcpy(tszIPAddr, st_ServiceConfig.st_XProxy.tszIPAddr); + APIAddr_IPAddr_SegAddr(tszIPAddr, &nPort); + if (!XClient_TCPSelect_InsertEx(xhProxyClient, &xhClient, tszIPAddr, nPort, false)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("Proxy客户端:%s,连接到转发代理服务器失败,服务地址:%s,错误码:%lX"), lpszClientAddr, st_ServiceConfig.st_XProxy.tszIPAddr, XClient_GetLastError()); + return false; + } + SocketOpt_HeartBeat_InsertAddrEx(xhProxyHeart, lpszClientAddr); + ModuleSession_Proxy_Insert(lpszClientAddr, st_ServiceConfig.st_XProxy.tszIPAddr, xhClient); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Proxy客户端:%s,连接到服务器:%s 成功"), lpszClientAddr, st_ServiceConfig.st_XProxy.tszIPAddr); + return true; +} +bool XEngine_Proxy_Recvmsg(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen) +{ + SESSION_FORWARD st_ProxyInfo = {}; + if (!ModuleSession_Proxy_GetForAddr(lpszClientAddr, &st_ProxyInfo)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("Proxy客户端:%s,获取转发地址信息失败,源地址:%s,目地址:%s,错误码:%lX"), lpszClientAddr, st_ProxyInfo.tszSrcAddr, st_ProxyInfo.tszDstAddr, ModuleSession_GetLastError()); + return false; + } + if (!XClient_TCPSelect_SendEx(xhProxyClient, st_ProxyInfo.xhClient, lpszMsgBuffer, nMsgLen)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("Proxy客户端:%s,转发数据失败,源地址:%s,目地址:%s,错误码:%lX"), lpszClientAddr, st_ProxyInfo.tszSrcAddr, st_ProxyInfo.tszDstAddr, XClient_GetLastError()); + return false; + } + SocketOpt_HeartBeat_ActiveAddrEx(xhProxyHeart, lpszClientAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_DEBUG, _X("Proxy客户端:%s,转发数据成功,源地址:%s,目地址:%s,大小:%d"), lpszClientAddr, st_ProxyInfo.tszSrcAddr, st_ProxyInfo.tszDstAddr, nMsgLen); + return true; +} diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ProxyTask.h b/XEngine_Source/XEngine_ServiceApp/XEngine_ProxyTask.h new file mode 100644 index 0000000..8d1f968 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ProxyTask.h @@ -0,0 +1,15 @@ +#pragma once +/******************************************************************** +// Created: 2025/01/20 10:45:13 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ServiceApp\XEngine_ProxyTask.h +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ServiceApp +// File Base: XEngine_ProxyTask +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 代理转发协议 +// History: +*********************************************************************/ +void CALLBACK XEngine_Proxy_CBRecv(XHANDLE xhToken, XNETHANDLE xhClient, XSOCKET hSocket, ENUM_XCLIENT_SOCKET_EVENTS enTCPClientEvents, LPCXSTR lpszMsgBuffer, int nMsgLen, XPVOID lParam); +bool XEngine_Proxy_Connect(LPCXSTR lpszClientAddr); +bool XEngine_Proxy_Recvmsg(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen); \ 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 5c053b5..c86ce7d 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp @@ -17,6 +17,10 @@ XHANDLE xhForwardHeart = NULL; XHANDLE xhForwardPacket = NULL; XHANDLE xhForwardPool = NULL; XHANDLE xhForwardClient = NULL; + +XHANDLE xhProxySocket = NULL; +XHANDLE xhProxyHeart = NULL; +XHANDLE xhProxyClient = NULL; //配置文件 XENGINE_SERVICECONFIG st_ServiceConfig; @@ -39,6 +43,11 @@ void ServiceApp_Stop(int signo) NetCore_TCPXCore_DestroyEx(xhForwardSocket); SocketOpt_HeartBeat_DestoryEx(xhForwardHeart); ManagePool_Thread_NQDestroy(xhForwardPool); + XClient_TCPSelect_StopEx(xhForwardClient); + //销毁proxy资源 + NetCore_TCPXCore_DestroyEx(xhProxySocket); + SocketOpt_HeartBeat_DestoryEx(xhProxyHeart); + XClient_TCPSelect_StopEx(xhProxyClient); //销毁日志资源 HelpComponents_XLog_Destroy(xhLog); } @@ -83,7 +92,7 @@ LONG WINAPI Coredump_ExceptionFilter(EXCEPTION_POINTERS* pExceptionPointers) static int i = 0; XCHAR tszFileStr[MAX_PATH] = {}; XCHAR tszTimeStr[128] = {}; - BaseLib_OperatorTime_TimeToStr(tszTimeStr); + BaseLib_Time_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); @@ -108,6 +117,13 @@ int main(int argc, char** argv) WSAStartup(MAKEWORD(2, 2), &st_WSAData); SetUnhandledExceptionFilter(Coredump_ExceptionFilter); +#ifndef _DEBUG + if (setlocale(LC_ALL, ".UTF8") == NULL) + { + fprintf(stderr, "Error setting locale.\n"); + return 1; + } +#endif #endif bIsRun = true; int nRet = 0; @@ -129,23 +145,16 @@ int main(int argc, char** argv) st_XLogConfig.XLog_MaxBackupFile = st_ServiceConfig.st_XLog.nMaxCount; st_XLogConfig.XLog_MaxSize = st_ServiceConfig.st_XLog.nMaxSize; _tcsxcpy(st_XLogConfig.tszFileName, st_ServiceConfig.st_XLog.tszLogFile); - xhLog = HelpComponents_XLog_Init(st_ServiceConfig.st_XLog.nLogLeave, &st_XLogConfig); + xhLog = HelpComponents_XLog_Init(st_ServiceConfig.st_XLog.nLogType, &st_XLogConfig); if (NULL == xhLog) { printf("启动服务中,启动日志失败,错误:%lX", XLog_GetLastError()); goto XENGINE_SERVICEAPP_EXIT; } //设置日志打印级别 - HelpComponents_XLog_SetLogPriority(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO); + HelpComponents_XLog_SetLogPriority(xhLog, st_ServiceConfig.st_XLog.nLogLeave); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化日志系统成功")); - BaseLib_OperatorVer_XGetStu(&st_VERXEngine); - if (st_VERXEngine.nVerCore < 8 || st_VERXEngine.nVerMain < 39) - { - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,当前XEngine:%s 版本过低,无法正常使用"), BaseLib_OperatorVer_XNumberStr()); - goto XENGINE_SERVICEAPP_EXIT; - } - signal(SIGINT, ServiceApp_Stop); signal(SIGTERM, ServiceApp_Stop); signal(SIGABRT, ServiceApp_Stop); @@ -154,15 +163,15 @@ int main(int argc, char** argv) if (st_ServiceConfig.nSocksPort > 0) { //启动心跳 - if (st_ServiceConfig.st_XTime.nSocksTimeOut > 0) + if (st_ServiceConfig.st_XTime.nSocksTimeout > 0) { - xhSocksHeart = SocketOpt_HeartBeat_InitEx(st_ServiceConfig.st_XTime.nSocksTimeOut, st_ServiceConfig.st_XTime.nTimeCheck, Network_Callback_SocksHeart); + xhSocksHeart = SocketOpt_HeartBeat_InitEx(st_ServiceConfig.st_XTime.nSocksTimeout, st_ServiceConfig.st_XTime.nTimeCheck, Network_Callback_SocksHeart); if (NULL == xhSocksHeart) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,初始化Socks心跳服务失败,错误:%lX"), NetCore_GetLastError()); goto XENGINE_SERVICEAPP_EXIT; } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化Socks心跳服务成功,时间:%d,次数:%d"), st_ServiceConfig.st_XTime.nSocksTimeOut, st_ServiceConfig.st_XTime.nTimeCheck); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化Socks心跳服务成功,时间:%d,次数:%d"), st_ServiceConfig.st_XTime.nSocksTimeout, st_ServiceConfig.st_XTime.nTimeCheck); } else { @@ -196,15 +205,15 @@ int main(int argc, char** argv) if (st_ServiceConfig.nTunnelPort > 0) { //启动心跳 - if (st_ServiceConfig.st_XTime.nTunnelTimeOut > 0) + if (st_ServiceConfig.st_XTime.nTunnelTimeout > 0) { - xhTunnelHeart = SocketOpt_HeartBeat_InitEx(st_ServiceConfig.st_XTime.nTunnelTimeOut, st_ServiceConfig.st_XTime.nTimeCheck, Network_Callback_TunnelHeart); + xhTunnelHeart = SocketOpt_HeartBeat_InitEx(st_ServiceConfig.st_XTime.nTunnelTimeout, st_ServiceConfig.st_XTime.nTimeCheck, Network_Callback_TunnelHeart); if (NULL == xhTunnelHeart) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,初始化Tunnel心跳服务失败,错误:%lX"), NetCore_GetLastError()); goto XENGINE_SERVICEAPP_EXIT; } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化Tunnel心跳服务成功,时间:%d,次数:%d"), st_ServiceConfig.st_XTime.nTunnelTimeOut, st_ServiceConfig.st_XTime.nTimeCheck); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化Tunnel心跳服务成功,时间:%d,次数:%d"), st_ServiceConfig.st_XTime.nTunnelTimeout, st_ServiceConfig.st_XTime.nTimeCheck); } else { @@ -245,15 +254,15 @@ int main(int argc, char** argv) } XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动Forward组包器成功")); //启动心跳 - if (st_ServiceConfig.st_XTime.nForwardTimeOut > 0) + if (st_ServiceConfig.st_XTime.nForwardTimeout > 0) { - xhForwardHeart = SocketOpt_HeartBeat_InitEx(st_ServiceConfig.st_XTime.nForwardTimeOut, st_ServiceConfig.st_XTime.nTimeCheck, Network_Callback_ForwardHeart); + xhForwardHeart = SocketOpt_HeartBeat_InitEx(st_ServiceConfig.st_XTime.nForwardTimeout, st_ServiceConfig.st_XTime.nTimeCheck, Network_Callback_ForwardHeart); if (NULL == xhForwardHeart) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,初始化Forward心跳服务失败,错误:%lX"), NetCore_GetLastError()); goto XENGINE_SERVICEAPP_EXIT; } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化Forward心跳服务成功,时间:%d,次数:%d"), st_ServiceConfig.st_XTime.nForwardTimeOut, st_ServiceConfig.st_XTime.nTimeCheck); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化Forward心跳服务成功,时间:%d,次数:%d"), st_ServiceConfig.st_XTime.nForwardTimeout, st_ServiceConfig.st_XTime.nTimeCheck); } else { @@ -271,7 +280,7 @@ int main(int argc, char** argv) XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,注册Forward网络事件成功")); //任务池 THREADPOOL_PARAMENT** ppSt_ListParam; - BaseLib_OperatorMemory_Malloc((XPPPMEM)&ppSt_ListParam, st_ServiceConfig.st_XMax.nForwardThread, sizeof(THREADPOOL_PARAMENT)); + BaseLib_Memory_Malloc((XPPPMEM)&ppSt_ListParam, st_ServiceConfig.st_XMax.nForwardThread, sizeof(THREADPOOL_PARAMENT)); for (int i = 0; i < st_ServiceConfig.st_XMax.nForwardThread; i++) { int* pInt_Pos = new int; @@ -300,6 +309,47 @@ int main(int argc, char** argv) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,Forward服务没有被启用")); } + //启动全代理协议服务 + if (st_ServiceConfig.nProxyPort > 0) + { + //启动心跳 + if (st_ServiceConfig.st_XTime.nProxyTimeout > 0) + { + xhProxyHeart = SocketOpt_HeartBeat_InitEx(st_ServiceConfig.st_XTime.nProxyTimeout, st_ServiceConfig.st_XTime.nTimeCheck, Network_Callback_ProxyHeart); + if (NULL == xhForwardHeart) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,初始化Proxy心跳服务失败,错误:%lX"), NetCore_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化Proxy心跳服务成功,时间:%d,次数:%d"), st_ServiceConfig.st_XTime.nProxyTimeout, st_ServiceConfig.st_XTime.nTimeCheck); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,Proxy心跳服务被设置为不启用")); + } + //网络 + xhProxySocket = NetCore_TCPXCore_StartEx(st_ServiceConfig.nProxyPort, st_ServiceConfig.st_XMax.nMaxClient, st_ServiceConfig.st_XMax.nIOThread); + if (NULL == xhProxySocket) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,启动Proxy网络服务器失败,错误:%lX"), NetCore_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动Proxy网络服务器成功,Proxy端口:%d,目标地址:%s,IO:%d"), st_ServiceConfig.nProxyPort, st_ServiceConfig.st_XProxy.tszIPAddr, st_ServiceConfig.st_XMax.nIOThread); + NetCore_TCPXCore_RegisterCallBackEx(xhProxySocket, Network_Callback_ProxyLogin, Network_Callback_ProxyRecv, Network_Callback_ProxyLeave); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,注册Proxy网络事件成功")); + //客户端 + xhProxyClient = XClient_TCPSelect_StartEx(XEngine_Proxy_CBRecv); + if (NULL == xhProxyClient) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动Proxy客户端服务失败,错误:%lX"), XClient_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,启动Proxy客户端服务成功")); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,Proxy服务没有被启用")); + } //发送信息报告 if (st_ServiceConfig.st_XReport.bEnable && !bIsTest) { @@ -319,7 +369,7 @@ int main(int argc, char** argv) XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,信息报告给API服务器没有启用")); } - 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()); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("所有服务成功启动,服务运行中,XEngine版本:%s%s,服务版本:%s,发行次数:%d。。。"), BaseLib_Version_XNumberStr(), BaseLib_Version_XTypeStr(), st_ServiceConfig.st_XVer.pStl_ListVer->front().c_str(), st_ServiceConfig.st_XVer.pStl_ListVer->size()); while (true) { @@ -356,6 +406,11 @@ int main(int argc, char** argv) NetCore_TCPXCore_DestroyEx(xhForwardSocket); SocketOpt_HeartBeat_DestoryEx(xhForwardHeart); ManagePool_Thread_NQDestroy(xhForwardPool); + XClient_TCPSelect_StopEx(xhForwardClient); + //销毁proxy资源 + NetCore_TCPXCore_DestroyEx(xhProxySocket); + SocketOpt_HeartBeat_DestoryEx(xhProxyHeart); + XClient_TCPSelect_StopEx(xhProxyClient); //销毁日志资源 HelpComponents_XLog_Destroy(xhLog); } diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj index 9b17ecf..2c162eb 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj @@ -30,27 +30,27 @@ Application true v143 - MultiByte + Unicode Application false v143 true - MultiByte + Unicode Application true v143 - MultiByte + Unicode Application false v143 true - MultiByte + Unicode @@ -97,6 +97,8 @@ WIN32;_DEBUG;_CONSOLE;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true 4819 + stdcpp20 + stdc17 Console @@ -113,6 +115,9 @@ true MultiThreaded 4819 + stdcpp20 + stdc17 + /utf-8 %(AdditionalOptions) Console @@ -127,6 +132,8 @@ true _DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true + stdcpp20 + stdc17 Console @@ -143,6 +150,9 @@ true MultiThreaded 4819 + stdcpp20 + stdc17 + /utf-8 %(AdditionalOptions) Console @@ -154,6 +164,7 @@ + @@ -163,6 +174,7 @@ + diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.filters b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.filters index 808b1e5..71f8003 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.filters +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.filters @@ -33,6 +33,9 @@ 源文件 + + 源文件 + @@ -53,5 +56,8 @@ 头文件 + + 头文件 + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp index 6ed1a05..63c3d75 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp @@ -127,12 +127,12 @@ bool XEngine_SocksTask_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int { int nListCount = 0; XCHAR** ppszListAddr; - ENUM_APIHELP_DOMAINTYPE enDomainType; - APIHELP_DOMAIN st_APIUrl; + ENUM_NETHELP_APIADDR_DOMAIN_TYPE enDomainType; + APIADDR_DOMAIN st_APIUrl; - memset(&st_APIUrl, '\0', sizeof(APIHELP_DOMAIN)); + memset(&st_APIUrl, '\0', sizeof(APIADDR_DOMAIN)); - APIHelp_Domain_GetInfo(tszClientAddr, &st_APIUrl, &enDomainType); + APIAddr_Domain_GetInfo(tszClientAddr, &st_APIUrl, &enDomainType); memset(tszClientAddr, '\0', sizeof(tszClientAddr)); if (_tcsxlen(st_APIUrl.tszSubDomain) > 0) { @@ -150,7 +150,7 @@ bool XEngine_SocksTask_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int } memset(tszClientAddr, '\0', sizeof(tszClientAddr)); _tcsxcpy(tszClientAddr, ppszListAddr[0]); //随便选择一个IP地址 - BaseLib_OperatorMemory_Free((XPPPMEM)&ppszListAddr, nListCount); + BaseLib_Memory_Free((XPPPMEM)&ppszListAddr, nListCount); if (!XClient_TCPSelect_InsertEx(xhSocksClient, &st_ProxyClient.xhClient, tszClientAddr, nPort)) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("SOCKS客户端:%s,创建客户端连接失败,连接到服务器:%s:%d,错误:%lX"), lpszClientAddr, tszClientAddr, nPort, XClient_GetLastError()); @@ -211,5 +211,5 @@ void CALLBACK XEngine_Socks_CBRecv(XHANDLE xhToken, XNETHANDLE xhClient, XSOCKET break; } } - BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ClientList, nListCount); + BaseLib_Memory_Free((XPPPMEM)&ppSt_ClientList, nListCount); } \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp index 8c0743c..f17fc4a 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp @@ -45,7 +45,7 @@ bool XEngine_TunnelTask_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, in XCHAR tszConnectAddr[128]; memset(tszConnectAddr, '\0', sizeof(tszConnectAddr)); //是否为IP地址 - if (BaseLib_OperatorIPAddr_IsIPV4Addr(tszIPAddr)) + if (APIAddr_IPAddr_IsIPV4Addr(tszIPAddr)) { _tcsxcpy(tszConnectAddr, tszIPAddr); } @@ -53,12 +53,12 @@ bool XEngine_TunnelTask_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, in { int nListCount = 0; XCHAR** ppszListAddr; - ENUM_APIHELP_DOMAINTYPE enDomainType; - APIHELP_DOMAIN st_APIUrl; + ENUM_NETHELP_APIADDR_DOMAIN_TYPE enDomainType; + APIADDR_DOMAIN st_APIUrl; - memset(&st_APIUrl, '\0', sizeof(APIHELP_DOMAIN)); + memset(&st_APIUrl, '\0', sizeof(APIADDR_DOMAIN)); - APIHelp_Domain_GetInfo(tszIPAddr, &st_APIUrl, &enDomainType); + APIAddr_Domain_GetInfo(tszIPAddr, &st_APIUrl, &enDomainType); memset(tszIPAddr, '\0', sizeof(tszIPAddr)); if (_tcsxlen(st_APIUrl.tszSubDomain) > 0) { @@ -77,7 +77,7 @@ bool XEngine_TunnelTask_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, in return false; } _tcsxcpy(tszConnectAddr, ppszListAddr[0]); //随便选择一个IP地址 - BaseLib_OperatorMemory_Free((XPPPMEM)&ppszListAddr, nListCount); + BaseLib_Memory_Free((XPPPMEM)&ppszListAddr, nListCount); } if (!XClient_TCPSelect_InsertEx(xhTunnelClient, &st_ProxyClient.xhClient, tszConnectAddr, nIPPort)) { @@ -137,5 +137,5 @@ void CALLBACK XEngine_Tunnel_CBRecv(XHANDLE xhToken, XNETHANDLE xhClient, XSOCKE break; } } - BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ClientList, nListCount); + BaseLib_Memory_Free((XPPPMEM)&ppSt_ClientList, nListCount); } \ No newline at end of file