Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Each SRS instance is missing a unique identifier for the instance. #1789

Closed
chatop2020 opened this issue May 31, 2020 · 4 comments
Closed

Each SRS instance is missing a unique identifier for the instance. #1789

chatop2020 opened this issue May 31, 2020 · 4 comments
Assignees
Labels
Feature It's a new feature. TransByAI Translated by AI/GPT.
Milestone

Comments

@chatop2020
Copy link

chatop2020 commented May 31, 2020

You need to have an instance identifier for SRS.
Can it be added? It can be passed as a parameter during startup or written in the configuration file.
Currently, the SRS instance only has a device_id at the heartbeat interface, which can identify the requesting SRS instance.
However, various structures in http_hook, including gb28181's webapi, do not have a device_id field. This makes SRS instance management difficult, and identifying them solely based on IP address is not foolproof.
Can the official team add an instance identifier for each SRS instance, which can be specified through the configuration file or startup parameters?

TRANS_BY_GPT3

@chatop2020
Copy link
Author

chatop2020 commented May 31, 2020

I think this is feasible, right?
srs_error_t SrsHttpHooks::on_publish(string url, SrsRequest* req)
{
srs_error_t err = srs_success;

int client_id = _srs_context->get_id();

SrsJsonObject* obj = SrsJsonAny::object();
SrsAutoFree(SrsJsonObject, obj);

obj->set("action", SrsJsonAny::str("on_publish"));
obj->set("device_id", SrsJsonAny::str(_srs_config->get_heartbeat_device_id()));
obj->set("client_id", SrsJsonAny::integer(client_id));
obj->set("ip", SrsJsonAny::str(req->ip.c_str()));
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str()));
obj->set("app", SrsJsonAny::str(req->app.c_str()));
obj->set("tcUrl", SrsJsonAny::str(req->tcUrl.c_str()));
obj->set("stream", SrsJsonAny::str(req->stream.c_str()));
obj->set("param", SrsJsonAny::str(req->param.c_str()));

std::string data = obj->dumps();
std::string res;
int status_code;

SrsHttpClient http;
if ((err = do_post(&http, url, data, status_code, res)) != srs_success) {
    return srs_error_wrap(err, "http: on_publish failed, client_id=%d, url=%s, request=%s, response=%s, code=%d",
        client_id, url.c_str(), data.c_str(), res.c_str(), status_code);
}

srs_trace("http: on_publish ok, client_id=%d, url=%s, request=%s, response=%s",
    client_id, url.c_str(), data.c_str(), res.c_str());

return err;

}

TRANS_BY_GPT3

@chatop2020
Copy link
Author

chatop2020 commented May 31, 2020

