Skip to content

Commit

Permalink
For #2424, use srandom/random to generate. 4.0.139
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jul 4, 2021
1 parent e802fe5 commit 642359a
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The changelog for SRS.

## SRS 4.0 Changelog

* v4.0, 2021-07-04, For [#2424](https://github.com/ossrs/srs/issues/2424), use srandom/random to generate. 4.0.139
* v4.0, 2021-07-01, Merge [#2452](https://github.com/ossrs/srs/pull/2452), fix FFmpeg bug by updating channel_layout. 4.0.138
* v4.0, 2021-06-30, Merge [#2440](https://github.com/ossrs/srs/pull/2440), fix [#2390](https://github.com/ossrs/srs/issues/2390), SRT bug for zerolatency. 4.0.137
* v4.0, 2021-06-28, Merge [#2435](https://github.com/ossrs/srs/pull/2435), fix bug for HTTP-RAW-API to check vhost. 4.0.136
Expand Down
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,7 @@ Please read [CHANGELOG](CHANGELOG.md#changelog).

## Releases

* 2021-06-26, [Release v3.0-r6](https://github.com/ossrs/srs/releases/tag/v3.0-r6), 3.0 release6, 3.0.163, 123011 lines.
* 2021-04-28, [Release v3.0-r5][r3.0r5], 3.0 release5, 3.0.161, 122750 lines.
* 2021-04-24, [Release v3.0-r4][r3.0r4], 3.0 release4, 3.0.160, 122750 lines.
* 2021-01-02, [Release v3.0-r3][r3.0r3], 3.0 release3, 3.0.156, 122736 lines.
* 2020-10-31, [Release v3.0-r2][r3.0r2], 3.0 release2, 3.0.153, 122663 lines.
* 2020-10-10, [Release v3.0-r1][r3.0r1], 3.0 release1, 3.0.144, 122674 lines.
* 2020-07-04, Release [v4.0.139](https://github.com/ossrs/srs/releases/tag/v4.0.139), 4.0 dev0, v4.0.139, 143245 lines.
* 2020-06-27, [Release v3.0-r0][r3.0r0], 3.0 release0, 3.0.141, 122674 lines.
* 2020-03-29, [Release v3.0-b3][r3.0b4], 3.0 beta4, 3.0.139, 122674 lines.
* 2020-03-18, [Release v3.0-b3][r3.0b3], 3.0 beta3, 3.0.134, 122509 lines.
Expand Down
1 change: 1 addition & 0 deletions trunk/.gitignore
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,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 @@ srs_error_t SrsLatestVersion::start()
return srs_success;
}

server_id_ = srs_random_str(10);
server_id_ = srs_random_str(16);

return trd_->start();
}
Expand Down
3 changes: 2 additions & 1 deletion trunk/src/app/srs_app_rtc_dtls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ using namespace std;
#include <srs_kernel_rtc_rtp.hpp>
#include <srs_app_log.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_utility.hpp>

#include <srtp2/srtp.h>
#include <openssl/ssl.h>
Expand Down Expand Up @@ -297,7 +298,7 @@ srs_error_t SrsDtlsCertificate::initialize()
X509_NAME* subject = X509_NAME_new();
srs_assert(subject);

int serial = rand();
int serial = (int)srs_random();
ASN1_INTEGER_set(X509_get_serialNumber(dtls_cert), serial);

const std::string& aor = RTMP_SIG_SRS_DOMAIN;
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,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/core/srs_core_version4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

#define VERSION_MAJOR 4
#define VERSION_MINOR 0
#define VERSION_REVISION 138
#define VERSION_REVISION 139

#endif
2 changes: 1 addition & 1 deletion trunk/src/kernel/srs_kernel_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,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
3 changes: 0 additions & 3 deletions trunk/src/main/srs_main_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ srs_error_t do_main(int argc, char** argv)

// TODO: support both little and big endian.
srs_assert(srs_is_little_endian());

// For RTC to generating random ICE username.
::srandom((unsigned long)(srs_update_system_time() | (::getpid()<<13)));

// for gperf gmp or gcp,
// should never enable it when not enabled for performance issue.
Expand Down
27 changes: 13 additions & 14 deletions trunk/src/protocol/srs_protocol_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,39 +131,38 @@ void srs_parse_query_string(string q, map<string,string>& query)
}
}

static bool _random_initialized = false;

void srs_random_generate(char* bytes, int size)
{
if (!_random_initialized) {
_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 + (random() % (256 - 0x0f - 0x0f));
bytes[i] = 0x0f + (srs_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()]);
ret.append(1, random_table[srs_random() % random_table.size()]);
}

return ret;
}

long srs_random()
{
static bool _random_initialized = false;
if (!_random_initialized) {
_random_initialized = true;
::srandom((unsigned long)(srs_update_system_time() | (::getpid()<<13)));
}

return random();
}

string srs_generate_tc_url(string host, string vhost, string app, int port)
{
string tcUrl = "rtmp://";
Expand Down
3 changes: 3 additions & 0 deletions trunk/src/protocol/srs_protocol_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ extern void srs_random_generate(char* bytes, int size);
// Generate random string [0-9a-z] in size of len bytes.
extern std::string srs_random_str(int len);

// Generate random value, use srandom(now_us) to init seed if not initialized.
extern long srs_random();

/**
* generate the tcUrl without param.
* @remark Use host as tcUrl.vhost if vhost is default vhost.
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 @@ -341,7 +341,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 @@ -423,7 +423,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 642359a

Please sign in to comment.