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

Live: Support follow client protocol for edge.

This commit is contained in:
winlin 2020-12-24 18:59:29 +08:00
parent 33fa43c118
commit 35431749c4
7 changed files with 57 additions and 2 deletions

View file

@ -3829,7 +3829,7 @@ srs_error_t SrsConfig::check_normal_config()
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"
&& m != "origin_cluster" && m != "protocol") {
&& m != "origin_cluster" && m != "protocol" && m != "follow_client") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.cluster.%s of %s", m.c_str(), vhost->arg0().c_str());
}
}
@ -6218,6 +6218,28 @@ string SrsConfig::get_vhost_edge_protocol(string vhost)
return conf->arg0();
}
bool SrsConfig::get_vhost_edge_follow_client(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("follow_client");
if (!conf) {
return DEFAULT;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
bool SrsConfig::get_vhost_edge_token_traverse(string vhost)
{
static bool DEFAULT = false;

View file

@ -775,6 +775,8 @@ public:
virtual SrsConfDirective* get_vhost_edge_origin(std::string vhost);
// Get the procotol to connect to origin server.
virtual std::string get_vhost_edge_protocol(std::string vhost);
// Whether follow client protocol to connect to origin.
virtual bool get_vhost_edge_follow_client(std::string vhost);
// Whether edge token tranverse is enabled,
// If true, edge will send connect origin to verfy the token of client.
// For example, we verify all clients on the origin FMS by server-side as,

View file

@ -240,6 +240,8 @@ srs_error_t SrsEdgeFlvUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb)
return srs_error_wrap(err, "edge get %s failed, path=%s", url.c_str(), path.c_str());
}
srs_trace("Edge: Connect to %s ok", url.c_str());
srs_freep(reader_);
reader_ = new SrsHttpFileReader(hr_->body_reader());
@ -446,8 +448,17 @@ srs_error_t SrsEdgeIngester::do_cycle()
return srs_error_wrap(err, "do cycle pull");
}
srs_freep(upstream);
// Use protocol in config.
string edge_protocol = _srs_config->get_vhost_edge_protocol(req->vhost);
// If follow client protocol, change to protocol of client.
bool follow_client = _srs_config->get_vhost_edge_follow_client(req->vhost);
if (follow_client && !req->protocol.empty()) {
edge_protocol = req->protocol;
}
// Create object by protocol.
srs_freep(upstream);
if (edge_protocol == "flv" || edge_protocol == "flvs") {
upstream = new SrsEdgeFlvUpstream(edge_protocol == "flv"? "http" : "https");
} else {