winlin

for #319, move the edge configs to cluster.

@@ -7,6 +7,8 @@ max_connections 1000; @@ -7,6 +7,8 @@ max_connections 1000;
7 pid objs/edge.pid; 7 pid objs/edge.pid;
8 srs_log_file ./objs/edge.log; 8 srs_log_file ./objs/edge.log;
9 vhost __defaultVhost__ { 9 vhost __defaultVhost__ {
10 - mode remote;  
11 - origin 127.0.0.1:19350; 10 + cluster {
  11 + mode remote;
  12 + origin 127.0.0.1:19350;
  13 + }
12 } 14 }
@@ -5,7 +5,9 @@ @@ -5,7 +5,9 @@
5 listen 1935 5 listen 1935
6 max_connections 1000; 6 max_connections 1000;
7 vhost __defaultVhost__ { 7 vhost __defaultVhost__ {
8 - mode remote;  
9 - origin 127.0.0.1:19350;  
10 - token_traverse on; 8 + cluster {
  9 + mode remote;
  10 + origin 127.0.0.1:19350;
  11 + token_traverse on;
  12 + }
11 } 13 }
@@ -520,6 +520,73 @@ vhost same.vhost.forward.srs.com { @@ -520,6 +520,73 @@ vhost same.vhost.forward.srs.com {
520 } 520 }
521 } 521 }
522 522
  523 +# vhost for stream cluster for RTMP/FLV
  524 +vhost cluster.srs.com {
  525 + # stream RTMP/FLV cluster config.
  526 + cluster {
  527 + # the mode of vhost, local or remote.
  528 + # local: vhost is origin vhost, which provides stream source.
  529 + # remote: vhost is edge vhost, which pull/push to origin.
  530 + # default: local
  531 + mode remote;
  532 + # for edge(remote mode), user must specifies the origin server
  533 + # format as: <server_name|ip>[:port]
  534 + # @remark user can specifies multiple origin for error backup, by space,
  535 + # for example, 192.168.1.100:1935 192.168.1.101:1935 192.168.1.102:1935
  536 + origin 127.0.0.1:1935 localhost:1935;
  537 +
  538 + # for edge, whether open the token traverse mode,
  539 + # if token traverse on, all connections of edge will forward to origin to check(auth),
  540 + # it's very important for the edge to do the token auth.
  541 + # the better way is use http callback to do the token auth by the edge,
  542 + # but if user prefer origin check(auth), the token_traverse if better solution.
  543 + # default: off
  544 + token_traverse off;
  545 +
  546 + # the vhost to transform for edge,
  547 + # to fetch from the specified vhost at origin,
  548 + # if not specified, use the current vhost of edge in origin, the variable [vhost].
  549 + # default: [vhost]
  550 + vhost same.edge.srs.com;
  551 +
  552 + # when upnode(forward to, edge push to, edge pull from) is srs,
  553 + # it's strongly recommend to open the debug_srs_upnode,
  554 + # when connect to upnode, it will take the debug info,
  555 + # for example, the id, source id, pid.
  556 + # please see: https://github.com/simple-rtmp-server/srs/wiki/v1_CN_SrsLog
  557 + # default: on
  558 + debug_srs_upnode on;
  559 + }
  560 +}
  561 +
  562 +# vhost for edge, edge and origin is the same vhost
  563 +vhost same.edge.srs.com {
  564 + # @see cluster.srs.com
  565 + cluster {
  566 + mode remote;
  567 + origin 127.0.0.1:1935 localhost:1935;
  568 + token_traverse off;
  569 + }
  570 +}
  571 +
  572 +# vhost for edge, edge transform vhost to fetch from another vhost.
  573 +vhost transform.edge.srs.com {
  574 + # @see cluster.srs.com
  575 + cluster {
  576 + mode remote;
  577 + origin 127.0.0.1:1935;
  578 + vhost same.edge.srs.com;
  579 + }
  580 +}
  581 +
  582 +# the vhost for srs debug info, whether send args in connect(tcUrl).
  583 +vhost debug.srs.com {
  584 + # @see cluster.srs.com
  585 + cluster {
  586 + debug_srs_upnode on;
  587 + }
  588 +}
  589 +
