胡斌

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() @@ -1822,7 +1822,7 @@ int SrsConfig::check_config()
1822 && n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks" 1822 && n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks"
1823 && n != "gop_cache" && n != "queue_length" 1823 && n != "gop_cache" && n != "queue_length"
1824 && n != "refer" && n != "refer_publish" && n != "refer_play" 1824 && n != "refer" && n != "refer_publish" && n != "refer_play"
1825 - && n != "forward" && n != "transcode" && n != "bandcheck" 1825 + && n != "forward" && n != "forward_server_srs" && n != "transcode" && n != "bandcheck"
1826 && n != "time_jitter" && n != "mix_correct" 1826 && n != "time_jitter" && n != "mix_correct"
1827 && n != "atc" && n != "atc_auto" 1827 && n != "atc" && n != "atc_auto"
1828 && n != "debug_srs_upnode" 1828 && n != "debug_srs_upnode"
@@ -1938,7 +1938,17 @@ int SrsConfig::check_config() @@ -1938,7 +1938,17 @@ int SrsConfig::check_config()
1938 return ret; 1938 return ret;
1939 } 1939 }
1940 }*/ 1940 }*/
1941 - } else if (n == "security") { 1941 + } else if (n == "forward_server_srs") {
  1942 + for (int j = 0; j < (int)conf->directives.size(); j++) {
  1943 + string m = conf->at(j)->name.c_str();
  1944 + if (m != "true" && m != "false") {
  1945 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1946 + srs_error("unsupported vhost forward_server_srs directive %s(only support true or flase), ret=%d", m.c_str(), ret);
  1947 + return ret;
  1948 + }
  1949 + }
  1950 + }
  1951 + else if (n == "security") {
1942 for (int j = 0; j < (int)conf->directives.size(); j++) { 1952 for (int j = 0; j < (int)conf->directives.size(); j++) {
1943 SrsConfDirective* security = conf->at(j); 1953 SrsConfDirective* security = conf->at(j);
1944 string m = security->name.c_str(); 1954 string m = security->name.c_str();
@@ -2745,6 +2755,22 @@ SrsConfDirective* SrsConfig::get_forward(string vhost) @@ -2745,6 +2755,22 @@ SrsConfDirective* SrsConfig::get_forward(string vhost)
2745 return conf->get("forward"); 2755 return conf->get("forward");
2746 } 2756 }
2747 2757
  2758 +bool SrsConfig::get_forward_server_srs(string vhost)
  2759 +{
  2760 + SrsConfDirective* conf = get_vhost(vhost);
  2761 +
  2762 + if (!conf) {
  2763 + return true;
  2764 + }
  2765 +
  2766 + conf = conf->get("forward_server_srs");
  2767 + if (!conf || conf->arg0().empty()) {
  2768 + return true;
  2769 + }
  2770 +
  2771 + return conf->arg0()=="true";
  2772 +}
  2773 +
2748 SrsConfDirective* SrsConfig::get_vhost_http_hooks(string vhost) 2774 SrsConfDirective* SrsConfig::get_vhost_http_hooks(string vhost)
2749 { 2775 {
2750 SrsConfDirective* conf = get_vhost(vhost); 2776 SrsConfDirective* conf = get_vhost(vhost);
@@ -569,6 +569,10 @@ public: @@ -569,6 +569,10 @@ public:
569 * get the forward directive of vhost. 569 * get the forward directive of vhost.
570 */ 570 */
571 virtual SrsConfDirective* get_forward(std::string vhost); 571 virtual SrsConfDirective* get_forward(std::string vhost);
  572 + /**
  573 + * get the forward server type of vhost,if srs return true,else false.
  574 + */
  575 + virtual bool get_forward_server_srs(std::string vhost);
572 // http_hooks section 576 // http_hooks section
573 private: 577 private:
574 /** 578 /**
@@ -235,10 +235,12 @@ int SrsForwarder::cycle() @@ -235,10 +235,12 @@ int SrsForwarder::cycle()
235 client->set_recv_timeout(SRS_CONSTS_RTMP_RECV_TIMEOUT_US); 235 client->set_recv_timeout(SRS_CONSTS_RTMP_RECV_TIMEOUT_US);
236 client->set_send_timeout(SRS_CONSTS_RTMP_SEND_TIMEOUT_US); 236 client->set_send_timeout(SRS_CONSTS_RTMP_SEND_TIMEOUT_US);
237 237
238 - if ((ret = client->handshake()) != ERROR_SUCCESS) {  
239 - srs_error("handshake with server failed. ret=%d", ret);  
240 - return ret;  
241 - } 238 + if ((ret = client->simple_handshake() != ERROR_SUCCESS)) {
  239 + if ((ret = client->handshake()) != ERROR_SUCCESS) {
  240 + srs_error("handshake with server failed. ret=%d", ret);
  241 + return ret;
  242 + }
  243 + }
242 if ((ret = connect_app(ep_server, ep_port)) != ERROR_SUCCESS) { 244 if ((ret = connect_app(ep_server, ep_port)) != ERROR_SUCCESS) {
243 srs_error("connect with server failed. ret=%d", ret); 245 srs_error("connect with server failed. ret=%d", ret);
244 return ret; 246 return ret;
@@ -373,7 +375,15 @@ int SrsForwarder::connect_app(string ep_server, string ep_port) @@ -373,7 +375,15 @@ int SrsForwarder::connect_app(string ep_server, string ep_port)
373 // @see https://github.com/ossrs/srs/issues/160 375 // @see https://github.com/ossrs/srs/issues/160
374 // the debug_srs_upnode is config in vhost and default to true. 376 // the debug_srs_upnode is config in vhost and default to true.
375 bool debug_srs_upnode = _srs_config->get_debug_srs_upnode(req->vhost); 377 bool debug_srs_upnode = _srs_config->get_debug_srs_upnode(req->vhost);
376 - if ((ret = client->connect_app(req->app, tc_url, req, debug_srs_upnode)) != ERROR_SUCCESS) { 378 +
  379 + //if forward_server is not srs,or srs compatible,don't send req when connect app,in case of be rejected
  380 + bool forward_server_srs = _srs_config->get_forward_server_srs(req->vhost);
  381 + if (!forward_server_srs) {
  382 + srs_trace("forward to srs incompatible server, tcUrl=%s,vhost:%s",
  383 + tc_url.c_str(), req->vhost.c_str());
  384 + }
  385 +
  386 + if ((ret = client->connect_app(req->app, tc_url, forward_server_srs ? req : NULL, debug_srs_upnode)) != ERROR_SUCCESS) {
377 srs_error("connect with server failed, tcUrl=%s, dsu=%d. ret=%d", 387 srs_error("connect with server failed, tcUrl=%s, dsu=%d. ret=%d",
378 tc_url.c_str(), debug_srs_upnode, ret); 388 tc_url.c_str(), debug_srs_upnode, ret);
379 return ret; 389 return ret;