From 1cc50412d6e05b24dbf77ae7db099696ac9ede0d Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Tue, 7 Dec 2021 13:21:18 +0800 Subject: [PATCH 01/12] added:base framework code and release dir --- .../XEngine_Config/XEngine_Config.json | 21 ++ XEngine_Release/XEngine_Log/.gitignore | 0 XEngine_Source/Makefile | 27 +++ XEngine_Source/VSClean.bat | 10 + XEngine_Source/VSCopy-x86.bat | 14 ++ XEngine_Source/XEngine.sln | 46 +++++ .../XEngine_ModuleConfigure/Makefile | 45 ++++ .../ModuleConfig_Define.h | 66 ++++++ .../ModuleConfig_Error.h | 18 ++ .../ModuleConfigure_Json.cpp | 122 +++++++++++ .../ModuleConfigure_Json.h | 23 +++ .../XEngine_ModuleConfigure.def | 6 + .../XEngine_ModuleConfigure.vcxproj | 183 +++++++++++++++++ .../XEngine_ModuleConfigure.vcxproj.filters | 56 +++++ .../XEngine_ModuleConfigure.vcxproj.user | 4 + .../XEngine_ModuleConfigure/dllmain.cpp | 19 ++ .../XEngine_ModuleConfigure/framework.h | 5 + .../XEngine_ModuleConfigure/pch.cpp | 35 ++++ XEngine_Source/XEngine_ModuleConfigure/pch.h | 44 ++++ XEngine_Source/XEngine_ServiceApp/Makefile | 49 +++++ .../XEngine_ServiceApp/XEngine_Configure.cpp | 56 +++++ .../XEngine_ServiceApp/XEngine_Configure.h | 14 ++ .../XEngine_ServiceApp/XEngine_Hdr.h | 79 +++++++ .../XEngine_ServiceApp/XEngine_Network.cpp | 121 +++++++++++ .../XEngine_ServiceApp/XEngine_Network.h | 25 +++ .../XEngine_ServiceApp/XEngine_ServiceApp.cpp | 192 ++++++++++++++++++ .../XEngine_ServiceApp.vcxproj | 161 +++++++++++++++ .../XEngine_ServiceApp.vcxproj.filters | 51 +++++ .../XEngine_ServiceApp.vcxproj.user | 4 + .../XEngine_ServiceApp/XEngine_SocksTask.cpp | 17 ++ .../XEngine_ServiceApp/XEngine_SocksTask.h | 14 ++ .../XEngine_ServiceApp/XEngine_TunnelTask.cpp | 17 ++ .../XEngine_ServiceApp/XEngine_TunnelTask.h | 14 ++ XEngine_Source/XEngine_UserProtocol.h | 32 +++ 34 files changed, 1590 insertions(+) create mode 100644 XEngine_Release/XEngine_Config/XEngine_Config.json create mode 100644 XEngine_Release/XEngine_Log/.gitignore create mode 100644 XEngine_Source/Makefile create mode 100644 XEngine_Source/VSClean.bat create mode 100644 XEngine_Source/VSCopy-x86.bat create mode 100644 XEngine_Source/XEngine.sln create mode 100644 XEngine_Source/XEngine_ModuleConfigure/Makefile create mode 100644 XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h create mode 100644 XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h create mode 100644 XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp create mode 100644 XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.h create mode 100644 XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.def create mode 100644 XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj create mode 100644 XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj.filters create mode 100644 XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj.user create mode 100644 XEngine_Source/XEngine_ModuleConfigure/dllmain.cpp create mode 100644 XEngine_Source/XEngine_ModuleConfigure/framework.h create mode 100644 XEngine_Source/XEngine_ModuleConfigure/pch.cpp create mode 100644 XEngine_Source/XEngine_ModuleConfigure/pch.h create mode 100644 XEngine_Source/XEngine_ServiceApp/Makefile create mode 100644 XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp create mode 100644 XEngine_Source/XEngine_ServiceApp/XEngine_Configure.h create mode 100644 XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h create mode 100644 XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp create mode 100644 XEngine_Source/XEngine_ServiceApp/XEngine_Network.h create mode 100644 XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp create mode 100644 XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj create mode 100644 XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.filters create mode 100644 XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.user create mode 100644 XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp create mode 100644 XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.h create mode 100644 XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp create mode 100644 XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.h create mode 100644 XEngine_Source/XEngine_UserProtocol.h diff --git a/XEngine_Release/XEngine_Config/XEngine_Config.json b/XEngine_Release/XEngine_Config/XEngine_Config.json new file mode 100644 index 0000000..dbc10ae --- /dev/null +++ b/XEngine_Release/XEngine_Config/XEngine_Config.json @@ -0,0 +1,21 @@ +{ + "tszIPAddr":"192.168.1.12", + "bDeamon":0, + "nSocksPort":5000, + "nTunnelPort":5001, + "XMax":{ + "nMaxClient":10000, + "nMaxQueue":10000, + "nIOThread":2 + }, + "XTime":{ + "nTimeCheck":3, + "nSocksTimeOut":5, + "nTunnelTimeOut":5 + }, + "XLog":{ + "MaxSize":1024000, + "MaxCount":10, + "LogLeave":32 + } +} \ No newline at end of file diff --git a/XEngine_Release/XEngine_Log/.gitignore b/XEngine_Release/XEngine_Log/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/XEngine_Source/Makefile b/XEngine_Source/Makefile new file mode 100644 index 0000000..1f2ecd6 --- /dev/null +++ b/XEngine_Source/Makefile @@ -0,0 +1,27 @@ +RELEASE = 0 +UNICODE = 0 +#编译的选项参数 +FLAGS = RELEASE=$(RELEASE) +#要编译的模块 +MODULE_CONFIGURE_PATH = ./XEngine_ModuleConfigure +APP_SERVICE_PATH = ./XEngine_ServiceApp + +XENGINE_MODULES = libXEngine_ModuleConfigure.so XEngine_ServiceApp.exe + +.PHONY:MakeAll +MakeAll:$(XENGINE_MODULES) + +libXEngine_ModuleConfigure.so: + make -C $(MODULE_CONFIGURE_PATH) $(FLAGS) + +XEngine_ServiceApp.exe: + make -C $(APP_SERVICE_PATH) $(FLAGS) + + +SetFlags_Install: + export FLAGS=InstallAll +InstallAll:SetFlags_Install $(NETENGINE_LIB) + +SetFlags_Clean: + export FLAGS=CleanAll +CleanAll:SetFlags_Clean $(NETENGINE_LIB) diff --git a/XEngine_Source/VSClean.bat b/XEngine_Source/VSClean.bat new file mode 100644 index 0000000..bf8eca3 --- /dev/null +++ b/XEngine_Source/VSClean.bat @@ -0,0 +1,10 @@ +@echo Off +del /s /a *.ncb *.so *.o *.db +FOR /R . %%d IN (.) DO rd /s /q "%%d\Debug" 2>nul +FOR /R . %%d IN (.) DO rd /s /q "%%d\Release" 2>nul +FOR /R . %%d IN (.) DO rd /s /q "%%d\x64" 2>nul +FOR /R . %%d IN (.) DO rd /s /q "%%d\Debug" 2>nul +FOR /R . %%d IN (.) DO rd /s /q "%%d\ipch" 2>nul + +rem If the Properties directory is empty, remove it +FOR /R . %%d in (.) do rd /q "%%d\Properties" 2> nul diff --git a/XEngine_Source/VSCopy-x86.bat b/XEngine_Source/VSCopy-x86.bat new file mode 100644 index 0000000..68d65d6 --- /dev/null +++ b/XEngine_Source/VSCopy-x86.bat @@ -0,0 +1,14 @@ +copy /y "%XEngine_Library%\x86\XEngine_BaseLib\XEngine_BaseLib.dll" "./" +copy /y "%XEngine_Library%\x86\XEngine_BaseLib\XEngine_Algorithm.dll" "./" +copy /y "%XEngine_Library%\x86\XEngine_Core\XEngine_Core.dll" "./" +copy /y "%XEngine_Library%\x86\XEngine_Core\XEngine_ManagePool.dll" "./" + +copy /y "%XEngine_Library%\x86\XEngine_SystemSdk\XEngine_SystemApi.dll" "./" + +copy /y "%XEngine_Library%\x86\XEngine_HelpComponents\HelpComponents_Packets.dll" "./" +copy /y "%XEngine_Library%\x86\XEngine_HelpComponents\HelpComponents_XLog.dll" "./" +copy /y "%XEngine_Library%\x86\XEngine_RfcComponents\RfcComponents_HttpServer.dll" "./" + +copy /y "%XEngine_Library%\x86\XEngine_LibEx\libcrypto-1_1.dll" "./" +copy /y "%XEngine_Library%\x86\XEngine_LibEx\libssl-1_1.dll" "./" +copy /y "%XEngine_Library%\x86\XEngine_HelpComponents\zlib1.dll" "./" \ No newline at end of file diff --git a/XEngine_Source/XEngine.sln b/XEngine_Source/XEngine.sln new file mode 100644 index 0000000..8d39a11 --- /dev/null +++ b/XEngine_Source/XEngine.sln @@ -0,0 +1,46 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31911.196 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XEngine_ServiceApp", "XEngine_ServiceApp\XEngine_ServiceApp.vcxproj", "{B94018F9-541B-4BE4-A2A8-AD49DD35357B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XEngine_ModuleConfigure", "XEngine_ModuleConfigure\XEngine_ModuleConfigure.vcxproj", "{F54F152C-594F-4465-A44E-2DB915B39760}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "XEngine_UserHdr", "XEngine_UserHdr", "{9E4F2158-9AC1-4C19-A3F7-375A9DBCF856}" + ProjectSection(SolutionItems) = preProject + XEngine_UserProtocol.h = XEngine_UserProtocol.h + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B94018F9-541B-4BE4-A2A8-AD49DD35357B}.Debug|x64.ActiveCfg = Debug|x64 + {B94018F9-541B-4BE4-A2A8-AD49DD35357B}.Debug|x64.Build.0 = Debug|x64 + {B94018F9-541B-4BE4-A2A8-AD49DD35357B}.Debug|x86.ActiveCfg = Debug|Win32 + {B94018F9-541B-4BE4-A2A8-AD49DD35357B}.Debug|x86.Build.0 = Debug|Win32 + {B94018F9-541B-4BE4-A2A8-AD49DD35357B}.Release|x64.ActiveCfg = Release|x64 + {B94018F9-541B-4BE4-A2A8-AD49DD35357B}.Release|x64.Build.0 = Release|x64 + {B94018F9-541B-4BE4-A2A8-AD49DD35357B}.Release|x86.ActiveCfg = Release|Win32 + {B94018F9-541B-4BE4-A2A8-AD49DD35357B}.Release|x86.Build.0 = Release|Win32 + {F54F152C-594F-4465-A44E-2DB915B39760}.Debug|x64.ActiveCfg = Debug|x64 + {F54F152C-594F-4465-A44E-2DB915B39760}.Debug|x64.Build.0 = Debug|x64 + {F54F152C-594F-4465-A44E-2DB915B39760}.Debug|x86.ActiveCfg = Debug|Win32 + {F54F152C-594F-4465-A44E-2DB915B39760}.Debug|x86.Build.0 = Debug|Win32 + {F54F152C-594F-4465-A44E-2DB915B39760}.Release|x64.ActiveCfg = Release|x64 + {F54F152C-594F-4465-A44E-2DB915B39760}.Release|x64.Build.0 = Release|x64 + {F54F152C-594F-4465-A44E-2DB915B39760}.Release|x86.ActiveCfg = Release|Win32 + {F54F152C-594F-4465-A44E-2DB915B39760}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9B202F91-A601-429E-BB0F-880DDEE096FE} + EndGlobalSection +EndGlobal diff --git a/XEngine_Source/XEngine_ModuleConfigure/Makefile b/XEngine_Source/XEngine_ModuleConfigure/Makefile new file mode 100644 index 0000000..1a44416 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleConfigure/Makefile @@ -0,0 +1,45 @@ +CC = g++ -Wall -std=c++17 -fPIC +RELEASE = 0 +UNICODE = 0 +INCLUDE = -I ./ +LOADBIN = +LIB = -ljsoncpp +LIBEX = -static-libgcc -lrt -ldl -lpthread +LOADSO = -Wl,-rpath= +LIBINCLUDE = ModuleConfigure_Json.o pch.o + +ifeq ($(RELEASE),1) +FLAGS = -c -O2 +DEBUG = +else +FLAGS = -c -lc_p +DEBUG = -g -pg +endif + +ifeq ($(UNICODE),1) +UNICODE = -D _UNICODE +else +UNICODE = +endif + + +all:$(LIBINCLUDE) + $(CC) $(DEBUG) $(LIBINCLUDE) -o libXEngine_ModuleConfigure.so -shared -fPIC $(LOADBIN) $(LIB) $(LIBEX) $(LOADSO) + +ModuleConfigure_Json.o:./ModuleConfigure_Json/ModuleConfigure_Json.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./ModuleConfigure_Json/ModuleConfigure_Json.cpp + +pch.o:./pch.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./pch.cpp + + +InstallAll:InstallSo +InstallSo:./libXEngine_ModuleConfigure.so + cp ./libXEngine_ModuleConfigure.so ../../XEngine_Release/libXEngine_ModuleConfigure.so + + +CleanAll:CleanObj CleanMk +CleanObj: + rm *.o +CleanMk: + rm *.so diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h new file mode 100644 index 0000000..f5aead6 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h @@ -0,0 +1,66 @@ +#pragma once +/******************************************************************** +// Created: 2021/12/02 16:09:03 +// File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ModuleConfigure\ModuleConfig_Define.h +// File Path: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ModuleConfigure +// File Base: ModuleConfig_Define +// File Ext: h +// Project: XEngine(ͨ) +// Author: qyt +// Purpose: ģ鵼 +// History: +*********************************************************************/ +////////////////////////////////////////////////////////////////////////// +// ݽṹ +////////////////////////////////////////////////////////////////////////// +typedef struct tag_XEngine_ServiceConfig +{ + TCHAR tszIPAddr[128]; //IPַ,Ҫ + BOOL bDeamon; //Ƿػ,LINUXЧ + int nSocksPort; //Socks˿,<=0 + int nTunnelPort; //Tunnel˿ + struct + { + int nMaxClient; //ͻ˸ + int nMaxQueue; //и + int nIOThread; //IO߳ + }st_XMax; + struct + { + int nTimeCheck; // + int nSocksTimeOut; //TCPʱʱ + int nTunnelTimeOut; //HTTPʱʱ + }st_XTime; //*ʱ=ʱ + struct + { + int nMaxSize; //־С + int nMaxCount; //־ + int nLogLeave; //־ȼ + }st_XLog; +}XENGINE_SERVICECONFIG; +////////////////////////////////////////////////////////////////////////// +// +////////////////////////////////////////////////////////////////////////// +extern "C" DWORD ModuleConfigure_GetLastError(int* pInt_ErrorCode = NULL); +/************************************************************************/ +/* ļöȡ */ +/************************************************************************/ +/******************************************************************** +ƣModuleConfigure_Json_File +ܣȡJSONļ + .һlpszConfigFile + In/OutIn + ַָͣ + ɿգN + ˼Ҫȡļ + .pSt_ServerConfig + In/OutOut + ͣݽṹָ + ɿգN + ˼Ϣ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +extern "C" BOOL ModuleConfigure_Json_File(LPCTSTR lpszConfigFile, XENGINE_SERVICECONFIG* pSt_ServerConfig); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h new file mode 100644 index 0000000..5c074ed --- /dev/null +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h @@ -0,0 +1,18 @@ +#pragma once +/******************************************************************** +// Created: 2021/12/02 16:15:47 +// File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ModuleConfigure\ModuleConfig_Error.h +// File Path: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ModuleConfigure +// File Base: ModuleConfig_Error +// File Ext: h +// Project: XEngine(ͨ) +// Author: qyt +// Purpose: ģ鵼 +// History: +*********************************************************************/ +#define ERROR_MODULE_CONFIGURE_JSON_PARAMENT 0xA0001 // +#define ERROR_MODULE_CONFIGURE_JSON_OPENFILE 0xA0002 //ļʧ +#define ERROR_MODULE_CONFIGURE_JSON_PARSE 0xA0003 //JSONʧ +#define ERROR_MODULE_CONFIGURE_JSON_XMAX 0xA0004 //ȡXMAXʧ +#define ERROR_MODULE_CONFIGURE_JSON_XTIME 0xA0005 //ȡXTIMEʧ +#define ERROR_MODULE_CONFIGURE_JSON_XLOG 0xA0006 //ȡXLOGʧ \ 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 new file mode 100644 index 0000000..2685847 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp @@ -0,0 +1,122 @@ +#include "pch.h" +#include "ModuleConfigure_Json.h" +/******************************************************************** +// Created: 2021/12/02 16:14:11 +// File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ModuleConfigure\ModuleConfigure_Json\ModuleConfigure_Json.cpp +// File Path: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ModuleConfigure\ModuleConfigure_Json +// File Base: ModuleConfigure_Json +// File Ext: cpp +// Project: XEngine(ͨ) +// Author: qyt +// Purpose: JSONöдʵ +// History: +*********************************************************************/ +CModuleConfigure_Json::CModuleConfigure_Json() +{ + +} +CModuleConfigure_Json::~CModuleConfigure_Json() +{ + +} +////////////////////////////////////////////////////////////////////////// +// ú +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +ƣModuleConfigure_Json_File +ܣȡJSONļ + .һlpszConfigFile + In/OutIn + ַָͣ + ɿգN + ˼Ҫȡļ + .pSt_ServerConfig + In/OutOut + ͣݽṹָ + ɿգN + ˼Ϣ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +BOOL CModuleConfigure_Json::ModuleConfigure_Json_File(LPCTSTR lpszConfigFile, XENGINE_SERVICECONFIG* pSt_ServerConfig) +{ + Config_IsErrorOccur = FALSE; + + if ((NULL == lpszConfigFile) || (NULL == pSt_ServerConfig)) + { + Config_IsErrorOccur = TRUE; + Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_PARAMENT; + return FALSE; + } + Json::Value st_JsonRoot; + JSONCPP_STRING st_JsonError; + Json::CharReaderBuilder st_JsonBuilder; + //ȡļݵ + FILE* pSt_File = _tfopen(lpszConfigFile, _T("rb")); + if (NULL == pSt_File) + { + Config_IsErrorOccur = TRUE; + Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_OPENFILE; + return FALSE; + } + int nCount = 0; + TCHAR tszMsgBuffer[4096]; + while (1) + { + int nRet = fread(tszMsgBuffer + nCount, 1, 2048, pSt_File); + if (nRet <= 0) + { + break; + } + nCount += nRet; + } + fclose(pSt_File); + //ʼļ + std::unique_ptr const pSt_JsonReader(st_JsonBuilder.newCharReader()); + if (!pSt_JsonReader->parse(tszMsgBuffer, tszMsgBuffer + nCount, &st_JsonRoot, &st_JsonError)) + { + Config_IsErrorOccur = TRUE; + Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_PARSE; + return FALSE; + } + _tcscpy(pSt_ServerConfig->tszIPAddr, st_JsonRoot["tszIPAddr"].asCString()); + pSt_ServerConfig->bDeamon = st_JsonRoot["bDeamon"].asInt(); + pSt_ServerConfig->nSocksPort = st_JsonRoot["nSocksPort"].asInt(); + pSt_ServerConfig->nTunnelPort = st_JsonRoot["nTunnelPort"].asInt(); + + if (st_JsonRoot["XMax"].empty() || (3 != st_JsonRoot["XMax"].size())) + { + Config_IsErrorOccur = TRUE; + Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XMAX; + return FALSE; + } + Json::Value st_JsonXMax = st_JsonRoot["XMax"]; + pSt_ServerConfig->st_XMax.nMaxClient = st_JsonXMax["nMaxClient"].asInt(); + pSt_ServerConfig->st_XMax.nMaxQueue = st_JsonXMax["nMaxQueue"].asInt(); + pSt_ServerConfig->st_XMax.nIOThread = st_JsonXMax["nIOThread"].asInt(); + + if (st_JsonRoot["XTime"].empty() || (3 != st_JsonRoot["XTime"].size())) + { + Config_IsErrorOccur = TRUE; + Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XTIME; + return FALSE; + } + 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(); + + if (st_JsonRoot["XLog"].empty() || (3 != st_JsonRoot["XLog"].size())) + { + Config_IsErrorOccur = TRUE; + Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XLOG; + return FALSE; + } + Json::Value st_JsonXLog = st_JsonRoot["XLog"]; + 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(); + return TRUE; +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.h b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.h new file mode 100644 index 0000000..43943ed --- /dev/null +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.h @@ -0,0 +1,23 @@ +#pragma once +/******************************************************************** +// Created: 2021/12/02 16:08:16 +// File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ModuleConfigure\ModuleConfigure_Json\ModuleConfigure_Json.h +// File Path: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ModuleConfigure\ModuleConfigure_Json +// File Base: ModuleConfigure_Json +// File Ext: h +// Project: XEngine(ͨ) +// Author: qyt +// Purpose: JSONļд +// History: +*********************************************************************/ + +class CModuleConfigure_Json +{ +public: + CModuleConfigure_Json(); + ~CModuleConfigure_Json(); +public: + BOOL ModuleConfigure_Json_File(LPCTSTR lpszConfigFile, XENGINE_SERVICECONFIG* pSt_ServerConfig); +protected: +private: +}; \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.def b/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.def new file mode 100644 index 0000000..6255e07 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.def @@ -0,0 +1,6 @@ +LIBRARY + +EXPORTS + ModuleConfigure_GetLastError + + ModuleConfigure_Json_File \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj b/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj new file mode 100644 index 0000000..acc2a80 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj @@ -0,0 +1,183 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {f54f152c-594f-4465-a44e-2db915b39760} + XEngineModuleConfigure + 10.0 + + + + DynamicLibrary + true + v142 + MultiByte + + + DynamicLibrary + false + v142 + true + Unicode + + + DynamicLibrary + true + v142 + Unicode + + + DynamicLibrary + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;XENGINEMODULECONFIGURE_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + 4819 + + + Windows + true + false + XEngine_ModuleConfigure.def + + + + + Level3 + true + true + true + WIN32;NDEBUG;XENGINEMODULECONFIGURE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + XEngine_ModuleConfigure.def + + + + + Level3 + true + _DEBUG;XENGINEMODULECONFIGURE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + XEngine_ModuleConfigure.def + + + + + Level3 + true + true + true + NDEBUG;XENGINEMODULECONFIGURE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + XEngine_ModuleConfigure.def + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj.filters b/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj.filters new file mode 100644 index 0000000..a8d85e7 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj.filters @@ -0,0 +1,56 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {49ae8b29-d807-47ec-907b-b4e5c91e1f62} + + + {865425d8-f7eb-4fb9-bcd1-8bb631209b4e} + + + + + 头文件 + + + 头文件 + + + 头文件\ModuleConfigure_Json + + + 头文件 + + + 头文件 + + + + + 源文件 + + + 源文件 + + + 源文件\ModuleConfigure_Json + + + + + 源文件 + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj.user b/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/dllmain.cpp b/XEngine_Source/XEngine_ModuleConfigure/dllmain.cpp new file mode 100644 index 0000000..daed8c8 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleConfigure/dllmain.cpp @@ -0,0 +1,19 @@ +// dllmain.cpp : 定义 DLL 应用程序的入口点。 +#include "pch.h" + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + diff --git a/XEngine_Source/XEngine_ModuleConfigure/framework.h b/XEngine_Source/XEngine_ModuleConfigure/framework.h new file mode 100644 index 0000000..80cbbc9 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleConfigure/framework.h @@ -0,0 +1,5 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 +// Windows 头文件 +#include diff --git a/XEngine_Source/XEngine_ModuleConfigure/pch.cpp b/XEngine_Source/XEngine_ModuleConfigure/pch.cpp new file mode 100644 index 0000000..2a4bfa5 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleConfigure/pch.cpp @@ -0,0 +1,35 @@ +#include "pch.h" +#include "ModuleConfigure_Json/ModuleConfigure_Json.h" +/******************************************************************** +// Created: 2021/12/02 16:20:26 +// File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ModuleConfigure\pch.cpp +// File Path: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ModuleConfigure +// File Base: pch +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 导出函数实现 +// History: +*********************************************************************/ +BOOL Config_IsErrorOccur = FALSE; +DWORD Config_dwErrorCode = 0; +////////////////////////////////////////////////////////////////////// +CModuleConfigure_Json m_ConfigJson; +////////////////////////////////////////////////////////////////////// +// 导出函数定义 +////////////////////////////////////////////////////////////////////// +extern "C" DWORD ModuleConfigure_GetLastError(int* pInt_ErrorCode) +{ + if (pInt_ErrorCode != NULL) + { + *pInt_ErrorCode = errno; + } + return Config_dwErrorCode; +} +/************************************************************************/ +/* 配置文件读取 */ +/************************************************************************/ +extern "C" BOOL ModuleConfigure_Json_File(LPCTSTR lpszConfigFile, XENGINE_SERVICECONFIG * pSt_ServerConfig) +{ + return m_ConfigJson.ModuleConfigure_Json_File(lpszConfigFile, pSt_ServerConfig); +} diff --git a/XEngine_Source/XEngine_ModuleConfigure/pch.h b/XEngine_Source/XEngine_ModuleConfigure/pch.h new file mode 100644 index 0000000..5bbbd53 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleConfigure/pch.h @@ -0,0 +1,44 @@ +// pch.h: 这是预编译标头文件。 +// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 +// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 +// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 +// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 + +#ifndef PCH_H +#define PCH_H + +#ifdef _WINDOWS +// 添加要在此处预编译的标头 +#include "framework.h" +#include +#include +#else +#ifdef _CENTOS +#include +#else +#include +#endif +#endif +#endif //PCH_H +#include +#include +#include +#include +using namespace std; +#include +#include +#include "ModuleConfig_Define.h" +#include "ModuleConfig_Error.h" +/******************************************************************** +// Created: 2021/12/02 16:07:58 +// File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ModuleConfigure\pch.h +// File Path: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ModuleConfigure +// File Base: pch +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 公用头文件 +// History: +*********************************************************************/ +extern BOOL Config_IsErrorOccur; +extern DWORD Config_dwErrorCode; \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/Makefile b/XEngine_Source/XEngine_ServiceApp/Makefile new file mode 100644 index 0000000..650e95e --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/Makefile @@ -0,0 +1,49 @@ +CC = g++ -Wall +RELEASE = 0 +UNICODE = 0 +LOADBIN = -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_Core -L /usr/local/lib/XEngine_Release/XEngine_HelpComponents -L /usr/local/lib/XEngine_Release/XEngine_RfcComponents -L ../XEngine_ModuleConfigure +LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_ManagePool -lHelpComponents_XLog -lHelpComponents_Packets -lRfcComponents_HttpServer -lXEngine_ModuleConfigure +LIBEX = -static-libgcc -ldl -lrt -lpthread +LOADSO = -Wl,-rpath=./,--disable-new-dtags +LIBINCLUDE = XEngine_Configure.o XEngine_Network.o XEngine_TCPTask.o XEngine_HTTPTask.o XEngine_ServiceApp.o + +ifeq ($(RELEASE),1) +FLAGS = -c -O2 +DEBUG = +else +FLAGS = -c -lc_p +DEBUG = -g -pg +endif + +ifeq ($(UNICODE),1) +UNICODE = -D _UNICODE +else +UNICODE = +endif + +all:$(LIBINCLUDE) + $(CC) $(DEBUG) $(LIBINCLUDE) -o XEngine_ServiceApp $(LOADBIN) $(LIB) $(LIBEX) $(LOADSO) + +XEngine_Configure.o:./XEngine_Configure.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) ./XEngine_Configure.cpp +XEngine_Network.o:./XEngine_Network.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) ./XEngine_Network.cpp +XEngine_TCPTask.o:./XEngine_TCPTask.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) ./XEngine_TCPTask.cpp +XEngine_HTTPTask.o:./XEngine_HTTPTask.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) ./XEngine_HTTPTask.cpp + +XEngine_ServiceApp.o:./XEngine_ServiceApp.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) ./XEngine_ServiceApp.cpp + + +InstallAll:InstallApp +InstallApp:./XEngine_ServiceApp + cp -f ./XEngine_ServiceApp ../../XEngine_Release/XEngine_ServiceApp + +CleanAll:CleanObj CleanMk +CleanObj: + rm *.o +CleanMk: + rm XEngine_ServiceApp + diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp new file mode 100644 index 0000000..4a30366 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.cpp @@ -0,0 +1,56 @@ +#include "XEngine_Hdr.h" +/******************************************************************** +// Created: 2021/12/02 16:34:09 +// File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp\XEngine_Configure.cpp +// File Path: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp +// File Base: XEngine_Configure +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 配置文件读写代码 +// History: +*********************************************************************/ +BOOL XEngine_Configure_Parament(int argc, char** argv, XENGINE_SERVICECONFIG* pSt_Configure) +{ + LPCTSTR lpszConfigFile = _T("./XEngine_Config/XEngine_Config.json"); + + if (!ModuleConfigure_Json_File(lpszConfigFile, pSt_Configure)) + { + printf("解析配置文件失败,ModuleConfigure_Json_File:%lX\n", ModuleConfigure_GetLastError()); + return FALSE; + } + + for (int i = 0; i < argc; i++) + { + if ((0 == _tcscmp("-h", argv[i])) || (0 == _tcscmp("-H", argv[i]))) + { + XEngine_Configure_Help(); + return FALSE; + } + else if (0 == _tcscmp("-TP", argv[i])) + { + pSt_Configure->nSocksPort = _ttoi(argv[i + 1]); + } + else if (0 == _tcscmp("-HP", argv[i])) + { + pSt_Configure->nTunnelPort = _ttoi(argv[i + 1]); + } + else if (0 == _tcscmp("-d", argv[i])) + { + pSt_Configure->bDeamon = _ttoi(argv[i + 1]); + } + } + + return TRUE; +} + +void XEngine_Configure_Help() +{ + printf(_T("--------------------------启动参数帮助开始--------------------------\n")); + printf(_T("网络消息队列服务启动参数:程序 参数 参数值,参数是区分大小写的。如果不指定将会加载默认的ini配置文件里面的参数\n")); + printf(_T("-h or -H:启动参数帮助提示信息\n")); + printf(_T("-TP:设置消息队列TCP服务端口号\n")); + printf(_T("-HP:设置消息队列HTTP服务端口号\n")); + printf(_T("-d:1 启用守护进程,2不启用\n")); + printf(_T("--------------------------启动参数帮助结束--------------------------\n")); +} diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.h b/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.h new file mode 100644 index 0000000..bcf8203 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Configure.h @@ -0,0 +1,14 @@ +#pragma once +/******************************************************************** +// Created: 2021/12/02 16:33:25 +// File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp\XEngine_Configure.h +// File Path: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp +// File Base: XEngine_Configure +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 配置文件操作代码 +// History: +*********************************************************************/ +BOOL XEngine_Configure_Parament(int argc, char** argv, XENGINE_SERVICECONFIG* pSt_Configure); +void XEngine_Configure_Help(); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h new file mode 100644 index 0000000..bd140c1 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h @@ -0,0 +1,79 @@ +#pragma once +//加载系统头文件 +#include +#include +#include +#include +#include +#include +#ifdef _WINDOWS +#include +#include +#else +#include +#include +#include +#endif +using namespace std; +//加载XEngine头文件 +#include +#include +#include +#include +#include +#include +#include +#include +#include +//加载项目相关头文件 +#include "../XEngine_UserProtocol.h" +#include "../XEngine_ModuleConfigure/ModuleConfig_Define.h" +#include "../XEngine_ModuleConfigure/ModuleConfig_Error.h" +//加载自己的头文件 +#include "XEngine_Configure.h" +#include "XEngine_Network.h" +#include "XEngine_SocksTask.h" +#include "XEngine_TunnelTask.h" +/******************************************************************** +// Created: 2021/12/02 16:34:41 +// File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp\XEngine_Hdr.h +// File Path: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp +// File Base: XEngine_Hdr +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 公用头文件 +// History: +*********************************************************************/ +extern BOOL bIsRun; +extern XLOG xhLog; +//Socks服务器 +extern XNETHANDLE xhSocksSocket; +extern XNETHANDLE xhSocksHeart; +//Tunnel服务器 +extern XNETHANDLE xhTunnelSocket; +extern XNETHANDLE xhTunnelHeart; +//配置文件 +extern XENGINE_SERVICECONFIG st_ServiceConfig; + +//网络类型定义 +#define XENGINE_CLIENT_NETTYPE_SOCKS 1 +#define XENGINE_CLIENT_NETTYPE_TUNNEL 2 + + +//连接库 +#ifdef _WINDOWS +#ifdef _WIN64 +#pragma comment(lib,"../x64/Release/XEngine_ModuleConfigure.lib") +#else +#ifdef _DEBUG +#pragma comment(lib,"../Debug/XEngine_ModuleConfigure.lib") +#else +#pragma comment(lib,"../Release/XEngine_ModuleConfigure.lib") +#endif +#endif +#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") +#pragma comment(lib,"XEngine_Core/XEngine_Core.lib") +#pragma comment(lib,"XEngine_HelpComponents/HelpComponents_XLog.lib") +#pragma comment(lib,"Ws2_32.lib") +#endif \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp new file mode 100644 index 0000000..331b3ec --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp @@ -0,0 +1,121 @@ +#include "XEngine_Hdr.h" +/******************************************************************** +// Created: 2021/12/02 16:40:28 +// File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp\XEngine_Network.cpp +// File Path: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp +// File Base: XEngine_Network +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 网络IO相关代码 +// History: +*********************************************************************/ +//////////////////////////////////////////////////////////////////////////下面是TCP网络IO相关代码处理函数 +BOOL __stdcall Network_Callback_TCPLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) +{ + //客户端连接后要把客户端插入心跳管理器中才有效 + SocketOpt_HeartBeat_InsertAddrEx(xhSocksHeart, lpszClientAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("TCP客户端:%s,连接到服务器"), lpszClientAddr); + return TRUE; +} +void __stdcall Network_Callback_TCPRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam) +{ + //需要激活一次 + SocketOpt_HeartBeat_ActiveAddrEx(xhSocksHeart, lpszClientAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_DEBUG, _T("TCP客户端:%s,投递数据包到组包队列成功,大小:%d"), lpszClientAddr, nMsgLen); +} +void __stdcall Network_Callback_TCPLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) +{ + //交给指定函数来处理客户端离开消息 + XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_SOCKS, FALSE); +} +void __stdcall Network_Callback_TCPHeart(LPCSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam) +{ + //同上 + XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_SOCKS, TRUE); +} +//////////////////////////////////////////////////////////////////////////下面是HTTP网络IO相关代码处理函数 +BOOL __stdcall Network_Callback_HTTPLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) +{ + SocketOpt_HeartBeat_InsertAddrEx(xhTunnelHeart, lpszClientAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("HTTP客户端:%s,连接到服务器"), lpszClientAddr); + return TRUE; +} +void __stdcall Network_Callback_HTTPRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam) +{ + SocketOpt_HeartBeat_ActiveAddrEx(xhTunnelHeart, lpszClientAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_DEBUG, _T("HTTP客户端:%s,投递数据包到组包队列成功,大小:%d"), lpszClientAddr, nMsgLen); +} +void __stdcall Network_Callback_HTTPLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) +{ + XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_TUNNEL, FALSE); +} +void __stdcall Network_Callback_HTTPHeart(LPCTSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam) +{ + XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_TUNNEL, TRUE); +} +//////////////////////////////////////////////////////////////////////////网络IO关闭操作 +void XEngine_Network_Close(LPCTSTR lpszClientAddr, int nIPProto, BOOL bHeart) +{ + if (XENGINE_CLIENT_NETTYPE_SOCKS == nIPProto) + { + //先关闭网络和心跳,他们主动回调的数据我们可以不用主动调用关闭 + if (bHeart) + { + //心跳超时属于主动关闭,所以要主动调用网络关闭 + NetCore_TCPXCore_CloseForClientEx(xhSocksSocket, lpszClientAddr); + } + else + { + //同上 + SocketOpt_HeartBeat_DeleteAddrEx(xhSocksHeart, lpszClientAddr); + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("TCP客户端:%s,离开服务器"), lpszClientAddr); + } + else if (XENGINE_CLIENT_NETTYPE_TUNNEL == nIPProto) + { + if (bHeart) + { + NetCore_TCPXCore_CloseForClientEx(xhTunnelSocket, lpszClientAddr); + } + else + { + SocketOpt_HeartBeat_DeleteAddrEx(xhTunnelHeart, lpszClientAddr); + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("HTTP客户端:%s,离开服务器"), lpszClientAddr); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("未知客户端:%s,离开服务器"), lpszClientAddr); + } +} +////////////////////////////////////////////////////////////////////////// +BOOL XEngine_Network_Send(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen, int nIPProto) +{ + //根据客户端类型来处理发送业务逻辑 + if (XENGINE_CLIENT_NETTYPE_SOCKS == nIPProto) + { + //发送数据给指定客户端 + if (!NetCore_TCPXCore_SendEx(xhSocksSocket, lpszClientAddr, lpszMsgBuffer, nMsgLen)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("TCP客户端:%s,发送数据失败,错误:%lX"), lpszClientAddr, NetCore_GetLastError()); + return FALSE; + } + //发送成功激活一次心跳 + SocketOpt_HeartBeat_ActiveAddrEx(xhSocksHeart, lpszClientAddr); + } + else if (XENGINE_CLIENT_NETTYPE_TUNNEL == nIPProto) + { + if (!NetCore_TCPXCore_SendEx(xhTunnelSocket, lpszClientAddr, lpszMsgBuffer, nMsgLen)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("HTTP客户端:%s,发送数据失败,错误:%lX"), lpszClientAddr, NetCore_GetLastError()); + return FALSE; + } + SocketOpt_HeartBeat_ActiveAddrEx(xhTunnelHeart, lpszClientAddr); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("未知客户端:%s,发送数据给失败,错误:%lX"), lpszClientAddr, NetCore_GetLastError()); + } + return TRUE; +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h new file mode 100644 index 0000000..548b210 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h @@ -0,0 +1,25 @@ +#pragma once +/******************************************************************** +// Created: 2021/12/02 16:39:22 +// File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp\XEngine_Network.h +// File Path: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp +// File Base: XEngine_Network +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 网络IO相关代码 +// History: +*********************************************************************/ +//TCP相关 +BOOL __stdcall Network_Callback_TCPLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam); //用户连接 +void __stdcall Network_Callback_TCPRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam); //接受到数据 +void __stdcall Network_Callback_TCPLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam); //用户离开 +void __stdcall Network_Callback_TCPHeart(LPCSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam); //心跳超时 +//HTTP相关 +BOOL __stdcall Network_Callback_HTTPLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam); +void __stdcall Network_Callback_HTTPRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam); +void __stdcall Network_Callback_HTTPLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam); +void __stdcall Network_Callback_HTTPHeart(LPCTSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam); +//关闭与发送 +void XEngine_Network_Close(LPCTSTR lpszClientAddr, int nIPProto, BOOL bHeart); +BOOL XEngine_Network_Send(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen, int nIPProto); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp new file mode 100644 index 0000000..a3a6e68 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp @@ -0,0 +1,192 @@ +#include "XEngine_Hdr.h" + +BOOL bIsRun = FALSE; +XLOG xhLog = NULL; + +XNETHANDLE xhSocksSocket = 0; +XNETHANDLE xhSocksHeart = 0; + +XNETHANDLE xhTunnelSocket = 0; +XNETHANDLE xhTunnelHeart = 0; +//配置文件 +XENGINE_SERVICECONFIG st_ServiceConfig; + +void ServiceApp_Stop(int signo) +{ + if (bIsRun) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("服务器退出...")); + bIsRun = FALSE; + //销毁TCP资源 + NetCore_TCPXCore_DestroyEx(xhSocksSocket); + SocketOpt_HeartBeat_DestoryEx(xhSocksHeart); + //销毁HTTP资源 + NetCore_TCPXCore_DestroyEx(xhTunnelSocket); + SocketOpt_HeartBeat_DestoryEx(xhTunnelHeart); + //销毁日志资源 + HelpComponents_XLog_Destroy(xhLog); + } +#ifdef _WINDOWS + WSACleanup(); +#endif + exit(0); +} +//LINUX守护进程 +static int ServiceApp_Deamon() +{ +#ifndef _WINDOWS + pid_t nPID = 0; + int nStatus = 0; + nPID = fork(); + if (nPID > 0) + { + exit(0); + } + + close(2); + while (1) + { + nPID = fork(); + if (nPID < 0) + { + exit(1); + } + if (nPID == 0) + { + return 0; + } + waitpid(nPID, &nStatus, 0); + sleep(1); + } +#endif + return 0; +} + +int main(int argc, char** argv) +{ +#ifdef _WINDOWS + WSADATA st_WSAData; + WSAStartup(MAKEWORD(2, 2), &st_WSAData); +#endif + bIsRun = TRUE; + LPCTSTR lpszLogFile = _T("./XEngine_Log/XEngine_MQServiceApp.Log"); + HELPCOMPONENTS_XLOG_CONFIGURE st_XLogConfig; + + memset(&st_XLogConfig, '\0', sizeof(HELPCOMPONENTS_XLOG_CONFIGURE)); + memset(&st_ServiceConfig, '\0', sizeof(XENGINE_SERVICECONFIG)); + + st_XLogConfig.XLog_MaxBackupFile = 10; + st_XLogConfig.XLog_MaxSize = 1024000; + _tcscpy(st_XLogConfig.tszFileName, lpszLogFile); + + signal(SIGINT, ServiceApp_Stop); + signal(SIGTERM, ServiceApp_Stop); + signal(SIGABRT, ServiceApp_Stop); + //初始化参数 + if (!XEngine_Configure_Parament(argc, argv, &st_ServiceConfig)) + { + return -1; + } + //判断是否以守护进程启动 + if (st_ServiceConfig.bDeamon) + { + ServiceApp_Deamon(); + } + //初始日志 + xhLog = HelpComponents_XLog_Init(HELPCOMPONENTS_XLOG_OUTTYPE_STD | HELPCOMPONENTS_XLOG_OUTTYPE_FILE, &st_XLogConfig); + if (NULL == xhLog) + { + printf("启动服务中,启动日志失败,错误:%lX", XLog_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + //设置日志打印级别 + HelpComponents_XLog_SetLogPriority(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,初始化日志系统成功")); + //启动TCP服务相关代码 + if (st_ServiceConfig.nSocksPort > 0) + { + //启动心跳 + if (st_ServiceConfig.st_XTime.nSocksTimeOut > 0) + { + if (!SocketOpt_HeartBeat_InitEx(&xhSocksHeart, st_ServiceConfig.st_XTime.nSocksTimeOut, st_ServiceConfig.st_XTime.nTimeCheck, Network_Callback_TCPHeart)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,初始化TCP心跳服务失败,错误:%lX"), NetCore_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,初始化TCP心跳服务成功,句柄:%llu,时间:%d,次数:%d"), xhSocksHeart, st_ServiceConfig.st_XTime.nSocksTimeOut, st_ServiceConfig.st_XTime.nTimeCheck); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,TCP心跳服务被设置为不启用")); + } + //启动网络 + if (!NetCore_TCPXCore_StartEx(&xhSocksSocket, st_ServiceConfig.nSocksPort, st_ServiceConfig.st_XMax.nMaxClient, st_ServiceConfig.st_XMax.nIOThread)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,启动TCP网络服务器失败,错误:%lX"), NetCore_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,启动TCP网络服务器成功,TCP端口:%d,网络IO线程个数:%d"), st_ServiceConfig.nSocksPort, st_ServiceConfig.st_XMax.nIOThread); + //绑定网络事件 + NetCore_TCPXCore_RegisterCallBackEx(xhSocksSocket, Network_Callback_TCPLogin, Network_Callback_TCPRecv, Network_Callback_TCPLeave); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,注册TCP网络事件成功")); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,TCP消息服务没有被启用")); + } + //启动HTTP服务相关代码 + if (st_ServiceConfig.nTunnelPort > 0) + { + //启动心跳 + if (st_ServiceConfig.st_XTime.nTunnelTimeOut > 0) + { + if (!SocketOpt_HeartBeat_InitEx(&xhTunnelHeart, st_ServiceConfig.st_XTime.nTunnelTimeOut, st_ServiceConfig.st_XTime.nTimeCheck, Network_Callback_HTTPHeart)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,初始化HTTP心跳服务失败,错误:%lX"), NetCore_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,初始化HTTP心跳服务成功,句柄:%llu,时间:%d,次数:%d"), xhTunnelHeart, st_ServiceConfig.st_XTime.nTunnelTimeOut, st_ServiceConfig.st_XTime.nTimeCheck); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,HTTP心跳服务被设置为不启用")); + } + //网络 + if (!NetCore_TCPXCore_StartEx(&xhTunnelSocket, st_ServiceConfig.nTunnelPort, st_ServiceConfig.st_XMax.nMaxClient, st_ServiceConfig.st_XMax.nIOThread)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,启动HTTP网络服务器失败,错误:%lX"), NetCore_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,启动HTTP网络服务器成功,HTTP端口:%d,IO:%d"), st_ServiceConfig.nTunnelPort, st_ServiceConfig.st_XMax.nIOThread); + NetCore_TCPXCore_RegisterCallBackEx(xhTunnelSocket, Network_Callback_HTTPLogin, Network_Callback_HTTPRecv, Network_Callback_HTTPLeave); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,注册HTTP网络事件成功")); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,HTTP消息服务没有被启用")); + } + + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("所有服务成功启动,服务运行中。。。")); + while (bIsRun) + { + std::this_thread::sleep_for(std::chrono::seconds(1)); + } +XENGINE_SERVICEAPP_EXIT: + if (bIsRun) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("有服务启动失败,服务器退出...")); + bIsRun = FALSE; + //销毁TCP资源 + NetCore_TCPXCore_DestroyEx(xhSocksSocket); + SocketOpt_HeartBeat_DestoryEx(xhSocksHeart); + //销毁HTTP资源 + NetCore_TCPXCore_DestroyEx(xhTunnelSocket); + SocketOpt_HeartBeat_DestoryEx(xhTunnelHeart); + //销毁日志资源 + HelpComponents_XLog_Destroy(xhLog); + } +#ifdef _WINDOWS + WSACleanup(); +#endif + return 0; +} diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj new file mode 100644 index 0000000..035d3a1 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj @@ -0,0 +1,161 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {b94018f9-541b-4be4-a2a8-ad49dd35357b} + XEngineServiceApp + 10.0 + + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + 4819 + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.filters b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.filters new file mode 100644 index 0000000..447abc3 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.filters @@ -0,0 +1,51 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.user b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp new file mode 100644 index 0000000..4c51702 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp @@ -0,0 +1,17 @@ +#include "XEngine_Hdr.h" +/******************************************************************** +// Created: 2021/12/02 17:08:19 +// File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp\XEngine_SocksTask.cpp +// File Path: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp +// File Base: XEngine_SocksTask +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: Socks任务处理代码 +// History: +*********************************************************************/ +BOOL XEngine_SocksTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen) +{ + + return TRUE; +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.h b/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.h new file mode 100644 index 0000000..3409083 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.h @@ -0,0 +1,14 @@ +#pragma once +/******************************************************************** +// Created: 2021/12/02 17:06:56 +// File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp\XEngine_SocksTask.h +// File Path: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp +// File Base: XEngine_SocksTask +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: Socks任务处理代码 +// History: +*********************************************************************/ +//任务处理相关函数,处理包的内容 +BOOL XEngine_SocksTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp new file mode 100644 index 0000000..50cbb13 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp @@ -0,0 +1,17 @@ +#include "XEngine_Hdr.h" +/******************************************************************** +// Created: 2021/12/02 17:15:57 +// File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp\XEngine_TunnelTask.cpp +// File Path: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp +// File Base: XEngine_TunnelTask +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: HTTP任务处理代码 +// History: +*********************************************************************/ +BOOL XEngine_TunnelTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen) +{ + + return TRUE; +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.h b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.h new file mode 100644 index 0000000..3fafc67 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.h @@ -0,0 +1,14 @@ +#pragma once +/******************************************************************** +// Created: 2021/12/02 17:14:41 +// File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp\XEngine_TunnelTask.h +// File Path: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp +// File Base: XEngine_TunnelTask +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: HTTP任务处理代码 +// History: +*********************************************************************/ +//任务处理相关函数,处理包的内容 +BOOL XEngine_TunnelTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen); \ No newline at end of file diff --git a/XEngine_Source/XEngine_UserProtocol.h b/XEngine_Source/XEngine_UserProtocol.h new file mode 100644 index 0000000..5c9ac1d --- /dev/null +++ b/XEngine_Source/XEngine_UserProtocol.h @@ -0,0 +1,32 @@ +#pragma once +/******************************************************************** +// Created: 2021/12/03 14:16:27 +// File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_UserProtocol.h +// File Path: D:\XEngine_ServiceApp\XEngine_Source +// File Base: XEngine_UserProtocol +// File Ext: h +// Project: XEngine(ͨ) +// Author: qyt +// Purpose: ûԶЭͷ +// History: +*********************************************************************/ +////////////////////////////////////////////////////////////////////////// +// Э鶨;unOperatorType +////////////////////////////////////////////////////////////////////////// +typedef enum +{ + //ûϢ + ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_MSG = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_USER + 1 +}ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_CUSTOM; +////////////////////////////////////////////////////////////////////////// +// Э鶨:unOperatorCode +////////////////////////////////////////////////////////////////////////// +#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MSG_TEXTREQ 0x0001 //Ϣ +#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MSG_TEXTREP 0x0002 //ظϢ +/////////////////////////////////////////////////////////////////////////// +// ݽṹ +/////////////////////////////////////////////////////////////////////////// +#pragma pack(push) +#pragma pack(1) +//ԼϢݽṹ +#pragma pack(pop) \ No newline at end of file -- Gitee From fb9c64852e9e9460300a34dc1d3f0078ce1eee4d Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Tue, 7 Dec 2021 13:28:47 +0800 Subject: [PATCH 02/12] added:socks and tunnel network handle --- .../XEngine_ServiceApp/XEngine_Hdr.h | 3 +++ .../XEngine_ServiceApp/XEngine_Network.cpp | 26 ++++++++++++------- .../XEngine_ServiceApp/XEngine_Network.h | 20 +++++++------- .../XEngine_ServiceApp/XEngine_ServiceApp.cpp | 8 +++--- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h index bd140c1..03d54a1 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h @@ -25,6 +25,8 @@ using namespace std; #include #include #include +#include +#include //加载项目相关头文件 #include "../XEngine_UserProtocol.h" #include "../XEngine_ModuleConfigure/ModuleConfig_Define.h" @@ -75,5 +77,6 @@ extern XENGINE_SERVICECONFIG st_ServiceConfig; #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") #pragma comment(lib,"XEngine_Core/XEngine_Core.lib") #pragma comment(lib,"XEngine_HelpComponents/HelpComponents_XLog.lib") +#pragma comment(lib,"XEngine_RfcComponents/RfcComponents_ProxyProtocol.lib") #pragma comment(lib,"Ws2_32.lib") #endif \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp index 331b3ec..b935692 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp @@ -10,47 +10,51 @@ // Purpose: 网络IO相关代码 // History: *********************************************************************/ -//////////////////////////////////////////////////////////////////////////下面是TCP网络IO相关代码处理函数 -BOOL __stdcall Network_Callback_TCPLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) +//////////////////////////////////////////////////////////////////////////下面是SOCKS网络IO相关代码处理函数 +BOOL __stdcall Network_Callback_SocksLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) { //客户端连接后要把客户端插入心跳管理器中才有效 + ProxyProtocol_SocksCore_Create(lpszClientAddr); SocketOpt_HeartBeat_InsertAddrEx(xhSocksHeart, lpszClientAddr); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("TCP客户端:%s,连接到服务器"), lpszClientAddr); return TRUE; } -void __stdcall Network_Callback_TCPRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam) +void __stdcall Network_Callback_SocksRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam) { //需要激活一次 + XEngine_SocksTask_Handle(lpszClientAddr, lpszRecvMsg, nMsgLen); SocketOpt_HeartBeat_ActiveAddrEx(xhSocksHeart, lpszClientAddr); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_DEBUG, _T("TCP客户端:%s,投递数据包到组包队列成功,大小:%d"), lpszClientAddr, nMsgLen); } -void __stdcall Network_Callback_TCPLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) +void __stdcall Network_Callback_SocksLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) { //交给指定函数来处理客户端离开消息 XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_SOCKS, FALSE); } -void __stdcall Network_Callback_TCPHeart(LPCSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam) +void __stdcall Network_Callback_SocksHeart(LPCSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam) { //同上 XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_SOCKS, TRUE); } -//////////////////////////////////////////////////////////////////////////下面是HTTP网络IO相关代码处理函数 -BOOL __stdcall Network_Callback_HTTPLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) +//////////////////////////////////////////////////////////////////////////下面是Tunnel网络IO相关代码处理函数 +BOOL __stdcall Network_Callback_TunnelLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) { + ProxyProtocol_TunnelCore_Create(lpszClientAddr); SocketOpt_HeartBeat_InsertAddrEx(xhTunnelHeart, lpszClientAddr); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("HTTP客户端:%s,连接到服务器"), lpszClientAddr); return TRUE; } -void __stdcall Network_Callback_HTTPRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam) +void __stdcall Network_Callback_TunnelRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam) { + XEngine_TunnelTask_Handle(lpszClientAddr, lpszRecvMsg, nMsgLen); SocketOpt_HeartBeat_ActiveAddrEx(xhTunnelHeart, lpszClientAddr); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_DEBUG, _T("HTTP客户端:%s,投递数据包到组包队列成功,大小:%d"), lpszClientAddr, nMsgLen); } -void __stdcall Network_Callback_HTTPLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) +void __stdcall Network_Callback_TunnelLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) { XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_TUNNEL, FALSE); } -void __stdcall Network_Callback_HTTPHeart(LPCTSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam) +void __stdcall Network_Callback_TunnelHeart(LPCTSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam) { XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_TUNNEL, TRUE); } @@ -70,6 +74,7 @@ void XEngine_Network_Close(LPCTSTR lpszClientAddr, int nIPProto, BOOL bHeart) //同上 SocketOpt_HeartBeat_DeleteAddrEx(xhSocksHeart, lpszClientAddr); } + ProxyProtocol_SocksCore_Delete(lpszClientAddr); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("TCP客户端:%s,离开服务器"), lpszClientAddr); } else if (XENGINE_CLIENT_NETTYPE_TUNNEL == nIPProto) @@ -82,6 +87,7 @@ void XEngine_Network_Close(LPCTSTR lpszClientAddr, int nIPProto, BOOL bHeart) { SocketOpt_HeartBeat_DeleteAddrEx(xhTunnelHeart, lpszClientAddr); } + ProxyProtocol_TunnelCore_Delete(lpszClientAddr); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("HTTP客户端:%s,离开服务器"), lpszClientAddr); } else diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h index 548b210..4f6b7fe 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h @@ -10,16 +10,16 @@ // Purpose: 网络IO相关代码 // History: *********************************************************************/ -//TCP相关 -BOOL __stdcall Network_Callback_TCPLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam); //用户连接 -void __stdcall Network_Callback_TCPRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam); //接受到数据 -void __stdcall Network_Callback_TCPLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam); //用户离开 -void __stdcall Network_Callback_TCPHeart(LPCSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam); //心跳超时 -//HTTP相关 -BOOL __stdcall Network_Callback_HTTPLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam); -void __stdcall Network_Callback_HTTPRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam); -void __stdcall Network_Callback_HTTPLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam); -void __stdcall Network_Callback_HTTPHeart(LPCTSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam); +//SOCKS相关 +BOOL __stdcall Network_Callback_SocksLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam); //用户连接 +void __stdcall Network_Callback_SocksRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam); //接受到数据 +void __stdcall Network_Callback_SocksLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam); //用户离开 +void __stdcall Network_Callback_SocksHeart(LPCSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam); //心跳超时 +//Tunnel相关 +BOOL __stdcall Network_Callback_TunnelLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam); +void __stdcall Network_Callback_TunnelRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam); +void __stdcall Network_Callback_TunnelLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam); +void __stdcall Network_Callback_TunnelHeart(LPCTSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam); //关闭与发送 void XEngine_Network_Close(LPCTSTR lpszClientAddr, int nIPProto, BOOL bHeart); BOOL XEngine_Network_Send(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen, int nIPProto); \ 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 a3a6e68..4560a92 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp @@ -108,7 +108,7 @@ int main(int argc, char** argv) //启动心跳 if (st_ServiceConfig.st_XTime.nSocksTimeOut > 0) { - if (!SocketOpt_HeartBeat_InitEx(&xhSocksHeart, st_ServiceConfig.st_XTime.nSocksTimeOut, st_ServiceConfig.st_XTime.nTimeCheck, Network_Callback_TCPHeart)) + if (!SocketOpt_HeartBeat_InitEx(&xhSocksHeart, st_ServiceConfig.st_XTime.nSocksTimeOut, st_ServiceConfig.st_XTime.nTimeCheck, Network_Callback_SocksHeart)) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,初始化TCP心跳服务失败,错误:%lX"), NetCore_GetLastError()); goto XENGINE_SERVICEAPP_EXIT; @@ -127,7 +127,7 @@ int main(int argc, char** argv) } XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,启动TCP网络服务器成功,TCP端口:%d,网络IO线程个数:%d"), st_ServiceConfig.nSocksPort, st_ServiceConfig.st_XMax.nIOThread); //绑定网络事件 - NetCore_TCPXCore_RegisterCallBackEx(xhSocksSocket, Network_Callback_TCPLogin, Network_Callback_TCPRecv, Network_Callback_TCPLeave); + NetCore_TCPXCore_RegisterCallBackEx(xhSocksSocket, Network_Callback_SocksLogin, Network_Callback_SocksRecv, Network_Callback_SocksLeave); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,注册TCP网络事件成功")); } else @@ -140,7 +140,7 @@ int main(int argc, char** argv) //启动心跳 if (st_ServiceConfig.st_XTime.nTunnelTimeOut > 0) { - if (!SocketOpt_HeartBeat_InitEx(&xhTunnelHeart, st_ServiceConfig.st_XTime.nTunnelTimeOut, st_ServiceConfig.st_XTime.nTimeCheck, Network_Callback_HTTPHeart)) + if (!SocketOpt_HeartBeat_InitEx(&xhTunnelHeart, st_ServiceConfig.st_XTime.nTunnelTimeOut, st_ServiceConfig.st_XTime.nTimeCheck, Network_Callback_TunnelHeart)) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,初始化HTTP心跳服务失败,错误:%lX"), NetCore_GetLastError()); goto XENGINE_SERVICEAPP_EXIT; @@ -158,7 +158,7 @@ int main(int argc, char** argv) goto XENGINE_SERVICEAPP_EXIT; } XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,启动HTTP网络服务器成功,HTTP端口:%d,IO:%d"), st_ServiceConfig.nTunnelPort, st_ServiceConfig.st_XMax.nIOThread); - NetCore_TCPXCore_RegisterCallBackEx(xhTunnelSocket, Network_Callback_HTTPLogin, Network_Callback_HTTPRecv, Network_Callback_HTTPLeave); + NetCore_TCPXCore_RegisterCallBackEx(xhTunnelSocket, Network_Callback_TunnelLogin, Network_Callback_TunnelRecv, Network_Callback_TunnelLeave); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,注册HTTP网络事件成功")); } else -- Gitee From 6d2a1b52a26c1ebfe3ea93b0ec1d26c57cf286ac Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Tue, 7 Dec 2021 15:56:00 +0800 Subject: [PATCH 03/12] added:socks configure information added:tunnel forward code --- .../ModuleConfig_Define.h | 4 + .../ModuleConfig_Error.h | 3 +- .../ModuleConfigure_Json.cpp | 9 ++ .../XEngine_ServiceApp/XEngine_Hdr.h | 6 ++ .../XEngine_ServiceApp/XEngine_ServiceApp.cpp | 40 ++++----- .../XEngine_ServiceApp/XEngine_TunnelTask.cpp | 88 ++++++++++++++++++- .../XEngine_ServiceApp/XEngine_TunnelTask.h | 3 +- XEngine_Source/XEngine_UserProtocol.h | 7 +- 8 files changed, 136 insertions(+), 24 deletions(-) diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h index f5aead6..e5be8e3 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h @@ -37,6 +37,10 @@ typedef struct tag_XEngine_ServiceConfig int nMaxCount; //־ int nLogLeave; //־ȼ }st_XLog; + struct + { + int nAuthType; + }st_XSocks; }XENGINE_SERVICECONFIG; ////////////////////////////////////////////////////////////////////////// // diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h index 5c074ed..60bdb82 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Error.h @@ -15,4 +15,5 @@ #define ERROR_MODULE_CONFIGURE_JSON_PARSE 0xA0003 //JSONʧ #define ERROR_MODULE_CONFIGURE_JSON_XMAX 0xA0004 //ȡXMAXʧ #define ERROR_MODULE_CONFIGURE_JSON_XTIME 0xA0005 //ȡXTIMEʧ -#define ERROR_MODULE_CONFIGURE_JSON_XLOG 0xA0006 //ȡXLOGʧ \ No newline at end of file +#define ERROR_MODULE_CONFIGURE_JSON_XLOG 0xA0006 //ȡXLOGʧ +#define ERROR_MODULE_CONFIGURE_JSON_XSOCK 0xA0007 \ 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 2685847..7c5ba4f 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp @@ -118,5 +118,14 @@ BOOL CModuleConfigure_Json::ModuleConfigure_Json_File(LPCTSTR 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(); + + if (st_JsonRoot["XSocks"].empty() || (1 != st_JsonRoot["XSocks"].size())) + { + Config_IsErrorOccur = TRUE; + Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XSOCK; + return FALSE; + } + Json::Value st_JsonXSocks = st_JsonRoot["XSocks"]; + pSt_ServerConfig->st_XSocks.nAuthType = st_JsonXSocks["nAuthType"].asInt(); return TRUE; } \ 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 03d54a1..acddbab 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h @@ -23,10 +23,14 @@ using namespace std; #include #include #include +#include +#include #include #include #include #include +#include +#include //加载项目相关头文件 #include "../XEngine_UserProtocol.h" #include "../XEngine_ModuleConfigure/ModuleConfig_Define.h" @@ -76,7 +80,9 @@ extern XENGINE_SERVICECONFIG st_ServiceConfig; #endif #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") #pragma comment(lib,"XEngine_Core/XEngine_Core.lib") +#pragma comment(lib,"XEngine_Core/XEngine_NetXApi.lib") #pragma comment(lib,"XEngine_HelpComponents/HelpComponents_XLog.lib") #pragma comment(lib,"XEngine_RfcComponents/RfcComponents_ProxyProtocol.lib") +#pragma comment(lib,"XEngine_Client/XClient_Socket.lib") #pragma comment(lib,"Ws2_32.lib") #endif \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp index 4560a92..f47659a 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp @@ -17,10 +17,10 @@ void ServiceApp_Stop(int signo) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("服务器退出...")); bIsRun = FALSE; - //销毁TCP资源 + //销毁Socks资源 NetCore_TCPXCore_DestroyEx(xhSocksSocket); SocketOpt_HeartBeat_DestoryEx(xhSocksHeart); - //销毁HTTP资源 + //销毁Tunnel资源 NetCore_TCPXCore_DestroyEx(xhTunnelSocket); SocketOpt_HeartBeat_DestoryEx(xhTunnelHeart); //销毁日志资源 @@ -102,7 +102,7 @@ int main(int argc, char** argv) //设置日志打印级别 HelpComponents_XLog_SetLogPriority(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,初始化日志系统成功")); - //启动TCP服务相关代码 + //启动Socks服务相关代码 if (st_ServiceConfig.nSocksPort > 0) { //启动心跳 @@ -110,31 +110,31 @@ int main(int argc, char** argv) { if (!SocketOpt_HeartBeat_InitEx(&xhSocksHeart, st_ServiceConfig.st_XTime.nSocksTimeOut, st_ServiceConfig.st_XTime.nTimeCheck, Network_Callback_SocksHeart)) { - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,初始化TCP心跳服务失败,错误:%lX"), NetCore_GetLastError()); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,初始化Socks心跳服务失败,错误:%lX"), NetCore_GetLastError()); goto XENGINE_SERVICEAPP_EXIT; } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,初始化TCP心跳服务成功,句柄:%llu,时间:%d,次数:%d"), xhSocksHeart, st_ServiceConfig.st_XTime.nSocksTimeOut, st_ServiceConfig.st_XTime.nTimeCheck); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,初始化Socks心跳服务成功,句柄:%llu,时间:%d,次数:%d"), xhSocksHeart, st_ServiceConfig.st_XTime.nSocksTimeOut, st_ServiceConfig.st_XTime.nTimeCheck); } else { - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,TCP心跳服务被设置为不启用")); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,Socks心跳服务被设置为不启用")); } //启动网络 if (!NetCore_TCPXCore_StartEx(&xhSocksSocket, st_ServiceConfig.nSocksPort, st_ServiceConfig.st_XMax.nMaxClient, st_ServiceConfig.st_XMax.nIOThread)) { - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,启动TCP网络服务器失败,错误:%lX"), NetCore_GetLastError()); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,启动Socks网络服务器失败,错误:%lX"), NetCore_GetLastError()); goto XENGINE_SERVICEAPP_EXIT; } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,启动TCP网络服务器成功,TCP端口:%d,网络IO线程个数:%d"), st_ServiceConfig.nSocksPort, st_ServiceConfig.st_XMax.nIOThread); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,启动Socks网络服务器成功,Socks端口:%d,网络IO线程个数:%d"), st_ServiceConfig.nSocksPort, st_ServiceConfig.st_XMax.nIOThread); //绑定网络事件 NetCore_TCPXCore_RegisterCallBackEx(xhSocksSocket, Network_Callback_SocksLogin, Network_Callback_SocksRecv, Network_Callback_SocksLeave); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,注册TCP网络事件成功")); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,注册Socks网络事件成功")); } else { - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,TCP消息服务没有被启用")); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,Socks消息服务没有被启用")); } - //启动HTTP服务相关代码 + //启动Tunnel服务相关代码 if (st_ServiceConfig.nTunnelPort > 0) { //启动心跳 @@ -142,28 +142,28 @@ int main(int argc, char** argv) { if (!SocketOpt_HeartBeat_InitEx(&xhTunnelHeart, st_ServiceConfig.st_XTime.nTunnelTimeOut, st_ServiceConfig.st_XTime.nTimeCheck, Network_Callback_TunnelHeart)) { - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,初始化HTTP心跳服务失败,错误:%lX"), NetCore_GetLastError()); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,初始化Tunnel心跳服务失败,错误:%lX"), NetCore_GetLastError()); goto XENGINE_SERVICEAPP_EXIT; } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,初始化HTTP心跳服务成功,句柄:%llu,时间:%d,次数:%d"), xhTunnelHeart, st_ServiceConfig.st_XTime.nTunnelTimeOut, st_ServiceConfig.st_XTime.nTimeCheck); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,初始化Tunnel心跳服务成功,句柄:%llu,时间:%d,次数:%d"), xhTunnelHeart, st_ServiceConfig.st_XTime.nTunnelTimeOut, st_ServiceConfig.st_XTime.nTimeCheck); } else { - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,HTTP心跳服务被设置为不启用")); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,Tunnel心跳服务被设置为不启用")); } //网络 if (!NetCore_TCPXCore_StartEx(&xhTunnelSocket, st_ServiceConfig.nTunnelPort, st_ServiceConfig.st_XMax.nMaxClient, st_ServiceConfig.st_XMax.nIOThread)) { - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,启动HTTP网络服务器失败,错误:%lX"), NetCore_GetLastError()); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,启动Tunnel网络服务器失败,错误:%lX"), NetCore_GetLastError()); goto XENGINE_SERVICEAPP_EXIT; } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,启动HTTP网络服务器成功,HTTP端口:%d,IO:%d"), st_ServiceConfig.nTunnelPort, st_ServiceConfig.st_XMax.nIOThread); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,启动Tunnel网络服务器成功,Tunnel端口:%d,IO:%d"), st_ServiceConfig.nTunnelPort, st_ServiceConfig.st_XMax.nIOThread); NetCore_TCPXCore_RegisterCallBackEx(xhTunnelSocket, Network_Callback_TunnelLogin, Network_Callback_TunnelRecv, Network_Callback_TunnelLeave); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,注册HTTP网络事件成功")); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,注册Tunnel网络事件成功")); } else { - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,HTTP消息服务没有被启用")); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,Tunnel消息服务没有被启用")); } XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("所有服务成功启动,服务运行中。。。")); @@ -176,10 +176,10 @@ XENGINE_SERVICEAPP_EXIT: { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("有服务启动失败,服务器退出...")); bIsRun = FALSE; - //销毁TCP资源 + //销毁Socks资源 NetCore_TCPXCore_DestroyEx(xhSocksSocket); SocketOpt_HeartBeat_DestoryEx(xhSocksHeart); - //销毁HTTP资源 + //销毁Tunnel资源 NetCore_TCPXCore_DestroyEx(xhTunnelSocket); SocketOpt_HeartBeat_DestoryEx(xhTunnelHeart); //销毁日志资源 diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp index 50cbb13..7810c24 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp @@ -12,6 +12,92 @@ *********************************************************************/ BOOL XEngine_TunnelTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen) { - + PROXYPROTOCOL_CLIENTINFO st_ProxyClient; + memset(&st_ProxyClient, '\0', sizeof(PROXYPROTOCOL_CLIENTINFO)); + + ProxyProtocol_TunnelCore_GetInfo(lpszClientAddr, &st_ProxyClient); + //创建成功就只需要转发 + if (ENUM_RFCCOMPONENTS_PROXY_STATUS_CREATE == st_ProxyClient.enStatus) + { + int nLen = 0; + int nIPPort = 0; + TCHAR tszIPAddr[MAX_PATH]; + TCHAR tszAuthInfo[MAX_PATH]; + TCHAR tszMsgBuffer[MAX_PATH]; + + memset(tszIPAddr, '\0', MAX_PATH); + memset(tszAuthInfo, '\0', MAX_PATH); + memset(tszMsgBuffer, '\0', MAX_PATH); + if (!ProxyProtocol_TunnelCore_Parse(lpszClientAddr, lpszMsgBuffer, nMsgLen, tszIPAddr, &nIPPort, tszAuthInfo)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Tunnel客户端:%s,解析协议失败,错误:%lX"), lpszClientAddr, ProxyProtocol_GetLastError()); + return FALSE; + } + TCHAR tszConnectAddr[128]; + memset(tszConnectAddr, '\0', sizeof(tszConnectAddr)); + //是否为IP地址 + if (BaseLib_OperatorIPAddr_IsIPV4Addr(tszIPAddr)) + { + _tcscpy(tszConnectAddr, tszIPAddr); + } + else + { + int nListCount = 0; + CHAR** ppszListAddr; + if (!NetXApi_Socket_DomainToAddr(tszIPAddr, &ppszListAddr, &nListCount)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Tunnel客户端:%s,解析域名失败,错误:%lX"), lpszClientAddr, ProxyProtocol_GetLastError()); + return FALSE; + } + _tcscpy(tszConnectAddr, ppszListAddr[0]); //随便选择一个IP地址 + BaseLib_OperatorMemory_Free((XPPPMEM)&ppszListAddr, nListCount); + } + if (!XClient_TCPSelect_Create(&st_ProxyClient.hSocket, tszConnectAddr, nIPPort)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Tunnel客户端:%s,创建客户端连接失败,连接到服务器:%s:%d,错误:%lX"), lpszClientAddr, tszConnectAddr, nIPPort, ProxyProtocol_GetLastError()); + return FALSE; + } + + std::thread pSTDThread(XEngine_TunnelTask_Thread, lpszClientAddr); + pSTDThread.detach(); + st_ProxyClient.enStatus = ENUM_RFCCOMPONENTS_PROXY_STATUS_FORWARD; + _tcscpy(st_ProxyClient.tszIPAddr, lpszClientAddr); + + ProxyProtocol_TunnelCore_SetInfo(lpszClientAddr, &st_ProxyClient, sizeof(PROXYPROTOCOL_CLIENTINFO)); + ProxyProtocol_TunnelCore_Packet(tszMsgBuffer, &nLen); + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_TUNNEL); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Tunnel客户端:%s,创建隧道代理服务成功,连接到服务器:%s:%d"), lpszClientAddr, tszConnectAddr, nIPPort); + } + else + { + //转发数据 + XClient_TCPSelect_SendMsg(st_ProxyClient.hSocket, lpszMsgBuffer, nMsgLen); + } return TRUE; +} +XHTHREAD CALLBACK XEngine_TunnelTask_Thread(LPCTSTR lpszClientAddr) +{ + TCHAR tszClientAddr[128]; + PROXYPROTOCOL_CLIENTINFO st_ProxyClient; + + memset(tszClientAddr, '\0', sizeof(tszClientAddr)); + _tcscpy(tszClientAddr, lpszClientAddr); + while (1) + { + int nMsgLen = 4096; + TCHAR tszMsgBuffer[4096]; + + memset(&st_ProxyClient, '\0', sizeof(PROXYPROTOCOL_CLIENTINFO)); + if (!ProxyProtocol_TunnelCore_GetInfo(tszClientAddr, &st_ProxyClient)) + { + break; + } + if (!XClient_TCPSelect_RecvMsg(st_ProxyClient.hSocket, tszMsgBuffer, &nMsgLen, FALSE)) + { + break; + } + XEngine_Network_Send(st_ProxyClient.tszIPAddr, tszMsgBuffer, nMsgLen, XENGINE_CLIENT_NETTYPE_TUNNEL); + } + XClient_TCPSelect_Close(st_ProxyClient.hSocket); + return 0; } \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.h b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.h index 3fafc67..ccec4d5 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.h @@ -11,4 +11,5 @@ // History: *********************************************************************/ //任务处理相关函数,处理包的内容 -BOOL XEngine_TunnelTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen); \ No newline at end of file +BOOL XEngine_TunnelTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen); +XHTHREAD CALLBACK XEngine_TunnelTask_Thread(LPCTSTR lpszClientAddr); \ No newline at end of file diff --git a/XEngine_Source/XEngine_UserProtocol.h b/XEngine_Source/XEngine_UserProtocol.h index 5c9ac1d..187b374 100644 --- a/XEngine_Source/XEngine_UserProtocol.h +++ b/XEngine_Source/XEngine_UserProtocol.h @@ -28,5 +28,10 @@ typedef enum /////////////////////////////////////////////////////////////////////////// #pragma pack(push) #pragma pack(1) -//ԼϢݽṹ +typedef struct +{ + TCHAR tszIPAddr[128]; + ENUM_RFCCOMPONENTS_PROXY_STATUS enStatus; + SOCKET hSocket; +}PROXYPROTOCOL_CLIENTINFO; #pragma pack(pop) \ No newline at end of file -- Gitee From 7ea160be07d17822be9d97825f626667e1101973 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Tue, 7 Dec 2021 17:03:14 +0800 Subject: [PATCH 04/12] support:no connect protocol proxy --- .../XEngine_ServiceApp/XEngine_Hdr.h | 3 ++ .../XEngine_ServiceApp/XEngine_Network.cpp | 16 ++++----- .../XEngine_ServiceApp/XEngine_TunnelTask.cpp | 35 +++++++++++++++---- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h index acddbab..9e9149b 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h @@ -25,6 +25,8 @@ using namespace std; #include #include #include +#include +#include #include #include #include @@ -81,6 +83,7 @@ extern XENGINE_SERVICECONFIG st_ServiceConfig; #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") #pragma comment(lib,"XEngine_Core/XEngine_Core.lib") #pragma comment(lib,"XEngine_Core/XEngine_NetXApi.lib") +#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIHelp.lib") #pragma comment(lib,"XEngine_HelpComponents/HelpComponents_XLog.lib") #pragma comment(lib,"XEngine_RfcComponents/RfcComponents_ProxyProtocol.lib") #pragma comment(lib,"XEngine_Client/XClient_Socket.lib") diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp index b935692..bc18c5d 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp @@ -16,7 +16,7 @@ BOOL __stdcall Network_Callback_SocksLogin(LPCTSTR lpszClientAddr, SOCKET hSocke //客户端连接后要把客户端插入心跳管理器中才有效 ProxyProtocol_SocksCore_Create(lpszClientAddr); SocketOpt_HeartBeat_InsertAddrEx(xhSocksHeart, lpszClientAddr); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("TCP客户端:%s,连接到服务器"), lpszClientAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("SOCKS客户端:%s,连接到服务器"), lpszClientAddr); return TRUE; } void __stdcall Network_Callback_SocksRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam) @@ -24,7 +24,7 @@ void __stdcall Network_Callback_SocksRecv(LPCTSTR lpszClientAddr, SOCKET hSocket //需要激活一次 XEngine_SocksTask_Handle(lpszClientAddr, lpszRecvMsg, nMsgLen); SocketOpt_HeartBeat_ActiveAddrEx(xhSocksHeart, lpszClientAddr); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_DEBUG, _T("TCP客户端:%s,投递数据包到组包队列成功,大小:%d"), lpszClientAddr, nMsgLen); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_DEBUG, _T("SOCKS客户端:%s,投递数据包到组包队列成功,大小:%d"), lpszClientAddr, nMsgLen); } void __stdcall Network_Callback_SocksLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) { @@ -41,14 +41,14 @@ BOOL __stdcall Network_Callback_TunnelLogin(LPCTSTR lpszClientAddr, SOCKET hSock { ProxyProtocol_TunnelCore_Create(lpszClientAddr); SocketOpt_HeartBeat_InsertAddrEx(xhTunnelHeart, lpszClientAddr); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("HTTP客户端:%s,连接到服务器"), lpszClientAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Tunnel客户端:%s,连接到服务器"), lpszClientAddr); return TRUE; } void __stdcall Network_Callback_TunnelRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam) { XEngine_TunnelTask_Handle(lpszClientAddr, lpszRecvMsg, nMsgLen); SocketOpt_HeartBeat_ActiveAddrEx(xhTunnelHeart, lpszClientAddr); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_DEBUG, _T("HTTP客户端:%s,投递数据包到组包队列成功,大小:%d"), lpszClientAddr, nMsgLen); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_DEBUG, _T("Tunnel客户端:%s,投递数据包到组包队列成功,大小:%d"), lpszClientAddr, nMsgLen); } void __stdcall Network_Callback_TunnelLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) { @@ -75,7 +75,7 @@ void XEngine_Network_Close(LPCTSTR lpszClientAddr, int nIPProto, BOOL bHeart) SocketOpt_HeartBeat_DeleteAddrEx(xhSocksHeart, lpszClientAddr); } ProxyProtocol_SocksCore_Delete(lpszClientAddr); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("TCP客户端:%s,离开服务器"), lpszClientAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("SOCKS客户端:%s,离开服务器"), lpszClientAddr); } else if (XENGINE_CLIENT_NETTYPE_TUNNEL == nIPProto) { @@ -88,7 +88,7 @@ void XEngine_Network_Close(LPCTSTR lpszClientAddr, int nIPProto, BOOL bHeart) SocketOpt_HeartBeat_DeleteAddrEx(xhTunnelHeart, lpszClientAddr); } ProxyProtocol_TunnelCore_Delete(lpszClientAddr); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("HTTP客户端:%s,离开服务器"), lpszClientAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Tunnel客户端:%s,离开服务器"), lpszClientAddr); } else { @@ -104,7 +104,7 @@ BOOL XEngine_Network_Send(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMs //发送数据给指定客户端 if (!NetCore_TCPXCore_SendEx(xhSocksSocket, lpszClientAddr, lpszMsgBuffer, nMsgLen)) { - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("TCP客户端:%s,发送数据失败,错误:%lX"), lpszClientAddr, NetCore_GetLastError()); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("SOCKS客户端:%s,发送数据失败,错误:%lX"), lpszClientAddr, NetCore_GetLastError()); return FALSE; } //发送成功激活一次心跳 @@ -114,7 +114,7 @@ BOOL XEngine_Network_Send(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMs { if (!NetCore_TCPXCore_SendEx(xhTunnelSocket, lpszClientAddr, lpszMsgBuffer, nMsgLen)) { - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("HTTP客户端:%s,发送数据失败,错误:%lX"), lpszClientAddr, NetCore_GetLastError()); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Tunnel客户端:%s,发送数据失败,错误:%lX"), lpszClientAddr, NetCore_GetLastError()); return FALSE; } SocketOpt_HeartBeat_ActiveAddrEx(xhTunnelHeart, lpszClientAddr); diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp index 7810c24..3c737ae 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp @@ -21,6 +21,7 @@ BOOL XEngine_TunnelTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in { int nLen = 0; int nIPPort = 0; + BOOL bProxy = TRUE; TCHAR tszIPAddr[MAX_PATH]; TCHAR tszAuthInfo[MAX_PATH]; TCHAR tszMsgBuffer[MAX_PATH]; @@ -28,8 +29,10 @@ BOOL XEngine_TunnelTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in memset(tszIPAddr, '\0', MAX_PATH); memset(tszAuthInfo, '\0', MAX_PATH); memset(tszMsgBuffer, '\0', MAX_PATH); - if (!ProxyProtocol_TunnelCore_Parse(lpszClientAddr, lpszMsgBuffer, nMsgLen, tszIPAddr, &nIPPort, tszAuthInfo)) + if (!ProxyProtocol_TunnelCore_Parse(lpszClientAddr, lpszMsgBuffer, nMsgLen, tszIPAddr, &nIPPort, tszAuthInfo, &bProxy)) { + ProxyProtocol_TunnelCore_Packet(tszMsgBuffer, &nLen, 400); + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_TUNNEL); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Tunnel客户端:%s,解析协议失败,错误:%lX"), lpszClientAddr, ProxyProtocol_GetLastError()); return FALSE; } @@ -44,28 +47,48 @@ BOOL XEngine_TunnelTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in { int nListCount = 0; CHAR** ppszListAddr; + ENUM_APIHELP_DOMAINTYPE enDomainType; + APIHELP_DOMAIN st_APIUrl; + + memset(&st_APIUrl, '\0', sizeof(APIHELP_DOMAIN)); + + APIHelp_Domain_GetInfo(tszIPAddr, &st_APIUrl, &enDomainType); + memset(tszIPAddr, '\0', sizeof(tszIPAddr)); + _stprintf(tszIPAddr, _T("%s.%s"), st_APIUrl.tszSubDomain, st_APIUrl.tszMainDomain); + if (!NetXApi_Socket_DomainToAddr(tszIPAddr, &ppszListAddr, &nListCount)) { + ProxyProtocol_TunnelCore_Packet(tszMsgBuffer, &nLen, 500); + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_TUNNEL); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Tunnel客户端:%s,解析域名失败,错误:%lX"), lpszClientAddr, ProxyProtocol_GetLastError()); return FALSE; } _tcscpy(tszConnectAddr, ppszListAddr[0]); //随便选择一个IP地址 BaseLib_OperatorMemory_Free((XPPPMEM)&ppszListAddr, nListCount); } - if (!XClient_TCPSelect_Create(&st_ProxyClient.hSocket, tszConnectAddr, nIPPort)) + if (!XClient_TCPSelect_Create(&st_ProxyClient.hSocket, tszConnectAddr, nIPPort, AF_INET, 1)) { + ProxyProtocol_TunnelCore_Packet(tszMsgBuffer, &nLen, 500); + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_TUNNEL); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Tunnel客户端:%s,创建客户端连接失败,连接到服务器:%s:%d,错误:%lX"), lpszClientAddr, tszConnectAddr, nIPPort, ProxyProtocol_GetLastError()); return FALSE; } - std::thread pSTDThread(XEngine_TunnelTask_Thread, lpszClientAddr); pSTDThread.detach(); st_ProxyClient.enStatus = ENUM_RFCCOMPONENTS_PROXY_STATUS_FORWARD; _tcscpy(st_ProxyClient.tszIPAddr, lpszClientAddr); - ProxyProtocol_TunnelCore_SetInfo(lpszClientAddr, &st_ProxyClient, sizeof(PROXYPROTOCOL_CLIENTINFO)); - ProxyProtocol_TunnelCore_Packet(tszMsgBuffer, &nLen); - XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_TUNNEL); + //判断是代理还是非代理协议 + if (bProxy) + { + ProxyProtocol_TunnelCore_Packet(tszMsgBuffer, &nLen); + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_TUNNEL); + } + else + { + //非代理协议直接发送数据 + XClient_TCPSelect_SendMsg(st_ProxyClient.hSocket, lpszMsgBuffer, nMsgLen); + } XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Tunnel客户端:%s,创建隧道代理服务成功,连接到服务器:%s:%d"), lpszClientAddr, tszConnectAddr, nIPPort); } else -- Gitee From 8afa12366ef5b5f3b1903edbbc8c19a05ea34bda Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Tue, 7 Dec 2021 17:04:42 +0800 Subject: [PATCH 05/12] update:readme --- README.en.md | 104 ++++++++++++++++++++++++++++++++++++++++----------- README.md | 98 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 159 insertions(+), 43 deletions(-) diff --git a/README.en.md b/README.en.md index b995ff8..98f963e 100644 --- a/README.en.md +++ b/README.en.md @@ -1,36 +1,96 @@ # XEngine_ProxyServer #### Description -c c++代理服务器 支持SOCKSV4 V5和HTTP隧道代理. +c c++ SOCKS5代理服务 HTTP Tunnel隧道代理服务 +c c++ Socks5 Proxy Service HTTP Tunnel Proxy Service #### Software Architecture -Software architecture description +the software developed based on xengine,using c/c++ development +This software is a standard proxy server that supports Socks5 and HTTP tunnel proxy -#### Installation +## Software features +this software support following features +1. SOCKS5 proxy +2. Tunnel proxy +3. support Permission Validation(planning) +4. operator log +5. encrypt Communication(planning) +6. load balanc(planning) -1. xxxx -2. xxxx -3. xxxx +## install -#### Instructions +#### Requirements +support system above windows 7sp1 and linux(ubuntu20.04,centos8) +XEngine need V7.23 or above +vcpkg need 2021.05.11 or above -1. xxxx -2. xxxx -3. xxxx +#### Windows +use vs2019 x86(debug or release) x64(only release) open and complie +You need to configure the environment in the following way, otherwise you may need to set the library directory in the project yourself -#### Contribution +##### install Dependent library +vcpkg:https://github.com/microsoft/vcpkg +vcpkg.exe install jsoncpp +vcpkg integrate install +you can not use vcpkg and config jsoncpp development for youself -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request +#### Linux +Linux use Makefile to complie +supproted ubuntu x64 or centos x64 +##### install Dependent library +install jsoncpp to your system +ubuntu20.04 +sudo apt install libjsoncpp-devel +Centos8.x +sudo dnf install jsoncpp-devel -#### Gitee Feature +##### XEngine Install +you can install xengine env to your system by shell +like this:sudo XEngine_RunEnv.sh -i 3 +##### complie +execute command in XEngine_Source path +make complie +make FLAGS=InstallAll install +make FLAGS=CleanAll clear -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +#### XEngine Env +install XEngine can be refer to xengine Readme docment +GITEE:https://gitee.com/xyry/libxengine +GITHUB:https://github.com/libxengine/xengine + +#### use + +1. Switch to the MASTER branch +2. download code +3. complie +4. install +5. run +6. run example code + +## directory struct +- XEngine_Docment docment directory +- XEngine_Release install directory +- XEngine_Source code directory +- XEngine_Apps Client code directory + +## other problems +You can refer to the document under the docment directory. It contains API protocol and service description. + +## Test Server Address +Address:app.xyry.org or 159.75.200.173 +Port:Socks5 5400,HTTP Tunnel 5401 + +## Participate in contribution + +1. Fork this code +2. Create new Feat_xxx branch +3. Submit the code +4. New Pull Request + +## Follow us +If you think this software is helpful to you, please give us a START + +## post issues + +if you have eny quest.post issues... \ No newline at end of file diff --git a/README.md b/README.md index 4698c87..79f3f42 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,93 @@ -# XEngine_ProxyServer +[中文](README.md) || [English](README.en.md) +# XEngine_MQService +本仓库有开发和主分支,如果要使用,请使用master分支下的代码 -#### 介绍 -c c++代理服务器 支持SOCKSV4 V5和HTTP隧道代理. +## 介绍 +c c++ SOCKS5代理服务 HTTP Tunnel隧道代理服务 +c c++ Socks5 Proxy Service HTTP Tunnel Proxy Service -#### 软件架构 -软件架构说明 +## 软件架构 +此软件基于XEngine开发.采用C/C++作为开发语言 +此软件是一款标准的代理服务器,支持Socks5和HTTP的隧道代理 +## 软件特性 +此软件支持以下特性 +1. SOCKS5代理 +2. Tunnel代理 +3. 权限验证(planning) +4. 操作日志 +5. 加密通信(planning) +6. 负载均衡(planning) +## 安装教程 -#### 安装教程 +#### 版本需求 +支持WINDOWS 7SP1和LINUX(UBUNT20.04,CENTOS8)以上系统 +XEngine版本需要V7.26或者以上版本 +vcpkg 需要2021.05.11以上版本 -1. xxxx -2. xxxx -3. xxxx +#### Windows +使用VS2019 x86(debug release) x64(release)打开并且编译 +你需要按照下面的方式配置环境,不然你可能需要自己在项目中设置库目录 +##### 三方库环境 +需要使用VCPKG安装环境.代码地址:https://github.com/microsoft/vcpkg +安装好后你可能需要把它集成到你的VS中 +然后命令安装环境: vcpkg.exe install jsoncpp +集成VS环境: vcpkg integrate install +vcpkg 主要为了方便安装jsoncpp,如果你想自己配置jsoncpp的环境,可以不使用vcpkg... + +#### Linux +Linux使用Makefile编译 +UBUNTU20.04 x64或者CENTOS8 x64均可 + +##### 三方库环境 +基于不同系统,可能命令不同,比如在Ubuntu下面 +sudo apt install libjsoncpp-devel +Centos8.x +sudo dnf install jsoncpp-devel + +##### 编译命令 +在XEngine_Source目录下执行命令 +make 编译 +make FLAGS=InstallAll 安装库程序 +make FLAGS=CleanAll 清理编译 + +#### XEngine环境 +安装XEngine可以参考其Readme文档 +GITEE:https://gitee.com/xyry/libxengine +GITHUB:https://github.com/libxengine/xengine #### 使用说明 -1. xxxx -2. xxxx -3. xxxx +1. 切换到MASTER分支 +2. 下载代码 +3. 编译 +4. 安装 +5. 运行 +6. 运行演示代码 + +## 目录结构 +- XEngine_Docment 文档目录结构 +- XEngine_Release 安装目录结构 +- XEngine_Source 源代目录结构 +- XEngine_Apps 演示客户端目录 + +## 其他问题 +你可以参考docment目录下的文档.里面包含了API协议和服务说明. + +## 测试服务器 +地址:app.xyry.org 或者 159.75.200.173 +端口:Socks5 5400,HTTP Tunnel 5401 -#### 参与贡献 +## 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 -4. 新建 Pull Request +4. 新建 Pull Request +## 关注我们 +如果你觉得这个软件对你有帮助,请你给我们一个START吧 -#### 特技 +## 提交问题 -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +如果你有问题,可以在issues中提交 \ No newline at end of file -- Gitee From dbf62e04710585af6618b5631c82ee0635d64b58 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Wed, 8 Dec 2021 14:31:40 +0800 Subject: [PATCH 06/12] added:close client type --- .../XEngine_ServiceApp/XEngine_Network.cpp | 42 ++++++++++++++----- .../XEngine_ServiceApp/XEngine_Network.h | 2 +- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp index bc18c5d..3b345ff 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp @@ -29,12 +29,12 @@ void __stdcall Network_Callback_SocksRecv(LPCTSTR lpszClientAddr, SOCKET hSocket void __stdcall Network_Callback_SocksLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) { //交给指定函数来处理客户端离开消息 - XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_SOCKS, FALSE); + XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_SOCKS, XENGINE_CLIENT_CLOSE_NETWORK); } void __stdcall Network_Callback_SocksHeart(LPCSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam) { //同上 - XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_SOCKS, TRUE); + XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_SOCKS, XENGINE_CLIENT_CLOSE_HEARTBEAT); } //////////////////////////////////////////////////////////////////////////下面是Tunnel网络IO相关代码处理函数 BOOL __stdcall Network_Callback_TunnelLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) @@ -52,43 +52,65 @@ void __stdcall Network_Callback_TunnelRecv(LPCTSTR lpszClientAddr, SOCKET hSocke } void __stdcall Network_Callback_TunnelLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) { - XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_TUNNEL, FALSE); + XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_TUNNEL, XENGINE_CLIENT_CLOSE_NETWORK); } void __stdcall Network_Callback_TunnelHeart(LPCTSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam) { - XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_TUNNEL, TRUE); + XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_TUNNEL, XENGINE_CLIENT_CLOSE_HEARTBEAT); } //////////////////////////////////////////////////////////////////////////网络IO关闭操作 -void XEngine_Network_Close(LPCTSTR lpszClientAddr, int nIPProto, BOOL bHeart) +void XEngine_Network_Close(LPCTSTR lpszClientAddr, int nIPProto, int nCloseType) { if (XENGINE_CLIENT_NETTYPE_SOCKS == nIPProto) { //先关闭网络和心跳,他们主动回调的数据我们可以不用主动调用关闭 - if (bHeart) + if (XENGINE_CLIENT_CLOSE_NETWORK == nCloseType) + { + SocketOpt_HeartBeat_DeleteAddrEx(xhSocksHeart, lpszClientAddr); + } + else if (XENGINE_CLIENT_CLOSE_HEARTBEAT == nCloseType) { //心跳超时属于主动关闭,所以要主动调用网络关闭 NetCore_TCPXCore_CloseForClientEx(xhSocksSocket, lpszClientAddr); } else { - //同上 + //主动关闭 SocketOpt_HeartBeat_DeleteAddrEx(xhSocksHeart, lpszClientAddr); + NetCore_TCPXCore_CloseForClientEx(xhSocksSocket, lpszClientAddr); + } + PROXYPROTOCOL_CLIENTINFO st_ProxyClient; + memset(&st_ProxyClient, '\0', sizeof(PROXYPROTOCOL_CLIENTINFO)); + if (ProxyProtocol_SocksCore_GetInfo(lpszClientAddr, &st_ProxyClient)) + { + XClient_TCPSelect_Close(st_ProxyClient.hSocket); } ProxyProtocol_SocksCore_Delete(lpszClientAddr); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("SOCKS客户端:%s,离开服务器"), lpszClientAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("SOCKS客户端:%s,离开服务器,离开类型;%d"), lpszClientAddr, nCloseType); } else if (XENGINE_CLIENT_NETTYPE_TUNNEL == nIPProto) { - if (bHeart) + if (XENGINE_CLIENT_CLOSE_NETWORK == nCloseType) + { + SocketOpt_HeartBeat_DeleteAddrEx(xhTunnelHeart, lpszClientAddr); + } + else if (XENGINE_CLIENT_CLOSE_HEARTBEAT == nCloseType) { NetCore_TCPXCore_CloseForClientEx(xhTunnelSocket, lpszClientAddr); } else { SocketOpt_HeartBeat_DeleteAddrEx(xhTunnelHeart, lpszClientAddr); + NetCore_TCPXCore_CloseForClientEx(xhTunnelSocket, lpszClientAddr); + } + PROXYPROTOCOL_CLIENTINFO st_ProxyClient; + memset(&st_ProxyClient, '\0', sizeof(PROXYPROTOCOL_CLIENTINFO)); + if (ProxyProtocol_TunnelCore_GetInfo(lpszClientAddr, &st_ProxyClient)) + { + XClient_TCPSelect_Close(st_ProxyClient.hSocket); } ProxyProtocol_TunnelCore_Delete(lpszClientAddr); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Tunnel客户端:%s,离开服务器"), lpszClientAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Tunnel客户端:%s,离开服务器,离开类型;%d"), lpszClientAddr, nCloseType); } else { diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h index 4f6b7fe..a433e44 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h @@ -21,5 +21,5 @@ void __stdcall Network_Callback_TunnelRecv(LPCTSTR lpszClientAddr, SOCKET hSocke void __stdcall Network_Callback_TunnelLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam); void __stdcall Network_Callback_TunnelHeart(LPCTSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam); //关闭与发送 -void XEngine_Network_Close(LPCTSTR lpszClientAddr, int nIPProto, BOOL bHeart); +void XEngine_Network_Close(LPCTSTR lpszClientAddr, int nIPProto, int nCloseType); BOOL XEngine_Network_Send(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen, int nIPProto); \ No newline at end of file -- Gitee From 37fd3abffd7f3c1f1eaf16958120da46532d87a3 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Wed, 8 Dec 2021 14:32:08 +0800 Subject: [PATCH 07/12] added:socks proxy code --- .../XEngine_ServiceApp/XEngine_Hdr.h | 8 +- .../XEngine_ServiceApp/XEngine_SocksTask.cpp | 195 +++++++++++++++++- .../XEngine_ServiceApp/XEngine_SocksTask.h | 3 +- XEngine_Source/XEngine_UserProtocol.h | 1 + 4 files changed, 204 insertions(+), 3 deletions(-) diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h index 9e9149b..429d4b4 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h @@ -13,6 +13,9 @@ #include #include #include +#include +#include +#include #endif using namespace std; //加载XEngine头文件 @@ -67,7 +70,10 @@ extern XENGINE_SERVICECONFIG st_ServiceConfig; //网络类型定义 #define XENGINE_CLIENT_NETTYPE_SOCKS 1 #define XENGINE_CLIENT_NETTYPE_TUNNEL 2 - +//关闭模式 +#define XENGINE_CLIENT_CLOSE_NETWORK 1 +#define XENGINE_CLIENT_CLOSE_HEARTBEAT 2 +#define XENGINE_CLIENT_CLOSE_SERVICE 3 //连接库 #ifdef _WINDOWS diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp index 4c51702..de2a87c 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp @@ -12,6 +12,199 @@ *********************************************************************/ BOOL XEngine_SocksTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen) { - + int nLen = 4096; + TCHAR tszMsgBuffer[4096]; + memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer)); + + ENUM_RFCCOMPONENTS_PROXY_STATUS enSocksStatus; + if (!ProxyProtocol_SocksCore_GetStatus(lpszClientAddr, &enSocksStatus)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("SOCKS客户端:%s,获取状态失败,错误:%lX"), lpszClientAddr, ProxyProtocol_GetLastError()); + return FALSE; + } + //获取到的状态来处理相对应的事件 + if (ENUM_RFCCOMPONENTS_PROXY_STATUS_CREATE == enSocksStatus) + { + int nListCount = 0; + ENUM_RFCCOMPONENTS_PROXYSOCKS_AUTH enListAuths[6]; + if (!ProxyProtocol_SocksCore_ParseAuth(lpszClientAddr, lpszMsgBuffer, nMsgLen, enListAuths, &nListCount)) + { + ProxyProtocol_SocksCore_HdrPacket(lpszClientAddr, tszMsgBuffer, &nLen, ENUM_RFCCOMPONENTS_PROXYSOCKS_AUTH_NOAUTH); + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_SOCKS); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("SOCKS客户端:%s,解析验证协议失败,错误:%lX"), lpszClientAddr, ProxyProtocol_GetLastError()); + return FALSE; + } + BOOL bFoundAuth = FALSE; + TCHAR tszAuthBuffer[MAX_PATH]; + memset(tszAuthBuffer, '\0', MAX_PATH); + + //客户端支持的验证类型 + for (int i = 0; i < nListCount; i++) + { + TCHAR tszTmpBuffer[64]; + memset(tszTmpBuffer, '\0', sizeof(tszTmpBuffer)); + + _stprintf(tszTmpBuffer, _T("%d"), enListAuths[i]); + _tcscat(tszAuthBuffer, tszTmpBuffer); + _tcscat(tszAuthBuffer, _T(" ")); + //服务器是否支持 + if (st_ServiceConfig.st_XSocks.nAuthType == enListAuths[i]) + { + bFoundAuth = TRUE; + } + } + if (!bFoundAuth) + { + ProxyProtocol_SocksCore_HdrPacket(lpszClientAddr, tszMsgBuffer, &nLen, ENUM_RFCCOMPONENTS_PROXYSOCKS_AUTH_NOAUTH); + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_SOCKS); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("SOCKS客户端:%s,解析验证协议成功,但是验证类型不支持,客户端的支持验证:%s,服务器支持的验证:%d"), lpszClientAddr, tszAuthBuffer, st_ServiceConfig.st_XSocks.nAuthType); + return FALSE; + } + ProxyProtocol_SocksCore_HdrPacket(lpszClientAddr, tszMsgBuffer, &nLen, st_ServiceConfig.st_XSocks.nAuthType); + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_SOCKS); + //如果是匿名,不会有ENUM_RFCCOMPONENTS_PROXY_STATUS_AUTH步骤 + if (ENUM_RFCCOMPONENTS_PROXYSOCKS_AUTH_ANONYMOUS == st_ServiceConfig.st_XSocks.nAuthType) + { + //跳过 + ProxyProtocol_SocksCore_SetStatus(lpszClientAddr, ENUM_RFCCOMPONENTS_PROXY_STATUS_USER); + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("SOCKS客户端:%s,解析验证协议成功,支持的验证类型:%s,使用的验证类型:%d"), lpszClientAddr, tszAuthBuffer, st_ServiceConfig.st_XSocks.nAuthType); + } + else if (ENUM_RFCCOMPONENTS_PROXY_STATUS_AUTH == enSocksStatus) + { + TCHAR tszUserName[MAX_PATH]; + TCHAR tszUserPass[MAX_PATH]; + ENUM_RFCCOMPONENTS_PROXYSOCKS_AUTH enProxyAuth; + + memset(tszUserName, '\0', MAX_PATH); + memset(tszUserPass, '\0', MAX_PATH); + + if (!ProxyProtocol_SocksCore_ParseUser(lpszClientAddr, lpszMsgBuffer, nMsgLen, &enProxyAuth, tszUserName, tszUserPass)) + { + ProxyProtocol_SocksCore_HdrPacket(lpszClientAddr, tszMsgBuffer, &nLen, XENGINE_RFCCOMPONENT_PROXY_SOCKS_RESPONSE_FAILED); + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_SOCKS); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("SOCKS客户端:%s,用户登录验证失败,错误:%lX"), lpszClientAddr, ProxyProtocol_GetLastError()); + return FALSE; + } + if (enProxyAuth != st_ServiceConfig.st_XSocks.nAuthType) + { + ProxyProtocol_SocksCore_HdrPacket(lpszClientAddr, tszMsgBuffer, &nLen, XENGINE_RFCCOMPONENT_PROXY_SOCKS_RESPONSE_FAILED); + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_SOCKS); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("SOCKS客户端:%s,用户登录验证失败,客户端发送的验证类型不支持"), lpszClientAddr); + return FALSE; + } + ProxyProtocol_SocksCore_HdrPacket(lpszClientAddr, tszMsgBuffer, &nLen, XENGINE_RFCCOMPONENT_PROXY_SOCKS_RESPONSE_SUCCESS); + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_SOCKS); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("SOCKS客户端:%s,用户登录验证成功,使用的验证类型:%d"), lpszClientAddr, enProxyAuth); + } + else if (ENUM_RFCCOMPONENTS_PROXY_STATUS_USER == enSocksStatus) + { + int nPort = 0; + TCHAR tszClientAddr[1024]; + PROXYPROTOCOL_CLIENTINFO st_ProxyClient; + ENUM_RFCCOMPONENTS_PROXYSOCKS_COMMAND enCommand; + ENUM_RFCCOMPONENTS_PROXYSOCKS_IPADDR enIPType; + + memset(tszClientAddr, '\0', sizeof(tszClientAddr)); + memset(&st_ProxyClient, '\0', sizeof(PROXYPROTOCOL_CLIENTINFO)); + if (!ProxyProtocol_SocksCore_ParseConnect(lpszClientAddr, lpszMsgBuffer, nMsgLen, &enCommand, &enIPType, tszClientAddr, &nPort)) + { + ProxyProtocol_SocksCore_HdrPacket(lpszClientAddr, tszMsgBuffer, &nLen, XENGINE_RFCCOMPONENT_PROXY_SOCKS_RESPONSE_NETWORK); + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_SOCKS); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("SOCKS客户端:%s,用户连接失败,错误:%lX"), lpszClientAddr, ProxyProtocol_GetLastError()); + return FALSE; + } + //命令类型 + if (ENUM_RFCCOMPONENTS_PROXYSOCKS_COMMAND_CONNECT == enCommand) + { + //连接类型,IP还是域名,没有IPV6环境.不好测试 + if (ENUM_RFCCOMPONENTS_PROXYSOCKS_IPADDR_IPV4 == enIPType) + { + if (!XClient_TCPSelect_Create(&st_ProxyClient.hSocket, tszClientAddr, nPort, AF_INET, 1)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("SOCKS客户端:%s,创建客户端连接失败,连接到服务器:%s:%d,错误:%lX"), lpszClientAddr, tszClientAddr, nPort, ProxyProtocol_GetLastError()); + return FALSE; + } + } + else + { + int nListCount = 0; + CHAR** ppszListAddr; + ENUM_APIHELP_DOMAINTYPE enDomainType; + APIHELP_DOMAIN st_APIUrl; + + memset(&st_APIUrl, '\0', sizeof(APIHELP_DOMAIN)); + + APIHelp_Domain_GetInfo(tszClientAddr, &st_APIUrl, &enDomainType); + memset(tszClientAddr, '\0', sizeof(tszClientAddr)); + _stprintf(tszClientAddr, _T("%s.%s"), st_APIUrl.tszSubDomain, st_APIUrl.tszMainDomain); + + if (!NetXApi_Socket_DomainToAddr(tszClientAddr, &ppszListAddr, &nListCount)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("SOCKS客户端:%s,解析域名失败,错误:%lX"), lpszClientAddr, ProxyProtocol_GetLastError()); + return FALSE; + } + memset(tszClientAddr, '\0', sizeof(tszClientAddr)); + _tcscpy(tszClientAddr, ppszListAddr[0]); //随便选择一个IP地址 + BaseLib_OperatorMemory_Free((XPPPMEM)&ppszListAddr, nListCount); + if (!XClient_TCPSelect_Create(&st_ProxyClient.hSocket, tszClientAddr, nPort, AF_INET, 1)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("SOCKS客户端:%s,创建客户端连接失败,连接到服务器:%s:%d,错误:%lX"), lpszClientAddr, tszClientAddr, nPort, ProxyProtocol_GetLastError()); + return FALSE; + } + } + } + //配置客户端信息 + st_ProxyClient.enStatus = ENUM_RFCCOMPONENTS_PROXY_STATUS_FORWARD; + _tcscpy(st_ProxyClient.tszIPAddr, lpszClientAddr); + ProxyProtocol_SocksCore_SetInfo(lpszClientAddr, &st_ProxyClient, sizeof(PROXYPROTOCOL_CLIENTINFO)); + //创建转发线程 + std::thread pSTDThread(XEngine_SocksTask_Thread, lpszClientAddr); + pSTDThread.detach(); + //回复结果 + ProxyProtocol_SocksCore_HdrPacket(lpszClientAddr, tszMsgBuffer, &nLen, XENGINE_RFCCOMPONENT_PROXY_SOCKS_RESPONSE_SUCCESS); + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nLen, XENGINE_CLIENT_NETTYPE_SOCKS); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("SOCKS客户端:%s,用户登录验证成功,连接到地址:%s:%d"), lpszClientAddr, tszClientAddr, nPort); + } + else + { + //ENUM_RFCCOMPONENTS_PROXY_STATUS_FORWARD 转发 + PROXYPROTOCOL_CLIENTINFO st_ProxyClient; + memset(&st_ProxyClient, '\0', sizeof(PROXYPROTOCOL_CLIENTINFO)); + if (ProxyProtocol_SocksCore_GetInfo(lpszClientAddr, &st_ProxyClient)) + { + XClient_TCPSelect_SendMsg(st_ProxyClient.hSocket, lpszMsgBuffer, nMsgLen); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Socks客户端:%s,转发数据失败,可能与服务器的连接已经关闭,错误:%lX"), lpszClientAddr, ProxyProtocol_GetLastError()); + } + } return TRUE; +} +XHTHREAD CALLBACK XEngine_SocksTask_Thread(LPCTSTR lpszClientAddr) +{ + TCHAR tszClientAddr[128]; + PROXYPROTOCOL_CLIENTINFO st_ProxyClient; + + memset(tszClientAddr, '\0', sizeof(tszClientAddr)); + _tcscpy(tszClientAddr, lpszClientAddr); + while (1) + { + int nMsgLen = 4096; + TCHAR tszMsgBuffer[4096]; + + memset(&st_ProxyClient, '\0', sizeof(PROXYPROTOCOL_CLIENTINFO)); + if (!ProxyProtocol_SocksCore_GetInfo(tszClientAddr, &st_ProxyClient)) + { + break; + } + if (!XClient_TCPSelect_RecvMsg(st_ProxyClient.hSocket, tszMsgBuffer, &nMsgLen, FALSE)) + { + break; + } + XEngine_Network_Send(st_ProxyClient.tszIPAddr, tszMsgBuffer, nMsgLen, XENGINE_CLIENT_NETTYPE_SOCKS); + } + XEngine_Network_Close(tszClientAddr, XENGINE_CLIENT_NETTYPE_SOCKS, XENGINE_CLIENT_CLOSE_SERVICE); + return 0; } \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.h b/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.h index 3409083..d4ace21 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.h @@ -11,4 +11,5 @@ // History: *********************************************************************/ //任务处理相关函数,处理包的内容 -BOOL XEngine_SocksTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen); \ No newline at end of file +BOOL XEngine_SocksTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen); +XHTHREAD CALLBACK XEngine_SocksTask_Thread(LPCTSTR lpszClientAddr); \ No newline at end of file diff --git a/XEngine_Source/XEngine_UserProtocol.h b/XEngine_Source/XEngine_UserProtocol.h index 187b374..7790776 100644 --- a/XEngine_Source/XEngine_UserProtocol.h +++ b/XEngine_Source/XEngine_UserProtocol.h @@ -33,5 +33,6 @@ typedef struct TCHAR tszIPAddr[128]; ENUM_RFCCOMPONENTS_PROXY_STATUS enStatus; SOCKET hSocket; + BOOL bConnect; }PROXYPROTOCOL_CLIENTINFO; #pragma pack(pop) \ No newline at end of file -- Gitee From f22c04a44647650fa6a08040c42937e3a484904d Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Wed, 8 Dec 2021 14:32:47 +0800 Subject: [PATCH 08/12] fixed:build error and close thread mode --- XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp index 3c737ae..b6cc419 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp @@ -22,11 +22,11 @@ BOOL XEngine_TunnelTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in int nLen = 0; int nIPPort = 0; BOOL bProxy = TRUE; - TCHAR tszIPAddr[MAX_PATH]; + TCHAR tszIPAddr[1024]; TCHAR tszAuthInfo[MAX_PATH]; TCHAR tszMsgBuffer[MAX_PATH]; - memset(tszIPAddr, '\0', MAX_PATH); + memset(tszIPAddr, '\0', sizeof(tszIPAddr)); memset(tszAuthInfo, '\0', MAX_PATH); memset(tszMsgBuffer, '\0', MAX_PATH); if (!ProxyProtocol_TunnelCore_Parse(lpszClientAddr, lpszMsgBuffer, nMsgLen, tszIPAddr, &nIPPort, tszAuthInfo, &bProxy)) @@ -121,6 +121,6 @@ XHTHREAD CALLBACK XEngine_TunnelTask_Thread(LPCTSTR lpszClientAddr) } XEngine_Network_Send(st_ProxyClient.tszIPAddr, tszMsgBuffer, nMsgLen, XENGINE_CLIENT_NETTYPE_TUNNEL); } - XClient_TCPSelect_Close(st_ProxyClient.hSocket); + XEngine_Network_Close(tszClientAddr, XENGINE_CLIENT_NETTYPE_TUNNEL, XENGINE_CLIENT_CLOSE_SERVICE); return 0; } \ No newline at end of file -- Gitee From 40168377133afe63443ca009f42866e8c023ab03 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Wed, 8 Dec 2021 15:56:22 +0800 Subject: [PATCH 09/12] fixed:tunnel task get client info error in the thread --- XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp index b6cc419..56fff2e 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp @@ -73,11 +73,13 @@ BOOL XEngine_TunnelTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Tunnel客户端:%s,创建客户端连接失败,连接到服务器:%s:%d,错误:%lX"), lpszClientAddr, tszConnectAddr, nIPPort, ProxyProtocol_GetLastError()); return FALSE; } - std::thread pSTDThread(XEngine_TunnelTask_Thread, lpszClientAddr); - pSTDThread.detach(); + //设置属于 st_ProxyClient.enStatus = ENUM_RFCCOMPONENTS_PROXY_STATUS_FORWARD; _tcscpy(st_ProxyClient.tszIPAddr, lpszClientAddr); ProxyProtocol_TunnelCore_SetInfo(lpszClientAddr, &st_ProxyClient, sizeof(PROXYPROTOCOL_CLIENTINFO)); + //启动线程 + std::thread pSTDThread(XEngine_TunnelTask_Thread, lpszClientAddr); + pSTDThread.detach(); //判断是代理还是非代理协议 if (bProxy) { -- Gitee From 2e4086da7efcc16fc856e58bdabf266b197e8569 Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Wed, 8 Dec 2021 16:36:26 +0800 Subject: [PATCH 10/12] fixed:linux build modofy:vscopy file --- XEngine_APPClient/VSClean.bat | 10 ++++++++++ XEngine_Source/VSCopy-Debug.bat | 14 ++++++++++++++ XEngine_Source/VSCopy-x86.bat | 14 +++++++++++--- .../XEngine_ModuleConfigure.vcxproj | 16 ++++++++++++---- XEngine_Source/XEngine_ServiceApp/Makefile | 14 +++++++------- .../XEngine_ServiceApp.vcxproj | 16 ++++++++++++---- 6 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 XEngine_APPClient/VSClean.bat create mode 100644 XEngine_Source/VSCopy-Debug.bat diff --git a/XEngine_APPClient/VSClean.bat b/XEngine_APPClient/VSClean.bat new file mode 100644 index 0000000..bf8eca3 --- /dev/null +++ b/XEngine_APPClient/VSClean.bat @@ -0,0 +1,10 @@ +@echo Off +del /s /a *.ncb *.so *.o *.db +FOR /R . %%d IN (.) DO rd /s /q "%%d\Debug" 2>nul +FOR /R . %%d IN (.) DO rd /s /q "%%d\Release" 2>nul +FOR /R . %%d IN (.) DO rd /s /q "%%d\x64" 2>nul +FOR /R . %%d IN (.) DO rd /s /q "%%d\Debug" 2>nul +FOR /R . %%d IN (.) DO rd /s /q "%%d\ipch" 2>nul + +rem If the Properties directory is empty, remove it +FOR /R . %%d in (.) do rd /q "%%d\Properties" 2> nul diff --git a/XEngine_Source/VSCopy-Debug.bat b/XEngine_Source/VSCopy-Debug.bat new file mode 100644 index 0000000..7ed9466 --- /dev/null +++ b/XEngine_Source/VSCopy-Debug.bat @@ -0,0 +1,14 @@ +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_ManagePool.dll" "./" +copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_NetXApi.dll" "./" + +copy /y "D:\XEngine\XEngine_SourceCode\Debug\NetHelp_APIHelp.dll" "./" +copy /y "D:\XEngine\XEngine_SourceCode\Debug\XClient_Socket.dll" "./" + +copy /y "D:\XEngine\XEngine_SourceCode\Debug\HelpComponents_XLog.dll" "./" +copy /y "D:\XEngine\XEngine_SourceCode\Debug\RfcComponents_ProxyProtocol.dll" "./" + +copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_ProcFile.dll" "./" +copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_SystemApi.dll" "./" \ No newline at end of file diff --git a/XEngine_Source/VSCopy-x86.bat b/XEngine_Source/VSCopy-x86.bat index 68d65d6..91b52bb 100644 --- a/XEngine_Source/VSCopy-x86.bat +++ b/XEngine_Source/VSCopy-x86.bat @@ -2,13 +2,21 @@ copy /y "%XEngine_Library%\x86\XEngine_BaseLib\XEngine_BaseLib.dll" "./" copy /y "%XEngine_Library%\x86\XEngine_BaseLib\XEngine_Algorithm.dll" "./" copy /y "%XEngine_Library%\x86\XEngine_Core\XEngine_Core.dll" "./" copy /y "%XEngine_Library%\x86\XEngine_Core\XEngine_ManagePool.dll" "./" +copy /y "%XEngine_Library%\x86\XEngine_Core\XEngine_NetXApi.dll" "./" -copy /y "%XEngine_Library%\x86\XEngine_SystemSdk\XEngine_SystemApi.dll" "./" +copy /y "%XEngine_Library%\x86\XEngine_NetHelp\NetHelp_APIHelp.dll" "./" +copy /y "%XEngine_Library%\x86\XEngine_Client\XClient_Socket.dll" "./" -copy /y "%XEngine_Library%\x86\XEngine_HelpComponents\HelpComponents_Packets.dll" "./" copy /y "%XEngine_Library%\x86\XEngine_HelpComponents\HelpComponents_XLog.dll" "./" -copy /y "%XEngine_Library%\x86\XEngine_RfcComponents\RfcComponents_HttpServer.dll" "./" +copy /y "%XEngine_Library%\x86\XEngine_RfcComponents\RfcComponents_ProxyProtocol.dll" "./" + +copy /y "%XEngine_Library%\x86\XEngine_SystemSdk\XEngine_ProcFile.dll" "./" +copy /y "%XEngine_Library%\x86\XEngine_SystemSdk\XEngine_SystemApi.dll" "./" + +copy /y "%XEngine_Library%\x86\XEngine_SystemSdk\XEngine_ProcFile.dll" "./" +copy /y "%XEngine_Library%\x86\XEngine_SystemSdk\XEngine_SystemApi.dll" "./" copy /y "%XEngine_Library%\x86\XEngine_LibEx\libcrypto-1_1.dll" "./" copy /y "%XEngine_Library%\x86\XEngine_LibEx\libssl-1_1.dll" "./" +copy /y "%XEngine_Library%\x86\XEngine_LibEx\libcurl.dll" "./" copy /y "%XEngine_Library%\x86\XEngine_HelpComponents\zlib1.dll" "./" \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj b/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj index acc2a80..4569d2e 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj +++ b/XEngine_Source/XEngine_ModuleConfigure/XEngine_ModuleConfigure.vcxproj @@ -37,7 +37,7 @@ false v142 true - Unicode + MultiByte DynamicLibrary @@ -50,7 +50,7 @@ false v142 true - Unicode + MultiByte @@ -77,12 +77,16 @@ false + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) true false + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) @@ -107,10 +111,12 @@ true true true - WIN32;NDEBUG;XENGINEMODULECONFIGURE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + WIN32;NDEBUG;XENGINEMODULECONFIGURE_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true Use pch.h + MultiThreaded + 4819 Windows @@ -143,10 +149,12 @@ true true true - NDEBUG;XENGINEMODULECONFIGURE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + NDEBUG;XENGINEMODULECONFIGURE_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true Use pch.h + MultiThreaded + 4819 Windows diff --git a/XEngine_Source/XEngine_ServiceApp/Makefile b/XEngine_Source/XEngine_ServiceApp/Makefile index 650e95e..de8ea8a 100644 --- a/XEngine_Source/XEngine_ServiceApp/Makefile +++ b/XEngine_Source/XEngine_ServiceApp/Makefile @@ -1,11 +1,11 @@ CC = g++ -Wall RELEASE = 0 UNICODE = 0 -LOADBIN = -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_Core -L /usr/local/lib/XEngine_Release/XEngine_HelpComponents -L /usr/local/lib/XEngine_Release/XEngine_RfcComponents -L ../XEngine_ModuleConfigure -LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_ManagePool -lHelpComponents_XLog -lHelpComponents_Packets -lRfcComponents_HttpServer -lXEngine_ModuleConfigure +LOADBIN = -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_Core -L /usr/local/lib/XEngine_Release/XEngine_HelpComponents -L /usr/local/lib/XEngine_Release/XEngine_RfcComponents -L /usr/local/lib/XEngine_Release/XEngine_Client -L /usr/local/lib/XEngine_Release/XEngine_NetHelp -L ../XEngine_ModuleConfigure +LIB = -lXEngine_BaseLib -lXEngine_Algorithm -lXEngine_Core -lXEngine_ManagePool -lXEngine_NetXApi -lHelpComponents_XLog -lRfcComponents_ProxyProtocol -lXClient_Socket -lNetHelp_APIHelp -lXEngine_ModuleConfigure LIBEX = -static-libgcc -ldl -lrt -lpthread LOADSO = -Wl,-rpath=./,--disable-new-dtags -LIBINCLUDE = XEngine_Configure.o XEngine_Network.o XEngine_TCPTask.o XEngine_HTTPTask.o XEngine_ServiceApp.o +LIBINCLUDE = XEngine_Configure.o XEngine_Network.o XEngine_SocksTask.o XEngine_TunnelTask.o XEngine_ServiceApp.o ifeq ($(RELEASE),1) FLAGS = -c -O2 @@ -28,10 +28,10 @@ XEngine_Configure.o:./XEngine_Configure.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) ./XEngine_Configure.cpp XEngine_Network.o:./XEngine_Network.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) ./XEngine_Network.cpp -XEngine_TCPTask.o:./XEngine_TCPTask.cpp - $(CC) $(DEBUG) $(FLAGS) $(UNICODE) ./XEngine_TCPTask.cpp -XEngine_HTTPTask.o:./XEngine_HTTPTask.cpp - $(CC) $(DEBUG) $(FLAGS) $(UNICODE) ./XEngine_HTTPTask.cpp +XEngine_SocksTask.o:./XEngine_SocksTask.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) ./XEngine_SocksTask.cpp +XEngine_TunnelTask.o:./XEngine_TunnelTask.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) ./XEngine_TunnelTask.cpp XEngine_ServiceApp.o:./XEngine_ServiceApp.cpp $(CC) $(DEBUG) $(FLAGS) $(UNICODE) ./XEngine_ServiceApp.cpp diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj index 035d3a1..49064fa 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj @@ -37,7 +37,7 @@ false v142 true - Unicode + MultiByte Application @@ -50,7 +50,7 @@ false v142 true - Unicode + MultiByte @@ -77,12 +77,16 @@ false + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) true false + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) @@ -103,8 +107,10 @@ true true true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + WIN32;NDEBUG;_CONSOLE;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true + MultiThreaded + 4819 Console @@ -131,8 +137,10 @@ true true true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + NDEBUG;_CONSOLE;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true + MultiThreaded + 4819 Console -- Gitee From 8dafa95c0975a88141876b7fd8ac97f3f81f93de Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Thu, 9 Dec 2021 09:10:57 +0800 Subject: [PATCH 11/12] added:client example --- .../APPClient_SocksExample.cpp | 128 +++++++++++++++ .../APPClient_SocksExample.vcxproj | 149 +++++++++++++++++ .../APPClient_SocksExample.vcxproj.filters | 22 +++ .../APPClient_SocksExample.vcxproj.user | 4 + .../APPClient_TunnelExample.cpp | 83 ++++++++++ .../APPClient_TunnelExample.vcxproj | 150 ++++++++++++++++++ .../APPClient_TunnelExample.vcxproj.filters | 22 +++ .../APPClient_TunnelExample.vcxproj.user | 4 + XEngine_APPClient/XEngine_APPClient.sln | 41 +++++ 9 files changed, 603 insertions(+) create mode 100644 XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.cpp create mode 100644 XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj create mode 100644 XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj.filters create mode 100644 XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj.user create mode 100644 XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.cpp create mode 100644 XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj create mode 100644 XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj.filters create mode 100644 XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj.user create mode 100644 XEngine_APPClient/XEngine_APPClient.sln diff --git a/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.cpp b/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.cpp new file mode 100644 index 0000000..802580e --- /dev/null +++ b/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.cpp @@ -0,0 +1,128 @@ +#ifdef _WINDOWS +#include +#include +#pragma comment(lib,"Ws2_32.lib") +#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") +#pragma comment(lib,"XEngine_Client/XClient_Socket.lib") +#pragma comment(lib,"XEngine_RfcComponents/RfcComponents_ProxyProtocol.lib") +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../../XEngine_Source/XEngine_UserProtocol.h" + +//需要优先配置XEngine +//WINDOWS支持VS2019 x86 debug 编译调试 +//linux使用下面的命令编译 +//g++ -std=c++17 -Wall -g APPClient_SocksExample.cpp -o APPClient_SocksExample.exe -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_Client -L /usr/local/lib/XEngine_Release/XEngine_RfcComponents -lXEngine_BaseLib -lXClient_Socket -lRfcComponents_ProxyProtocol +int main(int argc, char** argv) +{ +#ifdef _WINDOWS + WSADATA st_WSAData; + WSAStartup(MAKEWORD(2, 2), &st_WSAData); +#endif + SOCKET m_Socket; + LPCTSTR lpszServiceAddr = _T("127.0.0.1"); + if (!XClient_TCPSelect_Create(&m_Socket, lpszServiceAddr, 5400)) + { + printf("连接失败!错误:%lX\n", XClient_GetLastError()); + return 0; + } + printf("连接成功!\n"); + + int nMsgLen = 2048; + TCHAR tszMsgBuffer[2048]; + memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer)); + + int nCount = 2; + ENUM_RFCCOMPONENTS_PROXYSOCKS_AUTH enAuths[2] = { ENUM_RFCCOMPONENTS_PROXYSOCKS_AUTH_ANONYMOUS ,ENUM_RFCCOMPONENTS_PROXYSOCKS_AUTH_USERPASS }; + //////////////////////////////////////////////////////////////////////////验证 + ProxyProtocol_SocksClient_AuthPacket(tszMsgBuffer, &nMsgLen, enAuths, nCount); + if (!XClient_TCPSelect_SendMsg(m_Socket, tszMsgBuffer, nMsgLen)) + { + printf("发送投递失败!\n"); + return 0; + } + nMsgLen = 2048; + memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer)); + + if (!XClient_TCPSelect_RecvMsg(m_Socket, tszMsgBuffer, &nMsgLen, FALSE)) + { + printf("接受数据失败!\n"); + return 0; + } + ENUM_RFCCOMPONENTS_PROXYSOCKS_AUTH enServerAuth; + ProxyProtocol_SocksClient_AuthParse(tszMsgBuffer, &enServerAuth); + printf("接受服务器返回数据,内容:%d\n", enServerAuth); + //////////////////////////////////////////////////////////////////////////登录 匿名登录不需要 + /* + ProxyProtocol_SocksClient_LoginPacket(tszMsgBuffer, &nMsgLen); + if (!XClient_TCPSelect_SendMsg(m_Socket, tszMsgBuffer, nMsgLen)) + { + printf("发送投递失败!\n"); + return 0; + } + + nMsgLen = 2048; + memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer)); + if (!XClient_TCPSelect_RecvMsg(m_Socket, tszMsgBuffer, &nMsgLen, FALSE)) + { + printf("接受数据失败!\n"); + return 0; + } + if (ProxyProtocol_SocksClient_LoginParse(tszMsgBuffer)) + { + printf("login ok\n"); + } + else + { + printf("login failed\n"); + }*/ + //////////////////////////////////////////////////////////////////////////连接 + ProxyProtocol_SocksClient_ConnectPacket(tszMsgBuffer, &nMsgLen, "www.xyry.org", 80, ENUM_RFCCOMPONENTS_PROXYSOCKS_COMMAND_CONNECT, ENUM_RFCCOMPONENTS_PROXYSOCKS_IPADDR_DOMAIN); + if (!XClient_TCPSelect_SendMsg(m_Socket, tszMsgBuffer, nMsgLen)) + { + printf("发送投递失败!\n"); + return 0; + } + nMsgLen = 2048; + memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer)); + if (!XClient_TCPSelect_RecvMsg(m_Socket, tszMsgBuffer, &nMsgLen, FALSE)) + { + printf("接受数据失败!\n"); + return 0; + } + int nCode = 0; + ProxyProtocol_SocksClient_ConnectParse(tszMsgBuffer, &nCode); + //请求 + LPCTSTR lpszGetHttp = _T("GET / HTTP/1.1\r\nHost: www.xyry.org\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36\r\nAccept: text/html\r\n\r\n"); + if (!XClient_TCPSelect_SendMsg(m_Socket, lpszGetHttp, _tcslen(lpszGetHttp))) + { + printf("发送投递失败!\n"); + return 0; + } + while (1) + { + nMsgLen = 2048; + memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer)); + if (!XClient_TCPSelect_RecvMsg(m_Socket, tszMsgBuffer, &nMsgLen, FALSE)) + { + break; + } + printf("接受服务器返回数据,内容:%s\n", tszMsgBuffer); + } + + XClient_TCPSelect_Close(m_Socket); +#ifdef _WINDOWS + WSACleanup(); +#endif + return 0; +} \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj b/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj new file mode 100644 index 0000000..4d9b108 --- /dev/null +++ b/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj @@ -0,0 +1,149 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {420e0f5f-cefd-4bdf-a61a-bc23b7803549} + APPClientSocksExample + 10.0 + + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;_WINDOWS;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj.filters b/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj.filters new file mode 100644 index 0000000..b95aa3c --- /dev/null +++ b/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj.user b/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.cpp b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.cpp new file mode 100644 index 0000000..1ad7b34 --- /dev/null +++ b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.cpp @@ -0,0 +1,83 @@ +#ifdef _WINDOWS +#include +#include +#pragma comment(lib,"Ws2_32.lib") +#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") +#pragma comment(lib,"XEngine_Client/XClient_Socket.lib") +#pragma comment(lib,"XEngine_RfcComponents/RfcComponents_ProxyProtocol.lib") +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../../XEngine_Source/XEngine_UserProtocol.h" + +//需要优先配置XEngine +//WINDOWS支持VS2019 x86 debug 编译调试 +//linux使用下面的命令编译 +//g++ -std=c++17 -Wall -g APPClient_TunnelExample.cpp -o APPClient_TunnelExample.exe -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_Client -L /usr/local/lib/XEngine_Release/XEngine_RfcComponents -lXEngine_BaseLib -lXClient_Socket -lRfcComponents_ProxyProtocol +int main(int argc, char** argv) +{ +#ifdef _WINDOWS + WSADATA st_WSAData; + WSAStartup(MAKEWORD(2, 2), &st_WSAData); +#endif + SOCKET m_Socket; + LPCTSTR lpszServiceAddr = _T("192.168.1.12"); + if (!XClient_TCPSelect_Create(&m_Socket, lpszServiceAddr, 5401)) + { + printf("连接失败!错误:%lX\n", XClient_GetLastError()); + return 0; + } + printf("连接成功!\n"); + int nMsgLen = 2048; + TCHAR tszMsgBuffer[2048]; + memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer)); + + ProxyProtocol_TunnelClient_Packet(tszMsgBuffer, &nMsgLen, "www.xyry.org:80"); + if (!XClient_TCPSelect_SendMsg(m_Socket, tszMsgBuffer, nMsgLen)) + { + printf("发送投递失败!\n"); + return 0; + } + nMsgLen = 2048; + memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer)); + + if (!XClient_TCPSelect_RecvMsg(m_Socket, tszMsgBuffer, &nMsgLen, FALSE)) + { + printf("接受数据失败!\n"); + return 0; + } + printf("接受服务器返回数据,内容:%s\n", tszMsgBuffer); + + LPCTSTR lpszGetHttp = _T("GET / HTTP/1.1\r\nHost: www.xyry.org\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36\r\nAccept: text/html\r\n\r\n"); + if (!XClient_TCPSelect_SendMsg(m_Socket, lpszGetHttp, _tcslen(lpszGetHttp))) + { + printf("发送投递失败!\n"); + return 0; + } + + while (1) + { + nMsgLen = 2048; + memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer)); + if (!XClient_TCPSelect_RecvMsg(m_Socket, tszMsgBuffer, &nMsgLen, FALSE)) + { + break; + } + printf("接受服务器返回数据,内容:%s\n", tszMsgBuffer); + } + + XClient_TCPSelect_Close(m_Socket); +#ifdef _WINDOWS + WSACleanup(); +#endif + return 0; +} \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj new file mode 100644 index 0000000..1cc92e0 --- /dev/null +++ b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj @@ -0,0 +1,150 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {bfa995e0-82c3-47d6-b421-08937dee7f18} + APPClientTunnelExample + 10.0 + + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;_WINDOWS;%(PreprocessorDefinitions) + true + 4819 + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj.filters b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj.filters new file mode 100644 index 0000000..4053518 --- /dev/null +++ b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj.user b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_APPClient/XEngine_APPClient.sln b/XEngine_APPClient/XEngine_APPClient.sln new file mode 100644 index 0000000..a228438 --- /dev/null +++ b/XEngine_APPClient/XEngine_APPClient.sln @@ -0,0 +1,41 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31911.196 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_SocksExample", "APPClient_SocksExample\APPClient_SocksExample.vcxproj", "{420E0F5F-CEFD-4BDF-A61A-BC23B7803549}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_TunnelExample", "APPClient_TunnelExample\APPClient_TunnelExample.vcxproj", "{BFA995E0-82C3-47D6-B421-08937DEE7F18}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {420E0F5F-CEFD-4BDF-A61A-BC23B7803549}.Debug|x64.ActiveCfg = Debug|x64 + {420E0F5F-CEFD-4BDF-A61A-BC23B7803549}.Debug|x64.Build.0 = Debug|x64 + {420E0F5F-CEFD-4BDF-A61A-BC23B7803549}.Debug|x86.ActiveCfg = Debug|Win32 + {420E0F5F-CEFD-4BDF-A61A-BC23B7803549}.Debug|x86.Build.0 = Debug|Win32 + {420E0F5F-CEFD-4BDF-A61A-BC23B7803549}.Release|x64.ActiveCfg = Release|x64 + {420E0F5F-CEFD-4BDF-A61A-BC23B7803549}.Release|x64.Build.0 = Release|x64 + {420E0F5F-CEFD-4BDF-A61A-BC23B7803549}.Release|x86.ActiveCfg = Release|Win32 + {420E0F5F-CEFD-4BDF-A61A-BC23B7803549}.Release|x86.Build.0 = Release|Win32 + {BFA995E0-82C3-47D6-B421-08937DEE7F18}.Debug|x64.ActiveCfg = Debug|x64 + {BFA995E0-82C3-47D6-B421-08937DEE7F18}.Debug|x64.Build.0 = Debug|x64 + {BFA995E0-82C3-47D6-B421-08937DEE7F18}.Debug|x86.ActiveCfg = Debug|Win32 + {BFA995E0-82C3-47D6-B421-08937DEE7F18}.Debug|x86.Build.0 = Debug|Win32 + {BFA995E0-82C3-47D6-B421-08937DEE7F18}.Release|x64.ActiveCfg = Release|x64 + {BFA995E0-82C3-47D6-B421-08937DEE7F18}.Release|x64.Build.0 = Release|x64 + {BFA995E0-82C3-47D6-B421-08937DEE7F18}.Release|x86.ActiveCfg = Release|Win32 + {BFA995E0-82C3-47D6-B421-08937DEE7F18}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CC8142BD-8426-4A48-94DD-7560D3BA8C15} + EndGlobalSection +EndGlobal -- Gitee From 50ea6eac70a4606c6635bdfdb96aa5562290eb0a Mon Sep 17 00:00:00 2001 From: qyt <486179@qq.com> Date: Thu, 9 Dec 2021 09:28:21 +0800 Subject: [PATCH 12/12] update:readme and configure file --- README.en.md | 2 + README.md | 3 +- .../XEngine_Config/XEngine_Config.json | 41 ++++++++++--------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/README.en.md b/README.en.md index 98f963e..2acd5d0 100644 --- a/README.en.md +++ b/README.en.md @@ -1,4 +1,5 @@ # XEngine_ProxyServer +we have a development and a master branch. If you want to use it, please use the code under the master branch #### Description c c++ SOCKS5代理服务 HTTP Tunnel隧道代理服务 @@ -16,6 +17,7 @@ this software support following features 4. operator log 5. encrypt Communication(planning) 6. load balanc(planning) +7. custom cert proxy protocol(planning) ## install diff --git a/README.md b/README.md index 79f3f42..99c1bc7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [中文](README.md) || [English](README.en.md) -# XEngine_MQService +# XEngine_ProxyServer 本仓库有开发和主分支,如果要使用,请使用master分支下的代码 ## 介绍 @@ -17,6 +17,7 @@ c c++ Socks5 Proxy Service HTTP Tunnel Proxy Service 4. 操作日志 5. 加密通信(planning) 6. 负载均衡(planning) +7. 自定义证书代理协议(planning) ## 安装教程 diff --git a/XEngine_Release/XEngine_Config/XEngine_Config.json b/XEngine_Release/XEngine_Config/XEngine_Config.json index dbc10ae..e327e5b 100644 --- a/XEngine_Release/XEngine_Config/XEngine_Config.json +++ b/XEngine_Release/XEngine_Config/XEngine_Config.json @@ -1,21 +1,24 @@ { - "tszIPAddr":"192.168.1.12", - "bDeamon":0, - "nSocksPort":5000, - "nTunnelPort":5001, - "XMax":{ - "nMaxClient":10000, - "nMaxQueue":10000, - "nIOThread":2 - }, - "XTime":{ - "nTimeCheck":3, - "nSocksTimeOut":5, - "nTunnelTimeOut":5 - }, - "XLog":{ - "MaxSize":1024000, - "MaxCount":10, - "LogLeave":32 - } + "tszIPAddr":"192.168.1.12", + "bDeamon":0, + "nSocksPort":5400, + "nTunnelPort":5401, + "XMax":{ + "nMaxClient":10000, + "nMaxQueue":10000, + "nIOThread":2 + }, + "XTime":{ + "nTimeCheck":3, + "nSocksTimeOut":5, + "nTunnelTimeOut":5 + }, + "XLog":{ + "MaxSize":1024000, + "MaxCount":10, + "LogLeave":32 + }, + "XSocks":{ + "nAuthType":0 + } } \ No newline at end of file -- Gitee