523 590
524 591
525 592
@@ -600,38 +667,6 @@ vhost security.srs.com { @@ -600,38 +667,6 @@ vhost security.srs.com {
600 } 667 }
601 } 668 }
602 669
603 -# vhost for edge, edge and origin is the same vhost  
604 -vhost same.edge.srs.com {  
605 - # the mode of vhost, local or remote.  
606 - # local: vhost is origin vhost, which provides stream source.  
607 - # remote: vhost is edge vhost, which pull/push to origin.  
608 - # default: local  
609 - mode remote;  
610 - # for edge(remote mode), user must specifies the origin server  
611 - # format as: <server_name|ip>[:port]  
612 - # @remark user can specifies multiple origin for error backup, by space,  
613 - # for example, 192.168.1.100:1935 192.168.1.101:1935 192.168.1.102:1935  
614 - origin 127.0.0.1:1935 localhost:1935;  
615 - # for edge, whether open the token traverse mode,  
616 - # if token traverse on, all connections of edge will forward to origin to check(auth),  
617 - # it's very important for the edge to do the token auth.  
618 - # the better way is use http callback to do the token auth by the edge,  
619 - # but if user prefer origin check(auth), the token_traverse if better solution.  
620 - # default: off  
621 - token_traverse off;  
622 -}  
623 -  
624 -# vhost for edge, edge transform vhost to fetch from another vhost.  
625 -vhost transform.edge.srs.com {  
626 - mode remote;  
627 - origin 127.0.0.1:1935;  
628 - # the vhost to transform for edge,  
629 - # to fetch from the specified vhost at origin,  
630 - # if not specified, use the current vhost of edge in origin, the variable [vhost].  
631 - # default: [vhost]  
632 - vhost same.edge.srs.com;  
633 -}  
634 -  
635 # vhost for dvr 670 # vhost for dvr
636 vhost dvr.srs.com { 671 vhost dvr.srs.com {
637 # dvr RTMP stream to file, 672 # dvr RTMP stream to file,
@@ -1187,17 +1222,6 @@ vhost hooks.callback.srs.com { @@ -1187,17 +1222,6 @@ vhost hooks.callback.srs.com {
1187 } 1222 }
1188 } 1223 }
1189 1224
1190 -# the vhost for srs debug info, whether send args in connect(tcUrl).  
1191 -vhost debug.srs.com {  
1192 - # when upnode(forward to, edge push to, edge pull from) is srs,  
1193 - # it's strongly recommend to open the debug_srs_upnode,  
1194 - # when connect to upnode, it will take the debug info,  
1195 - # for example, the id, source id, pid.  
1196 - # please see: https://github.com/simple-rtmp-server/srs/wiki/v1_CN_SrsLog  
1197 - # default: on  
1198 - debug_srs_upnode on;  
1199 -}  
1200 -  
1201 # the main comments for transcode 1225 # the main comments for transcode
1202 vhost example.transcode.srs.com { 1226 vhost example.transcode.srs.com {
1203 # the streaming transcode configs. 1227 # the streaming transcode configs.
@@ -615,6 +615,9 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) @@ -615,6 +615,9 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
615 // merge config. 615 // merge config.
616 std::vector<ISrsReloadHandler*>::iterator it; 616 std::vector<ISrsReloadHandler*>::iterator it;
617 617
  618 + // following directly support reload.
  619 + // origin, token_traverse, vhost, debug_srs_upnode
  620 +
618 // state graph 621 // state graph
619 // old_vhost new_vhost 622 // old_vhost new_vhost
620 // DISABLED => ENABLED 623 // DISABLED => ENABLED
@@ -679,7 +682,7 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) @@ -679,7 +682,7 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
679 continue; 682 continue;
680 } 683 }
681 684
682 - // mode, never supports reload. 685 + // cluster.mode, never supports reload.
683 // first, for the origin and edge role change is too complex. 686 // first, for the origin and edge role change is too complex.
684 // second, the vhosts in origin device group normally are all origin, 687 // second, the vhosts in origin device group normally are all origin,
685 // they never change to edge sometimes. 688 // they never change to edge sometimes.
@@ -877,8 +880,7 @@ int SrsConfig::reload_conf(SrsConfig* conf) @@ -877,8 +880,7 @@ int SrsConfig::reload_conf(SrsConfig* conf)
877 // 880 //
878 // always support reload without additional code: 881 // always support reload without additional code:
879 // chunk_size, ff_log_dir, 882 // chunk_size, ff_log_dir,
880 - // bandcheck, http_hooks, heartbeat,  
881 - // token_traverse, debug_srs_upnode, 883 + // bandcheck, http_hooks, heartbeat,
882 // security 884 // security
883 885
884 // merge config: max_connections 886 // merge config: max_connections
@@ -1663,18 +1665,26 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj) @@ -1663,18 +1665,26 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj)
1663 obj->set("tcp_nodelay", dir->dumps_arg0_to_boolean()); 1665 obj->set("tcp_nodelay", dir->dumps_arg0_to_boolean());
1664 } 1666 }
1665 1667
1666 - // edge.  
1667 - if ((dir = vhost->get("mode")) != NULL) {  
1668 - obj->set("mode", dir->dumps_arg0_to_str());  
1669 - }  
1670 - if ((dir = vhost->get("origin")) != NULL) {  
1671 - obj->set("origin", dir->dumps_args());  
1672 - }  
1673 - if ((dir = vhost->get("token_traverse")) != NULL) {  
1674 - obj->set("token_traverse", dir->dumps_arg0_to_boolean());  
1675 - }  
1676 - if ((dir = vhost->get("vhost")) != NULL) {  
1677 - obj->set("vhost", dir->dumps_arg0_to_str()); 1668 + // cluster.
  1669 + if ((dir = vhost->get("cluster")) != NULL) {
  1670 + SrsAmf0Object* cluster = SrsAmf0Any::object();
  1671 + obj->set("cluster", cluster);
  1672 +
  1673 + for (int i = 0; i < (int)dir->directives.size(); i++) {
  1674 + SrsConfDirective* sdir = dir->directives.at(i);
  1675 +
  1676 + if (sdir->name == "mode") {
  1677 + cluster->set("mode", sdir->dumps_arg0_to_str());
  1678 + } else if (sdir->name == "origin") {
  1679 + cluster->set("origin", sdir->dumps_arg0_to_str());
  1680 + } else if (sdir->name == "token_traverse") {
  1681 + cluster->set("token_traverse", sdir->dumps_arg0_to_boolean());
  1682 + } else if (sdir->name == "vhost") {
  1683 + cluster->set("vhost", sdir->dumps_arg0_to_str());
  1684 + } else if (sdir->name == "debug_srs_upnode") {
  1685 + cluster->set("debug_srs_upnode", sdir->dumps_arg0_to_boolean());
  1686 + }
  1687 + }
1678 } 1688 }
1679 1689
1680 // forward 1690 // forward
@@ -1693,11 +1703,6 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj) @@ -1693,11 +1703,6 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj)
1693 } 1703 }
1694 } 1704 }
1695 1705
1696 - // debug_srs_upnode  
1697 - if ((dir = vhost->get("debug_srs_upnode")) != NULL) {  
1698 - obj->set("debug_srs_upnode", dir->dumps_arg0_to_boolean());  
1699 - }  
1700 -  
1701 // play 1706 // play
1702 if ((dir = vhost->get("play")) != NULL) { 1707 if ((dir = vhost->get("play")) != NULL) {
1703 SrsAmf0Object* play = SrsAmf0Any::object(); 1708 SrsAmf0Object* play = SrsAmf0Any::object();
@@ -2602,10 +2607,9 @@ int SrsConfig::check_config() @@ -2602,10 +2607,9 @@ int SrsConfig::check_config()
2602 SrsConfDirective* conf = vhost->at(i); 2607 SrsConfDirective* conf = vhost->at(i);
2603 string n = conf->name; 2608 string n = conf->name;
2604 if (n != "enabled" && n != "chunk_size" && n != "min_latency" && n != "tcp_nodelay" 2609 if (n != "enabled" && n != "chunk_size" && n != "min_latency" && n != "tcp_nodelay"
2605 - && n != "mode" && n != "origin" && n != "token_traverse" && n != "vhost"  
2606 && n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks" 2610 && n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks"
2607 && n != "refer" && n != "forward" && n != "transcode" && n != "bandcheck" 2611 && n != "refer" && n != "forward" && n != "transcode" && n != "bandcheck"
2608 - && n != "debug_srs_upnode" && n != "play" && n != "publish" 2612 + && n != "play" && n != "publish" && n != "cluster"
2609 && n != "security" && n != "http_remux" 2613 && n != "security" && n != "http_remux"
2610 && n != "http_static" && n != "hds" && n != "exec" 2614 && n != "http_static" && n != "hds" && n != "exec"
2611 ) { 2615 ) {
@@ -2654,6 +2658,15 @@ int SrsConfig::check_config() @@ -2654,6 +2658,15 @@ int SrsConfig::check_config()
2654 return ret; 2658 return ret;
2655 } 2659 }
2656 } 2660 }
  2661 + } else if (n == "cluster") {
  2662 + for (int j = 0; j < (int)conf->directives.size(); j++) {
  2663 + string m = conf->at(j)->name.c_str();
  2664 + if (m != "mode" && m != "origin" && m != "token_traverse" && m != "vhost" && m != "debug_srs_upnode") {
  2665 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  2666 + srs_error("unsupported vhost cluster directive %s, ret=%d", m.c_str(), ret);
  2667 + return ret;
  2668 + }
  2669 + }
2657 } else if (n == "publish") { 2670 } else if (n == "publish") {
2658 for (int j = 0; j < (int)conf->directives.size(); j++) { 2671 for (int j = 0; j < (int)conf->directives.size(); j++) {
2659 string m = conf->at(j)->name.c_str(); 2672 string m = conf->at(j)->name.c_str();
@@ -3185,6 +3198,11 @@ bool SrsConfig::get_debug_srs_upnode(string vhost) @@ -3185,6 +3198,11 @@ bool SrsConfig::get_debug_srs_upnode(string vhost)
3185 return DEFAULT; 3198 return DEFAULT;
3186 } 3199 }
3187 3200
  3201 + conf = conf->get("cluster");
  3202 + if (!conf || conf->arg0().empty()) {
  3203 + return DEFAULT;
  3204 + }
  3205 +
3188 conf = conf->get("debug_srs_upnode"); 3206 conf = conf->get("debug_srs_upnode");
3189 if (!conf || conf->arg0().empty()) { 3207 if (!conf || conf->arg0().empty()) {
3190 return DEFAULT; 3208 return DEFAULT;
@@ -3847,6 +3865,11 @@ bool SrsConfig::get_vhost_is_edge(SrsConfDirective* vhost) @@ -3847,6 +3865,11 @@ bool SrsConfig::get_vhost_is_edge(SrsConfDirective* vhost)
3847 if (!conf) { 3865 if (!conf) {
3848 return DEFAULT; 3866 return DEFAULT;
3849 } 3867 }
  3868 +
  3869 + conf = conf->get("cluster");
  3870 + if (!conf || conf->arg0().empty()) {
  3871 + return DEFAULT;
  3872 + }
3850 3873
3851 conf = conf->get("mode"); 3874 conf = conf->get("mode");
3852 if (!conf || conf->arg0().empty()) { 3875 if (!conf || conf->arg0().empty()) {
@@ -3863,6 +3886,11 @@ SrsConfDirective* SrsConfig::get_vhost_edge_origin(string vhost) @@ -3863,6 +3886,11 @@ SrsConfDirective* SrsConfig::get_vhost_edge_origin(string vhost)
3863 return NULL; 3886 return NULL;
3864 } 3887 }
3865 3888
  3889 + conf = conf->get("cluster");
  3890 + if (!conf || conf->arg0().empty()) {
  3891 + return NULL;
  3892 + }
  3893 +
3866 return conf->get("origin"); 3894 return conf->get("origin");
3867 } 3895 }
3868 3896
@@ -3875,6 +3903,11 @@ bool SrsConfig::get_vhost_edge_token_traverse(string vhost) @@ -3875,6 +3903,11 @@ bool SrsConfig::get_vhost_edge_token_traverse(string vhost)
3875 return DEFAULT; 3903 return DEFAULT;
3876 } 3904 }
3877 3905
  3906 + conf = conf->get("cluster");
  3907 + if (!conf || conf->arg0().empty()) {
  3908 + return DEFAULT;
  3909 + }
  3910 +
