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

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

Issue 3087003: Added HostKeyPair class, signatures for heartbeat messages. (Closed)
Patch Set: - Created 10 years, 4 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
« no previous file with comments | « remoting/host/chromoting_host.cc ('k') | remoting/host/heartbeat_sender.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
12 #include "remoting/host/host_key_pair.h"
12 #include "remoting/jingle_glue/iq_request.h" 13 #include "remoting/jingle_glue/iq_request.h"
14 #include "testing/gtest/include/gtest/gtest_prod.h"
13 15
14 namespace remoting { 16 namespace remoting {
15 17
16 class IqRequest; 18 class IqRequest;
19 class HostKeyPair;
17 class JingleClient; 20 class JingleClient;
18 class MutableHostConfig; 21 class MutableHostConfig;
19 22
20 // HeartbeatSender periodically sends hertbeats to the chromoting bot. 23 // HeartbeatSender periodically sends heartbeat stanzas to the Chromoting Bot.
21 // TODO(sergeyu): Write unittest for this class. 24 // Each heartbeat stanza looks as follows:
25 //
26 // <iq type="set" to="remoting@bot.talk.google.com"
27 // from="user@gmail.com/chromoting123123" id="5" xmlns="jabber:client">
28 // <rem:heartbeat rem:hostid="a1ddb11e-8aef-11df-bccf-18a905b9cb5a"
29 // xmlns:rem="google:remoting">
30 // <rem:signature rem:time="1279061748">.signature.</rem:signature>
31 // </rem:heartbeat>
32 // </iq>
33 //
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
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
38 // space. For example, for the heartbeat stanza above the message that is being
39 // signed is "user@gmail.com/chromoting123123 1279061748".
22 class HeartbeatSender : public base::RefCountedThreadSafe<HeartbeatSender> { 40 class HeartbeatSender : public base::RefCountedThreadSafe<HeartbeatSender> {
23 public: 41 public:
24 HeartbeatSender(); 42 HeartbeatSender();
43 virtual ~HeartbeatSender();
25 44
26 // Starts heart-beating for |jingle_client|. 45 // Initializes heart-beating for |jingle_client| with the specified
27 void Start(MutableHostConfig* config, JingleClient* jingle_client); 46 // config. Returns false if the config is invalid (e.g. private key
47 // cannot be parsed).
48 bool Init(MutableHostConfig* config, JingleClient* jingle_client);
49
50 // Starts heart-beating. Must be called after init.
51 void Start();
52
53 // Stops heart-beating. Must be called before corresponding JingleClient
54 // is destroyed. This object will not be deleted until Stop() is called,
55 // and it may (and will) crash after JingleClient is destroyed. Heartbeating
56 // cannot be restarted after it has been stopped, A new sender must be created
57 // instead.
58 void Stop();
28 59
29 private: 60 private:
30 void DoStart(); 61 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, DoSendStanza);
62 FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, CreateHeartbeatMessage);
63
64 enum State {
65 CREATED,
66 INITIALIZED,
67 STARTED,
68 STOPPED,
69 };
70
31 void DoSendStanza(); 71 void DoSendStanza();
32 72
73 // Helper methods used by DoSendStanza() to generate heartbeat stanzas.
74 // Caller owns the result.
75 buzz::XmlElement* CreateHeartbeatMessage();
76 buzz::XmlElement* CreateSignature();
77
33 void ProcessResponse(const buzz::XmlElement* response); 78 void ProcessResponse(const buzz::XmlElement* response);
34 79
35 bool started_; 80 State state_;
36 scoped_refptr<MutableHostConfig> config_; 81 scoped_refptr<MutableHostConfig> config_;
37 JingleClient* jingle_client_; 82 JingleClient* jingle_client_;
38 scoped_ptr<IqRequest> request_; 83 scoped_ptr<IqRequest> request_;
39 std::string host_id_; 84 std::string host_id_;
85 HostKeyPair key_pair_;
40 }; 86 };
41 87
42 } // namespace remoting 88 } // namespace remoting
43 89
44 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_ 90 #endif // REMOTING_HOST_HEARTBEAT_SENDER_H_
OLDNEW
« no previous file with comments | « remoting/host/chromoting_host.cc ('k') | remoting/host/heartbeat_sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698