Skip to content

Commit

Permalink
Make sure all tor profile have proper proxy config
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdh committed Nov 18, 2020
1 parent dfd40f7 commit 834a46b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions components/tor/tor_launcher_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ void TorLauncherFactory::GotSOCKSListeners(
tor_proxy_uri.erase(
std::remove(tor_proxy_uri.begin(), tor_proxy_uri.end(), '\"'),
tor_proxy_uri.end());
tor_proxy_uri_ = tor_proxy_uri;
for (auto& observer : observers_)
observer.NotifyTorNewProxyURI(tor_proxy_uri);
}
Expand Down
3 changes: 3 additions & 0 deletions components/tor/tor_launcher_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class TorLauncherFactory : public tor::TorControl::Delegate {
void KillTorProcess();
int64_t GetTorPid() const { return tor_pid_; }
bool IsTorConnected() const { return is_connected_; }
std::string GetTorProxyURI() const { return tor_proxy_uri_; }

void AddObserver(tor::TorProfileServiceImpl* serice);
void RemoveObserver(tor::TorProfileServiceImpl* service);
Expand Down Expand Up @@ -72,6 +73,8 @@ class TorLauncherFactory : public tor::TorControl::Delegate {

mojo::Remote<tor::mojom::TorLauncher> tor_launcher_;

std::string tor_proxy_uri_;

int64_t tor_pid_;

tor::mojom::TorConfig config_;
Expand Down
12 changes: 11 additions & 1 deletion components/tor/tor_profile_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,17 @@ void TorProfileServiceImpl::NotifyTorInitializing(

std::unique_ptr<net::ProxyConfigService>
TorProfileServiceImpl::CreateProxyConfigService() {
proxy_config_service_ = new net::ProxyConfigServiceTor();
// First tor profile will have empty proxy uri but it will receive update from
// NotifyTorNewProxyURI. And subsequent tor profile might not have
// NotifyTorNewProxyURI because it is called once when tor control is ready.
const std::string tor_proxy_uri = tor_launcher_factory_->GetTorProxyURI();
if (tor_proxy_uri.empty()) {
proxy_config_service_ =
new net::ProxyConfigServiceTor();
} else {
proxy_config_service_ =
new net::ProxyConfigServiceTor(tor_proxy_uri);
}
return std::unique_ptr<net::ProxyConfigServiceTor>(proxy_config_service_);
}

Expand Down

0 comments on commit 834a46b

Please sign in to comment.