3878 conf = conf->get("token_traverse"); 3911 conf = conf->get("token_traverse");
3879 if (!conf || conf->arg0().empty()) { 3912 if (!conf || conf->arg0().empty()) {
3880 return DEFAULT; 3913 return DEFAULT;
@@ -3892,6 +3925,11 @@ string SrsConfig::get_vhost_edge_transform_vhost(string vhost) @@ -3892,6 +3925,11 @@ string SrsConfig::get_vhost_edge_transform_vhost(string vhost)
3892 return DEFAULT; 3925 return DEFAULT;
3893 } 3926 }
3894 3927
  3928 + conf = conf->get("cluster");
  3929 + if (!conf || conf->arg0().empty()) {
  3930 + return DEFAULT;
  3931 + }
  3932 +
3895 conf = conf->get("vhost"); 3933 conf = conf->get("vhost");
3896 if (!conf || conf->arg0().empty()) { 3934 if (!conf || conf->arg0().empty()) {
3897 return DEFAULT; 3935 return DEFAULT;
@@ -5827,6 +5865,23 @@ int srs_config_transform_vhost(SrsConfDirective* root) @@ -5827,6 +5865,23 @@ int srs_config_transform_vhost(SrsConfDirective* root)
5827 continue; 5865 continue;
5828 } 5866 }
5829 5867
  5868 + // SRS3.0, change the folowing like a shadow:
  5869 + // mode, origin, token_traverse, vhost, debug_srs_upnode
  5870 + // SRS1/2:
  5871 + // vhost { shadow; }
  5872 + // SRS3+:
  5873 + // vhost { cluster { shadow; } }
  5874 + if (n == "mode" || n == "origin" || n == "token_traverse" || n == "vhost" || n == "debug_srs_upnode") {
  5875 + it = dir->directives.erase(it);
  5876 +
  5877 + SrsConfDirective* cluster = dir->get_or_create("cluster");
  5878 + SrsConfDirective* shadow = cluster->get_or_create(conf->name);
  5879 + shadow->args = conf->args;
  5880 +
  5881 + srs_freep(conf);
  5882 + continue;
  5883 + }
  5884 +
5830 ++it; 5885 ++it;
5831 } 5886 }
5832 } 5887 }
@@ -688,7 +688,7 @@ public: @@ -688,7 +688,7 @@ public:
688 * @remark this is used to protect the service bandwidth. 688 * @remark this is used to protect the service bandwidth.
689 */ 689 */
690 virtual int get_bw_check_limit_kbps(std::string vhost); 690 virtual int get_bw_check_limit_kbps(std::string vhost);
691 -// vhost edge section 691 +// vhost cluster section
692 public: 692 public:
693 /** 693 /**
694 * whether vhost is edge mode. 694 * whether vhost is edge mode.