aboutsummaryrefslogtreecommitdiff
path: root/cast
diff options
context:
space:
mode:
authorYuri Wiitala <miu@chromium.org>2020-11-20 06:41:23 -0800
committerCommit Bot <commit-bot@chromium.org>2020-11-20 15:53:59 +0000
commite1193a50d55fd11325862c0732c347779b426c63 (patch)
tree7afe7437621ffc259021f5c1d4bb9925f9871fb6 /cast
parent01490a48c0c69e0d30e283d881b4e53b339b2c80 (diff)
downloadopenscreen-e1193a50d55fd11325862c0732c347779b426c63.tar.gz
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>
Diffstat (limited to 'cast')
-rw-r--r--cast/common/channel/cast_socket_message_port.cc7
-rw-r--r--cast/common/channel/cast_socket_message_port.h3
-rw-r--r--cast/receiver/application_agent_unittest.cc18
3 files changed, 11 insertions, 17 deletions
diff --git a/cast/common/channel/cast_socket_message_port.cc b/cast/common/channel/cast_socket_message_port.cc
index 7b16f3e3..3bcdca22 100644
--- a/cast/common/channel/cast_socket_message_port.cc
+++ b/cast/common/channel/cast_socket_message_port.cc
@@ -89,6 +89,13 @@ void CastSocketMessagePort::OnMessage(VirtualConnectionRouter* router,
::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 36b25263..248c3ee6 100644
--- a/cast/common/channel/cast_socket_message_port.h
+++ b/cast/common/channel/cast_socket_message_port.h
@@ -28,7 +28,8 @@ class CastSocketMessagePort : public MessagePort, public CastMessageHandler {
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 6240ac02..8a02707f 100644
--- a/cast/receiver/application_agent_unittest.cc
+++ b/cast/receiver/application_agent_unittest.cc
@@ -435,8 +435,8 @@ TEST_F(ApplicationAgentTest, LaunchesApp_PassesMessages_ThenStopsApp) {
// 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 @@ TEST_F(ApplicationAgentTest, LaunchesApp_PassesMessages_ThenStopsApp) {
}
}
})";
- 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) {