Skip to content

Commit

Permalink
For #2424, use srandom/random to generate. 2.0.274
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jul 4, 2021
1 parent 0080346 commit 114a1c2
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ Remark:

## History

* <strong>v2.0, 2021-06-26, [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
3 changes: 2 additions & 1 deletion trunk/src/app/srs_app_ingest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using namespace std;
#include <srs_app_pithy_print.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_app_utility.hpp>
#include <srs_rtmp_utility.hpp>

// when error, ingester sleep for a while and retry.
// ingest never sleep a long time, for we must start the stream ASAP.
Expand Down Expand Up @@ -436,7 +437,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
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int SrsLatestVersion::start()
return ERROR_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.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR 2
#define VERSION_MINOR 0
#define VERSION_REVISION 273
#define VERSION_REVISION 274

// generated by configure, only macros.
#include <srs_auto_headers.hpp>
Expand Down
10 changes: 9 additions & 1 deletion trunk/src/kernel/srs_kernel_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,17 @@ int64_t srs_get_system_startup_time_ms()
if (_srs_system_time_startup_time <= 0) {
srs_update_system_time_ms();
}

return _srs_system_time_startup_time / 1000;
}
int64_t srs_get_system_startup_time_us()
{
if (_srs_system_time_startup_time <= 0) {
srs_update_system_time_ms();
}

return _srs_system_time_startup_time;
}
int64_t srs_update_system_time_ms()
{
timeval now;
Expand Down
1 change: 1 addition & 0 deletions trunk/src/kernel/srs_kernel_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extern int srs_avc_nalu_read_bit(SrsBitStream* stream, int8_t& v);
// get current system time in ms, use cache to avoid performance problem
extern int64_t srs_get_system_time_ms();
extern int64_t srs_get_system_startup_time_ms();
extern int64_t srs_get_system_startup_time_us();
// the deamon st-thread will update it.
extern int64_t srs_update_system_time_ms();

Expand Down
4 changes: 2 additions & 2 deletions trunk/src/protocol/srs_rtmp_handshake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,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 @@ -566,7 +566,7 @@ namespace _srs_internal

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

Expand Down
20 changes: 13 additions & 7 deletions trunk/src/protocol/srs_rtmp_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,24 @@ void srs_vhost_resolve(string& vhost, string& app, string& param)
}

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;
srs_trace("srand initialized the random.");
}

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

srandom((unsigned int)srs_get_system_startup_time_us());
srs_trace("srandom initialized the random.");
}

return random();
}

string srs_generate_tc_url(string ip, string vhost, string app, string port, string param)
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/protocol/srs_rtmp_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ extern void srs_vhost_resolve(
* 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.
Expand Down

0 comments on commit 114a1c2

Please sign in to comment.