胡斌

1.try simple handshake first when forword

2.add forward_server_srs,true or false,default true,directive in config file in vhost section
to disable connect app req params to make connect app success when connect some cdn server
... ... @@ -1822,7 +1822,7 @@ int SrsConfig::check_config()
&& n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks"
&& n != "gop_cache" && n != "queue_length"
&& n != "refer" && n != "refer_publish" && n != "refer_play"
&& n != "forward" && n != "transcode" && n != "bandcheck"
&& n != "forward" && n != "forward_server_srs" && n != "transcode" && n != "bandcheck"
&& n != "time_jitter" && n != "mix_correct"
&& n != "atc" && n != "atc_auto"
&& n != "debug_srs_upnode"
... ... @@ -1938,7 +1938,17 @@ int SrsConfig::check_config()
return ret;
}
}*/
} else if (n == "security") {
} else if (n == "forward_server_srs") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name.c_str();
if (m != "true" && m != "false") {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost forward_server_srs directive %s(only support true or flase), ret=%d", m.c_str(), ret);
return ret;
}
}
}
else if (n == "security") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
SrsConfDirective* security = conf->at(j);
string m = security->name.c_str();
... ... @@ -2745,6 +2755,22 @@ SrsConfDirective* SrsConfig::get_forward(string vhost)
return conf->get("forward");
}
bool SrsConfig::get_forward_server_srs(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return true;
}
conf = conf->get("forward_server_srs");
if (!conf || conf->arg0().empty()) {
return true;
}
return conf->arg0()=="true";
}
SrsConfDirective* SrsConfig::get_vhost_http_hooks(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
... ...
... ... @@ -569,6 +569,10 @@ public:
* get the forward directive of vhost.
*/
virtual SrsConfDirective* get_forward(std::string vhost);
/**
* get the forward server type of vhost,if srs return true,else false.
*/
virtual bool get_forward_server_srs(std::string vhost);
// http_hooks section
private:
/**
... ...
... ... @@ -235,10 +235,12 @@ int SrsForwarder::cycle()
client->set_recv_timeout(SRS_CONSTS_RTMP_RECV_TIMEOUT_US);
client->set_send_timeout(SRS_CONSTS_RTMP_SEND_TIMEOUT_US);
if ((ret = client->handshake()) != ERROR_SUCCESS) {
srs_error("handshake with server failed. ret=%d", ret);
return ret;
}
if ((ret = client->simple_handshake() != ERROR_SUCCESS)) {
if ((ret = client->handshake()) != ERROR_SUCCESS) {
srs_error("handshake with server failed. ret=%d", ret);
return ret;
}
}
if ((ret = connect_app(ep_server, ep_port)) != ERROR_SUCCESS) {
srs_error("connect with server failed. ret=%d", ret);
return ret;
... ... @@ -373,7 +375,15 @@ int SrsForwarder::connect_app(string ep_server, string ep_port)
// @see https://github.com/ossrs/srs/issues/160
// the debug_srs_upnode is config in vhost and default to true.
bool debug_srs_upnode = _srs_config->get_debug_srs_upnode(req->vhost);
if ((ret = client->connect_app(req->app, tc_url, req, debug_srs_upnode)) != ERROR_SUCCESS) {
//if forward_server is not srs,or srs compatible,don't send req when connect app,in case of be rejected
bool forward_server_srs = _srs_config->get_forward_server_srs(req->vhost);
if (!forward_server_srs) {
srs_trace("forward to srs incompatible server, tcUrl=%s,vhost:%s",
tc_url.c_str(), req->vhost.c_str());
}
if ((ret = client->connect_app(req->app, tc_url, forward_server_srs ? req : NULL, debug_srs_upnode)) != ERROR_SUCCESS) {
srs_error("connect with server failed, tcUrl=%s, dsu=%d. ret=%d",
tc_url.c_str(), debug_srs_upnode, ret);
return ret;
... ...