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