Skip to content

Commit f61cc32

Browse files
committed
added:hash ip mode for proxy support
1 parent e5d0920 commit f61cc32

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

XEngine_Release/XEngine_Config/XEngine_Config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"nRuleMode": 0,
3535
"tszDestIPAddr": [
3636
"127.0.0.1:5501",
37-
"127.0.0.1:5501"
37+
"118.25.14.242:5501"
3838
],
3939
"tszRuleIPAddr": [
4040
"10.0.0.1-10.0.4.69:5403",

XEngine_Source/XEngine_ModuleSession/ModuleSession_Proxy/ModuleSession_ProxyRule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ bool CModuleSession_ProxyRule::ModuleSession_ProxyRule_Set(LPCXSTR lpszIPAddr, L
144144
}
145145
}
146146
}
147-
st_Locker.unlock_shared();
147+
st_Locker.unlock();
148148
return true;
149149
}
150150
/********************************************************************

XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <thread>
1010
#include <list>
1111
#include <string>
12+
#include <functional>
1213
#ifdef _MSC_BUILD
1314
#include <Windows.h>
1415
#include <tchar.h>

XEngine_Source/XEngine_ServiceApp/XEngine_ProxyTask.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ bool XEngine_Proxy_Connect(LPCXSTR lpszClientAddr)
1919
XCHAR tszIPAddr[128] = {};
2020
XCHAR tszSrcIPAddr[128] = {};
2121
XCHAR tszDstIPAddr[128] = {};
22+
23+
_tcsxcpy(tszSrcIPAddr, lpszClientAddr);
24+
APIAddr_IPAddr_SegAddr(tszSrcIPAddr, &nSrcPort);
2225
//是否有单独的转发规则
2326
if (!st_ServiceConfig.st_XProxy.pStl_ListRuleAddr->empty())
2427
{
2528
//有规则,需要进行匹配
26-
_tcsxcpy(tszSrcIPAddr, lpszClientAddr);
27-
APIAddr_IPAddr_SegAddr(tszSrcIPAddr, &nSrcPort);
28-
2929
for (auto stl_ListIterator = st_ServiceConfig.st_XProxy.pStl_ListRuleAddr->begin(); stl_ListIterator != st_ServiceConfig.st_XProxy.pStl_ListRuleAddr->end(); stl_ListIterator++)
3030
{
3131
XCHAR tszTmpIPAddr[128] = {};
@@ -58,7 +58,14 @@ bool XEngine_Proxy_Connect(LPCXSTR lpszClientAddr)
5858
}
5959
else if (1 == st_ServiceConfig.st_XProxy.nRuleMode)
6060
{
61-
61+
size_t nHashValue = std::hash<xstring>{}(tszSrcIPAddr);
62+
size_t nIndex = nHashValue % st_ServiceConfig.st_XProxy.pStl_ListDestAddr->size();
63+
auto stl_ListIterator = st_ServiceConfig.st_XProxy.pStl_ListDestAddr->begin();
64+
std::advance(stl_ListIterator, nIndex);
65+
_tcsxcpy(tszIPAddr, stl_ListIterator->c_str());
66+
_tcsxcpy(tszDstIPAddr, stl_ListIterator->c_str());
67+
APIAddr_IPAddr_SegAddr(tszDstIPAddr, &nDstPort);
68+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Proxy客户端:%s,代理转发规则地址未命中,使用HASH规则,规则地址:%s:%d"), lpszClientAddr, tszDstIPAddr, nDstPort);
6269
}
6370
}
6471
if (!XClient_TCPSelect_InsertEx(xhProxyClient, &xhClient, tszDstIPAddr, nDstPort, false))

0 commit comments

Comments
 (0)