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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 138 |
139 TurnPort* port() { return port_; } | 139 TurnPort* port() { return port_; } |
140 | 140 |
141 int channel_id() const { return channel_id_; } | 141 int channel_id() const { return channel_id_; } |
142 // For testing only. | 142 // For testing only. |
143 void set_channel_id(int channel_id) { channel_id_ = channel_id; } | 143 void set_channel_id(int channel_id) { channel_id_ = channel_id; } |
144 | 144 |
145 const rtc::SocketAddress& address() const { return ext_addr_; } | 145 const rtc::SocketAddress& address() const { return ext_addr_; } |
146 BindState state() const { return state_; } | 146 BindState state() const { return state_; } |
147 | 147 |
148 uint32_t destruction_timestamp() { return destruction_timestamp_; } | 148 int64_t destruction_timestamp() { return destruction_timestamp_; } |
149 void set_destruction_timestamp(uint32_t destruction_timestamp) { | 149 void set_destruction_timestamp(int64_t destruction_timestamp) { |
150 destruction_timestamp_ = destruction_timestamp; | 150 destruction_timestamp_ = destruction_timestamp; |
151 } | 151 } |
152 | 152 |
153 // Helper methods to send permission and channel bind requests. | 153 // Helper methods to send permission and channel bind requests. |
154 void SendCreatePermissionRequest(int delay); | 154 void SendCreatePermissionRequest(int delay); |
155 void SendChannelBindRequest(int delay); | 155 void SendChannelBindRequest(int delay); |
156 // Sends a packet to the given destination address. | 156 // Sends a packet to the given destination address. |
157 // This will wrap the packet in STUN if necessary. | 157 // This will wrap the packet in STUN if necessary. |
158 int Send(const void* data, size_t size, bool payload, | 158 int Send(const void* data, size_t size, bool payload, |
159 const rtc::PacketOptions& options); | 159 const rtc::PacketOptions& options); |
160 | 160 |
161 void OnCreatePermissionSuccess(); | 161 void OnCreatePermissionSuccess(); |
162 void OnCreatePermissionError(StunMessage* response, int code); | 162 void OnCreatePermissionError(StunMessage* response, int code); |
163 void OnCreatePermissionTimeout(); | 163 void OnCreatePermissionTimeout(); |
164 void OnChannelBindSuccess(); | 164 void OnChannelBindSuccess(); |
165 void OnChannelBindError(StunMessage* response, int code); | 165 void OnChannelBindError(StunMessage* response, int code); |
166 void OnChannelBindTimeout(); | 166 void OnChannelBindTimeout(); |
167 // Signal sent when TurnEntry is destroyed. | 167 // Signal sent when TurnEntry is destroyed. |
168 sigslot::signal1<TurnEntry*> SignalDestroyed; | 168 sigslot::signal1<TurnEntry*> SignalDestroyed; |
169 | 169 |
170 private: | 170 private: |
171 TurnPort* port_; | 171 TurnPort* port_; |
172 int channel_id_; | 172 int channel_id_; |
173 rtc::SocketAddress ext_addr_; | 173 rtc::SocketAddress ext_addr_; |
174 BindState state_; | 174 BindState state_; |
175 // A non-zero value indicates that this entry is scheduled to be destroyed. | 175 // A non-zero value indicates that this entry is scheduled to be destroyed. |
176 // It is also used as an ID of the event scheduling. When the destruction | 176 // It is also used as an ID of the event scheduling. When the destruction |
177 // event actually fires, the TurnEntry will be destroyed only if the | 177 // event actually fires, the TurnEntry will be destroyed only if the |
178 // timestamp here matches the one in the firing event. | 178 // timestamp here matches the one in the firing event. |
179 uint32_t destruction_timestamp_ = 0; | 179 int64_t destruction_timestamp_ = 0; |
180 }; | 180 }; |
181 | 181 |
182 TurnPort::TurnPort(rtc::Thread* thread, | 182 TurnPort::TurnPort(rtc::Thread* thread, |
183 rtc::PacketSocketFactory* factory, | 183 rtc::PacketSocketFactory* factory, |
184 rtc::Network* network, | 184 rtc::Network* network, |
185 rtc::AsyncPacketSocket* socket, | 185 rtc::AsyncPacketSocket* socket, |
186 const std::string& username, | 186 const std::string& username, |
187 const std::string& password, | 187 const std::string& password, |
188 const ProtocolAddress& server_address, | 188 const ProtocolAddress& server_address, |
189 const RelayCredentials& credentials, | 189 const RelayCredentials& credentials, |
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 } | 983 } |
984 } | 984 } |
985 | 985 |
986 void TurnPort::DestroyEntry(TurnEntry* entry) { | 986 void TurnPort::DestroyEntry(TurnEntry* entry) { |
987 ASSERT(entry != NULL); | 987 ASSERT(entry != NULL); |
988 entry->SignalDestroyed(entry); | 988 entry->SignalDestroyed(entry); |
989 entries_.remove(entry); | 989 entries_.remove(entry); |
990 delete entry; | 990 delete entry; |
991 } | 991 } |
992 | 992 |
993 void TurnPort::DestroyEntryIfNotCancelled(TurnEntry* entry, | 993 void TurnPort::DestroyEntryIfNotCancelled(TurnEntry* entry, int64_t timestamp) { |
994 uint32_t timestamp) { | |
995 if (!EntryExists(entry)) { | 994 if (!EntryExists(entry)) { |
996 return; | 995 return; |
997 } | 996 } |
998 bool cancelled = timestamp != entry->destruction_timestamp(); | 997 bool cancelled = timestamp != entry->destruction_timestamp(); |
999 if (!cancelled) { | 998 if (!cancelled) { |
1000 DestroyEntry(entry); | 999 DestroyEntry(entry); |
1001 } | 1000 } |
1002 } | 1001 } |
1003 | 1002 |
1004 void TurnPort::OnConnectionDestroyed(Connection* conn) { | 1003 void TurnPort::OnConnectionDestroyed(Connection* conn) { |
1005 // Schedule an event to destroy TurnEntry for the connection, which is | 1004 // Schedule an event to destroy TurnEntry for the connection, which is |
1006 // already destroyed. | 1005 // already destroyed. |
1007 const rtc::SocketAddress& remote_address = conn->remote_candidate().address(); | 1006 const rtc::SocketAddress& remote_address = conn->remote_candidate().address(); |
1008 TurnEntry* entry = FindEntry(remote_address); | 1007 TurnEntry* entry = FindEntry(remote_address); |
1009 ASSERT(entry != NULL); | 1008 ASSERT(entry != NULL); |
1010 ScheduleEntryDestruction(entry); | 1009 ScheduleEntryDestruction(entry); |
1011 } | 1010 } |
1012 | 1011 |
1013 void TurnPort::ScheduleEntryDestruction(TurnEntry* entry) { | 1012 void TurnPort::ScheduleEntryDestruction(TurnEntry* entry) { |
1014 ASSERT(entry->destruction_timestamp() == 0); | 1013 ASSERT(entry->destruction_timestamp() == 0); |
1015 uint32_t timestamp = rtc::Time(); | 1014 int64_t timestamp = rtc::Time64(); |
1016 entry->set_destruction_timestamp(timestamp); | 1015 entry->set_destruction_timestamp(timestamp); |
1017 invoker_.AsyncInvokeDelayed<void>( | 1016 invoker_.AsyncInvokeDelayed<void>( |
1018 thread(), | 1017 thread(), |
1019 rtc::Bind(&TurnPort::DestroyEntryIfNotCancelled, this, entry, timestamp), | 1018 rtc::Bind(&TurnPort::DestroyEntryIfNotCancelled, this, entry, timestamp), |
1020 TURN_PERMISSION_TIMEOUT); | 1019 TURN_PERMISSION_TIMEOUT); |
1021 } | 1020 } |
1022 | 1021 |
1023 void TurnPort::CancelEntryDestruction(TurnEntry* entry) { | 1022 void TurnPort::CancelEntryDestruction(TurnEntry* entry) { |
1024 ASSERT(entry->destruction_timestamp() != 0); | 1023 ASSERT(entry->destruction_timestamp() != 0); |
1025 entry->set_destruction_timestamp(0); | 1024 entry->set_destruction_timestamp(0); |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1513 } else { | 1512 } else { |
1514 state_ = STATE_UNBOUND; | 1513 state_ = STATE_UNBOUND; |
1515 port_->DestroyConnection(ext_addr_); | 1514 port_->DestroyConnection(ext_addr_); |
1516 } | 1515 } |
1517 } | 1516 } |
1518 void TurnEntry::OnChannelBindTimeout() { | 1517 void TurnEntry::OnChannelBindTimeout() { |
1519 state_ = STATE_UNBOUND; | 1518 state_ = STATE_UNBOUND; |
1520 port_->DestroyConnection(ext_addr_); | 1519 port_->DestroyConnection(ext_addr_); |
1521 } | 1520 } |
1522 } // namespace cricket | 1521 } // namespace cricket |
OLD | NEW |