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

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

Issue 10106013: Chromoting: stopping the service if the host ID is permanently not recognized by the could. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cr feedback. Created 8 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 | 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/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
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(
50 Delegate* delegate,
51 const std::string& host_id, 51 const std::string& host_id,
52 SignalStrategy* signal_strategy, 52 SignalStrategy* signal_strategy,
53 HostKeyPair* key_pair) 53 HostKeyPair* key_pair)
54 : host_id_(host_id), 54 : delegate_(delegate),
55 host_id_(host_id),
55 signal_strategy_(signal_strategy), 56 signal_strategy_(signal_strategy),
56 key_pair_(key_pair), 57 key_pair_(key_pair),
57 interval_ms_(kDefaultHeartbeatIntervalMs), 58 interval_ms_(kDefaultHeartbeatIntervalMs),
58 sequence_id_(0), 59 sequence_id_(0),
59 sequence_id_was_set_(false), 60 sequence_id_was_set_(false),
60 sequence_id_recent_set_num_(0), 61 sequence_id_recent_set_num_(0),
61 heartbeat_succeeded_(false), 62 heartbeat_succeeded_(false),
62 failed_startup_heartbeat_count_(0) { 63 failed_startup_heartbeat_count_(0) {
63 DCHECK(signal_strategy_); 64 DCHECK(signal_strategy_);
64 DCHECK(key_pair_); 65 DCHECK(key_pair_);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 failed_startup_heartbeat_count_++; 128 failed_startup_heartbeat_count_++;
128 if (!heartbeat_succeeded_ && (failed_startup_heartbeat_count_ <= 129 if (!heartbeat_succeeded_ && (failed_startup_heartbeat_count_ <=
129 kMaxResendOnHostNotFoundCount)) { 130 kMaxResendOnHostNotFoundCount)) {
130 timer_resend_.Start(FROM_HERE, 131 timer_resend_.Start(FROM_HERE,
131 base::TimeDelta::FromMilliseconds( 132 base::TimeDelta::FromMilliseconds(
132 kResendDelayOnHostNotFoundMs), 133 kResendDelayOnHostNotFoundMs),
133 this, 134 this,
134 &HeartbeatSender::ResendStanza); 135 &HeartbeatSender::ResendStanza);
135 return; 136 return;
136 } 137 }
137 // TODO(lambroslambrou): Trigger an application-defined callback to 138 delegate_->OnUnknownHostIdError();
138 // shut down the host properly, instead of just exiting here 139 return;
139 // (http://crbug.com/112160).
140 LOG(ERROR) << "Exit: Host ID not found";
141 exit(kExitCodeHostIdInvalid);
142 } 140 }
143 } 141 }
144 142
145 LOG(ERROR) << "Received error in response to heartbeat: " 143 LOG(ERROR) << "Received error in response to heartbeat: "
146 << response->Str(); 144 << response->Str();
147 return; 145 return;
148 } 146 }
149 147
150 heartbeat_succeeded_ = true; 148 heartbeat_succeeded_ = true;
151 149
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 244
247 std::string message = signal_strategy_->GetLocalJid() + ' ' + 245 std::string message = signal_strategy_->GetLocalJid() + ' ' +
248 base::IntToString(sequence_id_); 246 base::IntToString(sequence_id_);
249 std::string signature(key_pair_->GetSignature(message)); 247 std::string signature(key_pair_->GetSignature(message));
250 signature_tag->AddText(signature); 248 signature_tag->AddText(signature);
251 249
252 return signature_tag.Pass(); 250 return signature_tag.Pass();
253 } 251 }
254 252
255 } // namespace remoting 253 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698