Sfoglia il codice sorgente

Added configuration option iceTransportPolicy

Paul-Louis Ageneau 4 anni fa
parent
commit
1df7fd47fe
4 ha cambiato i file con 22 aggiunte e 2 eliminazioni
  1. 6 0
      include/rtc/configuration.hpp
  2. 6 0
      include/rtc/rtc.h
  3. 1 0
      src/capi.cpp
  4. 9 2
      src/impl/peerconnection.cpp

+ 6 - 0
include/rtc/configuration.hpp

@@ -70,6 +70,11 @@ enum class CertificateType {
 	Rsa = RTC_CERTIFICATE_RSA
 };
 
+enum class TransportPolicy {
+	All = RTC_TRANSPORT_POLICY_ALL,
+	Relay = RTC_TRANSPORT_POLICY_RELAY
+};
+
 struct RTC_CPP_EXPORT Configuration {
 	// ICE settings
 	std::vector<IceServer> iceServers;
@@ -78,6 +83,7 @@ struct RTC_CPP_EXPORT Configuration {
 
 	// Options
 	CertificateType certificateType = CertificateType::Default;
+	TransportPolicy iceTransportPolicy = TransportPolicy::All;
 	bool enableIceTcp = false;
 	bool disableAutoNegotiation = false;
 

+ 6 - 0
include/rtc/rtc.h

@@ -113,6 +113,11 @@ typedef enum {
 	RTC_DIRECTION_INACTIVE = 4
 } rtcDirection;
 
+typedef enum {
+	RTC_TRANSPORT_POLICY_ALL = 0,
+	RTC_TRANSPORT_POLICY_RELAY = 1
+} rtcTransportPolicy;
+
 #define RTC_ERR_SUCCESS 0
 #define RTC_ERR_INVALID -1   // invalid argument
 #define RTC_ERR_FAILURE -2   // runtime error
@@ -152,6 +157,7 @@ typedef struct {
 	int iceServersCount;
 	const char *bindAddress; // libjuice only, NULL means any
 	rtcCertificateType certificateType;
+	rtcTransportPolicy iceTransportPolicy;
 	bool enableIceTcp;
 	bool disableAutoNegotiation;
 	uint16_t portRangeBegin; // 0 means automatic

+ 1 - 0
src/capi.cpp

@@ -343,6 +343,7 @@ int rtcCreatePeerConnection(const rtcConfiguration *config) {
 		}
 
 		c.certificateType = static_cast<CertificateType>(config->certificateType);
+		c.iceTransportPolicy = static_cast<TransportPolicy>(config->iceTransportPolicy);
 		c.enableIceTcp = config->enableIceTcp;
 		c.disableAutoNegotiation = config->disableAutoNegotiation;
 

+ 9 - 2
src/impl/peerconnection.cpp

@@ -872,6 +872,8 @@ void PeerConnection::processLocalDescription(Description description) {
 	// Set local fingerprint (wait for certificate if necessary)
 	description.setFingerprint(mCertificate.get()->fingerprint());
 
+	PLOG_VERBOSE << "Issuing local description: " << description;
+
 	{
 		// Set as local description
 		std::lock_guard lock(mLocalDescriptionMutex);
@@ -886,7 +888,6 @@ void PeerConnection::processLocalDescription(Description description) {
 		mLocalDescription->addCandidates(std::move(existingCandidates));
 	}
 
-	PLOG_VERBOSE << "Issuing local description: " << description;
 	mProcessor->enqueue(localDescriptionCallback.wrap(), std::move(description));
 
 	// Reciprocated tracks might need to be open
@@ -900,10 +901,16 @@ void PeerConnection::processLocalCandidate(Candidate candidate) {
 	if (!mLocalDescription)
 		throw std::logic_error("Got a local candidate without local description");
 
+	if(config.iceTransportPolicy == TransportPolicy::Relay && candidate.type() != Candidate::Type::Relayed) {
+		PLOG_VERBOSE << "Not issuing local candidate because of transport policy: " << candidate;
+		return;
+	}
+
+	PLOG_VERBOSE << "Issuing local candidate: " << candidate;
+
 	candidate.resolve(Candidate::ResolveMode::Simple);
 	mLocalDescription->addCandidate(candidate);
 
-	PLOG_VERBOSE << "Issuing local candidate: " << candidate;
 	mProcessor->enqueue(localCandidateCallback.wrap(), std::move(candidate));
 }