| 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 764 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   775 // |   775 // | 
|   776 // Connection |   776 // Connection | 
|   777 // |   777 // | 
|   778  |   778  | 
|   779 Connection::Connection(Port* port, |   779 Connection::Connection(Port* port, | 
|   780                        size_t index, |   780                        size_t index, | 
|   781                        const Candidate& remote_candidate) |   781                        const Candidate& remote_candidate) | 
|   782     : port_(port), |   782     : port_(port), | 
|   783       local_candidate_index_(index), |   783       local_candidate_index_(index), | 
|   784       remote_candidate_(remote_candidate), |   784       remote_candidate_(remote_candidate), | 
 |   785       read_state_(STATE_READ_INIT), | 
|   785       write_state_(STATE_WRITE_INIT), |   786       write_state_(STATE_WRITE_INIT), | 
|   786       receiving_(false), |  | 
|   787       connected_(true), |   787       connected_(true), | 
|   788       pruned_(false), |   788       pruned_(false), | 
|   789       use_candidate_attr_(false), |   789       use_candidate_attr_(false), | 
|   790       nominated_(false), |   790       nominated_(false), | 
|   791       remote_ice_mode_(ICEMODE_FULL), |   791       remote_ice_mode_(ICEMODE_FULL), | 
|   792       requests_(port->thread()), |   792       requests_(port->thread()), | 
|   793       rtt_(DEFAULT_RTT), |   793       rtt_(DEFAULT_RTT), | 
|   794       last_ping_sent_(0), |   794       last_ping_sent_(0), | 
|   795       last_ping_received_(0), |   795       last_ping_received_(0), | 
|   796       last_data_received_(0), |   796       last_data_received_(0), | 
|   797       last_ping_response_received_(0), |   797       last_ping_response_received_(0), | 
|   798       recv_rate_tracker_(100u, 10u), |   798       recv_rate_tracker_(100u, 10u), | 
|   799       send_rate_tracker_(100u, 10u), |   799       send_rate_tracker_(100u, 10u), | 
|   800       sent_packets_discarded_(0), |   800       sent_packets_discarded_(0), | 
|   801       sent_packets_total_(0), |   801       sent_packets_total_(0), | 
|   802       reported_(false), |   802       reported_(false), | 
|   803       state_(STATE_WAITING), |   803       state_(STATE_WAITING) { | 
|   804       receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT) { |  | 
|   805   // All of our connections start in WAITING state. |   804   // All of our connections start in WAITING state. | 
|   806   // TODO(mallinath) - Start connections from STATE_FROZEN. |   805   // TODO(mallinath) - Start connections from STATE_FROZEN. | 
|   807   // Wire up to send stun packets |   806   // Wire up to send stun packets | 
|   808   requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket); |   807   requests_.SignalSendPacket.connect(this, &Connection::OnSendStunPacket); | 
|   809   LOG_J(LS_INFO, this) << "Connection created"; |   808   LOG_J(LS_INFO, this) << "Connection created"; | 
|   810 } |   809 } | 
|   811  |   810  | 
|   812 Connection::~Connection() { |   811 Connection::~Connection() { | 
|   813 } |   812 } | 
|   814  |   813  | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
|   835       g = remote_candidate_.priority(); |   834       g = remote_candidate_.priority(); | 
|   836       d = local_candidate().priority(); |   835       d = local_candidate().priority(); | 
|   837     } |   836     } | 
|   838     priority = std::min(g, d); |   837     priority = std::min(g, d); | 
|   839     priority = priority << 32; |   838     priority = priority << 32; | 
|   840     priority += 2 * std::max(g, d) + (g > d ? 1 : 0); |   839     priority += 2 * std::max(g, d) + (g > d ? 1 : 0); | 
|   841   } |   840   } | 
|   842   return priority; |   841   return priority; | 
|   843 } |   842 } | 
|   844  |   843  | 
 |   844 void Connection::set_read_state(ReadState value) { | 
 |   845   ReadState old_value = read_state_; | 
 |   846   read_state_ = value; | 
 |   847   if (value != old_value) { | 
 |   848     LOG_J(LS_VERBOSE, this) << "set_read_state"; | 
 |   849     SignalStateChange(this); | 
 |   850     CheckTimeout(); | 
 |   851   } | 
 |   852 } | 
 |   853  | 
|   845 void Connection::set_write_state(WriteState value) { |   854 void Connection::set_write_state(WriteState value) { | 
|   846   WriteState old_value = write_state_; |   855   WriteState old_value = write_state_; | 
|   847   write_state_ = value; |   856   write_state_ = value; | 
|   848   if (value != old_value) { |   857   if (value != old_value) { | 
|   849     LOG_J(LS_VERBOSE, this) << "set_write_state from: " << old_value << " to " |   858     LOG_J(LS_VERBOSE, this) << "set_write_state from: " << old_value << " to " | 
|   850                             << value; |   859                             << value; | 
|   851     SignalStateChange(this); |   860     SignalStateChange(this); | 
|   852     CheckTimeout(); |   861     CheckTimeout(); | 
|   853   } |   862   } | 
|   854 } |  | 
|   855  |  | 
|   856 void Connection::set_receiving(bool value) { |  | 
|   857   if (value != receiving_) { |  | 
|   858     LOG_J(LS_VERBOSE, this) << "set_receiving to " << value; |  | 
|   859     receiving_ = value; |  | 
|   860     SignalStateChange(this); |  | 
|   861     CheckTimeout(); |  | 
|   862   } |  | 
|   863 } |   863 } | 
|   864  |   864  | 
|   865 void Connection::set_state(State state) { |   865 void Connection::set_state(State state) { | 
|   866   State old_state = state_; |   866   State old_state = state_; | 
|   867   state_ = state; |   867   state_ = state; | 
|   868   if (state != old_state) { |   868   if (state != old_state) { | 
|   869     LOG_J(LS_VERBOSE, this) << "set_state"; |   869     LOG_J(LS_VERBOSE, this) << "set_state"; | 
|   870   } |   870   } | 
|   871 } |   871 } | 
|   872  |   872  | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
|   895   } |   895   } | 
|   896 } |   896 } | 
|   897  |   897  | 
|   898 void Connection::OnReadPacket( |   898 void Connection::OnReadPacket( | 
|   899   const char* data, size_t size, const rtc::PacketTime& packet_time) { |   899   const char* data, size_t size, const rtc::PacketTime& packet_time) { | 
|   900   rtc::scoped_ptr<IceMessage> msg; |   900   rtc::scoped_ptr<IceMessage> msg; | 
|   901   std::string remote_ufrag; |   901   std::string remote_ufrag; | 
|   902   const rtc::SocketAddress& addr(remote_candidate_.address()); |   902   const rtc::SocketAddress& addr(remote_candidate_.address()); | 
|   903   if (!port_->GetStunMessage(data, size, addr, msg.accept(), &remote_ufrag)) { |   903   if (!port_->GetStunMessage(data, size, addr, msg.accept(), &remote_ufrag)) { | 
|   904     // The packet did not parse as a valid STUN message |   904     // The packet did not parse as a valid STUN message | 
|   905     // This is a data packet, pass it along. |  | 
|   906     set_receiving(true); |  | 
|   907     last_data_received_ = rtc::Time(); |  | 
|   908     recv_rate_tracker_.AddSamples(size); |  | 
|   909     SignalReadPacket(this, data, size, packet_time); |  | 
|   910  |   905  | 
|   911     // If timed out sending writability checks, start up again |   906     // If this connection is readable, then pass along the packet. | 
|   912     if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) { |   907     if (read_state_ == STATE_READABLE) { | 
|   913       LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. " |   908       // readable means data from this address is acceptable | 
|   914                       << "Resetting state to STATE_WRITE_INIT."; |   909       // Send it on! | 
|   915       set_write_state(STATE_WRITE_INIT); |   910       last_data_received_ = rtc::Time(); | 
 |   911       recv_rate_tracker_.AddSamples(size); | 
 |   912       SignalReadPacket(this, data, size, packet_time); | 
 |   913  | 
 |   914       // If timed out sending writability checks, start up again | 
 |   915       if (!pruned_ && (write_state_ == STATE_WRITE_TIMEOUT)) { | 
 |   916         LOG(LS_WARNING) << "Received a data packet on a timed-out Connection. " | 
 |   917                         << "Resetting state to STATE_WRITE_INIT."; | 
 |   918         set_write_state(STATE_WRITE_INIT); | 
 |   919       } | 
 |   920     } else { | 
 |   921       // Not readable means the remote address hasn't sent a valid | 
 |   922       // binding request yet. | 
 |   923  | 
 |   924       LOG_J(LS_WARNING, this) | 
 |   925         << "Received non-STUN packet from an unreadable connection."; | 
|   916     } |   926     } | 
|   917   } else if (!msg) { |   927   } else if (!msg) { | 
|   918     // The packet was STUN, but failed a check and was handled internally. |   928     // The packet was STUN, but failed a check and was handled internally. | 
|   919   } else { |   929   } else { | 
|   920     // The packet is STUN and passed the Port checks. |   930     // The packet is STUN and passed the Port checks. | 
|   921     // Perform our own checks to ensure this packet is valid. |   931     // Perform our own checks to ensure this packet is valid. | 
|   922     // If this is a STUN request, then update the readable bit and respond. |   932     // If this is a STUN request, then update the readable bit and respond. | 
|   923     // If this is a STUN response, then update the writable bit. |   933     // If this is a STUN response, then update the writable bit. | 
|   924     // Log at LS_INFO if we receive a ping on an unwritable connection. |   934     // Log at LS_INFO if we receive a ping on an unwritable connection. | 
|   925     rtc::LoggingSeverity sev = (!writable() ? rtc::LS_INFO : rtc::LS_VERBOSE); |   935     rtc::LoggingSeverity sev = (!writable() ? rtc::LS_INFO : rtc::LS_VERBOSE); | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   975           requests_.CheckResponse(msg.get()); |   985           requests_.CheckResponse(msg.get()); | 
|   976         } |   986         } | 
|   977         // Otherwise silently discard the response message. |   987         // Otherwise silently discard the response message. | 
|   978         break; |   988         break; | 
|   979  |   989  | 
|   980       // Remote end point sent an STUN indication instead of regular |   990       // Remote end point sent an STUN indication instead of regular | 
|   981       // binding request. In this case |last_ping_received_| will be updated. |   991       // binding request. In this case |last_ping_received_| will be updated. | 
|   982       // Otherwise we can mark connection to read timeout. No response will be |   992       // Otherwise we can mark connection to read timeout. No response will be | 
|   983       // sent in this scenario. |   993       // sent in this scenario. | 
|   984       case STUN_BINDING_INDICATION: |   994       case STUN_BINDING_INDICATION: | 
|   985         ReceivedPing(); |   995         if (read_state_ == STATE_READABLE) { | 
 |   996           ReceivedPing(); | 
 |   997         } else { | 
 |   998           LOG_J(LS_WARNING, this) << "Received STUN binding indication " | 
 |   999                                   << "from an unreadable connection."; | 
 |  1000         } | 
|   986         break; |  1001         break; | 
|   987  |  1002  | 
|   988       default: |  1003       default: | 
|   989         ASSERT(false); |  1004         ASSERT(false); | 
|   990         break; |  1005         break; | 
|   991     } |  1006     } | 
|   992   } |  1007   } | 
|   993 } |  1008 } | 
|   994  |  1009  | 
|   995 void Connection::OnReadyToSend() { |  1010 void Connection::OnReadyToSend() { | 
|   996   if (write_state_ == STATE_WRITABLE) { |  1011   if (write_state_ == STATE_WRITABLE) { | 
|   997     SignalReadyToSend(this); |  1012     SignalReadyToSend(this); | 
|   998   } |  1013   } | 
|   999 } |  1014 } | 
|  1000  |  1015  | 
|  1001 void Connection::Prune() { |  1016 void Connection::Prune() { | 
|  1002   if (!pruned_) { |  1017   if (!pruned_) { | 
|  1003     LOG_J(LS_VERBOSE, this) << "Connection pruned"; |  1018     LOG_J(LS_VERBOSE, this) << "Connection pruned"; | 
|  1004     pruned_ = true; |  1019     pruned_ = true; | 
|  1005     requests_.Clear(); |  1020     requests_.Clear(); | 
|  1006     set_write_state(STATE_WRITE_TIMEOUT); |  1021     set_write_state(STATE_WRITE_TIMEOUT); | 
|  1007   } |  1022   } | 
|  1008 } |  1023 } | 
|  1009  |  1024  | 
|  1010 void Connection::Destroy() { |  1025 void Connection::Destroy() { | 
|  1011   LOG_J(LS_VERBOSE, this) << "Connection destroyed"; |  1026   LOG_J(LS_VERBOSE, this) << "Connection destroyed"; | 
|  1012   port_->thread()->Post(this, MSG_DELETE); |  1027   set_read_state(STATE_READ_TIMEOUT); | 
 |  1028   set_write_state(STATE_WRITE_TIMEOUT); | 
|  1013 } |  1029 } | 
|  1014  |  1030  | 
|  1015 void Connection::PrintPingsSinceLastResponse(std::string* s, size_t max) { |  1031 void Connection::PrintPingsSinceLastResponse(std::string* s, size_t max) { | 
|  1016   std::ostringstream oss; |  1032   std::ostringstream oss; | 
|  1017   oss << std::boolalpha; |  1033   oss << std::boolalpha; | 
|  1018   if (pings_since_last_response_.size() > max) { |  1034   if (pings_since_last_response_.size() > max) { | 
|  1019     for (size_t i = 0; i < max; i++) { |  1035     for (size_t i = 0; i < max; i++) { | 
|  1020       const SentPing& ping = pings_since_last_response_[i]; |  1036       const SentPing& ping = pings_since_last_response_[i]; | 
|  1021       oss << rtc::hex_encode(ping.id) << " "; |  1037       oss << rtc::hex_encode(ping.id) << " "; | 
|  1022     } |  1038     } | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1066                          << " ping failures and " |  1082                          << " ping failures and " | 
|  1067                          << now - pings_since_last_response_[0].sent_time |  1083                          << now - pings_since_last_response_[0].sent_time | 
|  1068                          << " ms without a response," |  1084                          << " ms without a response," | 
|  1069                          << " ms since last received ping=" |  1085                          << " ms since last received ping=" | 
|  1070                          << now - last_ping_received_ |  1086                          << now - last_ping_received_ | 
|  1071                          << " ms since last received data=" |  1087                          << " ms since last received data=" | 
|  1072                          << now - last_data_received_ |  1088                          << now - last_data_received_ | 
|  1073                          << " rtt=" << rtt; |  1089                          << " rtt=" << rtt; | 
|  1074     set_write_state(STATE_WRITE_UNRELIABLE); |  1090     set_write_state(STATE_WRITE_UNRELIABLE); | 
|  1075   } |  1091   } | 
 |  1092  | 
|  1076   if ((write_state_ == STATE_WRITE_UNRELIABLE || |  1093   if ((write_state_ == STATE_WRITE_UNRELIABLE || | 
|  1077        write_state_ == STATE_WRITE_INIT) && |  1094        write_state_ == STATE_WRITE_INIT) && | 
|  1078       TooLongWithoutResponse(pings_since_last_response_, |  1095       TooLongWithoutResponse(pings_since_last_response_, | 
|  1079                              CONNECTION_WRITE_TIMEOUT, |  1096                              CONNECTION_WRITE_TIMEOUT, | 
|  1080                              now)) { |  1097                              now)) { | 
|  1081     LOG_J(LS_INFO, this) << "Timed out after " |  1098     LOG_J(LS_INFO, this) << "Timed out after " | 
|  1082                          << now - pings_since_last_response_[0].sent_time |  1099                          << now - pings_since_last_response_[0].sent_time | 
|  1083                          << " ms without a response" |  1100                          << " ms without a response" | 
|  1084                          << ", rtt=" << rtt; |  1101                          << ", rtt=" << rtt; | 
|  1085     set_write_state(STATE_WRITE_TIMEOUT); |  1102     set_write_state(STATE_WRITE_TIMEOUT); | 
|  1086   } |  1103   } | 
|  1087  |  | 
|  1088   // Check the receiving state. |  | 
|  1089   uint32 last_recv_time = last_received(); |  | 
|  1090   bool receiving = now <= last_recv_time + receiving_timeout_; |  | 
|  1091   set_receiving(receiving); |  | 
|  1092 } |  1104 } | 
|  1093  |  1105  | 
|  1094 void Connection::Ping(uint32 now) { |  1106 void Connection::Ping(uint32 now) { | 
|  1095   last_ping_sent_ = now; |  1107   last_ping_sent_ = now; | 
|  1096   ConnectionRequest *req = new ConnectionRequest(this); |  1108   ConnectionRequest *req = new ConnectionRequest(this); | 
|  1097   pings_since_last_response_.push_back(SentPing(req->id(), now)); |  1109   pings_since_last_response_.push_back(SentPing(req->id(), now)); | 
|  1098   LOG_J(LS_VERBOSE, this) << "Sending STUN ping " |  1110   LOG_J(LS_VERBOSE, this) << "Sending STUN ping " | 
|  1099                           << ", id=" << rtc::hex_encode(req->id()); |  1111                           << ", id=" << rtc::hex_encode(req->id()); | 
|  1100   requests_.Send(req); |  1112   requests_.Send(req); | 
|  1101   state_ = STATE_INPROGRESS; |  1113   state_ = STATE_INPROGRESS; | 
|  1102 } |  1114 } | 
|  1103  |  1115  | 
|  1104 void Connection::ReceivedPing() { |  1116 void Connection::ReceivedPing() { | 
|  1105   set_receiving(true); |  | 
|  1106   last_ping_received_ = rtc::Time(); |  1117   last_ping_received_ = rtc::Time(); | 
 |  1118   set_read_state(STATE_READABLE); | 
|  1107 } |  1119 } | 
|  1108  |  1120  | 
|  1109 void Connection::ReceivedPingResponse() { |  1121 void Connection::ReceivedPingResponse() { | 
|  1110   // We've already validated that this is a STUN binding response with |  1122   // We've already validated that this is a STUN binding response with | 
|  1111   // the correct local and remote username for this connection. |  1123   // the correct local and remote username for this connection. | 
|  1112   // So if we're not already, become writable. We may be bringing a pruned |  1124   // So if we're not already, become writable. We may be bringing a pruned | 
|  1113   // connection back to life, but if we don't really want it, we can always |  1125   // connection back to life, but if we don't really want it, we can always | 
|  1114   // prune it again. |  1126   // prune it again. | 
|  1115   set_receiving(true); |  | 
|  1116   set_write_state(STATE_WRITABLE); |  1127   set_write_state(STATE_WRITABLE); | 
|  1117   set_state(STATE_SUCCEEDED); |  1128   set_state(STATE_SUCCEEDED); | 
|  1118   pings_since_last_response_.clear(); |  1129   pings_since_last_response_.clear(); | 
|  1119   last_ping_response_received_ = rtc::Time(); |  1130   last_ping_response_received_ = rtc::Time(); | 
|  1120 } |  1131 } | 
|  1121  |  1132  | 
|  1122 std::string Connection::ToDebugId() const { |  1133 std::string Connection::ToDebugId() const { | 
|  1123   std::stringstream ss; |  1134   std::stringstream ss; | 
|  1124   ss << std::hex << this; |  1135   ss << std::hex << this; | 
|  1125   return ss.str(); |  1136   return ss.str(); | 
|  1126 } |  1137 } | 
|  1127  |  1138  | 
|  1128 std::string Connection::ToString() const { |  1139 std::string Connection::ToString() const { | 
|  1129   const char CONNECT_STATE_ABBREV[2] = { |  1140   const char CONNECT_STATE_ABBREV[2] = { | 
|  1130     '-',  // not connected (false) |  1141     '-',  // not connected (false) | 
|  1131     'C',  // connected (true) |  1142     'C',  // connected (true) | 
|  1132   }; |  1143   }; | 
|  1133   const char RECEIVE_STATE_ABBREV[2] = { |  1144   const char READ_STATE_ABBREV[3] = { | 
|  1134     '-',  // not receiving (false) |  1145     '-',  // STATE_READ_INIT | 
|  1135     'R',  // receiving (true) |  1146     'R',  // STATE_READABLE | 
 |  1147     'x',  // STATE_READ_TIMEOUT | 
|  1136   }; |  1148   }; | 
|  1137   const char WRITE_STATE_ABBREV[4] = { |  1149   const char WRITE_STATE_ABBREV[4] = { | 
|  1138     'W',  // STATE_WRITABLE |  1150     'W',  // STATE_WRITABLE | 
|  1139     'w',  // STATE_WRITE_UNRELIABLE |  1151     'w',  // STATE_WRITE_UNRELIABLE | 
|  1140     '-',  // STATE_WRITE_INIT |  1152     '-',  // STATE_WRITE_INIT | 
|  1141     'x',  // STATE_WRITE_TIMEOUT |  1153     'x',  // STATE_WRITE_TIMEOUT | 
|  1142   }; |  1154   }; | 
|  1143   const std::string ICESTATE[4] = { |  1155   const std::string ICESTATE[4] = { | 
|  1144     "W",  // STATE_WAITING |  1156     "W",  // STATE_WAITING | 
|  1145     "I",  // STATE_INPROGRESS |  1157     "I",  // STATE_INPROGRESS | 
|  1146     "S",  // STATE_SUCCEEDED |  1158     "S",  // STATE_SUCCEEDED | 
|  1147     "F"   // STATE_FAILED |  1159     "F"   // STATE_FAILED | 
|  1148   }; |  1160   }; | 
|  1149   const Candidate& local = local_candidate(); |  1161   const Candidate& local = local_candidate(); | 
|  1150   const Candidate& remote = remote_candidate(); |  1162   const Candidate& remote = remote_candidate(); | 
|  1151   std::stringstream ss; |  1163   std::stringstream ss; | 
|  1152   ss << "Conn[" << ToDebugId() |  1164   ss << "Conn[" << ToDebugId() | 
|  1153      << ":" << port_->content_name() |  1165      << ":" << port_->content_name() | 
|  1154      << ":" << local.id() << ":" << local.component() |  1166      << ":" << local.id() << ":" << local.component() | 
|  1155      << ":" << local.generation() |  1167      << ":" << local.generation() | 
|  1156      << ":" << local.type() << ":" << local.protocol() |  1168      << ":" << local.type() << ":" << local.protocol() | 
|  1157      << ":" << local.address().ToSensitiveString() |  1169      << ":" << local.address().ToSensitiveString() | 
|  1158      << "->" << remote.id() << ":" << remote.component() |  1170      << "->" << remote.id() << ":" << remote.component() | 
|  1159      << ":" << remote.priority() |  1171      << ":" << remote.priority() | 
|  1160      << ":" << remote.type() << ":" |  1172      << ":" << remote.type() << ":" | 
|  1161      << remote.protocol() << ":" << remote.address().ToSensitiveString() << "|" |  1173      << remote.protocol() << ":" << remote.address().ToSensitiveString() << "|" | 
|  1162      << CONNECT_STATE_ABBREV[connected()] |  1174      << CONNECT_STATE_ABBREV[connected()] | 
|  1163      << RECEIVE_STATE_ABBREV[receiving()] |  1175      << READ_STATE_ABBREV[read_state()] | 
|  1164      << WRITE_STATE_ABBREV[write_state()] |  1176      << WRITE_STATE_ABBREV[write_state()] | 
|  1165      << ICESTATE[state()] << "|" |  1177      << ICESTATE[state()] << "|" | 
|  1166      << priority() << "|"; |  1178      << priority() << "|"; | 
|  1167   if (rtt_ < DEFAULT_RTT) { |  1179   if (rtt_ < DEFAULT_RTT) { | 
|  1168     ss << rtt_ << "]"; |  1180     ss << rtt_ << "]"; | 
|  1169   } else { |  1181   } else { | 
|  1170     ss << "-]"; |  1182     ss << "-]"; | 
|  1171   } |  1183   } | 
|  1172   return ss.str(); |  1184   return ss.str(); | 
|  1173 } |  1185 } | 
|  1174  |  1186  | 
|  1175 std::string Connection::ToSensitiveString() const { |  1187 std::string Connection::ToSensitiveString() const { | 
|  1176   return ToString(); |  1188   return ToString(); | 
|  1177 } |  1189 } | 
|  1178  |  1190  | 
|  1179 void Connection::OnConnectionRequestResponse(ConnectionRequest* request, |  1191 void Connection::OnConnectionRequestResponse(ConnectionRequest* request, | 
|  1180                                              StunMessage* response) { |  1192                                              StunMessage* response) { | 
|  1181   // Log at LS_INFO if we receive a ping response on an unwritable |  1193   // Log at LS_INFO if we receive a ping response on an unwritable | 
|  1182   // connection. |  1194   // connection. | 
|  1183   rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; |  1195   rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; | 
|  1184  |  1196  | 
|  1185   uint32 rtt = request->Elapsed(); |  1197   uint32 rtt = request->Elapsed(); | 
|  1186  |  1198  | 
|  1187   ReceivedPingResponse(); |  1199   ReceivedPingResponse(); | 
 |  1200   if (remote_ice_mode_ == ICEMODE_LITE) { | 
 |  1201     // A ice-lite end point never initiates ping requests. This will allow | 
 |  1202     // us to move to STATE_READABLE without an incoming ping request. | 
 |  1203     set_read_state(STATE_READABLE); | 
 |  1204   } | 
|  1188  |  1205  | 
|  1189   if (LOG_CHECK_LEVEL_V(sev)) { |  1206   if (LOG_CHECK_LEVEL_V(sev)) { | 
|  1190     bool use_candidate = ( |  1207     bool use_candidate = ( | 
|  1191         response->GetByteString(STUN_ATTR_USE_CANDIDATE) != nullptr); |  1208         response->GetByteString(STUN_ATTR_USE_CANDIDATE) != nullptr); | 
|  1192     std::string pings; |  1209     std::string pings; | 
|  1193     PrintPingsSinceLastResponse(&pings, 5); |  1210     PrintPingsSinceLastResponse(&pings, 5); | 
|  1194     LOG_JV(sev, this) << "Received STUN ping response" |  1211     LOG_JV(sev, this) << "Received STUN ping response" | 
|  1195                       << ", id=" << rtc::hex_encode(request->id()) |  1212                       << ", id=" << rtc::hex_encode(request->id()) | 
|  1196                       << ", code=0"  // Makes logging easier to parse. |  1213                       << ", code=0"  // Makes logging easier to parse. | 
|  1197                       << ", rtt=" << rtt |  1214                       << ", rtt=" << rtt | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1245 void Connection::OnConnectionRequestSent(ConnectionRequest* request) { |  1262 void Connection::OnConnectionRequestSent(ConnectionRequest* request) { | 
|  1246   // Log at LS_INFO if we send a ping on an unwritable connection. |  1263   // Log at LS_INFO if we send a ping on an unwritable connection. | 
|  1247   rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; |  1264   rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; | 
|  1248   bool use_candidate = use_candidate_attr(); |  1265   bool use_candidate = use_candidate_attr(); | 
|  1249   LOG_JV(sev, this) << "Sent STUN ping" |  1266   LOG_JV(sev, this) << "Sent STUN ping" | 
|  1250                     << ", id=" << rtc::hex_encode(request->id()) |  1267                     << ", id=" << rtc::hex_encode(request->id()) | 
|  1251                     << ", use_candidate=" << use_candidate; |  1268                     << ", use_candidate=" << use_candidate; | 
|  1252 } |  1269 } | 
|  1253  |  1270  | 
|  1254 void Connection::CheckTimeout() { |  1271 void Connection::CheckTimeout() { | 
|  1255   // If write has timed out and it is not receiving, remove the connection. |  1272   // If both read and write have timed out or read has never initialized, then | 
|  1256   if (!receiving_ && write_state_ == STATE_WRITE_TIMEOUT) { |  1273   // this connection can contribute no more to p2p socket unless at some later | 
 |  1274   // date readability were to come back.  However, we gave readability a long | 
 |  1275   // time to timeout, so at this point, it seems fair to get rid of this | 
 |  1276   // connection. | 
 |  1277   if ((read_state_ == STATE_READ_TIMEOUT || | 
 |  1278        read_state_ == STATE_READ_INIT) && | 
 |  1279       write_state_ == STATE_WRITE_TIMEOUT) { | 
|  1257     port_->thread()->Post(this, MSG_DELETE); |  1280     port_->thread()->Post(this, MSG_DELETE); | 
|  1258   } |  1281   } | 
|  1259 } |  1282 } | 
|  1260  |  1283  | 
|  1261 void Connection::HandleRoleConflictFromPeer() { |  1284 void Connection::HandleRoleConflictFromPeer() { | 
|  1262   port_->SignalRoleConflict(port_); |  1285   port_->SignalRoleConflict(port_); | 
|  1263 } |  1286 } | 
|  1264  |  1287  | 
|  1265 void Connection::MaybeSetRemoteIceCredentials(const std::string& ice_ufrag, |  1288 void Connection::MaybeSetRemoteIceCredentials(const std::string& ice_ufrag, | 
|  1266                                               const std::string& ice_pwd) { |  1289                                               const std::string& ice_pwd) { | 
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1402     ASSERT(sent < 0); |  1425     ASSERT(sent < 0); | 
|  1403     error_ = port_->GetError(); |  1426     error_ = port_->GetError(); | 
|  1404     sent_packets_discarded_++; |  1427     sent_packets_discarded_++; | 
|  1405   } else { |  1428   } else { | 
|  1406     send_rate_tracker_.AddSamples(sent); |  1429     send_rate_tracker_.AddSamples(sent); | 
|  1407   } |  1430   } | 
|  1408   return sent; |  1431   return sent; | 
|  1409 } |  1432 } | 
|  1410  |  1433  | 
|  1411 }  // namespace cricket |  1434 }  // namespace cricket | 
| OLD | NEW |