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

Side by Side Diff: webrtc/base/natserver.cc

Issue 2620303003: Replace ASSERT by RTC_DCHECK in all non-test code. (Closed)
Patch Set: Address final nits. Created 3 years, 11 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 | « webrtc/base/messagequeue.cc ('k') | webrtc/base/natsocketfactory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <memory> 11 #include <memory>
12 12
13 #include "webrtc/base/checks.h"
13 #include "webrtc/base/natsocketfactory.h" 14 #include "webrtc/base/natsocketfactory.h"
14 #include "webrtc/base/natserver.h" 15 #include "webrtc/base/natserver.h"
15 #include "webrtc/base/logging.h" 16 #include "webrtc/base/logging.h"
16 #include "webrtc/base/socketadapters.h" 17 #include "webrtc/base/socketadapters.h"
17 18
18 namespace rtc { 19 namespace rtc {
19 20
20 RouteCmp::RouteCmp(NAT* nat) : symmetric(nat->IsSymmetric()) { 21 RouteCmp::RouteCmp(NAT* nat) : symmetric(nat->IsSymmetric()) {
21 } 22 }
22 23
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 BufferedReadAdapter::DirectSend(&code, sizeof(char)); 81 BufferedReadAdapter::DirectSend(&code, sizeof(char));
81 } 82 }
82 83
83 protected: 84 protected:
84 void ProcessInput(char* data, size_t* len) override { 85 void ProcessInput(char* data, size_t* len) override {
85 if (*len < 2) { 86 if (*len < 2) {
86 return; 87 return;
87 } 88 }
88 89
89 int family = data[1]; 90 int family = data[1];
90 ASSERT(family == AF_INET || family == AF_INET6); 91 RTC_DCHECK(family == AF_INET || family == AF_INET6);
91 if ((family == AF_INET && *len < kNATEncodedIPv4AddressSize) || 92 if ((family == AF_INET && *len < kNATEncodedIPv4AddressSize) ||
92 (family == AF_INET6 && *len < kNATEncodedIPv6AddressSize)) { 93 (family == AF_INET6 && *len < kNATEncodedIPv6AddressSize)) {
93 return; 94 return;
94 } 95 }
95 96
96 SocketAddress dest_addr; 97 SocketAddress dest_addr;
97 size_t address_length = UnpackAddressFromNAT(data, *len, &dest_addr); 98 size_t address_length = UnpackAddressFromNAT(data, *len, &dest_addr);
98 99
99 *len -= address_length; 100 *len -= address_length;
100 if (*len > 0) { 101 if (*len > 0) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 SocketAddress dest_addr; 163 SocketAddress dest_addr;
163 size_t length = UnpackAddressFromNAT(buf, size, &dest_addr); 164 size_t length = UnpackAddressFromNAT(buf, size, &dest_addr);
164 165
165 // Find the translation for these addresses (allocating one if necessary). 166 // Find the translation for these addresses (allocating one if necessary).
166 SocketAddressPair route(addr, dest_addr); 167 SocketAddressPair route(addr, dest_addr);
167 InternalMap::iterator iter = int_map_->find(route); 168 InternalMap::iterator iter = int_map_->find(route);
168 if (iter == int_map_->end()) { 169 if (iter == int_map_->end()) {
169 Translate(route); 170 Translate(route);
170 iter = int_map_->find(route); 171 iter = int_map_->find(route);
171 } 172 }
172 ASSERT(iter != int_map_->end()); 173 RTC_DCHECK(iter != int_map_->end());
173 174
174 // Allow the destination to send packets back to the source. 175 // Allow the destination to send packets back to the source.
175 iter->second->WhitelistInsert(dest_addr); 176 iter->second->WhitelistInsert(dest_addr);
176 177
177 // Send the packet to its intended destination. 178 // Send the packet to its intended destination.
178 rtc::PacketOptions options; 179 rtc::PacketOptions options;
179 iter->second->socket->SendTo(buf + length, size - length, dest_addr, options); 180 iter->second->socket->SendTo(buf + length, size - length, dest_addr, options);
180 } 181 }
181 182
182 void NATServer::OnExternalUDPPacket( 183 void NATServer::OnExternalUDPPacket(
183 AsyncPacketSocket* socket, const char* buf, size_t size, 184 AsyncPacketSocket* socket, const char* buf, size_t size,
184 const SocketAddress& remote_addr, const PacketTime& packet_time) { 185 const SocketAddress& remote_addr, const PacketTime& packet_time) {
185 SocketAddress local_addr = socket->GetLocalAddress(); 186 SocketAddress local_addr = socket->GetLocalAddress();
186 187
187 // Find the translation for this addresses. 188 // Find the translation for this addresses.
188 ExternalMap::iterator iter = ext_map_->find(local_addr); 189 ExternalMap::iterator iter = ext_map_->find(local_addr);
189 ASSERT(iter != ext_map_->end()); 190 RTC_DCHECK(iter != ext_map_->end());
190 191
191 // Allow the NAT to reject this packet. 192 // Allow the NAT to reject this packet.
192 if (ShouldFilterOut(iter->second, remote_addr)) { 193 if (ShouldFilterOut(iter->second, remote_addr)) {
193 LOG(LS_INFO) << "Packet from " << remote_addr.ToSensitiveString() 194 LOG(LS_INFO) << "Packet from " << remote_addr.ToSensitiveString()
194 << " was filtered out by the NAT."; 195 << " was filtered out by the NAT.";
195 return; 196 return;
196 } 197 }
197 198
198 // Forward this packet to the internal address. 199 // Forward this packet to the internal address.
199 // First prepend the address in a quasi-STUN format. 200 // First prepend the address in a quasi-STUN format.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 CritScope cs(&crit_); 243 CritScope cs(&crit_);
243 whitelist->insert(addr); 244 whitelist->insert(addr);
244 } 245 }
245 246
246 bool NATServer::TransEntry::WhitelistContains(const SocketAddress& ext_addr) { 247 bool NATServer::TransEntry::WhitelistContains(const SocketAddress& ext_addr) {
247 CritScope cs(&crit_); 248 CritScope cs(&crit_);
248 return whitelist->find(ext_addr) == whitelist->end(); 249 return whitelist->find(ext_addr) == whitelist->end();
249 } 250 }
250 251
251 } // namespace rtc 252 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/messagequeue.cc ('k') | webrtc/base/natsocketfactory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698