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:
parent
bc24c0407b
commit
6bd05f9cfc
7 changed files with 119 additions and 45 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 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}
|
||||
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.
|
||||
vhost exec.srs.com {
|
||||
# the exec used to fork process when got some event.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue