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

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

Issue 2229553003: Deprecate --quic_socket_walltimestamps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@128998762
Patch Set: Created 4 years, 4 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/quic/core/quic_sent_packet_manager.cc ('k') | net/tools/quic/quic_socket_utils.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_packet_reader.h" 5 #include "net/tools/quic/quic_packet_reader.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #ifndef __APPLE__ 8 #ifndef __APPLE__
9 // This is a GNU header that is not present in /usr/include on MacOS 9 // This is a GNU header that is not present in /usr/include on MacOS
10 #include <features.h> 10 #include <features.h>
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 hdr->msg_controllen = QuicSocketUtils::kSpaceForCmsg; 91 hdr->msg_controllen = QuicSocketUtils::kSpaceForCmsg;
92 } 92 }
93 93
94 int packets_read = 94 int packets_read =
95 recvmmsg(fd, mmsg_hdr_, kNumPacketsPerReadMmsgCall, 0, nullptr); 95 recvmmsg(fd, mmsg_hdr_, kNumPacketsPerReadMmsgCall, 0, nullptr);
96 96
97 if (packets_read <= 0) { 97 if (packets_read <= 0) {
98 return false; // recvmmsg failed. 98 return false; // recvmmsg failed.
99 } 99 }
100 100
101 QuicTime fallback_timestamp = QuicTime::Zero();
102 QuicWallTime fallback_walltimestamp = QuicWallTime::Zero(); 101 QuicWallTime fallback_walltimestamp = QuicWallTime::Zero();
103 for (int i = 0; i < packets_read; ++i) { 102 for (int i = 0; i < packets_read; ++i) {
104 if (mmsg_hdr_[i].msg_len == 0) { 103 if (mmsg_hdr_[i].msg_len == 0) {
105 continue; 104 continue;
106 } 105 }
107 106
108 if (mmsg_hdr_[i].msg_hdr.msg_controllen >= QuicSocketUtils::kSpaceForCmsg) { 107 if (mmsg_hdr_[i].msg_hdr.msg_controllen >= QuicSocketUtils::kSpaceForCmsg) {
109 QUIC_BUG << "Incorrectly set control length: " 108 QUIC_BUG << "Incorrectly set control length: "
110 << mmsg_hdr_[i].msg_hdr.msg_controllen << ", expected " 109 << mmsg_hdr_[i].msg_hdr.msg_controllen << ", expected "
111 << QuicSocketUtils::kSpaceForCmsg; 110 << QuicSocketUtils::kSpaceForCmsg;
112 continue; 111 continue;
113 } 112 }
114 113
115 IPEndPoint client_address = IPEndPoint(packets_[i].raw_address); 114 IPEndPoint client_address = IPEndPoint(packets_[i].raw_address);
116 IPAddress server_ip; 115 IPAddress server_ip;
117 QuicTime packet_timestamp = QuicTime::Zero();
118 QuicWallTime packet_walltimestamp = QuicWallTime::Zero(); 116 QuicWallTime packet_walltimestamp = QuicWallTime::Zero();
119 bool latched_walltimestamps = FLAGS_quic_socket_walltimestamps;
120 QuicSocketUtils::GetAddressAndTimestampFromMsghdr( 117 QuicSocketUtils::GetAddressAndTimestampFromMsghdr(
121 &mmsg_hdr_[i].msg_hdr, &server_ip, &packet_timestamp, 118 &mmsg_hdr_[i].msg_hdr, &server_ip, &packet_walltimestamp);
122 &packet_walltimestamp, latched_walltimestamps);
123 if (!IsInitializedAddress(server_ip)) { 119 if (!IsInitializedAddress(server_ip)) {
124 QUIC_BUG << "Unable to get server address."; 120 QUIC_BUG << "Unable to get server address.";
125 continue; 121 continue;
126 } 122 }
127 123
128 // This isn't particularly desirable, but not all platforms support socket 124 // This isn't particularly desirable, but not all platforms support socket
129 // timestamping. 125 // timestamping.
130 if (latched_walltimestamps) { 126 if (packet_walltimestamp.IsZero()) {
131 if (packet_walltimestamp.IsZero()) { 127 if (fallback_walltimestamp.IsZero()) {
132 if (fallback_walltimestamp.IsZero()) { 128 fallback_walltimestamp = clock.WallNow();
133 fallback_walltimestamp = clock.WallNow();
134 }
135 packet_walltimestamp = fallback_walltimestamp;
136 } 129 }
137 packet_timestamp = clock.ConvertWallTimeToQuicTime(packet_walltimestamp); 130 packet_walltimestamp = fallback_walltimestamp;
138 } else {
139 if (packet_timestamp == QuicTime::Zero()) {
140 if (fallback_timestamp == QuicTime::Zero()) {
141 fallback_timestamp = clock.Now();
142 }
143 packet_timestamp = fallback_timestamp;
144 }
145 } 131 }
132 QuicTime timestamp = clock.ConvertWallTimeToQuicTime(packet_walltimestamp);
146 QuicReceivedPacket packet(reinterpret_cast<char*>(packets_[i].iov.iov_base), 133 QuicReceivedPacket packet(reinterpret_cast<char*>(packets_[i].iov.iov_base),
147 mmsg_hdr_[i].msg_len, packet_timestamp, false); 134 mmsg_hdr_[i].msg_len, timestamp, false);
148 IPEndPoint server_address(server_ip, port); 135 IPEndPoint server_address(server_ip, port);
149 processor->ProcessPacket(server_address, client_address, packet); 136 processor->ProcessPacket(server_address, client_address, packet);
150 } 137 }
151 138
152 if (packets_dropped != nullptr) { 139 if (packets_dropped != nullptr) {
153 QuicSocketUtils::GetOverflowFromMsghdr(&mmsg_hdr_[0].msg_hdr, 140 QuicSocketUtils::GetOverflowFromMsghdr(&mmsg_hdr_[0].msg_hdr,
154 packets_dropped); 141 packets_dropped);
155 } 142 }
156 143
157 // We may not have read all of the packets available on the socket. 144 // We may not have read all of the packets available on the socket.
158 return packets_read == kNumPacketsPerReadMmsgCall; 145 return packets_read == kNumPacketsPerReadMmsgCall;
159 #else 146 #else
160 LOG(FATAL) << "Unsupported"; 147 LOG(FATAL) << "Unsupported";
161 return false; 148 return false;
162 #endif 149 #endif
163 } 150 }
164 151
165 /* static */ 152 /* static */
166 bool QuicPacketReader::ReadAndDispatchSinglePacket( 153 bool QuicPacketReader::ReadAndDispatchSinglePacket(
167 int fd, 154 int fd,
168 int port, 155 int port,
169 const QuicClock& clock, 156 const QuicClock& clock,
170 ProcessPacketInterface* processor, 157 ProcessPacketInterface* processor,
171 QuicPacketCount* packets_dropped) { 158 QuicPacketCount* packets_dropped) {
172 bool latched_walltimestamps = FLAGS_quic_socket_walltimestamps;
173 char buf[kMaxPacketSize]; 159 char buf[kMaxPacketSize];
174 160
175 IPEndPoint client_address; 161 IPEndPoint client_address;
176 IPAddress server_ip; 162 IPAddress server_ip;
177 QuicTime timestamp = QuicTime::Zero();
178 QuicWallTime walltimestamp = QuicWallTime::Zero(); 163 QuicWallTime walltimestamp = QuicWallTime::Zero();
179 int bytes_read = QuicSocketUtils::ReadPacket( 164 int bytes_read =
180 fd, buf, arraysize(buf), packets_dropped, &server_ip, &timestamp, 165 QuicSocketUtils::ReadPacket(fd, buf, arraysize(buf), packets_dropped,
181 &walltimestamp, latched_walltimestamps, &client_address); 166 &server_ip, &walltimestamp, &client_address);
182
183 if (bytes_read < 0) { 167 if (bytes_read < 0) {
184 return false; // ReadPacket failed. 168 return false; // ReadPacket failed.
185 } 169 }
186 170
187 if (server_ip.empty()) { 171 if (server_ip.empty()) {
188 QUIC_BUG << "Unable to get server address."; 172 QUIC_BUG << "Unable to get server address.";
189 return false; 173 return false;
190 } 174 }
191 // This isn't particularly desirable, but not all platforms support socket 175 // This isn't particularly desirable, but not all platforms support socket
192 // timestamping. 176 // timestamping.
193 if (latched_walltimestamps) { 177 if (walltimestamp.IsZero()) {
194 if (walltimestamp.IsZero()) { 178 walltimestamp = clock.WallNow();
195 walltimestamp = clock.WallNow();
196 }
197 timestamp = clock.ConvertWallTimeToQuicTime(walltimestamp);
198 } else {
199 if (timestamp == QuicTime::Zero()) {
200 timestamp = clock.Now();
201 }
202 } 179 }
180 QuicTime timestamp = clock.ConvertWallTimeToQuicTime(walltimestamp);
203 181
204 QuicReceivedPacket packet(buf, bytes_read, timestamp, false); 182 QuicReceivedPacket packet(buf, bytes_read, timestamp, false);
205 IPEndPoint server_address(server_ip, port); 183 IPEndPoint server_address(server_ip, port);
206 processor->ProcessPacket(server_address, client_address, packet); 184 processor->ProcessPacket(server_address, client_address, packet);
207 185
208 // The socket read was successful, so return true even if packet dispatch 186 // The socket read was successful, so return true even if packet dispatch
209 // failed. 187 // failed.
210 return true; 188 return true;
211 } 189 }
212 190
213 191
214 } // namespace net 192 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_sent_packet_manager.cc ('k') | net/tools/quic/quic_socket_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698