diff --git a/trunk/conf/demo.conf b/trunk/conf/demo.conf index 60b80f5b6..546e9d4e4 100644 --- a/trunk/conf/demo.conf +++ b/trunk/conf/demo.conf @@ -44,7 +44,10 @@ vhost demo.srs.com { enabled on; gop_cache on; queue_length 30; - forward 127.0.0.1:19350; + forward { + enabled on; + destination 127.0.0.1:19350; + } bandcheck { enabled off; } diff --git a/trunk/conf/forward.master.conf b/trunk/conf/forward.master.conf index 18d9bc16f..d4256a8db 100644 --- a/trunk/conf/forward.master.conf +++ b/trunk/conf/forward.master.conf @@ -8,5 +8,8 @@ pid ./objs/srs.master.pid; srs_log_tank file; srs_log_file ./objs/srs.master.log; vhost __defaultVhost__ { - forward 127.0.0.1:19350; + forward { + enabled on; + destination 127.0.0.1:19350; + } } diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index adaea7d28..07d2e4dec 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -268,33 +268,6 @@ vhost removed.srs.com { # @see scope.vhost.srs.com enabled off; } - - - - - - - - - - - - - - - - - - - - - - - - - - - # the vhost for antisuck. vhost refer.anti_suck.com { # refer hotlink-denial. @@ -534,13 +507,47 @@ vhost stream.control.com { # the vhost which forward publish streams. vhost same.vhost.forward.srs.com { - # forward all publish stream to the specified server. - # this used to split/forward the current stream for cluster active-standby, - # active-active for cdn to build high available fault tolerance system. - # format: {ip}:{port} {ip_N}:{port_N} - forward 127.0.0.1:1936 127.0.0.1:1937; + # forward stream to other servers. + forward { + # whether enable the forward. + # default: off + enabled on; + # forward all publish stream to the specified server. + # this used to split/forward the current stream for cluster active-standby, + # active-active for cdn to build high available fault tolerance system. + # format: {ip}:{port} {ip_N}:{port_N} + destination 127.0.0.1:1936 127.0.0.1:1937; + } } + + + + + + + + + + + + + + + + + + + + + + + + + + + + # the vhost for exec, fork process when publish stream. vhost exec.srs.com { # the exec used to fork process when got some event. diff --git a/trunk/conf/full.one.vhost.conf b/trunk/conf/full.one.vhost.conf index a48372f68..94fe6d97f 100644 --- a/trunk/conf/full.one.vhost.conf +++ b/trunk/conf/full.one.vhost.conf @@ -62,8 +62,8 @@ vhost vhost.srs.com { debug_srs_upnode off; } - # TODO forward { + enabled off; destination 127.0.0.1:1936 127.0.0.1:1937; } diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 60e2513d5..1b14ae09b 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -1575,7 +1575,7 @@ int SrsConfig::global_to_json(SrsAmf0Object* obj) sobj->set("exec", SrsAmf0Any::boolean(get_exec_enabled(dir->name))); sobj->set("bandcheck", SrsAmf0Any::boolean(get_bw_check_enabled(dir->name))); sobj->set("origin", SrsAmf0Any::boolean(!get_vhost_is_edge(dir->name))); - sobj->set("forward", SrsAmf0Any::boolean(get_forward(dir->name))); + sobj->set("forward", SrsAmf0Any::boolean(get_forward_enabled(dir->name))); sobj->set("security", SrsAmf0Any::boolean(get_security_enabled(dir->name))); sobj->set("refer", SrsAmf0Any::boolean(get_refer_enabled(dir->name))); @@ -1679,7 +1679,18 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj) // forward if ((dir = vhost->get("forward")) != NULL) { - obj->set("forward", dir->dumps_args()); + SrsAmf0Object* forward = SrsAmf0Any::object(); + obj->set("forward", forward); + + for (int i = 0; i < (int)dir->directives.size(); i++) { + SrsConfDirective* sdir = dir->directives.at(i); + + if (sdir->name == "enabled") { + forward->set("enabled", sdir->dumps_arg0_to_boolean()); + } else if (sdir->name == "destination") { + forward->set("destination", sdir->dumps_args()); + } + } } // debug_srs_upnode @@ -2705,15 +2716,14 @@ int SrsConfig::check_config() } } } else if (n == "forward") { - // TODO: FIXME: implements it. - /*for (int j = 0; j < (int)conf->directives.size(); j++) { + for (int j = 0; j < (int)conf->directives.size(); j++) { string m = conf->at(j)->name.c_str(); - if (m != "enabled" && m != "vhost" && m != "refer") { + if (m != "enabled" && m != "destination") { ret = ERROR_SYSTEM_CONFIG_INVALID; srs_error("unsupported vhost forward directive %s, 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); @@ -3581,14 +3591,41 @@ int SrsConfig::get_global_chunk_size() return ::atoi(conf->arg0().c_str()); } -SrsConfDirective* SrsConfig::get_forward(string vhost) +bool SrsConfig::get_forward_enabled(string vhost) +{ + static bool DEFAULT = false; + + SrsConfDirective* conf = get_vhost(vhost); + if (!conf) { + return DEFAULT; + } + + conf = conf->get("forward"); + if (!conf) { + return DEFAULT; + } + + conf = conf->get("enabled"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + + return SRS_CONF_PERFER_FALSE(conf->arg0()); +} + +SrsConfDirective* SrsConfig::get_forwards(string vhost) { SrsConfDirective* conf = get_vhost(vhost); if (!conf) { return NULL; } - return conf->get("forward"); + conf = conf->get("forward"); + if (!conf) { + return NULL; + } + + return conf->get("destination"); } SrsConfDirective* SrsConfig::get_vhost_http_hooks(string vhost) @@ -5774,6 +5811,22 @@ int srs_config_transform_vhost(SrsConfDirective* root) continue; } + // SRS3.0, change the forward. + // SRS1/2: + // vhost { forward; } + // SRS3+: + // vhost { forward { enabled; destination; } } + if (n == "forward") { + conf->get_or_create("enabled", "on"); + + SrsConfDirective* destination = conf->get_or_create("destination"); + destination->args = conf->args; + conf->args.clear(); + + ++it; + continue; + } + ++it; } } diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 75b388a20..4ba2381c5 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -598,10 +598,14 @@ private: virtual int get_global_chunk_size(); // forward section public: + /** + * whether the forwarder enabled. + */ + virtual bool get_forward_enabled(std::string vhost); /** * get the forward directive of vhost. */ - virtual SrsConfDirective* get_forward(std::string vhost); + virtual SrsConfDirective* get_forwards(std::string vhost); // http_hooks section private: /** diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index a68a5865a..2d4d8cc14 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -2235,7 +2235,11 @@ int SrsSource::create_forwarders() { int ret = ERROR_SUCCESS; - SrsConfDirective* conf = _srs_config->get_forward(_req->vhost); + if (_srs_config->get_forward_enabled(_req->vhost)) { + return ret; + } + + SrsConfDirective* conf = _srs_config->get_forwards(_req->vhost); for (int i = 0; conf && i < (int)conf->args.size(); i++) { std::string forward_server = conf->args.at(i);