Skip to content

Commit 551e838

Browse files
committed
fixed:stun message reply is incorrect
1 parent a21057c commit 551e838

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

XEngine_Source/XEngine_ServiceApp/XEngine_StreamMediaApp/StreamMedia_PullStream/PullStream_ClientWebRtc.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ bool PullStream_ClientProtocol_Stun(LPCXSTR lpszMSGBuffer, int nMSGLen)
2222
}
2323
bool PullStream_ClientProtocol_Handle(LPCXSTR lpszClientAddr, XSOCKET hSocket, LPCXSTR lpszMsgBuffer, int nMsgLen)
2424
{
25+
int nRVLen = 0;
26+
int nSDLen = 0;
27+
XCHAR tszRVBuffer[1024] = {};
28+
XCHAR tszSDBuffer[1024] = {};
29+
2530
if (PullStream_ClientProtocol_Dtls(lpszMsgBuffer, nMsgLen))
2631
{
27-
int nSDLen = 2048;
28-
XCHAR tszSDBuffer[2048] = {};
2932
XBYTE tszSDKey[128] = {};
3033
XBYTE tszRVKey[128] = {};
3134

@@ -63,22 +66,22 @@ bool PullStream_ClientProtocol_Handle(LPCXSTR lpszClientAddr, XSOCKET hSocket, L
6366
memcpy(tszUserStr, ppSt_ListAttr[i]->tszMsgBuffer, ppSt_ListAttr[i]->wLen);
6467
}
6568
}
66-
int nTMPLen = 0;
67-
int nMSGLen = 0;
68-
XCHAR tszTMPBuffer[1024] = {};
69-
XCHAR tszMSGBuffer[1024] = {};
7069
XCHAR tszICEPass[MAX_PATH] = {};
7170

7271
ModuleSession_PullStream_RTCGet(tszUserStr, NULL, NULL, tszICEPass);
7372

74-
NatProtocol_StunNat_BuildAttr(tszTMPBuffer, &nTMPLen, RFCCOMPONENTS_NATCLIENT_PROTOCOL_STUN_ATTR_USERNAME, tszUserStr, _tcsxlen(tszUserStr));
75-
NatProtocol_StunNat_BuildMapAddress(tszTMPBuffer + nTMPLen, &nTMPLen, st_ServiceConfig.tszIPAddr, st_ServiceConfig.nRTCPort, true);
76-
//NatProtocol_StunNat_BuildMSGIntegrity(tszTMPBuffer + nTMPLen, &nTMPLen, tszTMPBuffer, nTMPLen, "123456789");
77-
NatProtocol_StunNat_Packet(tszMSGBuffer, &nTMPLen, (LPCXSTR)st_NatClient.byTokenStr, RFCCOMPONENTS_NATCLIENT_PROTOCOL_STUN_CLASS_FLAGS, RFCCOMPONENTS_NATCLIENT_PROTOCOL_STUN_ATTR_MAPPED_ADDRESS);
78-
//NatProtocol_StunNat_BuildFinger(tszMSGBuffer + nTMPLen, &nMSGLen, tszMSGBuffer, nTMPLen);
73+
NatProtocol_StunNat_BuildAttr(tszRVBuffer, &nRVLen, RFCCOMPONENTS_NATCLIENT_PROTOCOL_STUN_ATTR_USERNAME, tszUserStr, _tcsxlen(tszUserStr));
74+
NatProtocol_StunNat_BuildMapAddress(tszRVBuffer + nRVLen, &nRVLen, st_ServiceConfig.tszIPAddr, st_ServiceConfig.nRTCPort, true);
75+
NatProtocol_StunNat_BuildMSGIntegrity(tszRVBuffer + nRVLen, &nRVLen, tszRVBuffer, nRVLen, tszICEPass);
76+
77+
nRVLen += 8; //Finger 消息先加
78+
NatProtocol_StunNat_Packet(tszSDBuffer, &nRVLen, (LPCXSTR)st_NatClient.byTokenStr, RFCCOMPONENTS_NATCLIENT_PROTOCOL_STUN_CLASS_RESPONSE, RFCCOMPONENTS_NATCLIENT_PROTOCOL_STUN_ATTR_MAPPED_ADDRESS, tszRVBuffer);
79+
nRVLen -= 8; //计算效验不包含自己的8个字节属性
80+
nSDLen = nRVLen;
81+
NatProtocol_StunNat_BuildFinger(tszSDBuffer + nSDLen, &nSDLen, tszSDBuffer, nSDLen);
7982
BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListAttr, nAttrCount);
8083

81-
XEngine_Network_Send(lpszClientAddr, tszMSGBuffer, nMsgLen, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_PUSH_RTC);
84+
XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, ENUM_XENGINE_STREAMMEDIA_CLIENT_TYPE_PUSH_RTC);
8285
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("STUN客户端:%s,请求的STUN协议处理成功,请求的用户:%s"), lpszClientAddr, tszUserStr);
8386
}
8487
else

0 commit comments

Comments
 (0)