Skip to content

Commit

Permalink
For #2424, use srandom/random to generate. 3.0.164
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jul 4, 2021
1 parent e7435a6 commit d72d052
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 15 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -137,6 +137,8 @@ Other important wiki:

## V3 changes

* <strong>v3.0, 2021-07-04, [3.0 release7(3.0.164)](https://github.com/ossrs/srs/releases/tag/v3.0-r7) released. 123463 lines.</strong>
* v3.0, 2021-07-04, For [#2424](https://github.com/ossrs/srs/issues/2424), use srandom/random to generate. 3.0.164
* <strong>v3.0, 2021-06-26, [3.0 release6(3.0.163)](https://github.com/ossrs/srs/releases/tag/v3.0-r6) released. 123011 lines.</strong>
* v3.0, 2021-06-26, For [#2424](https://github.com/ossrs/srs/issues/2424), query the latest available version. 3.0.163
* v3.0, 2021-05-12, Fix [#2311][bug #2311], Copy the request for stat client. 3.0.162
Expand Down Expand Up @@ -342,6 +344,8 @@ Other important wiki:

## V2 changes

* <strong>v2.0, 2021-07-04, [2.0 release9(2.0.274)](https://github.com/ossrs/srs/releases/tag/v2.0-r10) released. 87575 lines.</strong>
* v2.0, 2021-07-04, For [#2424](https://github.com/ossrs/srs/issues/2424), use srandom/random to generate. 2.0.274
* <strong>v2.0, 2021-06-26, [2.0 release9(2.0.273)](https://github.com/ossrs/srs/releases/tag/v2.0-r9) released. 87552 lines.</strong>
* v2.0, 2021-06-25, For [#2424](https://github.com/ossrs/srs/issues/2424), query the latest available version. 2.0.273
* <strong>v2.0, 2020-01-25, [2.0 release8(2.0.272)][r2.0r8] released. 87292 lines.</strong>
Expand Down
1 change: 1 addition & 0 deletions trunk/.gitignore
Expand Up @@ -13,6 +13,7 @@
/ide/srs_xcode/srs_xcode.xcodeproj/xcuserdata/
/research/aac/
/research/api-server/static-dir/mse
/research/api-server/static-dir/crossdomain.xml
/research/bat/
/research/big/
/research/bitch/
Expand Down
3 changes: 0 additions & 3 deletions trunk/research/api-server/static-dir/crossdomain.xml

This file was deleted.

2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_ingest.cpp
Expand Up @@ -484,7 +484,7 @@ void SrsIngester::show_ingest_log_message()
}

// random choose one ingester to report.
int index = rand() % (int)ingesters.size();
int index = srs_random() % (int)ingesters.size();
SrsIngesterFFMPEG* ingester = ingesters.at(index);

// reportable
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_latest_version.cpp
Expand Up @@ -54,7 +54,7 @@ srs_error_t SrsLatestVersion::start()
return srs_success;
}

char buf[10];
char buf[16];
srs_random_generate(buf, sizeof(buf));
for (int i = 0; i < (int)sizeof(buf); i++) {
buf[i] = 'a' + uint8_t(buf[i])%25;
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version3.hpp
Expand Up @@ -24,6 +24,6 @@
#ifndef SRS_CORE_VERSION3_HPP
#define SRS_CORE_VERSION3_HPP

#define SRS_VERSION3_REVISION 163
#define SRS_VERSION3_REVISION 164

#endif
2 changes: 1 addition & 1 deletion trunk/src/kernel/srs_kernel_utility.cpp
Expand Up @@ -119,7 +119,7 @@ srs_utime_t srs_get_system_startup_time()
if (_srs_system_time_startup_time <= 0) {
srs_update_system_time();
}

return _srs_system_time_startup_time;
}

Expand Down
17 changes: 11 additions & 6 deletions trunk/src/protocol/srs_protocol_utility.cpp
Expand Up @@ -149,17 +149,22 @@ void srs_parse_query_string(string q, map<string,string>& query)
}

void srs_random_generate(char* bytes, int size)
{
for (int i = 0; i < size; i++) {
// the common value in [0x0f, 0xf0]
bytes[i] = 0x0f + (srs_random() % (256 - 0x0f - 0x0f));
}
}

long srs_random()
{
static bool _random_initialized = false;
if (!_random_initialized) {
srand(0);
_random_initialized = true;
srandom((unsigned int)srs_get_system_startup_time());
}

for (int i = 0; i < size; i++) {
// the common value in [0x0f, 0xf0]
bytes[i] = 0x0f + (rand() % (256 - 0x0f - 0x0f));
}

return random();
}

string srs_generate_tc_url(string host, string vhost, string app, int port)
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/protocol/srs_protocol_utility.hpp
Expand Up @@ -69,6 +69,8 @@ extern void srs_parse_query_string(std::string q, std::map<std::string, std::str
* generate ramdom data for handshake.
*/
extern void srs_random_generate(char* bytes, int size);
// Generate random value, use srandom(now_us) to init seed if not initialized.
extern long srs_random();

/**
* generate the tcUrl without param.
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/protocol/srs_rtmp_handshake.cpp
Expand Up @@ -357,7 +357,7 @@ namespace srs_internal

key_block::key_block()
{
offset = (int32_t)rand();
offset = (int32_t)srs_random();
random0 = NULL;
random1 = NULL;

Expand Down Expand Up @@ -439,7 +439,7 @@ namespace srs_internal

digest_block::digest_block()
{
offset = (int32_t)rand();
offset = (int32_t)srs_random();
random0 = NULL;
random1 = NULL;

Expand Down

0 comments on commit d72d052

Please sign in to comment.