Skip to content

Commit 114a1c2

Browse files
committed
For #2424, use srandom/random to generate. 2.0.274
1 parent 0080346 commit 114a1c2

9 files changed

+33
-13
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ Remark:
340340

341341
## History
342342

343+
* <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>
344+
* v2.0, 2021-07-04, For [#2424](https://github.com/ossrs/srs/issues/2424), use srandom/random to generate. 2.0.274
343345
* <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>
344346
* v2.0, 2021-06-25, For [#2424](https://github.com/ossrs/srs/issues/2424), query the latest available version. 2.0.273
345347
* <strong>v2.0, 2020-01-25, [2.0 release8(2.0.272)][r2.0r8] released. 87292 lines.</strong>

trunk/src/app/srs_app_ingest.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ using namespace std;
3535
#include <srs_app_pithy_print.hpp>
3636
#include <srs_kernel_utility.hpp>
3737
#include <srs_app_utility.hpp>
38+
#include <srs_rtmp_utility.hpp>
3839

3940
// when error, ingester sleep for a while and retry.
4041
// ingest never sleep a long time, for we must start the stream ASAP.
@@ -436,7 +437,7 @@ void SrsIngester::show_ingest_log_message()
436437
}
437438

438439
// random choose one ingester to report.
439-
int index = rand() % (int)ingesters.size();
440+
int index = srs_random() % (int)ingesters.size();
440441
SrsIngesterFFMPEG* ingester = ingesters.at(index);
441442

442443
// reportable

trunk/src/app/srs_app_latest_version.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int SrsLatestVersion::start()
5454
return ERROR_SUCCESS;
5555
}
5656

57-
char buf[10];
57+
char buf[16];
5858
srs_random_generate(buf, sizeof(buf));
5959
for (int i = 0; i < (int)sizeof(buf); i++) {
6060
buf[i] = 'a' + uint8_t(buf[i])%25;

trunk/src/core/srs_core.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3131
// current release version
3232
#define VERSION_MAJOR 2
3333
#define VERSION_MINOR 0
34-
#define VERSION_REVISION 273
34+
#define VERSION_REVISION 274
3535

3636
// generated by configure, only macros.
3737
#include <srs_auto_headers.hpp>

trunk/src/kernel/srs_kernel_utility.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,17 @@ int64_t srs_get_system_startup_time_ms()
110110
if (_srs_system_time_startup_time <= 0) {
111111
srs_update_system_time_ms();
112112
}
113-
113+
114114
return _srs_system_time_startup_time / 1000;
115115
}
116+
int64_t srs_get_system_startup_time_us()
117+
{
118+
if (_srs_system_time_startup_time <= 0) {
119+
srs_update_system_time_ms();
120+
}
121+
122+
return _srs_system_time_startup_time;
123+
}
116124
int64_t srs_update_system_time_ms()
117125
{
118126
timeval now;

trunk/src/kernel/srs_kernel_utility.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ extern int srs_avc_nalu_read_bit(SrsBitStream* stream, int8_t& v);
4646
// get current system time in ms, use cache to avoid performance problem
4747
extern int64_t srs_get_system_time_ms();
4848
extern int64_t srs_get_system_startup_time_ms();
49+
extern int64_t srs_get_system_startup_time_us();
4950
// the deamon st-thread will update it.
5051
extern int64_t srs_update_system_time_ms();
5152

trunk/src/protocol/srs_rtmp_handshake.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ namespace _srs_internal
484484

485485
key_block::key_block()
486486
{
487-
offset = (int32_t)rand();
487+
offset = (int32_t)srs_random();
488488
random0 = NULL;
489489
random1 = NULL;
490490

@@ -566,7 +566,7 @@ namespace _srs_internal
566566

567567
digest_block::digest_block()
568568
{
569-
offset = (int32_t)rand();
569+
offset = (int32_t)srs_random();
570570
random0 = NULL;
571571
random1 = NULL;
572572

trunk/src/protocol/srs_rtmp_utility.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,24 @@ void srs_vhost_resolve(string& vhost, string& app, string& param)
115115
}
116116

117117
void srs_random_generate(char* bytes, int size)
118+
{
119+
for (int i = 0; i < size; i++) {
120+
// the common value in [0x0f, 0xf0]
121+
bytes[i] = 0x0f + (srs_random() % (256 - 0x0f - 0x0f));
122+
}
123+
}
124+
125+
long srs_random()
118126
{
119127
static bool _random_initialized = false;
120128
if (!_random_initialized) {
121-
srand(0);
122129
_random_initialized = true;
123-
srs_trace("srand initialized the random.");
124-
}
125-
126-
for (int i = 0; i < size; i++) {
127-
// the common value in [0x0f, 0xf0]
128-
bytes[i] = 0x0f + (rand() % (256 - 0x0f - 0x0f));
130+
131+
srandom((unsigned int)srs_get_system_startup_time_us());
132+
srs_trace("srandom initialized the random.");
129133
}
134+
135+
return random();
130136
}
131137

132138
string srs_generate_tc_url(string ip, string vhost, string app, string port, string param)

trunk/src/protocol/srs_rtmp_utility.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ extern void srs_vhost_resolve(
8080
* generate ramdom data for handshake.
8181
*/
8282
extern void srs_random_generate(char* bytes, int size);
83+
// Generate random value, use srandom(now_us) to init seed if not initialized.
84+
extern long srs_random();
8385

8486
/**
8587
* generate the tcUrl.

0 commit comments

Comments
 (0)