From ccacf371bf43c3b42759008af60dc86b77f3fd4a Mon Sep 17 00:00:00 2001 From: azw Date: Wed, 26 Apr 2023 07:56:25 +0000 Subject: [PATCH] 1 --- server/wsproxy/longsessionmgr.cc | 46 +++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/server/wsproxy/longsessionmgr.cc b/server/wsproxy/longsessionmgr.cc index 405c2a5..3869243 100644 --- a/server/wsproxy/longsessionmgr.cc +++ b/server/wsproxy/longsessionmgr.cc @@ -100,14 +100,54 @@ std::shared_ptr LongSessionMgr::GetSession(int socket_handle) 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; + + if (pkt->buf_len < IKCP_OVERHEAD) { + f8::UdpLog::Instance()->Warning("ProcUdpPacket host:%s port:%d buflen:%d over_head_error", + { + inet_ntoa(pkt->remote_addr.sin_addr), + 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()) { - int socket_handle = ikcp_getconv(pkt->buf); long long secret_key = KcpSession::ReadSecretKey(pkt->buf + IKCP_OVERHEAD, pkt->buf_len); - auto session = GetSession(socket_handle); - if (session && secret_key == session->GetKcpSession()->GetSecretKey()) { + 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 + }); } }