blob: 6fa046666da9e838c164062546dcdd4434978e08 [file] [log] [blame]
[email protected]56681582013-07-28 20:08:441// 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
avi6846aef2015-12-26 01:09:388#include <stdint.h>
9
[email protected]56681582013-07-28 20:08:4410#include <string>
11
[email protected]56681582013-07-28 20:08:4412#include "base/gtest_prod_util.h"
avi6846aef2015-12-26 01:09:3813#include "base/macros.h"
[email protected]56681582013-07-28 20:08:4414#include "chrome/browser/net/probe_message.pb.h"
15
16namespace chrome_browser_net {
17
18// Packet format between client and server is defined in probe_message.proto.
19class ProbeMessage {
20 public:
21 ProbeMessage();
22
23 // Generate a ProbeRequest packet.
24 void GenerateProbeRequest(const ProbePacket_Token& received_token,
avi6846aef2015-12-26 01:09:3825 uint32_t group_id,
26 uint32_t probe_size,
27 uint32_t pacing_interval_micros,
28 uint32_t number_probe_packets,
[email protected]56681582013-07-28 20:08:4429 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
avi6846aef2015-12-26 01:09:3839 static const uint32_t kMaxProbePacketBytes;
[email protected]a94b0d72013-11-18 05:04:4440
[email protected]56681582013-07-28 20:08:4441 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.
avi6846aef2015-12-26 01:09:3850 uint32_t Checksum(const std::string& str) const;
[email protected]56681582013-07-28 20:08:4451
52 // Encode the packet with kEncodingString. This is also used for decoding.
53 std::string Encode(const std::string& input) const;
54
avi6846aef2015-12-26 01:09:3855 static const uint32_t kVersion;
56 static const uint32_t kMaxNumberProbePackets;
57 static const uint32_t kMaxPacingIntervalMicros;
[email protected]56681582013-07-28 20:08:4458 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_