...
 
Commits (10)
    https://gitcode.net/xengine/XEngine_ProxyServer/-/commit/f6efc59b76aed206b6057963b706c9129589154d update:match xengine v8.15 2023-08-16T10:12:30+08:00 qyt 486179@qq.com https://gitcode.net/xengine/XEngine_ProxyServer/-/commit/a372a8bbbce9f4b6641d9de446291e3d18121bcd delete:unused protocol code 2023-08-16T10:16:03+08:00 qyt 486179@qq.com https://gitcode.net/xengine/XEngine_ProxyServer/-/commit/7df64c2535cf1135f153fe2639e2aa1f5f1ee8c6 added:insert have user info for session module 2023-08-16T10:31:19+08:00 qyt 486179@qq.com https://gitcode.net/xengine/XEngine_ProxyServer/-/commit/9900c823191d8bcb20dc57d446a3f2fa874365dc modify:Enumerating users now has more information 2023-08-16T10:56:28+08:00 qyt 486179@qq.com https://gitcode.net/xengine/XEngine_ProxyServer/-/commit/7b89a35acdb7e87d0746e65200986079f200be1a added:unbind protocol supported 2023-08-16T11:07:24+08:00 qyt 486179@qq.com https://gitcode.net/xengine/XEngine_ProxyServer/-/commit/157fb5f2939b6597bed57bde7c40082aa333af1c fixed:forward does not create packet when client login 2023-08-16T11:29:55+08:00 qyt 486179@qq.com https://gitcode.net/xengine/XEngine_ProxyServer/-/commit/22bfca1b3f49e46a817b953bc1ce355157bf743a fixed:does not delete packet res when client close 2023-08-16T13:35:34+08:00 qyt 486179@qq.com modify:does not close bind client when client close https://gitcode.net/xengine/XEngine_ProxyServer/-/commit/19b98a7466a0fae4dc14d892d4a6a07b38a02619 update:forward example 2023-08-17T09:53:54+08:00 qyt 486179@qq.com https://gitcode.net/xengine/XEngine_ProxyServer/-/commit/ed12fff88832f02931eb33a5e23378167fefe287 update:ModuleProtocol_Packet_ForwardList added new field 2023-08-17T09:54:44+08:00 qyt 486179@qq.com update:configure file https://gitcode.net/xengine/XEngine_ProxyServer/-/commit/b06f04b9f0e67c5f751247e4f8e32a8cc30699f6 update:readme and docment 2023-08-17T09:55:01+08:00 qyt 486179@qq.com
