Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(785)

Side by Side Diff: mojo/edk/system/node_controller.cc

Issue 2784463004: Mojo EDK: Avoid redundant queueing when sending to unknown peers (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 return; 687 return;
688 } 688 }
689 } 689 }
690 #endif // defined(OS_WIN) 690 #endif // defined(OS_WIN)
691 691
692 if (peer) { 692 if (peer) {
693 peer->PortsMessage(std::move(channel_message)); 693 peer->PortsMessage(std::move(channel_message));
694 return; 694 return;
695 } 695 }
696 696
697 // If we don't know who the peer is, queue the message for delivery. If this 697 // If we don't know who the peer is and we are the broker, we can only assume
698 // is the first message queued for the peer, we also ask the broker to 698 // the peer is invalid, i.e., it's either a junk name or has already been
699 // introduce us to them. 699 // disconnected.
700 scoped_refptr<NodeChannel> broker = GetBrokerChannel();
701 if (!broker) {
702 DVLOG(1) << "Dropping message for unknown peer: " << name;
703 return;
704 }
700 705
706 // If we aren't the broker, assume we just need to be introduced and queue
707 // until that can be either confirmed or denied by the broker.
701 bool needs_introduction = false; 708 bool needs_introduction = false;
702 { 709 {
703 base::AutoLock lock(peers_lock_); 710 base::AutoLock lock(peers_lock_);
704 auto& queue = pending_peer_messages_[name]; 711 auto& queue = pending_peer_messages_[name];
705 needs_introduction = queue.empty(); 712 needs_introduction = queue.empty();
706 queue.emplace(std::move(channel_message)); 713 queue.emplace(std::move(channel_message));
707 } 714 }
708 715 if (needs_introduction)
709 if (needs_introduction) {
710 scoped_refptr<NodeChannel> broker = GetBrokerChannel();
711 if (!broker) {
712 DVLOG(1) << "Dropping message for unknown peer: " << name;
713
714 base::AutoLock lock(peers_lock_);
715 pending_peer_messages_.erase(name);
716 return;
717 }
718 broker->RequestIntroduction(name); 716 broker->RequestIntroduction(name);
719 }
720 } 717 }
721 718
722 void NodeController::AcceptIncomingMessages() { 719 void NodeController::AcceptIncomingMessages() {
723 // This is an impactically large value which should never be reached in 720 // This is an impactically large value which should never be reached in
724 // practice. See the CHECK below for usage. 721 // practice. See the CHECK below for usage.
725 constexpr size_t kMaxAcceptedMessages = 1000000; 722 constexpr size_t kMaxAcceptedMessages = 1000000;
726 723
727 size_t num_messages_accepted = 0; 724 size_t num_messages_accepted = 0;
728 while (incoming_messages_flag_) { 725 while (incoming_messages_flag_) {
729 // TODO: We may need to be more careful to avoid starving the rest of the 726 // TODO: We may need to be more careful to avoid starving the rest of the
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 NodeController::PeerConnection::~PeerConnection() = default; 1461 NodeController::PeerConnection::~PeerConnection() = default;
1465 1462
1466 NodeController::PeerConnection& NodeController::PeerConnection:: 1463 NodeController::PeerConnection& NodeController::PeerConnection::
1467 operator=(const PeerConnection& other) = default; 1464 operator=(const PeerConnection& other) = default;
1468 1465
1469 NodeController::PeerConnection& NodeController::PeerConnection:: 1466 NodeController::PeerConnection& NodeController::PeerConnection::
1470 operator=(PeerConnection&& other) = default; 1467 operator=(PeerConnection&& other) = default;
1471 1468
1472 } // namespace edk 1469 } // namespace edk
1473 } // namespace mojo 1470 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698