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

Log: Use 8 bytes random string as context id

This commit is contained in:
winlin 2020-07-09 16:51:20 +08:00
parent 5b199249d0
commit 742826a655
6 changed files with 33 additions and 35 deletions

View file

@ -148,20 +148,39 @@ void srs_parse_query_string(string q, map<string,string>& query)
}
}
static bool _random_initialized = false;
void srs_random_generate(char* bytes, int size)
{
static bool _random_initialized = false;
if (!_random_initialized) {
srand(0);
_random_initialized = true;
::srandom((unsigned long)(srs_update_system_time() | (::getpid()<<13)));
}
for (int i = 0; i < size; i++) {
// the common value in [0x0f, 0xf0]
bytes[i] = 0x0f + (rand() % (256 - 0x0f - 0x0f));
bytes[i] = 0x0f + (random() % (256 - 0x0f - 0x0f));
}
}
std::string srs_random_str(int len)
{
if (!_random_initialized) {
_random_initialized = true;
::srandom((unsigned long)(srs_update_system_time() | (::getpid()<<13)));
}
static string random_table = "01234567890123456789012345678901234567890123456789abcdefghijklmnopqrstuvwxyz";
string ret;
ret.reserve(len);
for (int i = 0; i < len; ++i) {
ret.append(1, random_table[random() % random_table.size()]);
}
return ret;
}
string srs_generate_tc_url(string host, string vhost, string app, int port)
{
string tcUrl = "rtmp://";