[Connection] Remove class friendship
...for P2PTransportChannel and Port. Bug: webrtc:10647 Change-Id: I93231bb316792f9cd2173fbff936025e50c6ef33 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264148 Reviewed-by: Jonas Oreland <jonaso@webrtc.org> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#37018}
This commit is contained in:
parent
bfd30652b5
commit
2d133637d1
@ -115,6 +115,11 @@ class Connection : public CandidatePairInterface {
|
||||
bool writable() const;
|
||||
bool receiving() const;
|
||||
|
||||
const Port* port() const {
|
||||
RTC_DCHECK_RUN_ON(network_thread_);
|
||||
return port_.get();
|
||||
}
|
||||
|
||||
// Determines whether the connection has finished connecting. This can only
|
||||
// be false for TCP connections.
|
||||
bool connected() const;
|
||||
@ -355,7 +360,6 @@ class Connection : public CandidatePairInterface {
|
||||
|
||||
// The local port where this connection sends and receives packets.
|
||||
Port* port() { return port_.get(); }
|
||||
const Port* port() const { return port_.get(); }
|
||||
|
||||
// NOTE: A pointer to the network thread is held by `port_` so in theory we
|
||||
// shouldn't need to hold on to this pointer here, but rather defer to
|
||||
@ -464,9 +468,7 @@ class Connection : public CandidatePairInterface {
|
||||
rtc::EventBasedExponentialMovingAverage rtt_estimate_
|
||||
RTC_GUARDED_BY(network_thread_);
|
||||
|
||||
friend class Port;
|
||||
friend class ConnectionRequest;
|
||||
friend class P2PTransportChannel;
|
||||
};
|
||||
|
||||
// ProxyConnection defers all the interesting work to the port.
|
||||
|
||||
@ -203,8 +203,6 @@ P2PTransportChannel::P2PTransportChannel(
|
||||
IceControllerFactoryArgs args{
|
||||
[this] { return GetState(); }, [this] { return GetIceRole(); },
|
||||
[this](const Connection* connection) {
|
||||
// TODO(webrtc:10647/jonaso): Figure out a way to remove friendship
|
||||
// between P2PTransportChannel and Connection.
|
||||
return IsPortPruned(connection->port()) ||
|
||||
IsRemoteCandidatePruned(connection->remote_candidate());
|
||||
},
|
||||
@ -1832,6 +1830,24 @@ void P2PTransportChannel::PruneConnections() {
|
||||
}
|
||||
}
|
||||
|
||||
rtc::NetworkRoute P2PTransportChannel::ConfigureNetworkRoute(
|
||||
const Connection* conn) {
|
||||
RTC_DCHECK_RUN_ON(network_thread_);
|
||||
return {
|
||||
.connected = ReadyToSend(conn),
|
||||
.local = CreateRouteEndpointFromCandidate(
|
||||
/* local= */ true, conn->local_candidate(),
|
||||
/* uses_turn= */
|
||||
conn->port()->Type() == RELAY_PORT_TYPE),
|
||||
.remote = CreateRouteEndpointFromCandidate(
|
||||
/* local= */ false, conn->remote_candidate(),
|
||||
/* uses_turn= */ conn->remote_candidate().type() == RELAY_PORT_TYPE),
|
||||
.last_sent_packet_id = last_sent_packet_id_,
|
||||
.packet_overhead =
|
||||
conn->local_candidate().address().ipaddr().overhead() +
|
||||
GetProtocolOverhead(conn->local_candidate().protocol())};
|
||||
}
|
||||
|
||||
// Change the selected connection, and let listeners know.
|
||||
void P2PTransportChannel::SwitchSelectedConnection(Connection* conn,
|
||||
IceControllerEvent reason) {
|
||||
@ -1865,21 +1881,7 @@ void P2PTransportChannel::SwitchSelectedConnection(Connection* conn,
|
||||
SignalReadyToSend(this);
|
||||
}
|
||||
|
||||
network_route_.emplace(rtc::NetworkRoute());
|
||||
network_route_->connected = ReadyToSend(selected_connection_);
|
||||
network_route_->local = CreateRouteEndpointFromCandidate(
|
||||
/* local= */ true, selected_connection_->local_candidate(),
|
||||
/* uses_turn= */ selected_connection_->port()->Type() ==
|
||||
RELAY_PORT_TYPE);
|
||||
network_route_->remote = CreateRouteEndpointFromCandidate(
|
||||
/* local= */ false, selected_connection_->remote_candidate(),
|
||||
/* uses_turn= */ selected_connection_->remote_candidate().type() ==
|
||||
RELAY_PORT_TYPE);
|
||||
|
||||
network_route_->last_sent_packet_id = last_sent_packet_id_;
|
||||
network_route_->packet_overhead =
|
||||
selected_connection_->local_candidate().address().ipaddr().overhead() +
|
||||
GetProtocolOverhead(selected_connection_->local_candidate().protocol());
|
||||
network_route_.emplace(ConfigureNetworkRoute(selected_connection_));
|
||||
} else {
|
||||
RTC_LOG(LS_INFO) << ToString() << ": No selected connection";
|
||||
}
|
||||
@ -2051,7 +2053,7 @@ void P2PTransportChannel::HandleAllTimedOut() {
|
||||
OnSelectedConnectionDestroyed();
|
||||
}
|
||||
|
||||
bool P2PTransportChannel::ReadyToSend(Connection* connection) const {
|
||||
bool P2PTransportChannel::ReadyToSend(const Connection* connection) const {
|
||||
RTC_DCHECK_RUN_ON(network_thread_);
|
||||
// Note that we allow sending on an unreliable connection, because it's
|
||||
// possible that it became unreliable simply due to bad chance.
|
||||
|
||||
@ -254,7 +254,7 @@ class RTC_EXPORT P2PTransportChannel : public IceTransportInternal {
|
||||
}
|
||||
|
||||
// Returns true if it's possible to send packets on `connection`.
|
||||
bool ReadyToSend(Connection* connection) const;
|
||||
bool ReadyToSend(const Connection* connection) const;
|
||||
bool PresumedWritable(const Connection* conn) const;
|
||||
void UpdateConnectionStates();
|
||||
void RequestSortAndStateUpdate(IceControllerEvent reason_to_sort);
|
||||
@ -265,6 +265,7 @@ class RTC_EXPORT P2PTransportChannel : public IceTransportInternal {
|
||||
void SortConnectionsAndUpdateState(IceControllerEvent reason_to_sort);
|
||||
void SortConnections();
|
||||
void SortConnectionsIfNeeded();
|
||||
rtc::NetworkRoute ConfigureNetworkRoute(const Connection* conn);
|
||||
void SwitchSelectedConnection(Connection* conn, IceControllerEvent reason);
|
||||
void UpdateState();
|
||||
void HandleAllTimedOut();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user