[email protected] | 5668158 | 2013-07-28 20:08:44 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_NET_PROBE_MESSAGE_H_ |
| 6 | #define CHROME_BROWSER_NET_PROBE_MESSAGE_H_ |
| 7 | |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | 5668158 | 2013-07-28 20:08:44 | [diff] [blame] | 10 | #include <string> |
| 11 | |
[email protected] | 5668158 | 2013-07-28 20:08:44 | [diff] [blame] | 12 | #include "base/gtest_prod_util.h" |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 13 | #include "base/macros.h" |
[email protected] | 5668158 | 2013-07-28 20:08:44 | [diff] [blame] | 14 | #include "chrome/browser/net/probe_message.pb.h" |
| 15 | |
| 16 | namespace chrome_browser_net { |
| 17 | |
| 18 | // Packet format between client and server is defined in probe_message.proto. |
| 19 | class ProbeMessage { |
| 20 | public: |
| 21 | ProbeMessage(); |
| 22 | |
| 23 | // Generate a ProbeRequest packet. |
| 24 | void GenerateProbeRequest(const ProbePacket_Token& received_token, |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 25 | uint32_t group_id, |
| 26 | uint32_t probe_size, |
| 27 | uint32_t pacing_interval_micros, |
| 28 | uint32_t number_probe_packets, |
[email protected] | 5668158 | 2013-07-28 20:08:44 | [diff] [blame] | 29 | ProbePacket* output); |
| 30 | // Make an encoded packet (string) from a ProbePacket object. |
| 31 | std::string MakeEncodedPacket(const ProbePacket& packet) const; |
| 32 | // Fill some common fields in the packet header. |
| 33 | void SetPacketHeader(ProbePacket_Type packet_type, |
| 34 | ProbePacket* probe_packet) const; |
| 35 | // Parse the input string (which is an encoded packet) and save the result to |
| 36 | // packet. Return true if there is no error and false otherwise. |
| 37 | bool ParseInput(const std::string& input, ProbePacket* packet) const; |
| 38 | |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 39 | static const uint32_t kMaxProbePacketBytes; |
[email protected] | a94b0d7 | 2013-11-18 05:04:44 | [diff] [blame] | 40 | |
[email protected] | 5668158 | 2013-07-28 20:08:44 | [diff] [blame] | 41 | private: |
| 42 | // For unittest. |
| 43 | friend class ProbeMessageTest; |
| 44 | FRIEND_TEST_ALL_PREFIXES(ProbeMessageTest, TestChecksum); |
| 45 | FRIEND_TEST_ALL_PREFIXES(ProbeMessageTest, TestEncode); |
| 46 | FRIEND_TEST_ALL_PREFIXES(ProbeMessageTest, TestGenerateProbeRequest); |
| 47 | FRIEND_TEST_ALL_PREFIXES(ProbeMessageTest, TestSetPacketHeader); |
| 48 | |
| 49 | // Compute the checksum of the padding string. |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 50 | uint32_t Checksum(const std::string& str) const; |
[email protected] | 5668158 | 2013-07-28 20:08:44 | [diff] [blame] | 51 | |
| 52 | // Encode the packet with kEncodingString. This is also used for decoding. |
| 53 | std::string Encode(const std::string& input) const; |
| 54 | |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 55 | static const uint32_t kVersion; |
| 56 | static const uint32_t kMaxNumberProbePackets; |
| 57 | static const uint32_t kMaxPacingIntervalMicros; |
[email protected] | 5668158 | 2013-07-28 20:08:44 | [diff] [blame] | 58 | static const char kEncodingString[]; |
| 59 | |
| 60 | DISALLOW_COPY_AND_ASSIGN(ProbeMessage); |
| 61 | }; |
| 62 | } // namespace chrome_browser_net |
| 63 | #endif // CHROME_BROWSER_NET_PROBE_MESSAGE_H_ |