| 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/heartbeat_sender.h" | 5 #include "remoting/host/heartbeat_sender.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "remoting/base/constants.h" | 15 #include "remoting/base/constants.h" |
| 16 #include "remoting/host/constants.h" |
| 16 #include "remoting/jingle_glue/iq_sender.h" | 17 #include "remoting/jingle_glue/iq_sender.h" |
| 17 #include "remoting/jingle_glue/jingle_thread.h" | 18 #include "remoting/jingle_glue/jingle_thread.h" |
| 18 #include "remoting/jingle_glue/signal_strategy.h" | 19 #include "remoting/jingle_glue/signal_strategy.h" |
| 19 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 20 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 20 #include "third_party/libjingle/source/talk/xmpp/constants.h" | 21 #include "third_party/libjingle/source/talk/xmpp/constants.h" |
| 21 | 22 |
| 22 using buzz::QName; | 23 using buzz::QName; |
| 23 using buzz::XmlElement; | 24 using buzz::XmlElement; |
| 24 | 25 |
| 25 namespace remoting { | 26 namespace remoting { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 36 | 37 |
| 37 const char kHeartbeatResultTag[] = "heartbeat-result"; | 38 const char kHeartbeatResultTag[] = "heartbeat-result"; |
| 38 const char kSetIntervalTag[] = "set-interval"; | 39 const char kSetIntervalTag[] = "set-interval"; |
| 39 const char kExpectedSequenceIdTag[] = "expected-sequence-id"; | 40 const char kExpectedSequenceIdTag[] = "expected-sequence-id"; |
| 40 | 41 |
| 41 const int64 kDefaultHeartbeatIntervalMs = 5 * 60 * 1000; // 5 minutes. | 42 const int64 kDefaultHeartbeatIntervalMs = 5 * 60 * 1000; // 5 minutes. |
| 42 const int64 kResendDelayMs = 10 * 1000; // 10 seconds. | 43 const int64 kResendDelayMs = 10 * 1000; // 10 seconds. |
| 43 const int64 kResendDelayOnHostNotFoundMs = 10 * 1000; // 10 seconds. | 44 const int64 kResendDelayOnHostNotFoundMs = 10 * 1000; // 10 seconds. |
| 44 const int kMaxResendOnHostNotFoundCount = 12; // 2 minutes (12 x 10 seconds). | 45 const int kMaxResendOnHostNotFoundCount = 12; // 2 minutes (12 x 10 seconds). |
| 45 | 46 |
| 46 const int kExitCodeHostIdInvalid = 100; | |
| 47 | |
| 48 } // namespace | 47 } // namespace |
| 49 | 48 |
| 50 HeartbeatSender::HeartbeatSender( | 49 HeartbeatSender::HeartbeatSender( |
| 51 const std::string& host_id, | 50 const std::string& host_id, |
| 52 SignalStrategy* signal_strategy, | 51 SignalStrategy* signal_strategy, |
| 53 HostKeyPair* key_pair) | 52 HostKeyPair* key_pair) |
| 54 : host_id_(host_id), | 53 : host_id_(host_id), |
| 55 signal_strategy_(signal_strategy), | 54 signal_strategy_(signal_strategy), |
| 56 key_pair_(key_pair), | 55 key_pair_(key_pair), |
| 57 interval_ms_(kDefaultHeartbeatIntervalMs), | 56 interval_ms_(kDefaultHeartbeatIntervalMs), |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 base::TimeDelta::FromMilliseconds( | 130 base::TimeDelta::FromMilliseconds( |
| 132 kResendDelayOnHostNotFoundMs), | 131 kResendDelayOnHostNotFoundMs), |
| 133 this, | 132 this, |
| 134 &HeartbeatSender::ResendStanza); | 133 &HeartbeatSender::ResendStanza); |
| 135 return; | 134 return; |
| 136 } | 135 } |
| 137 // TODO(lambroslambrou): Trigger an application-defined callback to | 136 // TODO(lambroslambrou): Trigger an application-defined callback to |
| 138 // shut down the host properly, instead of just exiting here | 137 // shut down the host properly, instead of just exiting here |
| 139 // (http://crbug.com/112160). | 138 // (http://crbug.com/112160). |
| 140 LOG(ERROR) << "Exit: Host ID not found"; | 139 LOG(ERROR) << "Exit: Host ID not found"; |
| 141 exit(kExitCodeHostIdInvalid); | 140 exit(kInvalidHostIdExitCode); |
| 142 } | 141 } |
| 143 } | 142 } |
| 144 | 143 |
| 145 LOG(ERROR) << "Received error in response to heartbeat: " | 144 LOG(ERROR) << "Received error in response to heartbeat: " |
| 146 << response->Str(); | 145 << response->Str(); |
| 147 return; | 146 return; |
| 148 } | 147 } |
| 149 | 148 |
| 150 heartbeat_succeeded_ = true; | 149 heartbeat_succeeded_ = true; |
| 151 | 150 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 245 |
| 247 std::string message = signal_strategy_->GetLocalJid() + ' ' + | 246 std::string message = signal_strategy_->GetLocalJid() + ' ' + |
| 248 base::IntToString(sequence_id_); | 247 base::IntToString(sequence_id_); |
| 249 std::string signature(key_pair_->GetSignature(message)); | 248 std::string signature(key_pair_->GetSignature(message)); |
| 250 signature_tag->AddText(signature); | 249 signature_tag->AddText(signature); |
| 251 | 250 |
| 252 return signature_tag.Pass(); | 251 return signature_tag.Pass(); |
| 253 } | 252 } |
| 254 | 253 |
| 255 } // namespace remoting | 254 } // namespace remoting |
| OLD | NEW |