From d7078a72d4db5ce73a70ab63a95f24f543ed3a81 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 19 Dec 2019 14:15:21 +0800 Subject: [PATCH] For #1520, add TODO list for configing server itself in coworker. --- trunk/conf/origin.cluster.serverA.conf | 2 +- trunk/conf/origin.cluster.serverB.conf | 2 +- trunk/conf/origin.cluster.serverC.conf | 2 +- trunk/src/app/srs_app_rtmp_conn.cpp | 14 ++++++++++---- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/trunk/conf/origin.cluster.serverA.conf b/trunk/conf/origin.cluster.serverA.conf index c9b0efa06..7bc73c63a 100644 --- a/trunk/conf/origin.cluster.serverA.conf +++ b/trunk/conf/origin.cluster.serverA.conf @@ -15,6 +15,6 @@ vhost __defaultVhost__ { cluster { mode local; origin_cluster on; - coworkers 127.0.0.1:9091 127.0.0.1:9092; + coworkers 127.0.0.1:9090 127.0.0.1:9091 127.0.0.1:9092; } } diff --git a/trunk/conf/origin.cluster.serverB.conf b/trunk/conf/origin.cluster.serverB.conf index fe65bb0a3..b06417cd8 100644 --- a/trunk/conf/origin.cluster.serverB.conf +++ b/trunk/conf/origin.cluster.serverB.conf @@ -15,6 +15,6 @@ vhost __defaultVhost__ { cluster { mode local; origin_cluster on; - coworkers 127.0.0.1:9090 127.0.0.1:9092; + coworkers 127.0.0.1:9090 127.0.0.1:9091 127.0.0.1:9092; } } diff --git a/trunk/conf/origin.cluster.serverC.conf b/trunk/conf/origin.cluster.serverC.conf index 72bec36e5..efb991cc7 100644 --- a/trunk/conf/origin.cluster.serverC.conf +++ b/trunk/conf/origin.cluster.serverC.conf @@ -15,6 +15,6 @@ vhost __defaultVhost__ { cluster { mode local; origin_cluster on; - coworkers 127.0.0.1:9090 127.0.0.1:9091; + coworkers 127.0.0.1:9090 127.0.0.1:9091 127.0.0.1:9092; } } diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index 2eb26ff13..3a0a79281 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -607,11 +607,12 @@ srs_error_t SrsRtmpConn::playing(SrsSource* source) if (!info->edge && _srs_config->get_vhost_origin_cluster(req->vhost) && source->inactive()) { vector coworkers = _srs_config->get_vhost_coworkers(req->vhost); for (int i = 0; i < (int)coworkers.size(); i++) { - int port; - string host; - string url = "http://" + coworkers.at(i) + "/api/v1/clusters?" + // TODO: FIXME: User may config the server itself as coworker, we must identify and ignore it. + string host; int port = 0; string coworker = coworkers.at(i); + + string url = "http://" + coworker + "/api/v1/clusters?" + "vhost=" + req->vhost + "&ip=" + req->host + "&app=" + req->app + "&stream=" + req->stream - + "&coworker=" + coworkers.at(i); + + "&coworker=" + coworker; if ((err = SrsHttpHooks::discover_co_workers(url, host, port)) != srs_success) { // If failed to discovery stream in this coworker, we should request the next one util the last. // @see https://github.com/ossrs/srs/issues/1223 @@ -622,6 +623,11 @@ srs_error_t SrsRtmpConn::playing(SrsSource* source) } srs_trace("rtmp: redirect in cluster, from=%s:%d, target=%s:%d, url=%s", req->host.c_str(), req->port, host.c_str(), port, url.c_str()); + + // Ignore if host or port is invalid. + if (host.empty() || port == 0) { + continue; + } bool accepted = false; if ((err = rtmp->redirect(req, host, port, accepted)) != srs_success) {