OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 402 } |
403 | 403 |
404 LOG(LS_INFO) << "TurnPort connected to " << socket->GetRemoteAddress() | 404 LOG(LS_INFO) << "TurnPort connected to " << socket->GetRemoteAddress() |
405 << " using tcp."; | 405 << " using tcp."; |
406 SendRequest(new TurnAllocateRequest(this), 0); | 406 SendRequest(new TurnAllocateRequest(this), 0); |
407 } | 407 } |
408 | 408 |
409 void TurnPort::OnSocketClose(rtc::AsyncPacketSocket* socket, int error) { | 409 void TurnPort::OnSocketClose(rtc::AsyncPacketSocket* socket, int error) { |
410 LOG_J(LS_WARNING, this) << "Connection with server failed, error=" << error; | 410 LOG_J(LS_WARNING, this) << "Connection with server failed, error=" << error; |
411 ASSERT(socket == socket_); | 411 ASSERT(socket == socket_); |
412 if (!ready()) { | 412 Close(); |
413 OnAllocateError(); | |
414 } | |
415 request_manager_.Clear(); | |
416 state_ = STATE_DISCONNECTED; | |
417 } | 413 } |
418 | 414 |
419 void TurnPort::OnAllocateMismatch() { | 415 void TurnPort::OnAllocateMismatch() { |
420 if (allocate_mismatch_retries_ >= MAX_ALLOCATE_MISMATCH_RETRIES) { | 416 if (allocate_mismatch_retries_ >= MAX_ALLOCATE_MISMATCH_RETRIES) { |
421 LOG_J(LS_WARNING, this) << "Giving up on the port after " | 417 LOG_J(LS_WARNING, this) << "Giving up on the port after " |
422 << allocate_mismatch_retries_ | 418 << allocate_mismatch_retries_ |
423 << " retries for STUN_ERROR_ALLOCATION_MISMATCH"; | 419 << " retries for STUN_ERROR_ALLOCATION_MISMATCH"; |
424 OnAllocateError(); | 420 OnAllocateError(); |
425 return; | 421 return; |
426 } | 422 } |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 server_priority_, true); | 706 server_priority_, true); |
711 } | 707 } |
712 | 708 |
713 void TurnPort::OnAllocateError() { | 709 void TurnPort::OnAllocateError() { |
714 // We will send SignalPortError asynchronously as this can be sent during | 710 // We will send SignalPortError asynchronously as this can be sent during |
715 // port initialization. This way it will not be blocking other port | 711 // port initialization. This way it will not be blocking other port |
716 // creation. | 712 // creation. |
717 thread()->Post(this, MSG_ALLOCATE_ERROR); | 713 thread()->Post(this, MSG_ALLOCATE_ERROR); |
718 } | 714 } |
719 | 715 |
| 716 void TurnPort::OnTurnRefreshError() { |
| 717 // Need to Close the port asynchronously because otherwise, the refresh |
| 718 // request may be deleted twice: once at the end of the message processing |
| 719 // and the other in Close(). |
| 720 thread()->Post(this, MSG_REFRESH_ERROR); |
| 721 } |
| 722 |
720 void TurnPort::Close() { | 723 void TurnPort::Close() { |
| 724 if (!ready()) { |
| 725 OnAllocateError(); |
| 726 } |
| 727 request_manager_.Clear(); |
721 // Stop the port from creating new connections. | 728 // Stop the port from creating new connections. |
722 state_ = STATE_DISCONNECTED; | 729 state_ = STATE_DISCONNECTED; |
723 // Delete all existing connections; stop sending data. | 730 // Delete all existing connections; stop sending data. |
724 for (auto kv : connections()) { | 731 for (auto kv : connections()) { |
725 kv.second->Destroy(); | 732 kv.second->Destroy(); |
726 } | 733 } |
727 } | 734 } |
728 | 735 |
729 void TurnPort::OnMessage(rtc::Message* message) { | 736 void TurnPort::OnMessage(rtc::Message* message) { |
730 switch (message->message_id) { | 737 switch (message->message_id) { |
731 case MSG_ALLOCATE_ERROR: | 738 case MSG_ALLOCATE_ERROR: |
732 SignalPortError(this); | 739 SignalPortError(this); |
733 break; | 740 break; |
734 case MSG_ALLOCATE_MISMATCH: | 741 case MSG_ALLOCATE_MISMATCH: |
735 OnAllocateMismatch(); | 742 OnAllocateMismatch(); |
736 break; | 743 break; |
| 744 case MSG_REFRESH_ERROR: |
| 745 Close(); |
| 746 break; |
737 case MSG_TRY_ALTERNATE_SERVER: | 747 case MSG_TRY_ALTERNATE_SERVER: |
738 if (server_address().proto == PROTO_UDP) { | 748 if (server_address().proto == PROTO_UDP) { |
739 // Send another allocate request to alternate server, with the received | 749 // Send another allocate request to alternate server, with the received |
740 // realm and nonce values. | 750 // realm and nonce values. |
741 SendRequest(new TurnAllocateRequest(this), 0); | 751 SendRequest(new TurnAllocateRequest(this), 0); |
742 } else { | 752 } else { |
743 // Since it's TCP, we have to delete the connected socket and reconnect | 753 // Since it's TCP, we have to delete the connected socket and reconnect |
744 // with the alternate server. PrepareAddress will send stun binding once | 754 // with the alternate server. PrepareAddress will send stun binding once |
745 // the new socket is connected. | 755 // the new socket is connected. |
746 ASSERT(server_address().proto == PROTO_TCP); | 756 ASSERT(server_address().proto == PROTO_TCP); |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1483 } else { | 1493 } else { |
1484 state_ = STATE_UNBOUND; | 1494 state_ = STATE_UNBOUND; |
1485 port_->DestroyConnection(ext_addr_); | 1495 port_->DestroyConnection(ext_addr_); |
1486 } | 1496 } |
1487 } | 1497 } |
1488 void TurnEntry::OnChannelBindTimeout() { | 1498 void TurnEntry::OnChannelBindTimeout() { |
1489 state_ = STATE_UNBOUND; | 1499 state_ = STATE_UNBOUND; |
1490 port_->DestroyConnection(ext_addr_); | 1500 port_->DestroyConnection(ext_addr_); |
1491 } | 1501 } |
1492 } // namespace cricket | 1502 } // namespace cricket |
OLD | NEW |