1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 20:01:56 +00:00

RTC: Support server hijacker

This commit is contained in:
winlin 2020-08-07 17:04:34 +08:00
parent 73eb60a9d5
commit a1da95c906
2 changed files with 39 additions and 0 deletions

View file

@ -204,9 +204,18 @@ ISrsRtcServerHandler::~ISrsRtcServerHandler()
{
}
ISrsRtcServerHijacker::ISrsRtcServerHijacker()
{
}
ISrsRtcServerHijacker::~ISrsRtcServerHijacker()
{
}
SrsRtcServer::SrsRtcServer()
{
handler = NULL;
hijacker = NULL;
timer = new SrsHourGlass(this, 1 * SRS_UTIME_SECONDS);
}
@ -257,6 +266,11 @@ void SrsRtcServer::set_handler(ISrsRtcServerHandler* h)
handler = h;
}
void SrsRtcServer::set_hijacker(ISrsRtcServerHijacker* h)
{
hijacker = h;
}
srs_error_t SrsRtcServer::listen_udp()
{
srs_error_t err = srs_success;
@ -309,6 +323,18 @@ srs_error_t SrsRtcServer::on_udp_packet(SrsUdpMuxSocket* skt)
}
}
// Notify hijack to handle the UDP packet.
if (hijacker) {
bool consumed = false;
if ((err = hijacker->on_udp_packet(&consumed)) != srs_success) {
return srs_error_wrap(err, "hijack consumed=%u", consumed);
}
if (consumed) {
return err;
}
}
// For STUN, the peer address may change.
if (srs_is_stun((uint8_t*)data, size)) {
SrsStunPacket ping;

View file

@ -72,6 +72,17 @@ public:
virtual void on_timeout(SrsRtcConnection* session) = 0;
};
// The hijacker to hook server.
class ISrsRtcServerHijacker
{
public:
ISrsRtcServerHijacker();
virtual ~ISrsRtcServerHijacker();
public:
// If consumed set to true, server will ignore the packet.
virtual srs_error_t on_udp_packet(bool* pconsumed) = 0;
};
// The RTC server instance, listen UDP port, handle UDP packet, manage RTC connections.
class SrsRtcServer : virtual public ISrsUdpMuxHandler, virtual public ISrsHourGlass
{
@ -79,6 +90,7 @@ private:
SrsHourGlass* timer;
std::vector<SrsUdpMuxListener*> listeners;
ISrsRtcServerHandler* handler;
ISrsRtcServerHijacker* hijacker;
private:
// TODO: FIXME: Rename it.
std::map<std::string, SrsRtcConnection*> map_username_session; // key: username(local_ufrag + ":" + remote_ufrag)
@ -93,6 +105,7 @@ public:
virtual srs_error_t initialize();
// Set the handler for server events.
void set_handler(ISrsRtcServerHandler* h);
void set_hijacker(ISrsRtcServerHijacker* h);
public:
// TODO: FIXME: Support gracefully quit.
// TODO: FIXME: Support reload.