diff --git a/p2p/base/connection.cc b/p2p/base/connection.cc index 876deb1b37..2aa5070e33 100644 --- a/p2p/base/connection.cc +++ b/p2p/base/connection.cc @@ -162,13 +162,27 @@ constexpr int kSupportGoogPingVersionResponseIndex = namespace cricket { +class Connection::ConnectionRequest : public StunRequest { + public: + ConnectionRequest(StunRequestManager& manager, Connection* connection); + void Prepare(StunMessage* message) override; + void OnResponse(StunMessage* response) override; + void OnErrorResponse(StunMessage* response) override; + void OnTimeout() override; + void OnSent() override; + int resend_delay() override; + + private: + Connection* const connection_; +}; + // A ConnectionRequest is a STUN binding used to determine writability. -ConnectionRequest::ConnectionRequest(StunRequestManager& manager, - Connection* connection) +Connection::ConnectionRequest::ConnectionRequest(StunRequestManager& manager, + Connection* connection) : StunRequest(manager, std::make_unique()), connection_(connection) {} -void ConnectionRequest::Prepare(StunMessage* message) { +void Connection::ConnectionRequest::Prepare(StunMessage* message) { RTC_DCHECK_RUN_ON(connection_->network_thread_); message->SetType(STUN_BINDING_REQUEST); std::string username; @@ -258,22 +272,22 @@ void ConnectionRequest::Prepare(StunMessage* message) { } } -void ConnectionRequest::OnResponse(StunMessage* response) { +void Connection::ConnectionRequest::OnResponse(StunMessage* response) { RTC_DCHECK_RUN_ON(connection_->network_thread_); connection_->OnConnectionRequestResponse(this, response); } -void ConnectionRequest::OnErrorResponse(StunMessage* response) { +void Connection::ConnectionRequest::OnErrorResponse(StunMessage* response) { RTC_DCHECK_RUN_ON(connection_->network_thread_); connection_->OnConnectionRequestErrorResponse(this, response); } -void ConnectionRequest::OnTimeout() { +void Connection::ConnectionRequest::OnTimeout() { RTC_DCHECK_RUN_ON(connection_->network_thread_); connection_->OnConnectionRequestTimeout(this); } -void ConnectionRequest::OnSent() { +void Connection::ConnectionRequest::OnSent() { RTC_DCHECK_RUN_ON(connection_->network_thread_); connection_->OnConnectionRequestSent(this); // Each request is sent only once. After a single delay , the request will @@ -281,7 +295,7 @@ void ConnectionRequest::OnSent() { set_timed_out(); } -int ConnectionRequest::resend_delay() { +int Connection::ConnectionRequest::resend_delay() { return CONNECTION_RESPONSE_TIMEOUT; } @@ -1313,7 +1327,7 @@ void Connection::LogCandidatePairEvent(webrtc::IceCandidatePairEventType type, ice_event_log_->LogCandidatePairEvent(type, id(), transaction_id); } -void Connection::OnConnectionRequestResponse(ConnectionRequest* request, +void Connection::OnConnectionRequestResponse(StunRequest* request, StunMessage* response) { RTC_DCHECK_RUN_ON(network_thread_); // Log at LS_INFO if we receive a ping response on an unwritable @@ -1498,7 +1512,7 @@ ConnectionInfo Connection::stats() { return stats_; } -void Connection::MaybeUpdateLocalCandidate(ConnectionRequest* request, +void Connection::MaybeUpdateLocalCandidate(StunRequest* request, StunMessage* response) { // RFC 5245 // The agent checks the mapped address from the STUN response. If the diff --git a/p2p/base/connection.h b/p2p/base/connection.h index 35b168e1b9..83077d2f17 100644 --- a/p2p/base/connection.h +++ b/p2p/base/connection.h @@ -55,21 +55,6 @@ struct CandidatePair final : public CandidatePairInterface { Candidate remote; }; -// A ConnectionRequest is a simple STUN ping used to determine writability. -class ConnectionRequest : public StunRequest { - public: - ConnectionRequest(StunRequestManager& manager, Connection* connection); - void Prepare(StunMessage* message) override; - void OnResponse(StunMessage* response) override; - void OnErrorResponse(StunMessage* response) override; - void OnTimeout() override; - void OnSent() override; - int resend_delay() override; - - private: - Connection* const connection_; -}; - // Represents a communication link between a port on the local client and a // port on the remote client. class Connection : public CandidatePairInterface { @@ -329,6 +314,9 @@ class Connection : public CandidatePairInterface { void set_remote_nomination(uint32_t remote_nomination); protected: + // A ConnectionRequest is a simple STUN ping used to determine writability. + class ConnectionRequest; + // Constructs a new connection to the given remote port. Connection(rtc::WeakPtr port, size_t index, const Candidate& candidate); @@ -336,7 +324,7 @@ class Connection : public CandidatePairInterface { void OnSendStunPacket(const void* data, size_t size, StunRequest* req); // Callbacks from ConnectionRequest - virtual void OnConnectionRequestResponse(ConnectionRequest* req, + virtual void OnConnectionRequestResponse(StunRequest* req, StunMessage* response); void OnConnectionRequestErrorResponse(ConnectionRequest* req, StunMessage* response) @@ -380,8 +368,7 @@ class Connection : public CandidatePairInterface { private: // Update the local candidate based on the mapped address attribute. // If the local candidate changed, fires SignalStateChange. - void MaybeUpdateLocalCandidate(ConnectionRequest* request, - StunMessage* response) + void MaybeUpdateLocalCandidate(StunRequest* request, StunMessage* response) RTC_RUN_ON(network_thread_); void LogCandidatePairConfig(webrtc::IceCandidatePairConfigType type) @@ -467,8 +454,6 @@ class Connection : public CandidatePairInterface { const IceFieldTrials* field_trials_; rtc::EventBasedExponentialMovingAverage rtt_estimate_ RTC_GUARDED_BY(network_thread_); - - friend class ConnectionRequest; }; // ProxyConnection defers all the interesting work to the port. diff --git a/p2p/base/tcp_port.cc b/p2p/base/tcp_port.cc index 433f0871e9..ee644eb7f4 100644 --- a/p2p/base/tcp_port.cc +++ b/p2p/base/tcp_port.cc @@ -419,7 +419,7 @@ int TCPConnection::GetError() { return error_; } -void TCPConnection::OnConnectionRequestResponse(ConnectionRequest* req, +void TCPConnection::OnConnectionRequestResponse(StunRequest* req, StunMessage* response) { // Process the STUN response before we inform upper layer ready to send. Connection::OnConnectionRequestResponse(req, response); diff --git a/p2p/base/tcp_port.h b/p2p/base/tcp_port.h index 6bd935f613..958666e3b9 100644 --- a/p2p/base/tcp_port.h +++ b/p2p/base/tcp_port.h @@ -148,7 +148,7 @@ class TCPConnection : public Connection, public sigslot::has_slots<> { protected: // Set waiting_for_stun_binding_complete_ to false to allow data packets in // addition to what Port::OnConnectionRequestResponse does. - void OnConnectionRequestResponse(ConnectionRequest* req, + void OnConnectionRequestResponse(StunRequest* req, StunMessage* response) override; private: