Git Product home page Git Product logo

cronet.dart's Introduction

⚠️ This project has been superseeded by https://pub.dev/packages/cronet_http.

Experimental Cronet Dart bindings

This package binds to Cronet's native API to expose them in Dart.

This is a GSoC 2021 project.

Supported Platforms

Currently, Mobile and Desktop Platforms (Linux, Windows and MacOS*) are supported.

*MacOS is supported in Dart CLI platform only. Flutter compatible version coming soon.

Requirements

  1. Dart SDK 2.12.0 or above.
  2. CMake 3.10 or above. (If on windows, Visual Studio 2019 with C++ tools)
  3. C++ compiler. (g++/clang/msvc)
  4. Android NDK if targeting Android.

Usage

  1. Add package as a dependency in your pubspec.yaml.

  2. Run this from the root of your project.

    flutter pub get
    flutter pub run cronet:setup # Downloads the cronet binaries.

    We need to use flutter pub even if we want to use it with Dart CLI. See dart-lang/pub#2606 for further details.

    Note for Android: Remember to Add the following permissions in AndroidManifest.xml file.

     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    Optionally, enable cleartext traffic by adding android:usesCleartextTraffic="true" to AndroidManifest.xml file.

  3. Import

    import 'package:cronet/cronet.dart';

Note: Internet connection is required to download cronet binaries.

Example

  final client = HttpClient();
  client
      .getUrl(Uri.parse('http://info.cern.ch/'))
      .then((HttpClientRequest request) {
    return request.close();
  }).then((HttpClientResponse response) {
    response.transform(utf8.decoder).listen((contents) {
      print(contents);
    },
      onDone: () => print(
        'Done!'));
  });

See the API comparison with dart:io.

Run Example

Flutter

cd example/flutter
flutter pub get
flutter pub run cronet:setup # Downloads the cronet binaries.
flutter run

Dart CLI

cd example/cli
flutter pub get
flutter pub run cronet:setup # Downloads the cronet binaries.
dart run bin/example_dart.dart

Run Tests

flutter pub get
flutter pub run cronet:setup # Downloads the cronet binaries.
flutter test

You can also verify your cronet binaries using dart run cronet:setup verify. Make sure to have cmake 3.10.

Benchmarking

See benchmark summary and extensive reports for comparison with dart:io.

flutter pub get
flutter pub run cronet:setup # Downloads the cronet binaries.
dart run benchmark/latency.dart # For sequential requests benchmark.
dart run benchmark/throughput.dart # For parallel requests benchmark.
dart run benchmark/run_all.dart # To run all the benchmarks and get reports.

Use -h to see available cli arguments and usage informations.

To know how to setup local test servers, read benchmarking guide.

Note: Test results may get affected by: #11.

Building Your Own

  1. Make sure you've downloaded your custom version of cronet shared library and filename follows the pattern cronet.86.0.4240.198.<extension> with a prefix lib if on linux. Else, you can build cronet from source using the provided instuctions. Then copy the library to the designated folder. For linux, the files are under .dart_tool/cronet/linux64.

  2. Run dart run cronet:setup build from the root of your project.

Note for Windows: Run step 2 from x64 Native Tools Command Prompt for VS 2019 shell.

Note for Android: Copy the produced jar files in android/libs and .so files in android/src/main/jniLibs subdirectory from the root of this package.

cronet.dart's People

Contributors

dcharkes avatar mannprerak2 avatar unsuitable001 avatar zhileichen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cronet.dart's Issues

32 Bit system support

Currently only 64bit systems (Android and Desktops) are compatible with this package. Support for 32 bit systems are required for older devices and Android Emulators.

Benchmarks

We should get an understanding of how package:cronet stacks up against dart:io. Cronet is not integrated into the Dart VM which might create some overhead. On the other hand Cronet provides HTTP 2 and QUIC.

We should add a benchmarks/ folder. Some inspiration from setting up benchmarks can be done from https://github.com/dart-lang/sdk/blob/master/benchmarks/MapLookup/dart/MapLookup.dart.

We are interested in multiple dimensions:

  • JIT (dart ...) and AOT (dart compile exe ...).
  • Latency (how fast can a single request be) and throughput (how many concurrent requests per second can we do) - tested by doing only sequential requests and parallel requests respectively.

fix: throughput benchmark

Modify Throughput Benchmark such that the no. of parallel request is always constant.

Results:

Latency Test Results

Mode package:cronet dart:io
JIT 241.556 ms 416.000 ms
AOT 246.111 ms 368.333 ms

Throughput Test Results (Duration: 1s)

Mode package:cronet dart:io
JIT 140 (Parallel Requests: 1024) 28 (Parallel Requests: 64)
AOT 162 (Parallel Requests: 128) 28 (Parallel Requests: 64)

Webtransport support

Hi,
thank you for this library!

I was wondering if support for the Webtransport protocol is planned.
It seems Webtransport is supported by Cronet (as its js APIs are available in Chromium/Chrome since version 97).

Support for the Webtransport protocol would be huge in enabling Flutter developers to develop faster real-time apps and games.

flutter pub run cronet:setup failed with error

flutter pub run cronet:setup failed with error

Unhandled exception:
Invalid argument(s): Failed to lookup symbol 'VersionString': error code 127
#0 DynamicLibrary.lookup (dart:ffi-patch/ffi_dynamic_library_patch.dart:34:70)
#1 Wrapper._VersionString_ptr (package:cronet/src/wrapper/generated_bindings.dart:34:52)
#2 Wrapper._VersionString_ptr (package:cronet/src/wrapper/generated_bindings.dart)
#3 Wrapper._VersionString (package:cronet/src/wrapper/generated_bindings.dart:36:7)
#4 Wrapper._VersionString (package:cronet/src/wrapper/generated_bindings.dart)
#5 Wrapper.VersionString (package:cronet/src/wrapper/generated_bindings.dart:30:12)
#6 downloadCronetBinaries (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/cronet-0.0.7/bin/setup.dart:99:32)
#7 main (file:///C:/flutter/.pub-cache/hosted/pub.dartlang.org/cronet-0.0.7/bin/setup.dart:280:13)
#8 _delayEntrypointInvocation. (dart:isolate-patch/isolate_patch.dart:295:32)
#9 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
pub finished with exit code 255

[√] Flutter (Channel stable, 3.3.9, on Microsoft Windows [Version 10.0.22621.900], locale ja-JP)
• Flutter version 3.3.9 on channel stable at C:\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision b8f7f1f986 (3 weeks ago), 2022-11-23 06:43:51 +0900
• Engine revision 8f2221fbef
• Dart version 2.18.5
• DevTools version 2.15.0

error: No net_fetcher for performing AIA chasing.

When we try to establish any HTTPS connection, we see this error at the very beginning of the request -
[0713/084505.884443:ERROR:cert_verify_proc_builtin.cc(559)] No net_fetcher for performing AIA chasing.
We may encounter this multiple times in case of redirects but strictly in case of TLS connections.

This also affects: https://chromium.googlesource.com/chromium/src/+/475fd34f798f69ae3fb52b117355fa6195adde28/components/cronet/native/sample/

Data is fetched with accuracy despite of this error.

Investigate using the Cronet shipped in Android

On Android, Cronet is available as a Java API.

We would save binary size for Flutter apps if we could access the underlying Cronet dynamic library shipped on Android and bind to that, instead of shipping our own Cronet dynamic library.

QUIC not working?

Any idea why cronet is using TCP even though I've defined to use quic in HttpClient constructor?
Tested on Windows 10 Home 21h1

Security Policy violation Binary Artifacts

This issue was automatically created by Allstar.

Security Policy Violation
Project is out of compliance with Binary Artifacts policy: binaries present in source code

Rule Description
Binary Artifacts are an increased security risk in your repository. Binary artifacts cannot be reviewed, allowing the introduction of possibly obsolete or maliciously subverted executables. For more information see the Security Scorecards Documentation for Binary Artifacts.

Remediation Steps
To remediate, remove the generated executable artifacts from the repository.

Artifacts Found

  • ios/lib/libwrapper.a

Additional Information
This policy is drawn from Security Scorecards, which is a tool that scores a project's adherence to security best practices. You may wish to run a Scorecards scan directly on this repository for more details.


Allstar has been installed on all Google managed GitHub orgs. Policies are gradually being rolled out and enforced by the GOSST and OSPO teams. Learn more at http://go/allstar

This issue will auto resolve when the policy is in compliance.

Issue created by Allstar. See https://github.com/ossf/allstar/ for more information. For questions specific to the repository, please contact the owner or maintainer.

When I use 32-bit dynamic library, there is an error

When I use 32-bit dynamic library, whether it is http or quic, the following error occurs:

[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Invalid argument(s): Count must be in the range [0, 1073741823].
#0 _asExternalTypedData (dart:ffi-patch/ffi_patch.dart:45)
#1 Uint8Pointer.asTypedList (dart:ffi-patch/ffi_patch.dart:432)
#2 CallbackHandler.listen. (package:cronet/src/http_callback_handler.dart:170)
#3 _rootRunUnary (dart:async/zone.dart:1444)
#4 _CustomZone.runUnary (dart:async/zone.dart:1335)
#5 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244)
#6 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341)
#7 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271)
#8 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733)
#9 _StreamController._add (dart:async/stream_controller.dart:607)
#10 _StreamController.add (dart:async/stream_controller.dart:554)
#11 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184)

Force Close Release APK

i have clone this repo and following instruction on readme,

and when I running the example app I have some issue like this
Screen Shot 2022-02-16 at 11 42 04

so I try to comment that line,
it is worked, and I have not issue if I running on debug mode, but if I run flutter run --release or flutter build apk
application always force close on emulator or real device

Screen Shot 2022-02-16 at 17 52 28

Screen Shot 2022-02-16 at 11 46 24

if i miss something, can you tell me please?

MacOS support

  • Investigate building Cronet on MacOS
  • Add a binary

Flutter support

We should add Flutter support (Flutter Desktop x3 and mobile x2).

Add separate set methods to set common http headers in http requests

HttpHeaders class also gives us some handy methods to mutate some commonly used headers (such as contentLength, persistentConnection etc.) besides the set method.

set method can be used to add any headers, including but not limited to the above mentioned ones. set method is being implemented via #26 and tracked using #25.

This issue is a superset/improvement of #25.

Sudden hiccups during benchmarking

While doing benchmarking, we've observed sudden and sorta random dips in performance.

[0712/103533.128980:ERROR:cert_verify_proc_builtin.cc(559)] No net_fetcher for performing AIA chasing.
Cronet(Throughput): Total Spawned: 8, Returned in time: 8.
[0712/103533.583837:ERROR:cert_verify_proc_builtin.cc(559)] No net_fetcher for performing AIA chasing.
Cronet(Throughput): Total Spawned: 16, Returned in time: 16.
[0712/103534.120373:ERROR:cert_verify_proc_builtin.cc(559)] No net_fetcher for performing AIA chasing.
Cronet(Throughput): Total Spawned: 32, Returned in time: 30.
[0712/103548.869642:ERROR:cert_verify_proc_builtin.cc(559)] No net_fetcher for performing AIA chasing.
Cronet(Throughput): Total Spawned: 64, Returned in time: 64.
[0712/103549.496886:ERROR:cert_verify_proc_builtin.cc(559)] No net_fetcher for performing AIA chasing.
Cronet(Throughput): Total Spawned: 128, Returned in time: 121.
[0712/103557.274973:ERROR:cert_verify_proc_builtin.cc(559)] No net_fetcher for performing AIA chasing.
Cronet(Throughput): Total Spawned: 256, Returned in time: 256.

See dips in 32 and 128 marks. Errors are due to #10 . This issue may affect reports in #3 .

Cache and Cookie Store

Cronet enables us to specify storage type to store cookies and cache requests to speed up network request even more.

TODO: Add options to specify storage type (i.e. in disk, in memory) including their size or disabling any kind of storage.

Adding user specified headers in http request

Adding support for user added headers while performing a request. Most common use case for this feature is setting content-type header while sending some data through POST request.

Use package:args

The files in bin/ tool/ and benchmarks/ (after #8) could use package:args for a more structured approach to command line arguments.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.