1
This commit is contained in:
parent
9fb8c7c51a
commit
ccacf371bf
@ -100,14 +100,54 @@ std::shared_ptr<LongSession> LongSessionMgr::GetSession(int socket_handle)
|
|||||||
|
|
||||||
void LongSessionMgr::ProcUdpPacket(a8::UdpPacket* pkt)
|
void LongSessionMgr::ProcUdpPacket(a8::UdpPacket* pkt)
|
||||||
{
|
{
|
||||||
|
f8::UdpLog::Instance()->Debug("ProcUdpPacket host:%s port:%d buflen:%d",
|
||||||
|
{
|
||||||
|
inet_ntoa(pkt->remote_addr.sin_addr),
|
||||||
|
pkt->remote_addr.sin_port,
|
||||||
|
pkt->buf_len
|
||||||
|
});
|
||||||
const int IKCP_OVERHEAD = 24;
|
const int IKCP_OVERHEAD = 24;
|
||||||
if (pkt->buf_len > IKCP_OVERHEAD + KcpSession::GetSecretKeyLen()) {
|
|
||||||
int socket_handle = ikcp_getconv(pkt->buf);
|
if (pkt->buf_len < IKCP_OVERHEAD) {
|
||||||
long long secret_key = KcpSession::ReadSecretKey(pkt->buf + IKCP_OVERHEAD, pkt->buf_len);
|
f8::UdpLog::Instance()->Warning("ProcUdpPacket host:%s port:%d buflen:%d over_head_error",
|
||||||
auto session = GetSession(socket_handle);
|
{
|
||||||
if (session && secret_key == session->GetKcpSession()->GetSecretKey()) {
|
inet_ntoa(pkt->remote_addr.sin_addr),
|
||||||
session->GetKcpSession()->OnRecvPacket(pkt);
|
pkt->remote_addr.sin_port,
|
||||||
|
pkt->buf_len
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
int socket_handle = ikcp_getconv(pkt->buf);
|
||||||
|
auto session = GetSession(socket_handle);
|
||||||
|
if (!session) {
|
||||||
|
f8::UdpLog::Instance()->Warning("ProcUdpPacket host:%s socket_handle:%d session_error",
|
||||||
|
{
|
||||||
|
inet_ntoa(pkt->remote_addr.sin_addr),
|
||||||
|
pkt->remote_addr.sin_port,
|
||||||
|
socket_handle
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pkt->buf_len > IKCP_OVERHEAD + KcpSession::GetSecretKeyLen()) {
|
||||||
|
long long secret_key = KcpSession::ReadSecretKey(pkt->buf + IKCP_OVERHEAD, pkt->buf_len);
|
||||||
|
if (secret_key == session->GetKcpSession()->GetSecretKey()) {
|
||||||
|
session->GetKcpSession()->OnRecvPacket(pkt);
|
||||||
|
} else {
|
||||||
|
f8::UdpLog::Instance()->Warning("ProcUdpPacket host:%s port:%d socket_handle%d secret_key:%d secret_error",
|
||||||
|
{
|
||||||
|
inet_ntoa(pkt->remote_addr.sin_addr),
|
||||||
|
pkt->remote_addr.sin_port,
|
||||||
|
socket_handle,
|
||||||
|
secret_key
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
f8::UdpLog::Instance()->Warning("ProcUdpPacket host:%s port:%d buflen:%d bufflen_error",
|
||||||
|
{
|
||||||
|
inet_ntoa(pkt->remote_addr.sin_addr),
|
||||||
|
pkt->remote_addr.sin_port,
|
||||||
|
pkt->buf_len
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user