| OLD | NEW |
| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 DisconnectAllClients(); | 164 DisconnectAllClients(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void ChromotingHost::SetMaximumSessionDuration( | 167 void ChromotingHost::SetMaximumSessionDuration( |
| 168 const base::TimeDelta& max_session_duration) { | 168 const base::TimeDelta& max_session_duration) { |
| 169 max_session_duration_ = max_session_duration; | 169 max_session_duration_ = max_session_duration; |
| 170 } | 170 } |
| 171 | 171 |
| 172 //////////////////////////////////////////////////////////////////////////// | 172 //////////////////////////////////////////////////////////////////////////// |
| 173 // protocol::ClientSession::EventHandler implementation. | 173 // protocol::ClientSession::EventHandler implementation. |
| 174 void ChromotingHost::OnSessionAuthenticating(ClientSession* client) { |
| 175 // We treat each incoming connection as a failure to authenticate, |
| 176 // and clear the backoff when a connection successfully |
| 177 // authenticates. This allows the backoff to protect from parallel |
| 178 // connection attempts as well as sequential ones. |
| 179 if (login_backoff_.ShouldRejectRequest()) { |
| 180 LOG(WARNING) << "Disconnecting client " << client->client_jid() << " due to" |
| 181 " an overload of failed login attempts."; |
| 182 client->DisconnectSession(); |
| 183 return; |
| 184 } |
| 185 login_backoff_.InformOfRequest(false); |
| 186 } |
| 187 |
| 174 bool ChromotingHost::OnSessionAuthenticated(ClientSession* client) { | 188 bool ChromotingHost::OnSessionAuthenticated(ClientSession* client) { |
| 175 DCHECK(CalledOnValidThread()); | 189 DCHECK(CalledOnValidThread()); |
| 176 | 190 |
| 177 login_backoff_.Reset(); | 191 login_backoff_.Reset(); |
| 178 | 192 |
| 179 // Disconnect all other clients. |it| should be advanced before Disconnect() | 193 // Disconnect all other clients. |it| should be advanced before Disconnect() |
| 180 // is called to avoid it becoming invalid when the client is removed from | 194 // is called to avoid it becoming invalid when the client is removed from |
| 181 // the list. | 195 // the list. |
| 182 ClientList::iterator it = clients_.begin(); | 196 ClientList::iterator it = clients_.begin(); |
| 183 while (it != clients_.end()) { | 197 while (it != clients_.end()) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 protocol::Session* session, | 272 protocol::Session* session, |
| 259 protocol::SessionManager::IncomingSessionResponse* response) { | 273 protocol::SessionManager::IncomingSessionResponse* response) { |
| 260 DCHECK(CalledOnValidThread()); | 274 DCHECK(CalledOnValidThread()); |
| 261 | 275 |
| 262 if (!started_) { | 276 if (!started_) { |
| 263 *response = protocol::SessionManager::DECLINE; | 277 *response = protocol::SessionManager::DECLINE; |
| 264 return; | 278 return; |
| 265 } | 279 } |
| 266 | 280 |
| 267 if (login_backoff_.ShouldRejectRequest()) { | 281 if (login_backoff_.ShouldRejectRequest()) { |
| 282 LOG(WARNING) << "Rejecting connection due to" |
| 283 " an overload of failed login attempts."; |
| 268 *response = protocol::SessionManager::OVERLOAD; | 284 *response = protocol::SessionManager::OVERLOAD; |
| 269 return; | 285 return; |
| 270 } | 286 } |
| 271 | 287 |
| 272 // We treat each incoming connection as a failure to authenticate, | |
| 273 // and clear the backoff when a connection successfully | |
| 274 // authenticates. This allows the backoff to protect from parallel | |
| 275 // connection attempts as well as sequential ones. | |
| 276 login_backoff_.InformOfRequest(false); | |
| 277 | |
| 278 protocol::SessionConfig config; | 288 protocol::SessionConfig config; |
| 279 if (!protocol_config_->Select(session->candidate_config(), &config)) { | 289 if (!protocol_config_->Select(session->candidate_config(), &config)) { |
| 280 LOG(WARNING) << "Rejecting connection from " << session->jid() | 290 LOG(WARNING) << "Rejecting connection from " << session->jid() |
| 281 << " because no compatible configuration has been found."; | 291 << " because no compatible configuration has been found."; |
| 282 *response = protocol::SessionManager::INCOMPATIBLE; | 292 *response = protocol::SessionManager::INCOMPATIBLE; |
| 283 return; | 293 return; |
| 284 } | 294 } |
| 285 | 295 |
| 286 session->set_config(config); | 296 session->set_config(config); |
| 287 | 297 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 DCHECK(CalledOnValidThread()); | 329 DCHECK(CalledOnValidThread()); |
| 320 | 330 |
| 321 while (!clients_.empty()) { | 331 while (!clients_.empty()) { |
| 322 size_t size = clients_.size(); | 332 size_t size = clients_.size(); |
| 323 clients_.front()->DisconnectSession(); | 333 clients_.front()->DisconnectSession(); |
| 324 CHECK_EQ(clients_.size(), size - 1); | 334 CHECK_EQ(clients_.size(), size - 1); |
| 325 } | 335 } |
| 326 } | 336 } |
| 327 | 337 |
| 328 } // namespace remoting | 338 } // namespace remoting |
| OLD | NEW |