| 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 910 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 921   return true; | 921   return true; | 
| 922 } | 922 } | 
| 923 | 923 | 
| 924 void TurnPort::SendRequest(StunRequest* req, int delay) { | 924 void TurnPort::SendRequest(StunRequest* req, int delay) { | 
| 925   request_manager_.SendDelayed(req, delay); | 925   request_manager_.SendDelayed(req, delay); | 
| 926 } | 926 } | 
| 927 | 927 | 
| 928 void TurnPort::AddRequestAuthInfo(StunMessage* msg) { | 928 void TurnPort::AddRequestAuthInfo(StunMessage* msg) { | 
| 929   // If we've gotten the necessary data from the server, add it to our request. | 929   // If we've gotten the necessary data from the server, add it to our request. | 
| 930   VERIFY(!hash_.empty()); | 930   VERIFY(!hash_.empty()); | 
| 931   VERIFY(msg->AddAttribute(new StunByteStringAttribute( | 931   msg->AddAttribute(new StunByteStringAttribute( | 
| 932       STUN_ATTR_USERNAME, credentials_.username))); | 932       STUN_ATTR_USERNAME, credentials_.username)); | 
| 933   VERIFY(msg->AddAttribute(new StunByteStringAttribute( | 933   msg->AddAttribute(new StunByteStringAttribute( | 
| 934       STUN_ATTR_REALM, realm_))); | 934       STUN_ATTR_REALM, realm_)); | 
| 935   VERIFY(msg->AddAttribute(new StunByteStringAttribute( | 935   msg->AddAttribute(new StunByteStringAttribute( | 
| 936       STUN_ATTR_NONCE, nonce_))); | 936       STUN_ATTR_NONCE, nonce_)); | 
| 937   VERIFY(msg->AddMessageIntegrity(hash())); | 937   VERIFY(msg->AddMessageIntegrity(hash())); | 
| 938 } | 938 } | 
| 939 | 939 | 
| 940 int TurnPort::Send(const void* data, size_t len, | 940 int TurnPort::Send(const void* data, size_t len, | 
| 941                    const rtc::PacketOptions& options) { | 941                    const rtc::PacketOptions& options) { | 
| 942   return socket_->SendTo(data, len, server_address_.address, options); | 942   return socket_->SendTo(data, len, server_address_.address, options); | 
| 943 } | 943 } | 
| 944 | 944 | 
| 945 void TurnPort::UpdateHash() { | 945 void TurnPort::UpdateHash() { | 
| 946   VERIFY(ComputeStunCredentialHash(credentials_.username, realm_, | 946   VERIFY(ComputeStunCredentialHash(credentials_.username, realm_, | 
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1075     : StunRequest(new TurnMessage()), | 1075     : StunRequest(new TurnMessage()), | 
| 1076       port_(port) { | 1076       port_(port) { | 
| 1077 } | 1077 } | 
| 1078 | 1078 | 
| 1079 void TurnAllocateRequest::Prepare(StunMessage* request) { | 1079 void TurnAllocateRequest::Prepare(StunMessage* request) { | 
| 1080   // Create the request as indicated in RFC 5766, Section 6.1. | 1080   // Create the request as indicated in RFC 5766, Section 6.1. | 
| 1081   request->SetType(TURN_ALLOCATE_REQUEST); | 1081   request->SetType(TURN_ALLOCATE_REQUEST); | 
| 1082   StunUInt32Attribute* transport_attr = StunAttribute::CreateUInt32( | 1082   StunUInt32Attribute* transport_attr = StunAttribute::CreateUInt32( | 
| 1083       STUN_ATTR_REQUESTED_TRANSPORT); | 1083       STUN_ATTR_REQUESTED_TRANSPORT); | 
| 1084   transport_attr->SetValue(IPPROTO_UDP << 24); | 1084   transport_attr->SetValue(IPPROTO_UDP << 24); | 
| 1085   VERIFY(request->AddAttribute(transport_attr)); | 1085   request->AddAttribute(transport_attr); | 
| 1086   if (!port_->hash().empty()) { | 1086   if (!port_->hash().empty()) { | 
| 1087     port_->AddRequestAuthInfo(request); | 1087     port_->AddRequestAuthInfo(request); | 
| 1088   } | 1088   } | 
| 1089 } | 1089 } | 
| 1090 | 1090 | 
| 1091 void TurnAllocateRequest::OnSent() { | 1091 void TurnAllocateRequest::OnSent() { | 
| 1092   LOG_J(LS_INFO, port_) << "TURN allocate request sent" | 1092   LOG_J(LS_INFO, port_) << "TURN allocate request sent" | 
| 1093                         << ", id=" << rtc::hex_encode(id()); | 1093                         << ", id=" << rtc::hex_encode(id()); | 
| 1094   StunRequest::OnSent(); | 1094   StunRequest::OnSent(); | 
| 1095 } | 1095 } | 
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1249     : StunRequest(new TurnMessage()), | 1249     : StunRequest(new TurnMessage()), | 
| 1250       port_(port), | 1250       port_(port), | 
| 1251       lifetime_(-1) { | 1251       lifetime_(-1) { | 
| 1252 } | 1252 } | 
| 1253 | 1253 | 
| 1254 void TurnRefreshRequest::Prepare(StunMessage* request) { | 1254 void TurnRefreshRequest::Prepare(StunMessage* request) { | 
| 1255   // Create the request as indicated in RFC 5766, Section 7.1. | 1255   // Create the request as indicated in RFC 5766, Section 7.1. | 
| 1256   // No attributes need to be included. | 1256   // No attributes need to be included. | 
| 1257   request->SetType(TURN_REFRESH_REQUEST); | 1257   request->SetType(TURN_REFRESH_REQUEST); | 
| 1258   if (lifetime_ > -1) { | 1258   if (lifetime_ > -1) { | 
| 1259     VERIFY(request->AddAttribute(new StunUInt32Attribute( | 1259     request->AddAttribute(new StunUInt32Attribute( | 
| 1260         STUN_ATTR_LIFETIME, lifetime_))); | 1260         STUN_ATTR_LIFETIME, lifetime_)); | 
| 1261   } | 1261   } | 
| 1262 | 1262 | 
| 1263   port_->AddRequestAuthInfo(request); | 1263   port_->AddRequestAuthInfo(request); | 
| 1264 } | 1264 } | 
| 1265 | 1265 | 
| 1266 void TurnRefreshRequest::OnSent() { | 1266 void TurnRefreshRequest::OnSent() { | 
| 1267   LOG_J(LS_INFO, port_) << "TURN refresh request sent" | 1267   LOG_J(LS_INFO, port_) << "TURN refresh request sent" | 
| 1268                         << ", id=" << rtc::hex_encode(id()); | 1268                         << ", id=" << rtc::hex_encode(id()); | 
| 1269   StunRequest::OnSent(); | 1269   StunRequest::OnSent(); | 
| 1270 } | 1270 } | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1319       port_(port), | 1319       port_(port), | 
| 1320       entry_(entry), | 1320       entry_(entry), | 
| 1321       ext_addr_(ext_addr) { | 1321       ext_addr_(ext_addr) { | 
| 1322   entry_->SignalDestroyed.connect( | 1322   entry_->SignalDestroyed.connect( | 
| 1323       this, &TurnCreatePermissionRequest::OnEntryDestroyed); | 1323       this, &TurnCreatePermissionRequest::OnEntryDestroyed); | 
| 1324 } | 1324 } | 
| 1325 | 1325 | 
| 1326 void TurnCreatePermissionRequest::Prepare(StunMessage* request) { | 1326 void TurnCreatePermissionRequest::Prepare(StunMessage* request) { | 
| 1327   // Create the request as indicated in RFC5766, Section 9.1. | 1327   // Create the request as indicated in RFC5766, Section 9.1. | 
| 1328   request->SetType(TURN_CREATE_PERMISSION_REQUEST); | 1328   request->SetType(TURN_CREATE_PERMISSION_REQUEST); | 
| 1329   VERIFY(request->AddAttribute(new StunXorAddressAttribute( | 1329   request->AddAttribute(new StunXorAddressAttribute( | 
| 1330       STUN_ATTR_XOR_PEER_ADDRESS, ext_addr_))); | 1330       STUN_ATTR_XOR_PEER_ADDRESS, ext_addr_)); | 
| 1331   port_->AddRequestAuthInfo(request); | 1331   port_->AddRequestAuthInfo(request); | 
| 1332 } | 1332 } | 
| 1333 | 1333 | 
| 1334 void TurnCreatePermissionRequest::OnSent() { | 1334 void TurnCreatePermissionRequest::OnSent() { | 
| 1335   LOG_J(LS_INFO, port_) << "TURN create permission request sent" | 1335   LOG_J(LS_INFO, port_) << "TURN create permission request sent" | 
| 1336                         << ", id=" << rtc::hex_encode(id()); | 1336                         << ", id=" << rtc::hex_encode(id()); | 
| 1337   StunRequest::OnSent(); | 1337   StunRequest::OnSent(); | 
| 1338 } | 1338 } | 
| 1339 | 1339 | 
| 1340 void TurnCreatePermissionRequest::OnResponse(StunMessage* response) { | 1340 void TurnCreatePermissionRequest::OnResponse(StunMessage* response) { | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1380       entry_(entry), | 1380       entry_(entry), | 
| 1381       channel_id_(channel_id), | 1381       channel_id_(channel_id), | 
| 1382       ext_addr_(ext_addr) { | 1382       ext_addr_(ext_addr) { | 
| 1383   entry_->SignalDestroyed.connect( | 1383   entry_->SignalDestroyed.connect( | 
| 1384       this, &TurnChannelBindRequest::OnEntryDestroyed); | 1384       this, &TurnChannelBindRequest::OnEntryDestroyed); | 
| 1385 } | 1385 } | 
| 1386 | 1386 | 
| 1387 void TurnChannelBindRequest::Prepare(StunMessage* request) { | 1387 void TurnChannelBindRequest::Prepare(StunMessage* request) { | 
| 1388   // Create the request as indicated in RFC5766, Section 11.1. | 1388   // Create the request as indicated in RFC5766, Section 11.1. | 
| 1389   request->SetType(TURN_CHANNEL_BIND_REQUEST); | 1389   request->SetType(TURN_CHANNEL_BIND_REQUEST); | 
| 1390   VERIFY(request->AddAttribute(new StunUInt32Attribute( | 1390   request->AddAttribute(new StunUInt32Attribute( | 
| 1391       STUN_ATTR_CHANNEL_NUMBER, channel_id_ << 16))); | 1391       STUN_ATTR_CHANNEL_NUMBER, channel_id_ << 16)); | 
| 1392   VERIFY(request->AddAttribute(new StunXorAddressAttribute( | 1392   request->AddAttribute(new StunXorAddressAttribute( | 
| 1393       STUN_ATTR_XOR_PEER_ADDRESS, ext_addr_))); | 1393       STUN_ATTR_XOR_PEER_ADDRESS, ext_addr_)); | 
| 1394   port_->AddRequestAuthInfo(request); | 1394   port_->AddRequestAuthInfo(request); | 
| 1395 } | 1395 } | 
| 1396 | 1396 | 
| 1397 void TurnChannelBindRequest::OnSent() { | 1397 void TurnChannelBindRequest::OnSent() { | 
| 1398   LOG_J(LS_INFO, port_) << "TURN channel bind request sent" | 1398   LOG_J(LS_INFO, port_) << "TURN channel bind request sent" | 
| 1399                         << ", id=" << rtc::hex_encode(id()); | 1399                         << ", id=" << rtc::hex_encode(id()); | 
| 1400   StunRequest::OnSent(); | 1400   StunRequest::OnSent(); | 
| 1401 } | 1401 } | 
| 1402 | 1402 | 
| 1403 void TurnChannelBindRequest::OnResponse(StunMessage* response) { | 1403 void TurnChannelBindRequest::OnResponse(StunMessage* response) { | 
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1464 | 1464 | 
| 1465 int TurnEntry::Send(const void* data, size_t size, bool payload, | 1465 int TurnEntry::Send(const void* data, size_t size, bool payload, | 
| 1466                     const rtc::PacketOptions& options) { | 1466                     const rtc::PacketOptions& options) { | 
| 1467   rtc::ByteBufferWriter buf; | 1467   rtc::ByteBufferWriter buf; | 
| 1468   if (state_ != STATE_BOUND) { | 1468   if (state_ != STATE_BOUND) { | 
| 1469     // If we haven't bound the channel yet, we have to use a Send Indication. | 1469     // If we haven't bound the channel yet, we have to use a Send Indication. | 
| 1470     TurnMessage msg; | 1470     TurnMessage msg; | 
| 1471     msg.SetType(TURN_SEND_INDICATION); | 1471     msg.SetType(TURN_SEND_INDICATION); | 
| 1472     msg.SetTransactionID( | 1472     msg.SetTransactionID( | 
| 1473         rtc::CreateRandomString(kStunTransactionIdLength)); | 1473         rtc::CreateRandomString(kStunTransactionIdLength)); | 
| 1474     VERIFY(msg.AddAttribute(new StunXorAddressAttribute( | 1474     msg.AddAttribute(new StunXorAddressAttribute( | 
| 1475         STUN_ATTR_XOR_PEER_ADDRESS, ext_addr_))); | 1475         STUN_ATTR_XOR_PEER_ADDRESS, ext_addr_)); | 
| 1476     VERIFY(msg.AddAttribute(new StunByteStringAttribute( | 1476     msg.AddAttribute(new StunByteStringAttribute( | 
| 1477         STUN_ATTR_DATA, data, size))); | 1477         STUN_ATTR_DATA, data, size)); | 
| 1478     VERIFY(msg.Write(&buf)); | 1478     VERIFY(msg.Write(&buf)); | 
| 1479 | 1479 | 
| 1480     // If we're sending real data, request a channel bind that we can use later. | 1480     // If we're sending real data, request a channel bind that we can use later. | 
| 1481     if (state_ == STATE_UNBOUND && payload) { | 1481     if (state_ == STATE_UNBOUND && payload) { | 
| 1482       SendChannelBindRequest(0); | 1482       SendChannelBindRequest(0); | 
| 1483       state_ = STATE_BINDING; | 1483       state_ = STATE_BINDING; | 
| 1484     } | 1484     } | 
| 1485   } else { | 1485   } else { | 
| 1486     // If the channel is bound, we can send the data as a Channel Message. | 1486     // If the channel is bound, we can send the data as a Channel Message. | 
| 1487     buf.WriteUInt16(channel_id_); | 1487     buf.WriteUInt16(channel_id_); | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1549   } else { | 1549   } else { | 
| 1550     state_ = STATE_UNBOUND; | 1550     state_ = STATE_UNBOUND; | 
| 1551     port_->FailAndPruneConnection(ext_addr_); | 1551     port_->FailAndPruneConnection(ext_addr_); | 
| 1552   } | 1552   } | 
| 1553 } | 1553 } | 
| 1554 void TurnEntry::OnChannelBindTimeout() { | 1554 void TurnEntry::OnChannelBindTimeout() { | 
| 1555   state_ = STATE_UNBOUND; | 1555   state_ = STATE_UNBOUND; | 
| 1556   port_->FailAndPruneConnection(ext_addr_); | 1556   port_->FailAndPruneConnection(ext_addr_); | 
| 1557 } | 1557 } | 
| 1558 }  // namespace cricket | 1558 }  // namespace cricket | 
| OLD | NEW | 
|---|