Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes that enables ICE-TCP support #1802

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion erizo/src/erizo/LibNiceConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ void LibNiceConnection::startSync() {
g_value_set_boolean(&keepalive, TRUE);
g_object_set_property(G_OBJECT(agent_), "keepalive-conncheck", &keepalive);

GValue ice_tcp = { 0 };
g_value_init(&ice_tcp, G_TYPE_BOOLEAN);
g_value_set_boolean(&ice_tcp, TRUE);
g_object_set_property(G_OBJECT(agent_), "ice-tcp", &ice_tcp);

if (ice_config_.stun_server.compare("") != 0 && ice_config_.stun_port != 0) {
GValue stun_server = { 0 }, stun_server_port = { 0 };
g_value_init(&stun_server, G_TYPE_STRING);
Expand Down Expand Up @@ -520,7 +525,24 @@ void LibNiceConnection::getCandidate(uint stream_id, uint component_id, const st
default:
break;
}
cand_info.netProtocol = "udp";
if (NICE_CANDIDATE_TRANSPORT_UDP == cand->transport) {
cand_info.netProtocol = "udp";
} else {
cand_info.netProtocol = "tcp";
switch (cand->transport) {
case NICE_CANDIDATE_TRANSPORT_TCP_ACTIVE:
cand_info.tcpType = TCP_ACTIVE;
break;
case NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE:
cand_info.tcpType = TCP_PASSIVE;
break;
case NICE_CANDIDATE_TRANSPORT_TCP_SO:
cand_info.tcpType = TCP_SO;
break;
default:
break;
}
}
cand_info.transProtocol = ice_config_.transport_name;
cand_info.username = ufrag_;
cand_info.password = upass_;
Expand Down
20 changes: 18 additions & 2 deletions erizo/src/erizo/NicerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,20 @@ void NicerConnection::onCandidate(nr_ice_media_stream *stream, int component_id,
default:
break;
}
cand_info.netProtocol = "udp";
cand_info.netProtocol = cand->addr.protocol == IPPROTO_UDP ? "udp" : "tcp";
if (cand->addr.protocol == IPPROTO_TCP) {
switch (cand->tcp_type) {
case nr_socket_tcp_type::TCP_TYPE_ACTIVE:
cand_info.tcpType = TCP_ACTIVE;
break;
case nr_socket_tcp_type::TCP_TYPE_PASSIVE:
cand_info.tcpType = TCP_PASSIVE;
break;
default:
cand_info.tcpType = TCP_SO;
break;
}
}
cand_info.transProtocol = ice_config_.transport_name;
cand_info.username = ufrag_;
cand_info.password = upass_;
Expand Down Expand Up @@ -658,8 +671,11 @@ void NicerConnection::initializeGlobals() {
// Set the priorites for candidate type preferences.
// These numbers come from RFC 5245 S. 4.1.2.2
NR_reg_set_uchar(const_cast<char *>(NR_ICE_REG_PREF_TYPE_SRV_RFLX), 100);
NR_reg_set_uchar(const_cast<char *>(NR_ICE_REG_PREF_TYPE_SRV_RFLX_TCP), 99);
NR_reg_set_uchar(const_cast<char *>(NR_ICE_REG_PREF_TYPE_PEER_RFLX), 110);
NR_reg_set_uchar(const_cast<char *>(NR_ICE_REG_PREF_TYPE_PEER_RFLX_TCP), 109);
NR_reg_set_uchar(const_cast<char *>(NR_ICE_REG_PREF_TYPE_HOST), 126);
NR_reg_set_uchar(const_cast<char *>(NR_ICE_REG_PREF_TYPE_HOST_TCP), 125);
NR_reg_set_uchar(const_cast<char *>(NR_ICE_REG_PREF_TYPE_RELAYED), 5);
NR_reg_set_uchar(const_cast<char *>(NR_ICE_REG_PREF_TYPE_RELAYED_TCP), 0);

Expand Down Expand Up @@ -692,7 +708,7 @@ void NicerConnection::initializeGlobals() {
NR_reg_set_uint4(const_cast<char *>("stun.client.maximum_transmits"), 7);
NR_reg_set_uint4(const_cast<char *>(NR_ICE_REG_TRICKLE_GRACE_PERIOD), 5000);

NR_reg_set_char(const_cast<char *>(NR_ICE_REG_ICE_TCP_DISABLE), true);
NR_reg_set_char(const_cast<char *>(NR_ICE_REG_ICE_TCP_DISABLE), false);
NR_reg_set_char(const_cast<char *>(NR_STUN_REG_PREF_ALLOW_LINK_LOCAL_ADDRS), 1);
}
}
Expand Down
53 changes: 53 additions & 0 deletions erizo/src/erizo/SdpInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ namespace erizo {
enum HostType {
HOST, SRFLX, PRFLX, RELAY
};

enum TcpType {
TCP_ACTIVE,
TCP_PASSIVE,
TCP_SO
};

/**
* Channel types
*/
Expand Down Expand Up @@ -92,11 +99,56 @@ class CandidateInfo {
default: return "host";
}
}

static HostType typeFromString(std::string type) {
if (type == "host") {
return erizo::HOST;
} else if (type == "srflx") {
return erizo::SRFLX;
} else if (type == "prflx") {
return erizo::PRFLX;
} else if (type == "relay") {
return erizo::RELAY;
}

// this is not correct, must be erizo::INVALID
return erizo::HOST;
}

std::string getTcpTypeName() const {
if ("udp" == netProtocol) {
return "";
}

switch (tcpType) {
case TCP_ACTIVE: return "active";
case TCP_PASSIVE: return "passive";
case TCP_SO: return "so";
default: return "active";
}
}

static TcpType tcpTypeFromString(std::string tcptype) {
if ("active" == tcptype) {
return erizo::TCP_ACTIVE;
} else if ("passive" == tcptype) {
return erizo::TCP_PASSIVE;
} else if ("so" == tcptype) {
return erizo::TCP_SO;
}

// not correct, TcpType enum should contain INVALID/UNDEFINED field
return erizo::TCP_ACTIVE;
}

std::string to_string() const {
std::ostringstream sdp_stream;
sdp_stream << "a=candidate:" << foundation << " " << componentId << " ";
sdp_stream << netProtocol << " " << priority << " " << hostAddress << " ";
sdp_stream << hostPort << " typ " << getTypeName();
if ("tcp" == netProtocol) {
sdp_stream << " tcptype " << getTcpTypeName();
}
if (!rAddress.empty()) {
sdp_stream << " raddr " << rAddress << " rport " << rPort;
}
Expand All @@ -114,6 +166,7 @@ class CandidateInfo {
int rPort;
std::string netProtocol;
HostType hostType;
TcpType tcpType;
std::string transProtocol;
std::string username;
std::string password;
Expand Down
48 changes: 10 additions & 38 deletions erizoAPI/ConnectionDescription.cc
Original file line number Diff line number Diff line change
Expand Up @@ -516,32 +516,18 @@ NAN_METHOD(ConnectionDescription::addCandidate) {
cand.priority = Nan::To<unsigned int>(info[4]).FromJust();
cand.hostAddress = getString(info[5]);
cand.hostPort = Nan::To<unsigned int>(info[6]).FromJust();
cand.hostType = erizo::CandidateInfo::typeFromString(getString(info[7]));

// libnice does not support tcp candidates, we ignore them
if (cand.netProtocol.compare("UDP") && cand.netProtocol.compare("udp")) {
info.GetReturnValue().Set(Nan::New(false));
return;
}

std::string type = getString(info[7]);
if (type == "host") {
cand.hostType = erizo::HOST;
} else if (type == "srflx") {
cand.hostType = erizo::SRFLX;
} else if (type == "prflx") {
cand.hostType = erizo::PRFLX;
} else if (type == "relay") {
cand.hostType = erizo::RELAY;
} else {
cand.hostType = erizo::HOST;
if ("tcp" == cand.netProtocol) {
cand.tcpType = erizo::CandidateInfo::tcpTypeFromString(getString(info[8]));
}

if (cand.hostType == erizo::SRFLX || cand.hostType == erizo::RELAY) {
cand.rAddress = getString(info[8]);
cand.rPort = Nan::To<unsigned int>(info[9]).FromJust();
cand.rAddress = getString(info[9]);
cand.rPort = Nan::To<unsigned int>(info[10]).FromJust();
}

cand.sdp = getString(info[10]);
cand.sdp = getString(info[11]);

sdp->candidateVector_.push_back(cand);
info.GetReturnValue().Set(Nan::New(true));
Expand Down Expand Up @@ -609,7 +595,7 @@ NAN_METHOD(ConnectionDescription::getCandidates) {

v8::Local<v8::Array> candidates_array = Nan::New<v8::Array>(candidates.size());
uint index = 0;
for (erizo::CandidateInfo &candidate : candidates) {
for (erizo::CandidateInfo const& candidate : candidates) {
v8::Local<v8::Object> candidate_info = Nan::New<v8::Object>();
Nan::Set(candidate_info, Nan::New("bundle").ToLocalChecked(), Nan::New(candidate.isBundle));
Nan::Set(candidate_info, Nan::New("tag").ToLocalChecked(), Nan::New(candidate.tag));
Expand All @@ -625,24 +611,10 @@ NAN_METHOD(ConnectionDescription::getCandidates) {
Nan::Set(candidate_info, Nan::New("relayPort").ToLocalChecked(), Nan::New(candidate.rPort));
Nan::Set(candidate_info, Nan::New("protocol").ToLocalChecked(),
Nan::New(candidate.netProtocol.c_str()).ToLocalChecked());
std::string host_type = "host";
switch (candidate.hostType) {
case erizo::HOST:
host_type = "host";
break;
case erizo::SRFLX:
host_type = "srflx";
break;
case erizo::PRFLX:
host_type = "prflx";
break;
case erizo::RELAY:
default:
host_type = "relay";
break;
}
Nan::Set(candidate_info, Nan::New("hostType").ToLocalChecked(),
Nan::New(host_type.c_str()).ToLocalChecked());
Nan::New(candidate.getTypeName().c_str()).ToLocalChecked());
Nan::Set(candidate_info, Nan::New("tcpType").ToLocalChecked(),
Nan::New(candidate.getTcpTypeName().c_str()).ToLocalChecked());
Nan::Set(candidate_info, Nan::New("transport").ToLocalChecked(),
Nan::New(candidate.transProtocol.c_str()).ToLocalChecked());
Nan::Set(candidate_info, Nan::New("user").ToLocalChecked(),
Expand Down
24 changes: 8 additions & 16 deletions erizoAPI/WebRtcConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ using v8::Value;
using json = nlohmann::json;
using erizo::CandidateInfo;
using erizo::HostType;
using erizo::TcpType;

Nan::Persistent<Function> WebRtcConnection::constructor;

Expand Down Expand Up @@ -529,26 +530,17 @@ NAN_METHOD(WebRtcConnection::addRemoteCandidate) {
cand.hostPort = Nan::To<int>(info[7]).FromJust();

Nan::Utf8String param4(Nan::To<v8::String>(info[8]).ToLocalChecked());
std::string type = std::string(*param4);

if (type == "host") {
cand.hostType = HostType::HOST;
} else if (type == "srflx") {
cand.hostType = HostType::SRFLX;
} else if (type == "prflx") {
cand.hostType = HostType::PRFLX;
} else if (type == "relay") {
cand.hostType = HostType::RELAY;
} else {
cand.hostType = HostType::HOST;
}
cand.hostType = CandidateInfo::typeFromString(*param4);

Nan::Utf8String param41(Nan::To<v8::String>(info[9]).ToLocalChecked());
cand.tcpType = CandidateInfo::tcpTypeFromString(*param41);

Nan::Utf8String param5(Nan::To<v8::String>(info[9]).ToLocalChecked());
Nan::Utf8String param5(Nan::To<v8::String>(info[10]).ToLocalChecked());
cand.rAddress = std::string(*param5);

cand.rPort = Nan::To<int>(info[10]).FromJust();
cand.rPort = Nan::To<int>(info[11]).FromJust();

Nan::Utf8String param6(Nan::To<v8::String>(info[11]).ToLocalChecked());
Nan::Utf8String param6(Nan::To<v8::String>(info[12]).ToLocalChecked());
cand.sdp = std::string(*param6);

Nan::Persistent<v8::Promise::Resolver> *persistent = new Nan::Persistent<v8::Promise::Resolver>(resolver);
Expand Down
23 changes: 15 additions & 8 deletions erizo_controller/common/semanticSdp/CandidateInfo.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
class CandidateInfo {
constructor(foundation, componentId, transport, priority, address, port,
type, generation, relAddr, relPort) {
type, tcptype, generation, raddr, rport) {
this.foundation = foundation;
this.componentId = componentId;
this.transport = transport;
this.priority = priority;
this.address = address;
this.port = port;
this.type = type;
this.tcptype = tcptype;
this.generation = generation;
this.relAddr = relAddr;
this.relPort = relPort;
this.raddr = raddr;
this.rport = rport;
}

clone() {
return new CandidateInfo(this.foundation, this.componentId, this.transport, this.priority,
this.address, this.port, this.type, this.generation, this.relAddr, this.relPort);
this.address, this.port, this.type, this.tcptype,
this.generation, this.raddr, this.rport);
}

plain() {
Expand All @@ -29,8 +31,9 @@ class CandidateInfo {
type: this.type,
generation: this.generation,
};
if (this.relAddr) plain.relAddr = this.relAddr;
if (this.relPort) plain.relPort = this.relPort;
if (this.tcptype) plain.tcptype = this.tcptype;
if (this.raddr) plain.raddr = this.raddr;
if (this.rport) plain.rport = this.rport;
return plain;
}

Expand Down Expand Up @@ -62,16 +65,20 @@ class CandidateInfo {
return this.type;
}

getTcpType() {
return this.tcptype;
}

getGeneration() {
return this.generation;
}

getRelAddr() {
return this.relAddr;
return this.raddr;
}

getRelPort() {
return this.relPort;
return this.rport;
}
}

Expand Down
7 changes: 4 additions & 3 deletions erizo_controller/common/semanticSdp/SDPInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ class SDPInfo {
ip: candidate.getAddress(),
port: candidate.getPort(),
type: candidate.getType(),
relAddr: candidate.getRelAddr(),
relPort: candidate.getRelPort(),
tcptype: (candidate.getTcpType()) ? candidate.getTcpType() : null,
raddr: (candidate.getRelAddr()) ? candidate.getRelAddr() : null,
rport: (candidate.getRelPort()) ? candidate.getRelPort() : null,
generation: candidate.getGeneration(),
});
});
Expand Down Expand Up @@ -870,7 +871,7 @@ SDPInfo.process = (sdp) => {
candidates.forEach((candidate) => {
mediaInfo.addCandidate(new CandidateInfo(candidate.foundation, candidate.component,
candidate.transport, candidate.priority, candidate.ip, candidate.port, candidate.type,
candidate.generation, candidate.relAddr, candidate.relPort));
candidate.tcptype, candidate.generation, candidate.raddr, candidate.rport));
});
}

Expand Down
Loading