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 #include <algorithm> | 10 #include <algorithm> |
11 | 11 |
12 #include "webrtc/p2p/base/relayport.h" | 12 #include "webrtc/p2p/base/relayport.h" |
13 #include "webrtc/base/asyncpacketsocket.h" | 13 #include "webrtc/base/asyncpacketsocket.h" |
14 #include "webrtc/base/helpers.h" | 14 #include "webrtc/base/helpers.h" |
15 #include "webrtc/base/logging.h" | 15 #include "webrtc/base/logging.h" |
16 | 16 |
17 namespace cricket { | 17 namespace cricket { |
18 | 18 |
19 static const uint32_t kMessageConnectTimeout = 1; | 19 static const int kMessageConnectTimeout = 1; |
20 static const int kKeepAliveDelay = 10 * 60 * 1000; | 20 static const int kKeepAliveDelay = 10 * 60 * 1000; |
21 static const int kRetryTimeout = 50 * 1000; // ICE says 50 secs | 21 static const int kRetryTimeout = 50 * 1000; // ICE says 50 secs |
22 // How long to wait for a socket to connect to remote host in milliseconds | 22 // How long to wait for a socket to connect to remote host in milliseconds |
23 // before trying another connection. | 23 // before trying another connection. |
24 static const int kSoftConnectTimeoutMs = 3 * 1000; | 24 static const int kSoftConnectTimeoutMs = 3 * 1000; |
25 | 25 |
26 // Handles a connection to one address/port/protocol combination for a | 26 // Handles a connection to one address/port/protocol combination for a |
27 // particular RelayEntry. | 27 // particular RelayEntry. |
28 class RelayConnection : public sigslot::has_slots<> { | 28 class RelayConnection : public sigslot::has_slots<> { |
29 public: | 29 public: |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 void OnSent() override; | 168 void OnSent() override; |
169 int resend_delay() override; | 169 int resend_delay() override; |
170 | 170 |
171 void OnResponse(StunMessage* response) override; | 171 void OnResponse(StunMessage* response) override; |
172 void OnErrorResponse(StunMessage* response) override; | 172 void OnErrorResponse(StunMessage* response) override; |
173 void OnTimeout() override; | 173 void OnTimeout() override; |
174 | 174 |
175 private: | 175 private: |
176 RelayEntry* entry_; | 176 RelayEntry* entry_; |
177 RelayConnection* connection_; | 177 RelayConnection* connection_; |
178 uint32_t start_time_; | 178 int64_t start_time_; |
179 }; | 179 }; |
180 | 180 |
181 RelayPort::RelayPort(rtc::Thread* thread, | 181 RelayPort::RelayPort(rtc::Thread* thread, |
182 rtc::PacketSocketFactory* factory, | 182 rtc::PacketSocketFactory* factory, |
183 rtc::Network* network, | 183 rtc::Network* network, |
184 const rtc::IPAddress& ip, | 184 const rtc::IPAddress& ip, |
185 uint16_t min_port, | 185 uint16_t min_port, |
186 uint16_t max_port, | 186 uint16_t max_port, |
187 const std::string& username, | 187 const std::string& username, |
188 const std::string& password) | 188 const std::string& password) |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 sent = current_connection_->Send(data, size, options); | 772 sent = current_connection_->Send(data, size, options); |
773 } | 773 } |
774 return sent; | 774 return sent; |
775 } | 775 } |
776 | 776 |
777 AllocateRequest::AllocateRequest(RelayEntry* entry, | 777 AllocateRequest::AllocateRequest(RelayEntry* entry, |
778 RelayConnection* connection) | 778 RelayConnection* connection) |
779 : StunRequest(new RelayMessage()), | 779 : StunRequest(new RelayMessage()), |
780 entry_(entry), | 780 entry_(entry), |
781 connection_(connection) { | 781 connection_(connection) { |
782 start_time_ = rtc::Time(); | 782 start_time_ = rtc::Time64(); |
783 } | 783 } |
784 | 784 |
785 void AllocateRequest::Prepare(StunMessage* request) { | 785 void AllocateRequest::Prepare(StunMessage* request) { |
786 request->SetType(STUN_ALLOCATE_REQUEST); | 786 request->SetType(STUN_ALLOCATE_REQUEST); |
787 | 787 |
788 StunByteStringAttribute* username_attr = | 788 StunByteStringAttribute* username_attr = |
789 StunAttribute::CreateByteString(STUN_ATTR_USERNAME); | 789 StunAttribute::CreateByteString(STUN_ATTR_USERNAME); |
790 username_attr->CopyBytes( | 790 username_attr->CopyBytes( |
791 entry_->port()->username_fragment().c_str(), | 791 entry_->port()->username_fragment().c_str(), |
792 entry_->port()->username_fragment().size()); | 792 entry_->port()->username_fragment().size()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 void AllocateRequest::OnErrorResponse(StunMessage* response) { | 827 void AllocateRequest::OnErrorResponse(StunMessage* response) { |
828 const StunErrorCodeAttribute* attr = response->GetErrorCode(); | 828 const StunErrorCodeAttribute* attr = response->GetErrorCode(); |
829 if (!attr) { | 829 if (!attr) { |
830 LOG(INFO) << "Bad allocate response error code"; | 830 LOG(INFO) << "Bad allocate response error code"; |
831 } else { | 831 } else { |
832 LOG(INFO) << "Allocate error response:" | 832 LOG(INFO) << "Allocate error response:" |
833 << " code=" << attr->code() | 833 << " code=" << attr->code() |
834 << " reason='" << attr->reason() << "'"; | 834 << " reason='" << attr->reason() << "'"; |
835 } | 835 } |
836 | 836 |
837 if (rtc::TimeSince(start_time_) <= kRetryTimeout) | 837 if (rtc::Time64() - start_time_ <= kRetryTimeout) |
838 entry_->ScheduleKeepAlive(); | 838 entry_->ScheduleKeepAlive(); |
839 } | 839 } |
840 | 840 |
841 void AllocateRequest::OnTimeout() { | 841 void AllocateRequest::OnTimeout() { |
842 LOG(INFO) << "Allocate request timed out"; | 842 LOG(INFO) << "Allocate request timed out"; |
843 entry_->HandleConnectFailure(connection_->socket()); | 843 entry_->HandleConnectFailure(connection_->socket()); |
844 } | 844 } |
845 | 845 |
846 } // namespace cricket | 846 } // namespace cricket |
OLD | NEW |