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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "remoting/base/constants.h" | 12 #include "remoting/base/constants.h" |
13 #include "remoting/jingle_glue/iq_sender.h" | 13 #include "remoting/jingle_glue/iq_sender.h" |
14 #include "remoting/jingle_glue/jingle_thread.h" | 14 #include "remoting/jingle_glue/jingle_thread.h" |
15 #include "remoting/jingle_glue/signal_strategy.h" | 15 #include "remoting/jingle_glue/signal_strategy.h" |
16 #include "remoting/protocol/jingle_messages.h" | |
Sergey Ulanov
2012/01/31 02:37:13
don't need this include.
Lambros
2012/01/31 21:57:29
Done.
| |
16 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 17 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
17 #include "third_party/libjingle/source/talk/xmpp/constants.h" | 18 #include "third_party/libjingle/source/talk/xmpp/constants.h" |
18 | 19 |
19 using buzz::QName; | 20 using buzz::QName; |
20 using buzz::XmlElement; | 21 using buzz::XmlElement; |
21 | 22 |
22 namespace remoting { | 23 namespace remoting { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 const char kHeartbeatQueryTag[] = "heartbeat"; | 27 const char kHeartbeatQueryTag[] = "heartbeat"; |
27 const char kHostIdAttr[] = "hostid"; | 28 const char kHostIdAttr[] = "hostid"; |
28 const char kHeartbeatSignatureTag[] = "signature"; | 29 const char kHeartbeatSignatureTag[] = "signature"; |
29 const char kSignatureTimeAttr[] = "time"; | 30 const char kSignatureTimeAttr[] = "time"; |
30 | 31 |
32 const char kErrorTag[] = "error"; | |
Sergey Ulanov
2012/01/31 02:37:13
IMO it is not necessary to define it here if it is
Wez
2012/01/31 05:44:03
We may as well define it, for consistency with the
Sergey Ulanov
2012/01/31 07:41:35
Or alternatively we could remove other constants t
Lambros
2012/01/31 21:57:29
Normally, I'd agree that defining a constant for s
| |
33 const char kNotFoundTag[] = "item-not-found"; | |
34 | |
31 const char kHeartbeatResultTag[] = "heartbeat-result"; | 35 const char kHeartbeatResultTag[] = "heartbeat-result"; |
32 const char kSetIntervalTag[] = "set-interval"; | 36 const char kSetIntervalTag[] = "set-interval"; |
33 | 37 |
34 const int64 kDefaultHeartbeatIntervalMs = 5 * 60 * 1000; // 5 minutes. | 38 const int64 kDefaultHeartbeatIntervalMs = 5 * 60 * 1000; // 5 minutes. |
35 | 39 |
36 } // namespace | 40 } // namespace |
37 | 41 |
38 HeartbeatSender::HeartbeatSender( | 42 HeartbeatSender::HeartbeatSender( |
39 const std::string& host_id, | 43 const std::string& host_id, |
40 SignalStrategy* signal_strategy, | 44 SignalStrategy* signal_strategy, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 VLOG(1) << "Sending heartbeat stanza to " << kChromotingBotJid; | 77 VLOG(1) << "Sending heartbeat stanza to " << kChromotingBotJid; |
74 request_.reset(iq_sender_->SendIq( | 78 request_.reset(iq_sender_->SendIq( |
75 buzz::STR_SET, kChromotingBotJid, CreateHeartbeatMessage(), | 79 buzz::STR_SET, kChromotingBotJid, CreateHeartbeatMessage(), |
76 base::Bind(&HeartbeatSender::ProcessResponse, | 80 base::Bind(&HeartbeatSender::ProcessResponse, |
77 base::Unretained(this)))); | 81 base::Unretained(this)))); |
78 } | 82 } |
79 | 83 |
80 void HeartbeatSender::ProcessResponse(const XmlElement* response) { | 84 void HeartbeatSender::ProcessResponse(const XmlElement* response) { |
81 std::string type = response->Attr(buzz::QN_TYPE); | 85 std::string type = response->Attr(buzz::QN_TYPE); |
82 if (type == buzz::STR_ERROR) { | 86 if (type == buzz::STR_ERROR) { |
87 const XmlElement* error_element = | |
88 response->FirstNamed(QName(remoting::protocol::kJabberNamespace, | |
Sergey Ulanov
2012/01/31 02:37:13
You can use buzz::NS_CLIENT here instead to be con
Lambros
2012/01/31 21:57:29
Done.
| |
89 kErrorTag)); | |
90 if (error_element) { | |
91 if (error_element->FirstNamed(QName(buzz::NS_STANZA, kNotFoundTag))) { | |
92 // TODO(lambroslambrou): Trigger an application-defined callback to | |
93 // shut down the host properly, instead of just exiting here. | |
Wez
2012/01/31 05:44:03
Create a Type-Cleanup bug for this and include the
Lambros
2012/01/31 21:57:29
Done.
| |
94 LOG(ERROR) << "Received error: Host ID invalid"; | |
95 exit(1); | |
Wez
2012/01/31 05:44:03
I think this should be _exit(1), so that destructo
Sergey Ulanov
2012/01/31 07:41:35
As I understand the only difference is that _exit(
Lambros
2012/01/31 21:57:29
I think exit() is fine here. It will run atexit()
| |
96 } | |
97 } | |
98 | |
83 LOG(ERROR) << "Received error in response to heartbeat: " | 99 LOG(ERROR) << "Received error in response to heartbeat: " |
84 << response->Str(); | 100 << response->Str(); |
Sergey Ulanov
2012/01/31 02:37:13
revert this?
Lambros
2012/01/31 21:57:29
Done.
| |
85 return; | 101 return; |
86 } | 102 } |
87 | 103 |
88 // This method must only be called for error or result stanzas. | 104 // This method must only be called for error or result stanzas. |
89 DCHECK_EQ(std::string(buzz::STR_RESULT), type); | 105 DCHECK_EQ(std::string(buzz::STR_RESULT), type); |
90 | 106 |
91 const XmlElement* result_element = | 107 const XmlElement* result_element = |
92 response->FirstNamed(QName(kChromotingXmlNamespace, kHeartbeatResultTag)); | 108 response->FirstNamed(QName(kChromotingXmlNamespace, kHeartbeatResultTag)); |
93 if (result_element) { | 109 if (result_element) { |
94 const XmlElement* set_interval_element = | 110 const XmlElement* set_interval_element = |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str); | 154 QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str); |
139 | 155 |
140 std::string message = signal_strategy_->GetLocalJid() + ' ' + time_str; | 156 std::string message = signal_strategy_->GetLocalJid() + ' ' + time_str; |
141 std::string signature(key_pair_->GetSignature(message)); | 157 std::string signature(key_pair_->GetSignature(message)); |
142 signature_tag->AddText(signature); | 158 signature_tag->AddText(signature); |
143 | 159 |
144 return signature_tag; | 160 return signature_tag; |
145 } | 161 } |
146 | 162 |
147 } // namespace remoting | 163 } // namespace remoting |
OLD | NEW |