mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
"stun and dtls done"
This commit is contained in:
parent
30d8b2209f
commit
9d5495c0c2
19 changed files with 1220 additions and 160 deletions
|
@ -25,11 +25,15 @@
|
|||
#define SRS_APP_RTC_CONN_HPP
|
||||
|
||||
#include <srs_core.hpp>
|
||||
#include <srs_service_st.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
#include <srtp2/srtp.h>
|
||||
|
||||
class SrsServer;
|
||||
class SrsStunPacket;
|
||||
|
||||
|
@ -55,7 +59,14 @@ public:
|
|||
SrsSdp();
|
||||
virtual ~SrsSdp();
|
||||
|
||||
srs_error_t parse(const std::string& sdp);
|
||||
srs_error_t decode(const std::string& sdp_str);
|
||||
srs_error_t encode(std::string& sdp_str);
|
||||
|
||||
std::string get_ice_ufrag() const { return ice_ufrag; }
|
||||
std::string get_ice_pwd() const { return ice_pwd; }
|
||||
|
||||
void set_ice_ufrag(const std::string& u) { ice_ufrag = u; }
|
||||
void set_ice_pwd(const std::string& p) { ice_pwd = p; }
|
||||
private:
|
||||
srs_error_t parse_attr(const std::string& line);
|
||||
};
|
||||
|
@ -69,19 +80,63 @@ enum SrsRtcSessionStateType
|
|||
CLOSED = 4,
|
||||
};
|
||||
|
||||
class SrsDtlsSession
|
||||
{
|
||||
private:
|
||||
SSL* dtls;
|
||||
BIO* bio_in;
|
||||
BIO* bio_out;
|
||||
|
||||
std::string client_key;
|
||||
std::string server_key;
|
||||
|
||||
srtp_t srtp_send;
|
||||
srtp_t srtp_recv;
|
||||
|
||||
srs_netfd_t fd;
|
||||
const sockaddr* from;
|
||||
int fromlen;
|
||||
|
||||
bool handshake_done;
|
||||
|
||||
public:
|
||||
SrsDtlsSession(srs_netfd_t lfd, const sockaddr* f, int fl);
|
||||
virtual ~SrsDtlsSession();
|
||||
|
||||
srs_error_t on_dtls(const char* data, const int len);
|
||||
srs_error_t on_dtls_application_data(const char* data, const int len);
|
||||
|
||||
void send_client_hello();
|
||||
srs_error_t handshake();
|
||||
srs_error_t srtp_init();
|
||||
srs_error_t srtp_sender_side_init();
|
||||
srs_error_t srtp_receiver_side_init();
|
||||
};
|
||||
|
||||
class SrsRtcSession
|
||||
{
|
||||
public:
|
||||
private:
|
||||
SrsSdp peer_sdp;
|
||||
SrsSdp offer_sdp;
|
||||
SrsSdp remote_sdp;
|
||||
SrsSdp local_sdp;
|
||||
SrsRtcSessionStateType session_state;
|
||||
SrsDtlsSession* dtls_session;
|
||||
public:
|
||||
SrsRtcSession();
|
||||
virtual ~SrsRtcSession();
|
||||
|
||||
SrsSdp* get_local_sdp() { return &local_sdp; }
|
||||
SrsSdp* get_remote_sdp() { return &remote_sdp; }
|
||||
SrsRtcSessionStateType get_session_state() { return session_state; }
|
||||
|
||||
void set_local_sdp(const SrsSdp& sdp) { local_sdp = sdp; }
|
||||
void set_remote_sdp(const SrsSdp& sdp) { remote_sdp = sdp; }
|
||||
void set_session_state(SrsRtcSessionStateType state) { session_state = state; }
|
||||
|
||||
srs_error_t on_udp_packet(const std::string& peer_ip, const int peer_port, const char* data, const int size);
|
||||
srs_error_t on_stun(const SrsStunPacket& stun_packet);
|
||||
srs_error_t on_binding_request(const SrsStunPacket& stun_packet, const std::string& peer_ip, const uint16_t peer_port,
|
||||
SrsStunPacket& stun_binding_response);
|
||||
srs_error_t on_dtls(const char* buf, const int nb_buf);
|
||||
srs_error_t send_client_hello(srs_netfd_t fd, const sockaddr* from, int fromlen);
|
||||
srs_error_t send_packet();
|
||||
};
|
||||
|
||||
|
@ -89,19 +144,26 @@ class SrsRtcServer
|
|||
{
|
||||
private:
|
||||
SrsServer* server;
|
||||
std::map<std::string, SrsRtcSession*> map_sessions;
|
||||
std::map<std::string, SrsRtcSession*> map_ufrag_sessions;
|
||||
std::map<std::string, SrsRtcSession*> map_ip_port_sessions;
|
||||
public:
|
||||
SrsRtcServer(SrsServer* svr);
|
||||
virtual ~SrsRtcServer();
|
||||
public:
|
||||
virtual srs_error_t initialize();
|
||||
virtual srs_error_t on_udp_packet(const std::string& peer_ip, const int peer_port, const char* data, const int size);
|
||||
virtual srs_error_t on_udp_packet(srs_netfd_t fd, const std::string& peer_ip, const int peer_port,
|
||||
const sockaddr* from, const int fromlen, const char* data, const int size);
|
||||
|
||||
SrsRtcSession* create_rtc_session(const SrsSdp& remote_sdp, SrsSdp& local_sdp);
|
||||
bool insert_into_ip_port_sessions(const std::string& peer_ip, const uint16_t peer_port, SrsRtcSession* rtc_session);
|
||||
private:
|
||||
srs_error_t on_stun(const std::string& peer_ip, const int peer_port, const char* data, const int size);
|
||||
srs_error_t on_dtls(const std::string& peer_ip, const int peer_port, const char* data, const int size);
|
||||
srs_error_t on_rtp_or_rtcp(const std::string& peer_ip, const int peer_port, const char* data, const int size);
|
||||
srs_error_t on_stun(srs_netfd_t fd, const std::string& peer_ip, const int peer_port, const sockaddr* from, const int fromlen, const char* data, const int size);
|
||||
srs_error_t on_dtls(srs_netfd_t fd, const std::string& peer_ip, const int peer_port, const sockaddr* from, const int fromlen, const char* data, const int size);
|
||||
srs_error_t on_rtp_or_rtcp(srs_netfd_t fd, const std::string& peer_ip, const int peer_port,
|
||||
const sockaddr* from, const int fromlen, const char* data, const int size);
|
||||
private:
|
||||
SrsRtcSession* find_rtc_session(const std::string& ufrag);
|
||||
SrsRtcSession* find_rtc_session_by_ufrag(const std::string& ufrag);
|
||||
SrsRtcSession* find_rtc_session_by_ip_port(const std::string& peer_ip, const uint16_t peer_port);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue