Browse Source

Merge branch 'v0.18'

Paul-Louis Ageneau 2 years ago
parent
commit
3bf9f4395e
5 changed files with 83 additions and 15 deletions
  1. 1 4
      src/description.cpp
  2. 39 8
      src/impl/channel.cpp
  3. 24 0
      src/impl/icetransport.cpp
  4. 14 2
      src/impl/peerconnection.cpp
  5. 5 1
      src/impl/peerconnection.hpp

+ 1 - 4
src/description.cpp

@@ -187,11 +187,8 @@ optional<string> Description::fingerprint() const { return mFingerprint; }
 bool Description::ended() const { return mEnded; }
 
 void Description::hintType(Type type) {
-	if (mType == Type::Unspec) {
+	if (mType == Type::Unspec)
 		mType = type;
-		if (mType == Type::Answer && mRole == Role::ActPass)
-			mRole = Role::Passive; // ActPass is illegal for an answer, so default to passive
-	}
 }
 
 void Description::setFingerprint(string fingerprint) {

+ 39 - 8
src/impl/channel.cpp

@@ -7,22 +7,44 @@
  */
 
 #include "channel.hpp"
+#include "internals.hpp"
 
 namespace rtc::impl {
 
 void Channel::triggerOpen() {
 	mOpenTriggered = true;
-	openCallback();
+	try {
+		openCallback();
+	} catch (const std::exception &e) {
+		PLOG_WARNING << "Uncaught exception in callback: " << e.what();
+	}
 	flushPendingMessages();
 }
 
-void Channel::triggerClosed() { closedCallback(); }
+void Channel::triggerClosed() {
+	try {
+		closedCallback();
+	} catch (const std::exception &e) {
+		PLOG_WARNING << "Uncaught exception in callback: " << e.what();
+	}
+}
 
-void Channel::triggerError(string error) { errorCallback(std::move(error)); }
+void Channel::triggerError(string error) {
+	try {
+		errorCallback(std::move(error));
+	} catch (const std::exception &e) {
+		PLOG_WARNING << "Uncaught exception in callback: " << e.what();
+	}
+}
 
 void Channel::triggerAvailable(size_t count) {
-	if (count == 1)
-		availableCallback();
+	if (count == 1) {
+		try {
+			availableCallback();
+		} catch (const std::exception &e) {
+			PLOG_WARNING << "Uncaught exception in callback: " << e.what();
+		}
+	}
 
 	flushPendingMessages();
 }
@@ -30,8 +52,13 @@ void Channel::triggerAvailable(size_t count) {
 void Channel::triggerBufferedAmount(size_t amount) {
 	size_t previous = bufferedAmount.exchange(amount);
 	size_t threshold = bufferedAmountLowThreshold.load();
-	if (previous > threshold && amount <= threshold)
-		bufferedAmountLowCallback();
+	if (previous > threshold && amount <= threshold) {
+		try {
+			bufferedAmountLowCallback();
+		} catch (const std::exception &e) {
+			PLOG_WARNING << "Uncaught exception in callback: " << e.what();
+		}
+	}
 }
 
 void Channel::flushPendingMessages() {
@@ -43,7 +70,11 @@ void Channel::flushPendingMessages() {
 		if (!next)
 			break;
 
-		messageCallback(*next);
+		try {
+			messageCallback(*next);
+		} catch (const std::exception &e) {
+			PLOG_WARNING << "Uncaught exception in callback: " << e.what();
+		}
 	}
 }
 

+ 24 - 0
src/impl/icetransport.cpp

@@ -169,9 +169,21 @@ Description IceTransport::getLocalDescription(Description::Type type) const {
 }
 
 void IceTransport::setRemoteDescription(const Description &description) {
+	// RFC 5763: The answerer MUST use either a setup attribute value of setup:active or
+	// setup:passive.
+	// See https://www.rfc-editor.org/rfc/rfc5763.html#section-5
+	if (description.type() == Description::Type::Answer &&
+	    description.role() == Description::Role::ActPass)
+		throw std::logic_error("Illegal role actpass in remote answer description");
+
+	// RFC 5763: Note that if the answerer uses setup:passive, then the DTLS handshake
+	// will not begin until the answerer is received, which adds additional latency.
+	// setup:active allows the answer and the DTLS handshake to occur in parallel. Thus,
+	// setup:active is RECOMMENDED.
 	if (mRole == Description::Role::ActPass)
 		mRole = description.role() == Description::Role::Active ? Description::Role::Passive
 		                                                        : Description::Role::Active;
+
 	if (mRole == description.role())
 		throw std::logic_error("Incompatible roles with remote description");
 
@@ -604,9 +616,21 @@ Description IceTransport::getLocalDescription(Description::Type type) const {
 }
 
 void IceTransport::setRemoteDescription(const Description &description) {
+	// RFC 5763: The answerer MUST use either a setup attribute value of setup:active or
+	// setup:passive.
+	// See https://www.rfc-editor.org/rfc/rfc5763.html#section-5
+	if (description.type() == Description::Type::Answer &&
+	    description.role() == Description::Role::ActPass)
+		throw std::logic_error("Illegal role actpass in remote answer description");
+
+	// RFC 5763: Note that if the answerer uses setup:passive, then the DTLS handshake
+	// will not begin until the answerer is received, which adds additional latency.
+	// setup:active allows the answer and the DTLS handshake to occur in parallel. Thus,
+	// setup:active is RECOMMENDED.
 	if (mRole == Description::Role::ActPass)
 		mRole = description.role() == Description::Role::Active ? Description::Role::Passive
 		                                                        : Description::Role::Active;
+
 	if (mRole == description.role())
 		throw std::logic_error("Incompatible roles with remote description");
 

+ 14 - 2
src/impl/peerconnection.cpp

@@ -1115,7 +1115,13 @@ void PeerConnection::triggerPendingDataChannels() {
 			break;
 
 		auto impl = std::move(*next);
-		dataChannelCallback(std::make_shared<rtc::DataChannel>(impl));
+
+		try {
+			dataChannelCallback(std::make_shared<rtc::DataChannel>(impl));
+		} catch (const std::exception &e) {
+			PLOG_WARNING << "Uncaught exception in callback: " << e.what();
+		}
+
 		impl->triggerOpen();
 	}
 }
@@ -1127,7 +1133,13 @@ void PeerConnection::triggerPendingTracks() {
 			break;
 
 		auto impl = std::move(*next);
-		trackCallback(std::make_shared<rtc::Track>(impl));
+
+		try {
+			trackCallback(std::make_shared<rtc::Track>(impl));
+		} catch (const std::exception &e) {
+			PLOG_WARNING << "Uncaught exception in callback: " << e.what();
+		}
+
 		// Do not trigger open immediately for tracks as it'll be done later
 	}
 }

+ 5 - 1
src/impl/peerconnection.hpp

@@ -99,7 +99,11 @@ struct PeerConnection : std::enable_shared_from_this<PeerConnection> {
 
 	// Helper method for asynchronous callback invocation
 	template <typename... Args> void trigger(synchronized_callback<Args...> *cb, Args... args) {
-		(*cb)(std::move(args...));
+		try {
+			(*cb)(std::move(args...));
+		} catch (const std::exception &e) {
+			PLOG_WARNING << "Uncaught exception in callback: " << e.what();
+		}
 	}
 
 	const Configuration config;