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

ICE works.

上级 73d6ae3b
......@@ -49,7 +49,7 @@ tap.test('server.updateSettings() with invalid options must fail', { timeout: 10
});
});
tap.test('server.updateSettings() in a closed Server must fail', { timeout: 1000 }, (t) =>
tap.test('server.updateSettings() in a closed server must fail', { timeout: 1000 }, (t) =>
{
let server = mediasoup.Server();
......@@ -86,7 +86,7 @@ tap.test('server.Room() must succeed', { timeout: 1000 }, (t) =>
setTimeout(() => room.close(), 100);
});
tap.test('server.Room() in a closed Server must fail', { timeout: 1000 }, (t) =>
tap.test('server.Room() in a closed server must fail', { timeout: 1000 }, (t) =>
{
let server = mediasoup.Server();
......
......@@ -11,6 +11,7 @@
#include "RTC/TCPConnection.h"
#include <string>
#include <vector>
#include <list>
#include <json/json.h>
namespace RTC
......@@ -35,6 +36,9 @@ namespace RTC
RTCP = 2
};
private:
static size_t maxSources;
public:
Transport(Listener* listener, unsigned int transportId, Json::Value& data, Transport* rtpTransport = nullptr);
virtual ~Transport();
......@@ -45,6 +49,11 @@ namespace RTC
std::string& GetIcePassword();
Transport* CreateAssociatedTransport(unsigned int transportId);
private:
bool SetSendingSource(RTC::TransportSource* source);
bool IsValidSource(RTC::TransportSource* source);
bool RemoveSource(RTC::TransportSource* source);
/* Pure virtual methods inherited from RTC::IceServer::Listener. */
public:
virtual void onOutgoingSTUNMessage(RTC::IceServer* iceServer, RTC::STUNMessage* msg, RTC::TransportSource* source) override;
......@@ -93,8 +102,12 @@ namespace RTC
std::vector<RTC::UDPSocket*> udpSockets;
std::vector<RTC::TCPServer*> tcpServers;
// Others.
std::vector<IceCandidate> iceLocalCandidates;
bool allocated = false;
std::vector<IceCandidate> iceLocalCandidates;
std::list<RTC::TransportSource> sources;
RTC::TransportSource* sendingSource = nullptr;
bool icePaired = false;
bool icePairedWithUseCandidate = false;
};
/* Inline methods. */
......@@ -110,6 +123,126 @@ namespace RTC
{
return this->iceServer->GetPassword();
}
/**
* Set the given source as a valid one and mark it as the sending source for
* outgoing data.
*
* @param source: A RTC::TransportSource (which is a UDP tuple or TCP connection).
* @return: true if the given source was not an already valid source,
* false otherwise.
*/
inline
bool Transport::SetSendingSource(RTC::TransportSource* source)
{
// If the give source is already a valid one return.
// NOTE: The IsValidSource() method will also mark it as sending source.
if (IsValidSource(source))
return false;
// If there are Transport::maxSources sources then close and remove the last one.
if (this->sources.size() == Transport::maxSources)
{
RTC::TransportSource* last_source = &(*this->sources.end());
last_source->Close();
this->sources.pop_back();
}
// Add the new source at the beginning.
this->sources.push_front(*source);
// Set it as sending source (make it point to the first source in the list).
this->sendingSource = &(*this->sources.begin());
// If it is UDP then we must store the remote address (until now it is
// just a pointer that will be freed soon).
if (this->sendingSource->IsUDP())
this->sendingSource->StoreUdpRemoteAddress();
return true;
}
/**
* Check whether the given source is contained in the list of valid sources for
* this transport. In case it is, the given source is also marked as sending
* source for the outgoing data.
*
* @param source: The RTC::TransportSource to check.
* @return: true if it is a valid source, false otherwise.
*/
inline
bool Transport::IsValidSource(RTC::TransportSource* source)
{
// If there is no sending source yet then we know that the sources list
// is empty, so return false.
if (!this->sendingSource)
return false;
// First check the current sending source. If it matches then return true.
if (this->sendingSource->Compare(source))
return true;
// Otherwise check other valid source in the sources list.
for (auto it = this->sources.begin(); it != this->sources.end(); ++it)
{
RTC::TransportSource* valid_source = &(*it);
// If found set it as sending source.
if (valid_source->Compare(source))
{
this->sendingSource = valid_source;
return true;
}
}
return false;
}
/**
* Remove the given source from the list of valid sources. Also update the
* sending source if the given source was the sending source and make it point
* to the next valid source (if any).
*
* @param source: The RTC::TransportSource to remove.
* @return: true if the given source was present in the list of valid
* sources, false otherwise.
*/
inline
bool Transport::RemoveSource(RTC::TransportSource* source)
{
for (auto it = this->sources.begin(); it != this->sources.end(); ++it)
{
RTC::TransportSource* valid_source = &(*it);
// If the source was a valid source then remove it.
if (valid_source->Compare(source))
{
this->sources.erase(it);
// If it was the sending source then unset it and set the sending
// source to the first valid source (if any).
if (this->sendingSource == valid_source)
{
if (this->sources.begin() != this->sources.end())
{
this->sendingSource = &(*this->sources.begin());
}
else
{
this->sendingSource = nullptr;
// This is just useful is there are just TCP sources.
this->icePaired = false;
this->icePairedWithUseCandidate = false;
}
}
return true;
}
}
return false;
}
}
#endif
......@@ -135,7 +135,7 @@ namespace RTC
return;
}
MS_DEBUG("processing STUN Binding Request with Priority %u%s", (unsigned int)msg->GetPriority(), msg->HasUseCandidate() ? " and UseCandidate" : "");
MS_DEBUG("processing STUN Binding Request [Priority:%u, UseCandidate:%s]", (unsigned int)msg->GetPriority(), msg->HasUseCandidate() ? "true" : "false");
// Create a success response.
RTC::STUNMessage* response = msg->CreateSuccessResponse();
......
......@@ -26,6 +26,10 @@
namespace RTC
{
/* Class variables. */
size_t Transport::maxSources = 8;
/* Instance methods. */
Transport::Transport(Listener* listener, unsigned int transportId, Json::Value& data, Transport* rtpTransport) :
......@@ -268,14 +272,28 @@ namespace RTC
{
MS_TRACE();
// TODO
// Send the STUN response over the same transport source.
source->Send(msg->GetRaw(), msg->GetLength());
}
void Transport::onICEValidPair(RTC::IceServer* iceServer, RTC::TransportSource* source, bool has_use_candidate)
{
MS_TRACE();
// TODO
this->icePaired = true;
if (has_use_candidate)
this->icePairedWithUseCandidate = true;
/*
* RFC 5245 section 11.2 "Receiving Media":
*
* ICE implementations MUST be prepared to receive media on each component
* on any candidates provided for that component.
*/
if (SetSendingSource(source))
MS_DEBUG("got an ICE valid pair [UseCandidate:%s]", has_use_candidate ? "true" : "false");
// TODO: more
}
inline
......@@ -283,7 +301,17 @@ namespace RTC
{
MS_TRACE();
// TODO
RTC::STUNMessage* msg = RTC::STUNMessage::Parse(data, len);
if (!msg)
{
MS_DEBUG("ignoring wrong STUN message received");
return;
}
// Pass it to the IceServer.
this->iceServer->ProcessSTUNMessage(msg, source);
delete msg;
}
inline
......@@ -291,6 +319,16 @@ namespace RTC
{
MS_TRACE();
if (!IsValidSource(source))
{
MS_DEBUG("ignoring DTLS data coming from an invalid source");
return;
}
// TODO: remove
MS_DEBUG("received DTLS data");
// TODO
}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论