1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 11:51:57 +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

@ -708,6 +708,11 @@ vhost cluster.srs.com {
# flvs, Connect origin by HTTPS-FLV
# Default: rtmp
protocol rtmp;
# Whether follow client protocol to connect to origin.
# @remark The FLV might use different signature(in query string) to RTMP.
# Default: off
follow_client off;
}
}

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 {

View file

@ -1578,6 +1578,8 @@ SrsRequest::SrsRequest()
duration = -1;
port = SRS_CONSTS_RTMP_DEFAULT_PORT;
args = NULL;
protocol = "rtmp";
}
SrsRequest::~SrsRequest()
@ -1606,6 +1608,8 @@ SrsRequest* SrsRequest::copy()
cp->args = args->copy()->to_object();
}
cp->protocol = protocol;
return cp;
}
@ -1633,6 +1637,8 @@ void SrsRequest::update_auth(SrsRequest* req)
args = req->args->copy()->to_object();
}
protocol = req->protocol;
srs_info("update req of soruce for auth ok");
}

View file

@ -489,6 +489,12 @@ public:
public:
// Transform it as HTTP request.
virtual SrsRequest* as_http();
public:
// The protocol of client:
// rtmp, Adobe RTMP protocol.
// flv, HTTP-FLV protocol.
// flvs, HTTPS-FLV protocol.
std::string protocol;
};
// The response to client.

View file

@ -681,6 +681,9 @@ SrsRequest* SrsHttpMessage::to_request(string vhost)
req->ip = oip;
}
// The request streaming protocol.
req->protocol = (schema_ == "http")? "flv" : "flvs";
return req;
}