Browse Source

Close existing data channel on open message on already used stream

Paul-Louis Ageneau 2 years ago
parent
commit
bf148bb6e5
1 changed files with 11 additions and 7 deletions
  1. 11 7
      src/impl/peerconnection.cpp

+ 11 - 7
src/impl/peerconnection.cpp

@@ -432,6 +432,17 @@ void PeerConnection::forwardMessage(message_ptr message) {
 	auto [channel, found] = findDataChannel(stream);
 
 	if (DataChannel::IsOpenMessage(message)) {
+		if (found) {
+			// The stream is already used, the receiver must close the DataChannel
+			PLOG_WARNING << "Got open message on already used stream " << stream;
+			if(channel && channel->isOpen())
+				channel->close();
+			else
+				sctpTransport->closeStream(message->stream);
+
+			return;
+		}
+
 		const uint16_t remoteParity = (iceTransport->role() == Description::Role::Active) ? 1 : 0;
 		if (stream % 2 != remoteParity) {
 			// The odd/even rule is violated, the receiver must close the DataChannel
@@ -440,13 +451,6 @@ void PeerConnection::forwardMessage(message_ptr message) {
 			return;
 		}
 
-		if (found) {
-			// The stream is already used, the receiver must close the DataChannel
-			PLOG_WARNING << "Got open message on already used stream " << stream;
-			sctpTransport->closeStream(message->stream);
-			return;
-		}
-
 		channel = std::make_shared<IncomingDataChannel>(weak_from_this(), sctpTransport);
 		channel->assignStream(stream);
 		channel->openCallback =