Feature: Support HTTP protocol and add building option
This commit is contained in:
@@ -143,6 +143,14 @@ ULONG CBuffer::GetBufferLength() const
|
||||
}
|
||||
|
||||
|
||||
void CBuffer::Skip(ULONG ulPos) {
|
||||
if (ulPos == 0)
|
||||
return;
|
||||
MoveMemory(m_Base, m_Base + ulPos, m_ulMaxLength - ulPos);
|
||||
m_Ptr -= ulPos;
|
||||
}
|
||||
|
||||
|
||||
PBYTE CBuffer::GetBuffer(ULONG ulPos) const
|
||||
{
|
||||
if (m_Base==NULL || ulPos>=(m_Ptr - m_Base))
|
||||
|
||||
@@ -15,6 +15,7 @@ public:
|
||||
BOOL ReAllocateBuffer(ULONG ulLength);
|
||||
BOOL WriteBuffer(PBYTE Buffer, ULONG ulLength);
|
||||
PBYTE GetBuffer(ULONG ulPos=0) const;
|
||||
void Skip(ULONG ulPos);
|
||||
|
||||
protected:
|
||||
PBYTE m_Base;
|
||||
|
||||
@@ -96,11 +96,12 @@ VOID IOCPClient::setManagerCallBack(void* Manager, DataProcessCB dataProcess)
|
||||
}
|
||||
|
||||
|
||||
IOCPClient::IOCPClient(State&bExit, bool exit_while_disconnect) : g_bExit(bExit)
|
||||
IOCPClient::IOCPClient(State&bExit, bool exit_while_disconnect, int mask) : g_bExit(bExit)
|
||||
{
|
||||
m_ServerAddr = {};
|
||||
m_nHostPort = 0;
|
||||
m_Manager = NULL;
|
||||
m_masker = mask ? new HttpMask("example.com") : new PkgMask();
|
||||
#ifdef _WIN32
|
||||
WSADATA wsaData;
|
||||
WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
@@ -147,6 +148,7 @@ IOCPClient::~IOCPClient()
|
||||
ZSTD_freeCCtx(m_Cctx);
|
||||
ZSTD_freeDCtx(m_Dctx);
|
||||
#endif
|
||||
m_masker->Destroy();
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡIP<49><50>ַ
|
||||
@@ -196,6 +198,7 @@ BOOL IOCPClient::ConnectServer(const char* szServerIP, unsigned short uPort)
|
||||
SetServerAddress(szServerIP, uPort);
|
||||
}
|
||||
m_sCurIP = m_Domain.SelectIP();
|
||||
m_masker->SetServer(m_sCurIP.c_str());
|
||||
unsigned short port = m_nHostPort;
|
||||
|
||||
m_sClientSocket = socket(AF_INET,SOCK_STREAM, IPPROTO_TCP); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@@ -362,8 +365,16 @@ VOID IOCPClient::OnServerReceiving(char* szBuffer, ULONG ulLength)
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>С <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǾͲ<C7BE><CDB2><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
while (m_CompressedBuffer.GetBufferLength() > HDR_LENGTH)
|
||||
{
|
||||
// UnMask
|
||||
char* src = (char*)m_CompressedBuffer.GetBuffer();
|
||||
ULONG srcSize = m_CompressedBuffer.GetBufferLength();
|
||||
ULONG ret = m_masker->UnMask(src, srcSize);
|
||||
m_CompressedBuffer.Skip(ret);
|
||||
if (m_CompressedBuffer.GetBufferLength() <= HDR_LENGTH)
|
||||
break;
|
||||
|
||||
char szPacketFlag[FLAG_LENGTH + 3] = {0};
|
||||
LPBYTE src = m_CompressedBuffer.GetBuffer();
|
||||
src = (char*)m_CompressedBuffer.GetBuffer();
|
||||
CopyMemory(szPacketFlag, src, FLAG_LENGTH);
|
||||
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>ͷ
|
||||
if (memcmp(m_szPacketFlag, szPacketFlag, FLAG_LENGTH) != 0)
|
||||
@@ -431,6 +442,7 @@ BOOL IOCPClient::OnServerSending(const char* szBuffer, ULONG ulOriginalLength)
|
||||
AUTO_TICK(50);
|
||||
assert (ulOriginalLength > 0);
|
||||
{
|
||||
int cmd = BYTE(szBuffer[0]);
|
||||
//<2F><><EFBFBD><EFBFBD>1.001<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>õ<EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> +12
|
||||
//<2F><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>// HelloWorld 10 22
|
||||
//<2F><><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9> ѹ<><D1B9><EFBFBD>㷨 <><CEA2><EFBFBD>ṩ
|
||||
@@ -470,14 +482,22 @@ BOOL IOCPClient::OnServerSending(const char* szBuffer, ULONG ulOriginalLength)
|
||||
if (CompressedBuffer != buf) delete [] CompressedBuffer;
|
||||
|
||||
// <20>ֿ鷢<D6BF><E9B7A2>
|
||||
return SendWithSplit((char*)m_WriteBuffer.GetBuffer(), m_WriteBuffer.GetBufferLength(), MAX_SEND_BUFFER);
|
||||
return SendWithSplit((char*)m_WriteBuffer.GetBuffer(), m_WriteBuffer.GetBufferLength(), MAX_SEND_BUFFER, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
// 5 2 // 2 2 1
|
||||
BOOL IOCPClient::SendWithSplit(const char* szBuffer, ULONG ulLength, ULONG ulSplitLength)
|
||||
BOOL IOCPClient::SendWithSplit(const char* src, ULONG srcSize, ULONG ulSplitLength, int cmd)
|
||||
{
|
||||
if (src == nullptr || srcSize == 0 || ulSplitLength == 0)
|
||||
return FALSE;
|
||||
// Mask
|
||||
char* szBuffer = nullptr;
|
||||
ULONG ulLength = 0;
|
||||
m_masker->Mask(szBuffer, ulLength, (char*)src, srcSize, cmd);
|
||||
|
||||
AUTO_TICK(25);
|
||||
bool isFail = false;
|
||||
int iReturn = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD><CBB6><EFBFBD>
|
||||
const char* Travel = szBuffer;
|
||||
int i = 0;
|
||||
@@ -497,14 +517,15 @@ BOOL IOCPClient::SendWithSplit(const char* szBuffer, ULONG ulLength, ULONG ulSpl
|
||||
}
|
||||
if (j == ulSendRetry)
|
||||
{
|
||||
return FALSE;
|
||||
isFail = true;
|
||||
break;
|
||||
}
|
||||
|
||||
ulSended += iReturn;
|
||||
Travel += ulSplitLength;
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
|
||||
if (i>0) //1024
|
||||
if (!isFail && i>0) //1024
|
||||
{
|
||||
int j = 0;
|
||||
for (; j < ulSendRetry; j++)
|
||||
@@ -518,10 +539,15 @@ BOOL IOCPClient::SendWithSplit(const char* szBuffer, ULONG ulLength, ULONG ulSpl
|
||||
}
|
||||
if (j == ulSendRetry)
|
||||
{
|
||||
return FALSE;
|
||||
isFail = true;
|
||||
}
|
||||
ulSended += iReturn;
|
||||
}
|
||||
if (szBuffer != src)
|
||||
SAFE_DELETE_ARRAY(szBuffer);
|
||||
if (isFail) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return (ulSended == ulLength) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#endif
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "common/commands.h"
|
||||
#include "zstd/zstd.h"
|
||||
#include "domain_pool.h"
|
||||
#include "common/mask.h"
|
||||
|
||||
#define MAX_RECV_BUFFER 1024*32
|
||||
#define MAX_SEND_BUFFER 1024*32
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
class IOCPClient
|
||||
{
|
||||
public:
|
||||
IOCPClient(State& bExit, bool exit_while_disconnect = false);
|
||||
IOCPClient(State& bExit, bool exit_while_disconnect = false, int mask=0);
|
||||
virtual ~IOCPClient();
|
||||
|
||||
int SendLoginInfo(const LOGIN_INFOR& logInfo) {
|
||||
@@ -110,7 +110,7 @@ protected:
|
||||
BOOL OnServerSending(const char* szBuffer, ULONG ulOriginalLength);
|
||||
static DWORD WINAPI WorkThreadProc(LPVOID lParam);
|
||||
VOID OnServerReceiving(char* szBuffer, ULONG ulReceivedLength);
|
||||
BOOL SendWithSplit(const char* szBuffer, ULONG ulLength, ULONG ulSplitLength);
|
||||
BOOL SendWithSplit(const char* src, ULONG srcSize, ULONG ulSplitLength, int cmd);
|
||||
|
||||
protected:
|
||||
sockaddr_in m_ServerAddr;
|
||||
@@ -134,4 +134,5 @@ protected:
|
||||
std::string m_sCurIP;
|
||||
int m_nHostPort;
|
||||
bool m_exit_while_disconnect;
|
||||
PkgMask* m_masker;
|
||||
};
|
||||
|
||||
@@ -21,7 +21,8 @@ IOCPClient* NewNetClient(CONNECT_ADDRESS* conn, State& bExit, bool exit_while_di
|
||||
return new IOCPClient(bExit, exit_while_disconnect);
|
||||
if (conn->protoType == PROTO_UDP)
|
||||
return new IOCPUDPClient(bExit, exit_while_disconnect);
|
||||
|
||||
if (conn->protoType == PROTO_HTTP)
|
||||
return new IOCPClient(bExit, exit_while_disconnect, MaskTypeHTTP);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -201,6 +201,7 @@
|
||||
<ClCompile Include="X264Encoder.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\common\mask.h" />
|
||||
<ClInclude Include="..\server\2015Remote\pwd_gen.h" />
|
||||
<ClInclude Include="Audio.h" />
|
||||
<ClInclude Include="AudioManager.h" />
|
||||
|
||||
Reference in New Issue
Block a user