mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-11-24 00:47:21 +08:00
公网部署时,ICE 端口可能遭受恶意请求或扫描。异常会话长期不退出, 导致 UDP 会话、TURN relay 端口及关联资源无法及时释放,最终可能耗尽 可用端口。 - 增加 UDP ICE 会话空闲超时配置,自动关闭长期无数据的会话 - 完善 TURN Allocation 的创建、刷新、超时和主动释放流程 - 会话异常退出或销毁时清理 relay 端口、Permission 和 ChannelBind - 为 relay 会话注册表增加并发保护,避免残留或竞态访问 - 使用弱引用解除会话对象之间的循环引用 - 修正 Allocation Mismatch 错误码为 437 - 补充 iceSessionTimeoutSec 配置及使用说明 Plan-Item: ICEBUGFIX --------- Co-authored-by: xiongziliang <771730766@qq.com>
72 lines
2.5 KiB
C++
72 lines
2.5 KiB
C++
/*
|
|
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
|
*
|
|
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
|
*
|
|
* Use of this source code is governed by MIT-like license that can be found in the
|
|
* LICENSE file in the root of the source tree. All contributing project authors
|
|
* may be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
|
|
#ifndef ZLMEDIAKIT_WEBRTC_ICE_SESSION_H
|
|
#define ZLMEDIAKIT_WEBRTC_ICE_SESSION_H
|
|
|
|
#include "Network/Session.h"
|
|
#include "IceTransport.hpp"
|
|
#include "Http/HttpRequestSplitter.h"
|
|
|
|
namespace mediakit {
|
|
|
|
class IceSession : public toolkit::Session, public RTC::IceTransport::Listener, public HttpRequestSplitter {
|
|
public:
|
|
using Ptr = std::shared_ptr<IceSession>;
|
|
using WeakPtr = std::weak_ptr<IceSession>;
|
|
IceSession(const toolkit::Socket::Ptr &sock);
|
|
~IceSession() override;
|
|
|
|
static toolkit::EventPoller::Ptr queryPoller(const toolkit::Buffer::Ptr &buffer);
|
|
|
|
//// Session override////
|
|
// void attachServer(const Server &server) override;
|
|
void onRecv(const toolkit::Buffer::Ptr &) override;
|
|
void onError(const toolkit::SockException &err) override;
|
|
void onManager() override;
|
|
|
|
// ice related callbacks ///
|
|
void onIceTransportRecvData(const toolkit::Buffer::Ptr& buffer, const RTC::IceTransport::Pair::Ptr& pair) override;
|
|
void onIceTransportGatheringCandidate(const RTC::IceTransport::Pair::Ptr& pair, const RTC::CandidateInfo& candidate) override;
|
|
void onIceTransportDisconnected() override;
|
|
void onIceTransportCompleted() override;
|
|
|
|
//// HttpRequestSplitter override ////
|
|
ssize_t onRecvHeader(const char *data, size_t len) override;
|
|
const char *onSearchPacketTail(const char *data, size_t len) override;
|
|
|
|
void onRecv_l(const char *data, size_t len);
|
|
protected:
|
|
bool _over_tcp = false;
|
|
toolkit::Ticker _alive_ticker;
|
|
|
|
RTC::IceTransport::Pair::Ptr _session_pair = nullptr;
|
|
RTC::IceServer::Ptr _ice_transport;
|
|
};
|
|
|
|
class IceSessionManager {
|
|
public:
|
|
static IceSessionManager &Instance();
|
|
IceSession::Ptr getItem(const std::string& key);
|
|
void addItem(const std::string& key, const IceSession::Ptr &ptr);
|
|
void removeItem(const std::string& key);
|
|
|
|
private:
|
|
IceSessionManager() = default;
|
|
|
|
private:
|
|
std::mutex _mtx;
|
|
std::unordered_map<std::string, std::weak_ptr<IceSession>> _map;
|
|
};
|
|
}// namespace mediakit
|
|
|
|
#endif //ZLMEDIAKIT_WEBRTC_ICE_SESSION_H
|