提交 9f73fee8 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

C++ cleanup and add ICE state "disconnected".

上级 4743f0e4
......@@ -77,6 +77,11 @@ class Transport extends EventEmitter
case 'icestatechange':
{
this._data.iceState = data.iceState;
// Unset .iceSelectedTuple if required
if (data.iceState === 'disconnected')
{
delete this._data.iceSelectedTuple;
}
// Emit it to the app
this.emit(event, data);
break;
......@@ -157,6 +162,8 @@ class Transport extends EventEmitter
// We won't receive events anymore, so be nice and manually update
// some fields and emit events before firing 'close'
delete this._data.iceSelectedTuple;
if (this._data.iceState !== 'closed')
{
this._data.iceState = 'closed';
......
......@@ -7,7 +7,7 @@ debugerror.log = console.error.bind(console);
const domready = require('domready');
const rtcninja = require('rtcninja');
// const randomString = require('random-string');
const randomString = require('random-string');
const Peer = require('./Peer');
let protooWsUrl;
......@@ -33,10 +33,10 @@ function run()
{
debug('run()');
// let username = randomString();
// let uuid = randomString();
let username = 'alice';
let uuid = 'aaaa';
let username = randomString();
let uuid = randomString();
// let username = 'alice';
// let uuid = 'aaaa';
let peer = new Peer(protooWsUrl, username, uuid);
......
......@@ -171,7 +171,7 @@ app.put('/test-transport', function(req)
{
let promise = mediaPeer.createTransport(
{
udp : true,
udp : false,
tcp : true,
preferIPv4 : true,
preferUdp : true
......
......@@ -20,7 +20,7 @@ public:
private:
void Close();
RTC::Room* GetRoomFromRequest(Channel::Request* request, unsigned int* roomId = nullptr);
RTC::Room* GetRoomFromRequest(Channel::Request* request, uint32_t* roomId = nullptr);
/* Methods inherited from SignalsHandler::Listener. */
public:
......@@ -43,7 +43,7 @@ private:
SignalsHandler* signalsHandler = nullptr;
// Others.
bool closed = false;
std::unordered_map<unsigned int, RTC::Room*> rooms;
std::unordered_map<uint32_t, RTC::Room*> rooms;
};
#endif
......@@ -23,7 +23,8 @@ namespace RTC
{
NEW = 1,
CONNECTED,
COMPLETED
COMPLETED,
DISCONNECTED
};
public:
......@@ -38,6 +39,7 @@ namespace RTC
virtual void onICESelectedTuple(ICEServer* iceServer, RTC::TransportTuple* tuple) = 0;
virtual void onICEConnected(ICEServer* iceServer) = 0;
virtual void onICECompleted(ICEServer* iceServer) = 0;
virtual void onICEDisconnected(ICEServer* iceServer) = 0;
};
public:
......@@ -50,6 +52,7 @@ namespace RTC
std::string& GetPassword();
IceState GetState();
bool IsValidTuple(RTC::TransportTuple* tuple);
void RemoveTuple(RTC::TransportTuple* tuple);
// This should be just called in 'connected' or completed' state
// and the given tuple must be an already valid tuple.
void ForceSelectedTuple(RTC::TransportTuple* tuple);
......
......@@ -31,15 +31,15 @@ namespace RTC
};
public:
IceCandidate(RTC::UDPSocket* udpSocket, uint64_t priority);
IceCandidate(RTC::TCPServer* tcpServer, uint64_t priority);
IceCandidate(RTC::UDPSocket* udpSocket, uint32_t priority);
IceCandidate(RTC::TCPServer* tcpServer, uint32_t priority);
Json::Value toJson();
private:
// Others.
std::string foundation;
uint64_t priority;
uint32_t priority;
std::string ip;
Protocol protocol;
MS_PORT port;
......
#ifndef MS_RTC_PEER_H
#define MS_RTC_PEER_H
#include "common.h"
#include "RTC/Transport.h"
#include "Channel/Request.h"
#include "Channel/Notifier.h"
......@@ -21,7 +22,7 @@ namespace RTC
};
public:
Peer(Listener* listener, Channel::Notifier* notifier, unsigned int peerId, std::string& peerName);
Peer(Listener* listener, Channel::Notifier* notifier, uint32_t peerId, std::string& peerName);
virtual ~Peer();
void Close();
......@@ -29,7 +30,7 @@ namespace RTC
void HandleRequest(Channel::Request* request);
private:
RTC::Transport* GetTransportFromRequest(Channel::Request* request, unsigned int* iceTransportId = nullptr);
RTC::Transport* GetTransportFromRequest(Channel::Request* request, uint32_t* iceTransportId = nullptr);
/* Pure virtual methods inherited from RTC::Transport::Listener. */
public:
......@@ -37,7 +38,7 @@ namespace RTC
public:
// Passed by argument.
unsigned int peerId;
uint32_t peerId;
std::string peerName;
private:
......@@ -45,7 +46,7 @@ namespace RTC
Listener* listener = nullptr;
Channel::Notifier* notifier = nullptr;
// Others.
std::unordered_map<unsigned int, RTC::Transport*> transports;
std::unordered_map<uint32_t, RTC::Transport*> transports;
};
}
......
......@@ -31,11 +31,8 @@ namespace RTC
virtual void onTransportClosed(RTC::Transport* transport) = 0;
};
private:
static size_t maxTuples;
public:
Transport(Listener* listener, Channel::Notifier* notifier, unsigned int transportId, Json::Value& data, Transport* rtpTransport = nullptr);
Transport(Listener* listener, Channel::Notifier* notifier, uint32_t transportId, Json::Value& data, Transport* rtpTransport = nullptr);
virtual ~Transport();
void Close();
......@@ -43,7 +40,7 @@ namespace RTC
void HandleRequest(Channel::Request* request);
std::string& GetIceUsernameFragment();
std::string& GetIcePassword();
Transport* CreateAssociatedTransport(unsigned int transportId);
Transport* CreateAssociatedTransport(uint32_t transportId);
private:
void ClosePorts();
......@@ -81,6 +78,7 @@ namespace RTC
virtual void onICESelectedTuple(ICEServer* iceServer, RTC::TransportTuple* tuple) override;
virtual void onICEConnected(ICEServer* iceServer) override;
virtual void onICECompleted(ICEServer* iceServer) override;
virtual void onICEDisconnected(ICEServer* iceServer) override;
/* Pure virtual methods inherited from RTC::DTLSTransport::Listener. */
public:
......@@ -93,7 +91,7 @@ namespace RTC
public:
// Passed by argument.
unsigned int transportId;
uint32_t transportId;
protected:
// Others.
......
......@@ -199,14 +199,13 @@ namespace Utils
public:
static void ClassInit();
static void ClassDestroy();
static unsigned int GetRandomUInt(unsigned int min, unsigned int max);
static uint32_t GetRandomUInt(uint32_t min, uint32_t max);
static const std::string GetRandomString(size_t len);
// static const char* GetRandomHexString(char* str, size_t len);
static MS_4BYTES GetCRC32(const MS_BYTE* data, size_t size);
static const MS_BYTE* GetHMAC_SHA1(const std::string &key, const MS_BYTE* data, size_t len);
private:
static unsigned int seed;
static uint32_t seed;
static HMAC_CTX hmacSha1Ctx;
static MS_BYTE hmacSha1Buffer[];
static const MS_4BYTES crc32Table[256];
......@@ -215,14 +214,14 @@ namespace Utils
/* Inline static methods. */
inline
unsigned int Crypto::GetRandomUInt(unsigned int min, unsigned int max)
uint32_t Crypto::GetRandomUInt(uint32_t min, uint32_t max)
{
// NOTE: This is the original, but produces very small values.
// Crypto::seed = (214013 * Crypto::seed) + 2531011;
// return (((Crypto::seed>>16)&0x7FFF) % (max - min + 1)) + min;
// This seems to produce better results.
Crypto::seed = (unsigned int)((214013 * Crypto::seed) + 2531011);
Crypto::seed = (uint32_t)((214013 * Crypto::seed) + 2531011);
return (((Crypto::seed>>4)&0x7FFF7FFF) % (max - min + 1)) + min;
}
......@@ -247,23 +246,6 @@ namespace Utils
return std::string(buffer, len);
}
// inline
// const char* Crypto::GetRandomHexString(char* buffer, size_t len)
// {
// static const char hex_chars[] =
// {
// '0','1','2','3','4','5','6','7','8','9',
// 'A','B','C','D','E','F','G','H','I','J',
// 'K','L','M','N','O','P','Q','R','S','T',
// 'U','V','W','X','Y','Z'
// };
// for (size_t i = 0; i < len; ++i)
// buffer[i] = hex_chars[GetRandomUInt(0, sizeof(hex_chars) - 1)];
// return buffer;
// }
inline
MS_4BYTES Crypto::GetCRC32(const MS_BYTE* data, size_t size)
{
......
......@@ -3,6 +3,7 @@
#include <cstddef> // size_t
#include <cstdint> // uint8_t, etc
#include <cinttypes> // PRIu64, etc
#include <sys/socket.h> // struct sockaddr, struct sockaddr_storage, AF_INET, AF_INET6
#include <netinet/in.h> // sockaddr_in, sockaddr_in6
#include <arpa/inet.h> // htonl(), htons(), ntohl(), ntohs()
......
......@@ -87,7 +87,7 @@ void Loop::Close()
this->channel->Close();
}
RTC::Room* Loop::GetRoomFromRequest(Channel::Request* request, unsigned int* roomId)
RTC::Room* Loop::GetRoomFromRequest(Channel::Request* request, uint32_t* roomId)
{
MS_TRACE();
......@@ -177,7 +177,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
case Channel::Request::MethodId::worker_createRoom:
{
RTC::Room* room;
unsigned int roomId;
uint32_t roomId;
try
{
......@@ -209,7 +209,7 @@ void Loop::onChannelRequest(Channel::UnixStreamSocket* channel, Channel::Request
this->rooms[roomId] = room;
MS_DEBUG("Room created [roomId:%u]", roomId);
MS_DEBUG("Room created [roomId:%" PRIu32 "]", roomId);
request->Accept();
break;
......
......@@ -206,8 +206,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 *)MS_APP_NAME, -1, -1, 0);
X509_NAME_add_entry_by_txt(cert_name, "CN", MBSTRING_ASC, (unsigned char *)MS_APP_NAME, -1, -1, 0);
X509_NAME_add_entry_by_txt(cert_name, "O", MBSTRING_ASC, (uint8_t*)MS_APP_NAME, -1, -1, 0);
X509_NAME_add_entry_by_txt(cert_name, "CN", MBSTRING_ASC, (uint8_t*)MS_APP_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(DTLSTransport::certificate, cert_name);
......@@ -418,7 +418,7 @@ namespace RTC
{
std::string algorithm_str = it->first;
FingerprintAlgorithm algorithm = it->second;
unsigned char binary_fingerprint[EVP_MAX_MD_SIZE];
uint8_t binary_fingerprint[EVP_MAX_MD_SIZE];
unsigned int size = 0;
char hex_fingerprint[(EVP_MAX_MD_SIZE * 2) + 1];
const EVP_MD* hash_function;
......@@ -960,7 +960,7 @@ namespace RTC
MS_ASSERT(this->remoteFingerprint.algorithm != FingerprintAlgorithm::NONE, "remote fingerprint not set");
X509* certificate;
unsigned char binary_fingerprint[EVP_MAX_MD_SIZE];
uint8_t binary_fingerprint[EVP_MAX_MD_SIZE];
unsigned int size = 0;
char hex_fingerprint[(EVP_MAX_MD_SIZE * 2) + 1];
const EVP_MD* hash_function;
......
......@@ -136,7 +136,7 @@ namespace RTC
return;
}
MS_DEBUG("processing STUN Binding Request [Priority:%u, UseCandidate:%s]", (unsigned int)msg->GetPriority(), msg->HasUseCandidate() ? "true" : "false");
MS_DEBUG("processing STUN Binding Request [Priority:%" PRIu32 ", UseCandidate:%s]", (uint32_t)msg->GetPriority(), msg->HasUseCandidate() ? "true" : "false");
// Create a success response.
RTC::STUNMessage* response = msg->CreateSuccessResponse();
......@@ -191,13 +191,63 @@ namespace RTC
return false;
}
void ICEServer::RemoveTuple(RTC::TransportTuple* tuple)
{
auto it = this->tuples.begin();
RTC::TransportTuple* removed_tuple = nullptr;
// Find the removed tuple.
for (; it != this->tuples.end(); ++it)
{
RTC::TransportTuple* stored_tuple = &(*it);
if (stored_tuple->Compare(tuple))
{
removed_tuple = stored_tuple;
break;
}
}
// If not found, ignore.
if (!removed_tuple)
return;
// If this is not the selected tuple just remove it.
if (removed_tuple != this->selectedTuple)
{
this->tuples.erase(it);
return;
}
// Otherwise this was the selected tuple.
else
{
this->tuples.erase(it);
this->selectedTuple = nullptr;
// Mark the first tuple as selected tuple (if any).
if (this->tuples.begin() != this->tuples.end())
{
SetSelectedTuple(&(*this->tuples.begin()));
}
// Or just emit 'disconnected' and the null selected tuple..
else
{
// Update state.
this->state = IceState::DISCONNECTED;
// Notify the listener.
this->listener->onICESelectedTuple(this, nullptr);
this->listener->onICEDisconnected(this);
}
}
}
void ICEServer::ForceSelectedTuple(RTC::TransportTuple* tuple)
{
MS_TRACE();
MS_ASSERT(this->state != IceState::NEW, "cannot force the selected tuple if not in 'connecting' or 'connected' state");
// TODO: Remove as this assert is reduntant.
MS_ASSERT(this->selectedTuple != nullptr, "cannot force the selected tuple if there was not a selected tuple");
auto stored_tuple = HasTuple(tuple);
......@@ -258,6 +308,50 @@ namespace RTC
break;
}
case IceState::DISCONNECTED:
{
// There should be no tuples.
MS_ASSERT(this->tuples.size() == 0, "state is 'disconnected' but there are %zu tuples", this->tuples.size());
// There shouldn't be a selected tuple.
MS_ASSERT(this->selectedTuple == nullptr, "state is 'disconnected' but there is selected tuple");
if (!has_use_candidate)
{
MS_DEBUG("transition from state 'disconnected' to 'connected'");
// Store the tuple.
auto stored_tuple = AddTuple(tuple);
// Mark it as selected tuple.
SetSelectedTuple(stored_tuple);
// Update state.
this->state = IceState::CONNECTED;
// Notify the listener.
this->listener->onICEConnected(this);
}
else
{
MS_DEBUG("transition from state 'disconnected' to 'completed'");
// Store the tuple.
auto stored_tuple = AddTuple(tuple);
// Mark it as selected tuple.
SetSelectedTuple(stored_tuple);
// Update state.
this->state = IceState::COMPLETED;
// Notify the listener.
this->listener->onICECompleted(this);
}
break;
}
case IceState::CONNECTED:
{
// There should be some tuples.
......@@ -385,42 +479,4 @@ namespace RTC
// Notify the listener.
this->listener->onICESelectedTuple(this, this->selectedTuple);
}
// TODO
// bool Transport::RemoveTuple(RTC::TransportTuple* tuple)
// {
// for (auto it = this->tuples.begin(); it != this->tuples.end(); ++it)
// {
// RTC::TransportTuple* valid_tuple = &(*it);
// // If the tuple was a valid tuple then remove it.
// if (valid_tuple->Compare(tuple))
// {
// this->tuples.erase(it);
// // If it was the media tuple then unset it and set the media
// // tuple to the first valid tuple (if any).
// if (this->mediaTuple == valid_tuple)
// {
// if (this->tuples.begin() != this->tuples.end())
// {
// this->mediaTuple = &(*this->tuples.begin());
// }
// else
// {
// this->mediaTuple = nullptr;
// // This is just useful is there are just TCP tuples.
// this->icePaired = false;
// this->icePairedWithUseCandidate = false;
// // TODO: This should fire a 'icefailed' event.
// }
// }
// return true;
// }
// }
// return false;
// }
}
......@@ -6,7 +6,7 @@ namespace RTC
{
/* Instance methods. */
IceCandidate::IceCandidate(RTC::UDPSocket* udpSocket, uint64_t priority) :
IceCandidate::IceCandidate(RTC::UDPSocket* udpSocket, uint32_t priority) :
foundation("udpcandidate"),
priority(priority),
ip(udpSocket->GetLocalIP()),
......@@ -15,7 +15,7 @@ namespace RTC
type(CandidateType::HOST)
{}
IceCandidate::IceCandidate(RTC::TCPServer* tcpServer, uint64_t priority) :
IceCandidate::IceCandidate(RTC::TCPServer* tcpServer, uint32_t priority) :
foundation("tcpcandidate"),
priority(priority),
ip(tcpServer->GetLocalIP()),
......@@ -42,7 +42,7 @@ namespace RTC
Json::Value data;
data[k_foundation] = this->foundation;
data[k_priority] = (unsigned int)this->priority;
data[k_priority] = this->priority;
data[k_ip] = this->ip;
data[k_port] = this->port;
......
......@@ -8,7 +8,7 @@ namespace RTC
{
/* Instance methods. */
Peer::Peer(Listener* listener, Channel::Notifier* notifier, unsigned int peerId, std::string& peerName) :
Peer::Peer(Listener* listener, Channel::Notifier* notifier, uint32_t peerId, std::string& peerName) :
peerId(peerId),
peerName(peerName),
listener(listener),
......@@ -75,11 +75,11 @@ namespace RTC
{
case Channel::Request::MethodId::peer_close:
{
unsigned int peerId = this->peerId;
uint32_t peerId = this->peerId;
Close();
MS_DEBUG("Peer closed [peerId:%u]", peerId);
MS_DEBUG("Peer closed [peerId:%" PRIu32 "]", peerId);
request->Accept();
break;
......@@ -97,7 +97,7 @@ namespace RTC
case Channel::Request::MethodId::peer_createTransport:
{
RTC::Transport* transport;
unsigned int transportId;
uint32_t transportId;
try
{
......@@ -129,7 +129,7 @@ namespace RTC
this->transports[transportId] = transport;
MS_DEBUG("Transport created [transportId:%u]", transportId);
MS_DEBUG("Transport created [transportId:%" PRIu32 "]", transportId);
auto data = transport->toJson();
......@@ -141,7 +141,7 @@ namespace RTC
case Channel::Request::MethodId::peer_createAssociatedTransport:
{
RTC::Transport* transport;
unsigned int transportId;
uint32_t transportId;
try
{
......@@ -197,7 +197,7 @@ namespace RTC
this->transports[transportId] = transport;
MS_DEBUG("Associated Transport created [transportId:%u]", transportId);
MS_DEBUG("Associated Transport created [transportId:%" PRIu32 "]", transportId);
auto data = transport->toJson();
......@@ -242,7 +242,7 @@ namespace RTC
}
}
RTC::Transport* Peer::GetTransportFromRequest(Channel::Request* request, unsigned int* transportId)
RTC::Transport* Peer::GetTransportFromRequest(Channel::Request* request, uint32_t* transportId)
{
MS_TRACE();
......
......@@ -14,7 +14,7 @@
/* Static helpers. */
static inline
uint64_t generateIceCandidatePriority(uint16_t local_preference, RTC::ICEServer::IceComponent component)
uint32_t generateIceCandidatePriority(uint16_t local_preference, RTC::ICEServer::IceComponent component)
{
MS_TRACE();
......@@ -29,13 +29,9 @@ uint64_t generateIceCandidatePriority(uint16_t local_preference, RTC::ICEServer:
namespace RTC
{
/* Class variables. */
size_t Transport::maxTuples = 8;
/* Instance methods. */
Transport::Transport(Listener* listener, Channel::Notifier* notifier, unsigned int transportId, Json::Value& data, Transport* rtpTransport) :
Transport::Transport(Listener* listener, Channel::Notifier* notifier, uint32_t transportId, Json::Value& data, Transport* rtpTransport) :
transportId(transportId),
listener(listener),
notifier(notifier)
......@@ -108,7 +104,7 @@ namespace RTC
if (preferUdp)
local_preference += ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_PROTOCOL_INCREMENT;
uint64_t priority = generateIceCandidatePriority(local_preference, this->iceServer->GetComponent());
uint32_t priority = generateIceCandidatePriority(local_preference, this->iceServer->GetComponent());
try
{
......@@ -135,7 +131,7 @@ namespace RTC
if (preferUdp)
local_preference += ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_PROTOCOL_INCREMENT;
uint64_t priority = generateIceCandidatePriority(local_preference, this->iceServer->GetComponent());
uint32_t priority = generateIceCandidatePriority(local_preference, this->iceServer->GetComponent());
try
{
......@@ -162,7 +158,7 @@ namespace RTC
if (preferTcp)
local_preference += ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_PROTOCOL_INCREMENT;
uint64_t priority = generateIceCandidatePriority(local_preference, this->iceServer->GetComponent());
uint32_t priority = generateIceCandidatePriority(local_preference, this->iceServer->GetComponent());
try
{
......@@ -189,7 +185,7 @@ namespace RTC
if (preferTcp)
local_preference += ICE_CANDIDATE_LOCAL_PRIORITY_PREFER_PROTOCOL_INCREMENT;
uint64_t priority = generateIceCandidatePriority(local_preference, this->iceServer->GetComponent());
uint32_t priority = generateIceCandidatePriority(local_preference, this->iceServer->GetComponent());
try
{
......@@ -283,6 +279,7 @@ namespace RTC
static const Json::StaticString v_new("new");
static const Json::StaticString v_connected("connected");
static const Json::StaticString v_completed("completed");
static const Json::StaticString v_disconnected("disconnected");
static const Json::StaticString k_dtlsLocalParameters("dtlsLocalParameters");
static const Json::StaticString k_fingerprints("fingerprints");
static const Json::StaticString k_role("role");
......@@ -329,6 +326,9 @@ namespace RTC
case RTC::ICEServer::IceState::COMPLETED:
data[k_iceState] = v_completed;
break;
case RTC::ICEServer::IceState::DISCONNECTED:
data[k_iceState] = v_disconnected;
break;
}
// Add `dtlsLocalParameters.fingerprints`.
......@@ -381,11 +381,11 @@ namespace RTC
{
case Channel::Request::MethodId::transport_close:
{
unsigned int transportId = this->transportId;
uint32_t transportId = this->transportId;
Close();
MS_DEBUG("Transport closed [transportId:%u]", transportId);
MS_DEBUG("Transport closed [transportId:%" PRIu32 "]", transportId);
request->Accept();
break;
......@@ -522,6 +522,8 @@ namespace RTC
{
MS_TRACE();
this->selectedTuple = nullptr;
for (auto socket : this->udpSockets)
socket->Close();
this->udpSockets.clear();
......@@ -531,7 +533,7 @@ namespace RTC
this->tcpServers.clear();
}
Transport* Transport::CreateAssociatedTransport(unsigned int transportId)
Transport* Transport::CreateAssociatedTransport(uint32_t transportId)
{
MS_TRACE();
......@@ -738,14 +740,9 @@ namespace RTC
if (!IsAlive())
return;
// TODO
// RTC::TransportTuple tuple(connection);
RTC::TransportTuple tuple(connection);
// if (RemoveTuple(&tuple))
// {
// MS_DEBUG("valid tuple %s:", is_closed_by_peer ? "closed by peer" : "locally closed");
// }
this->iceServer->RemoveTuple(&tuple);
}
void Transport::onSTUNDataRecv(RTC::TCPConnection *connection, const MS_BYTE* data, size_t len)
......@@ -820,11 +817,12 @@ namespace RTC
this->selectedTuple = tuple;
// Notify.
eventData[k_iceSelectedTuple] = tuple->toJson();
// Notify.
this->notifier->Emit(this->transportId, "iceselectedtuplechange", eventData);
// Notify if tuple is given.
if (tuple)
{
eventData[k_iceSelectedTuple] = tuple->toJson();
this->notifier->Emit(this->transportId, "iceselectedtuplechange", eventData);
}
}
void Transport::onICEConnected(RTC::ICEServer* iceServer)
......@@ -865,6 +863,24 @@ namespace RTC
MayRunDTLSTransport();
}
void Transport::onICEDisconnected(RTC::ICEServer* iceServer)
{
MS_TRACE();
static const Json::StaticString k_iceState("iceState");
static const Json::StaticString v_disconnected("disconnected");
Json::Value eventData;
MS_DEBUG("ICE disconnected");
// Unset the
// Notify.
eventData[k_iceState] = v_disconnected;
this->notifier->Emit(this->transportId, "icestatechange", eventData);
}
void Transport::onDTLSConnecting(RTC::DTLSTransport* dtlsTransport)
{
MS_TRACE();
......@@ -901,39 +917,39 @@ namespace RTC
this->notifier->Emit(this->transportId, "dtlsstatechange", eventData);
}
void Transport::onDTLSClosed(RTC::DTLSTransport* dtlsTransport)
void Transport::onDTLSFailed(RTC::DTLSTransport* dtlsTransport)
{
MS_TRACE();
static const Json::StaticString k_dtlsState("dtlsState");
static const Json::StaticString v_closed("closed");
static const Json::StaticString v_failed("failed");
Json::Value eventData;
MS_DEBUG("DTLS remotely disconnected");
MS_DEBUG("DTLS failed");
ClosePorts();
// Notify.
eventData[k_dtlsState] = v_closed;
eventData[k_dtlsState] = v_failed;
this->notifier->Emit(this->transportId, "dtlsstatechange", eventData);
}
void Transport::onDTLSFailed(RTC::DTLSTransport* dtlsTransport)
void Transport::onDTLSClosed(RTC::DTLSTransport* dtlsTransport)
{
MS_TRACE();
static const Json::StaticString k_dtlsState("dtlsState");
static const Json::StaticString v_failed("failed");
static const Json::StaticString v_closed("closed");
Json::Value eventData;
MS_DEBUG("DTLS failed");
MS_DEBUG("DTLS remotely disconnected");
ClosePorts();
// Notify.
eventData[k_dtlsState] = v_failed;
eventData[k_dtlsState] = v_closed;
this->notifier->Emit(this->transportId, "dtlsstatechange", eventData);
}
......@@ -943,7 +959,7 @@ namespace RTC
if (!this->selectedTuple)
{
MS_DEBUG("no media address set, cannot send DTLS packet");
MS_DEBUG("no selected tuple set, cannot send DTLS packet");
return;
}
......
......@@ -8,7 +8,7 @@ namespace Utils
{
/* Static variables. */
unsigned int Crypto::seed;
uint32_t Crypto::seed;
HMAC_CTX Crypto::hmacSha1Ctx;
MS_BYTE Crypto::hmacSha1Buffer[20]; // SHA-1 result is 20 bytes long.
const MS_4BYTES Crypto::crc32Table[] =
......@@ -66,7 +66,7 @@ namespace Utils
// 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;
Crypto::seed = (uint32_t)(unsigned long)&Crypto::seed;
// Create an OpenSSL HMAC_CTX context for HMAC SHA1 calculation.
HMAC_CTX_init(&Crypto::hmacSha1Ctx);
......@@ -88,11 +88,11 @@ namespace Utils
ret = HMAC_Init_ex(&Crypto::hmacSha1Ctx, key.c_str(), key.length(), EVP_sha1(), nullptr);
MS_ASSERT(ret == 1, "OpenSSL HMAC_Init_ex() failed with key '%s'", key.c_str());
ret = HMAC_Update(&Crypto::hmacSha1Ctx, (const unsigned char*)data, (int)len);
ret = HMAC_Update(&Crypto::hmacSha1Ctx, (const uint8_t*)data, (int)len);
MS_ASSERT(ret == 1, "OpenSSL HMAC_Update() failed with key '%s' and data length %zu bytes", key.c_str(), len);
unsigned int result_len;
ret = HMAC_Final(&Crypto::hmacSha1Ctx, (unsigned char *)Crypto::hmacSha1Buffer, &result_len);
uint32_t result_len;
ret = HMAC_Final(&Crypto::hmacSha1Ctx, (uint8_t *)Crypto::hmacSha1Buffer, &result_len);
MS_ASSERT(ret == 1, "OpenSSL HMAC_Final() failed with key '%s' and data length %zu bytes", key.c_str(), len);
MS_ASSERT(result_len == 20, "OpenSSL HMAC_Final() result_len is %u instead of 20", result_len);
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论