I have added it myself, compiled successfully, and the result is as follows:
[2020-5-31 6:54:21 PM] OUTPUT ::ffff:192.168.2.45 POST /GlobalSrs/StartSrs StatusCode:200 Body: true
[2020-5-31 6:54:23 PM] INPUT ::ffff:127.0.0.1 POST /SrsHooks/OnConnect {"client":{"Action":"on_connect","Device_Id":"22364bc4-5134-494d-8249-51d06777fb7f","Client_Id":152,"Ip":"127.0.0.1","Vhost":"defaultVhost","App":"live","TcUrl":"rtmp://127.0.0.1:1935/live","PageUrl":""}}
[2020-5-31 6:54:23 PM] INPUT ::ffff:127.0.0.1 POST /SrsHooks/OnPublish {"client":{"Action":"on_publish","Device_Id":"22364bc4-5134-494d-8249-51d06777fb7f","Client_Id":152,"Ip":"127.0.0.1","Vhost":"defaultVhost","App":"live","TcUrl":"rtmp://127.0.0.1:1935/live","Stream":"192.168.2.165","Param":""}}
[2020-5-31 6:54:27 PM] INPUT ::ffff:127.0.0.1 POST /SrsHooks/OnConnect {"client":{"Action":"on_connect","Device_Id":"22364bc4-5134-494d-8249-51d06777fb7f","Client_Id":155,"Ip":"127.0.0.1","Vhost":"defaultVhost","App":"live","TcUrl":"rtmp://127.0.0.1/live","PageUrl":""}}
[2020-5-31 6:54:27 PM] INPUT ::ffff:127.0.0.1 POST /SrsHooks/OnPublish {"client":{"Action":"on_publish","Device_Id":"22364bc4-5134-494d-8249-51d06777fb7f","Client_Id":155,"Ip":"127.0.0.1","Vhost":"defaultVhost","App":"live","TcUrl":"rtmp://127.0.0.1/live","Stream":"34020000001340000000@34020000001320000001","Param":"?vhost=127.0.0.1"}}
[2020-5-31 6:54:27 PM] INPUT ::ffff:127.0.0.1 POST /SrsHooks/OnConnect {"client":{"Action":"on_connect","Device_Id":"22364bc4-5134-494d-8249-51d06777fb7f","Client_Id":157,"Ip":"127.0.0.1","Vhost":"defaultVhost","App":"live","TcUrl":"rtmp://127.0.0.1:1935/live","PageUrl":""}}
[2020-5-31 6:54:27 PM] INPUT ::ffff:127.0.0.1 POST /SrsHooks/OnPublish {"client":{"Action":"on_publish","Device_Id":"22364bc4-5134-494d-8249-51d06777fb7f","Client_Id":157,"Ip":"127.0.0.1","Vhost":"defaultVhost","App":"live","TcUrl":"rtmp://127.0.0.1:1935/live","Stream":"192.168.2.164","Param":""}}
[2020-5-31 6:54:28 PM] INPUT ::ffff:127.0.0.1 POST /SrsHooks/OnConnect {"client":{"Action":"on_connect","Device_Id":"22364bc4-5134-494d-8249-51d06777fb7f","Client_Id":160,"Ip":"127.0.0.1","Vhost":"defaultVhost","App":"live","TcUrl":"rtmp://127.0.0.1/live","PageUrl":""}}
[2020-5-31 6:54:28 PM] INPUT ::ffff:127.0.0.1 POST /SrsHooks/OnPublish {"client":{"Action":"on_publish","Device_Id":"22364bc4-5134-494d-8249-51d06777fb7f","Client_Id":160,"Ip":"127.0.0.1","Vhost":"defaultVhost","App":"live","TcUrl":"rtmp://127.0.0.1/live","Stream":"34020000001340000000@34020000001320000002","Param":"?vhost=127.0.0.1"}}
[2020-5-31 6:54:32 PM] INPUT ::ffff:127.0.0.1 POST /SrsHooks/OnConnect {"client":{"Action":"on_connect","Device_Id":"22364bc4-5134-494d-8249-51d06777fb7f","Client_Id":163,"Ip":"127.0.0.1","Vhost":"defaultVhost","App":"live","TcUrl":"rtmp://127.0.0.1/live","PageUrl":""}}
[2020-5-31 6:54:32 PM] INPUT ::ffff:127.0.0.1 POST /SrsHooks/OnPublish {"client":{"Action":"on_publish","Device_Id":"22364bc4-5134-494d-8249-51d06777fb7f","Client_Id":163,"Ip":"127.0.0.1","Vhost":"defaultVhost","App":"live","TcUrl":"rtmp://127.0.0.1/live","Stream":"34020000001330000001@34020000001320000001","Param":"?vhost=127.0.0.1"}}

The code is as follows:
srs_error_t SrsHttpHooks::on_connect(string url, SrsRequest* req)
{
srs_error_t err = srs_success;

int client_id = _srs_context->get_id();

SrsJsonObject* obj = SrsJsonAny::object();
SrsAutoFree(SrsJsonObject, obj);

std::string device_id = _srs_config->get_heartbeat_device_id();


obj->set("action", SrsJsonAny::str("on_connect"));
obj->set("device_id", SrsJsonAny::str(device_id.c_str()));
obj->set("client_id", SrsJsonAny::integer(client_id));
obj->set("ip", SrsJsonAny::str(req->ip.c_str()));
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str()));
obj->set("app", SrsJsonAny::str(req->app.c_str()));
obj->set("tcUrl", SrsJsonAny::str(req->tcUrl.c_str()));
obj->set("pageUrl", SrsJsonAny::str(req->pageUrl.c_str()));

std::string data = obj->dumps();
std::string res;
int status_code;

SrsHttpClient http;
if ((err = do_post(&http, url, data, status_code, res)) != srs_success) {
    return srs_error_wrap(err, "http: on_connect failed, client_id=%d, url=%s, request=%s, response=%s, code=%d",
        client_id, url.c_str(), data.c_str(), res.c_str(), status_code);
}

srs_trace("http: on_connect ok, client_id=%d, url=%s, request=%s, response=%s",
          client_id, url.c_str(), data.c_str(), res.c_str());

return err;

}

The official can consider making this more systematic.

TRANS_BY_GPT3

@winlinvip winlinvip added the Feature It's a new feature. label Jun 15, 2020
@winlinvip
Copy link
Member

winlinvip commented Jun 15, 2020

This is a reasonable demand, see if any friends are willing to implement it.

TRANS_BY_GPT3

@winlinvip
Copy link
Member

winlinvip commented Aug 23, 2021

UUID has already been supported here.

TRANS_BY_GPT3

@winlinvip winlinvip self-assigned this Sep 4, 2021
@winlinvip winlinvip changed the title 每个srs实例缺少一个实例唯一标识 Each SRS instance is missing a unique identifier for the instance. Jul 28, 2023
@winlinvip winlinvip added the TransByAI Translated by AI/GPT. label Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature It's a new feature. TransByAI Translated by AI/GPT.
Projects
None yet
Development

No branches or pull requests

2 participants