1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Fix #1501, use request ip for origin cluster. 3.0.66

This commit is contained in:
winlin 2019-11-30 18:50:24 +08:00
parent 488f16f60c
commit e5285ecabf
7 changed files with 40 additions and 23 deletions

View file

@ -152,6 +152,7 @@ Please select according to languages:
### V3 changes ### V3 changes
* v3.0, 2019-11-30, Fix #1501, use request ip for origin cluster. 3.0.66
* v3.0, 2019-11-30, Random tid for docker. 3.0.65 * v3.0, 2019-11-30, Random tid for docker. 3.0.65
* v3.0, 2019-11-30, Refine debug info for edge. 3.0.64 * v3.0, 2019-11-30, Refine debug info for edge. 3.0.64
* v3.0, 2019-10-30, Cover protocol stack RTMP. 3.0.63 * v3.0, 2019-10-30, Cover protocol stack RTMP. 3.0.63

View file

@ -58,30 +58,44 @@ SrsCoWorkers* SrsCoWorkers::instance()
return _instance; return _instance;
} }
SrsJsonAny* SrsCoWorkers::dumps(string vhost, string app, string stream) SrsJsonAny* SrsCoWorkers::dumps(string vhost, string host, string app, string stream)
{ {
SrsRequest* r = find_stream_info(vhost, app, stream); SrsRequest* r = find_stream_info(vhost, app, stream);
if (!r) { if (!r) {
// TODO: FIXME: Find stream from our origin util return to the start point. // TODO: FIXME: Find stream from our origin util return to the start point.
return SrsJsonAny::null(); return SrsJsonAny::null();
} }
vector<string> service_ports = _srs_config->get_listens(); // The service port parsing from listen port.
if (service_ports.empty()) { string listen_host;
return SrsJsonAny::null(); int listen_port = SRS_CONSTS_RTMP_DEFAULT_PORT;
vector<string> listen_hostports = _srs_config->get_listens();
if (!listen_hostports.empty()) {
string list_hostport = listen_hostports.at(0);
if (list_hostport.find(":") != string::npos) {
srs_parse_hostport(list_hostport, listen_host, listen_port);
} else {
listen_port = ::atoi(list_hostport.c_str());
}
} }
string service_ip = srs_get_public_internet_address(); // The ip of server, we use the request host as ip, if listen host is localhost or loopback.
string service_hostport = service_ports.at(0); // For example, the server may behind a NAT(192.x.x.x), while its ip is a docker ip(172.x.x.x),
// we should use the NAT(192.x.x.x) address as it's the exposed ip.
int service_port = SRS_CONSTS_RTMP_DEFAULT_PORT; // @see https://github.com/ossrs/srs/issues/1501
if (service_hostport.find(":") != string::npos) { string service_ip;
string service_host; if (listen_host != SRS_CONSTS_LOCALHOST && listen_host != SRS_CONSTS_LOOPBACK && listen_host != SRS_CONSTS_LOOPBACK6) {
srs_parse_hostport(service_hostport, service_host, service_port); service_ip = listen_host;
} else {
service_port = ::atoi(service_hostport.c_str());
} }
if (service_ip.empty()) {
service_ip = host;
}
if (service_ip.empty()) {
service_ip = srs_get_public_internet_address();
}
// The backend API endpoint.
string backend = _srs_config->get_http_api_listen(); string backend = _srs_config->get_http_api_listen();
if (backend.find(":") == string::npos) { if (backend.find(":") == string::npos) {
backend = service_ip + ":" + backend; backend = service_ip + ":" + backend;
@ -92,7 +106,7 @@ SrsJsonAny* SrsCoWorkers::dumps(string vhost, string app, string stream)
return SrsJsonAny::object() return SrsJsonAny::object()
->set("ip", SrsJsonAny::str(service_ip.c_str())) ->set("ip", SrsJsonAny::str(service_ip.c_str()))
->set("port", SrsJsonAny::integer(service_port)) ->set("port", SrsJsonAny::integer(listen_port))
->set("vhost", SrsJsonAny::str(r->vhost.c_str())) ->set("vhost", SrsJsonAny::str(r->vhost.c_str()))
->set("api", SrsJsonAny::str(backend.c_str())) ->set("api", SrsJsonAny::str(backend.c_str()))
->set("routers", routers); ->set("routers", routers);

View file

@ -46,7 +46,7 @@ private:
public: public:
static SrsCoWorkers* instance(); static SrsCoWorkers* instance();
public: public:
virtual SrsJsonAny* dumps(std::string vhost, std::string app, std::string stream); virtual SrsJsonAny* dumps(std::string vhost, std::string host, std::string app, std::string stream);
private: private:
virtual SrsRequest* find_stream_info(std::string vhost, std::string app, std::string stream); virtual SrsRequest* find_stream_info(std::string vhost, std::string app, std::string stream);
public: public:

View file

@ -1297,7 +1297,7 @@ srs_error_t SrsGoApiClusters::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
->set("stream", SrsJsonAny::str(stream.c_str()))); ->set("stream", SrsJsonAny::str(stream.c_str())));
SrsCoWorkers* coworkers = SrsCoWorkers::instance(); SrsCoWorkers* coworkers = SrsCoWorkers::instance();
data->set("origin", coworkers->dumps(vhost, app, stream)); data->set("origin", coworkers->dumps(vhost, ip, app, stream));
return srs_api_response(w, r, obj->dumps()); return srs_api_response(w, r, obj->dumps());
} }
@ -1342,7 +1342,7 @@ srs_error_t SrsHttpApi::do_cycle()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
srs_trace("api get peer ip success. ip=%s", ip.c_str()); srs_trace("API server client, ip=%s", ip.c_str());
// initialize parser // initialize parser
if ((err = parser->initialize(HTTP_REQUEST, true)) != srs_success) { if ((err = parser->initialize(HTTP_REQUEST, true)) != srs_success) {

View file

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

View file

@ -116,6 +116,8 @@
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
#define SRS_CONSTS_NULL_FILE "/dev/null" #define SRS_CONSTS_NULL_FILE "/dev/null"
#define SRS_CONSTS_LOCALHOST "127.0.0.1" #define SRS_CONSTS_LOCALHOST "127.0.0.1"
#define SRS_CONSTS_LOOPBACK "0.0.0.0"
#define SRS_CONSTS_LOOPBACK6 "::"
// The signal defines. // The signal defines.
// To reload the config file and apply new config. // To reload the config file and apply new config.

View file

@ -231,9 +231,9 @@ string srs_any_address_for_listener()
} }
if (ipv6_active && !ipv4_active) { if (ipv6_active && !ipv4_active) {
return "::"; return SRS_CONSTS_LOOPBACK6;
} }
return "0.0.0.0"; return SRS_CONSTS_LOOPBACK;
} }
void srs_parse_endpoint(string hostport, string& ip, int& port) void srs_parse_endpoint(string hostport, string& ip, int& port)