OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef REMOTING_HOST_HEARTBEAT_SENDER_H_ | 5 #ifndef REMOTING_HOST_HEARTBEAT_SENDER_H_ |
6 #define REMOTING_HOST_HEARTBEAT_SENDER_H_ | 6 #define REMOTING_HOST_HEARTBEAT_SENDER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 // <rem:signature rem:time="1279061748">.signature.</rem:signature> | 30 // <rem:signature rem:time="1279061748">.signature.</rem:signature> |
31 // </rem:heartbeat> | 31 // </rem:heartbeat> |
32 // </iq> | 32 // </iq> |
33 // | 33 // |
34 // The time attribute of the signature is the decimal time when the message | 34 // The time attribute of the signature is the decimal time when the message |
35 // was sent in second since the epoch (01/01/1970). The signature is a BASE64 | 35 // was sent in second since the epoch (01/01/1970). The signature is a BASE64 |
36 // encoded SHA-1/RSA signature created with the host's private key. The message | 36 // encoded SHA-1/RSA signature created with the host's private key. The message |
37 // being signed is the full Jid concatenated with the time value, separated by | 37 // being signed is the full Jid concatenated with the time value, separated by |
38 // space. For example, for the heartbeat stanza above the message that is being | 38 // space. For example, for the heartbeat stanza above the message that is being |
39 // signed is "user@gmail.com/chromoting123123 1279061748". | 39 // signed is "user@gmail.com/chromoting123123 1279061748". |
| 40 // |
| 41 // Bot sends the following result stanza in response to each heartbeat: |
| 42 // |
| 43 // <iq type="set" from="remoting@bot.talk.google.com" |
| 44 // to="user@gmail.com/chromoting123123" id="5" xmlns="jabber:client"> |
| 45 // <rem:heartbeat-result xmlns:rem="google:remoting"> |
| 46 // <rem:set-interval>300</rem:set-interval> |
| 47 // </rem:heartbeat> |
| 48 // </iq> |
| 49 // |
| 50 // The set-interval tag is used to specify desired heartbeat interval |
| 51 // in seconds. The heartbeat-result and the set-interval tags are |
| 52 // optional. Host uses default heartbeat interval if it doesn't find |
| 53 // set-interval tag in the result Iq stanza it receives from the |
| 54 // server. |
| 55 // |
40 // TODO(sergeyu): Is it enough to sign JID and nothing else? | 56 // TODO(sergeyu): Is it enough to sign JID and nothing else? |
41 class HeartbeatSender : public base::RefCountedThreadSafe<HeartbeatSender> { | 57 class HeartbeatSender : public base::RefCountedThreadSafe<HeartbeatSender> { |
42 public: | 58 public: |
43 HeartbeatSender(); | 59 HeartbeatSender(); |
44 virtual ~HeartbeatSender(); | 60 virtual ~HeartbeatSender(); |
45 | 61 |
46 // Initializes heart-beating for |jingle_client| with the specified | 62 // Initializes heart-beating for |jingle_client| with the specified |
47 // config. Returns false if the config is invalid (e.g. private key | 63 // config. Returns false if the config is invalid (e.g. private key |
48 // cannot be parsed). | 64 // cannot be parsed). |
49 bool Init(MutableHostConfig* config, JingleClient* jingle_client); | 65 bool Init(MutableHostConfig* config, JingleClient* jingle_client); |
50 | 66 |
51 // Starts heart-beating. Must be called after init. | 67 // Starts heart-beating. Must be called after init. |
52 void Start(); | 68 void Start(); |
53 | 69 |
54 // Stops heart-beating. Must be called before corresponding JingleClient | 70 // Stops heart-beating. Must be called before corresponding JingleClient |
55 // is destroyed. This object will not be deleted until Stop() is called, | 71 // is destroyed. This object will not be deleted until Stop() is called, |
56 // and it may (and will) crash after JingleClient is destroyed. Heartbeating | 72 // and it may (and will) crash after JingleClient is destroyed. Heartbeating |
57 // cannot be restarted after it has been stopped, A new sender must be created | 73 // cannot be restarted after it has been stopped, A new sender must be created |
58 // instead. | 74 // instead. |
59 void Stop(); | 75 void Stop(); |
60 | 76 |
61 private: | 77 private: |
62 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, DoSendStanza); | 78 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, DoSendStanza); |
63 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, CreateHeartbeatMessage); | 79 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, CreateHeartbeatMessage); |
| 80 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, ProcessResponse); |
64 | 81 |
65 enum State { | 82 enum State { |
66 CREATED, | 83 CREATED, |
67 INITIALIZED, | 84 INITIALIZED, |
68 STARTED, | 85 STARTED, |
69 STOPPED, | 86 STOPPED, |
70 }; | 87 }; |
71 | 88 |
72 void DoSendStanza(); | 89 void DoSendStanza(); |
73 | 90 |
74 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. | 91 // Helper methods used by DoSendStanza() to generate heartbeat stanzas. |
75 // Caller owns the result. | 92 // Caller owns the result. |
76 buzz::XmlElement* CreateHeartbeatMessage(); | 93 buzz::XmlElement* CreateHeartbeatMessage(); |
77 buzz::XmlElement* CreateSignature(); | 94 buzz::XmlElement* CreateSignature(); |
78 | 95 |
79 void ProcessResponse(const buzz::XmlElement* response); | 96 void ProcessResponse(const buzz::XmlElement* response); |
80 | 97 |
81 State state_; | 98 State state_; |
82 scoped_refptr<MutableHostConfig> config_; | 99 scoped_refptr<MutableHostConfig> config_; |
83 JingleClient* jingle_client_; | 100 JingleClient* jingle_client_; |
84 scoped_ptr<IqRequest> request_; | 101 scoped_ptr<IqRequest> request_; |
85 std::string host_id_; | 102 std::string host_id_; |
86 HostKeyPair key_pair_; | 103 HostKeyPair key_pair_; |
| 104 int interval_ms_; |
87 | 105 |
88 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); | 106 DISALLOW_COPY_AND_ASSIGN(HeartbeatSender); |
89 }; | 107 }; |
90 | 108 |
91 } // namespace remoting | 109 } // namespace remoting |
92 | 110 |
93 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ | 111 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ |
OLD | NEW |