From 92f2bcd87863bd4298f42b083c282dc8ba52577e Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 16 Feb 2018 10:31:19 +0800 Subject: [PATCH] For #464, support config origin cluster --- trunk/conf/full.conf | 18 +++++++++++++----- trunk/src/app/srs_app_config.cpp | 25 ++++++++++++++++++++++++- trunk/src/app/srs_app_config.hpp | 5 +++++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 64f8bfde8..cd80f41e0 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -365,10 +365,16 @@ vhost cluster.srs.com { # default: on debug_srs_upnode on; + # For origin(mode local) cluster, turn on the cluster. + # default: off + # TODO: FIXME: Support reload. + origin_cluster off; + # For origin (mode local) cluster, the co-worker's HTTP APIs. # This origin will connect to co-workers and communicate with them. # please read: https://github.com/ossrs/srs/wiki/v3_EN_OriginCluster - coworkers 127.0.0.1:9091 127.0.0.1:9092; + # TODO: FIXME: Support reload. + coworkers 127.0.0.1:9091 127.0.0.1:9092; } } @@ -1798,8 +1804,9 @@ http_api { } vhost a.origin.cluster.srs.com { cluster { - mode local; - coworkers 127.0.0.1:9091; + mode local; + origin_cluster on; + coworkers 127.0.0.1:9091; } } @@ -1809,7 +1816,8 @@ http_api { } vhost b.origin.cluster.srs.com { cluster { - mode local; - coworkers 127.0.0.1:9090; + mode local; + origin_cluster on; + coworkers 127.0.0.1:9090; } } diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 547a4a792..1f2e2468a 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -3726,7 +3726,8 @@ srs_error_t SrsConfig::check_normal_config() } else if (n == "cluster") { for (int j = 0; j < (int)conf->directives.size(); j++) { string m = conf->at(j)->name; - if (m != "mode" && m != "origin" && m != "token_traverse" && m != "vhost" && m != "debug_srs_upnode" && m != "coworkers") { + if (m != "mode" && m != "origin" && m != "token_traverse" && m != "vhost" && m != "debug_srs_upnode" && m != "coworkers" + && m != "origin_cluster") { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.cluster.%s of %s", m.c_str(), vhost->arg0().c_str()); } } @@ -5157,6 +5158,28 @@ string SrsConfig::get_vhost_edge_transform_vhost(string vhost) return conf->arg0(); } +bool SrsConfig::get_vhost_origin_cluster(string vhost) +{ + static bool DEFAULT = false; + + SrsConfDirective* conf = get_vhost(vhost); + if (!conf) { + return DEFAULT; + } + + conf = conf->get("cluster"); + if (!conf) { + return DEFAULT; + } + + conf = conf->get("origin_cluster"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + + return SRS_CONF_PERFER_FALSE(conf->arg0()); +} + vector SrsConfig::get_vhost_coworkers(string vhost) { vector coworkers; diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 348ec489a..14dc8a7fe 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -939,6 +939,11 @@ public: * @see https://github.com/ossrs/srs/issues/372 */ virtual std::string get_vhost_edge_transform_vhost(std::string vhost); + /** + * Whether enable the origin cluster. + * @see https://github.com/ossrs/srs/wiki/v3_EN_OriginCluster + */ + virtual bool get_vhost_origin_cluster(std::string vhost); /** * Get the co-workers of origin cluster. * @see https://github.com/ossrs/srs/wiki/v3_EN_OriginCluster