Browse Source

Merge branch 'v0.18'

Paul-Louis Ageneau 2 years ago
parent
commit
16f95dcaf7
2 changed files with 15 additions and 17 deletions
  1. 8 16
      src/impl/peerconnection.cpp
  2. 7 1
      src/peerconnection.cpp

+ 8 - 16
src/impl/peerconnection.cpp

@@ -424,15 +424,15 @@ void PeerConnection::forwardMessage(message_ptr message) {
 		return;
 	}
 
+	auto iceTransport = std::atomic_load(&mIceTransport);
+	auto sctpTransport = std::atomic_load(&mSctpTransport);
+	if (!iceTransport || !sctpTransport)
+		return;
+
 	const uint16_t stream = uint16_t(message->stream);
 	auto channel = findDataChannel(stream);
 
 	if (DataChannel::IsOpenMessage(message)) {
-		auto iceTransport = getIceTransport();
-		auto sctpTransport = getSctpTransport();
-		if (!iceTransport || !sctpTransport)
-			return;
-
 		const uint16_t remoteParity = (iceTransport->role() == Description::Role::Active) ? 1 : 0;
 		if (stream % 2 != remoteParity) {
 			// The odd/even rule is violated, close the DataChannel
@@ -462,9 +462,7 @@ void PeerConnection::forwardMessage(message_ptr message) {
 
 		// Invalid, close the DataChannel
 		PLOG_WARNING << "Got unexpected message on stream " << stream;
-		if (auto sctpTransport = getSctpTransport())
-			sctpTransport->closeStream(message->stream);
-
+		sctpTransport->closeStream(message->stream);
 		return;
 	}
 
@@ -591,7 +589,7 @@ shared_ptr<DataChannel> PeerConnection::emplaceDataChannel(string label, DataCha
 	lock.unlock(); // we are going to call assignDataChannels()
 
 	// If SCTP is connected, assign and open now
-	auto sctpTransport = getSctpTransport();
+	auto sctpTransport = std::atomic_load(&mSctpTransport);
 	if (sctpTransport && sctpTransport->state() == SctpTransport::State::Connected) {
 		assignDataChannels();
 		channel->open(sctpTransport);
@@ -617,7 +615,7 @@ uint16_t PeerConnection::maxDataChannelStream() const {
 void PeerConnection::assignDataChannels() {
 	std::unique_lock lock(mDataChannelsMutex); // we are going to emplace
 
-	auto iceTransport = getIceTransport();
+	auto iceTransport = std::atomic_load(&mIceTransport);
 	if (!iceTransport)
 		throw std::logic_error("Attempted to assign DataChannels without ICE transport");
 
@@ -1019,12 +1017,6 @@ void PeerConnection::processRemoteDescription(Description description) {
 		mRemoteDescription->addCandidates(std::move(existingCandidates));
 	}
 
-	auto iceTransport = initIceTransport();
-	if (!iceTransport)
-		return; // closed
-
-	iceTransport->setRemoteDescription(std::move(description));
-
 	if (description.hasApplication()) {
 		auto dtlsTransport = std::atomic_load(&mDtlsTransport);
 		auto sctpTransport = std::atomic_load(&mSctpTransport);

+ 7 - 1
src/peerconnection.cpp

@@ -218,8 +218,14 @@ void PeerConnection::setRemoteDescription(Description description) {
 	// Candidates will be added at the end, extract them for now
 	auto remoteCandidates = description.extractCandidates();
 	auto type = description.type();
-	impl()->processRemoteDescription(std::move(description));
 
+	auto iceTransport = impl()->initIceTransport();
+	if (!iceTransport)
+		return; // closed
+
+	iceTransport->setRemoteDescription(description); // ICE transport might reject the description
+
+	impl()->processRemoteDescription(std::move(description));
 	impl()->changeSignalingState(newSignalingState);
 	signalingLock.unlock();