提交 6c23ab20 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Complete command line options and remove remaining multi-thread stuff.

上级 46f9edd8
......@@ -14,7 +14,7 @@ extern "C"
}
/*
* Logger facility for MediaSoup.
* Logger facility.
*
* If the macro MS_DEVEL is set (see below) the output is even more verbose
* (it shows the file number in each log and enables the MS_TRACE() call).
......
......@@ -60,7 +60,7 @@ namespace RTC
static Fingerprints fingerprints;
typedef std::vector<SrtpProfileMapEntry> SRTPProfiles;
static SRTPProfiles srtpProfiles;
static __thread MS_BYTE sslReadBuffer[];
static MS_BYTE sslReadBuffer[];
public:
DTLSHandler(Listener* listener);
......
......@@ -24,7 +24,7 @@ namespace RTC
static void onSRTPEvent(srtp_event_data_t* data);
private:
static __thread MS_BYTE encryptBuffer[];
static MS_BYTE encryptBuffer[];
public:
SRTPSession(Type type, RTC::SRTPProfile profile, MS_BYTE* key, size_t key_len);
......
......@@ -16,6 +16,7 @@ public:
struct Configuration
{
unsigned int logLevel { LOG_DEBUG };
bool useSyslog { false };
unsigned int syslogFacility { LOG_USER };
struct
......@@ -26,6 +27,7 @@ public:
MS_PORT maxPort { 59999 };
std::string dtlsCertificateFile;
std::string dtlsPrivateKeyFile;
// Private fields.
bool hasIPv4 { false };
bool hasIPv6 { false };
......
......@@ -7,6 +7,8 @@
#include <netinet/in.h> // sockaddr_in, sockaddr_in6
#include <arpa/inet.h> // htonl(), htons(), ntohl(), ntohs()
#define MS_PROCESS_NAME "mediasoup-worker"
#define MS_BYTE uint8_t
#define MS_2BYTES uint16_t
#define MS_4BYTES uint32_t
......
......@@ -17,7 +17,7 @@ public:
} UvSendData;
private:
static __thread MS_BYTE readBuffer[];
static MS_BYTE readBuffer[];
public:
UDPSocket(const std::string &ip, MS_PORT port);
......
......@@ -20,12 +20,12 @@ void DepOpenSSL::ClassInit()
MS_DEBUG("loaded openssl version: %s", SSLeay_version(SSLEAY_VERSION));
// First initialize OpenSSL stuff.
// Initialize OpenSSL stuff.
SSL_load_error_strings();
SSL_library_init();
RAND_poll();
// Make OpenSSL thread-safe.
// Make OpenSSL thread-safe (even if we are single thread).
DepOpenSSL::mutexes = new pthread_mutex_t[CRYPTO_num_locks()];
if (!DepOpenSSL::mutexes)
MS_THROW_ERROR("allocation of mutexes failed");
......
......@@ -20,8 +20,9 @@ void Logger::EnableSyslog()
{
MS_TRACE();
// TODO: Set the process name/id as well.
openlog("MediaSoup", (LOG_PID), Settings::configuration.syslogFacility);
MS_DEBUG("logging to Syslog");
openlog(MS_PROCESS_NAME, (LOG_PID), Settings::configuration.syslogFacility);
Logger::isSyslogEnabled = true;
}
......@@ -75,7 +75,7 @@ namespace RTC
{ RTC::SRTPProfile::AES_CM_128_HMAC_SHA1_80, "SRTP_AES128_CM_SHA1_80" },
{ RTC::SRTPProfile::AES_CM_128_HMAC_SHA1_32, "SRTP_AES128_CM_SHA1_32" }
};
__thread MS_BYTE DTLSHandler::sslReadBuffer[MS_SSL_READ_BUFFER_SIZE];
MS_BYTE DTLSHandler::sslReadBuffer[MS_SSL_READ_BUFFER_SIZE];
/* Static methods. */
......@@ -207,8 +207,8 @@ namespace RTC
LOG_OPENSSL_ERROR("X509_get_subject_name() failed");
goto error;
}
X509_NAME_add_entry_by_txt(cert_name, "O", MBSTRING_ASC, (unsigned char *)"Mediasoup", -1, -1, 0);
X509_NAME_add_entry_by_txt(cert_name, "CN", MBSTRING_ASC, (unsigned char *)"Mediasoup", -1, -1, 0);
X509_NAME_add_entry_by_txt(cert_name, "O", MBSTRING_ASC, (unsigned char *)MS_PROCESS_NAME, -1, -1, 0);
X509_NAME_add_entry_by_txt(cert_name, "CN", MBSTRING_ASC, (unsigned char *)MS_PROCESS_NAME, -1, -1, 0);
// It is self signed so set the issuer name to be the same as the subject.
ret = X509_set_issuer_name(DTLSHandler::certificate, cert_name);
......
......@@ -12,7 +12,7 @@ namespace RTC
{
/* Static variables. */
__thread MS_BYTE SRTPSession::encryptBuffer[MS_ENCRYPT_BUFFER_SIZE];
MS_BYTE SRTPSession::encryptBuffer[MS_ENCRYPT_BUFFER_SIZE];
/* Static methods. */
......
......@@ -35,7 +35,6 @@ namespace RTC
/* Static methods. */
// NOTE: Must be called from MediaSoup::Init().
void TCPServer::ClassInit()
{
MS_TRACE();
......@@ -95,11 +94,6 @@ namespace RTC
servers[1] = new RTC::TCPServer(uvHandles[1]);
}
/*
* By calling this method, two different workers (threads) can access to the
* static map of available ports. No problem since the map keys are not modified,
* and values are a MS_PORT (uint16_t) which is atomic.
*/
void TCPServer::RandomizePort(int address_family, uv_tcp_t* uvHandles[], bool pair)
{
MS_TRACE();
......
......@@ -88,6 +88,7 @@ void Settings::SetConfiguration(int argc, char* argv[])
struct option options[] =
{
{ "logLevel", optional_argument, nullptr, 'l' },
{ "useSyslog", optional_argument, nullptr, 's' },
{ "syslogFacility", optional_argument, nullptr, 'f' },
{ "rtcListenIPv4", optional_argument, nullptr, '4' },
{ "rtcListenIPv6", optional_argument, nullptr, '6' },
......@@ -113,6 +114,12 @@ void Settings::SetConfiguration(int argc, char* argv[])
SetLogLevel(value_string);
break;
case 's':
value_string = std::string(optarg);
if (value_string.compare("true") == 0)
Settings::configuration.useSyslog = true;
break;
case 'f':
value_string = std::string(optarg);
SetSyslogFacility(value_string);
......@@ -174,6 +181,10 @@ void Settings::SetConfiguration(int argc, char* argv[])
// Set DTLS certificate files (if provided),
Settings::SetDtlsCertificateAndPrivateKeyFiles();
// Use syslog if requested.
if (Settings::configuration.useSyslog)
Logger::EnableSyslog();
}
void Settings::PrintConfiguration()
......@@ -183,6 +194,7 @@ void Settings::PrintConfiguration()
MS_DEBUG("[configuration]");
MS_DEBUG("- logLevel: \"%s\"", Settings::logLevel2String[Settings::configuration.logLevel].c_str());
MS_DEBUG("- useSyslog: \"%s\"", Settings::configuration.useSyslog ? "true" : "false");
MS_DEBUG("- syslogFacility: \"%s\"", Settings::syslogFacility2String[Settings::configuration.syslogFacility].c_str());
MS_DEBUG("- RTC:");
......@@ -309,7 +321,7 @@ void Settings::SetRtcListenIPv4(const std::string &ip)
{
MS_TRACE();
if (ip.empty())
if (ip.empty() || ip.compare("false") == 0)
{
Settings::configuration.RTC.listenIPv4.clear();
Settings::configuration.RTC.hasIPv4 = false;
......@@ -339,7 +351,7 @@ void Settings::SetRtcListenIPv6(const std::string &ip)
{
MS_TRACE();
if (ip.empty())
if (ip.empty() || ip.compare("false") == 0)
{
Settings::configuration.RTC.listenIPv6.clear();
Settings::configuration.RTC.hasIPv6 = false;
......
......@@ -64,9 +64,8 @@ namespace Utils
{
MS_TRACE();
// TODO: refactor comment
// Init the seed of each thread with a random number taken from the address
// of the seed variable itself (which is different for each thread).
// Init the vrypto seed with a random number taken from the address
// of the seed variable itself (which is random).
Crypto::seed = (unsigned int)(unsigned long)&Crypto::seed;
// Create an OpenSSL HMAC_CTX context for HMAC SHA1 calculation.
......
......@@ -57,7 +57,7 @@ void on_error_close(uv_handle_t* handle)
/* Static variables. */
__thread MS_BYTE UDPSocket::readBuffer[MS_READ_BUFFER_SIZE];
MS_BYTE UDPSocket::readBuffer[MS_READ_BUFFER_SIZE];
/* Instance methods. */
......@@ -309,7 +309,7 @@ void UDPSocket::onUvRecvAlloc(size_t suggested_size, uv_buf_t* buf)
{
MS_TRACE();
// Tell UV to write into the per thread buffer.
// Tell UV to write into the static buffer.
buf->base = (char *)UDPSocket::readBuffer;
// Give UV all the buffer space.
buf->len = MS_READ_BUFFER_SIZE;
......
......@@ -18,7 +18,6 @@
#include <string>
#include <csignal> // sigaction()
#include <cerrno>
#include <cstdint> // uint8_t, etc // TODO: remove?
static void init();
static void ignoreSignals();
......@@ -31,10 +30,12 @@ int main(int argc, char* argv[])
if (argc == 1)
MS_EXIT_FAILURE("process id must be given as first argument");
id = std::string(argv[1]);
id = MS_PROCESS_NAME "#" + std::string(argv[1]);
Logger::Init(id);
MS_INFO("starting " MS_PROCESS_NAME);
#if defined(MS_LITTLE_ENDIAN)
MS_DEBUG("detected Little-Endian CPU");
#elif defined(MS_BIG_ENDIAN)
......@@ -46,7 +47,7 @@ int main(int argc, char* argv[])
#elif defined(INTPTR_MAX) && defined(INT64_MAX) && (INTPTR_MAX == INT64_MAX)
MS_DEBUG("detected 64 bits architecture");
#else
MS_NOTICE("cannot determine whether the architecture is 32 or 64 bits");
MS_WARN("cannot determine whether the architecture is 32 or 64 bits");
#endif
try
......@@ -58,8 +59,6 @@ int main(int argc, char* argv[])
MS_EXIT_FAILURE("%s", error.what());
}
MS_NOTICE("starting MediaSoup");
// Print configuration.
Settings::PrintConfiguration();
......@@ -77,7 +76,7 @@ int main(int argc, char* argv[])
}
destroy();
MS_EXIT_SUCCESS("MediaSoup ends");
MS_EXIT_SUCCESS(MS_PROCESS_NAME " ends");
}
void init()
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论