1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

for #319, refine the config forward.

This commit is contained in:
winlin 2015-08-30 07:59:25 +08:00
parent bc24c0407b
commit 6bd05f9cfc
7 changed files with 119 additions and 45 deletions

View file

@ -44,7 +44,10 @@ vhost demo.srs.com {
enabled on; enabled on;
gop_cache on; gop_cache on;
queue_length 30; queue_length 30;
forward 127.0.0.1:19350; forward {
enabled on;
destination 127.0.0.1:19350;
}
bandcheck { bandcheck {
enabled off; enabled off;
} }

View file

@ -8,5 +8,8 @@ pid ./objs/srs.master.pid;
srs_log_tank file; srs_log_tank file;
srs_log_file ./objs/srs.master.log; srs_log_file ./objs/srs.master.log;
vhost __defaultVhost__ { vhost __defaultVhost__ {
forward 127.0.0.1:19350; forward {
enabled on;
destination 127.0.0.1:19350;
}
} }

View file

@ -268,33 +268,6 @@ vhost removed.srs.com {
# @see scope.vhost.srs.com # @see scope.vhost.srs.com
enabled off; enabled off;
} }
# the vhost for antisuck. # the vhost for antisuck.
vhost refer.anti_suck.com { vhost refer.anti_suck.com {
# refer hotlink-denial. # refer hotlink-denial.
@ -534,12 +507,46 @@ vhost stream.control.com {
# the vhost which forward publish streams. # the vhost which forward publish streams.
vhost same.vhost.forward.srs.com { vhost same.vhost.forward.srs.com {
# forward stream to other servers.
forward {
# whether enable the forward.
# default: off
enabled on;
# forward all publish stream to the specified server. # forward all publish stream to the specified server.
# this used to split/forward the current stream for cluster active-standby, # this used to split/forward the current stream for cluster active-standby,
# active-active for cdn to build high available fault tolerance system. # active-active for cdn to build high available fault tolerance system.
# format: {ip}:{port} {ip_N}:{port_N} # format: {ip}:{port} {ip_N}:{port_N}
forward 127.0.0.1:1936 127.0.0.1:1937; destination 127.0.0.1:1936 127.0.0.1:1937;
} }
}
# the vhost for exec, fork process when publish stream. # the vhost for exec, fork process when publish stream.
vhost exec.srs.com { vhost exec.srs.com {

View file

@ -62,8 +62,8 @@ vhost vhost.srs.com {
debug_srs_upnode off; debug_srs_upnode off;
} }
# TODO
forward { forward {
enabled off;
destination 127.0.0.1:1936 127.0.0.1:1937; destination 127.0.0.1:1936 127.0.0.1:1937;
} }

View file

@ -1575,7 +1575,7 @@ int SrsConfig::global_to_json(SrsAmf0Object* obj)
sobj->set("exec", SrsAmf0Any::boolean(get_exec_enabled(dir->name))); sobj->set("exec", SrsAmf0Any::boolean(get_exec_enabled(dir->name)));
sobj->set("bandcheck", SrsAmf0Any::boolean(get_bw_check_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("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("security", SrsAmf0Any::boolean(get_security_enabled(dir->name)));
sobj->set("refer", SrsAmf0Any::boolean(get_refer_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 // forward
if ((dir = vhost->get("forward")) != NULL) { 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 // debug_srs_upnode
@ -2705,15 +2716,14 @@ int SrsConfig::check_config()
} }
} }
} else if (n == "forward") { } 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(); 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; ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("unsupported vhost forward directive %s, ret=%d", m.c_str(), ret); srs_error("unsupported vhost forward directive %s, ret=%d", m.c_str(), ret);
return ret; return ret;
} }
}*/ }
} else if (n == "security") { } else if (n == "security") {
for (int j = 0; j < (int)conf->directives.size(); j++) { for (int j = 0; j < (int)conf->directives.size(); j++) {
SrsConfDirective* security = conf->at(j); SrsConfDirective* security = conf->at(j);
@ -3581,14 +3591,41 @@ int SrsConfig::get_global_chunk_size()
return ::atoi(conf->arg0().c_str()); 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); SrsConfDirective* conf = get_vhost(vhost);
if (!conf) { if (!conf) {
return NULL; 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) SrsConfDirective* SrsConfig::get_vhost_http_hooks(string vhost)
@ -5774,6 +5811,22 @@ int srs_config_transform_vhost(SrsConfDirective* root)
continue; 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; ++it;
} }
} }

View file

@ -598,10 +598,14 @@ private:
virtual int get_global_chunk_size(); virtual int get_global_chunk_size();
// forward section // forward section
public: public:
/**
* whether the forwarder enabled.
*/
virtual bool get_forward_enabled(std::string vhost);
/** /**
* get the forward directive of vhost. * get the forward directive of vhost.
*/ */
virtual SrsConfDirective* get_forward(std::string vhost); virtual SrsConfDirective* get_forwards(std::string vhost);
// http_hooks section // http_hooks section
private: private:
/** /**

View file

@ -2235,7 +2235,11 @@ int SrsSource::create_forwarders()
{ {
int ret = ERROR_SUCCESS; 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++) { for (int i = 0; conf && i < (int)conf->args.size(); i++) {
std::string forward_server = conf->args.at(i); std::string forward_server = conf->args.at(i);