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

[WIP] Add support to ICE TCP candidates #1627

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
18 changes: 16 additions & 2 deletions erizo/src/erizo/NicerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ void NicerConnection::startSync() {
ELOG_DEBUG("%s message: setting remote credentials in constructor, ufrag:%s, pass:%s",
toLog(), ice_config_.username.c_str(), ice_config_.password.c_str());
setRemoteCredentialsSync(ice_config_.username, ice_config_.password);
peer_->controlling = 0;
} else {
peer_->controlling = 1;
}
Expand Down Expand Up @@ -431,7 +432,19 @@ 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;
}
}
cand_info.transProtocol = ice_config_.transport_name;
cand_info.username = ufrag_;
cand_info.password = upass_;
Expand Down Expand Up @@ -602,6 +615,7 @@ void NicerConnection::initializeGlobals() {
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_PEER_RFLX), 110);
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 @@ -634,7 +648,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
18 changes: 18 additions & 0 deletions erizo/src/erizo/SdpInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ namespace erizo {
enum HostType {
HOST, SRFLX, PRFLX, RELAY
};
enum TcpType {
TCP_ACTIVE, TCP_PASSIVE, TCP_SO
};
/**
* Channel types
*/
Expand Down Expand Up @@ -92,11 +95,25 @@ class CandidateInfo {
default: return "host";
}
}
std::string getTcpTypeName() const {
if (netProtocol == "udp") {
return "";
}
switch (tcpType) {
case TCP_ACTIVE: return "active";
case TCP_PASSIVE: return "passive";
case TCP_SO: return "so";
default: return "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 (netProtocol == "tcp") {
sdp_stream << " tcptype " << getTcpTypeName();
}
if (!rAddress.empty()) {
sdp_stream << " raddr " << rAddress << " rport " << rPort;
}
Expand All @@ -114,6 +131,7 @@ class CandidateInfo {
int rPort;
std::string netProtocol;
HostType hostType;
TcpType tcpType;
std::string transProtocol;
std::string username;
std::string password;
Expand Down
36 changes: 27 additions & 9 deletions erizoAPI/ConnectionDescription.cc
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,6 @@ NAN_METHOD(ConnectionDescription::addCandidate) {
cand.hostAddress = getString(info[5]);
cand.hostPort = Nan::To<unsigned int>(info[6]).FromJust();

// 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;
Expand All @@ -478,12 +472,21 @@ NAN_METHOD(ConnectionDescription::addCandidate) {
cand.hostType = erizo::HOST;
}

std::string tcpType = getString(info[8]);
if (tcpType == "active") {
cand.tcpType = erizo::TCP_ACTIVE;
} else if (tcpType == "passive") {
cand.tcpType = erizo::TCP_PASSIVE;
} else if (tcpType == "so") {
cand.tcpType = erizo::TCP_SO;
}

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 @@ -585,6 +588,21 @@ NAN_METHOD(ConnectionDescription::getCandidates) {
}
Nan::Set(candidate_info, Nan::New("hostType").ToLocalChecked(),
Nan::New(host_type.c_str()).ToLocalChecked());

std::string tcp_type = "active";
switch (candidate.tcpType) {
case erizo::TCP_ACTIVE:
tcp_type = "active";
break;
case erizo::TCP_PASSIVE:
tcp_type = "passive";
break;
case erizo::TCP_SO:
tcp_type = "so";
break;
}
Nan::Set(candidate_info, Nan::New("tcpType").ToLocalChecked(),
Nan::New(tcp_type.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
18 changes: 15 additions & 3 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 @@ -434,12 +435,23 @@ NAN_METHOD(WebRtcConnection::addRemoteCandidate) {
cand.hostType = HostType::HOST;
}

Nan::Utf8String param5(Nan::To<v8::String>(info[9]).ToLocalChecked());
Nan::Utf8String param41(Nan::To<v8::String>(info[9]).ToLocalChecked());
std::string tcpType = std::string(*param4);

if (tcpType == "active") {
cand.tcpType = TcpType::TCP_ACTIVE;
} else if (tcpType == "passive") {
cand.tcpType = TcpType::TCP_PASSIVE;
} else if (tcpType == "so") {
cand.tcpType = TcpType::TCP_SO;
}

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);

me->addRemoteCandidate(mid, sdpMLine, cand);
Expand Down
11 changes: 9 additions & 2 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, relAddr, relPort) {
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;
}

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.relAddr, this.relPort);
}

plain() {
Expand All @@ -27,6 +29,7 @@ class CandidateInfo {
address: this.address,
port: this.port,
type: this.type,
tcptype: this.tcpType,
generation: this.generation,
};
if (this.relAddr) plain.relAddr = this.relAddr;
Expand Down Expand Up @@ -62,6 +65,10 @@ class CandidateInfo {
return this.type;
}

getTcpType() {
return this.tcpType;
}

getGeneration() {
return this.generation;
}
Expand Down
3 changes: 2 additions & 1 deletion erizo_controller/common/semanticSdp/SDPInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ class SDPInfo {
ip: candidate.getAddress(),
port: candidate.getPort(),
type: candidate.getType(),
tcptype: candidate.getTcpType(),
relAddr: candidate.getRelAddr(),
relPort: candidate.getRelPort(),
generation: candidate.getGeneration(),
Expand Down Expand Up @@ -822,7 +823,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.relAddr, candidate.relPort));
});
}

