// Lifetime for STUN ports on high-cost networks: 2 minutes inline constexpr TimeDelta kHighCostPortKeepaliveLifetime =
TimeDelta::Seconds(2 * 60);
// Communicates using the address on the outside of a NAT. class RTC_EXPORT UDPPort : public Port {
public: static std::unique_ptr<UDPPort> Create( const PortParametersRef& args,
AsyncPacketSocket* socket, bool emit_local_for_anyaddress,
std::optional<TimeDelta> stun_keepalive_interval) { // Using `new` to access a non-public constructor. auto port = absl::WrapUnique(new UDPPort(
args, IceCandidateType::kHost, socket, emit_local_for_anyaddress));
port->set_stun_keepalive_delay(stun_keepalive_interval); if (!port->Init()) { return nullptr;
} return port;
}
static std::unique_ptr<UDPPort> Create( const PortParametersRef& args,
uint16_t min_port,
uint16_t max_port, bool emit_local_for_anyaddress,
std::optional<TimeDelta> stun_keepalive_interval) { // Using `new` to access a non-public constructor. auto port =
absl::WrapUnique(new UDPPort(args, IceCandidateType::kHost, min_port,
max_port, emit_local_for_anyaddress));
port->set_stun_keepalive_delay(stun_keepalive_interval); if (!port->Init()) { return nullptr;
} return port;
}
// This method will send STUN binding request if STUN server address is set. void MaybePrepareStunCandidate();
void SendStunBindingRequests();
// Helper function which will set `addr`'s IP to the default local address if // `addr` is the "any" address and `emit_local_for_anyaddress_` is true. When // returning false, it indicates that the operation has failed and the // address shouldn't be used by any candidate. bool MaybeSetDefaultLocalAddress(SocketAddress* addr) const;
private: // A helper class which can be called repeatedly to resolve multiple // addresses, as opposed to AsyncDnsResolverInterface, which can only // resolve one address per instance. class AddressResolver {
public: explicit AddressResolver(
PacketSocketFactory* factory,
std::function<void(const SocketAddress&, int)> done_callback);
void Resolve(const SocketAddress& address, int family, const FieldTrialsView& field_trials); bool GetResolvedAddress(const SocketAddress& input, int family,
SocketAddress* output) const;
PacketSocketFactory* socket_factory_; // The function is called when resolving the specified address is finished. // The first argument is the input address, the second argument is the error // or 0 if it succeeded.
std::function<void(const SocketAddress&, int)> done_; // Resolver may fire callbacks that refer to done_, so ensure // that all resolvers are destroyed first.
ResolverMap resolvers_;
};
// DNS resolution of the STUN server. void ResolveStunAddress(const SocketAddress& stun_addr); void OnResolveResult(const SocketAddress& input, int error);
// Send a STUN binding request to the given address. Calling this method may // cause the set of known server addresses to be modified, eg. by replacing an // unresolved server address with a resolved address. void SendStunBindingRequest(const SocketAddress& stun_addr);
// If this is a low-cost network, it will keep on sending STUN binding // requests indefinitely to keep the NAT binding alive. Otherwise, stop // sending STUN binding requests after kHighCostPortKeepaliveLifetime.
TimeDelta GetStunKeepaliveLifetime() { return (network_cost() >= kNetworkCostHigh) ? kHighCostPortKeepaliveLifetime
: TimeDelta::PlusInfinity();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.