连通性检测过程
P2PTransportChannel::SortConnectionsAndUpdateState
P2PTransportChannel::MaybeStartPinging
P2PTransportChannel::CheckAndPing
BasicIceController::SelectConnectionToPing
H:\webrtc-20210315\webrtc-20210315\webrtc\webrtc-checkout\src\p2p\base\basic_ice_controller.cc
BasicIceController::FindNextPingableConnection
查找下一个可以ping的连接。
// Returns the next pingable connection to ping.const Connection* BasicIceController::FindNextPingableConnection() {int64_t now = rtc::TimeMillis();// Rule 1: Selected connection takes priority over non-selected ones.if (selected_connection_ && selected_connection_->connected() &&selected_connection_->writable() &&WritableConnectionPastPingInterval(selected_connection_, now)) {return selected_connection_;}// Rule 2: If the channel is weak, we need to find a new writable and// receiving connection, probably on a different network. If there are lots of// connections, it may take several seconds between two pings for every// non-selected connection. This will cause the receiving state of those// connections to be false, and thus they won't be selected. This is// problematic for network fail-over. We want to make sure at least one// connection per network is pinged frequently enough in order for it to be// selectable. So we prioritize one connection per network.// Rule 2.1: Among such connections, pick the one with the earliest// last-ping-sent time.if (weak()) {std::vector<const Connection*> pingable_selectable_connections;absl::c_copy_if(GetBestWritableConnectionPerNetwork(),std::back_inserter(pingable_selectable_connections),[this, now](const Connection* conn) {return WritableConnectionPastPingInterval(conn, now);});auto iter = absl::c_min_element(pingable_selectable_connections,[](const Connection* conn1, const Connection* conn2) {return conn1->last_ping_sent() < conn2->last_ping_sent();});if (iter != pingable_selectable_connections.end()) {return *iter;}}// Rule 3: Triggered checks have priority over non-triggered connections.// Rule 3.1: Among triggered checks, oldest takes precedence.const Connection* oldest_triggered_check =FindOldestConnectionNeedingTriggeredCheck(now);if (oldest_triggered_check) {return oldest_triggered_check;}// Rule 4: Unpinged connections have priority over pinged ones.RTC_CHECK(connections_.size() ==pinged_connections_.size() + unpinged_connections_.size());// If there are unpinged and pingable connections, only ping those.// Otherwise, treat everything as unpinged.// TODO(honghaiz): Instead of adding two separate vectors, we can add a state// "pinged" to filter out unpinged connections.if (absl::c_none_of(unpinged_connections_,[this, now](const Connection* conn) {return this->IsPingable(conn, now);})) {unpinged_connections_.insert(pinged_connections_.begin(),pinged_connections_.end());pinged_connections_.clear();}// Among un-pinged pingable connections, "more pingable" takes precedence.std::vector<const Connection*> pingable_connections;absl::c_copy_if(unpinged_connections_, std::back_inserter(pingable_connections),[this, now](const Connection* conn) { return IsPingable(conn, now); });auto iter = absl::c_max_element(pingable_connections,[this](const Connection* conn1, const Connection* conn2) {// Some implementations of max_element// compare an element with itself.if (conn1 == conn2) {return false;}return MorePingable(conn1, conn2) == conn2;});if (iter != pingable_connections.end()) {return *iter;}return nullptr;}
P2PTransportChannel::PingConnection

当前角色是控制方,才会去判断是否提名,和使用candidate属性。
Connection::Ping
SentPing结构

nomination为0,不提名;大于0,提名
