| OLD | NEW |
| 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 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 error_(0), | 207 error_(0), |
| 208 ready_(false), | 208 ready_(false), |
| 209 stun_keepalive_delay_(KEEPALIVE_DELAY), | 209 stun_keepalive_delay_(KEEPALIVE_DELAY), |
| 210 emit_local_for_anyaddress_(emit_local_for_anyaddress) { | 210 emit_local_for_anyaddress_(emit_local_for_anyaddress) { |
| 211 requests_.set_origin(origin); | 211 requests_.set_origin(origin); |
| 212 } | 212 } |
| 213 | 213 |
| 214 bool UDPPort::Init() { | 214 bool UDPPort::Init() { |
| 215 stun_keepalive_lifetime_ = GetStunKeepaliveLifetime(); | 215 stun_keepalive_lifetime_ = GetStunKeepaliveLifetime(); |
| 216 if (!SharedSocket()) { | 216 if (!SharedSocket()) { |
| 217 ASSERT(socket_ == NULL); | 217 RTC_DCHECK(socket_ == NULL); |
| 218 socket_ = socket_factory()->CreateUdpSocket( | 218 socket_ = socket_factory()->CreateUdpSocket( |
| 219 rtc::SocketAddress(ip(), 0), min_port(), max_port()); | 219 rtc::SocketAddress(ip(), 0), min_port(), max_port()); |
| 220 if (!socket_) { | 220 if (!socket_) { |
| 221 LOG_J(LS_WARNING, this) << "UDP socket creation failed"; | 221 LOG_J(LS_WARNING, this) << "UDP socket creation failed"; |
| 222 return false; | 222 return false; |
| 223 } | 223 } |
| 224 socket_->SignalReadPacket.connect(this, &UDPPort::OnReadPacket); | 224 socket_->SignalReadPacket.connect(this, &UDPPort::OnReadPacket); |
| 225 } | 225 } |
| 226 socket_->SignalSentPacket.connect(this, &UDPPort::OnSentPacket); | 226 socket_->SignalSentPacket.connect(this, &UDPPort::OnSentPacket); |
| 227 socket_->SignalReadyToSend.connect(this, &UDPPort::OnReadyToSend); | 227 socket_->SignalReadyToSend.connect(this, &UDPPort::OnReadyToSend); |
| 228 socket_->SignalAddressReady.connect(this, &UDPPort::OnLocalAddressReady); | 228 socket_->SignalAddressReady.connect(this, &UDPPort::OnLocalAddressReady); |
| 229 requests_.SignalSendPacket.connect(this, &UDPPort::OnSendPacket); | 229 requests_.SignalSendPacket.connect(this, &UDPPort::OnSendPacket); |
| 230 return true; | 230 return true; |
| 231 } | 231 } |
| 232 | 232 |
| 233 UDPPort::~UDPPort() { | 233 UDPPort::~UDPPort() { |
| 234 if (!SharedSocket()) | 234 if (!SharedSocket()) |
| 235 delete socket_; | 235 delete socket_; |
| 236 } | 236 } |
| 237 | 237 |
| 238 void UDPPort::PrepareAddress() { | 238 void UDPPort::PrepareAddress() { |
| 239 ASSERT(requests_.empty()); | 239 RTC_DCHECK(requests_.empty()); |
| 240 if (socket_->GetState() == rtc::AsyncPacketSocket::STATE_BOUND) { | 240 if (socket_->GetState() == rtc::AsyncPacketSocket::STATE_BOUND) { |
| 241 OnLocalAddressReady(socket_, socket_->GetLocalAddress()); | 241 OnLocalAddressReady(socket_, socket_->GetLocalAddress()); |
| 242 } | 242 } |
| 243 } | 243 } |
| 244 | 244 |
| 245 void UDPPort::MaybePrepareStunCandidate() { | 245 void UDPPort::MaybePrepareStunCandidate() { |
| 246 // Sending binding request to the STUN server if address is available to | 246 // Sending binding request to the STUN server if address is available to |
| 247 // prepare STUN candidate. | 247 // prepare STUN candidate. |
| 248 if (!server_addresses_.empty()) { | 248 if (!server_addresses_.empty()) { |
| 249 SendStunBindingRequests(); | 249 SendStunBindingRequests(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 AddAddress(addr, addr, rtc::SocketAddress(), UDP_PROTOCOL_NAME, "", "", | 318 AddAddress(addr, addr, rtc::SocketAddress(), UDP_PROTOCOL_NAME, "", "", |
| 319 LOCAL_PORT_TYPE, ICE_TYPE_PREFERENCE_HOST, 0, false); | 319 LOCAL_PORT_TYPE, ICE_TYPE_PREFERENCE_HOST, 0, false); |
| 320 MaybePrepareStunCandidate(); | 320 MaybePrepareStunCandidate(); |
| 321 } | 321 } |
| 322 | 322 |
| 323 void UDPPort::OnReadPacket(rtc::AsyncPacketSocket* socket, | 323 void UDPPort::OnReadPacket(rtc::AsyncPacketSocket* socket, |
| 324 const char* data, | 324 const char* data, |
| 325 size_t size, | 325 size_t size, |
| 326 const rtc::SocketAddress& remote_addr, | 326 const rtc::SocketAddress& remote_addr, |
| 327 const rtc::PacketTime& packet_time) { | 327 const rtc::PacketTime& packet_time) { |
| 328 ASSERT(socket == socket_); | 328 RTC_DCHECK(socket == socket_); |
| 329 ASSERT(!remote_addr.IsUnresolvedIP()); | 329 RTC_DCHECK(!remote_addr.IsUnresolvedIP()); |
| 330 | 330 |
| 331 // Look for a response from the STUN server. | 331 // Look for a response from the STUN server. |
| 332 // Even if the response doesn't match one of our outstanding requests, we | 332 // Even if the response doesn't match one of our outstanding requests, we |
| 333 // will eat it because it might be a response to a retransmitted packet, and | 333 // will eat it because it might be a response to a retransmitted packet, and |
| 334 // we already cleared the request when we got the first response. | 334 // we already cleared the request when we got the first response. |
| 335 if (server_addresses_.find(remote_addr) != server_addresses_.end()) { | 335 if (server_addresses_.find(remote_addr) != server_addresses_.end()) { |
| 336 requests_.CheckResponse(data, size); | 336 requests_.CheckResponse(data, size); |
| 337 return; | 337 return; |
| 338 } | 338 } |
| 339 | 339 |
| 340 if (Connection* conn = GetConnection(remote_addr)) { | 340 if (Connection* conn = GetConnection(remote_addr)) { |
| 341 conn->OnReadPacket(data, size, packet_time); | 341 conn->OnReadPacket(data, size, packet_time); |
| 342 } else { | 342 } else { |
| 343 Port::OnReadPacket(data, size, remote_addr, PROTO_UDP); | 343 Port::OnReadPacket(data, size, remote_addr, PROTO_UDP); |
| 344 } | 344 } |
| 345 } | 345 } |
| 346 | 346 |
| 347 void UDPPort::OnSentPacket(rtc::AsyncPacketSocket* socket, | 347 void UDPPort::OnSentPacket(rtc::AsyncPacketSocket* socket, |
| 348 const rtc::SentPacket& sent_packet) { | 348 const rtc::SentPacket& sent_packet) { |
| 349 PortInterface::SignalSentPacket(sent_packet); | 349 PortInterface::SignalSentPacket(sent_packet); |
| 350 } | 350 } |
| 351 | 351 |
| 352 void UDPPort::OnReadyToSend(rtc::AsyncPacketSocket* socket) { | 352 void UDPPort::OnReadyToSend(rtc::AsyncPacketSocket* socket) { |
| 353 Port::OnReadyToSend(); | 353 Port::OnReadyToSend(); |
| 354 } | 354 } |
| 355 | 355 |
| 356 void UDPPort::SendStunBindingRequests() { | 356 void UDPPort::SendStunBindingRequests() { |
| 357 // We will keep pinging the stun server to make sure our NAT pin-hole stays | 357 // We will keep pinging the stun server to make sure our NAT pin-hole stays |
| 358 // open until the deadline (specified in SendStunBindingRequest). | 358 // open until the deadline (specified in SendStunBindingRequest). |
| 359 ASSERT(requests_.empty()); | 359 RTC_DCHECK(requests_.empty()); |
| 360 | 360 |
| 361 for (ServerAddresses::const_iterator it = server_addresses_.begin(); | 361 for (ServerAddresses::const_iterator it = server_addresses_.begin(); |
| 362 it != server_addresses_.end(); ++it) { | 362 it != server_addresses_.end(); ++it) { |
| 363 SendStunBindingRequest(*it); | 363 SendStunBindingRequest(*it); |
| 364 } | 364 } |
| 365 } | 365 } |
| 366 | 366 |
| 367 void UDPPort::ResolveStunAddress(const rtc::SocketAddress& stun_addr) { | 367 void UDPPort::ResolveStunAddress(const rtc::SocketAddress& stun_addr) { |
| 368 if (!resolver_) { | 368 if (!resolver_) { |
| 369 resolver_.reset(new AddressResolver(socket_factory())); | 369 resolver_.reset(new AddressResolver(socket_factory())); |
| 370 resolver_->SignalDone.connect(this, &UDPPort::OnResolveResult); | 370 resolver_->SignalDone.connect(this, &UDPPort::OnResolveResult); |
| 371 } | 371 } |
| 372 | 372 |
| 373 LOG_J(LS_INFO, this) << "Starting STUN host lookup for " | 373 LOG_J(LS_INFO, this) << "Starting STUN host lookup for " |
| 374 << stun_addr.ToSensitiveString(); | 374 << stun_addr.ToSensitiveString(); |
| 375 resolver_->Resolve(stun_addr); | 375 resolver_->Resolve(stun_addr); |
| 376 } | 376 } |
| 377 | 377 |
| 378 void UDPPort::OnResolveResult(const rtc::SocketAddress& input, | 378 void UDPPort::OnResolveResult(const rtc::SocketAddress& input, |
| 379 int error) { | 379 int error) { |
| 380 ASSERT(resolver_.get() != NULL); | 380 RTC_DCHECK(resolver_.get() != NULL); |
| 381 | 381 |
| 382 rtc::SocketAddress resolved; | 382 rtc::SocketAddress resolved; |
| 383 if (error != 0 || | 383 if (error != 0 || |
| 384 !resolver_->GetResolvedAddress(input, ip().family(), &resolved)) { | 384 !resolver_->GetResolvedAddress(input, ip().family(), &resolved)) { |
| 385 LOG_J(LS_WARNING, this) << "StunPort: stun host lookup received error " | 385 LOG_J(LS_WARNING, this) << "StunPort: stun host lookup received error " |
| 386 << error; | 386 << error; |
| 387 OnStunBindingOrResolveRequestFailed(input); | 387 OnStunBindingOrResolveRequestFailed(input); |
| 388 return; | 388 return; |
| 389 } | 389 } |
| 390 | 390 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 const std::vector<Candidate>& existing_candidates = Candidates(); | 508 const std::vector<Candidate>& existing_candidates = Candidates(); |
| 509 std::vector<Candidate>::const_iterator it = existing_candidates.begin(); | 509 std::vector<Candidate>::const_iterator it = existing_candidates.begin(); |
| 510 for (; it != existing_candidates.end(); ++it) { | 510 for (; it != existing_candidates.end(); ++it) { |
| 511 if (it->address() == addr) | 511 if (it->address() == addr) |
| 512 return true; | 512 return true; |
| 513 } | 513 } |
| 514 return false; | 514 return false; |
| 515 } | 515 } |
| 516 | 516 |
| 517 } // namespace cricket | 517 } // namespace cricket |
| OLD | NEW |