summaryrefslogtreecommitdiffstats
path: root/remoting/host/heartbeat_sender.h
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-04 23:04:05 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-04 23:04:05 +0000
commitcdf8c57cbf1d997346e650fb5d0b301f7abc4dd4 (patch)
tree81a7bfd30b29dfaea9cd2644daf06f39d11b17a0 /remoting/host/heartbeat_sender.h
parentc0035fff490b71ff952b97b6a3d22b1041689979 (diff)
downloadchromium_src-cdf8c57cbf1d997346e650fb5d0b301f7abc4dd4.zip
chromium_src-cdf8c57cbf1d997346e650fb5d0b301f7abc4dd4.tar.gz
chromium_src-cdf8c57cbf1d997346e650fb5d0b301f7abc4dd4.tar.bz2
Added HostKeyPair class, signatures for heartbeat messages.
BUG=None TEST=unittests Review URL: http://codereview.chromium.org/3087003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54991 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host/heartbeat_sender.h')
-rw-r--r--remoting/host/heartbeat_sender.h59
1 files changed, 53 insertions, 6 deletions
diff --git a/remoting/host/heartbeat_sender.h b/remoting/host/heartbeat_sender.h
index 08665c6..07e2568e 100644
--- a/remoting/host/heartbeat_sender.h
+++ b/remoting/host/heartbeat_sender.h
@@ -9,34 +9,81 @@
#include "base/scoped_ptr.h"
#include "base/ref_counted.h"
+#include "remoting/host/host_key_pair.h"
#include "remoting/jingle_glue/iq_request.h"
+#include "testing/gtest/include/gtest/gtest_prod.h"
namespace remoting {
class IqRequest;
+class HostKeyPair;
class JingleClient;
class MutableHostConfig;
-// HeartbeatSender periodically sends hertbeats to the chromoting bot.
-// TODO(sergeyu): Write unittest for this class.
+// HeartbeatSender periodically sends heartbeat stanzas to the Chromoting Bot.
+// Each heartbeat stanza looks as follows:
+//
+// <iq type="set" to="remoting@bot.talk.google.com"
+// from="user@gmail.com/chromoting123123" id="5" xmlns="jabber:client">
+// <rem:heartbeat rem:hostid="a1ddb11e-8aef-11df-bccf-18a905b9cb5a"
+// xmlns:rem="google:remoting">
+// <rem:signature rem:time="1279061748">.signature.</rem:signature>
+// </rem:heartbeat>
+// </iq>
+//
+// The time attribute of the signature is the decimal time when the message
+// was sent in second since the epoch (01/01/1970). The signature is a BASE64
+// encoded SHA-1/RSA signature created with the host's private key. The message
+// being signed is the full Jid concatenated with the time value, separated by
+// space. For example, for the heartbeat stanza above the message that is being
+// signed is "user@gmail.com/chromoting123123 1279061748".
+// TODO(sergeyu): Is it enough to sign JID and nothing else?
class HeartbeatSender : public base::RefCountedThreadSafe<HeartbeatSender> {
public:
HeartbeatSender();
+ virtual ~HeartbeatSender();
- // Starts heart-beating for |jingle_client|.
- void Start(MutableHostConfig* config, JingleClient* jingle_client);
+ // Initializes heart-beating for |jingle_client| with the specified
+ // config. Returns false if the config is invalid (e.g. private key
+ // cannot be parsed).
+ bool Init(MutableHostConfig* config, JingleClient* jingle_client);
+
+ // Starts heart-beating. Must be called after init.
+ void Start();
+
+ // Stops heart-beating. Must be called before corresponding JingleClient
+ // is destroyed. This object will not be deleted until Stop() is called,
+ // and it may (and will) crash after JingleClient is destroyed. Heartbeating
+ // cannot be restarted after it has been stopped, A new sender must be created
+ // instead.
+ void Stop();
private:
- void DoStart();
+ FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, DoSendStanza);
+ FRIEND_TEST_ALL_PREFIXES(HeartbeatSenderTest, CreateHeartbeatMessage);
+
+ enum State {
+ CREATED,
+ INITIALIZED,
+ STARTED,
+ STOPPED,
+ };
+
void DoSendStanza();
+ // Helper methods used by DoSendStanza() to generate heartbeat stanzas.
+ // Caller owns the result.
+ buzz::XmlElement* CreateHeartbeatMessage();
+ buzz::XmlElement* CreateSignature();
+
void ProcessResponse(const buzz::XmlElement* response);
- bool started_;
+ State state_;
scoped_refptr<MutableHostConfig> config_;
JingleClient* jingle_client_;
scoped_ptr<IqRequest> request_;
std::string host_id_;
+ HostKeyPair key_pair_;
};
} // namespace remoting