XEngine_ProxyServer V1.6.0.1001
增加:数据转发解绑协议支持
增加:数据转发为会话模块插入现在有用户信息了
更新:匹配XEngine到V8.15版本
修改:数据转发枚举用户信息现在有更多信息
修正:数据转发枚举用户列表没有释放内存的问题
修正:数据转发用户登录的时候没有创建包管理器的问题
修正:数据转发用户退出没有释放包资源的问题
删除:数据转发没有用的协议处理代码
added:unbind protocol supported
added:insert have user info for session module
update:match xengine v8.15
modify:Enumerating users now has more information
fixed:does not free memory when enum user
fixed:forward does not create packet when client login
fixed:does not delete packet res when client close
modify:does not close bind client when client close
delete:unused protocol code
======================================================================================
XEngine_ProxyServer V1.5.1.1001
更新:匹配XEngine到V8.x版本
......
......@@ -25,7 +25,7 @@ this software support following features
## install
#### XEngine Evn
you must install XEngine,need V8.10 or above,install XEngine can be refer to xengine Readme docment
you must install XEngine,need V8.15 or above,install XEngine can be refer to xengine Readme docment
GITEE:https://gitee.com/xyry/libxengine
GITHUB:https://github.com/libxengine/xengine
......
......@@ -25,7 +25,7 @@ c c++ Socks5 Proxy Service,HTTP Tunnel Proxy Service,tcp forward service
## 安装教程
#### XEngine环境
必须安装XEngine,版本需要V8.10或者以上版本,安装XEngine可以参考其Readme文档
必须安装XEngine,版本需要V8.15或者以上版本,安装XEngine可以参考其Readme文档
GITEE:https://gitee.com/xyry/libxengine
GITHUB:https://github.com/libxengine/xengine
......@@ -89,6 +89,9 @@ make FLAGS=CleanAll 清理编译
透传代理
转发代理支持权限和确认
支持加密代理
转发代理绑定解绑支持附加用户信息
转发代理绑定支持拒绝
转发代理支持用户验证
## 关注我们
如果你觉得这个软件对你有帮助,请你给我们一个START吧
......
......@@ -45,20 +45,31 @@ int main(int argc, char** argv)
int nMsgLen = 0;
XENGINE_PROTOCOLHDR st_ProtocolHdr;
XENGINE_PROTOCOL_USERAUTH st_UserAuth;
memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR));
memset(&st_UserAuth, '\0', sizeof(XENGINE_PROTOCOL_USERAUTH));
//登录
st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER;
st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL;
st_ProtocolHdr.byIsReply = true;
st_ProtocolHdr.byVersion = 0;
st_ProtocolHdr.unPacketSize = sizeof(XENGINE_PROTOCOL_USERAUTH);
st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_AUTH;
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LOGREQ;
_tcsxcpy(st_UserAuth.tszUserName, "test");
if (!XClient_TCPSelect_SendMsg(m_Socket, (LPCXSTR)&st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR)))
{
printf("发送失败!\n");
return 0;
}
if (!XClient_TCPSelect_SendMsg(m_Socket, (LPCXSTR)&st_UserAuth, sizeof(XENGINE_PROTOCOL_USERAUTH)))
{
printf("发送失败!\n");
return 0;
}
nMsgLen = 0;
XCHAR* ptszMsgBuffer = NULL;
......@@ -104,7 +115,7 @@ int main(int argc, char** argv)
//请求绑定
Json::Value st_JsonRoot;
Json::Value st_JsonArray = st_JsonAddr["Array"];
st_JsonRoot["tszDstAddr"] = st_JsonArray[0].asCString();
st_JsonRoot["tszDstAddr"] = st_JsonArray[0]["tszSrcAddr"].asCString();
st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER;
st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL;
......@@ -172,7 +183,7 @@ int main(int argc, char** argv)
}
}
std::this_thread::sleep_for(std::chrono::seconds(5000));
std::this_thread::sleep_for(std::chrono::seconds(20000));
XClient_TCPSelect_Close(m_Socket);
#ifdef _MSC_BUILD
WSACleanup();
......
......@@ -78,7 +78,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
......
......@@ -14,19 +14,20 @@
"nTimeCheck": 3,
"nSocksTimeOut": 5,
"nTunnelTimeOut": 5,
"nForwardTimeOut": 5
"nForwardTimeOut": 0
},
"XLog": {
"MaxSize": 1024000,
"MaxCount": 10,
"LogLeave": 32,
"tszLogFile": "./XEngine_Log/XEngine_ServiceApp.log"
"tszLogFile": "./XEngine_Log/XEngine_ProxyServiceApp.log"
},
"XAuth": {
"bAuth": 0,
"tszAuthFile": "./XEngine_Config/UserList.txt"
},
"XVer": [
"1.6.0.1001 Build20230817",
"1.5.1.1001 Build20230426",
"1.5.0.1001 Build20230202",
"1.4.0.1001 Build20221111",
......
......@@ -35,7 +35,7 @@ extern "C" XLONG ModuleProtocol_GetLastError(int* pInt_SysError = NULL);
类型:协议头
可空:N
意思:输入请求的头
参数.四:ppptszListAddr
参数.四:pppSt_ListUser
In/Out:In
类型:三级指针
可空:N
......@@ -50,7 +50,7 @@ extern "C" XLONG ModuleProtocol_GetLastError(int* pInt_SysError = NULL);
意思:是否成功
备注:
*********************************************************************/
extern "C" bool ModuleProtocol_Packet_ForwardList(XCHAR* ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XCHAR*** ppptszListAddr, int nCount);
extern "C" bool ModuleProtocol_Packet_ForwardList(XCHAR* ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, SESSION_FORWARD * **pppSt_ListUser, int nCount);
/************************************************************************/
/* 解析导出函数 */
/************************************************************************/
......
......@@ -40,7 +40,7 @@ CModuleProtocol_Packet::~CModuleProtocol_Packet()
类型:协议头
可空:N
意思:输入请求的头
参数.四:ppptszListAddr
参数.四:pppSt_ListUser
In/Out:In
类型:三级指针
可空:N
......@@ -55,7 +55,7 @@ CModuleProtocol_Packet::~CModuleProtocol_Packet()
意思:是否成功
备注:
*********************************************************************/
bool CModuleProtocol_Packet::ModuleProtocol_Packet_ForwardList(XCHAR* ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XCHAR*** ppptszListAddr, int nCount)
bool CModuleProtocol_Packet::ModuleProtocol_Packet_ForwardList(XCHAR* ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, SESSION_FORWARD*** pppSt_ListUser, int nCount)
{
Protocol_IsErrorOccur = false;
......@@ -70,7 +70,20 @@ bool CModuleProtocol_Packet::ModuleProtocol_Packet_ForwardList(XCHAR* ptszMsgBuf
for (int i = 0; i < nCount; i++)
{
st_JsonArray[i] = (*ppptszListAddr)[i];
Json::Value st_JsonObject;
Json::Value st_JsonSub;
st_JsonObject["bForward"] = (*pppSt_ListUser)[i]->bForward;
st_JsonObject["tszSrcAddr"] = (*pppSt_ListUser)[i]->tszSrcAddr;
st_JsonObject["tszDstAddr"] = (*pppSt_ListUser)[i]->tszDstAddr;
st_JsonSub["tszUserName"] = (*pppSt_ListUser)[i]->st_UserAuth.tszUserName;
st_JsonSub["tszUserPass"] = (*pppSt_ListUser)[i]->st_UserAuth.tszUserPass;
st_JsonSub["tszDCode"] = (*pppSt_ListUser)[i]->st_UserAuth.tszDCode;
st_JsonSub["enClientType"] = (*pppSt_ListUser)[i]->st_UserAuth.enClientType;
st_JsonSub["enDeviceType"] = (*pppSt_ListUser)[i]->st_UserAuth.enDeviceType;
st_JsonObject["st_UserAuth"] = st_JsonSub;
st_JsonArray.append(st_JsonObject);
}
st_JsonRoot["Count"] = nCount;
st_JsonRoot["Array"] = st_JsonArray;
......
......@@ -17,6 +17,6 @@ public:
CModuleProtocol_Packet();
~CModuleProtocol_Packet();
public:
bool ModuleProtocol_Packet_ForwardList(XCHAR* ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XCHAR*** ppptszListAddr, int nCount);
bool ModuleProtocol_Packet_ForwardList(XCHAR* ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, SESSION_FORWARD*** pppSt_ListUser, int nCount);
private:
};
\ No newline at end of file
......@@ -31,9 +31,9 @@ extern "C" XLONG ModuleProtocol_GetLastError(int* pInt_SysError)
/************************************************************************/
/* 封包导出函数 */
/************************************************************************/
extern "C" bool ModuleProtocol_Packet_ForwardList(XCHAR * ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, XCHAR * **ppptszListAddr, int nCount)
extern "C" bool ModuleProtocol_Packet_ForwardList(XCHAR * ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, SESSION_FORWARD * **pppSt_ListUser, int nCount)
{
return m_ProtocolPacket.ModuleProtocol_Packet_ForwardList(ptszMsgBuffer, pInt_Len, pSt_ProtocolHdr, ppptszListAddr, nCount);
return m_ProtocolPacket.ModuleProtocol_Packet_ForwardList(ptszMsgBuffer, pInt_Len, pSt_ProtocolHdr, pppSt_ListUser, nCount);
}
/************************************************************************/
/* 解析导出函数 */
......
......@@ -22,6 +22,7 @@ using namespace std;
#include <XEngine_Include/XEngine_Types.h>
#include <XEngine_Include/XEngine_ProtocolHdr.h>
#include "../XEngine_UserProtocol.h"
#include "../XEngine_ModuleSession/ModuleSession_Define.h"
#include "ModuleProtocol_Define.h"
#include "ModuleProtocol_Error.h"
/********************************************************************
......
......@@ -10,6 +10,13 @@
// Purpose: 导出定义
// History:
*********************************************************************/
typedef struct
{
XENGINE_PROTOCOL_USERAUTH st_UserAuth;
XCHAR tszSrcAddr[128];
XCHAR tszDstAddr[128];
bool bForward;
}SESSION_FORWARD, * LPSESSION_FORWARD;
//////////////////////////////////////////////////////////////////////////
// 导出函数
//////////////////////////////////////////////////////////////////////////
......@@ -25,16 +32,21 @@ extern "C" XLONG ModuleSession_GetLastError(int* pInt_SysError = NULL);
类型:常量字符指针
可空:N
意思:输入要插入的客户端
参数.二:pSt_UserAuth
In/Out:In
类型:数据结构指针
可空:N
意思:输入要保存的客户端附加数据
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
extern "C" bool ModuleSession_Forward_Insert(LPCXSTR lpszAddr);
extern "C" bool ModuleSession_Forward_Insert(LPCXSTR lpszAddr, XENGINE_PROTOCOL_USERAUTH * pSt_UserAuth);
/********************************************************************
函数名称:ModuleSession_Forward_List
函数功能:获取列表
参数.一:ppptszListAddr
参数.一:pppSt_ListUser
In/Out:Out
类型:三级指针
可空:N
......@@ -54,7 +66,7 @@ extern "C" bool ModuleSession_Forward_Insert(LPCXSTR lpszAddr);
意思:是否成功
备注:
*********************************************************************/
extern "C" bool ModuleSession_Forward_List(XCHAR*** ppptszListAddr, int* pInt_Count, LPCXSTR lpszAddr = NULL);
extern "C" bool ModuleSession_Forward_List(SESSION_FORWARD * **pppSt_ListUser, int* pInt_Count, LPCXSTR lpszAddr = NULL);
/********************************************************************
函数名称:ModuleSession_Forward_Bind
函数功能:绑定转发需求
......@@ -75,6 +87,25 @@ extern "C" bool ModuleSession_Forward_List(XCHAR*** ppptszListAddr, int* pInt_Co
*********************************************************************/
extern "C" bool ModuleSession_Forward_Bind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr);
/********************************************************************
函数名称:ModuleSession_Forward_UNBind
函数功能:解除绑定转发需求
参数.一:lpszSrcAddr
In/Out:In
类型:常量字符指针
可空:N
意思:输入绑定的原始地址
参数.二:lpszDstAddr
In/Out:In
类型:常量字符指针
可空:N
意思:输出绑定的目标地址
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
extern "C" bool ModuleSession_Forward_UNBind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr);
/********************************************************************
函数名称:ModuleSession_Forward_Delete
函数功能:删除用户
参数.一:lpszAddr
......@@ -85,14 +116,14 @@ extern "C" bool ModuleSession_Forward_Bind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstA
参数.二:ptszDstAddr
In/Out:Out
类型:字符指针
可空:N
可空:Y
意思:输出解绑的地址
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
extern "C" bool ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHAR * ptszDstAddr);
extern "C" bool ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHAR * ptszDstAddr = NULL);
/********************************************************************
函数名称:ModuleSession_Forward_Get
函数功能:获取转发用户给
......
......@@ -30,12 +30,17 @@ CModuleSession_Forward::~CModuleSession_Forward()
类型:常量字符指针
可空:N
意思:输入要插入的客户端
参数.二:pSt_UserAuth
In/Out:In
类型:数据结构指针
可空:N
意思:输入要保存的客户端附加数据
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
bool CModuleSession_Forward::ModuleSession_Forward_Insert(LPCXSTR lpszAddr)
bool CModuleSession_Forward::ModuleSession_Forward_Insert(LPCXSTR lpszAddr, XENGINE_PROTOCOL_USERAUTH* pSt_UserAuth)
{
Session_IsErrorOccur = false;
......@@ -49,6 +54,7 @@ bool CModuleSession_Forward::ModuleSession_Forward_Insert(LPCXSTR lpszAddr)
memset(&st_Forward, '\0', sizeof(SESSION_FORWARD));
_tcsxcpy(st_Forward.tszSrcAddr, lpszAddr);
memcpy(&st_Forward.st_UserAuth, pSt_UserAuth, sizeof(XENGINE_PROTOCOL_USERAUTH));
st_Locker.lock();
unordered_map<tstring, SESSION_FORWARD>::const_iterator stl_MapIterator = stl_MapSession.find(lpszAddr);
......@@ -86,7 +92,7 @@ bool CModuleSession_Forward::ModuleSession_Forward_Insert(LPCXSTR lpszAddr)
意思:是否成功
备注:
*********************************************************************/
bool CModuleSession_Forward::ModuleSession_Forward_List(XCHAR*** ppptszListAddr, int* pInt_Count, LPCXSTR lpszAddr)
bool CModuleSession_Forward::ModuleSession_Forward_List(SESSION_FORWARD*** pppSt_ListUser, int* pInt_Count, LPCXSTR lpszAddr /* = NULL */)
{
Session_IsErrorOccur = false;
......@@ -106,7 +112,7 @@ bool CModuleSession_Forward::ModuleSession_Forward_List(XCHAR*** ppptszListAddr,
{
*pInt_Count = stl_MapSession.size() - 1; //减去自己
}
BaseLib_OperatorMemory_Malloc((XPPPMEM)ppptszListAddr, *pInt_Count, 128);
BaseLib_OperatorMemory_Malloc((XPPPMEM)pppSt_ListUser, *pInt_Count, sizeof(SESSION_FORWARD));
//遍历
auto stl_MapIterator = stl_MapSession.begin();
for (int i = 0; stl_MapIterator != stl_MapSession.end(); stl_MapIterator++, i++)
......@@ -118,7 +124,7 @@ bool CModuleSession_Forward::ModuleSession_Forward_List(XCHAR*** ppptszListAddr,
continue;
}
}
_tcsxcpy((*ppptszListAddr)[i], stl_MapIterator->first.c_str());
*(*pppSt_ListUser)[i] = stl_MapIterator->second;
}
st_Locker.unlock_shared();
return true;
......@@ -180,6 +186,54 @@ bool CModuleSession_Forward::ModuleSession_Forward_Bind(LPCXSTR lpszSrcAddr, LPC
return true;
}
/********************************************************************
函数名称:ModuleSession_Forward_UNBind
函数功能:解除绑定转发需求
参数.一:lpszSrcAddr
In/Out:In
类型:常量字符指针
可空:N
意思:输入绑定的原始地址
参数.二:lpszDstAddr
In/Out:In
类型:常量字符指针
可空:N
意思:输出绑定的目标地址
返回值
类型:逻辑型
意思:是否成功
备注:
*********************************************************************/
bool CModuleSession_Forward::ModuleSession_Forward_UNBind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr)
{
Session_IsErrorOccur = false;
if ((NULL == lpszSrcAddr) || (NULL == lpszDstAddr))
{
Session_IsErrorOccur = true;
Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_PARAMENT;
return false;
}
st_Locker.lock_shared();
//查找
auto stl_MapSrcIterator = stl_MapSession.find(lpszSrcAddr);
auto stl_MapDstIterator = stl_MapSession.find(lpszDstAddr);
if (stl_MapSrcIterator == stl_MapSession.end() || stl_MapDstIterator == stl_MapSession.end())
{
Session_IsErrorOccur = true;
Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_NOTFOUND;
st_Locker.unlock_shared();
return false;
}
//解除双方绑定
stl_MapSrcIterator->second.bForward = false;
memset(stl_MapSrcIterator->second.tszDstAddr, '\0', sizeof(stl_MapSrcIterator->second.tszDstAddr));
stl_MapDstIterator->second.bForward = false;
memset(stl_MapDstIterator->second.tszDstAddr, '\0', sizeof(stl_MapDstIterator->second.tszDstAddr));
st_Locker.unlock_shared();
return true;
}
/********************************************************************
函数名称:ModuleSession_Forward_Delete
函数功能:删除用户
参数.一:lpszAddr
......@@ -190,7 +244,7 @@ bool CModuleSession_Forward::ModuleSession_Forward_Bind(LPCXSTR lpszSrcAddr, LPC
参数.二:ptszDstAddr
In/Out:Out
类型:字符指针
可空:N
可空:Y
意思:输出解绑的地址
返回值
类型:逻辑型
......@@ -220,7 +274,11 @@ bool CModuleSession_Forward::ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHA
//如果有转发,需要清理对方的转发设置
if (stl_MapSrcIterator->second.bForward)
{
_tcsxcpy(ptszDstAddr, stl_MapSrcIterator->second.tszDstAddr);
if (NULL != ptszDstAddr)
{
_tcsxcpy(ptszDstAddr, stl_MapSrcIterator->second.tszDstAddr);
}
auto stl_MapDstIterator = stl_MapSession.find(stl_MapSrcIterator->second.tszSrcAddr);
if (stl_MapDstIterator == stl_MapSession.end())
{
......
......@@ -10,12 +10,6 @@
// Purpose: 会话转发协议
// History:
*********************************************************************/
typedef struct
{
XCHAR tszSrcAddr[128];
XCHAR tszDstAddr[128];
bool bForward;
}SESSION_FORWARD, * LPSESSION_FORWARD;
class CModuleSession_Forward
{
......@@ -23,10 +17,11 @@ public:
CModuleSession_Forward();
~CModuleSession_Forward();
public:
bool ModuleSession_Forward_Insert(LPCXSTR lpszAddr);
bool ModuleSession_Forward_List(XCHAR*** ppptszListAddr, int* pInt_Count, LPCXSTR lpszAddr = NULL);
bool ModuleSession_Forward_Insert(LPCXSTR lpszAddr, XENGINE_PROTOCOL_USERAUTH* pSt_UserAuth);
bool ModuleSession_Forward_List(SESSION_FORWARD*** pppSt_ListUser, int* pInt_Count, LPCXSTR lpszAddr = NULL);
bool ModuleSession_Forward_Bind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr);
bool ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHAR* ptszDstAddr);
bool ModuleSession_Forward_UNBind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr);
bool ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHAR* ptszDstAddr = NULL);
bool ModuleSession_Forward_Get(LPCXSTR lpszAddr, XCHAR* ptszDstAddr);
private:
shared_mutex st_Locker;
......
......@@ -6,5 +6,6 @@ EXPORTS
ModuleSession_Forward_Insert
ModuleSession_Forward_List
ModuleSession_Forward_Bind
ModuleSession_Forward_UNBind
ModuleSession_Forward_Delete
ModuleSession_Forward_Get
\ No newline at end of file
......@@ -29,18 +29,22 @@ extern "C" XLONG ModuleSession_GetLastError(int* pInt_SysError)
/************************************************************************/
/* 转发导出函数 */
/************************************************************************/
extern "C" bool ModuleSession_Forward_Insert(LPCXSTR lpszAddr)
extern "C" bool ModuleSession_Forward_Insert(LPCXSTR lpszAddr, XENGINE_PROTOCOL_USERAUTH * pSt_UserAuth)
{
return m_Forward.ModuleSession_Forward_Insert(lpszAddr);
return m_Forward.ModuleSession_Forward_Insert(lpszAddr, pSt_UserAuth);
}
extern "C" bool ModuleSession_Forward_List(XCHAR * **ppptszListAddr, int* pInt_Count, LPCXSTR lpszAddr)
extern "C" bool ModuleSession_Forward_List(SESSION_FORWARD * **pppSt_ListUser, int* pInt_Count, LPCXSTR lpszAddr)
{
return m_Forward.ModuleSession_Forward_List(ppptszListAddr, pInt_Count, lpszAddr);
return m_Forward.ModuleSession_Forward_List(pppSt_ListUser, pInt_Count, lpszAddr);
}
extern "C" bool ModuleSession_Forward_Bind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr)
{
return m_Forward.ModuleSession_Forward_Bind(lpszSrcAddr, lpszDstAddr);
}
extern "C" bool ModuleSession_Forward_UNBind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr)
{
return m_Forward.ModuleSession_Forward_UNBind(lpszSrcAddr, lpszDstAddr);
}
extern "C" bool ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHAR * ptszDstAddr)
{
return m_Forward.ModuleSession_Forward_Delete(lpszAddr, ptszDstAddr);
......
......@@ -20,6 +20,7 @@
using namespace std;
#include <XEngine_Include/XEngine_CommHdr.h>
#include <XEngine_Include/XEngine_Types.h>
#include <XEngine_Include/XEngine_ProtocolHdr.h>
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Define.h>
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Error.h>
#include "ModuleSession_Define.h"
......
......@@ -22,7 +22,7 @@ XHTHREAD CALLBACK XEngine_Forward_Thread(XPVOID lParam)
continue;
}
int nListCount = 0;
HELPCOMPONENT_PACKET_CLIENT** ppSt_ListClient;
XENGINE_MANAGEPOOL_TASKEVENT** ppSt_ListClient;
HelpComponents_Datas_GetPoolEx(xhForwardPacket, nThreadPos, &ppSt_ListClient, &nListCount);
for (int i = 0; i < nListCount; i++)
{
......@@ -47,21 +47,22 @@ bool XEngine_Forward_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int n
int nSDLen = 10240;
XCHAR tszSDBuffer[10240];
memset(tszSDBuffer, '\0', sizeof(tszSDBuffer));
//判断协议头和尾部
if ((XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER != pSt_ProtocolHdr->wHeader) || (XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL != pSt_ProtocolHdr->wTail))
{
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("Forward客户端:%s,协议错误"), lpszClientAddr);
return false;
}
//处理验证协议
if (ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_AUTH == pSt_ProtocolHdr->unOperatorType)
{
if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LOGREQ == pSt_ProtocolHdr->unOperatorCode)
{
XENGINE_PROTOCOL_USERAUTH st_UserAuth;
memset(&st_UserAuth, '\0', sizeof(XENGINE_PROTOCOL_USERAUTH));
memcpy(&st_UserAuth, lpszMsgBuffer, sizeof(XENGINE_PROTOCOL_USERAUTH));
pSt_ProtocolHdr->wReserve = 0;
pSt_ProtocolHdr->unPacketSize = 0;
pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LOGREP;
ModuleSession_Forward_Insert(lpszClientAddr);
ModuleSession_Forward_Insert(lpszClientAddr, &st_UserAuth);
XEngine_Network_Send(lpszClientAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,登录到服务器"), lpszClientAddr);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,设置的用户:%s,登录到服务器"), lpszClientAddr, st_UserAuth.tszUserName);
}
}
//处理转发协议
......@@ -70,12 +71,13 @@ bool XEngine_Forward_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int n
if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LISTREQ == pSt_ProtocolHdr->unOperatorCode)
{
int nListCount = 0;
XCHAR** pptszListAddr;
SESSION_FORWARD** ppSt_ListUser;
pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LISTREP;
if (ModuleSession_Forward_List(&pptszListAddr, &nListCount, lpszClientAddr))
if (ModuleSession_Forward_List(&ppSt_ListUser, &nListCount, lpszClientAddr))
{
ModuleProtocol_Packet_ForwardList(tszSDBuffer, &nSDLen, pSt_ProtocolHdr, &pptszListAddr, nListCount);
ModuleProtocol_Packet_ForwardList(tszSDBuffer, &nSDLen, pSt_ProtocolHdr, &ppSt_ListUser, nListCount);
BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListUser, nListCount);
XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_CLIENT_NETTYPE_FORWARD);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,请求可用转发列表成功"), lpszClientAddr);
}
......@@ -113,6 +115,38 @@ bool XEngine_Forward_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int n
XEngine_Network_Send(lpszClientAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,请求绑定转发地址:%s 成功"), lpszClientAddr, tszDstAddr);
}
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_UNREQ == pSt_ProtocolHdr->unOperatorCode)
{
XCHAR tszDstAddr[128];
memset(tszDstAddr, '\0', sizeof(tszDstAddr));
if (!ModuleSession_Forward_Get(lpszClientAddr, tszDstAddr))
{
pSt_ProtocolHdr->wReserve = 411;
pSt_ProtocolHdr->unPacketSize = 0;
pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_UNREP;
XEngine_Network_Send(lpszClientAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("Forward客户端:%s,请求解绑失败,错误:%lX"), lpszClientAddr, ModuleSession_GetLastError());
return false;
}
if (!ModuleSession_Forward_UNBind(lpszClientAddr, tszDstAddr))
{
pSt_ProtocolHdr->wReserve = 411;
pSt_ProtocolHdr->unPacketSize = 0;
pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_UNREP;
XEngine_Network_Send(lpszClientAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("Forward客户端:%s,请求解绑失败,解除绑定的地址:%s,错误:%lX"), lpszClientAddr, tszDstAddr, ModuleSession_GetLastError());
return false;
}
//先告知对方要转发数据
pSt_ProtocolHdr->wReserve = 0;
pSt_ProtocolHdr->unPacketSize = 0;
XEngine_Network_Send(tszDstAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD);
//最后返回结果
pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_UNREP;
XEngine_Network_Send(lpszClientAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,请求解绑转发地址:%s 成功"), lpszClientAddr, tszDstAddr);
}
}
return true;
......
......@@ -61,6 +61,7 @@ void CALLBACK Network_Callback_TunnelHeart(LPCXSTR lpszClientAddr, XSOCKET hSock
//////////////////////////////////////////////////////////////////////////下面是Tunnel网络IO相关代码处理函数
bool CALLBACK Network_Callback_ForwardLogin(LPCXSTR lpszClientAddr, XSOCKET hSocket, XPVOID lParam)
{
HelpComponents_Datas_CreateEx(xhForwardPacket, lpszClientAddr);
SocketOpt_HeartBeat_InsertAddrEx(xhForwardHeart, lpszClientAddr);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,连接到服务器"), lpszClientAddr);
return true;
......@@ -177,14 +178,8 @@ void XEngine_Network_Close(LPCXSTR lpszClientAddr, int nIPProto, int nCloseType)
SocketOpt_HeartBeat_DeleteAddrEx(xhForwardHeart, lpszClientAddr);
NetCore_TCPXCore_CloseForClientEx(xhForwardSocket, lpszClientAddr);
}
XCHAR tszClientAddr[128];
memset(tszClientAddr, '\0', sizeof(tszClientAddr));
ModuleSession_Forward_Delete(lpszClientAddr, tszClientAddr);
if (_tcsxlen(tszClientAddr) > 0)
{
XEngine_Network_Close(tszClientAddr, XENGINE_CLIENT_NETTYPE_FORWARD, XENGINE_CLIENT_CLOSE_SERVICE);
}
HelpComponents_Datas_DeleteEx(xhForwardPacket, lpszClientAddr);
ModuleSession_Forward_Delete(lpszClientAddr);
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,离开服务器,离开类型;%d"), lpszClientAddr, nCloseType);
}
else
......