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

Side by Side Diff: remoting/host/chromoting_host.cc

Issue 9836062: Implement exponential backoff for failed Me2Me authentication attempts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "remoting/host/chromoting_host.h" 5 #include "remoting/host/chromoting_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
(...skipping 13 matching lines...) Expand all
24 #include "remoting/protocol/input_stub.h" 24 #include "remoting/protocol/input_stub.h"
25 #include "remoting/protocol/jingle_session_manager.h" 25 #include "remoting/protocol/jingle_session_manager.h"
26 #include "remoting/protocol/libjingle_transport_factory.h" 26 #include "remoting/protocol/libjingle_transport_factory.h"
27 #include "remoting/protocol/session_config.h" 27 #include "remoting/protocol/session_config.h"
28 28
29 using remoting::protocol::ConnectionToClient; 29 using remoting::protocol::ConnectionToClient;
30 using remoting::protocol::InputStub; 30 using remoting::protocol::InputStub;
31 31
32 namespace remoting { 32 namespace remoting {
33 33
34 namespace {
35
36 const net::BackoffEntry::Policy kDefaultBackoffPolicy = {
37 // Number of initial errors (in sequence) to ignore before applying
38 // exponential back-off rules.
39 0,
40
41 // Initial delay for exponential back-off in ms.
42 2000,
43
44 // Factor by which the waiting time will be multiplied.
45 2,
46
47 // Fuzzing percentage. ex: 10% will spread requests randomly
48 // between 90%-100% of the calculated time.
49 0,
50
51 // Maximum amount of time we are willing to delay our request in ms.
52 -1,
53
54 // Time to keep an entry from being discarded even when it
55 // has no significant state, -1 to never discard.
56 -1,
57 };
58
59 } // namespace
60
34 ChromotingHost::ChromotingHost( 61 ChromotingHost::ChromotingHost(
35 ChromotingHostContext* context, 62 ChromotingHostContext* context,
36 SignalStrategy* signal_strategy, 63 SignalStrategy* signal_strategy,
37 DesktopEnvironment* environment, 64 DesktopEnvironment* environment,
38 const protocol::NetworkSettings& network_settings) 65 const protocol::NetworkSettings& network_settings)
39 : context_(context), 66 : context_(context),
40 desktop_environment_(environment), 67 desktop_environment_(environment),
41 network_settings_(network_settings), 68 network_settings_(network_settings),
42 signal_strategy_(signal_strategy), 69 signal_strategy_(signal_strategy),
43 stopping_recorders_(0), 70 stopping_recorders_(0),
44 state_(kInitial), 71 state_(kInitial),
45 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()), 72 protocol_config_(protocol::CandidateSessionConfig::CreateDefault()),
73 login_backoff_(&kDefaultBackoffPolicy),
46 authenticating_client_(false), 74 authenticating_client_(false),
47 reject_authenticating_client_(false) { 75 reject_authenticating_client_(false) {
48 DCHECK(context_); 76 DCHECK(context_);
49 DCHECK(signal_strategy); 77 DCHECK(signal_strategy);
50 DCHECK(desktop_environment_); 78 DCHECK(desktop_environment_);
51 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); 79 DCHECK(context_->network_message_loop()->BelongsToCurrentThread());
52 desktop_environment_->set_host(this); 80 desktop_environment_->set_host(this);
53 } 81 }
54 82
55 ChromotingHost::~ChromotingHost() { 83 ChromotingHost::~ChromotingHost() {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 scoped_ptr<protocol::AuthenticatorFactory> authenticator_factory) { 158 scoped_ptr<protocol::AuthenticatorFactory> authenticator_factory) {
131 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); 159 DCHECK(context_->network_message_loop()->BelongsToCurrentThread());
132 session_manager_->set_authenticator_factory(authenticator_factory.Pass()); 160 session_manager_->set_authenticator_factory(authenticator_factory.Pass());
133 } 161 }
134 162
135 //////////////////////////////////////////////////////////////////////////// 163 ////////////////////////////////////////////////////////////////////////////
136 // protocol::ClientSession::EventHandler implementation. 164 // protocol::ClientSession::EventHandler implementation.
137 void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { 165 void ChromotingHost::OnSessionAuthenticated(ClientSession* client) {
138 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); 166 DCHECK(context_->network_message_loop()->BelongsToCurrentThread());
139 167
140 // TODO(sergeyu): Update BackoffEntry here. 168 login_backoff_.Reset();
141 } 169 }
142 170
143 void ChromotingHost::OnSessionAuthenticatedAndConnected(ClientSession* client) { 171 void ChromotingHost::OnSessionAuthenticatedAndConnected(ClientSession* client) {
144 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); 172 DCHECK(context_->network_message_loop()->BelongsToCurrentThread());
145 173
146 // Disconnect all other clients. 174 // Disconnect all other clients.
147 // Iterate over a copy of the list of clients, to avoid mutating the list 175 // Iterate over a copy of the list of clients, to avoid mutating the list
148 // while iterating over it. 176 // while iterating over it.
149 ClientList clients_copy(clients_); 177 ClientList clients_copy(clients_);
150 for (ClientList::const_iterator other_client = clients_copy.begin(); 178 for (ClientList::const_iterator other_client = clients_copy.begin();
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 void ChromotingHost::OnIncomingSession( 272 void ChromotingHost::OnIncomingSession(
245 protocol::Session* session, 273 protocol::Session* session,
246 protocol::SessionManager::IncomingSessionResponse* response) { 274 protocol::SessionManager::IncomingSessionResponse* response) {
247 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); 275 DCHECK(context_->network_message_loop()->BelongsToCurrentThread());
248 276
249 if (state_ != kStarted) { 277 if (state_ != kStarted) {
250 *response = protocol::SessionManager::DECLINE; 278 *response = protocol::SessionManager::DECLINE;
251 return; 279 return;
252 } 280 }
253 281
282 if (login_backoff_.ShouldRejectRequest()) {
283 *response = protocol::SessionManager::DISABLED;
284 return;
285 }
286
287 login_backoff_.InformOfRequest(false);
Jói 2012/03/26 12:31:56 It's confusing to me that this is unconditionally
Sergey Ulanov 2012/03/26 23:00:32 Yes, that's the idea. This method is called when a
288
254 protocol::SessionConfig config; 289 protocol::SessionConfig config;
255 if (!protocol_config_->Select(session->candidate_config(), &config)) { 290 if (!protocol_config_->Select(session->candidate_config(), &config)) {
256 LOG(WARNING) << "Rejecting connection from " << session->jid() 291 LOG(WARNING) << "Rejecting connection from " << session->jid()
257 << " because no compatible configuration has been found."; 292 << " because no compatible configuration has been found.";
258 *response = protocol::SessionManager::INCOMPATIBLE; 293 *response = protocol::SessionManager::INCOMPATIBLE;
259 return; 294 return;
260 } 295 }
261 296
262 session->set_config(config); 297 session->set_config(config);
263 298
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 OnShutdown()); 405 OnShutdown());
371 406
372 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin(); 407 for (std::vector<base::Closure>::iterator it = shutdown_tasks_.begin();
373 it != shutdown_tasks_.end(); ++it) { 408 it != shutdown_tasks_.end(); ++it) {
374 it->Run(); 409 it->Run();
375 } 410 }
376 shutdown_tasks_.clear(); 411 shutdown_tasks_.clear();
377 } 412 }
378 413
379 } // namespace remoting 414 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698