summaryrefslogtreecommitdiffstats
path: root/net/quic/quic_packet_creator.h
diff options
context:
space:
mode:
authorrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-23 23:29:37 +0000
committerrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-23 23:29:37 +0000
commita5061244d407a27683b36e4d1ed35d895722805d (patch)
treec48806826561e5d26be8e9ac45012984c1a65ecf /net/quic/quic_packet_creator.h
parent46c39747bfa9048442e89f47b578df99001a9575 (diff)
downloadchromium_src-a5061244d407a27683b36e4d1ed35d895722805d.zip
chromium_src-a5061244d407a27683b36e4d1ed35d895722805d.tar.gz
chromium_src-a5061244d407a27683b36e4d1ed35d895722805d.tar.bz2
Add QuicPacketCreator and QuicFecGroup.
Review URL: https://chromiumcodereview.appspot.com/11238013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163724 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/quic/quic_packet_creator.h')
-rw-r--r--net/quic/quic_packet_creator.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/net/quic/quic_packet_creator.h b/net/quic/quic_packet_creator.h
new file mode 100644
index 0000000..2aa26b9
--- /dev/null
+++ b/net/quic/quic_packet_creator.h
@@ -0,0 +1,93 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// Some helpers for quic packet creation.
+
+#ifndef NET_QUIC_QUIC_PACKET_CREATOR_H_
+#define NET_QUIC_QUIC_PACKET_CREATOR_H_
+
+#include <utility>
+#include <vector>
+
+#include "base/string_piece.h"
+#include "net/quic/quic_fec_group.h"
+#include "net/quic/quic_framer.h"
+#include "net/quic/quic_protocol.h"
+
+namespace net {
+
+class NET_EXPORT_PRIVATE QuicPacketCreator : public QuicFecBuilderInterface {
+ public:
+ // Options for controlling how packets are created.
+ struct Options {
+ Options() {
+ Clear();
+ }
+ void Clear() {
+ memset(this, 0, sizeof(Options));
+ max_packet_length = kMaxPacketSize;
+ }
+
+ // TODO(alyssar, rch) max frames/packet
+ size_t max_packet_length;
+ bool separate_fin_packet;
+ bool random_reorder; // Inefficient: rewrite if used at scale.
+ // TODO(rch) should probably be max packets per group.
+ bool use_fec;
+ };
+
+ QuicPacketCreator(QuicGuid guid, QuicFramer* framer);
+
+ virtual ~QuicPacketCreator();
+
+ // QuicFecBuilderInterface
+ virtual void OnBuiltFecProtectedPayload(const QuicPacketHeader& header,
+ base::StringPiece payload) OVERRIDE;
+
+ typedef std::pair<QuicPacketSequenceNumber, QuicPacket*> PacketPair;
+
+ // Converts a raw payload to a series of QuicPackets.
+ void DataToStream(QuicStreamId id,
+ base::StringPiece data,
+ QuicStreamOffset offset,
+ bool fin,
+ std::vector<PacketPair>* packets);
+
+ PacketPair ResetStream(QuicStreamId id,
+ QuicStreamOffset offset,
+ QuicErrorCode error);
+
+ PacketPair CloseConnection(QuicConnectionCloseFrame* close_frame);
+
+ PacketPair AckPacket(QuicAckFrame* ack_frame);
+
+ QuicPacketSequenceNumber sequence_number() const {
+ return sequence_number_;
+ }
+
+ void set_sequence_number(QuicPacketSequenceNumber s) {
+ sequence_number_ = s;
+ }
+
+ Options* options() {
+ return &options_;
+ }
+
+ private:
+ void FillPacketHeader(QuicFecGroupNumber fec_group,
+ QuicPacketFlags flags,
+ QuicPacketHeader* header);
+
+ Options options_;
+ QuicGuid guid_;
+ QuicFramer* framer_;
+ QuicPacketSequenceNumber sequence_number_;
+ QuicFecGroupNumber fec_group_number_;
+ scoped_ptr<QuicFecGroup> fec_group_;
+
+};
+
+} // namespace net
+
+#endif // NET_QUIC_QUIC_PACKET_CREATOR_H_