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

Side by Side Diff: net/tools/quic/quic_client.cc

Issue 1760423002: n/a (QUIC toy client/server) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@115456160
Patch Set: Update dependency Created 4 years, 9 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
« no previous file with comments | « net/tools/quic/quic_client.h ('k') | net/tools/quic/quic_client_base.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/tools/quic/quic_client.h" 5 #include "net/tools/quic/quic_client.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <netinet/in.h> 8 #include <netinet/in.h>
9 #include <string.h> 9 #include <string.h>
10 #include <sys/epoll.h> 10 #include <sys/epoll.h>
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 supported_versions, 67 supported_versions,
68 config, 68 config,
69 new QuicEpollConnectionHelper(epoll_server), 69 new QuicEpollConnectionHelper(epoll_server),
70 proof_verifier), 70 proof_verifier),
71 server_address_(server_address), 71 server_address_(server_address),
72 local_port_(0), 72 local_port_(0),
73 epoll_server_(epoll_server), 73 epoll_server_(epoll_server),
74 initialized_(false), 74 initialized_(false),
75 packets_dropped_(0), 75 packets_dropped_(0),
76 overflow_supported_(false), 76 overflow_supported_(false),
77 use_recvmmsg_(false),
77 store_response_(false), 78 store_response_(false),
78 latest_response_code_(-1), 79 latest_response_code_(-1),
79 packet_reader_(CreateQuicPacketReader()) {} 80 packet_reader_(CreateQuicPacketReader()) {}
80 81
81 QuicClient::~QuicClient() { 82 QuicClient::~QuicClient() {
82 if (connected()) { 83 if (connected()) {
83 session()->connection()->SendConnectionCloseWithDetails( 84 session()->connection()->SendConnectionCloseWithDetails(
84 QUIC_PEER_GOING_AWAY, "Client being torn down"); 85 QUIC_PEER_GOING_AWAY, "Client being torn down");
85 } 86 }
86 87
87 STLDeleteElements(&data_to_resend_on_connect_); 88 STLDeleteElements(&data_to_resend_on_connect_);
88 STLDeleteElements(&data_sent_before_handshake_); 89 STLDeleteElements(&data_sent_before_handshake_);
89 90
90 CleanUpAllUDPSockets(); 91 CleanUpAllUDPSockets();
91 } 92 }
92 93
93 bool QuicClient::Initialize() { 94 bool QuicClient::Initialize() {
94 QuicClientBase::Initialize(); 95 QuicClientBase::Initialize();
95 96
97 #if MMSG_MORE
98 use_recvmmsg_ = true;
99 #endif
100
101 set_num_sent_client_hellos(0);
102 set_num_stateless_rejects_received(0);
103 set_connection_error(QUIC_NO_ERROR);
104
96 // If an initial flow control window has not explicitly been set, then use the 105 // If an initial flow control window has not explicitly been set, then use the
97 // same values that Chrome uses. 106 // same values that Chrome uses.
98 const uint32_t kSessionMaxRecvWindowSize = 15 * 1024 * 1024; // 15 MB 107 const uint32_t kSessionMaxRecvWindowSize = 15 * 1024 * 1024; // 15 MB
99 const uint32_t kStreamMaxRecvWindowSize = 6 * 1024 * 1024; // 6 MB 108 const uint32_t kStreamMaxRecvWindowSize = 6 * 1024 * 1024; // 6 MB
100 if (config()->GetInitialStreamFlowControlWindowToSend() == 109 if (config()->GetInitialStreamFlowControlWindowToSend() ==
101 kMinimumFlowControlSendWindow) { 110 kMinimumFlowControlSendWindow) {
102 config()->SetInitialStreamFlowControlWindowToSend(kStreamMaxRecvWindowSize); 111 config()->SetInitialStreamFlowControlWindowToSend(kStreamMaxRecvWindowSize);
103 } 112 }
104 if (config()->GetInitialSessionFlowControlWindowToSend() == 113 if (config()->GetInitialSessionFlowControlWindowToSend() ==
105 kMinimumFlowControlSendWindow) { 114 kMinimumFlowControlSendWindow) {
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 set_writer(writer); 387 set_writer(writer);
379 session()->connection()->SetQuicPacketWriter(writer, false); 388 session()->connection()->SetQuicPacketWriter(writer, false);
380 389
381 return true; 390 return true;
382 } 391 }
383 392
384 void QuicClient::OnEvent(int fd, EpollEvent* event) { 393 void QuicClient::OnEvent(int fd, EpollEvent* event) {
385 DCHECK_EQ(fd, GetLatestFD()); 394 DCHECK_EQ(fd, GetLatestFD());
386 395
387 if (event->in_events & EPOLLIN) { 396 if (event->in_events & EPOLLIN) {
388 while (connected()) { 397 bool more_to_read = true;
389 if ( 398 while (connected() && more_to_read) {
390 #if MMSG_MORE 399 if (use_recvmmsg_) {
391 !ReadAndProcessPackets() 400 more_to_read = packet_reader_->ReadAndDispatchPackets(
392 #else 401 GetLatestFD(), QuicClient::GetLatestClientAddress().port(), this,
393 !ReadAndProcessPacket() 402 overflow_supported_ ? &packets_dropped_ : nullptr);
394 #endif 403 } else {
395 ) { 404 more_to_read = QuicPacketReader::ReadAndDispatchSinglePacket(
396 break; 405 GetLatestFD(), QuicClient::GetLatestClientAddress().port(), this,
406 overflow_supported_ ? &packets_dropped_ : nullptr);
397 } 407 }
398 } 408 }
399 } 409 }
400 if (connected() && (event->in_events & EPOLLOUT)) { 410 if (connected() && (event->in_events & EPOLLOUT)) {
401 writer()->SetWritable(); 411 writer()->SetWritable();
402 session()->connection()->OnCanWrite(); 412 session()->connection()->OnCanWrite();
403 } 413 }
404 if (event->in_events & EPOLLERR) { 414 if (event->in_events & EPOLLERR) {
405 DVLOG(1) << "Epollerr"; 415 DVLOG(1) << "Epollerr";
406 } 416 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 const string& QuicClient::latest_response_trailers() const { 473 const string& QuicClient::latest_response_trailers() const {
464 QUIC_BUG_IF(!store_response_) << "Response not stored!"; 474 QUIC_BUG_IF(!store_response_) << "Response not stored!";
465 return latest_response_trailers_; 475 return latest_response_trailers_;
466 } 476 }
467 477
468 QuicPacketWriter* QuicClient::CreateQuicPacketWriter() { 478 QuicPacketWriter* QuicClient::CreateQuicPacketWriter() {
469 return new QuicDefaultPacketWriter(GetLatestFD()); 479 return new QuicDefaultPacketWriter(GetLatestFD());
470 } 480 }
471 481
472 QuicPacketReader* QuicClient::CreateQuicPacketReader() { 482 QuicPacketReader* QuicClient::CreateQuicPacketReader() {
473 // TODO(rtenneti): Add support for QuicPacketReader. 483 return new QuicPacketReader();
474 // return new QuicPacketReader();
475 return nullptr;
476 } 484 }
477 485
478 bool QuicClient::ReadAndProcessPacket() {
479 // Allocate some extra space so we can send an error if the server goes over
480 // the limit.
481 char buf[2 * kMaxPacketSize];
482
483 IPEndPoint server_address;
484 IPAddress client_ip;
485
486 int bytes_read = QuicSocketUtils::ReadPacket(
487 GetLatestFD(), buf, arraysize(buf),
488 overflow_supported_ ? &packets_dropped_ : nullptr, &client_ip,
489 &server_address);
490
491 if (bytes_read < 0) {
492 return false;
493 }
494
495 QuicEncryptedPacket packet(buf, bytes_read, false);
496
497 IPEndPoint client_address(client_ip,
498 QuicClient::GetLatestClientAddress().port());
499
500 session()->ProcessUdpPacket(client_address, server_address, packet);
501 return true;
502 }
503
504 /*
505 bool QuicClient::ReadAndProcessPackets() {
506 return packet_reader_->ReadAndDispatchPackets(
507 GetLatestFD(), QuicClient::GetLatestClientAddress().port(), this,
508 overflow_supported_ ? &packets_dropped_ : nullptr);
509 }
510 */
511
512 const IPEndPoint QuicClient::GetLatestClientAddress() const { 486 const IPEndPoint QuicClient::GetLatestClientAddress() const {
513 if (fd_address_map_.empty()) { 487 if (fd_address_map_.empty()) {
514 return IPEndPoint(); 488 return IPEndPoint();
515 } 489 }
516 490
517 return fd_address_map_.back().second; 491 return fd_address_map_.back().second;
518 } 492 }
519 493
520 int QuicClient::GetLatestFD() const { 494 int QuicClient::GetLatestFD() const {
521 if (fd_address_map_.empty()) { 495 if (fd_address_map_.empty()) {
522 return -1; 496 return -1;
523 } 497 }
524 498
525 return fd_address_map_.back().first; 499 return fd_address_map_.back().first;
526 } 500 }
527 501
528 void QuicClient::ProcessPacket(const IPEndPoint& self_address, 502 void QuicClient::ProcessPacket(const IPEndPoint& self_address,
529 const IPEndPoint& peer_address, 503 const IPEndPoint& peer_address,
530 const QuicEncryptedPacket& packet) { 504 const QuicEncryptedPacket& packet) {
531 session()->connection()->ProcessUdpPacket(self_address, peer_address, packet); 505 session()->connection()->ProcessUdpPacket(self_address, peer_address, packet);
532 } 506 }
533 507
534 } // namespace net 508 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_client.h ('k') | net/tools/quic/quic_client_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698