正在显示
7 个修改的文件
包含
119 行增加
和
45 行删除
| @@ -44,7 +44,10 @@ vhost demo.srs.com { | @@ -44,7 +44,10 @@ vhost demo.srs.com { | ||
| 44 | enabled on; | 44 | enabled on; |
| 45 | gop_cache on; | 45 | gop_cache on; |
| 46 | queue_length 30; | 46 | queue_length 30; |
| 47 | - forward 127.0.0.1:19350; | 47 | + forward { |
| 48 | + enabled on; | ||
| 49 | + destination 127.0.0.1:19350; | ||
| 50 | + } | ||
| 48 | bandcheck { | 51 | bandcheck { |
| 49 | enabled off; | 52 | enabled off; |
| 50 | } | 53 | } |
| @@ -8,5 +8,8 @@ pid ./objs/srs.master.pid; | @@ -8,5 +8,8 @@ pid ./objs/srs.master.pid; | ||
| 8 | srs_log_tank file; | 8 | srs_log_tank file; |
| 9 | srs_log_file ./objs/srs.master.log; | 9 | srs_log_file ./objs/srs.master.log; |
| 10 | vhost __defaultVhost__ { | 10 | vhost __defaultVhost__ { |
| 11 | - forward 127.0.0.1:19350; | 11 | + forward { |
| 12 | + enabled on; | ||
| 13 | + destination 127.0.0.1:19350; | ||
| 14 | + } | ||
| 12 | } | 15 | } |
| @@ -268,33 +268,6 @@ vhost removed.srs.com { | @@ -268,33 +268,6 @@ vhost removed.srs.com { | ||
| 268 | # @see scope.vhost.srs.com | 268 | # @see scope.vhost.srs.com |
| 269 | enabled off; | 269 | enabled off; |
| 270 | } | 270 | } |
| 271 | - | ||
| 272 | - | ||
| 273 | - | ||
| 274 | - | ||
| 275 | - | ||
| 276 | - | ||
| 277 | - | ||
| 278 | - | ||
| 279 | - | ||
| 280 | - | ||
| 281 | - | ||
| 282 | - | ||
| 283 | - | ||
| 284 | - | ||
| 285 | - | ||
| 286 | - | ||
| 287 | - | ||
| 288 | - | ||
| 289 | - | ||
| 290 | - | ||
| 291 | - | ||
| 292 | - | ||
| 293 | - | ||
| 294 | - | ||
| 295 | - | ||
| 296 | - | ||
| 297 | - | ||
| 298 | # the vhost for antisuck. | 271 | # the vhost for antisuck. |
| 299 | vhost refer.anti_suck.com { | 272 | vhost refer.anti_suck.com { |
| 300 | # refer hotlink-denial. | 273 | # refer hotlink-denial. |
| @@ -534,13 +507,47 @@ vhost stream.control.com { | @@ -534,13 +507,47 @@ vhost stream.control.com { | ||
| 534 | 507 | ||
| 535 | # the vhost which forward publish streams. | 508 | # the vhost which forward publish streams. |
| 536 | vhost same.vhost.forward.srs.com { | 509 | vhost same.vhost.forward.srs.com { |
| 537 | - # forward all publish stream to the specified server. | ||
| 538 | - # this used to split/forward the current stream for cluster active-standby, | ||
| 539 | - # active-active for cdn to build high available fault tolerance system. | ||
| 540 | - # format: {ip}:{port} {ip_N}:{port_N} | ||
| 541 | - forward 127.0.0.1:1936 127.0.0.1:1937; | 510 | + # forward stream to other servers. |
| 511 | + forward { | ||
| 512 | + # whether enable the forward. | ||
| 513 | + # default: off | ||
| 514 | + enabled on; | ||
| 515 | + # forward all publish stream to the specified server. | ||
| 516 | + # this used to split/forward the current stream for cluster active-standby, | ||
| 517 | + # active-active for cdn to build high available fault tolerance system. | ||
| 518 | + # format: {ip}:{port} {ip_N}:{port_N} | ||
| 519 | + destination 127.0.0.1:1936 127.0.0.1:1937; | ||
| 520 | + } | ||
| 542 | } | 521 | } |
| 543 | 522 | ||
| 523 | + | ||
| 524 | + | ||
| 525 | + | ||
| 526 | + | ||
| 527 | + | ||
| 528 | + | ||
| 529 | + | ||
| 530 | + | ||
| 531 | + | ||
| 532 | + | ||
| 533 | + | ||
| 534 | + | ||
| 535 | + | ||
| 536 | + | ||
| 537 | + | ||
| 538 | + | ||
| 539 | + | ||
| 540 | + | ||
| 541 | + | ||
| 542 | + | ||
| 543 | + | ||
| 544 | + | ||
| 545 | + | ||
| 546 | + | ||
| 547 | + | ||
| 548 | + | ||
| 549 | + | ||
| 550 | + | ||
| 544 | # the vhost for exec, fork process when publish stream. | 551 | # the vhost for exec, fork process when publish stream. |
| 545 | vhost exec.srs.com { | 552 | vhost exec.srs.com { |
| 546 | # the exec used to fork process when got some event. | 553 | # the exec used to fork process when got some event. |
| @@ -62,8 +62,8 @@ vhost vhost.srs.com { | @@ -62,8 +62,8 @@ vhost vhost.srs.com { | ||
| 62 | debug_srs_upnode off; | 62 | debug_srs_upnode off; |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | - # TODO | ||
| 66 | forward { | 65 | forward { |
| 66 | + enabled off; | ||
| 67 | destination 127.0.0.1:1936 127.0.0.1:1937; | 67 | destination 127.0.0.1:1936 127.0.0.1:1937; |
| 68 | } | 68 | } |
| 69 | 69 |
| @@ -1575,7 +1575,7 @@ int SrsConfig::global_to_json(SrsAmf0Object* obj) | @@ -1575,7 +1575,7 @@ int SrsConfig::global_to_json(SrsAmf0Object* obj) | ||
| 1575 | sobj->set("exec", SrsAmf0Any::boolean(get_exec_enabled(dir->name))); | 1575 | sobj->set("exec", SrsAmf0Any::boolean(get_exec_enabled(dir->name))); |
| 1576 | sobj->set("bandcheck", SrsAmf0Any::boolean(get_bw_check_enabled(dir->name))); | 1576 | sobj->set("bandcheck", SrsAmf0Any::boolean(get_bw_check_enabled(dir->name))); |
| 1577 | sobj->set("origin", SrsAmf0Any::boolean(!get_vhost_is_edge(dir->name))); | 1577 | sobj->set("origin", SrsAmf0Any::boolean(!get_vhost_is_edge(dir->name))); |
| 1578 | - sobj->set("forward", SrsAmf0Any::boolean(get_forward(dir->name))); | 1578 | + sobj->set("forward", SrsAmf0Any::boolean(get_forward_enabled(dir->name))); |
| 1579 | 1579 | ||
| 1580 | sobj->set("security", SrsAmf0Any::boolean(get_security_enabled(dir->name))); | 1580 | sobj->set("security", SrsAmf0Any::boolean(get_security_enabled(dir->name))); |
| 1581 | sobj->set("refer", SrsAmf0Any::boolean(get_refer_enabled(dir->name))); | 1581 | sobj->set("refer", SrsAmf0Any::boolean(get_refer_enabled(dir->name))); |
| @@ -1679,7 +1679,18 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj) | @@ -1679,7 +1679,18 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj) | ||
| 1679 | 1679 | ||
| 1680 | // forward | 1680 | // forward |
| 1681 | if ((dir = vhost->get("forward")) != NULL) { | 1681 | if ((dir = vhost->get("forward")) != NULL) { |
| 1682 | - obj->set("forward", dir->dumps_args()); | 1682 | + SrsAmf0Object* forward = SrsAmf0Any::object(); |
| 1683 | + obj->set("forward", forward); | ||
| 1684 | + | ||
| 1685 | + for (int i = 0; i < (int)dir->directives.size(); i++) { | ||
| 1686 | + SrsConfDirective* sdir = dir->directives.at(i); | ||
| 1687 | + | ||
| 1688 | + if (sdir->name == "enabled") { | ||
| 1689 | + forward->set("enabled", sdir->dumps_arg0_to_boolean()); | ||
| 1690 | + } else if (sdir->name == "destination") { | ||
| 1691 | + forward->set("destination", sdir->dumps_args()); | ||
| 1692 | + } | ||
| 1693 | + } | ||
| 1683 | } | 1694 | } |
| 1684 | 1695 | ||
| 1685 | // debug_srs_upnode | 1696 | // debug_srs_upnode |
| @@ -2705,15 +2716,14 @@ int SrsConfig::check_config() | @@ -2705,15 +2716,14 @@ int SrsConfig::check_config() | ||
| 2705 | } | 2716 | } |
| 2706 | } | 2717 | } |
| 2707 | } else if (n == "forward") { | 2718 | } else if (n == "forward") { |
| 2708 | - // TODO: FIXME: implements it. | ||
| 2709 | - /*for (int j = 0; j < (int)conf->directives.size(); j++) { | 2719 | + for (int j = 0; j < (int)conf->directives.size(); j++) { |
| 2710 | string m = conf->at(j)->name.c_str(); | 2720 | string m = conf->at(j)->name.c_str(); |
| 2711 | - if (m != "enabled" && m != "vhost" && m != "refer") { | 2721 | + if (m != "enabled" && m != "destination") { |
| 2712 | ret = ERROR_SYSTEM_CONFIG_INVALID; | 2722 | ret = ERROR_SYSTEM_CONFIG_INVALID; |
| 2713 | srs_error("unsupported vhost forward directive %s, ret=%d", m.c_str(), ret); | 2723 | srs_error("unsupported vhost forward directive %s, ret=%d", m.c_str(), ret); |
| 2714 | return ret; | 2724 | return ret; |
| 2715 | } | 2725 | } |
| 2716 | - }*/ | 2726 | + } |
| 2717 | } else if (n == "security") { | 2727 | } else if (n == "security") { |
| 2718 | for (int j = 0; j < (int)conf->directives.size(); j++) { | 2728 | for (int j = 0; j < (int)conf->directives.size(); j++) { |
| 2719 | SrsConfDirective* security = conf->at(j); | 2729 | SrsConfDirective* security = conf->at(j); |
| @@ -3581,14 +3591,41 @@ int SrsConfig::get_global_chunk_size() | @@ -3581,14 +3591,41 @@ int SrsConfig::get_global_chunk_size() | ||
| 3581 | return ::atoi(conf->arg0().c_str()); | 3591 | return ::atoi(conf->arg0().c_str()); |
| 3582 | } | 3592 | } |
| 3583 | 3593 | ||
| 3584 | -SrsConfDirective* SrsConfig::get_forward(string vhost) | 3594 | +bool SrsConfig::get_forward_enabled(string vhost) |
| 3585 | { | 3595 | { |
| 3596 | + static bool DEFAULT = false; | ||
| 3597 | + | ||
| 3586 | SrsConfDirective* conf = get_vhost(vhost); | 3598 | SrsConfDirective* conf = get_vhost(vhost); |
| 3587 | if (!conf) { | 3599 | if (!conf) { |
| 3600 | + return DEFAULT; | ||
| 3601 | + } | ||
| 3602 | + | ||
| 3603 | + conf = conf->get("forward"); | ||
| 3604 | + if (!conf) { | ||
| 3605 | + return DEFAULT; | ||
| 3606 | + } | ||
| 3607 | + | ||
| 3608 | + conf = conf->get("enabled"); | ||
| 3609 | + if (!conf || conf->arg0().empty()) { | ||
| 3610 | + return DEFAULT; | ||
| 3611 | + } | ||
| 3612 | + | ||
| 3613 | + return SRS_CONF_PERFER_FALSE(conf->arg0()); | ||
| 3614 | +} | ||
| 3615 | + | ||
| 3616 | +SrsConfDirective* SrsConfig::get_forwards(string vhost) | ||
| 3617 | +{ | ||
| 3618 | + SrsConfDirective* conf = get_vhost(vhost); | ||
| 3619 | + if (!conf) { | ||
| 3620 | + return NULL; | ||
| 3621 | + } | ||
| 3622 | + | ||
| 3623 | + conf = conf->get("forward"); | ||
| 3624 | + if (!conf) { | ||
| 3588 | return NULL; | 3625 | return NULL; |
| 3589 | } | 3626 | } |
| 3590 | 3627 | ||
| 3591 | - return conf->get("forward"); | 3628 | + return conf->get("destination"); |
| 3592 | } | 3629 | } |
| 3593 | 3630 | ||
| 3594 | SrsConfDirective* SrsConfig::get_vhost_http_hooks(string vhost) | 3631 | SrsConfDirective* SrsConfig::get_vhost_http_hooks(string vhost) |
| @@ -5774,6 +5811,22 @@ int srs_config_transform_vhost(SrsConfDirective* root) | @@ -5774,6 +5811,22 @@ int srs_config_transform_vhost(SrsConfDirective* root) | ||
| 5774 | continue; | 5811 | continue; |
| 5775 | } | 5812 | } |
| 5776 | 5813 | ||
| 5814 | + // SRS3.0, change the forward. | ||
| 5815 | + // SRS1/2: | ||
| 5816 | + // vhost { forward; } | ||
| 5817 | + // SRS3+: | ||
| 5818 | + // vhost { forward { enabled; destination; } } | ||
| 5819 | + if (n == "forward") { | ||
| 5820 | + conf->get_or_create("enabled", "on"); | ||
| 5821 | + | ||
| 5822 | + SrsConfDirective* destination = conf->get_or_create("destination"); | ||
| 5823 | + destination->args = conf->args; | ||
| 5824 | + conf->args.clear(); | ||
| 5825 | + | ||
| 5826 | + ++it; | ||
| 5827 | + continue; | ||
| 5828 | + } | ||
| 5829 | + | ||
| 5777 | ++it; | 5830 | ++it; |
| 5778 | } | 5831 | } |
| 5779 | } | 5832 | } |
| @@ -599,9 +599,13 @@ private: | @@ -599,9 +599,13 @@ private: | ||
| 599 | // forward section | 599 | // forward section |
| 600 | public: | 600 | public: |
| 601 | /** | 601 | /** |
| 602 | + * whether the forwarder enabled. | ||
| 603 | + */ | ||
| 604 | + virtual bool get_forward_enabled(std::string vhost); | ||
| 605 | + /** | ||
| 602 | * get the forward directive of vhost. | 606 | * get the forward directive of vhost. |
| 603 | */ | 607 | */ |
| 604 | - virtual SrsConfDirective* get_forward(std::string vhost); | 608 | + virtual SrsConfDirective* get_forwards(std::string vhost); |
| 605 | // http_hooks section | 609 | // http_hooks section |
| 606 | private: | 610 | private: |
| 607 | /** | 611 | /** |
| @@ -2235,7 +2235,11 @@ int SrsSource::create_forwarders() | @@ -2235,7 +2235,11 @@ int SrsSource::create_forwarders() | ||
| 2235 | { | 2235 | { |
| 2236 | int ret = ERROR_SUCCESS; | 2236 | int ret = ERROR_SUCCESS; |
| 2237 | 2237 | ||
| 2238 | - SrsConfDirective* conf = _srs_config->get_forward(_req->vhost); | 2238 | + if (_srs_config->get_forward_enabled(_req->vhost)) { |
| 2239 | + return ret; | ||
| 2240 | + } | ||
| 2241 | + | ||
| 2242 | + SrsConfDirective* conf = _srs_config->get_forwards(_req->vhost); | ||
| 2239 | for (int i = 0; conf && i < (int)conf->args.size(); i++) { | 2243 | for (int i = 0; conf && i < (int)conf->args.size(); i++) { |
| 2240 | std::string forward_server = conf->args.at(i); | 2244 | std::string forward_server = conf->args.at(i); |
| 2241 | 2245 |
-
请 注册 或 登录 后发表评论