CastSocketMessagePort: Filter broadcast messages.
Adds a filter for broadcast messages since MessagePorts represent
1-to-1 connections.
Also, clarified a comment for GetSocketId() in the header file.
Bug: b/162542369
Change-Id: Ib30524d2759cf6ef5184ff2881735dcdcd3151dc
Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/2546886
Commit-Queue: Yuri Wiitala <miu@chromium.org>
Reviewed-by: Jordan Bayles <jophba@chromium.org>
diff --git a/cast/common/channel/cast_socket_message_port.cc b/cast/common/channel/cast_socket_message_port.cc
index 7b16f3e..3bcdca2 100644
--- a/cast/common/channel/cast_socket_message_port.cc
+++ b/cast/common/channel/cast_socket_message_port.cc
@@ -89,6 +89,13 @@
::cast::channel::CastMessage message) {
OSP_DCHECK(router == router_);
OSP_DCHECK(!socket || socket_.get() == socket);
+
+ // Message ports are for specific virtual connections, and do not pass-through
+ // broadcasts.
+ if (message.destination_id() == kBroadcastId) {
+ return;
+ }
+
OSP_DVLOG << "Received a cast socket message";
if (!client_) {
OSP_DLOG_WARN << "Dropping message due to nullptr client_";
diff --git a/cast/common/channel/cast_socket_message_port.h b/cast/common/channel/cast_socket_message_port.h
index 36b2526..248c3ee 100644
--- a/cast/common/channel/cast_socket_message_port.h
+++ b/cast/common/channel/cast_socket_message_port.h
@@ -28,7 +28,8 @@
void SetSocket(WeakPtr<CastSocket> socket);
- // Returns current socket identifier, or -1 if not connected.
+ // Returns current socket identifier, or ToCastSocketId(nullptr) if not
+ // connected.
int GetSocketId();
// MessagePort overrides.
diff --git a/cast/receiver/application_agent_unittest.cc b/cast/receiver/application_agent_unittest.cc
index 6240ac0..8a02707 100644
--- a/cast/receiver/application_agent_unittest.cc
+++ b/cast/receiver/application_agent_unittest.cc
@@ -435,8 +435,8 @@
// Phase 1: Sender sends a LAUNCH request, which causes the idle app to stop
// and the receiver app to launch. The receiver (ApplicationAgent) broadcasts
- // a RECEIVER_STATUS to indicate the app is running; and both the receiver app
- // and the sender will get a copy of it.
+ // a RECEIVER_STATUS to indicate the app is running; but the receiver app
+ // should not get a copy of that.
Sequence phase1;
MessagePort* port_for_app = nullptr;
EXPECT_CALL(*idle_app(), DidStop()).InSequence(phase1);
@@ -473,20 +473,6 @@
}
}
})";
- EXPECT_CALL(some_app, OnMessage(_, _, _))
- .InSequence(phase1)
- .WillOnce(Invoke([&](const std::string& source_id,
- const std::string& the_namespace,
- const std::string& message) {
- EXPECT_EQ(kPlatformReceiverId, source_id);
- EXPECT_EQ(kReceiverNamespace, the_namespace);
- const auto parsed = json::Parse(message);
- EXPECT_TRUE(parsed.is_value()) << parsed.error();
- if (parsed.is_value()) {
- EXPECT_EQ(json::Parse(kRunningAppReceiverStatus).value(),
- parsed.value());
- }
- }));
EXPECT_CALL(*sender_inbound(), OnMessage(_, _))
.InSequence(phase1)
.WillOnce(Invoke([&](CastSocket*, CastMessage message) {