Expand Down
7 changes: 2 additions & 5 deletions erizo_controller/erizoJS/models/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,10 @@ class Connection extends events.EventEmitter {
return;
}
candidatesInfo.candidates.forEach((candidate) => {
if (candidate.transport.toLowerCase() !== 'udp') {
return;
}
this.wrtc.addRemoteCandidate(sdpCandidate.sdpMid, sdpCandidate.sdpMLineIndex,
candidate.foundation, candidate.component, candidate.priority, candidate.transport,
candidate.ip, candidate.port, candidate.type, candidate.raddr, candidate.rport,
sdpCandidate.candidate);
candidate.ip, candidate.port, candidate.type, candidate.tcpType,
candidate.raddr, candidate.rport, sdpCandidate.candidate);
});
}

Expand Down
12 changes: 7 additions & 5 deletions erizo_controller/erizoJS/models/SessionDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function getMediaInfoFromDescription(info, sdp, mediaType) {
candidates.forEach((candidate) => {
media.addCandidate(new CandidateInfo(candidate.foundation, candidate.componentId,
candidate.protocol, candidate.priority, candidate.hostIp, candidate.hostPort,
candidate.hostType, 0, candidate.relayIp, candidate.relayPort));
candidate.hostType, candidate.tcpType, 0, candidate.relayIp, candidate.relayPort));
});
}

Expand Down Expand Up @@ -163,8 +163,10 @@ function getMediaInfoFromDescription(info, sdp, mediaType) {

function candidateToString(cand) {
let str = `candidate:${cand.foundation} ${cand.componentId} ${cand.transport}` +
` ${cand.priority} ${cand.address} ${cand.port} typ ${cand.type}`;

` ${cand.priority} ${cand.address} ${cand.port} typ ${cand.hostType}`;
if (cand.hostType === 'tcp') {
str += ` tcptype ${cand.tcpType}`;
}
str += (cand.relAddr != null) ? ` raddr ${cand.relAddr} rport ${cand.relPort}` : '';

str += (cand.tcptype != null) ? ` tcptype ${cand.tcptype}` : '';
Expand Down Expand Up @@ -303,8 +305,8 @@ class SessionDescription {
const candidateString = candidateToString(candidate);
info.addCandidate(media.getType(), candidate.getFoundation(), candidate.getComponentId(),
candidate.getTransport(), candidate.getPriority(), candidate.getAddress(),
candidate.getPort(), candidate.getType(), candidate.getRelAddr(), candidate.getRelPort(),
candidateString);
candidate.getPort(), candidate.getType(), candidate.getTcpType(),
candidate.getRelAddr(), candidate.getRelPort(), candidateString);
});

const ice = media.getICE();
Expand Down