forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Remoting Host] Enable RFC 7050 IP synthesis on hosts
This CL enables DNS64/NAT64 prefix discovery and IP synthesis on the host. This allows hosts on DNS64/NAT64 network to connect to our IPv4-only relay servers using Chromotocol. Connections via WebRTC are not affected because they have IPv6 relay endpoints. As stated in CL 1392286, this does not fix direct/STUN connection between IPv4-only and DNS64/NAT64 peers. Non-NaCl platforms support NetworkChangeNotifier so the host will refresh the prefix only when the network interface has been changed, rather than refreshing it every time we are about to make the connection. Bug: 914617 Change-Id: I458156fa1221d8755e84e62b8409b1cb15d1f024 Reviewed-on: https://chromium-review.googlesource.com/c/1392360 Commit-Queue: Yuwei Huang <yuweih@chromium.org> Reviewed-by: Joe Downing <joedow@chromium.org> Cr-Commit-Position: refs/heads/master@{#621399}
- Loading branch information
Showing
9 changed files
with
159 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "remoting/protocol/rfc7050_prefix_refresher.h" | ||
|
||
#include "base/bind.h" | ||
#include "base/bind_helpers.h" | ||
#include "base/logging.h" | ||
#include "base/threading/thread_task_runner_handle.h" | ||
#include "base/time/time.h" | ||
#include "remoting/protocol/rfc7050_ip_synthesizer.h" | ||
|
||
namespace { | ||
// Network changes will fire multiple notifications in a short period of time. | ||
// This delay reduces the number of DNS queries being sent out. | ||
constexpr base::TimeDelta kRefreshDelay = | ||
base::TimeDelta::FromMilliseconds(500); | ||
} // namespace | ||
|
||
namespace remoting { | ||
namespace protocol { | ||
|
||
Rfc7050PrefixRefresher::Rfc7050PrefixRefresher() | ||
: ip_synthesizer_(Rfc7050IpSynthesizer::GetInstance()), | ||
task_runner_(base::ThreadTaskRunnerHandle::Get()), | ||
weak_factory_(this) { | ||
DCHECK(net::NetworkChangeNotifier::HasNetworkChangeNotifier()); | ||
|
||
// The first update should be run immediately so that the IP synthesizer is | ||
// ready to use right after the constructor is run. | ||
OnUpdateDns64Prefix(); | ||
|
||
net::NetworkChangeNotifier::AddNetworkChangeObserver(this); | ||
net::NetworkChangeNotifier::AddDNSObserver(this); | ||
} | ||
|
||
Rfc7050PrefixRefresher::~Rfc7050PrefixRefresher() { | ||
net::NetworkChangeNotifier::RemoveDNSObserver(this); | ||
net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); | ||
} | ||
|
||
void Rfc7050PrefixRefresher::OnDNSChanged() { | ||
ScheduleUpdateDns64Prefix(); | ||
} | ||
|
||
void Rfc7050PrefixRefresher::OnNetworkChanged( | ||
net::NetworkChangeNotifier::ConnectionType type) { | ||
ScheduleUpdateDns64Prefix(); | ||
} | ||
|
||
void Rfc7050PrefixRefresher::ScheduleUpdateDns64Prefix() { | ||
DCHECK(task_runner_->BelongsToCurrentThread()); | ||
if (update_dns64_prefix_scheduled_) { | ||
return; | ||
} | ||
update_dns64_prefix_scheduled_ = true; | ||
task_runner_->PostDelayedTask( | ||
FROM_HERE, | ||
base::BindOnce(&Rfc7050PrefixRefresher::OnUpdateDns64Prefix, | ||
weak_factory_.GetWeakPtr()), | ||
kRefreshDelay); | ||
} | ||
|
||
void Rfc7050PrefixRefresher::OnUpdateDns64Prefix() { | ||
DCHECK(task_runner_->BelongsToCurrentThread()); | ||
update_dns64_prefix_scheduled_ = false; | ||
ip_synthesizer_->UpdateDns64Prefix(base::DoNothing()); | ||
} | ||
|
||
} // namespace protocol | ||
} // namespace remoting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef REMOTING_PROTOCOL_RFC7050_PREFIX_REFRESHER_H_ | ||
#define REMOTING_PROTOCOL_RFC7050_PREFIX_REFRESHER_H_ | ||
|
||
#include "base/macros.h" | ||
#include "base/memory/ref_counted.h" | ||
#include "base/memory/weak_ptr.h" | ||
#include "base/single_thread_task_runner.h" | ||
#include "net/base/network_change_notifier.h" | ||
|
||
namespace remoting { | ||
namespace protocol { | ||
|
||
class Rfc7050IpSynthesizer; | ||
|
||
// Helper class to observe network changes and update Rfc7050IpSynthesizer's | ||
// DNS64 prefix when the network is changed. | ||
class Rfc7050PrefixRefresher | ||
: public net::NetworkChangeNotifier::DNSObserver, | ||
public net::NetworkChangeNotifier::NetworkChangeObserver { | ||
public: | ||
Rfc7050PrefixRefresher(); | ||
~Rfc7050PrefixRefresher() override; | ||
|
||
private: | ||
// DNSObserver override. | ||
void OnDNSChanged() override; | ||
|
||
// NetworkChangeObserver override. | ||
void OnNetworkChanged( | ||
net::NetworkChangeNotifier::ConnectionType type) override; | ||
|
||
void ScheduleUpdateDns64Prefix(); | ||
void OnUpdateDns64Prefix(); | ||
|
||
bool update_dns64_prefix_scheduled_ = false; | ||
Rfc7050IpSynthesizer* ip_synthesizer_; | ||
scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | ||
base::WeakPtrFactory<Rfc7050PrefixRefresher> weak_factory_; | ||
DISALLOW_COPY_AND_ASSIGN(Rfc7050PrefixRefresher); | ||
}; | ||
|
||
} // namespace protocol | ||
} // namespace remoting | ||
|
||
#endif // REMOTING_PROTOCOL_RFC7050_PREFIX_REFRESHER_H_ |