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