1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-12 11:21:52 +00:00

Support go-oryx rtmplb with proxy protocol. 3.0.56

This commit is contained in:
winlin 2019-10-04 19:03:34 +08:00
parent 130c545f9a
commit 88df9a2497
7 changed files with 54 additions and 8 deletions

View file

@ -158,6 +158,7 @@ Please select according to languages:
### V3 changes
* v3.0, 2019-10-04, Support go-oryx rtmplb with [proxy protocol](https://github.com/ossrs/go-oryx/wiki/RtmpProxy). 3.0.56
* v3.0, 2019-10-03, Fix [#775][bug #775], Support SO_REUSEPORT to improve edge performance. 3.0.54
* v3.0, 2019-10-03, Remove KAFKA. 3.0.53
* v3.0, 2019-05-14, Covert Kernel File reader/writer. 3.0.52

View file

@ -160,6 +160,12 @@ srs_error_t SrsRtmpConn::do_cycle()
return srs_error_wrap(err, "rtmp handshake");
}
uint32_t rip = rtmp->proxy_real_ip();
if (rip > 0) {
srs_trace("RTMP proxy real client ip=%d.%d.%d.%d",
uint8_t(rip>>24), uint8_t(rip>>16), uint8_t(rip>>8), uint8_t(rip));
}
SrsRequest* req = info->req;
if ((err = rtmp->connect_app(req)) != srs_success) {
return srs_error_wrap(err, "rtmp connect tcUrl");

View file

@ -27,7 +27,7 @@
// The version config.
#define VERSION_MAJOR 3
#define VERSION_MINOR 0
#define VERSION_REVISION 55
#define VERSION_REVISION 56
// The macros generated by configure script.
#include <srs_auto_headers.hpp>

View file

@ -176,6 +176,7 @@
#define ERROR_RTMP_STREAM_NAME_EMPTY 2051
#define ERROR_HTTP_HIJACK 2052
#define ERROR_RTMP_MESSAGE_CREATE 2053
#define ERROR_RTMP_PROXY_EXCEED 2054
//
// The system control message,
// It's not an error, but special control logic.

View file

@ -151,7 +151,6 @@ void srs_random_generate(char* bytes, int size)
if (!_random_initialized) {
srand(0);
_random_initialized = true;
srs_trace("srand initialized the random.");
}
for (int i = 0; i < size; i++) {

View file

@ -1659,9 +1659,15 @@ bool srs_client_type_is_publish(SrsRtmpConnType type)
SrsHandshakeBytes::SrsHandshakeBytes()
{
c0c1 = s0s1s2 = c2 = NULL;
proxy_real_ip = 0;
}
SrsHandshakeBytes::~SrsHandshakeBytes()
{
dispose();
}
void SrsHandshakeBytes::dispose()
{
srs_freepa(c0c1);
srs_freepa(s0s1s2);
@ -1683,6 +1689,26 @@ srs_error_t SrsHandshakeBytes::read_c0c1(ISrsProtocolReadWriter* io)
return srs_error_wrap(err, "read c0c1");
}
// Whether RTMP proxy, @see https://github.com/ossrs/go-oryx/wiki/RtmpProxy
if (uint8_t(c0c1[0]) == 0xF3) {
uint16_t nn = uint16_t(c0c1[1])<<8 | uint16_t(c0c1[2]);
ssize_t nn_consumed = 3 + nn;
if (nn > 1024) {
return srs_error_new(ERROR_RTMP_PROXY_EXCEED, "proxy exceed max size, nn=%d", nn);
}
// 4B client real IP.
if (nn >= 4) {
proxy_real_ip = uint32_t(c0c1[3])<<24 | uint32_t(c0c1[4])<<16 | uint32_t(c0c1[5])<<8 | uint32_t(c0c1[6]);
nn -= 4;
}
memmove(c0c1, c0c1 + nn_consumed, 1537 - nn_consumed);
if ((err = io->read_fully(c0c1 + 1537 - nn_consumed, nn_consumed, &nsize)) != srs_success) {
return srs_error_wrap(err, "read c0c1");
}
}
return err;
}
@ -1888,7 +1914,7 @@ srs_error_t SrsRtmpClient::handshake()
}
}
srs_freep(hs_bytes);
hs_bytes->dispose();
return err;
}
@ -1904,7 +1930,7 @@ srs_error_t SrsRtmpClient::simple_handshake()
return srs_error_wrap(err, "simple handshake");
}
srs_freep(hs_bytes);
hs_bytes->dispose();
return err;
}
@ -1920,7 +1946,7 @@ srs_error_t SrsRtmpClient::complex_handshake()
return srs_error_wrap(err, "complex handshake");
}
srs_freep(hs_bytes);
hs_bytes->dispose();
return err;
}
@ -2193,6 +2219,11 @@ SrsRtmpServer::~SrsRtmpServer()
srs_freep(hs_bytes);
}
uint32_t SrsRtmpServer::proxy_real_ip()
{
return hs_bytes->proxy_real_ip;
}
void SrsRtmpServer::set_auto_response(bool v)
{
protocol->set_auto_response(v);
@ -2285,7 +2316,7 @@ srs_error_t SrsRtmpServer::handshake()
}
}
srs_freep(hs_bytes);
hs_bytes->dispose();
return err;
}

View file

@ -500,6 +500,8 @@ bool srs_client_type_is_publish(SrsRtmpConnType type);
class SrsHandshakeBytes
{
public:
// For RTMP proxy, the real IP.
uint32_t proxy_real_ip;
// [1+1536]
char* c0c1;
// [1+1536+1536]
@ -509,6 +511,8 @@ public:
public:
SrsHandshakeBytes();
virtual ~SrsHandshakeBytes();
public:
virtual void dispose();
public:
virtual srs_error_t read_c0c1(ISrsProtocolReadWriter* io);
virtual srs_error_t read_s0s1s2(ISrsProtocolReadWriter* io);
@ -615,6 +619,10 @@ private:
public:
SrsRtmpServer(ISrsProtocolReadWriter* skt);
virtual ~SrsRtmpServer();
public:
// For RTMP proxy, the real IP. 0 if no proxy.
// @doc https://github.com/ossrs/go-oryx/wiki/RtmpProxy
virtual uint32_t proxy_real_ip();
// Protocol methods proxy
public:
// Set the auto response message when recv for protocol stack.