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:
parent
488f16f60c
commit
e5285ecabf
7 changed files with 40 additions and 23 deletions
|
@ -152,6 +152,7 @@ Please select according to languages:
|
|||
|
||||
### 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, Refine debug info for edge. 3.0.64
|
||||
* v3.0, 2019-10-30, Cover protocol stack RTMP. 3.0.63
|
||||
|
|
|
@ -58,7 +58,7 @@ SrsCoWorkers* SrsCoWorkers::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);
|
||||
if (!r) {
|
||||
|
@ -66,22 +66,36 @@ SrsJsonAny* SrsCoWorkers::dumps(string vhost, string app, string stream)
|
|||
return SrsJsonAny::null();
|
||||
}
|
||||
|
||||
vector<string> service_ports = _srs_config->get_listens();
|
||||
if (service_ports.empty()) {
|
||||
return SrsJsonAny::null();
|
||||
// The service port parsing from listen port.
|
||||
string listen_host;
|
||||
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();
|
||||
string service_hostport = service_ports.at(0);
|
||||
|
||||
int service_port = SRS_CONSTS_RTMP_DEFAULT_PORT;
|
||||
if (service_hostport.find(":") != string::npos) {
|
||||
string service_host;
|
||||
srs_parse_hostport(service_hostport, service_host, service_port);
|
||||
} else {
|
||||
service_port = ::atoi(service_hostport.c_str());
|
||||
// The ip of server, we use the request host as ip, if listen host is localhost or loopback.
|
||||
// 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.
|
||||
// @see https://github.com/ossrs/srs/issues/1501
|
||||
string service_ip;
|
||||
if (listen_host != SRS_CONSTS_LOCALHOST && listen_host != SRS_CONSTS_LOOPBACK && listen_host != SRS_CONSTS_LOOPBACK6) {
|
||||
service_ip = listen_host;
|
||||
}
|
||||
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();
|
||||
if (backend.find(":") == string::npos) {
|
||||
backend = service_ip + ":" + backend;
|
||||
|
@ -92,7 +106,7 @@ SrsJsonAny* SrsCoWorkers::dumps(string vhost, string app, string stream)
|
|||
|
||||
return SrsJsonAny::object()
|
||||
->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("api", SrsJsonAny::str(backend.c_str()))
|
||||
->set("routers", routers);
|
||||
|
|
|
@ -46,7 +46,7 @@ private:
|
|||
public:
|
||||
static SrsCoWorkers* instance();
|
||||
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:
|
||||
virtual SrsRequest* find_stream_info(std::string vhost, std::string app, std::string stream);
|
||||
public:
|
||||
|
|
|
@ -1297,7 +1297,7 @@ srs_error_t SrsGoApiClusters::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
|
|||
->set("stream", SrsJsonAny::str(stream.c_str())));
|
||||
|
||||
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());
|
||||
}
|
||||
|
@ -1342,7 +1342,7 @@ srs_error_t SrsHttpApi::do_cycle()
|
|||
{
|
||||
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
|
||||
if ((err = parser->initialize(HTTP_REQUEST, true)) != srs_success) {
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
// The version config.
|
||||
#define VERSION_MAJOR 3
|
||||
#define VERSION_MINOR 0
|
||||
#define VERSION_REVISION 65
|
||||
#define VERSION_REVISION 66
|
||||
|
||||
// The macros generated by configure script.
|
||||
#include <srs_auto_headers.hpp>
|
||||
|
|
|
@ -116,6 +116,8 @@
|
|||
///////////////////////////////////////////////////////////
|
||||
#define SRS_CONSTS_NULL_FILE "/dev/null"
|
||||
#define SRS_CONSTS_LOCALHOST "127.0.0.1"
|
||||
#define SRS_CONSTS_LOOPBACK "0.0.0.0"
|
||||
#define SRS_CONSTS_LOOPBACK6 "::"
|
||||
|
||||
// The signal defines.
|
||||
// To reload the config file and apply new config.
|
||||
|
|
|
@ -231,9 +231,9 @@ string srs_any_address_for_listener()
|
|||
}
|
||||
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue