Compare commits

..

9 Commits

Author SHA1 Message Date
klzgrad
ca7b43eaa7 Add continuous integration and tests 2022-05-21 16:38:46 +08:00
klzgrad
6b3d013dd4 Add build scripts 2022-05-21 16:38:46 +08:00
klzgrad
7d42cd8e93 Add example config.json 2022-05-21 16:38:46 +08:00
klzgrad
8c04cadb5a Add README 2022-05-21 16:38:46 +08:00
klzgrad
10abd3cec1 Add LICENSE 2022-05-21 16:38:46 +08:00
klzgrad
cc6a6fd247 Add source import tool 2022-05-21 16:38:46 +08:00
klzgrad
57f567c2b9 Add Cronet CGO SDK builder
bidi_example.cc does not work in cross compile yet, because libstdc++-dev
is not installed in cross compile sysroots.
2022-05-21 16:38:17 +08:00
klzgrad
7804341572 Add initial implementation of Naive client 2022-05-21 16:32:35 +08:00
klzgrad
c1fd469d0f cronet: Use fixed proxy resolution from experiment option proxy_server 2022-05-21 16:32:35 +08:00
11 changed files with 19 additions and 115 deletions

View File

@ -111,18 +111,6 @@ if (false) {
configs -= [ "//build/config/compiler:thin_archive" ]
}
executable("cronet_example") {
testonly = true
sources = [ "native/sample/bidi_example.cc" ]
deps = [
"//components/cronet",
"//components/cronet/native:cronet_native_headers",
]
if ((is_linux || is_chromeos) && !is_component_build) {
public_configs = [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
}
}
executable("cronet_example_external") {
testonly = true
no_default_deps = true

View File

@ -146,8 +146,7 @@ void PostTaskToInitThread(const base::Location& posted_from,
g_init_task_executor->task_runner()->PostTask(posted_from, std::move(task));
}
void EnsureInitialized(const char* /*enable_features*/,
const char* /*disable_features*/) {
void EnsureInitialized() {
if (g_init_task_executor) {
// Ensure that init is done on the init thread.
g_init_thread_init_done.Wait();

View File

@ -357,10 +357,9 @@ CronetContext::NetworkTasks::BuildDefaultURLRequestContext(
SetSharedURLRequestContextBuilderConfig(&context_builder);
const auto proxy_server_it =
context_config_->effective_experimental_options.find("proxy_server");
context_config_->experimental_options.find("proxy_server");
std::string proxy_server_str = "direct://";
if (proxy_server_it !=
context_config_->effective_experimental_options.end()) {
if (proxy_server_it != context_config_->experimental_options.end()) {
const base::Value& value = proxy_server_it->second;
if (value.is_string()) {
proxy_server_str = value.GetString();

View File

@ -31,8 +31,7 @@ void PostTaskToInitThread(const base::Location& posted_from,
// or binding to an existing thread, to run initialization and process
// network notifications on. The implementation must be thread-safe and
// idempotent, and must complete initialization before returning.
void EnsureInitialized(const char* enable_features = nullptr,
const char* disable_features = nullptr);
void EnsureInitialized();
// Creates a proxy config service appropriate for this platform that fetches the
// system proxy settings. Cronet will call this API only after a prior call

View File

@ -22,18 +22,14 @@ namespace cronet {
namespace {
scoped_refptr<base::SingleThreadTaskRunner> InitializeAndCreateTaskRunner(
const char* enable_features,
const char* disable_features) {
scoped_refptr<base::SingleThreadTaskRunner> InitializeAndCreateTaskRunner() {
// Cronet tests sets AtExitManager as part of TestSuite, so statically linked
// library is not allowed to set its own.
#if !defined(CRONET_TESTS_IMPLEMENTATION)
std::ignore = new base::AtExitManager;
#endif
base::FeatureList::InitializeInstance(
enable_features ? enable_features : "",
disable_features ? disable_features : "");
base::FeatureList::InitializeInstance(std::string(), std::string());
// Note that in component builds this ThreadPoolInstance will be shared with
// the calling process, if it also depends on //base. In particular this means
@ -44,19 +40,16 @@ scoped_refptr<base::SingleThreadTaskRunner> InitializeAndCreateTaskRunner(
return base::ThreadPool::CreateSingleThreadTaskRunner({});
}
base::SingleThreadTaskRunner* InitTaskRunner(
const char* enable_features = nullptr,
const char* disable_features = nullptr) {
base::SingleThreadTaskRunner* InitTaskRunner() {
static scoped_refptr<base::SingleThreadTaskRunner> init_task_runner =
InitializeAndCreateTaskRunner(enable_features, disable_features);
InitializeAndCreateTaskRunner();
return init_task_runner.get();
}
} // namespace
void EnsureInitialized(const char* enable_features,
const char* disable_features) {
std::ignore = InitTaskRunner(enable_features, disable_features);
void EnsureInitialized() {
std::ignore = InitTaskRunner();
}
bool OnInitThread() {

View File

@ -7,7 +7,6 @@
#include <unordered_set>
#include <utility>
#include "base/base_switches.h"
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/files/file_path.h"
@ -103,25 +102,6 @@ Cronet_EngineImpl::~Cronet_EngineImpl() {
Cronet_RESULT Cronet_EngineImpl::StartWithParams(
Cronet_EngineParamsPtr params) {
absl::optional<base::Value::DictStorage> experimental_options =
URLRequestContextConfig::ParseExperimentalOptions(
params->experimental_options);
if (experimental_options) {
const auto& iter = experimental_options->find("feature_list");
if (iter != experimental_options->end()) {
const base::Value& feature_list = iter->second;
if (feature_list.is_dict()) {
const std::string* enable_features =
feature_list.GetDict().FindString(switches::kEnableFeatures);
const std::string* disable_features =
feature_list.GetDict().FindString(switches::kDisableFeatures);
cronet::EnsureInitialized(
enable_features ? enable_features->c_str() : nullptr,
disable_features ? disable_features->c_str() : nullptr);
}
}
}
cronet::EnsureInitialized();
base::AutoLock lock(lock_);

View File

@ -107,13 +107,6 @@ Cronet_EnginePtr CreateCronetEngine() {
Cronet_EnginePtr cronet_engine = Cronet_Engine_Create();
Cronet_EngineParamsPtr engine_params = Cronet_EngineParams_Create();
Cronet_EngineParams_user_agent_set(engine_params, "Cronet");
Cronet_EngineParams_experimental_options_set(engine_params, R"({
"ssl_key_log_file": "/tmp/keys",
"feature_list": {
"enable-features": "PartitionConnectionsByNetworkIsolationKey"
},
"proxy_server": "socks5://127.0.0.1:1080"
})");
Cronet_Engine_StartWithParams(cronet_engine, engine_params);
Cronet_EngineParams_Destroy(engine_params);
return cronet_engine;
@ -129,26 +122,17 @@ int main(int argc, const char* argv[]) {
stream_engine* cronet_stream_engine =
Cronet_Engine_GetStreamEngine(cronet_engine);
Cronet_Engine_StartNetLogToFile(cronet_engine, "/tmp/log.json", true);
BidirectionalStreamCallback stream_callback;
stream_callback.stream = bidirectional_stream_create(
cronet_stream_engine, &stream_callback, stream_callback.callback());
bidirectional_stream_header headers[] = {
{"-network-isolation-key", "http://a"},
};
const bidirectional_stream_header_array headers_array = {1, 1, headers};
if (bidirectional_stream_start(stream_callback.stream, url, 0, "GET",
&headers_array, true) < 0) {
stream_callback.done = true;
}
bidirectional_stream_start(stream_callback.stream, url, 0, "GET", nullptr,
true);
puts("bidirectional_stream_start");
while (!stream_callback.done) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
bidirectional_stream_destroy(stream_callback.stream);
Cronet_Engine_StopNetLog(cronet_engine);
Cronet_Engine_Shutdown(cronet_engine);
Cronet_Engine_Destroy(cronet_engine);
return 0;

View File

@ -758,23 +758,6 @@ void URLRequestContextConfig::SetContextBuilderExperimentalOptions(
continue;
}
session_params->spdy_go_away_on_ip_change = iter.second.GetBool();
} else if (iter.first == "proxy_server") {
if (!iter.second.is_string()) {
LOG(ERROR) << "\"" << iter.first << "\" config params \"" << iter.second
<< "\" is not a string";
effective_experimental_options.erase(iter.first);
continue;
}
// Handled in CronetContext::NetworkTasks::BuildDefaultURLRequestContext.
} else if (iter.first == "feature_list") {
if (!iter.second.is_dict()) {
LOG(ERROR) << "\"" << iter.first << "\" config params \"" << iter.second
<< "\" is not a dictionary value";
effective_experimental_options.erase(iter.first);
continue;
}
// Already handled in Cronet_EngineImpl::StartWithParams.
// Only checks and reports errors here.
} else {
LOG(WARNING) << "Unrecognized Cronet experimental option \"" << iter.first
<< "\" with params \"" << iter.second;

View File

@ -216,12 +216,6 @@ struct URLRequestContextConfig {
// not specify for other targets.
absl::optional<double> network_thread_priority);
// Parses experimental options from their JSON format to the format used
// internally.
// Returns an empty optional if the operation was unsuccessful.
static absl::optional<base::Value::DictStorage> ParseExperimentalOptions(
std::string unparsed_experimental_options);
private:
URLRequestContextConfig(
// Enable QUIC.
@ -259,6 +253,12 @@ struct URLRequestContextConfig {
// not specify for other targets.
absl::optional<double> network_thread_priority);
// Parses experimental options from their JSON format to the format used
// internally.
// Returns an empty optional if the operation was unsuccessful.
static absl::optional<base::Value::DictStorage> ParseExperimentalOptions(
std::string unparsed_experimental_options);
// Makes appropriate changes to settings in |this|.
void SetContextConfigExperimentalOptions();

View File

@ -21,7 +21,6 @@
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/base/request_priority.h"
#include "net/base/schemeful_site.h"
#include "net/http/bidirectional_stream.h"
#include "net/http/bidirectional_stream_request_info.h"
#include "net/http/http_network_session.h"
@ -97,20 +96,8 @@ int BidirectionalStream::Start(const char* url,
request_info->priority = static_cast<net::RequestPriority>(priority);
// Http method is a token, just as header name.
request_info->method = method;
if (!net::HttpUtil::IsValidHeaderName(request_info->method)) {
LOG(ERROR) << "Invalid method " << request_info->method;
if (!net::HttpUtil::IsValidHeaderName(request_info->method))
return -1;
}
std::string network_isolation_key_header;
if (headers.GetHeader("-network-isolation-key",
&network_isolation_key_header)) {
net::SchemefulSite site(GURL{network_isolation_key_header});
if (site.opaque()) {
LOG(ERROR) << "Invalid -network-isolation-key "
<< network_isolation_key_header;
return -1;
}
}
request_info->extra_headers.CopyFrom(headers);
request_info->end_stream_on_headers = end_of_stream;
write_end_of_stream_ = end_of_stream;

View File

@ -207,14 +207,6 @@ void BidirectionalStream::StartRequest(const SSLConfig& ssl_config) {
HttpRequestInfo http_request_info;
http_request_info.url = request_info_->url;
http_request_info.method = request_info_->method;
std::string network_isolation_key_header;
if (request_info_->extra_headers.GetHeader("-network-isolation-key",
&network_isolation_key_header)) {
request_info_->extra_headers.RemoveHeader("-network-isolation-key");
net::SchemefulSite site(GURL{network_isolation_key_header});
CHECK(!site.opaque());
http_request_info.network_isolation_key = NetworkIsolationKey(site, site);
}
http_request_info.extra_headers = request_info_->extra_headers;
http_request_info.socket_tag = request_info_->socket_tag;
stream_request_ =