mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 11:51:57 +00:00
Fix #2508, Support features query by API. 5.0.10
This commit is contained in:
parent
69faf06f0f
commit
adf0043cbc
7 changed files with 252 additions and 42 deletions
|
@ -20,6 +20,7 @@ The changelog for SRS.
|
|||
|
||||
## SRS 4.0 Changelog
|
||||
|
||||
* v4.0, 2021-08-07, Fix [#2508](https://github.com/ossrs/srs/pull/2508), Support features query by API. 4.0.149
|
||||
* v4.0, 2021-07-25, Fix build failed. 4.0.146
|
||||
* v4.0, 2021-07-24, Merge [#2373](https://github.com/ossrs/srs/pull/2373), RTC: Fix NACK negotiation bug for Firefox. 4.0.145
|
||||
* v4.0, 2021-07-24, Merge [#2483](https://github.com/ossrs/srs/pull/2483), RTC: Support statistic for HTTP-API, HTTP-Callback and Security. 4.0.144
|
||||
|
|
|
@ -3617,6 +3617,7 @@ srs_error_t SrsConfig::check_normal_config()
|
|||
&& n != "ff_log_level" && n != "grace_final_wait" && n != "force_grace_quit"
|
||||
&& n != "grace_start_wait" && n != "empty_ip_ok" && n != "disable_daemon_for_docker"
|
||||
&& n != "inotify_auto_reload" && n != "auto_reload_for_docker" && n != "tcmalloc_release_rate"
|
||||
&& n != "query_latest_version"
|
||||
&& n != "circuit_breaker" && n != "is_full"
|
||||
) {
|
||||
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal directive %s", n.c_str());
|
||||
|
@ -5672,8 +5673,7 @@ int SrsConfig::get_global_chunk_size()
|
|||
return ::atoi(conf->arg0().c_str());
|
||||
}
|
||||
|
||||
bool SrsConfig::get_forward_enabled(string vhost)
|
||||
{
|
||||
bool SrsConfig::get_forward_enabled(string vhost) {
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = get_vhost(vhost);
|
||||
|
@ -5681,7 +5681,14 @@ bool SrsConfig::get_forward_enabled(string vhost)
|
|||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("forward");
|
||||
return get_forward_enabled(conf);
|
||||
}
|
||||
|
||||
bool SrsConfig::get_forward_enabled(SrsConfDirective* vhost)
|
||||
{
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = vhost->get("forward");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
@ -5723,7 +5730,19 @@ bool SrsConfig::get_vhost_http_hooks_enabled(string vhost)
|
|||
{
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
|
||||
SrsConfDirective* conf = get_vhost(vhost);
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
return get_vhost_http_hooks_enabled(conf);
|
||||
}
|
||||
|
||||
bool SrsConfig::get_vhost_http_hooks_enabled(SrsConfDirective* vhost)
|
||||
{
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = vhost->get("http_hooks");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
@ -6098,12 +6117,19 @@ bool SrsConfig::get_security_enabled(string vhost)
|
|||
return DEFAULT;
|
||||
}
|
||||
|
||||
SrsConfDirective* security = conf->get("security");
|
||||
if (!security) {
|
||||
return get_security_enabled(conf);
|
||||
}
|
||||
|
||||
bool SrsConfig::get_security_enabled(SrsConfDirective* vhost)
|
||||
{
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = vhost->get("security");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = security->get("enabled");
|
||||
conf = conf->get("enabled");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
@ -6578,7 +6604,19 @@ bool SrsConfig::get_exec_enabled(string vhost)
|
|||
{
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = get_exec(vhost);
|
||||
SrsConfDirective* conf = get_vhost(vhost);
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
return get_exec_enabled(conf);
|
||||
}
|
||||
|
||||
bool SrsConfig::get_exec_enabled(SrsConfDirective* vhost)
|
||||
{
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = vhost->get("exec");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
@ -6790,7 +6828,19 @@ bool SrsConfig::get_dash_enabled(string vhost)
|
|||
{
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = get_dash(vhost);
|
||||
SrsConfDirective* conf = get_vhost(vhost);
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
return get_dash_enabled(conf);
|
||||
}
|
||||
|
||||
bool SrsConfig::get_dash_enabled(SrsConfDirective* vhost)
|
||||
{
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = vhost->get("dash");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
@ -6898,7 +6948,19 @@ bool SrsConfig::get_hls_enabled(string vhost)
|
|||
{
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = get_hls(vhost);
|
||||
SrsConfDirective* conf = get_vhost(vhost);
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
return get_hls_enabled(conf);
|
||||
}
|
||||
|
||||
bool SrsConfig::get_hls_enabled(SrsConfDirective* vhost)
|
||||
{
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = vhost->get("hls");
|
||||
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
|
@ -7304,7 +7366,19 @@ bool SrsConfig::get_hds_enabled(const string &vhost)
|
|||
{
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = get_hds(vhost);
|
||||
SrsConfDirective* conf = get_vhost(vhost);
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
return get_hds_enabled(conf);
|
||||
}
|
||||
|
||||
bool SrsConfig::get_hds_enabled(SrsConfDirective* vhost)
|
||||
{
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = vhost->get("hds");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
@ -7382,7 +7456,19 @@ bool SrsConfig::get_dvr_enabled(string vhost)
|
|||
{
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = get_dvr(vhost);
|
||||
SrsConfDirective* conf = get_vhost(vhost);
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
return get_dvr_enabled(conf);
|
||||
}
|
||||
|
||||
bool SrsConfig::get_dvr_enabled(SrsConfDirective* vhost)
|
||||
{
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = vhost->get("dvr");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
@ -8160,7 +8246,14 @@ bool SrsConfig::get_vhost_http_remux_enabled(string vhost)
|
|||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("http_remux");
|
||||
return get_vhost_http_remux_enabled(conf);
|
||||
}
|
||||
|
||||
bool SrsConfig::get_vhost_http_remux_enabled(SrsConfDirective* vhost)
|
||||
{
|
||||
static bool DEFAULT = false;
|
||||
|
||||
SrsConfDirective* conf = vhost->get("http_remux");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
|
|
@ -643,6 +643,7 @@ private:
|
|||
public:
|
||||
// Whether the forwarder enabled.
|
||||
virtual bool get_forward_enabled(std::string vhost);
|
||||
virtual bool get_forward_enabled(SrsConfDirective* vhost);
|
||||
// Get the forward directive of vhost.
|
||||
virtual SrsConfDirective* get_forwards(std::string vhost);
|
||||
|
||||
|
@ -686,6 +687,7 @@ public:
|
|||
// Whether vhost http-hooks enabled.
|
||||
// @remark, if not enabled, donot callback all http hooks.
|
||||
virtual bool get_vhost_http_hooks_enabled(std::string vhost);
|
||||
virtual bool get_vhost_http_hooks_enabled(SrsConfDirective* vhost);
|
||||
// Get the on_connect callbacks of vhost.
|
||||
// @return the on_connect callback directive, the args is the url to callback.
|
||||
virtual SrsConfDirective* get_vhost_on_connect(std::string vhost);
|
||||
|
@ -765,6 +767,7 @@ public:
|
|||
public:
|
||||
// Whether the secrity of vhost enabled.
|
||||
virtual bool get_security_enabled(std::string vhost);
|
||||
virtual bool get_security_enabled(SrsConfDirective* vhost);
|
||||
// Get the security rules.
|
||||
virtual SrsConfDirective* get_security_rules(std::string vhost);
|
||||
// vhost transcode section
|
||||
|
@ -847,6 +850,7 @@ private:
|
|||
public:
|
||||
// Whether the exec is enabled of vhost.
|
||||
virtual bool get_exec_enabled(std::string vhost);
|
||||
virtual bool get_exec_enabled(SrsConfDirective* vhost);
|
||||
// Get all exec publish directives of vhost.
|
||||
virtual std::vector<SrsConfDirective*> get_exec_publishs(std::string vhost);
|
||||
// vhost ingest section
|
||||
|
@ -884,6 +888,7 @@ private:
|
|||
public:
|
||||
// Whether DASH is enabled.
|
||||
virtual bool get_dash_enabled(std::string vhost);
|
||||
virtual bool get_dash_enabled(SrsConfDirective* vhost);
|
||||
// Get the duration of segment in srs_utime_t.
|
||||
virtual srs_utime_t get_dash_fragment(std::string vhost);
|
||||
// Get the period to update MPD in srs_utime_t.
|
||||
|
@ -901,6 +906,7 @@ private:
|
|||
public:
|
||||
// Whether HLS is enabled.
|
||||
virtual bool get_hls_enabled(std::string vhost);
|
||||
virtual bool get_hls_enabled(SrsConfDirective* vhost);
|
||||
// Get the HLS m3u8 list ts segment entry prefix info.
|
||||
virtual std::string get_hls_entry_prefix(std::string vhost);
|
||||
// Get the HLS ts/m3u8 file store path.
|
||||
|
@ -958,6 +964,7 @@ private:
|
|||
public:
|
||||
// Whether HDS is enabled.
|
||||
virtual bool get_hds_enabled(const std::string &vhost);
|
||||
virtual bool get_hds_enabled(SrsConfDirective* vhost);
|
||||
// Get the HDS file store path.
|
||||
virtual std::string get_hds_path(const std::string &vhost);
|
||||
// Get the hds fragment time, in srs_utime_t.
|
||||
|
@ -972,6 +979,7 @@ private:
|
|||
public:
|
||||
// Whether dvr is enabled.
|
||||
virtual bool get_dvr_enabled(std::string vhost);
|
||||
virtual bool get_dvr_enabled(SrsConfDirective* vhost);
|
||||
// Get the filter of dvr to apply to.
|
||||
// @remark user can use srs_config_apply_filter(conf, req):bool to check it.
|
||||
virtual SrsConfDirective* get_dvr_apply(std::string vhost);
|
||||
|
@ -1047,6 +1055,7 @@ public:
|
|||
public:
|
||||
// Get whether vhost enabled http flv live stream
|
||||
virtual bool get_vhost_http_remux_enabled(std::string vhost);
|
||||
virtual bool get_vhost_http_remux_enabled(SrsConfDirective* vhost);
|
||||
// Get the fast cache duration for http audio live stream.
|
||||
virtual srs_utime_t get_vhost_http_remux_fast_cache(std::string vhost);
|
||||
// Get the http flv live stream mount point for vhost.
|
||||
|
|
|
@ -25,10 +25,103 @@ using namespace std;
|
|||
// Whether we are in docker, defined in main module.
|
||||
extern bool _srs_in_docker;
|
||||
|
||||
// Check the feature by cond
|
||||
#define SRS_CHECK_FEATURE(cond, ss) if (cond) ss << "&" << #cond << "=1"
|
||||
#define SRS_CHECK_FEATURE2(cond, key, ss) if (cond) ss << "&" << key << "=1"
|
||||
#define SRS_CHECK_FEATURE3(cond, key, value, ss) if (cond) ss << "&" << key << "=" << value
|
||||
|
||||
void srs_build_features(stringstream& ss)
|
||||
{
|
||||
ss << "&docker=" << _srs_in_docker
|
||||
<< "&packager=" << SRS_PACKAGER;
|
||||
if (SRS_OSX_BOOL) {
|
||||
ss << "&os=mac";
|
||||
} else {
|
||||
ss << "&os=linux";
|
||||
}
|
||||
|
||||
SRS_CHECK_FEATURE2(_srs_in_docker, "docker", ss);
|
||||
SRS_CHECK_FEATURE3(!string(SRS_PACKAGER).empty(), "packager", SRS_PACKAGER, ss);
|
||||
SRS_CHECK_FEATURE2(SRS_CROSSBUILD_BOOL, "cross", ss);
|
||||
|
||||
SRS_CHECK_FEATURE2(SRS_RTC_BOOL && _srs_config->get_rtc_server_enabled(), "rtc", ss);
|
||||
SRS_CHECK_FEATURE2(SRS_SRT_BOOL && _srs_config->get_srt_enabled(), "srt", ss);
|
||||
SRS_CHECK_FEATURE2(_srs_config->get_http_api_enabled(), "api", ss);
|
||||
SRS_CHECK_FEATURE2(_srs_config->get_https_api_enabled(), "https", ss);
|
||||
SRS_CHECK_FEATURE2(_srs_config->get_raw_api(), "raw", ss);
|
||||
|
||||
int nn_vhosts = 0;
|
||||
bool rtsp = false, forward = false, ingest = false, edge = false, hls = false, dvr = false, flv = false;
|
||||
bool hooks = false, dash = false, hds = false, exec = false, transcode = false, security = false;
|
||||
|
||||
SrsConfDirective* root = _srs_config->get_root();
|
||||
// Note that we limit the loop, never detect all configs.
|
||||
for (int i = 0; i < (int)root->directives.size() && i < 128; i++) {
|
||||
SrsConfDirective* conf = root->at(i);
|
||||
|
||||
if (!rtsp && conf->is_stream_caster() && _srs_config->get_stream_caster_enabled(conf)) {
|
||||
if (_srs_config->get_stream_caster_engine(conf) == "rtsp") {
|
||||
rtsp = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (conf->is_vhost() && _srs_config->get_vhost_enabled(conf)) {
|
||||
nn_vhosts++;
|
||||
if (!forward && _srs_config->get_forward_enabled(conf)) {
|
||||
forward = true;
|
||||
}
|
||||
if (!edge && _srs_config->get_vhost_is_edge(conf)) {
|
||||
edge = true;
|
||||
}
|
||||
if (!hls && _srs_config->get_hls_enabled(conf)) {
|
||||
hls = true;
|
||||
}
|
||||
if (!dvr && _srs_config->get_dvr_enabled(conf)) {
|
||||
dvr = true;
|
||||
}
|
||||
if (!flv && _srs_config->get_vhost_http_remux_enabled(conf)) {
|
||||
flv = true;
|
||||
}
|
||||
if (!hooks && _srs_config->get_vhost_http_hooks_enabled(conf)) {
|
||||
hooks = true;
|
||||
}
|
||||
if (!dash && _srs_config->get_dash_enabled(conf)) {
|
||||
dash = true;
|
||||
}
|
||||
if (!hds && _srs_config->get_hds_enabled(conf)) {
|
||||
hds = true;
|
||||
}
|
||||
if (!exec && _srs_config->get_exec_enabled(conf)) {
|
||||
exec = true;
|
||||
}
|
||||
if (!security && _srs_config->get_security_enabled(conf)) {
|
||||
security = true;
|
||||
}
|
||||
|
||||
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
||||
SrsConfDirective* prop = conf->directives.at(j);
|
||||
if (!ingest && prop->name == "ingest" && _srs_config->get_ingest_enabled(prop)) {
|
||||
ingest = true;
|
||||
}
|
||||
if (!transcode && prop->name == "transcode" && _srs_config->get_transcode_enabled(prop)) {
|
||||
transcode = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SRS_CHECK_FEATURE2(nn_vhosts, "vhosts", ss);
|
||||
SRS_CHECK_FEATURE(rtsp, ss);
|
||||
SRS_CHECK_FEATURE(forward, ss);
|
||||
SRS_CHECK_FEATURE(ingest, ss);
|
||||
SRS_CHECK_FEATURE(edge, ss);
|
||||
SRS_CHECK_FEATURE(hls, ss);
|
||||
SRS_CHECK_FEATURE(dvr, ss);
|
||||
SRS_CHECK_FEATURE(flv, ss);
|
||||
SRS_CHECK_FEATURE(hooks, ss);
|
||||
SRS_CHECK_FEATURE(dash, ss);
|
||||
SRS_CHECK_FEATURE(hds, ss);
|
||||
SRS_CHECK_FEATURE(exec, ss);
|
||||
SRS_CHECK_FEATURE(transcode, ss);
|
||||
SRS_CHECK_FEATURE(security, ss);
|
||||
}
|
||||
|
||||
SrsLatestVersion::SrsLatestVersion()
|
||||
|
@ -65,34 +158,48 @@ srs_error_t SrsLatestVersion::cycle()
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (true) {
|
||||
string url;
|
||||
srs_utime_t starttime = srs_update_system_time();
|
||||
if ((err = query_latest_version()) != srs_success) {
|
||||
if ((err = query_latest_version(url)) != srs_success) {
|
||||
srs_warn("query err %s", srs_error_desc(err).c_str());
|
||||
srs_freep(err); // Ignore any error.
|
||||
}
|
||||
|
||||
srs_utime_t first_random_wait = 0;
|
||||
srs_random_generate((char*)&first_random_wait, 8);
|
||||
srs_random_generate((char *) &first_random_wait, 8);
|
||||
first_random_wait = srs_utime_t(uint64_t((first_random_wait + starttime + getpid())) % (60 * 60)) * SRS_UTIME_SECONDS; // in s.
|
||||
|
||||
srs_trace("Startup query id=%s, eip=%s, match=%s, stable=%s, wait=%ds, cost=%dms", server_id_.c_str(), srs_get_public_internet_address().c_str(), match_version_.c_str(), stable_version_.c_str(), srsu2msi(first_random_wait)/1000, srsu2msi(srs_update_system_time() - starttime));
|
||||
srs_trace("Startup query id=%s, eip=%s, match=%s, stable=%s, wait=%ds, cost=%dms, url=%s",
|
||||
server_id_.c_str(), srs_get_public_internet_address().c_str(), match_version_.c_str(),
|
||||
stable_version_.c_str(), srsu2msi(first_random_wait) / 1000, srsu2msi(srs_update_system_time() - starttime),
|
||||
url.c_str());
|
||||
srs_usleep(first_random_wait);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
starttime = srs_update_system_time();
|
||||
if ((err = query_latest_version()) != srs_success) {
|
||||
if ((err = trd_->pull()) != srs_success) {
|
||||
break;
|
||||
}
|
||||
|
||||
string url;
|
||||
srs_utime_t starttime = srs_update_system_time();
|
||||
if ((err = query_latest_version(url)) != srs_success) {
|
||||
srs_warn("query err %s", srs_error_desc(err).c_str());
|
||||
srs_freep(err); // Ignore any error.
|
||||
}
|
||||
|
||||
srs_trace("Finish query id=%s, eip=%s, match=%s, stable=%s, cost=%dms", server_id_.c_str(), srs_get_public_internet_address().c_str(), match_version_.c_str(), stable_version_.c_str(), srsu2msi(srs_update_system_time() - starttime));
|
||||
srs_trace("Finish query id=%s, eip=%s, match=%s, stable=%s, cost=%dms, url=%s",
|
||||
server_id_.c_str(), srs_get_public_internet_address().c_str(), match_version_.c_str(),
|
||||
stable_version_.c_str(), srsu2msi(srs_update_system_time() - starttime), url.c_str());
|
||||
|
||||
srs_usleep(3600 * SRS_UTIME_SECONDS); // Every an hour.
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsLatestVersion::query_latest_version()
|
||||
srs_error_t SrsLatestVersion::query_latest_version(string& url)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
|
@ -104,7 +211,7 @@ srs_error_t SrsLatestVersion::query_latest_version()
|
|||
<< "&eip=" << srs_get_public_internet_address()
|
||||
<< "&ts=" << srsu2ms(srs_get_system_time());
|
||||
srs_build_features(ss);
|
||||
string url = ss.str();
|
||||
url = ss.str();
|
||||
|
||||
SrsHttpUri uri;
|
||||
if ((err = uri.initialize(url)) != srs_success) {
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
public:
|
||||
virtual srs_error_t cycle();
|
||||
private:
|
||||
srs_error_t query_latest_version();
|
||||
srs_error_t query_latest_version(std::string& url);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -9,6 +9,6 @@
|
|||
|
||||
#define VERSION_MAJOR 4
|
||||
#define VERSION_MINOR 0
|
||||
#define VERSION_REVISION 148
|
||||
#define VERSION_REVISION 149
|
||||
|
||||
#endif
|
||||
|
|
|
@ -9,6 +9,6 @@
|
|||
|
||||
#define VERSION_MAJOR 5
|
||||
#define VERSION_MINOR 0
|
||||
#define VERSION_REVISION 9
|
||||
#define VERSION_REVISION 10
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue