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

Side by Side Diff: net/quic/crypto/crypto_framer.cc

Issue 147763009: Add the client address to the Public Reset packet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Remove crypto_handshake_message.* from the CL; they were committed separately Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/crypto/crypto_framer.h ('k') | net/quic/crypto/crypto_handshake.h » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "net/quic/crypto/crypto_framer.h" 5 #include "net/quic/crypto/crypto_framer.h"
6 6
7 #include "net/quic/crypto/crypto_handshake.h" 7 #include "net/quic/crypto/crypto_protocol.h"
8 #include "net/quic/quic_data_reader.h" 8 #include "net/quic/quic_data_reader.h"
9 #include "net/quic/quic_data_writer.h" 9 #include "net/quic/quic_data_writer.h"
10 10
11 using base::StringPiece; 11 using base::StringPiece;
12 using std::make_pair; 12 using std::make_pair;
13 using std::pair; 13 using std::pair;
14 using std::vector; 14 using std::vector;
15 15
16 namespace net { 16 namespace net {
17 17
18 namespace { 18 namespace {
19 19
20 const size_t kQuicTagSize = sizeof(uint32); 20 const size_t kQuicTagSize = sizeof(uint32);
21 const size_t kCryptoEndOffsetSize = sizeof(uint32); 21 const size_t kCryptoEndOffsetSize = sizeof(uint32);
22 const size_t kNumEntriesSize = sizeof(uint16); 22 const size_t kNumEntriesSize = sizeof(uint16);
23 23
24 // OneShotVisitor is a framer visitor that records a single handshake message. 24 // OneShotVisitor is a framer visitor that records a single handshake message.
25 class OneShotVisitor : public CryptoFramerVisitorInterface { 25 class OneShotVisitor : public CryptoFramerVisitorInterface {
26 public: 26 public:
27 explicit OneShotVisitor(CryptoHandshakeMessage* out) 27 explicit OneShotVisitor(CryptoHandshakeMessage* out)
28 : out_(out), 28 : out_(out),
29 error_(false) { 29 error_(false),
30 done_(false) {
30 } 31 }
31 32
32 virtual void OnError(CryptoFramer* framer) OVERRIDE { error_ = true; } 33 virtual void OnError(CryptoFramer* framer) OVERRIDE { error_ = true; }
33 34
34 virtual void OnHandshakeMessage( 35 virtual void OnHandshakeMessage(
35 const CryptoHandshakeMessage& message) OVERRIDE { 36 const CryptoHandshakeMessage& message) OVERRIDE {
36 *out_ = message; 37 *out_ = message;
38 done_ = true;
37 } 39 }
38 40
39 bool error() const { return error_; } 41 bool error() const { return error_; }
40 42
43 bool done() const { return done_; }
44
41 private: 45 private:
42 CryptoHandshakeMessage* const out_; 46 CryptoHandshakeMessage* const out_;
43 bool error_; 47 bool error_;
48 bool done_;
44 }; 49 };
45 50
46 } // namespace 51 } // namespace
47 52
48 CryptoFramer::CryptoFramer() 53 CryptoFramer::CryptoFramer()
49 : visitor_(NULL), 54 : visitor_(NULL),
50 num_entries_(0), 55 num_entries_(0),
51 values_len_(0) { 56 values_len_(0) {
52 Clear(); 57 Clear();
53 } 58 }
54 59
55 CryptoFramer::~CryptoFramer() {} 60 CryptoFramer::~CryptoFramer() {}
56 61
57 // static 62 // static
58 CryptoHandshakeMessage* CryptoFramer::ParseMessage(StringPiece in) { 63 CryptoHandshakeMessage* CryptoFramer::ParseMessage(StringPiece in) {
59 scoped_ptr<CryptoHandshakeMessage> msg(new CryptoHandshakeMessage); 64 scoped_ptr<CryptoHandshakeMessage> msg(new CryptoHandshakeMessage);
60 OneShotVisitor visitor(msg.get()); 65 OneShotVisitor visitor(msg.get());
61 CryptoFramer framer; 66 CryptoFramer framer;
62 67
63 framer.set_visitor(&visitor); 68 framer.set_visitor(&visitor);
64 if (!framer.ProcessInput(in) || visitor.error() || 69 if (!framer.ProcessInput(in) || visitor.error() || !visitor.done() ||
65 framer.InputBytesRemaining()) { 70 framer.InputBytesRemaining()) {
66 return NULL; 71 return NULL;
67 } 72 }
68 73
69 return msg.release(); 74 return msg.release();
70 } 75 }
71 76
72 bool CryptoFramer::ProcessInput(StringPiece input) { 77 bool CryptoFramer::ProcessInput(StringPiece input) {
73 DCHECK_EQ(QUIC_NO_ERROR, error_); 78 DCHECK_EQ(QUIC_NO_ERROR, error_);
74 if (error_ != QUIC_NO_ERROR) { 79 if (error_ != QUIC_NO_ERROR) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 } 288 }
284 *end_offset += pad_length; 289 *end_offset += pad_length;
285 if (!writer->WriteUInt32(*end_offset)) { 290 if (!writer->WriteUInt32(*end_offset)) {
286 DCHECK(false) << "Failed to write end offset."; 291 DCHECK(false) << "Failed to write end offset.";
287 return false; 292 return false;
288 } 293 }
289 return true; 294 return true;
290 } 295 }
291 296
292 } // namespace net 297 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/crypto_framer.h ('k') | net/quic/crypto/crypto_handshake.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698