0
Files
src/remoting/protocol/port_allocator.h
Yuwei Huang 6e397a7459 [crd host] Allow for applying network settings after authenticated
This is split off from crrev.com/c/5805923, which includes changes in
SessionPolicies that we haven't settle down. The point of this CL is to
refactor the host code so that ClientSession can provide NetworkSettings
after authenticated, rather than using some NetworkSettings object that
is cached for the whole process. Currently it still just reads
NetworkSettings from TransportContext, but it will eventually be
removed.

Things done in this CL:

1. Update PortAllocator so that it can apply NetworkSettings after its
   creation. Also add a CHECK to ensure no PortAllocator sessions are
   created before the settings are applied.
2. Update WebRTC/ICE transports to allow for accepting NetworkSettings
   from ClientSession. Since transports may attempt to start port
   allocations before NetworkSettings are received, some extra logic is
   added to delay port allocation until NetworkSettings are received.

Tested with the website client (WebRTC) and the iOS client (ICE) and
verified that things still work.

Bug: 359977809
Change-Id: I193f95407281cb0be794a6a992eb1fc66ed0ce3f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5807721
Reviewed-by: Joe Downing <joedow@chromium.org>
Commit-Queue: Yuwei Huang <yuweih@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1346423}
2024-08-25 06:46:45 +00:00

86 lines
2.6 KiB
C++

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_PROTOCOL_PORT_ALLOCATOR_H_
#define REMOTING_PROTOCOL_PORT_ALLOCATOR_H_
#include <string>
#include <string_view>
#include <vector>
#include "base/memory/weak_ptr.h"
#include "remoting/protocol/ice_config.h"
#include "remoting/protocol/network_settings.h"
#include "remoting/protocol/transport_context.h"
#include "third_party/webrtc/p2p/client/basic_port_allocator.h"
namespace remoting::protocol {
class PortAllocator : public cricket::BasicPortAllocator {
public:
PortAllocator(std::unique_ptr<rtc::NetworkManager> network_manager,
std::unique_ptr<rtc::PacketSocketFactory> socket_factory,
scoped_refptr<TransportContext> transport_context);
~PortAllocator() override;
void ApplyNetworkSettings(const NetworkSettings& network_settings);
scoped_refptr<TransportContext> transport_context() {
return transport_context_;
}
cricket::PortAllocatorSession* CreateSessionInternal(
std::string_view content_name,
int component,
std::string_view ice_ufrag,
std::string_view ice_pwd) override;
base::WeakPtr<PortAllocator> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
private:
std::unique_ptr<rtc::NetworkManager> network_manager_;
std::unique_ptr<rtc::PacketSocketFactory> socket_factory_;
scoped_refptr<TransportContext> transport_context_;
bool network_settings_applied_ = false;
base::WeakPtrFactory<PortAllocator> weak_factory_{this};
};
class PortAllocatorSession : public cricket::BasicPortAllocatorSession {
public:
PortAllocatorSession(PortAllocator* allocator,
const std::string& content_name,
int component,
const std::string& ice_ufrag,
const std::string& ice_pwd);
~PortAllocatorSession() override;
private:
bool relay_enabled() {
return !(flags() & cricket::PORTALLOCATOR_DISABLE_RELAY);
}
// BasicPortAllocatorSession overrides.
void GetPortConfigurations() override;
// Callback for TransportContext::GetIceConfig().
void OnIceConfig(const IceConfig& ice_config);
// Creates PortConfiguration that includes STUN and TURN servers from
// |ice_config_|.
std::unique_ptr<cricket::PortConfiguration> GetPortConfiguration();
scoped_refptr<TransportContext> transport_context_;
IceConfig ice_config_;
base::WeakPtrFactory<PortAllocatorSession> weak_factory_{this};
};
} // namespace remoting::protocol
#endif // REMOTING_PROTOCOL_PORT_ALLOCATOR_H_