| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/edk/system/node_controller.h" | 5 #include "mojo/edk/system/node_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 base::AutoLock lock(peers_lock_); | 705 base::AutoLock lock(peers_lock_); |
| 706 auto& queue = pending_peer_messages_[name]; | 706 auto& queue = pending_peer_messages_[name]; |
| 707 needs_introduction = queue.empty(); | 707 needs_introduction = queue.empty(); |
| 708 queue.emplace(std::move(channel_message)); | 708 queue.emplace(std::move(channel_message)); |
| 709 } | 709 } |
| 710 | 710 |
| 711 if (needs_introduction) { | 711 if (needs_introduction) { |
| 712 scoped_refptr<NodeChannel> broker = GetBrokerChannel(); | 712 scoped_refptr<NodeChannel> broker = GetBrokerChannel(); |
| 713 if (!broker) { | 713 if (!broker) { |
| 714 DVLOG(1) << "Dropping message for unknown peer: " << name; | 714 DVLOG(1) << "Dropping message for unknown peer: " << name; |
| 715 |
| 716 base::AutoLock lock(peers_lock_); |
| 717 pending_peer_messages_.erase(name); |
| 715 return; | 718 return; |
| 716 } | 719 } |
| 717 broker->RequestIntroduction(name); | 720 broker->RequestIntroduction(name); |
| 718 } | 721 } |
| 719 } | 722 } |
| 720 | 723 |
| 721 void NodeController::AcceptIncomingMessages() { | 724 void NodeController::AcceptIncomingMessages() { |
| 722 // This is an impactically large value which should never be reached in | 725 // This is an impactically large value which should never be reached in |
| 723 // practice. See the CHECK below for usage. | 726 // practice. See the CHECK below for usage. |
| 724 constexpr size_t kMaxAcceptedMessages = 1000000; | 727 constexpr size_t kMaxAcceptedMessages = 1000000; |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 933 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 931 | 934 |
| 932 auto it = pending_children_.find(from_node); | 935 auto it = pending_children_.find(from_node); |
| 933 if (it == pending_children_.end() || token != from_node) { | 936 if (it == pending_children_.end() || token != from_node) { |
| 934 DLOG(ERROR) << "Received unexpected AcceptParent message from " | 937 DLOG(ERROR) << "Received unexpected AcceptParent message from " |
| 935 << from_node; | 938 << from_node; |
| 936 DropPeer(from_node, nullptr); | 939 DropPeer(from_node, nullptr); |
| 937 return; | 940 return; |
| 938 } | 941 } |
| 939 | 942 |
| 943 { |
| 944 base::AutoLock lock(reserved_ports_lock_); |
| 945 auto it = pending_child_tokens_.find(from_node); |
| 946 if (it != pending_child_tokens_.end()) { |
| 947 std::string token = std::move(it->second); |
| 948 pending_child_tokens_.erase(it); |
| 949 pending_child_tokens_[child_name] = std::move(token); |
| 950 } |
| 951 } |
| 952 |
| 940 scoped_refptr<NodeChannel> channel = it->second; | 953 scoped_refptr<NodeChannel> channel = it->second; |
| 941 pending_children_.erase(it); | 954 pending_children_.erase(it); |
| 942 | 955 |
| 943 DCHECK(channel); | 956 DCHECK(channel); |
| 944 | 957 |
| 945 DVLOG(1) << "Parent " << name_ << " accepted child " << child_name; | 958 DVLOG(1) << "Parent " << name_ << " accepted child " << child_name; |
| 946 | 959 |
| 947 AddPeer(child_name, channel, false /* start_channel */); | 960 AddPeer(child_name, channel, false /* start_channel */); |
| 948 | 961 |
| 949 // TODO(rockot/amistry): We could simplify child initialization if we could | 962 // TODO(rockot/amistry): We could simplify child initialization if we could |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 ports::PortRef local_port; | 1161 ports::PortRef local_port; |
| 1149 { | 1162 { |
| 1150 base::AutoLock lock(reserved_ports_lock_); | 1163 base::AutoLock lock(reserved_ports_lock_); |
| 1151 auto it = reserved_ports_.find(token); | 1164 auto it = reserved_ports_.find(token); |
| 1152 if (it == reserved_ports_.end()) { | 1165 if (it == reserved_ports_.end()) { |
| 1153 DVLOG(1) << "Ignoring request to connect to port for unknown token " | 1166 DVLOG(1) << "Ignoring request to connect to port for unknown token " |
| 1154 << token; | 1167 << token; |
| 1155 return; | 1168 return; |
| 1156 } | 1169 } |
| 1157 local_port = it->second.port; | 1170 local_port = it->second.port; |
| 1171 reserved_ports_.erase(it); |
| 1158 } | 1172 } |
| 1159 | 1173 |
| 1160 int rv = node_->MergePorts(local_port, from_node, connector_port_name); | 1174 int rv = node_->MergePorts(local_port, from_node, connector_port_name); |
| 1161 if (rv != ports::OK) | 1175 if (rv != ports::OK) |
| 1162 DLOG(ERROR) << "MergePorts failed: " << rv; | 1176 DLOG(ERROR) << "MergePorts failed: " << rv; |
| 1163 | 1177 |
| 1164 AcceptIncomingMessages(); | 1178 AcceptIncomingMessages(); |
| 1165 } | 1179 } |
| 1166 | 1180 |
| 1167 void NodeController::OnRequestIntroduction(const ports::NodeName& from_node, | 1181 void NodeController::OnRequestIntroduction(const ports::NodeName& from_node, |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1448 NodeController::PeerConnection::~PeerConnection() = default; | 1462 NodeController::PeerConnection::~PeerConnection() = default; |
| 1449 | 1463 |
| 1450 NodeController::PeerConnection& NodeController::PeerConnection:: | 1464 NodeController::PeerConnection& NodeController::PeerConnection:: |
| 1451 operator=(const PeerConnection& other) = default; | 1465 operator=(const PeerConnection& other) = default; |
| 1452 | 1466 |
| 1453 NodeController::PeerConnection& NodeController::PeerConnection:: | 1467 NodeController::PeerConnection& NodeController::PeerConnection:: |
| 1454 operator=(PeerConnection&& other) = default; | 1468 operator=(PeerConnection&& other) = default; |
| 1455 | 1469 |
| 1456 } // namespace edk | 1470 } // namespace edk |
| 1457 } // namespace mojo | 1471 } // namespace mojo |
| OLD | NEW |