mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
reject repeated srt pusher connection
This commit is contained in:
parent
b3c3ce9bf3
commit
1481928b53
2 changed files with 22 additions and 4 deletions
|
@ -167,6 +167,8 @@ void srt_handle::add_newconn(SRT_CONN_PTR conn_ptr, int events) {
|
|||
add_new_puller(conn_ptr, conn_ptr->get_subpath());
|
||||
} else {
|
||||
if(add_new_pusher(conn_ptr) == false) {
|
||||
srs_trace("push connection is repeated and rejected, fd:%d, streamid:%s",
|
||||
conn_ptr->get_conn(), conn_ptr->get_streamid().c_str());
|
||||
conn_ptr->close();
|
||||
return;
|
||||
}
|
||||
|
@ -362,14 +364,28 @@ void srt_handle::check_alive() {
|
|||
|
||||
void srt_handle::close_push_conn(SRTSOCKET srtsocket) {
|
||||
auto iter = _conn_map.find(srtsocket);
|
||||
if (iter == _conn_map.end()) {
|
||||
return;
|
||||
|
||||
if (iter != _conn_map.end()) {
|
||||
SRT_CONN_PTR conn_ptr = iter->second;
|
||||
auto push_iter = _push_conn_map.find(conn_ptr->get_subpath());
|
||||
if (push_iter != _push_conn_map.end()) {
|
||||
_push_conn_map.erase(push_iter);
|
||||
}
|
||||
_conn_map.erase(iter);
|
||||
conn_ptr->close();
|
||||
}
|
||||
|
||||
srt_epoll_remove_usock(_handle_pollid, srtsocket);
|
||||
_conn_map.erase(iter);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool srt_handle::add_new_pusher(SRT_CONN_PTR conn_ptr) {
|
||||
auto push_iter = _push_conn_map.find(conn_ptr->get_subpath());
|
||||
if (push_iter != _push_conn_map.end()) {
|
||||
return false;
|
||||
}
|
||||
_push_conn_map.insert(std::make_pair(conn_ptr->get_subpath(), conn_ptr));
|
||||
_conn_map.insert(std::make_pair(conn_ptr->get_conn(), conn_ptr));
|
||||
srs_trace("srt_handle add new pusher streamid:%s, subpath:%s",
|
||||
conn_ptr->get_streamid().c_str(), conn_ptr->get_subpath().c_str());
|
||||
|
|
|
@ -60,9 +60,11 @@ private:
|
|||
private:
|
||||
int _handle_pollid;
|
||||
|
||||
std::unordered_map<SRTSOCKET, SRT_CONN_PTR> _conn_map;
|
||||
std::unordered_map<SRTSOCKET, SRT_CONN_PTR> _conn_map;//save all srt connection: pull or push
|
||||
std::shared_ptr<std::thread> _work_thread_ptr;
|
||||
|
||||
//save push srt connection for prevent from repeat push connection
|
||||
std::unordered_map<std::string, SRT_CONN_PTR> _push_conn_map;//key:streamid, value:SRT_CONN_PTR
|
||||
//streamid, play map<SRTSOCKET, SRT_CONN_PTR>
|
||||
std::unordered_map<std::string, std::unordered_map<SRTSOCKET, SRT_CONN_PTR>> _streamid_map;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue