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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 for (size_t i = 0; i < removed_sockets_.size(); ++i) | 94 for (size_t i = 0; i < removed_sockets_.size(); ++i) |
95 delete removed_sockets_[i]; | 95 delete removed_sockets_[i]; |
96 while (!server_sockets_.empty()) { | 96 while (!server_sockets_.empty()) { |
97 rtc::AsyncSocket* socket = server_sockets_.begin()->first; | 97 rtc::AsyncSocket* socket = server_sockets_.begin()->first; |
98 server_sockets_.erase(server_sockets_.begin()->first); | 98 server_sockets_.erase(server_sockets_.begin()->first); |
99 delete socket; | 99 delete socket; |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 void RelayServer::AddInternalSocket(rtc::AsyncPacketSocket* socket) { | 103 void RelayServer::AddInternalSocket(rtc::AsyncPacketSocket* socket) { |
104 ASSERT(internal_sockets_.end() == | 104 RTC_DCHECK(internal_sockets_.end() == std::find(internal_sockets_.begin(), |
105 std::find(internal_sockets_.begin(), internal_sockets_.end(), socket)); | 105 internal_sockets_.end(), |
106 socket)); | |
106 internal_sockets_.push_back(socket); | 107 internal_sockets_.push_back(socket); |
107 socket->SignalReadPacket.connect(this, &RelayServer::OnInternalPacket); | 108 socket->SignalReadPacket.connect(this, &RelayServer::OnInternalPacket); |
108 } | 109 } |
109 | 110 |
110 void RelayServer::RemoveInternalSocket(rtc::AsyncPacketSocket* socket) { | 111 void RelayServer::RemoveInternalSocket(rtc::AsyncPacketSocket* socket) { |
111 SocketList::iterator iter = | 112 SocketList::iterator iter = |
112 std::find(internal_sockets_.begin(), internal_sockets_.end(), socket); | 113 std::find(internal_sockets_.begin(), internal_sockets_.end(), socket); |
113 ASSERT(iter != internal_sockets_.end()); | 114 RTC_DCHECK(iter != internal_sockets_.end()); |
114 internal_sockets_.erase(iter); | 115 internal_sockets_.erase(iter); |
115 removed_sockets_.push_back(socket); | 116 removed_sockets_.push_back(socket); |
116 socket->SignalReadPacket.disconnect(this); | 117 socket->SignalReadPacket.disconnect(this); |
117 } | 118 } |
118 | 119 |
119 void RelayServer::AddExternalSocket(rtc::AsyncPacketSocket* socket) { | 120 void RelayServer::AddExternalSocket(rtc::AsyncPacketSocket* socket) { |
120 ASSERT(external_sockets_.end() == | 121 RTC_DCHECK(external_sockets_.end() == std::find(external_sockets_.begin(), |
121 std::find(external_sockets_.begin(), external_sockets_.end(), socket)); | 122 external_sockets_.end(), |
123 socket)); | |
122 external_sockets_.push_back(socket); | 124 external_sockets_.push_back(socket); |
123 socket->SignalReadPacket.connect(this, &RelayServer::OnExternalPacket); | 125 socket->SignalReadPacket.connect(this, &RelayServer::OnExternalPacket); |
124 } | 126 } |
125 | 127 |
126 void RelayServer::RemoveExternalSocket(rtc::AsyncPacketSocket* socket) { | 128 void RelayServer::RemoveExternalSocket(rtc::AsyncPacketSocket* socket) { |
127 SocketList::iterator iter = | 129 SocketList::iterator iter = |
128 std::find(external_sockets_.begin(), external_sockets_.end(), socket); | 130 std::find(external_sockets_.begin(), external_sockets_.end(), socket); |
129 ASSERT(iter != external_sockets_.end()); | 131 RTC_DCHECK(iter != external_sockets_.end()); |
130 external_sockets_.erase(iter); | 132 external_sockets_.erase(iter); |
131 removed_sockets_.push_back(socket); | 133 removed_sockets_.push_back(socket); |
132 socket->SignalReadPacket.disconnect(this); | 134 socket->SignalReadPacket.disconnect(this); |
133 } | 135 } |
134 | 136 |
135 void RelayServer::AddInternalServerSocket(rtc::AsyncSocket* socket, | 137 void RelayServer::AddInternalServerSocket(rtc::AsyncSocket* socket, |
136 cricket::ProtocolType proto) { | 138 cricket::ProtocolType proto) { |
137 ASSERT(server_sockets_.end() == | 139 RTC_DCHECK(server_sockets_.end() == server_sockets_.find(socket)); |
138 server_sockets_.find(socket)); | |
139 server_sockets_[socket] = proto; | 140 server_sockets_[socket] = proto; |
140 socket->SignalReadEvent.connect(this, &RelayServer::OnReadEvent); | 141 socket->SignalReadEvent.connect(this, &RelayServer::OnReadEvent); |
141 } | 142 } |
142 | 143 |
143 void RelayServer::RemoveInternalServerSocket( | 144 void RelayServer::RemoveInternalServerSocket( |
144 rtc::AsyncSocket* socket) { | 145 rtc::AsyncSocket* socket) { |
145 ServerSocketMap::iterator iter = server_sockets_.find(socket); | 146 ServerSocketMap::iterator iter = server_sockets_.find(socket); |
146 ASSERT(iter != server_sockets_.end()); | 147 RTC_DCHECK(iter != server_sockets_.end()); |
147 server_sockets_.erase(iter); | 148 server_sockets_.erase(iter); |
148 socket->SignalReadEvent.disconnect(this); | 149 socket->SignalReadEvent.disconnect(this); |
149 } | 150 } |
150 | 151 |
151 int RelayServer::GetConnectionCount() const { | 152 int RelayServer::GetConnectionCount() const { |
152 return static_cast<int>(connections_.size()); | 153 return static_cast<int>(connections_.size()); |
153 } | 154 } |
154 | 155 |
155 rtc::SocketAddressPair RelayServer::GetConnection(int connection) const { | 156 rtc::SocketAddressPair RelayServer::GetConnection(int connection) const { |
156 int i = 0; | 157 int i = 0; |
(...skipping 11 matching lines...) Expand all Loading... | |
168 for (ConnectionMap::const_iterator it = connections_.begin(); | 169 for (ConnectionMap::const_iterator it = connections_.begin(); |
169 it != connections_.end(); ++it) { | 170 it != connections_.end(); ++it) { |
170 if (it->second->addr_pair().destination() == address) { | 171 if (it->second->addr_pair().destination() == address) { |
171 return true; | 172 return true; |
172 } | 173 } |
173 } | 174 } |
174 return false; | 175 return false; |
175 } | 176 } |
176 | 177 |
177 void RelayServer::OnReadEvent(rtc::AsyncSocket* socket) { | 178 void RelayServer::OnReadEvent(rtc::AsyncSocket* socket) { |
178 ASSERT(server_sockets_.find(socket) != server_sockets_.end()); | 179 RTC_DCHECK(server_sockets_.find(socket) != server_sockets_.end()); |
179 AcceptConnection(socket); | 180 AcceptConnection(socket); |
180 } | 181 } |
181 | 182 |
182 void RelayServer::OnInternalPacket( | 183 void RelayServer::OnInternalPacket( |
183 rtc::AsyncPacketSocket* socket, const char* bytes, size_t size, | 184 rtc::AsyncPacketSocket* socket, const char* bytes, size_t size, |
184 const rtc::SocketAddress& remote_addr, | 185 const rtc::SocketAddress& remote_addr, |
185 const rtc::PacketTime& packet_time) { | 186 const rtc::PacketTime& packet_time) { |
186 | 187 |
187 // Get the address of the connection we just received on. | 188 // Get the address of the connection we just received on. |
188 rtc::SocketAddressPair ap(remote_addr, socket->GetLocalAddress()); | 189 rtc::SocketAddressPair ap(remote_addr, socket->GetLocalAddress()); |
189 ASSERT(!ap.destination().IsNil()); | 190 RTC_DCHECK(!ap.destination().IsNil()); |
190 | 191 |
191 // If this did not come from an existing connection, it should be a STUN | 192 // If this did not come from an existing connection, it should be a STUN |
192 // allocate request. | 193 // allocate request. |
193 ConnectionMap::iterator piter = connections_.find(ap); | 194 ConnectionMap::iterator piter = connections_.find(ap); |
194 if (piter == connections_.end()) { | 195 if (piter == connections_.end()) { |
195 HandleStunAllocate(bytes, size, ap, socket); | 196 HandleStunAllocate(bytes, size, ap, socket); |
196 return; | 197 return; |
197 } | 198 } |
198 | 199 |
199 RelayServerConnection* int_conn = piter->second; | 200 RelayServerConnection* int_conn = piter->second; |
(...skipping 24 matching lines...) Expand all Loading... | |
224 } | 225 } |
225 } | 226 } |
226 | 227 |
227 void RelayServer::OnExternalPacket( | 228 void RelayServer::OnExternalPacket( |
228 rtc::AsyncPacketSocket* socket, const char* bytes, size_t size, | 229 rtc::AsyncPacketSocket* socket, const char* bytes, size_t size, |
229 const rtc::SocketAddress& remote_addr, | 230 const rtc::SocketAddress& remote_addr, |
230 const rtc::PacketTime& packet_time) { | 231 const rtc::PacketTime& packet_time) { |
231 | 232 |
232 // Get the address of the connection we just received on. | 233 // Get the address of the connection we just received on. |
233 rtc::SocketAddressPair ap(remote_addr, socket->GetLocalAddress()); | 234 rtc::SocketAddressPair ap(remote_addr, socket->GetLocalAddress()); |
234 ASSERT(!ap.destination().IsNil()); | 235 RTC_DCHECK(!ap.destination().IsNil()); |
235 | 236 |
236 // If this connection already exists, then forward the traffic. | 237 // If this connection already exists, then forward the traffic. |
237 ConnectionMap::iterator piter = connections_.find(ap); | 238 ConnectionMap::iterator piter = connections_.find(ap); |
238 if (piter != connections_.end()) { | 239 if (piter != connections_.end()) { |
239 // TODO: Check the HMAC. | 240 // TODO: Check the HMAC. |
240 RelayServerConnection* ext_conn = piter->second; | 241 RelayServerConnection* ext_conn = piter->second; |
241 RelayServerConnection* int_conn = | 242 RelayServerConnection* int_conn = |
242 ext_conn->binding()->GetInternalConnection( | 243 ext_conn->binding()->GetInternalConnection( |
243 ext_conn->addr_pair().source()); | 244 ext_conn->addr_pair().source()); |
244 ASSERT(int_conn != NULL); | 245 RTC_DCHECK(int_conn != NULL); |
245 int_conn->Send(bytes, size, ext_conn->addr_pair().source()); | 246 int_conn->Send(bytes, size, ext_conn->addr_pair().source()); |
246 ext_conn->Lock(); // allow outgoing packets | 247 ext_conn->Lock(); // allow outgoing packets |
247 return; | 248 return; |
248 } | 249 } |
249 | 250 |
250 // The first packet should always be a STUN / TURN packet. If it isn't, then | 251 // The first packet should always be a STUN / TURN packet. If it isn't, then |
251 // we should just ignore this packet. | 252 // we should just ignore this packet. |
252 RelayMessage msg; | 253 RelayMessage msg; |
253 rtc::ByteBufferReader buf(bytes, size); | 254 rtc::ByteBufferReader buf(bytes, size); |
254 if (!msg.Read(&buf)) { | 255 if (!msg.Read(&buf)) { |
(...skipping 27 matching lines...) Expand all Loading... | |
282 ext_conn->binding()->AddExternalConnection(ext_conn); | 283 ext_conn->binding()->AddExternalConnection(ext_conn); |
283 AddConnection(ext_conn); | 284 AddConnection(ext_conn); |
284 | 285 |
285 // We always know where external packets should be forwarded, so we can lock | 286 // We always know where external packets should be forwarded, so we can lock |
286 // them from the beginning. | 287 // them from the beginning. |
287 ext_conn->Lock(); | 288 ext_conn->Lock(); |
288 | 289 |
289 // Send this message on the appropriate internal connection. | 290 // Send this message on the appropriate internal connection. |
290 RelayServerConnection* int_conn = ext_conn->binding()->GetInternalConnection( | 291 RelayServerConnection* int_conn = ext_conn->binding()->GetInternalConnection( |
291 ext_conn->addr_pair().source()); | 292 ext_conn->addr_pair().source()); |
292 ASSERT(int_conn != NULL); | 293 RTC_DCHECK(int_conn != NULL); |
293 int_conn->Send(bytes, size, ext_conn->addr_pair().source()); | 294 int_conn->Send(bytes, size, ext_conn->addr_pair().source()); |
294 } | 295 } |
295 | 296 |
296 bool RelayServer::HandleStun( | 297 bool RelayServer::HandleStun( |
297 const char* bytes, size_t size, const rtc::SocketAddress& remote_addr, | 298 const char* bytes, size_t size, const rtc::SocketAddress& remote_addr, |
298 rtc::AsyncPacketSocket* socket, std::string* username, | 299 rtc::AsyncPacketSocket* socket, std::string* username, |
299 StunMessage* msg) { | 300 StunMessage* msg) { |
300 | 301 |
301 // Parse this into a stun message. Eat the message if this fails. | 302 // Parse this into a stun message. Eat the message if this fails. |
302 rtc::ByteBufferReader buf(bytes, size); | 303 rtc::ByteBufferReader buf(bytes, size); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 if (!data_attr) { | 465 if (!data_attr) { |
465 int_conn->SendStunError(request, 400, "Bad Request"); | 466 int_conn->SendStunError(request, 400, "Bad Request"); |
466 return; | 467 return; |
467 } | 468 } |
468 | 469 |
469 rtc::SocketAddress ext_addr(addr_attr->ipaddr(), addr_attr->port()); | 470 rtc::SocketAddress ext_addr(addr_attr->ipaddr(), addr_attr->port()); |
470 RelayServerConnection* ext_conn = | 471 RelayServerConnection* ext_conn = |
471 int_conn->binding()->GetExternalConnection(ext_addr); | 472 int_conn->binding()->GetExternalConnection(ext_addr); |
472 if (!ext_conn) { | 473 if (!ext_conn) { |
473 // Create a new connection to establish the relationship with this binding. | 474 // Create a new connection to establish the relationship with this binding. |
474 ASSERT(external_sockets_.size() == 1); | 475 RTC_DCHECK(external_sockets_.size() == 1); |
475 rtc::AsyncPacketSocket* socket = external_sockets_[0]; | 476 rtc::AsyncPacketSocket* socket = external_sockets_[0]; |
476 rtc::SocketAddressPair ap(ext_addr, socket->GetLocalAddress()); | 477 rtc::SocketAddressPair ap(ext_addr, socket->GetLocalAddress()); |
477 ext_conn = new RelayServerConnection(int_conn->binding(), ap, socket); | 478 ext_conn = new RelayServerConnection(int_conn->binding(), ap, socket); |
478 ext_conn->binding()->AddExternalConnection(ext_conn); | 479 ext_conn->binding()->AddExternalConnection(ext_conn); |
479 AddConnection(ext_conn); | 480 AddConnection(ext_conn); |
480 } | 481 } |
481 | 482 |
482 // If this connection has pinged us, then allow outgoing traffic. | 483 // If this connection has pinged us, then allow outgoing traffic. |
483 if (ext_conn->locked()) | 484 if (ext_conn->locked()) |
484 ext_conn->Send(data_attr->bytes(), data_attr->length()); | 485 ext_conn->Send(data_attr->bytes(), data_attr->length()); |
(...skipping 17 matching lines...) Expand all Loading... | |
502 StunUInt32Attribute* options2_attr = | 503 StunUInt32Attribute* options2_attr = |
503 StunAttribute::CreateUInt32(cricket::STUN_ATTR_OPTIONS); | 504 StunAttribute::CreateUInt32(cricket::STUN_ATTR_OPTIONS); |
504 options2_attr->SetValue(0x01); | 505 options2_attr->SetValue(0x01); |
505 response.AddAttribute(options2_attr); | 506 response.AddAttribute(options2_attr); |
506 | 507 |
507 int_conn->SendStun(response); | 508 int_conn->SendStun(response); |
508 } | 509 } |
509 } | 510 } |
510 | 511 |
511 void RelayServer::AddConnection(RelayServerConnection* conn) { | 512 void RelayServer::AddConnection(RelayServerConnection* conn) { |
512 ASSERT(connections_.find(conn->addr_pair()) == connections_.end()); | 513 RTC_DCHECK(connections_.find(conn->addr_pair()) == connections_.end()); |
513 connections_[conn->addr_pair()] = conn; | 514 connections_[conn->addr_pair()] = conn; |
514 } | 515 } |
515 | 516 |
516 void RelayServer::RemoveConnection(RelayServerConnection* conn) { | 517 void RelayServer::RemoveConnection(RelayServerConnection* conn) { |
517 ConnectionMap::iterator iter = connections_.find(conn->addr_pair()); | 518 ConnectionMap::iterator iter = connections_.find(conn->addr_pair()); |
518 ASSERT(iter != connections_.end()); | 519 RTC_DCHECK(iter != connections_.end()); |
519 connections_.erase(iter); | 520 connections_.erase(iter); |
520 } | 521 } |
521 | 522 |
522 void RelayServer::RemoveBinding(RelayServerBinding* binding) { | 523 void RelayServer::RemoveBinding(RelayServerBinding* binding) { |
523 BindingMap::iterator iter = bindings_.find(binding->username()); | 524 BindingMap::iterator iter = bindings_.find(binding->username()); |
524 ASSERT(iter != bindings_.end()); | 525 RTC_DCHECK(iter != bindings_.end()); |
525 bindings_.erase(iter); | 526 bindings_.erase(iter); |
526 | 527 |
527 if (log_bindings_) { | 528 if (log_bindings_) { |
528 LOG(LS_INFO) << "Removed binding " << binding->username() << ", " | 529 LOG(LS_INFO) << "Removed binding " << binding->username() << ", " |
529 << bindings_.size() << " remaining"; | 530 << bindings_.size() << " remaining"; |
530 } | 531 } |
531 } | 532 } |
532 | 533 |
533 void RelayServer::OnMessage(rtc::Message *pmsg) { | 534 void RelayServer::OnMessage(rtc::Message *pmsg) { |
534 #if ENABLE_DEBUG | 535 #if ENABLE_DEBUG |
kwiberg-webrtc
2017/01/12 02:10:41
Should this be DCHECK_IS_ON?
nisse-webrtc
2017/01/12 10:53:24
It should. Fixed.
kwiberg-webrtc
2017/01/12 11:00:38
Actually, do you need it at all? DCHECK is careful
nisse-webrtc
2017/01/12 11:09:42
Can probably be deleted, I'll give it a try.
| |
535 static const uint32_t kMessageAcceptConnection = 1; | 536 static const uint32_t kMessageAcceptConnection = 1; |
536 ASSERT(pmsg->message_id == kMessageAcceptConnection); | 537 RTC_DCHECK(pmsg->message_id == kMessageAcceptConnection); |
537 #endif | 538 #endif |
538 rtc::MessageData* data = pmsg->pdata; | 539 rtc::MessageData* data = pmsg->pdata; |
539 rtc::AsyncSocket* socket = | 540 rtc::AsyncSocket* socket = |
540 static_cast <rtc::TypedMessageData<rtc::AsyncSocket*>*> | 541 static_cast <rtc::TypedMessageData<rtc::AsyncSocket*>*> |
541 (data)->data(); | 542 (data)->data(); |
542 AcceptConnection(socket); | 543 AcceptConnection(socket); |
543 delete data; | 544 delete data; |
544 } | 545 } |
545 | 546 |
546 void RelayServer::OnTimeout(RelayServerBinding* binding) { | 547 void RelayServer::OnTimeout(RelayServerBinding* binding) { |
547 // This call will result in all of the necessary clean-up. We can't call | 548 // This call will result in all of the necessary clean-up. We can't call |
548 // delete here, because you can't delete an object that is signaling you. | 549 // delete here, because you can't delete an object that is signaling you. |
549 thread_->Dispose(binding); | 550 thread_->Dispose(binding); |
550 } | 551 } |
551 | 552 |
552 void RelayServer::AcceptConnection(rtc::AsyncSocket* server_socket) { | 553 void RelayServer::AcceptConnection(rtc::AsyncSocket* server_socket) { |
553 // Check if someone is trying to connect to us. | 554 // Check if someone is trying to connect to us. |
554 rtc::SocketAddress accept_addr; | 555 rtc::SocketAddress accept_addr; |
555 rtc::AsyncSocket* accepted_socket = | 556 rtc::AsyncSocket* accepted_socket = |
556 server_socket->Accept(&accept_addr); | 557 server_socket->Accept(&accept_addr); |
557 if (accepted_socket != NULL) { | 558 if (accepted_socket != NULL) { |
558 // We had someone trying to connect, now check which protocol to | 559 // We had someone trying to connect, now check which protocol to |
559 // use and create a packet socket. | 560 // use and create a packet socket. |
560 ASSERT(server_sockets_[server_socket] == cricket::PROTO_TCP || | 561 RTC_DCHECK(server_sockets_[server_socket] == cricket::PROTO_TCP || |
561 server_sockets_[server_socket] == cricket::PROTO_SSLTCP); | 562 server_sockets_[server_socket] == cricket::PROTO_SSLTCP); |
562 if (server_sockets_[server_socket] == cricket::PROTO_SSLTCP) { | 563 if (server_sockets_[server_socket] == cricket::PROTO_SSLTCP) { |
563 accepted_socket = new rtc::AsyncSSLServerSocket(accepted_socket); | 564 accepted_socket = new rtc::AsyncSSLServerSocket(accepted_socket); |
564 } | 565 } |
565 rtc::AsyncTCPSocket* tcp_socket = | 566 rtc::AsyncTCPSocket* tcp_socket = |
566 new rtc::AsyncTCPSocket(accepted_socket, false); | 567 new rtc::AsyncTCPSocket(accepted_socket, false); |
567 | 568 |
568 // Finally add the socket so it can start communicating with the client. | 569 // Finally add the socket so it can start communicating with the client. |
569 AddInternalSocket(tcp_socket); | 570 AddInternalSocket(tcp_socket); |
570 } | 571 } |
571 } | 572 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 msg.AddAttribute(magic_cookie_attr); | 611 msg.AddAttribute(magic_cookie_attr); |
611 | 612 |
612 StunAddressAttribute* addr_attr = | 613 StunAddressAttribute* addr_attr = |
613 StunAttribute::CreateAddress(STUN_ATTR_SOURCE_ADDRESS2); | 614 StunAttribute::CreateAddress(STUN_ATTR_SOURCE_ADDRESS2); |
614 addr_attr->SetIP(from_addr.ipaddr()); | 615 addr_attr->SetIP(from_addr.ipaddr()); |
615 addr_attr->SetPort(from_addr.port()); | 616 addr_attr->SetPort(from_addr.port()); |
616 msg.AddAttribute(addr_attr); | 617 msg.AddAttribute(addr_attr); |
617 | 618 |
618 StunByteStringAttribute* data_attr = | 619 StunByteStringAttribute* data_attr = |
619 StunAttribute::CreateByteString(STUN_ATTR_DATA); | 620 StunAttribute::CreateByteString(STUN_ATTR_DATA); |
620 ASSERT(size <= 65536); | 621 RTC_DCHECK(size <= 65536); |
621 data_attr->CopyBytes(data, uint16_t(size)); | 622 data_attr->CopyBytes(data, uint16_t(size)); |
622 msg.AddAttribute(data_attr); | 623 msg.AddAttribute(data_attr); |
623 | 624 |
624 SendStun(msg); | 625 SendStun(msg); |
625 } | 626 } |
626 | 627 |
627 void RelayServerConnection::SendStun(const StunMessage& msg) { | 628 void RelayServerConnection::SendStun(const StunMessage& msg) { |
628 // Note that the binding has been used again. | 629 // Note that the binding has been used again. |
629 binding_->NoteUsed(); | 630 binding_->NoteUsed(); |
630 | 631 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
711 const rtc::SocketAddress& ext_addr) { | 712 const rtc::SocketAddress& ext_addr) { |
712 | 713 |
713 // Look for an internal connection that is locked to this address. | 714 // Look for an internal connection that is locked to this address. |
714 for (size_t i = 0; i < internal_connections_.size(); ++i) { | 715 for (size_t i = 0; i < internal_connections_.size(); ++i) { |
715 if (internal_connections_[i]->locked() && | 716 if (internal_connections_[i]->locked() && |
716 (ext_addr == internal_connections_[i]->default_destination())) | 717 (ext_addr == internal_connections_[i]->default_destination())) |
717 return internal_connections_[i]; | 718 return internal_connections_[i]; |
718 } | 719 } |
719 | 720 |
720 // If one was not found, we send to the first connection. | 721 // If one was not found, we send to the first connection. |
721 ASSERT(internal_connections_.size() > 0); | 722 RTC_DCHECK(internal_connections_.size() > 0); |
722 return internal_connections_[0]; | 723 return internal_connections_[0]; |
723 } | 724 } |
724 | 725 |
725 RelayServerConnection* RelayServerBinding::GetExternalConnection( | 726 RelayServerConnection* RelayServerBinding::GetExternalConnection( |
726 const rtc::SocketAddress& ext_addr) { | 727 const rtc::SocketAddress& ext_addr) { |
727 for (size_t i = 0; i < external_connections_.size(); ++i) { | 728 for (size_t i = 0; i < external_connections_.size(); ++i) { |
728 if (ext_addr == external_connections_[i]->addr_pair().source()) | 729 if (ext_addr == external_connections_[i]->addr_pair().source()) |
729 return external_connections_[i]; | 730 return external_connections_[i]; |
730 } | 731 } |
731 return 0; | 732 return 0; |
732 } | 733 } |
733 | 734 |
734 void RelayServerBinding::OnMessage(rtc::Message *pmsg) { | 735 void RelayServerBinding::OnMessage(rtc::Message *pmsg) { |
735 if (pmsg->message_id == MSG_LIFETIME_TIMER) { | 736 if (pmsg->message_id == MSG_LIFETIME_TIMER) { |
736 ASSERT(!pmsg->pdata); | 737 RTC_DCHECK(!pmsg->pdata); |
737 | 738 |
738 // If the lifetime timeout has been exceeded, then send a signal. | 739 // If the lifetime timeout has been exceeded, then send a signal. |
739 // Otherwise, just keep waiting. | 740 // Otherwise, just keep waiting. |
740 if (rtc::TimeMillis() >= last_used_ + lifetime_) { | 741 if (rtc::TimeMillis() >= last_used_ + lifetime_) { |
741 LOG(LS_INFO) << "Expiring binding " << username_; | 742 LOG(LS_INFO) << "Expiring binding " << username_; |
742 SignalTimeout(this); | 743 SignalTimeout(this); |
743 } else { | 744 } else { |
744 server_->thread()->PostDelayed(RTC_FROM_HERE, lifetime_, this, | 745 server_->thread()->PostDelayed(RTC_FROM_HERE, lifetime_, this, |
745 MSG_LIFETIME_TIMER); | 746 MSG_LIFETIME_TIMER); |
746 } | 747 } |
747 | 748 |
748 } else { | 749 } else { |
749 RTC_NOTREACHED(); | 750 RTC_NOTREACHED(); |
750 } | 751 } |
751 } | 752 } |
752 | 753 |
753 } // namespace cricket | 754 } // namespace cricket |
OLD | NEW |