From f887f6919675c350840d984c5a51bee085404c01 Mon Sep 17 00:00:00 2001 From: John Turpish Date: Thu, 26 Sep 2024 12:41:45 -0400 Subject: [PATCH] Maintenance --- .github/tour.sh | 5 +- .github/ut.sh | 39 ++++- .gitignore | 1 + .../chrome/browser/BUILD.gn.patch | 27 ++++ .../chrome/browser/about_flags.cc.patch | 38 +++++ ...me_autocomplete_scheme_classifier.cc.patch | 51 ++++++ .../chrome_content_browser_client.cc.patch | 81 ++++++++++ .../chrome/browser/flag-metadata.json.patch | 16 ++ .../chrome/browser/flag_descriptions.cc.patch | 16 ++ .../chrome/browser/flag_descriptions.h.patch | 24 +++ .../chrome/browser/ipfs_extra_parts.cc | 10 ++ .../chrome/browser/ipfs_extra_parts.h | 10 ++ .../browser/prefs/browser_prefs.cc.patch | 37 +++++ .../browser/shell_integration_mac.mm.patch | 13 ++ .../common/chrome_content_client.cc.patch | 17 ++ .../linux/common/desktop.template.patch | 13 ++ .../chrome/installer/util/shell_util.cc.patch | 20 +++ .../components/cbor/reader.cc.patch | 44 ++++++ .../components/cbor/reader.h.patch | 26 ++++ .../components/cbor/reader_unittest.cc.patch | 47 ++++++ .../components/cbor/values.cc.patch | 145 ++++++++++++++++++ .../components/cbor/values.h.patch | 79 ++++++++++ .../components/cbor/writer.cc.patch | 14 ++ .../components/cbor/writer_unittest.cc.patch | 36 +++++ .../clipboard_recent_content_generic.cc.patch | 13 ++ .../net/dns/dns_config_service_linux.cc.patch | 18 +++ .../weborigin/scheme_registry.cc.patch | 15 ++ .../128.0.6613.186/url/BUILD.gn.patch | 32 ++++ .../128.0.6613.186/url/url_canon.h.patch | 26 ++++ .../128.0.6613.186/url/url_canon_ipfs.cc | 54 +++++++ .../128.0.6613.186/url/url_util.cc.patch | 45 ++++++ .../chrome/browser/BUILD.gn.patch | 27 ++++ .../chrome/browser/about_flags.cc.patch | 38 +++++ ...me_autocomplete_scheme_classifier.cc.patch | 51 ++++++ .../chrome_content_browser_client.cc.patch | 81 ++++++++++ .../chrome/browser/flag-metadata.json.patch | 16 ++ .../chrome/browser/flag_descriptions.cc.patch | 16 ++ .../chrome/browser/flag_descriptions.h.patch | 24 +++ .../chrome/browser/ipfs_extra_parts.cc | 10 ++ .../chrome/browser/ipfs_extra_parts.h | 10 ++ .../browser/prefs/browser_prefs.cc.patch | 36 +++++ .../browser/shell_integration_mac.mm.patch | 13 ++ .../common/chrome_content_client.cc.patch | 17 ++ .../linux/common/desktop.template.patch | 13 ++ .../chrome/installer/util/shell_util.cc.patch | 20 +++ .../components/cbor/reader.cc.patch | 44 ++++++ .../components/cbor/reader.h.patch | 26 ++++ .../components/cbor/reader_unittest.cc.patch | 47 ++++++ .../components/cbor/values.cc.patch | 145 ++++++++++++++++++ .../components/cbor/values.h.patch | 79 ++++++++++ .../components/cbor/writer.cc.patch | 14 ++ .../components/cbor/writer_unittest.cc.patch | 36 +++++ .../clipboard_recent_content_generic.cc.patch | 13 ++ .../net/dns/dns_config_service_linux.cc.patch | 18 +++ .../weborigin/scheme_registry.cc.patch | 15 ++ .../131.0.6738.0/url/BUILD.gn.patch | 32 ++++ .../131.0.6738.0/url/url_canon.h.patch | 26 ++++ .../131.0.6738.0/url/url_canon_ipfs.cc | 54 +++++++ .../131.0.6738.0/url/url_util.cc.patch | 45 ++++++ .../chrome/browser/BUILD.gn.patch | 27 ++++ .../chrome/browser/about_flags.cc.patch | 38 +++++ ...me_autocomplete_scheme_classifier.cc.patch | 51 ++++++ .../chrome_content_browser_client.cc.patch | 81 ++++++++++ .../chrome/browser/flag-metadata.json.patch | 16 ++ .../chrome/browser/flag_descriptions.cc.patch | 16 ++ .../chrome/browser/flag_descriptions.h.patch | 24 +++ .../chrome/browser/ipfs_extra_parts.cc | 10 ++ .../chrome/browser/ipfs_extra_parts.h | 10 ++ .../browser/prefs/browser_prefs.cc.patch | 36 +++++ .../browser/shell_integration_mac.mm.patch | 13 ++ .../common/chrome_content_client.cc.patch | 17 ++ .../linux/common/desktop.template.patch | 13 ++ .../chrome/installer/util/shell_util.cc.patch | 20 +++ .../components/cbor/reader.cc.patch | 44 ++++++ .../components/cbor/reader.h.patch | 26 ++++ .../components/cbor/reader_unittest.cc.patch | 47 ++++++ .../components/cbor/values.cc.patch | 145 ++++++++++++++++++ .../components/cbor/values.h.patch | 79 ++++++++++ .../components/cbor/writer.cc.patch | 14 ++ .../components/cbor/writer_unittest.cc.patch | 36 +++++ .../clipboard_recent_content_generic.cc.patch | 13 ++ .../net/dns/dns_config_service_linux.cc.patch | 18 +++ .../weborigin/scheme_registry.cc.patch | 15 ++ .../131.0.6753.0/url/BUILD.gn.patch | 32 ++++ .../131.0.6753.0/url/url_canon.h.patch | 26 ++++ .../131.0.6753.0/url/url_canon_ipfs.cc | 54 +++++++ .../131.0.6753.0/url/url_util.cc.patch | 45 ++++++ .../chrome/browser/BUILD.gn.patch | 27 ++++ .../chrome/browser/about_flags.cc.patch | 38 +++++ ...me_autocomplete_scheme_classifier.cc.patch | 51 ++++++ .../chrome_content_browser_client.cc.patch | 81 ++++++++++ .../chrome/browser/flag-metadata.json.patch | 16 ++ .../chrome/browser/flag_descriptions.cc.patch | 16 ++ .../chrome/browser/flag_descriptions.h.patch | 24 +++ .../chrome/browser/ipfs_extra_parts.cc | 10 ++ .../chrome/browser/ipfs_extra_parts.h | 10 ++ .../browser/prefs/browser_prefs.cc.patch | 36 +++++ .../browser/shell_integration_mac.mm.patch | 13 ++ .../common/chrome_content_client.cc.patch | 17 ++ .../linux/common/desktop.template.patch | 13 ++ .../chrome/installer/util/shell_util.cc.patch | 20 +++ .../components/cbor/reader.cc.patch | 44 ++++++ .../components/cbor/reader.h.patch | 26 ++++ .../components/cbor/reader_unittest.cc.patch | 47 ++++++ .../components/cbor/values.cc.patch | 145 ++++++++++++++++++ .../components/cbor/values.h.patch | 79 ++++++++++ .../components/cbor/writer.cc.patch | 14 ++ .../components/cbor/writer_unittest.cc.patch | 36 +++++ .../clipboard_recent_content_generic.cc.patch | 13 ++ .../net/dns/dns_config_service_linux.cc.patch | 18 +++ .../weborigin/scheme_registry.cc.patch | 15 ++ .../131.0.6776.0/url/BUILD.gn.patch | 32 ++++ .../131.0.6776.0/url/url_canon.h.patch | 26 ++++ .../131.0.6776.0/url/url_canon_ipfs.cc | 54 +++++++ .../131.0.6776.0/url/url_util.cc.patch | 45 ++++++ .../chrome/browser/BUILD.gn.patch | 27 ++++ .../chrome/browser/about_flags.cc.patch | 38 +++++ ...me_autocomplete_scheme_classifier.cc.patch | 51 ++++++ .../chrome_content_browser_client.cc.patch | 81 ++++++++++ .../chrome/browser/flag-metadata.json.patch | 16 ++ .../chrome/browser/flag_descriptions.cc.patch | 16 ++ .../chrome/browser/flag_descriptions.h.patch | 24 +++ .../chrome/browser/ipfs_extra_parts.cc | 10 ++ .../chrome/browser/ipfs_extra_parts.h | 10 ++ .../browser/prefs/browser_prefs.cc.patch | 36 +++++ .../browser/shell_integration_mac.mm.patch | 13 ++ .../common/chrome_content_client.cc.patch | 17 ++ .../linux/common/desktop.template.patch | 13 ++ .../chrome/installer/util/shell_util.cc.patch | 20 +++ .../components/cbor/reader.cc.patch | 44 ++++++ .../components/cbor/reader.h.patch | 26 ++++ .../components/cbor/reader_unittest.cc.patch | 47 ++++++ .../components/cbor/values.cc.patch | 145 ++++++++++++++++++ .../components/cbor/values.h.patch | 79 ++++++++++ .../components/cbor/writer.cc.patch | 14 ++ .../components/cbor/writer_unittest.cc.patch | 36 +++++ .../clipboard_recent_content_generic.cc.patch | 13 ++ .../net/dns/dns_config_service_linux.cc.patch | 18 +++ .../weborigin/scheme_registry.cc.patch | 15 ++ .../132.0.6779.0/url/BUILD.gn.patch | 32 ++++ .../132.0.6779.0/url/url_canon.h.patch | 26 ++++ .../132.0.6779.0/url/url_canon_ipfs.cc | 54 +++++++ .../132.0.6779.0/url/url_util.cc.patch | 45 ++++++ cmake/AppleClang.cmake | 2 +- cmake/Clang.cmake | 2 +- cmake/CodeCoverage.cmake | 16 +- cmake/GNU.cmake | 2 +- cmake/MSVC.cmake | 2 +- cmake/inc_link.py | 22 ++- cmake/patch.py | 63 ++++---- cmake/recent-electron.txt | 2 +- component/cache_requestor.cc | 2 +- component/chromium_http.h | 2 + doc/0.0.1.2_blog.md | 120 ++++++++++----- library/.clang-tidy | 66 ++++---- library/CMakeLists.txt | 7 +- library/conanfile.py | 5 +- library/include/ipfs_client/client.h | 2 + .../ipfs_client/crypto/identity_hasher.h | 14 ++ .../include/ipfs_client/ctx/dns_txt_lookup.cc | 1 - .../include/ipfs_client/ctx/dns_txt_lookup.h | 2 +- .../ctx/transitory_gateway_config.h | 7 + .../ipfs_client/gw/block_request_splitter.h | 3 +- .../include/ipfs_client/gw/gateway_request.h | 18 ++- .../ipfs_client/gw/inline_request_handler.h | 4 + library/include/ipfs_client/gw/requestor.h | 4 +- library/include/multibase/algorithm.h | 4 + library/include/multibase/basic_algorithm.h | 4 + library/src/ipfs_client/block_requestor.cc | 1 - library/src/ipfs_client/car.cc | 21 ++- library/src/ipfs_client/car_unittest.cc | 2 + library/src/ipfs_client/cid.cc | 19 ++- library/src/ipfs_client/client.cc | 55 ++++--- .../ipfs_client/crypto/openssl_sha2_256.cc | 7 +- .../crypto/openssl_signature_verifier.cc | 19 ++- .../ipfs_client/crypto/signing_key_type.cc | 6 +- .../src/ipfs_client/ctx/boost_beast_http.cc | 43 +++--- .../ctx/boost_beast_http_unittest.cc | 4 + .../src/ipfs_client/ctx/default_gateways.cc | 42 ++--- library/src/ipfs_client/ctx/dns_txt_lookup.cc | 3 + .../ipfs_client/ctx/nlohmann_cbor_parser.cc | 4 + .../ipfs_client/ctx/nlohmann_json_parser.cc | 5 + .../ipfs_client/ctx/null_dns_txt_lookup.cc | 9 +- .../src/ipfs_client/ctx/null_http_provider.cc | 1 + .../ctx/transitory_gateway_config.cc | 17 +- library/src/ipfs_client/dag_cbor_value.cc | 12 +- library/src/ipfs_client/dag_json_value.cc | 1 + .../generated_directory_listing.cc | 5 +- .../ipfs_client/gw/block_request_splitter.cc | 13 +- .../gw/block_request_splitter_unittest.cc | 8 +- .../src/ipfs_client/gw/default_requestor.cc | 2 + .../src/ipfs_client/gw/dnslink_requestor.cc | 43 +++--- library/src/ipfs_client/gw/gateway_request.cc | 76 +++++---- .../ipfs_client/gw/gateway_request_type.cc | 5 +- .../gw/gateway_request_unittest.cc | 4 +- library/src/ipfs_client/gw/gateway_state.cc | 51 +++--- library/src/ipfs_client/gw/gateway_state.h | 4 +- .../ipfs_client/gw/inline_request_handler.cc | 19 ++- .../ipfs_client/gw/multi_gateway_requestor.cc | 33 ++-- .../ipfs_client/gw/multi_gateway_requestor.h | 2 + .../gw/multi_gateway_requestor_unittest.cc | 4 +- .../src/ipfs_client/gw/providers_response.cc | 63 ++++---- library/src/ipfs_client/gw/requestor.cc | 8 +- library/src/ipfs_client/gw/requestor_pool.h | 32 ---- .../ipfs_client/gw/terminating_requestor.cc | 20 ++- .../ipfs_client/http_request_description.cc | 4 +- library/src/ipfs_client/identity_cid.cc | 10 +- library/src/ipfs_client/ipfs_request.cc | 13 +- library/src/ipfs_client/ipld/block_source.cc | 8 +- library/src/ipfs_client/ipld/chunk.cc | 14 +- library/src/ipfs_client/ipld/dag_cbor_node.cc | 14 +- library/src/ipfs_client/ipld/dag_headers.cc | 12 +- library/src/ipfs_client/ipld/dag_json_node.cc | 17 +- library/src/ipfs_client/ipld/dag_node.cc | 50 +++--- .../src/ipfs_client/ipld/dag_node_unittest.cc | 37 +++++ .../src/ipfs_client/ipld/directory_shard.cc | 47 +++--- library/src/ipfs_client/ipld/dnslink_name.cc | 15 +- library/src/ipfs_client/ipld/ipns_name.cc | 15 +- library/src/ipfs_client/ipld/link.cc | 8 +- .../src/ipfs_client/ipld/resolution_state.cc | 28 ++-- library/src/ipfs_client/ipld/root.cc | 29 ++-- .../src/ipfs_client/ipld/small_directory.cc | 20 +-- library/src/ipfs_client/ipld/symlink.cc | 20 ++- library/src/ipfs_client/ipld/unixfs_file.cc | 15 +- library/src/ipfs_client/ipns_names.cc | 13 +- library/src/ipfs_client/ipns_record.cc | 45 +++--- library/src/ipfs_client/logger.cc | 10 +- library/src/ipfs_client/multi_base.cc | 28 ++-- library/src/ipfs_client/multi_hash.cc | 11 +- library/src/ipfs_client/multicodec.cc | 9 +- .../src/ipfs_client/opinionated_context.cc | 7 + library/src/ipfs_client/partition.cc | 33 ++-- library/src/ipfs_client/partition_unittest.cc | 2 +- library/src/ipfs_client/path2url.cc | 3 +- library/src/ipfs_client/pb_dag.cc | 67 +++++--- library/src/ipfs_client/redirects.cc | 32 ++-- library/src/ipfs_client/response.cc | 4 +- library/src/ipfs_client/web_util.cc | 13 +- library/src/libp2p/multi/uvarint.cc | 33 ++-- library/src/log_macros.h | 13 -- library/src/smhasher/MurmurHash3.cc | 27 ++-- library/src/vocab/byte_view.cc | 1 - library/src/vocab/slash_delimited.cc | 78 +++++----- ...752pbiB9G4PpvZbTyBxt9akY7sJF3GvSnnWpRuop9M | 2 - ...gBpvEnsjKcsPTYoQv57WahtZg6q4g3QV7sRbe2Ro4V | 2 - ...HhQWRBG41NoHky1gwyBLcV6ADu563uVwyNQy8hcbHT | 2 - ...3MGQPiduqek71sDXQBC9XJRNvihuRgg5sh7N8x1K9o | 2 - ...ax36u2wvjo455ncj66kvqllffgqoeiqhxcmbem7mla | 1 - ...uqpub254klezspvwnlvtmzqcswh57krihny6mtnrem | 1 - 249 files changed, 6004 insertions(+), 726 deletions(-) create mode 100644 chromium_edits/128.0.6613.186/chrome/browser/BUILD.gn.patch create mode 100644 chromium_edits/128.0.6613.186/chrome/browser/about_flags.cc.patch create mode 100644 chromium_edits/128.0.6613.186/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch create mode 100644 chromium_edits/128.0.6613.186/chrome/browser/chrome_content_browser_client.cc.patch create mode 100644 chromium_edits/128.0.6613.186/chrome/browser/flag-metadata.json.patch create mode 100644 chromium_edits/128.0.6613.186/chrome/browser/flag_descriptions.cc.patch create mode 100644 chromium_edits/128.0.6613.186/chrome/browser/flag_descriptions.h.patch create mode 100644 chromium_edits/128.0.6613.186/chrome/browser/ipfs_extra_parts.cc create mode 100644 chromium_edits/128.0.6613.186/chrome/browser/ipfs_extra_parts.h create mode 100644 chromium_edits/128.0.6613.186/chrome/browser/prefs/browser_prefs.cc.patch create mode 100644 chromium_edits/128.0.6613.186/chrome/browser/shell_integration_mac.mm.patch create mode 100644 chromium_edits/128.0.6613.186/chrome/common/chrome_content_client.cc.patch create mode 100644 chromium_edits/128.0.6613.186/chrome/installer/linux/common/desktop.template.patch create mode 100644 chromium_edits/128.0.6613.186/chrome/installer/util/shell_util.cc.patch create mode 100644 chromium_edits/128.0.6613.186/components/cbor/reader.cc.patch create mode 100644 chromium_edits/128.0.6613.186/components/cbor/reader.h.patch create mode 100644 chromium_edits/128.0.6613.186/components/cbor/reader_unittest.cc.patch create mode 100644 chromium_edits/128.0.6613.186/components/cbor/values.cc.patch create mode 100644 chromium_edits/128.0.6613.186/components/cbor/values.h.patch create mode 100644 chromium_edits/128.0.6613.186/components/cbor/writer.cc.patch create mode 100644 chromium_edits/128.0.6613.186/components/cbor/writer_unittest.cc.patch create mode 100644 chromium_edits/128.0.6613.186/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch create mode 100644 chromium_edits/128.0.6613.186/net/dns/dns_config_service_linux.cc.patch create mode 100644 chromium_edits/128.0.6613.186/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch create mode 100644 chromium_edits/128.0.6613.186/url/BUILD.gn.patch create mode 100644 chromium_edits/128.0.6613.186/url/url_canon.h.patch create mode 100644 chromium_edits/128.0.6613.186/url/url_canon_ipfs.cc create mode 100644 chromium_edits/128.0.6613.186/url/url_util.cc.patch create mode 100644 chromium_edits/131.0.6738.0/chrome/browser/BUILD.gn.patch create mode 100644 chromium_edits/131.0.6738.0/chrome/browser/about_flags.cc.patch create mode 100644 chromium_edits/131.0.6738.0/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch create mode 100644 chromium_edits/131.0.6738.0/chrome/browser/chrome_content_browser_client.cc.patch create mode 100644 chromium_edits/131.0.6738.0/chrome/browser/flag-metadata.json.patch create mode 100644 chromium_edits/131.0.6738.0/chrome/browser/flag_descriptions.cc.patch create mode 100644 chromium_edits/131.0.6738.0/chrome/browser/flag_descriptions.h.patch create mode 100644 chromium_edits/131.0.6738.0/chrome/browser/ipfs_extra_parts.cc create mode 100644 chromium_edits/131.0.6738.0/chrome/browser/ipfs_extra_parts.h create mode 100644 chromium_edits/131.0.6738.0/chrome/browser/prefs/browser_prefs.cc.patch create mode 100644 chromium_edits/131.0.6738.0/chrome/browser/shell_integration_mac.mm.patch create mode 100644 chromium_edits/131.0.6738.0/chrome/common/chrome_content_client.cc.patch create mode 100644 chromium_edits/131.0.6738.0/chrome/installer/linux/common/desktop.template.patch create mode 100644 chromium_edits/131.0.6738.0/chrome/installer/util/shell_util.cc.patch create mode 100644 chromium_edits/131.0.6738.0/components/cbor/reader.cc.patch create mode 100644 chromium_edits/131.0.6738.0/components/cbor/reader.h.patch create mode 100644 chromium_edits/131.0.6738.0/components/cbor/reader_unittest.cc.patch create mode 100644 chromium_edits/131.0.6738.0/components/cbor/values.cc.patch create mode 100644 chromium_edits/131.0.6738.0/components/cbor/values.h.patch create mode 100644 chromium_edits/131.0.6738.0/components/cbor/writer.cc.patch create mode 100644 chromium_edits/131.0.6738.0/components/cbor/writer_unittest.cc.patch create mode 100644 chromium_edits/131.0.6738.0/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch create mode 100644 chromium_edits/131.0.6738.0/net/dns/dns_config_service_linux.cc.patch create mode 100644 chromium_edits/131.0.6738.0/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch create mode 100644 chromium_edits/131.0.6738.0/url/BUILD.gn.patch create mode 100644 chromium_edits/131.0.6738.0/url/url_canon.h.patch create mode 100644 chromium_edits/131.0.6738.0/url/url_canon_ipfs.cc create mode 100644 chromium_edits/131.0.6738.0/url/url_util.cc.patch create mode 100644 chromium_edits/131.0.6753.0/chrome/browser/BUILD.gn.patch create mode 100644 chromium_edits/131.0.6753.0/chrome/browser/about_flags.cc.patch create mode 100644 chromium_edits/131.0.6753.0/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch create mode 100644 chromium_edits/131.0.6753.0/chrome/browser/chrome_content_browser_client.cc.patch create mode 100644 chromium_edits/131.0.6753.0/chrome/browser/flag-metadata.json.patch create mode 100644 chromium_edits/131.0.6753.0/chrome/browser/flag_descriptions.cc.patch create mode 100644 chromium_edits/131.0.6753.0/chrome/browser/flag_descriptions.h.patch create mode 100644 chromium_edits/131.0.6753.0/chrome/browser/ipfs_extra_parts.cc create mode 100644 chromium_edits/131.0.6753.0/chrome/browser/ipfs_extra_parts.h create mode 100644 chromium_edits/131.0.6753.0/chrome/browser/prefs/browser_prefs.cc.patch create mode 100644 chromium_edits/131.0.6753.0/chrome/browser/shell_integration_mac.mm.patch create mode 100644 chromium_edits/131.0.6753.0/chrome/common/chrome_content_client.cc.patch create mode 100644 chromium_edits/131.0.6753.0/chrome/installer/linux/common/desktop.template.patch create mode 100644 chromium_edits/131.0.6753.0/chrome/installer/util/shell_util.cc.patch create mode 100644 chromium_edits/131.0.6753.0/components/cbor/reader.cc.patch create mode 100644 chromium_edits/131.0.6753.0/components/cbor/reader.h.patch create mode 100644 chromium_edits/131.0.6753.0/components/cbor/reader_unittest.cc.patch create mode 100644 chromium_edits/131.0.6753.0/components/cbor/values.cc.patch create mode 100644 chromium_edits/131.0.6753.0/components/cbor/values.h.patch create mode 100644 chromium_edits/131.0.6753.0/components/cbor/writer.cc.patch create mode 100644 chromium_edits/131.0.6753.0/components/cbor/writer_unittest.cc.patch create mode 100644 chromium_edits/131.0.6753.0/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch create mode 100644 chromium_edits/131.0.6753.0/net/dns/dns_config_service_linux.cc.patch create mode 100644 chromium_edits/131.0.6753.0/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch create mode 100644 chromium_edits/131.0.6753.0/url/BUILD.gn.patch create mode 100644 chromium_edits/131.0.6753.0/url/url_canon.h.patch create mode 100644 chromium_edits/131.0.6753.0/url/url_canon_ipfs.cc create mode 100644 chromium_edits/131.0.6753.0/url/url_util.cc.patch create mode 100644 chromium_edits/131.0.6776.0/chrome/browser/BUILD.gn.patch create mode 100644 chromium_edits/131.0.6776.0/chrome/browser/about_flags.cc.patch create mode 100644 chromium_edits/131.0.6776.0/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch create mode 100644 chromium_edits/131.0.6776.0/chrome/browser/chrome_content_browser_client.cc.patch create mode 100644 chromium_edits/131.0.6776.0/chrome/browser/flag-metadata.json.patch create mode 100644 chromium_edits/131.0.6776.0/chrome/browser/flag_descriptions.cc.patch create mode 100644 chromium_edits/131.0.6776.0/chrome/browser/flag_descriptions.h.patch create mode 100644 chromium_edits/131.0.6776.0/chrome/browser/ipfs_extra_parts.cc create mode 100644 chromium_edits/131.0.6776.0/chrome/browser/ipfs_extra_parts.h create mode 100644 chromium_edits/131.0.6776.0/chrome/browser/prefs/browser_prefs.cc.patch create mode 100644 chromium_edits/131.0.6776.0/chrome/browser/shell_integration_mac.mm.patch create mode 100644 chromium_edits/131.0.6776.0/chrome/common/chrome_content_client.cc.patch create mode 100644 chromium_edits/131.0.6776.0/chrome/installer/linux/common/desktop.template.patch create mode 100644 chromium_edits/131.0.6776.0/chrome/installer/util/shell_util.cc.patch create mode 100644 chromium_edits/131.0.6776.0/components/cbor/reader.cc.patch create mode 100644 chromium_edits/131.0.6776.0/components/cbor/reader.h.patch create mode 100644 chromium_edits/131.0.6776.0/components/cbor/reader_unittest.cc.patch create mode 100644 chromium_edits/131.0.6776.0/components/cbor/values.cc.patch create mode 100644 chromium_edits/131.0.6776.0/components/cbor/values.h.patch create mode 100644 chromium_edits/131.0.6776.0/components/cbor/writer.cc.patch create mode 100644 chromium_edits/131.0.6776.0/components/cbor/writer_unittest.cc.patch create mode 100644 chromium_edits/131.0.6776.0/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch create mode 100644 chromium_edits/131.0.6776.0/net/dns/dns_config_service_linux.cc.patch create mode 100644 chromium_edits/131.0.6776.0/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch create mode 100644 chromium_edits/131.0.6776.0/url/BUILD.gn.patch create mode 100644 chromium_edits/131.0.6776.0/url/url_canon.h.patch create mode 100644 chromium_edits/131.0.6776.0/url/url_canon_ipfs.cc create mode 100644 chromium_edits/131.0.6776.0/url/url_util.cc.patch create mode 100644 chromium_edits/132.0.6779.0/chrome/browser/BUILD.gn.patch create mode 100644 chromium_edits/132.0.6779.0/chrome/browser/about_flags.cc.patch create mode 100644 chromium_edits/132.0.6779.0/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch create mode 100644 chromium_edits/132.0.6779.0/chrome/browser/chrome_content_browser_client.cc.patch create mode 100644 chromium_edits/132.0.6779.0/chrome/browser/flag-metadata.json.patch create mode 100644 chromium_edits/132.0.6779.0/chrome/browser/flag_descriptions.cc.patch create mode 100644 chromium_edits/132.0.6779.0/chrome/browser/flag_descriptions.h.patch create mode 100644 chromium_edits/132.0.6779.0/chrome/browser/ipfs_extra_parts.cc create mode 100644 chromium_edits/132.0.6779.0/chrome/browser/ipfs_extra_parts.h create mode 100644 chromium_edits/132.0.6779.0/chrome/browser/prefs/browser_prefs.cc.patch create mode 100644 chromium_edits/132.0.6779.0/chrome/browser/shell_integration_mac.mm.patch create mode 100644 chromium_edits/132.0.6779.0/chrome/common/chrome_content_client.cc.patch create mode 100644 chromium_edits/132.0.6779.0/chrome/installer/linux/common/desktop.template.patch create mode 100644 chromium_edits/132.0.6779.0/chrome/installer/util/shell_util.cc.patch create mode 100644 chromium_edits/132.0.6779.0/components/cbor/reader.cc.patch create mode 100644 chromium_edits/132.0.6779.0/components/cbor/reader.h.patch create mode 100644 chromium_edits/132.0.6779.0/components/cbor/reader_unittest.cc.patch create mode 100644 chromium_edits/132.0.6779.0/components/cbor/values.cc.patch create mode 100644 chromium_edits/132.0.6779.0/components/cbor/values.h.patch create mode 100644 chromium_edits/132.0.6779.0/components/cbor/writer.cc.patch create mode 100644 chromium_edits/132.0.6779.0/components/cbor/writer_unittest.cc.patch create mode 100644 chromium_edits/132.0.6779.0/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch create mode 100644 chromium_edits/132.0.6779.0/net/dns/dns_config_service_linux.cc.patch create mode 100644 chromium_edits/132.0.6779.0/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch create mode 100644 chromium_edits/132.0.6779.0/url/BUILD.gn.patch create mode 100644 chromium_edits/132.0.6779.0/url/url_canon.h.patch create mode 100644 chromium_edits/132.0.6779.0/url/url_canon_ipfs.cc create mode 100644 chromium_edits/132.0.6779.0/url/url_util.cc.patch create mode 100644 library/include/ipfs_client/crypto/identity_hasher.h delete mode 100644 library/include/ipfs_client/ctx/dns_txt_lookup.cc create mode 100644 library/src/ipfs_client/ctx/dns_txt_lookup.cc delete mode 100644 library/src/ipfs_client/gw/requestor_pool.h create mode 100644 library/src/ipfs_client/ipld/dag_node_unittest.cc delete mode 100644 test_data/blocks/QmaP752pbiB9G4PpvZbTyBxt9akY7sJF3GvSnnWpRuop9M delete mode 100644 test_data/blocks/QmaYgBpvEnsjKcsPTYoQv57WahtZg6q4g3QV7sRbe2Ro4V delete mode 100644 test_data/blocks/QmasHhQWRBG41NoHky1gwyBLcV6ADu563uVwyNQy8hcbHT delete mode 100644 test_data/blocks/Qmaw3MGQPiduqek71sDXQBC9XJRNvihuRgg5sh7N8x1K9o delete mode 100644 test_data/blocks/bafkreifj6ukwnplhax36u2wvjo455ncj66kvqllffgqoeiqhxcmbem7mla delete mode 100644 test_data/blocks/bafkreifkvfacmzhruqpub254klezspvwnlvtmzqcswh57krihny6mtnrem diff --git a/.github/tour.sh b/.github/tour.sh index 63cb675d..b7244824 100755 --- a/.github/tour.sh +++ b/.github/tour.sh @@ -17,8 +17,9 @@ grep -n . ipfs_client_clitester/conanfile.txt echo Install dependencies. sudo apt-get update -sudo apt-get install --yes cmake ninja-build binutils libc6{,-dev} -pip3 install conan +sudo apt-get install --yes cmake ninja-build binutils libc6{,-dev} pipx +pipx ensurepath +pipx install conan conan profile detect || echo "Profile detection failed. Perhaps the default profile already existed - perhaps this user has already done some conan-based builds." sed -i 's,compiler.cppstd=.*$,compiler.cppstd=20,' "$(conan profile path default)" conan profile show diff --git a/.github/ut.sh b/.github/ut.sh index b83c3267..95d87d33 100755 --- a/.github/ut.sh +++ b/.github/ut.sh @@ -1,11 +1,40 @@ #!/bin/bash -ex echo Install dependencies - sudo apt-get update - sudo apt-get install --yes cmake ninja-build lcov binutils doxygen graphviz libc6{,-dev} valgrind - npm install -g @marp-team/marp-cli -g++ --version -clang++ --version + sudo apt-get update + sudo apt-get install --yes \ + cmake \ + ninja-build \ + doxygen \ + graphviz \ + valgrind \ + pipx + +for pl in lib{capture-tiny,datetime}-perl +do + sudo apt-get install "${pl}" +done + +wget https://github.com/linux-test-project/lcov/releases/download/v2.1/lcov-2.1.tar.gz +tar xzvf lcov-2.1.tar.gz +export PATH="${PWD}/lcov-2.1/bin:${PATH}" +hash -r + +pipx ensurepath +pipx install conan +npm install -g @marp-team/marp-cli + +set +x +echo Show versions: +for p in g++ gcc clang{++,} lcov conan +do + which "${p}" + "${p}" --version +done +set -x + +conan profile detect + echo Configure mkdir build cmake \ diff --git a/.gitignore b/.gitignore index a0733ae6..e942eca9 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ gotit.json .kdev4/ipfs-chromium.kdev4 *.autosave.* *.autosave +compile_commands.json diff --git a/chromium_edits/128.0.6613.186/chrome/browser/BUILD.gn.patch b/chromium_edits/128.0.6613.186/chrome/browser/BUILD.gn.patch new file mode 100644 index 00000000..54a6921f --- /dev/null +++ b/chromium_edits/128.0.6613.186/chrome/browser/BUILD.gn.patch @@ -0,0 +1,27 @@ +diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn +index fe0452e8bd462..575137d6dbbf9 100644 +--- a/chrome/browser/BUILD.gn ++++ b/chrome/browser/BUILD.gn +@@ -41,6 +41,7 @@ import("//sandbox/features.gni") + import("//services/screen_ai/buildflags/features.gni") + import("//testing/libfuzzer/fuzzer_test.gni") + import("//third_party/blink/public/public_features.gni") ++import("//third_party/ipfs_client/args.gni") + import("//third_party/protobuf/proto_library.gni") + import("//third_party/webrtc/webrtc.gni") + import("//third_party/widevine/cdm/widevine.gni") +@@ -2717,6 +2718,14 @@ static_library("browser") { + ] + } + ++ if (enable_ipfs) { ++ sources += [ ++ "ipfs_extra_parts.cc", ++ "ipfs_extra_parts.h", ++ ] ++ deps += [ "//components/ipfs" ] ++ } ++ + if (is_chromeos_ash) { + deps += [ "//chrome/browser/screen_ai:screen_ai_dlc_installer" ] + } diff --git a/chromium_edits/128.0.6613.186/chrome/browser/about_flags.cc.patch b/chromium_edits/128.0.6613.186/chrome/browser/about_flags.cc.patch new file mode 100644 index 00000000..6dc27a42 --- /dev/null +++ b/chromium_edits/128.0.6613.186/chrome/browser/about_flags.cc.patch @@ -0,0 +1,38 @@ +diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc +index 96370d4ac35a9..82bf3f78caccc 100644 +--- a/chrome/browser/about_flags.cc ++++ b/chrome/browser/about_flags.cc +@@ -220,6 +220,7 @@ + #include "third_party/blink/public/common/features_generated.h" + #include "third_party/blink/public/common/forcedark/forcedark_switches.h" + #include "third_party/blink/public/common/switches.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + #include "ui/accessibility/accessibility_features.h" + #include "ui/accessibility/accessibility_switches.h" + #include "ui/base/ozone_buildflags.h" +@@ -320,6 +321,10 @@ + #include "extensions/common/switches.h" + #endif // BUILDFLAG(ENABLE_EXTENSIONS) + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "components/ipfs/ipfs_features.h" ++#endif ++ + #if BUILDFLAG(ENABLE_PDF) + #include "pdf/pdf_features.h" + #endif +@@ -10130,6 +10135,14 @@ const FeatureEntry kFeatureEntries[] = { + flag_descriptions::kOmitCorsClientCertDescription, kOsAll, + FEATURE_VALUE_TYPE(network::features::kOmitCorsClientCert)}, + ++#if BUILDFLAG(ENABLE_IPFS) ++ {"enable-ipfs", ++ flag_descriptions::kEnableIpfsName, ++ flag_descriptions::kEnableIpfsDescription, ++ kOsMac | kOsWin | kOsLinux,//TODO: These are the only variants currently getting built, but that is not likely to remain the case ++ FEATURE_VALUE_TYPE(ipfs::kEnableIpfs)}, ++#endif ++ + {"use-idna2008-non-transitional", + flag_descriptions::kUseIDNA2008NonTransitionalName, + flag_descriptions::kUseIDNA2008NonTransitionalDescription, kOsAll, diff --git a/chromium_edits/128.0.6613.186/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch b/chromium_edits/128.0.6613.186/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch new file mode 100644 index 00000000..f9965a24 --- /dev/null +++ b/chromium_edits/128.0.6613.186/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch @@ -0,0 +1,51 @@ +diff --git a/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc b/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc +index 9f234a2a7d41d..a9378ca80dc1e 100644 +--- a/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc ++++ b/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc +@@ -13,6 +13,7 @@ + #include "chrome/browser/profiles/profile_io_data.h" + #include "components/custom_handlers/protocol_handler_registry.h" + #include "content/public/common/url_constants.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + #include "url/url_util.h" + + #if BUILDFLAG(IS_ANDROID) +@@ -20,6 +21,11 @@ + #include "chrome/browser/ui/android/omnibox/jni_headers/ChromeAutocompleteSchemeClassifier_jni.h" + #endif + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "components/ipfs/ipfs_features.h" ++#endif ++ ++ + #if BUILDFLAG(IS_ANDROID) + static jlong + JNI_ChromeAutocompleteSchemeClassifier_CreateAutocompleteClassifier( +@@ -53,12 +59,20 @@ ChromeAutocompleteSchemeClassifier::GetInputTypeForScheme( + if (scheme.empty()) { + return metrics::OmniboxInputType::EMPTY; + } +- if (base::IsStringASCII(scheme) && +- (ProfileIOData::IsHandledProtocol(scheme) || +- base::EqualsCaseInsensitiveASCII(scheme, content::kViewSourceScheme) || +- base::EqualsCaseInsensitiveASCII(scheme, url::kJavaScriptScheme) || +- base::EqualsCaseInsensitiveASCII(scheme, url::kDataScheme))) { +- return metrics::OmniboxInputType::URL; ++ if (base::IsStringASCII(scheme)) { ++ if (ProfileIOData::IsHandledProtocol(scheme) || ++ base::EqualsCaseInsensitiveASCII(scheme, content::kViewSourceScheme) || ++ base::EqualsCaseInsensitiveASCII(scheme, url::kJavaScriptScheme) || ++ base::EqualsCaseInsensitiveASCII(scheme, url::kDataScheme)) { ++ return metrics::OmniboxInputType::URL; ++ } ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs) && ++ (base::EqualsCaseInsensitiveASCII(scheme, "ipfs") || base::EqualsCaseInsensitiveASCII(scheme, "ipns")) ++ ) { ++ return metrics::OmniboxInputType::URL; ++ } ++#endif + } + + // Also check for schemes registered via registerProtocolHandler(), which diff --git a/chromium_edits/128.0.6613.186/chrome/browser/chrome_content_browser_client.cc.patch b/chromium_edits/128.0.6613.186/chrome/browser/chrome_content_browser_client.cc.patch new file mode 100644 index 00000000..f506d677 --- /dev/null +++ b/chromium_edits/128.0.6613.186/chrome/browser/chrome_content_browser_client.cc.patch @@ -0,0 +1,81 @@ +diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc +index c4b98aa0e759f..0b645f5482fca 100644 +--- a/chrome/browser/chrome_content_browser_client.cc ++++ b/chrome/browser/chrome_content_browser_client.cc +@@ -396,6 +396,7 @@ + #include "third_party/blink/public/mojom/browsing_topics/browsing_topics.mojom.h" + #include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom.h" + #include "third_party/blink/public/public_buildflags.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + #include "third_party/widevine/cdm/buildflags.h" + #include "ui/base/clipboard/clipboard_format_type.h" + #include "ui/base/l10n/l10n_util.h" +@@ -516,6 +517,13 @@ + #include "chrome/browser/chrome_browser_main_posix.h" + #endif + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "chrome/browser/ipfs_extra_parts.h" ++#include "components/ipfs/interceptor.h" ++#include "components/ipfs/ipfs_features.h" ++#include "components/ipfs/url_loader_factory.h" ++#endif ++ + #if !BUILDFLAG(IS_ANDROID) + #include "chrome/browser/digital_credentials/digital_identity_provider_desktop.h" + #include "chrome/browser/preloading/preview/preview_navigation_throttle.h" +@@ -1870,6 +1878,11 @@ ChromeContentBrowserClient::CreateBrowserMainParts(bool is_integration_test) { + main_parts->AddParts( + std::make_unique()); + ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ main_parts->AddParts(std::make_unique()); ++ } ++#endif + return main_parts; + } + +@@ -6482,12 +6495,29 @@ void ChromeContentBrowserClient:: + const std::optional& request_initiator_origin, + NonNetworkURLLoaderFactoryMap* factories) { + #if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS) || \ +- !BUILDFLAG(IS_ANDROID) ++ !BUILDFLAG(IS_ANDROID) || BUILDFLAG(ENABLE_IPFS) + content::RenderFrameHost* frame_host = + RenderFrameHost::FromID(render_process_id, render_frame_id); + WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host); + #endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS) || \ + // !BUILDFLAG(IS_ANDROID) ++#if BUILDFLAG(ENABLE_IPFS) ++ if (!web_contents) { ++ VLOG(2) << "No web contents, can't register url loader factory."; ++ } else if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ network::mojom::URLLoaderFactory* default_factory = g_browser_process->system_network_context_manager()->GetURLLoaderFactory(); ++ auto* context = web_contents->GetBrowserContext(); ++ ipfs::IpfsURLLoaderFactory::Create( ++ factories, ++ context, ++ default_factory, ++ GetSystemNetworkContext(), ++ Profile::FromBrowserContext(context)->GetPrefs() ++ ); ++ } else { ++ LOG(INFO) << "IPFS disabled."; ++ } ++#endif // BUILDFLAG(ENABLE_IPFS) + + #if BUILDFLAG(IS_CHROMEOS_ASH) + if (web_contents) { +@@ -6633,6 +6663,11 @@ ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors( + scoped_refptr navigation_response_task_runner) { + std::vector> + interceptors; ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ interceptors.push_back(std::make_unique(g_browser_process->system_network_context_manager()->GetURLLoaderFactory(), GetSystemNetworkContext())); ++ } ++#endif + #if BUILDFLAG(ENABLE_OFFLINE_PAGES) + interceptors.push_back( + std::make_unique( diff --git a/chromium_edits/128.0.6613.186/chrome/browser/flag-metadata.json.patch b/chromium_edits/128.0.6613.186/chrome/browser/flag-metadata.json.patch new file mode 100644 index 00000000..f954d6b0 --- /dev/null +++ b/chromium_edits/128.0.6613.186/chrome/browser/flag-metadata.json.patch @@ -0,0 +1,16 @@ +diff --git a/chrome/browser/flag-metadata.json b/chrome/browser/flag-metadata.json +index fa225f6564471..e8444d0f88e84 100644 +--- a/chrome/browser/flag-metadata.json ++++ b/chrome/browser/flag-metadata.json +@@ -3386,6 +3386,11 @@ + "owners": [ "adamta@google.com", "chrome-feed-fundamentals@google.com" ], + "expiry_milestone": 130 + }, ++ { ++ "name": "enable-ipfs", ++ "owners": [ "//components/ipfs/OWNERS" ], ++ "expiry_milestone": 150 ++ }, + { + "name": "enable-isolated-sandboxed-iframes", + "owners": [ "wjmaclean@chromium.org", "alexmos@chromium.org", "creis@chromium.org" ], diff --git a/chromium_edits/128.0.6613.186/chrome/browser/flag_descriptions.cc.patch b/chromium_edits/128.0.6613.186/chrome/browser/flag_descriptions.cc.patch new file mode 100644 index 00000000..4d5c4d25 --- /dev/null +++ b/chromium_edits/128.0.6613.186/chrome/browser/flag_descriptions.cc.patch @@ -0,0 +1,16 @@ +diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc +index be5b3f2e79a5f..d61281fca8be5 100644 +--- a/chrome/browser/flag_descriptions.cc ++++ b/chrome/browser/flag_descriptions.cc +@@ -302,6 +302,11 @@ const char kEnableBenchmarkingChoiceDefaultFeatureStates[] = + const char kEnableBenchmarkingChoiceMatchFieldTrialTestingConfig[] = + "Match Field Trial Testing Config"; + ++#if BUILDFLAG(ENABLE_IPFS) ++extern const char kEnableIpfsName[] = "Enable IPFS"; ++extern const char kEnableIpfsDescription[] = "Enable ipfs:// and ipns:// URLs"; ++#endif ++ + const char kPreloadingOnPerformancePageName[] = + "Preloading Settings on Performance Page"; + const char kPreloadingOnPerformancePageDescription[] = diff --git a/chromium_edits/128.0.6613.186/chrome/browser/flag_descriptions.h.patch b/chromium_edits/128.0.6613.186/chrome/browser/flag_descriptions.h.patch new file mode 100644 index 00000000..ea921b20 --- /dev/null +++ b/chromium_edits/128.0.6613.186/chrome/browser/flag_descriptions.h.patch @@ -0,0 +1,24 @@ +diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h +index b14d6612eaa86..34aa125a87e57 100644 +--- a/chrome/browser/flag_descriptions.h ++++ b/chrome/browser/flag_descriptions.h +@@ -24,6 +24,7 @@ + #include "pdf/buildflags.h" + #include "printing/buildflags/buildflags.h" + #include "third_party/blink/public/common/buildflags.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + + // This file declares strings used in chrome://flags. These messages are not + // translated, because instead of end-users they target Chromium developers and +@@ -195,6 +196,11 @@ extern const char kEnableBenchmarkingChoiceDisabled[]; + extern const char kEnableBenchmarkingChoiceDefaultFeatureStates[]; + extern const char kEnableBenchmarkingChoiceMatchFieldTrialTestingConfig[]; + ++#if BUILDFLAG(ENABLE_IPFS) ++extern const char kEnableIpfsName[]; ++extern const char kEnableIpfsDescription[]; ++#endif ++ + extern const char kFontationsFontBackendName[]; + extern const char kFontationsFontBackendDescription[]; + diff --git a/chromium_edits/128.0.6613.186/chrome/browser/ipfs_extra_parts.cc b/chromium_edits/128.0.6613.186/chrome/browser/ipfs_extra_parts.cc new file mode 100644 index 00000000..90d2596f --- /dev/null +++ b/chromium_edits/128.0.6613.186/chrome/browser/ipfs_extra_parts.cc @@ -0,0 +1,10 @@ +#include "ipfs_extra_parts.h" + +#include "profiles/profile.h" + +#include + +void IpfsExtraParts::PostProfileInit(Profile* profile, bool /* is_initial_profile */ ) { + DCHECK(profile); + ipfs::InterRequestState::CreateForBrowserContext(profile, profile->GetPrefs()); +} diff --git a/chromium_edits/128.0.6613.186/chrome/browser/ipfs_extra_parts.h b/chromium_edits/128.0.6613.186/chrome/browser/ipfs_extra_parts.h new file mode 100644 index 00000000..2059c437 --- /dev/null +++ b/chromium_edits/128.0.6613.186/chrome/browser/ipfs_extra_parts.h @@ -0,0 +1,10 @@ +#ifndef IPFS_EXTRA_PART_H_ +#define IPFS_EXTRA_PART_H_ + +#include + +class IpfsExtraParts : public ChromeBrowserMainExtraParts { + void PostProfileInit(Profile* profile, bool is_initial_profile) override; +}; + +#endif // IPFS_EXTRA_PART_H_ diff --git a/chromium_edits/128.0.6613.186/chrome/browser/prefs/browser_prefs.cc.patch b/chromium_edits/128.0.6613.186/chrome/browser/prefs/browser_prefs.cc.patch new file mode 100644 index 00000000..6464d20f --- /dev/null +++ b/chromium_edits/128.0.6613.186/chrome/browser/prefs/browser_prefs.cc.patch @@ -0,0 +1,37 @@ +diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc +index 8cf6b5d7d4281..699490b84fc37 100644 +--- a/chrome/browser/prefs/browser_prefs.cc ++++ b/chrome/browser/prefs/browser_prefs.cc +@@ -199,6 +199,8 @@ + #include "printing/buildflags/buildflags.h" + #include "rlz/buildflags/buildflags.h" + #include "services/screen_ai/buildflags/buildflags.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" ++ + + #if BUILDFLAG(ENABLE_BACKGROUND_MODE) + #include "chrome/browser/background/background_mode_manager.h" +@@ -244,6 +246,11 @@ + #include "chrome/browser/pdf/pdf_pref_names.h" + #endif // BUILDFLAG(ENABLE_PDF) + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "components/ipfs/ipfs_features.h" ++#include "components/ipfs/preferences.h" ++#endif ++ + #if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE) + #include "chrome/browser/screen_ai/pref_names.h" + #endif +@@ -1783,6 +1790,11 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry, + IncognitoModePrefs::RegisterProfilePrefs(registry); + invalidation::PerUserTopicSubscriptionManager::RegisterProfilePrefs(registry); + invalidation::InvalidatorRegistrarWithMemory::RegisterProfilePrefs(registry); ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ ipfs::RegisterPreferences(registry); ++ } ++#endif + language::LanguagePrefs::RegisterProfilePrefs(registry); + login_detection::prefs::RegisterProfilePrefs(registry); + lookalikes::RegisterProfilePrefs(registry); diff --git a/chromium_edits/128.0.6613.186/chrome/browser/shell_integration_mac.mm.patch b/chromium_edits/128.0.6613.186/chrome/browser/shell_integration_mac.mm.patch new file mode 100644 index 00000000..220e2546 --- /dev/null +++ b/chromium_edits/128.0.6613.186/chrome/browser/shell_integration_mac.mm.patch @@ -0,0 +1,13 @@ +diff --git a/chrome/browser/shell_integration_mac.mm b/chrome/browser/shell_integration_mac.mm +index c6bb768979453..c0d0abb9c78f3 100644 +--- a/chrome/browser/shell_integration_mac.mm ++++ b/chrome/browser/shell_integration_mac.mm +@@ -79,6 +79,8 @@ bool SetAsDefaultBrowser() { + if (LSSetDefaultHandlerForURLScheme(CFSTR("https"), identifier) != noErr) { + return false; + } ++ LSSetDefaultHandlerForURLScheme(CFSTR("ipfs"), identifier); ++ LSSetDefaultHandlerForURLScheme(CFSTR("ipns"), identifier); + if (LSSetDefaultRoleHandlerForContentType(kUTTypeHTML, kLSRolesViewer, + identifier) != noErr) { + return false; diff --git a/chromium_edits/128.0.6613.186/chrome/common/chrome_content_client.cc.patch b/chromium_edits/128.0.6613.186/chrome/common/chrome_content_client.cc.patch new file mode 100644 index 00000000..d0ce5acb --- /dev/null +++ b/chromium_edits/128.0.6613.186/chrome/common/chrome_content_client.cc.patch @@ -0,0 +1,17 @@ +diff --git a/chrome/common/chrome_content_client.cc b/chrome/common/chrome_content_client.cc +index 23baff86bfc1f..df9417b28e153 100644 +--- a/chrome/common/chrome_content_client.cc ++++ b/chrome/common/chrome_content_client.cc +@@ -308,6 +308,12 @@ void ChromeContentClient::AddAdditionalSchemes(Schemes* schemes) { + #if BUILDFLAG(IS_ANDROID) + schemes->local_schemes.push_back(url::kContentScheme); + #endif ++ for ( const char* ip_s : {"ipfs", "ipns"} ) { ++ schemes->standard_schemes.push_back(ip_s); ++ schemes->cors_enabled_schemes.push_back(ip_s); ++ schemes->secure_schemes.push_back(ip_s); ++ schemes->csp_bypassing_schemes.push_back(ip_s); ++ } + } + + std::u16string ChromeContentClient::GetLocalizedString(int message_id) { diff --git a/chromium_edits/128.0.6613.186/chrome/installer/linux/common/desktop.template.patch b/chromium_edits/128.0.6613.186/chrome/installer/linux/common/desktop.template.patch new file mode 100644 index 00000000..dcd9460b --- /dev/null +++ b/chromium_edits/128.0.6613.186/chrome/installer/linux/common/desktop.template.patch @@ -0,0 +1,13 @@ +diff --git a/chrome/installer/linux/common/desktop.template b/chrome/installer/linux/common/desktop.template +index 2eb13ee1aba46..9af65726bde89 100644 +--- a/chrome/installer/linux/common/desktop.template ++++ b/chrome/installer/linux/common/desktop.template +@@ -111,7 +111,7 @@ Terminal=false + Icon=@@PACKAGE@@ + Type=Application + Categories=Network;WebBrowser; +-MimeType=application/pdf;application/rdf+xml;application/rss+xml;application/xhtml+xml;application/xhtml_xml;application/xml;image/gif;image/jpeg;image/png;image/webp;text/html;text/xml;x-scheme-handler/http;x-scheme-handler/https; ++MimeType=application/pdf;application/rdf+xml;application/rss+xml;application/xhtml+xml;application/xhtml_xml;application/xml;image/gif;image/jpeg;image/png;image/webp;text/html;text/xml;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/ipfs;x-scheme-handler/ipns; + Actions=new-window;new-private-window; + + [Desktop Action new-window] diff --git a/chromium_edits/128.0.6613.186/chrome/installer/util/shell_util.cc.patch b/chromium_edits/128.0.6613.186/chrome/installer/util/shell_util.cc.patch new file mode 100644 index 00000000..ff731765 --- /dev/null +++ b/chromium_edits/128.0.6613.186/chrome/installer/util/shell_util.cc.patch @@ -0,0 +1,20 @@ +diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc +index 87a2c70b6cb1a..50c52f1ef579e 100644 +--- a/chrome/installer/util/shell_util.cc ++++ b/chrome/installer/util/shell_util.cc +@@ -1523,11 +1523,12 @@ const wchar_t* ShellUtil::kDefaultFileAssociations[] = { + const wchar_t* ShellUtil::kPotentialFileAssociations[] = { + L".htm", L".html", L".pdf", L".shtml", L".svg", + L".xht", L".xhtml", L".webp", nullptr}; +-const wchar_t* ShellUtil::kBrowserProtocolAssociations[] = {L"http", L"https", +- nullptr}; ++const wchar_t* ShellUtil::kBrowserProtocolAssociations[] = { ++ L"http", L"https", L"ipfs", L"ipns", nullptr}; + const wchar_t* ShellUtil::kPotentialProtocolAssociations[] = { + L"http", L"https", L"irc", L"mailto", L"mms", L"news", L"nntp", +- L"sms", L"smsto", L"snews", L"tel", L"urn", L"webcal", nullptr}; ++ L"sms", L"smsto", L"snews", L"tel", L"urn", L"webcal", L"ipfs", ++ L"ipns", nullptr}; + const wchar_t* ShellUtil::kRegUrlProtocol = L"URL Protocol"; + const wchar_t* ShellUtil::kRegApplication = L"\\Application"; + const wchar_t* ShellUtil::kRegAppUserModelId = L"AppUserModelId"; diff --git a/chromium_edits/128.0.6613.186/components/cbor/reader.cc.patch b/chromium_edits/128.0.6613.186/components/cbor/reader.cc.patch new file mode 100644 index 00000000..88eef088 --- /dev/null +++ b/chromium_edits/128.0.6613.186/components/cbor/reader.cc.patch @@ -0,0 +1,44 @@ +diff --git a/components/cbor/reader.cc b/components/cbor/reader.cc +index 464e93937d8d7..220dd4960cd2b 100644 +--- a/components/cbor/reader.cc ++++ b/components/cbor/reader.cc +@@ -22,7 +22,7 @@ + namespace cbor { + + namespace constants { +-const char kUnsupportedMajorType[] = "Unsupported major type."; ++const char kUnsupportedMajorType[] = "Unsupported major type operation."; + } + + namespace { +@@ -156,7 +156,11 @@ std::optional Reader::DecodeCompleteDataItem(const Config& config, + case Value::Type::FLOAT_VALUE: + // Floating point values also go here since they are also type 7. + return DecodeToSimpleValueOrFloat(*header, config); +- case Value::Type::TAG: // We explicitly don't support TAG. ++ case Value::Type::TAG: ++ if (config.parse_tags) { ++ return ReadTagContent(*header, config, max_nesting_level); ++ } ++ break; + case Value::Type::NONE: + case Value::Type::INVALID_UTF8: + break; +@@ -347,6 +351,17 @@ std::optional Reader::ReadByteStringContent( + return Value(std::move(cbor_byte_string)); + } + ++std::optional Reader::ReadTagContent( ++ const Reader::DataItemHeader& header, ++ const Config& config, ++ int max_nesting_level) { ++ auto tagged_content = DecodeCompleteDataItem(config, max_nesting_level); ++ if (tagged_content.has_value()) { ++ tagged_content.value().SetTag(header.value); ++ } ++ return tagged_content; ++} ++ + std::optional Reader::ReadArrayContent( + const Reader::DataItemHeader& header, + const Config& config, diff --git a/chromium_edits/128.0.6613.186/components/cbor/reader.h.patch b/chromium_edits/128.0.6613.186/components/cbor/reader.h.patch new file mode 100644 index 00000000..2dbc0534 --- /dev/null +++ b/chromium_edits/128.0.6613.186/components/cbor/reader.h.patch @@ -0,0 +1,26 @@ +diff --git a/components/cbor/reader.h b/components/cbor/reader.h +index 5f11ba48ba494..d4c9c489da4b6 100644 +--- a/components/cbor/reader.h ++++ b/components/cbor/reader.h +@@ -131,6 +131,11 @@ class CBOR_EXPORT Reader { + // during decoding will set raise the `UNSUPPORTED_FLOATING_POINT_VALUE` + // error. + bool allow_floating_point = false; ++ ++ // If the parser encounters a TAG element, should it be parsed out and ++ // the tag value saved (true), or should the entire node and its content ++ // be discarded (false) ++ bool parse_tags = false; + }; + + Reader(const Reader&) = delete; +@@ -205,6 +210,9 @@ class CBOR_EXPORT Reader { + std::optional ReadMapContent(const DataItemHeader& header, + const Config& config, + int max_nesting_level); ++ std::optional ReadTagContent(const DataItemHeader& header, ++ const Config& config, ++ int max_nesting_level); + std::optional ReadByte(); + std::optional> ReadBytes(uint64_t num_bytes); + bool IsKeyInOrder(const Value& new_key, diff --git a/chromium_edits/128.0.6613.186/components/cbor/reader_unittest.cc.patch b/chromium_edits/128.0.6613.186/components/cbor/reader_unittest.cc.patch new file mode 100644 index 00000000..150e0c73 --- /dev/null +++ b/chromium_edits/128.0.6613.186/components/cbor/reader_unittest.cc.patch @@ -0,0 +1,47 @@ +diff --git a/components/cbor/reader_unittest.cc b/components/cbor/reader_unittest.cc +index e5c02ceea3402..f26b8e77f6da3 100644 +--- a/components/cbor/reader_unittest.cc ++++ b/components/cbor/reader_unittest.cc +@@ -1449,5 +1449,42 @@ TEST(CBORReaderTest, AllowInvalidUTF8) { + EXPECT_FALSE(cbor); + EXPECT_EQ(Reader::DecoderError::INVALID_UTF8, error); + } ++TEST(CBORReaderTest, RejectsTagUnderDefaultConfig) { ++ static const uint8_t kTaggedCbor[] = { ++ 0xd8, 0x2a, 0x58, 0x25, 0x00, 0x01, 0x71, 0x12, 0x20, 0x69, 0xea, 0x07, ++ 0x40, 0xf9, 0x80, 0x7a, 0x28, 0xf4, 0xd9, 0x32, 0xc6, 0x2e, 0x7c, 0x1c, ++ 0x83, 0xbe, 0x05, 0x5e, 0x55, 0x07, 0x2c, 0x90, 0x26, 0x6a, 0xb3, 0xe7, ++ 0x9d, 0xf6, 0x3a, 0x36, 0x5b ++ }; ++ Reader::Config config; ++ auto cbor = Reader::Read(kTaggedCbor, config); ++ EXPECT_FALSE(cbor.has_value()); ++} ++TEST(CBORReaderTest, ReadsTagWhenConfiguredToDoSo) { ++ static const uint8_t kTaggedCbor[] = { ++ 0xd8, 0x2a, 0x58, 0x25, 0x00, 0x01, 0x71, 0x12, 0x20, 0x69, 0xea, 0x07, ++ 0x40, 0xf9, 0x80, 0x7a, 0x28, 0xf4, 0xd9, 0x32, 0xc6, 0x2e, 0x7c, 0x1c, ++ 0x83, 0xbe, 0x05, 0x5e, 0x55, 0x07, 0x2c, 0x90, 0x26, 0x6a, 0xb3, 0xe7, ++ 0x9d, 0xf6, 0x3a, 0x36, 0x5b ++ }; ++ Reader::Config config; ++ config.parse_tags = true; ++ auto cbor = Reader::Read(kTaggedCbor, config); ++ EXPECT_TRUE(cbor.has_value()); ++ auto& v = cbor.value(); ++ EXPECT_TRUE(v.has_tag()); ++ EXPECT_EQ(v.GetTag(),42UL); ++ EXPECT_TRUE(v.is_bytestring()); ++ EXPECT_EQ(v.type(), Value::Type::BYTE_STRING); ++ auto& bytes = v.GetBytestring(); ++ EXPECT_EQ(bytes.size(), 37UL); ++ EXPECT_EQ(bytes.at(0), 0x00);//identity multibase (e.g. not base-encoded, bytes are themselves) ++ EXPECT_EQ(bytes.at(1), 0x01);//CID version 1 ++ EXPECT_EQ(bytes.at(2), 0x71);//codec = dag-cbor ++ EXPECT_EQ(bytes.at(3), 0x12);//multihash = 18 = sha2-256 ++ EXPECT_EQ(bytes.at(4), 0x20);//hash length = 32 bytes ++ EXPECT_EQ(bytes.at(5), 0x69);//first byte of hash digest ++ EXPECT_EQ(bytes.at(36),0x5b);//last byte of hash digest ++} + + } // namespace cbor diff --git a/chromium_edits/128.0.6613.186/components/cbor/values.cc.patch b/chromium_edits/128.0.6613.186/components/cbor/values.cc.patch new file mode 100644 index 00000000..2832d248 --- /dev/null +++ b/chromium_edits/128.0.6613.186/components/cbor/values.cc.patch @@ -0,0 +1,145 @@ +diff --git a/components/cbor/values.cc b/components/cbor/values.cc +index 7c6b7a0aeaae3..5096311ba2a20 100644 +--- a/components/cbor/values.cc ++++ b/components/cbor/values.cc +@@ -66,32 +66,34 @@ Value::Value(Type type) : type_(type) { + NOTREACHED_IN_MIGRATION(); + } + +-Value::Value(SimpleValue in_simple) +- : type_(Type::SIMPLE_VALUE), simple_value_(in_simple) { ++Value::Value(SimpleValue in_simple, uint64_t tag) ++ : type_(Type::SIMPLE_VALUE), simple_value_(in_simple), tag_(tag) { + CHECK(static_cast(in_simple) >= 20 && static_cast(in_simple) <= 23); + } + +-Value::Value(bool boolean_value) : type_(Type::SIMPLE_VALUE) { ++Value::Value(bool boolean_value, uint64_t tag) : type_(Type::SIMPLE_VALUE), tag_(tag) { + simple_value_ = boolean_value ? Value::SimpleValue::TRUE_VALUE + : Value::SimpleValue::FALSE_VALUE; + } + +-Value::Value(double float_value) +- : type_(Type::FLOAT_VALUE), float_value_(float_value) {} ++Value::Value(double float_value, uint64_t tag) ++ : type_(Type::FLOAT_VALUE), float_value_(float_value), tag_(tag) {} + +-Value::Value(int integer_value) +- : Value(base::checked_cast(integer_value)) {} ++Value::Value(int integer_value, uint64_t tag) ++ : Value(base::checked_cast(integer_value), tag) {} + +-Value::Value(int64_t integer_value) : integer_value_(integer_value) { ++Value::Value(int64_t integer_value, uint64_t tag) : integer_value_(integer_value), tag_(tag) { + type_ = integer_value >= 0 ? Type::UNSIGNED : Type::NEGATIVE; + } + +-Value::Value(base::span in_bytes) ++Value::Value(base::span in_bytes, uint64_t tag) + : type_(Type::BYTE_STRING), +- bytestring_value_(in_bytes.begin(), in_bytes.end()) {} ++ bytestring_value_(in_bytes.begin(), in_bytes.end()), ++ tag_(tag) ++ {} + +-Value::Value(base::span in_bytes, Type type) +- : type_(type), bytestring_value_(in_bytes.begin(), in_bytes.end()) { ++Value::Value(base::span in_bytes, Type type, uint64_t tag) ++ : type_(type), bytestring_value_(in_bytes.begin(), in_bytes.end()), tag_(tag) { + DCHECK(type_ == Type::BYTE_STRING || type_ == Type::INVALID_UTF8); + } + +@@ -117,7 +119,8 @@ Value::Value(std::string&& in_string, Type type) noexcept : type_(type) { + } + } + +-Value::Value(std::string_view in_string, Type type) : type_(type) { ++Value::Value(std::string_view in_string, Type type, uint64_t tag) ++: type_(type), tag_(tag) { + switch (type_) { + case Type::STRING: + new (&string_value_) std::string(); +@@ -133,16 +136,18 @@ Value::Value(std::string_view in_string, Type type) : type_(type) { + } + } + +-Value::Value(const ArrayValue& in_array) : type_(Type::ARRAY), array_value_() { ++Value::Value(const ArrayValue& in_array, uint64_t tag) ++: type_(Type::ARRAY), array_value_(), tag_(tag) { + array_value_.reserve(in_array.size()); + for (const auto& val : in_array) + array_value_.emplace_back(val.Clone()); + } + +-Value::Value(ArrayValue&& in_array) noexcept +- : type_(Type::ARRAY), array_value_(std::move(in_array)) {} ++Value::Value(ArrayValue&& in_array, uint64_t tag) noexcept ++ : type_(Type::ARRAY), array_value_(std::move(in_array)), tag_(tag) {} + +-Value::Value(const MapValue& in_map) : type_(Type::MAP), map_value_() { ++Value::Value(const MapValue& in_map, uint64_t tag) ++: type_(Type::MAP), map_value_(), tag_(tag) { + map_value_.reserve(in_map.size()); + for (const auto& it : in_map) + map_value_.emplace_hint(map_value_.end(), it.first.Clone(), +@@ -168,31 +173,36 @@ Value Value::Clone() const { + case Type::NONE: + return Value(); + case Type::INVALID_UTF8: +- return Value(bytestring_value_, Type::INVALID_UTF8); ++ return Value(bytestring_value_, Type::INVALID_UTF8, tag_); + case Type::UNSIGNED: + case Type::NEGATIVE: +- return Value(integer_value_); ++ return Value(integer_value_, tag_); + case Type::BYTE_STRING: +- return Value(bytestring_value_); ++ return Value(bytestring_value_, tag_); + case Type::STRING: +- return Value(string_value_); ++ return Value(string_value_, Type::STRING, tag_); + case Type::ARRAY: +- return Value(array_value_); ++ return Value(array_value_, tag_); + case Type::MAP: +- return Value(map_value_); ++ return Value(map_value_, tag_); + case Type::TAG: + NOTREACHED_IN_MIGRATION() << constants::kUnsupportedMajorType; + return Value(); + case Type::SIMPLE_VALUE: +- return Value(simple_value_); ++ return Value(simple_value_, tag_); + case Type::FLOAT_VALUE: +- return Value(float_value_); ++ return Value(float_value_, tag_); + } + + NOTREACHED_IN_MIGRATION(); + return Value(); + } + ++Value& Value::SetTag(uint64_t tag) noexcept { ++ tag_ = tag; ++ return *this; ++} ++ + Value::SimpleValue Value::GetSimpleValue() const { + CHECK(is_simple()); + return simple_value_; +@@ -258,9 +268,14 @@ const Value::BinaryValue& Value::GetInvalidUTF8() const { + return bytestring_value_; + } + ++uint64_t Value::GetTag() const { ++ CHECK(has_tag()); ++ return tag_; ++} ++ + void Value::InternalMoveConstructFrom(Value&& that) { + type_ = that.type_; +- ++ tag_ = that.tag_; + switch (type_) { + case Type::UNSIGNED: + case Type::NEGATIVE: diff --git a/chromium_edits/128.0.6613.186/components/cbor/values.h.patch b/chromium_edits/128.0.6613.186/components/cbor/values.h.patch new file mode 100644 index 00000000..5556e8c5 --- /dev/null +++ b/chromium_edits/128.0.6613.186/components/cbor/values.h.patch @@ -0,0 +1,79 @@ +diff --git a/components/cbor/values.h b/components/cbor/values.h +index d55369f1a71bf..7dabb368c51d6 100644 +--- a/components/cbor/values.h ++++ b/components/cbor/values.h +@@ -125,28 +125,29 @@ class CBOR_EXPORT Value { + + explicit Value(Type type); + +- explicit Value(SimpleValue in_simple); +- explicit Value(bool boolean_value); +- explicit Value(double in_float); ++ explicit Value(SimpleValue in_simple, uint64_t tag = NO_TAG); ++ explicit Value(bool boolean_value, uint64_t tag = NO_TAG); ++ explicit Value(double in_float, uint64_t tag = NO_TAG); + +- explicit Value(int integer_value); +- explicit Value(int64_t integer_value); ++ explicit Value(int integer_value, uint64_t tag = NO_TAG); ++ explicit Value(int64_t integer_value, uint64_t tag = NO_TAG); + explicit Value(uint64_t integer_value) = delete; + +- explicit Value(base::span in_bytes); ++ explicit Value(base::span in_bytes, uint64_t tag = NO_TAG); + explicit Value(BinaryValue&& in_bytes) noexcept; + + explicit Value(const char* in_string, Type type = Type::STRING); + explicit Value(std::string&& in_string, Type type = Type::STRING) noexcept; +- explicit Value(std::string_view in_string, Type type = Type::STRING); ++ explicit Value(std::string_view in_string, Type type = Type::STRING, uint64_t tag = NO_TAG); + +- explicit Value(const ArrayValue& in_array); +- explicit Value(ArrayValue&& in_array) noexcept; ++ explicit Value(const ArrayValue& in_array, uint64_t tag = NO_TAG); ++ explicit Value(ArrayValue&& in_array, uint64_t tag = NO_TAG) noexcept; + +- explicit Value(const MapValue& in_map); ++ explicit Value(const MapValue& in_map, uint64_t tag = NO_TAG); + explicit Value(MapValue&& in_map) noexcept; + + Value& operator=(Value&& that) noexcept; ++ Value& SetTag(uint64_t) noexcept; + + Value(const Value&) = delete; + Value& operator=(const Value&) = delete; +@@ -177,6 +178,7 @@ class CBOR_EXPORT Value { + bool is_string() const { return type() == Type::STRING; } + bool is_array() const { return type() == Type::ARRAY; } + bool is_map() const { return type() == Type::MAP; } ++ bool has_tag() const { return tag_ != NO_TAG; } + + // These will all fatally assert if the type doesn't match. + SimpleValue GetSimpleValue() const; +@@ -192,12 +194,13 @@ class CBOR_EXPORT Value { + const ArrayValue& GetArray() const; + const MapValue& GetMap() const; + const BinaryValue& GetInvalidUTF8() const; ++ uint64_t GetTag() const; + + private: + friend class Reader; + // This constructor allows INVALID_UTF8 values to be created, which only + // |Reader| and InvalidUTF8StringValueForTesting() may do. +- Value(base::span in_bytes, Type type); ++ Value(base::span in_bytes, Type type, uint64_t tag = NO_TAG); + + Type type_; + +@@ -211,6 +214,11 @@ class CBOR_EXPORT Value { + MapValue map_value_; + }; + ++ //This value specified as Invalid, ++ // used here to represent absence of TAG ++ constexpr static uint64_t NO_TAG = 0xFFFF; ++ uint64_t tag_ = NO_TAG; ++ + void InternalMoveConstructFrom(Value&& that); + void InternalCleanup(); + }; diff --git a/chromium_edits/128.0.6613.186/components/cbor/writer.cc.patch b/chromium_edits/128.0.6613.186/components/cbor/writer.cc.patch new file mode 100644 index 00000000..150c3fca --- /dev/null +++ b/chromium_edits/128.0.6613.186/components/cbor/writer.cc.patch @@ -0,0 +1,14 @@ +diff --git a/components/cbor/writer.cc b/components/cbor/writer.cc +index e7e47774abe9a..4c085d5693a38 100644 +--- a/components/cbor/writer.cc ++++ b/components/cbor/writer.cc +@@ -47,6 +47,9 @@ bool Writer::EncodeCBOR(const Value& node, + if (max_nesting_level < 0) + return false; + ++ if (node.has_tag()) { ++ StartItem(Value::Type::TAG, node.GetTag()); ++ } + switch (node.type()) { + case Value::Type::NONE: { + StartItem(Value::Type::BYTE_STRING, 0); diff --git a/chromium_edits/128.0.6613.186/components/cbor/writer_unittest.cc.patch b/chromium_edits/128.0.6613.186/components/cbor/writer_unittest.cc.patch new file mode 100644 index 00000000..1acf5f7f --- /dev/null +++ b/chromium_edits/128.0.6613.186/components/cbor/writer_unittest.cc.patch @@ -0,0 +1,36 @@ +diff --git a/components/cbor/writer_unittest.cc b/components/cbor/writer_unittest.cc +index ee11e7cb86712..b8942f1829a37 100644 +--- a/components/cbor/writer_unittest.cc ++++ b/components/cbor/writer_unittest.cc +@@ -523,4 +523,31 @@ TEST(CBORWriterTest, OverlyNestedCBOR) { + EXPECT_FALSE(Writer::Write(Value(map), 4).has_value()); + } + ++TEST(CBORWriterTest, CanWriteTag) { ++ std::array content{ ++ 0x00, 0x01, 0x71, 0x12, 0x20, ++ 0x69, 0xea, 0x07, 0x40, 0xf9, ++ 0x80, 0x7a, 0x28, 0xf4, 0xd9, ++ 0x32, 0xc6, 0x2e, 0x7c, 0x1c, ++ 0x83, 0xbe, 0x05, 0x5e, 0x55, ++ 0x07, 0x2c, 0x90, 0x26, 0x6a, ++ 0xb3, 0xe7, 0x9d, 0xf6, 0x3a, ++ 0x36, 0x5b ++ }; ++ Value to_write(content); ++ to_write.SetTag(42); ++ auto result = Writer::Write(to_write); ++ EXPECT_TRUE(result.has_value()); ++ auto& bytes = result.value(); ++ EXPECT_EQ(bytes.size(), 41UL); ++ EXPECT_EQ(bytes.at(0), 0xd8); ++ EXPECT_EQ(bytes.at(1), 0x2a); ++ EXPECT_EQ(bytes.at(2), 0x58); ++ EXPECT_EQ(bytes.at(3), 0x25); ++ for (auto i = 0UL; i < content.size(); ++i) { ++ ASSERT_LT(i + 4UL, bytes.size()); ++ ASSERT_EQ(content.at(i), bytes.at(i+4UL)); ++ } ++} ++ + } // namespace cbor diff --git a/chromium_edits/128.0.6613.186/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch b/chromium_edits/128.0.6613.186/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch new file mode 100644 index 00000000..31e2e173 --- /dev/null +++ b/chromium_edits/128.0.6613.186/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch @@ -0,0 +1,13 @@ +diff --git a/components/open_from_clipboard/clipboard_recent_content_generic.cc b/components/open_from_clipboard/clipboard_recent_content_generic.cc +index 9c0cda2dfb314..fea1c527c6d1d 100644 +--- a/components/open_from_clipboard/clipboard_recent_content_generic.cc ++++ b/components/open_from_clipboard/clipboard_recent_content_generic.cc +@@ -20,7 +20,7 @@ + namespace { + // Schemes appropriate for suggestion by ClipboardRecentContent. + const char* kAuthorizedSchemes[] = { +- url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme, ++ url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme, "ipfs", "ipns" + // TODO(mpearson): add support for chrome:// URLs. Right now the scheme + // for that lives in content and is accessible via + // GetEmbedderRepresentationOfAboutScheme() or content::kChromeUIScheme diff --git a/chromium_edits/128.0.6613.186/net/dns/dns_config_service_linux.cc.patch b/chromium_edits/128.0.6613.186/net/dns/dns_config_service_linux.cc.patch new file mode 100644 index 00000000..fd7227a5 --- /dev/null +++ b/chromium_edits/128.0.6613.186/net/dns/dns_config_service_linux.cc.patch @@ -0,0 +1,18 @@ +diff --git a/net/dns/dns_config_service_linux.cc b/net/dns/dns_config_service_linux.cc +index 7aaf9fa5b0b78..5a9f5b5a70dd9 100644 +--- a/net/dns/dns_config_service_linux.cc ++++ b/net/dns/dns_config_service_linux.cc +@@ -276,11 +276,11 @@ bool IsNsswitchConfigCompatible( + // Ignore any entries after `kDns` because Chrome will fallback to the + // system resolver if a result was not found in DNS. + return true; +- ++ case NsswitchReader::Service::kResolve: ++ break; + case NsswitchReader::Service::kMdns: + case NsswitchReader::Service::kMdns4: + case NsswitchReader::Service::kMdns6: +- case NsswitchReader::Service::kResolve: + case NsswitchReader::Service::kNis: + RecordIncompatibleNsswitchReason( + IncompatibleNsswitchReason::kIncompatibleService, diff --git a/chromium_edits/128.0.6613.186/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch b/chromium_edits/128.0.6613.186/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch new file mode 100644 index 00000000..663fe49e --- /dev/null +++ b/chromium_edits/128.0.6613.186/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch @@ -0,0 +1,15 @@ +diff --git a/third_party/blink/renderer/platform/weborigin/scheme_registry.cc b/third_party/blink/renderer/platform/weborigin/scheme_registry.cc +index e1bc209c337c5..6fbac29fcddfd 100644 +--- a/third_party/blink/renderer/platform/weborigin/scheme_registry.cc ++++ b/third_party/blink/renderer/platform/weborigin/scheme_registry.cc +@@ -68,8 +68,8 @@ class URLSchemesRegistry final { + // is considered secure. Additional checks are performed to ensure that + // other http pages are filtered out. + service_worker_schemes({"http", "https"}), +- fetch_api_schemes({"http", "https"}), +- allowed_in_referrer_schemes({"http", "https"}) { ++ fetch_api_schemes({"http", "https", "ipfs", "ipns"}), ++ allowed_in_referrer_schemes({"http", "https", "ipfs", "ipns"}) { + for (auto& scheme : url::GetCorsEnabledSchemes()) + cors_enabled_schemes.insert(scheme.c_str()); + for (auto& scheme : url::GetCSPBypassingSchemes()) { diff --git a/chromium_edits/128.0.6613.186/url/BUILD.gn.patch b/chromium_edits/128.0.6613.186/url/BUILD.gn.patch new file mode 100644 index 00000000..be4bfca8 --- /dev/null +++ b/chromium_edits/128.0.6613.186/url/BUILD.gn.patch @@ -0,0 +1,32 @@ +diff --git a/url/BUILD.gn b/url/BUILD.gn +index f22b73bc29f06..df36977322ec7 100644 +--- a/url/BUILD.gn ++++ b/url/BUILD.gn +@@ -5,6 +5,7 @@ + import("//build/buildflag_header.gni") + import("//testing/libfuzzer/fuzzer_test.gni") + import("//testing/test.gni") ++import("//third_party/ipfs_client/args.gni") + import("features.gni") + + import("//build/config/cronet/config.gni") +@@ -67,6 +68,7 @@ component("url") { + public_deps = [ + "//base", + "//build:robolectric_buildflags", ++ "//third_party/ipfs_client:ipfs_buildflags", + ] + + configs += [ "//build/config/compiler:wexit_time_destructors" ] +@@ -89,6 +91,11 @@ component("url") { + public_configs = [ "//third_party/jdk" ] + } + ++ if (enable_ipfs) { ++ sources += [ "url_canon_ipfs.cc" ] ++ deps += [ "//third_party/ipfs_client:ipfs_client" ] ++ } ++ + if (is_win) { + # Don't conflict with Windows' "url.dll". + output_name = "url_lib" diff --git a/chromium_edits/128.0.6613.186/url/url_canon.h.patch b/chromium_edits/128.0.6613.186/url/url_canon.h.patch new file mode 100644 index 00000000..57a53f5b --- /dev/null +++ b/chromium_edits/128.0.6613.186/url/url_canon.h.patch @@ -0,0 +1,26 @@ +diff --git a/url/url_canon.h b/url/url_canon.h +index ab5ec90988943..d28d325a01fc0 100644 +--- a/url/url_canon.h ++++ b/url/url_canon.h +@@ -821,6 +821,21 @@ bool CanonicalizeMailtoURL(const char16_t* spec, + CanonOutput* output, + Parsed* new_parsed); + ++COMPONENT_EXPORT(URL) ++bool CanonicalizeIpfsURL(std::string_view spec, ++ const Parsed& parsed, ++ SchemeType scheme_type, ++ CharsetConverter* query_converter, ++ CanonOutput* output, ++ Parsed* new_parsed); ++COMPONENT_EXPORT(URL) ++bool CanonicalizeIpfsURL(std::basic_string_view spec, ++ const Parsed& parsed, ++ SchemeType scheme_type, ++ CharsetConverter* query_converter, ++ CanonOutput* output, ++ Parsed* new_parsed); ++ + // Part replacer -------------------------------------------------------------- + + // Internal structure used for storing separate strings for each component. diff --git a/chromium_edits/128.0.6613.186/url/url_canon_ipfs.cc b/chromium_edits/128.0.6613.186/url/url_canon_ipfs.cc new file mode 100644 index 00000000..e40732ee --- /dev/null +++ b/chromium_edits/128.0.6613.186/url/url_canon_ipfs.cc @@ -0,0 +1,54 @@ +#include "url_canon_internal.h" + +#include +#include + +#include + +bool url::CanonicalizeIpfsURL(std::string_view spec, + const Parsed& parsed, + SchemeType scheme_type, + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed) { + if (spec.size() < 1) { + return false; + } + if ( parsed.host.len < 1 ) { + return false; + } + auto cid_str = spec.substr( parsed.host.begin, static_cast(parsed.host.len) ); + auto cid = ipfs::Cid(cid_str); + if ( !cid.valid() ) { + cid = ipfs::id_cid::forText( std::string{cid_str} + " is not a valid CID." ); + } + auto as_str = cid.to_string(); + if ( as_str.empty() ) { + return false; + } + std::string stdurl{ spec.substr(0UL, static_cast(parsed.host.begin)) }; + stdurl.append( as_str ); + spec.remove_prefix(parsed.host.end()); + stdurl.append(spec); + auto len = static_cast(stdurl.size()); + Parsed parsed_input; + ParseStandardURL(stdurl.data(), len, &parsed_input); + return CanonicalizeStandardURL( + stdurl.data(), + parsed_input, + scheme_type, + charset_converter, + output, output_parsed + ); +} +bool url::CanonicalizeIpfsURL(std::basic_string_view spec, + const Parsed& parsed, + SchemeType scheme_type, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* new_parsed) { + RawCanonOutput<2048> as8; + ConvertUTF16ToUTF8(spec.data(), spec.size(), &as8); + return CanonicalizeIpfsURL({as8.data(), as8.length()}, parsed, scheme_type, + query_converter, output, new_parsed); +} diff --git a/chromium_edits/128.0.6613.186/url/url_util.cc.patch b/chromium_edits/128.0.6613.186/url/url_util.cc.patch new file mode 100644 index 00000000..988797b0 --- /dev/null +++ b/chromium_edits/128.0.6613.186/url/url_util.cc.patch @@ -0,0 +1,45 @@ +diff --git a/url/url_util.cc b/url/url_util.cc +index ce5225e121f5d..79e33208f728e 100644 +--- a/url/url_util.cc ++++ b/url/url_util.cc +@@ -76,6 +76,8 @@ struct SchemeRegistry { + std::vector referrer_schemes = { + {kHttpsScheme, SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION}, + {kHttpScheme, SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION}, ++ {"ipfs", SCHEME_WITH_HOST}, ++ {"ipns", SCHEME_WITH_HOST}, + }; + + // Schemes that do not trigger mixed content warning. +@@ -84,6 +86,8 @@ struct SchemeRegistry { + kWssScheme, + kDataScheme, + kAboutScheme, ++ {"ipfs", SCHEME_WITH_HOST}, ++ {"ipns", SCHEME_WITH_HOST}, + }; + + // Schemes that normal pages cannot link to or access (i.e., with the same +@@ -105,6 +109,8 @@ struct SchemeRegistry { + kHttpsScheme, + kHttpScheme, + kDataScheme, ++ {"ipfs", SCHEME_WITH_HOST}, ++ {"ipns", SCHEME_WITH_HOST}, + }; + + // Schemes that can be used by web to store data (local storage, etc). +@@ -308,7 +314,12 @@ bool DoCanonicalize(const CHAR* spec, + success = CanonicalizeFileSystemURL( + spec, ParseFileSystemURL(std::basic_string_view(spec, spec_len)), + charset_converter, output, output_parsed); +- ++ } else if (DoCompareSchemeComponent(spec, scheme, "ipfs")) { ++ auto spec_view = std::basic_string_view(spec, spec_len); ++ // Switch multibase away from case-sensitive ones before continuing canonicalization. ++ auto parsed_input = ParseStandardURL(spec_view); ++ success = CanonicalizeIpfsURL(spec_view, parsed_input, scheme_type, ++ charset_converter, output, output_parsed); + } else if (DoIsStandard(spec, scheme, &scheme_type)) { + // All "normal" URLs. + success = CanonicalizeStandardURL( diff --git a/chromium_edits/131.0.6738.0/chrome/browser/BUILD.gn.patch b/chromium_edits/131.0.6738.0/chrome/browser/BUILD.gn.patch new file mode 100644 index 00000000..c52dbb78 --- /dev/null +++ b/chromium_edits/131.0.6738.0/chrome/browser/BUILD.gn.patch @@ -0,0 +1,27 @@ +diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn +index 420eb64a63436..9777ec829f35f 100644 +--- a/chrome/browser/BUILD.gn ++++ b/chrome/browser/BUILD.gn +@@ -40,6 +40,7 @@ import("//sandbox/features.gni") + import("//services/screen_ai/buildflags/features.gni") + import("//testing/libfuzzer/fuzzer_test.gni") + import("//third_party/blink/public/public_features.gni") ++import("//third_party/ipfs_client/args.gni") + import("//third_party/protobuf/proto_library.gni") + import("//third_party/webrtc/webrtc.gni") + import("//third_party/widevine/cdm/widevine.gni") +@@ -2490,6 +2491,14 @@ static_library("browser") { + "//ui/webui", + ] + ++ if (enable_ipfs) { ++ sources += [ ++ "ipfs_extra_parts.cc", ++ "ipfs_extra_parts.h", ++ ] ++ deps += [ "//components/ipfs" ] ++ } ++ + # Platforms that have a network diagnostics dialog. All others fall through + # to the stub which is not implemented. + if (is_chromeos_ash) { diff --git a/chromium_edits/131.0.6738.0/chrome/browser/about_flags.cc.patch b/chromium_edits/131.0.6738.0/chrome/browser/about_flags.cc.patch new file mode 100644 index 00000000..efe54e59 --- /dev/null +++ b/chromium_edits/131.0.6738.0/chrome/browser/about_flags.cc.patch @@ -0,0 +1,38 @@ +diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc +index 3442100308555..b090a17e85952 100644 +--- a/chrome/browser/about_flags.cc ++++ b/chrome/browser/about_flags.cc +@@ -226,6 +226,7 @@ + #include "third_party/blink/public/common/features_generated.h" + #include "third_party/blink/public/common/forcedark/forcedark_switches.h" + #include "third_party/blink/public/common/switches.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + #include "ui/accessibility/accessibility_features.h" + #include "ui/accessibility/accessibility_switches.h" + #include "ui/base/ozone_buildflags.h" +@@ -326,6 +327,10 @@ + #include "extensions/common/switches.h" + #endif // BUILDFLAG(ENABLE_EXTENSIONS) + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "components/ipfs/ipfs_features.h" ++#endif ++ + #if BUILDFLAG(ENABLE_PDF) + #include "pdf/pdf_features.h" + #endif +@@ -9887,6 +9892,14 @@ const FeatureEntry kFeatureEntries[] = { + flag_descriptions::kOmitCorsClientCertDescription, kOsAll, + FEATURE_VALUE_TYPE(network::features::kOmitCorsClientCert)}, + ++#if BUILDFLAG(ENABLE_IPFS) ++ {"enable-ipfs", ++ flag_descriptions::kEnableIpfsName, ++ flag_descriptions::kEnableIpfsDescription, ++ kOsMac | kOsWin | kOsLinux,//TODO: These are the only variants currently getting built, but that is not likely to remain the case ++ FEATURE_VALUE_TYPE(ipfs::kEnableIpfs)}, ++#endif ++ + {"use-idna2008-non-transitional", + flag_descriptions::kUseIDNA2008NonTransitionalName, + flag_descriptions::kUseIDNA2008NonTransitionalDescription, kOsAll, diff --git a/chromium_edits/131.0.6738.0/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch b/chromium_edits/131.0.6738.0/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch new file mode 100644 index 00000000..f9965a24 --- /dev/null +++ b/chromium_edits/131.0.6738.0/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch @@ -0,0 +1,51 @@ +diff --git a/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc b/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc +index 9f234a2a7d41d..a9378ca80dc1e 100644 +--- a/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc ++++ b/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc +@@ -13,6 +13,7 @@ + #include "chrome/browser/profiles/profile_io_data.h" + #include "components/custom_handlers/protocol_handler_registry.h" + #include "content/public/common/url_constants.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + #include "url/url_util.h" + + #if BUILDFLAG(IS_ANDROID) +@@ -20,6 +21,11 @@ + #include "chrome/browser/ui/android/omnibox/jni_headers/ChromeAutocompleteSchemeClassifier_jni.h" + #endif + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "components/ipfs/ipfs_features.h" ++#endif ++ ++ + #if BUILDFLAG(IS_ANDROID) + static jlong + JNI_ChromeAutocompleteSchemeClassifier_CreateAutocompleteClassifier( +@@ -53,12 +59,20 @@ ChromeAutocompleteSchemeClassifier::GetInputTypeForScheme( + if (scheme.empty()) { + return metrics::OmniboxInputType::EMPTY; + } +- if (base::IsStringASCII(scheme) && +- (ProfileIOData::IsHandledProtocol(scheme) || +- base::EqualsCaseInsensitiveASCII(scheme, content::kViewSourceScheme) || +- base::EqualsCaseInsensitiveASCII(scheme, url::kJavaScriptScheme) || +- base::EqualsCaseInsensitiveASCII(scheme, url::kDataScheme))) { +- return metrics::OmniboxInputType::URL; ++ if (base::IsStringASCII(scheme)) { ++ if (ProfileIOData::IsHandledProtocol(scheme) || ++ base::EqualsCaseInsensitiveASCII(scheme, content::kViewSourceScheme) || ++ base::EqualsCaseInsensitiveASCII(scheme, url::kJavaScriptScheme) || ++ base::EqualsCaseInsensitiveASCII(scheme, url::kDataScheme)) { ++ return metrics::OmniboxInputType::URL; ++ } ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs) && ++ (base::EqualsCaseInsensitiveASCII(scheme, "ipfs") || base::EqualsCaseInsensitiveASCII(scheme, "ipns")) ++ ) { ++ return metrics::OmniboxInputType::URL; ++ } ++#endif + } + + // Also check for schemes registered via registerProtocolHandler(), which diff --git a/chromium_edits/131.0.6738.0/chrome/browser/chrome_content_browser_client.cc.patch b/chromium_edits/131.0.6738.0/chrome/browser/chrome_content_browser_client.cc.patch new file mode 100644 index 00000000..1d017d79 --- /dev/null +++ b/chromium_edits/131.0.6738.0/chrome/browser/chrome_content_browser_client.cc.patch @@ -0,0 +1,81 @@ +diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc +index dc8ff48895906..1d7b6871539d4 100644 +--- a/chrome/browser/chrome_content_browser_client.cc ++++ b/chrome/browser/chrome_content_browser_client.cc +@@ -406,6 +406,7 @@ + #include "third_party/blink/public/mojom/browsing_topics/browsing_topics.mojom.h" + #include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom.h" + #include "third_party/blink/public/public_buildflags.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + #include "third_party/widevine/cdm/buildflags.h" + #include "ui/base/clipboard/clipboard_format_type.h" + #include "ui/base/l10n/l10n_util.h" +@@ -533,6 +534,13 @@ + #include "chrome/browser/chrome_browser_main_posix.h" + #endif + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "chrome/browser/ipfs_extra_parts.h" ++#include "components/ipfs/interceptor.h" ++#include "components/ipfs/ipfs_features.h" ++#include "components/ipfs/url_loader_factory.h" ++#endif ++ + #if !BUILDFLAG(IS_ANDROID) + #include "chrome/browser/digital_credentials/digital_identity_provider_desktop.h" + #include "chrome/browser/preloading/preview/preview_navigation_throttle.h" +@@ -1866,6 +1874,11 @@ ChromeContentBrowserClient::CreateBrowserMainParts(bool is_integration_test) { + main_parts->AddParts( + std::make_unique()); + ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ main_parts->AddParts(std::make_unique()); ++ } ++#endif + return main_parts; + } + +@@ -6537,12 +6550,29 @@ void ChromeContentBrowserClient:: + const std::optional& request_initiator_origin, + NonNetworkURLLoaderFactoryMap* factories) { + #if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS) || \ +- !BUILDFLAG(IS_ANDROID) ++ !BUILDFLAG(IS_ANDROID) || BUILDFLAG(ENABLE_IPFS) + content::RenderFrameHost* frame_host = + RenderFrameHost::FromID(render_process_id, render_frame_id); + WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host); + #endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS) || \ + // !BUILDFLAG(IS_ANDROID) ++#if BUILDFLAG(ENABLE_IPFS) ++ if (!web_contents) { ++ VLOG(2) << "No web contents, can't register url loader factory."; ++ } else if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ network::mojom::URLLoaderFactory* default_factory = g_browser_process->system_network_context_manager()->GetURLLoaderFactory(); ++ auto* context = web_contents->GetBrowserContext(); ++ ipfs::IpfsURLLoaderFactory::Create( ++ factories, ++ context, ++ default_factory, ++ GetSystemNetworkContext(), ++ Profile::FromBrowserContext(context)->GetPrefs() ++ ); ++ } else { ++ LOG(INFO) << "IPFS disabled."; ++ } ++#endif // BUILDFLAG(ENABLE_IPFS) + + #if BUILDFLAG(IS_CHROMEOS_ASH) + if (web_contents) { +@@ -6690,6 +6720,11 @@ ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors( + scoped_refptr navigation_response_task_runner) { + std::vector> + interceptors; ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ interceptors.push_back(std::make_unique(g_browser_process->system_network_context_manager()->GetURLLoaderFactory(), GetSystemNetworkContext())); ++ } ++#endif + #if BUILDFLAG(ENABLE_OFFLINE_PAGES) + interceptors.push_back( + std::make_unique( diff --git a/chromium_edits/131.0.6738.0/chrome/browser/flag-metadata.json.patch b/chromium_edits/131.0.6738.0/chrome/browser/flag-metadata.json.patch new file mode 100644 index 00000000..5b355d78 --- /dev/null +++ b/chromium_edits/131.0.6738.0/chrome/browser/flag-metadata.json.patch @@ -0,0 +1,16 @@ +diff --git a/chrome/browser/flag-metadata.json b/chrome/browser/flag-metadata.json +index 4fc3afdc34cd8..8a7f4a161b55c 100644 +--- a/chrome/browser/flag-metadata.json ++++ b/chrome/browser/flag-metadata.json +@@ -3402,6 +3402,11 @@ + "owners": [ "adamta@google.com", "bling-get-set-up@google.com" ], + "expiry_milestone": 140 + }, ++ { ++ "name": "enable-ipfs", ++ "owners": [ "//components/ipfs/OWNERS" ], ++ "expiry_milestone": 150 ++ }, + { + "name": "enable-isolated-sandboxed-iframes", + "owners": [ "wjmaclean@chromium.org", "alexmos@chromium.org", "creis@chromium.org" ], diff --git a/chromium_edits/131.0.6738.0/chrome/browser/flag_descriptions.cc.patch b/chromium_edits/131.0.6738.0/chrome/browser/flag_descriptions.cc.patch new file mode 100644 index 00000000..fcb8ed12 --- /dev/null +++ b/chromium_edits/131.0.6738.0/chrome/browser/flag_descriptions.cc.patch @@ -0,0 +1,16 @@ +diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc +index b3f82c261f350..abed67a4cf591 100644 +--- a/chrome/browser/flag_descriptions.cc ++++ b/chrome/browser/flag_descriptions.cc +@@ -356,6 +356,11 @@ const char kEnableBookmarksSelectedTypeOnSigninForTestingDescription[] = + "sync-enable-bookmarks-in-transport-mode. Enables the bookmarks " + "UserSelectableType upon sign-in"; + ++#if BUILDFLAG(ENABLE_IPFS) ++extern const char kEnableIpfsName[] = "Enable IPFS"; ++extern const char kEnableIpfsDescription[] = "Enable ipfs:// and ipns:// URLs"; ++#endif ++ + const char kPreloadingOnPerformancePageName[] = + "Preloading Settings on Performance Page"; + const char kPreloadingOnPerformancePageDescription[] = diff --git a/chromium_edits/131.0.6738.0/chrome/browser/flag_descriptions.h.patch b/chromium_edits/131.0.6738.0/chrome/browser/flag_descriptions.h.patch new file mode 100644 index 00000000..93cf630e --- /dev/null +++ b/chromium_edits/131.0.6738.0/chrome/browser/flag_descriptions.h.patch @@ -0,0 +1,24 @@ +diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h +index 83b0edc7c9d5f..e3723ef1f9eea 100644 +--- a/chrome/browser/flag_descriptions.h ++++ b/chrome/browser/flag_descriptions.h +@@ -24,6 +24,7 @@ + #include "pdf/buildflags.h" + #include "printing/buildflags/buildflags.h" + #include "third_party/blink/public/common/buildflags.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + + // This file declares strings used in chrome://flags. These messages are not + // translated, because instead of end-users they target Chromium developers and +@@ -222,6 +223,11 @@ extern const char kEnableBenchmarkingChoiceMatchFieldTrialTestingConfig[]; + extern const char kEnableBookmarksSelectedTypeOnSigninForTestingName[]; + extern const char kEnableBookmarksSelectedTypeOnSigninForTestingDescription[]; + ++#if BUILDFLAG(ENABLE_IPFS) ++extern const char kEnableIpfsName[]; ++extern const char kEnableIpfsDescription[]; ++#endif ++ + extern const char kFontationsFontBackendName[]; + extern const char kFontationsFontBackendDescription[]; + diff --git a/chromium_edits/131.0.6738.0/chrome/browser/ipfs_extra_parts.cc b/chromium_edits/131.0.6738.0/chrome/browser/ipfs_extra_parts.cc new file mode 100644 index 00000000..90d2596f --- /dev/null +++ b/chromium_edits/131.0.6738.0/chrome/browser/ipfs_extra_parts.cc @@ -0,0 +1,10 @@ +#include "ipfs_extra_parts.h" + +#include "profiles/profile.h" + +#include + +void IpfsExtraParts::PostProfileInit(Profile* profile, bool /* is_initial_profile */ ) { + DCHECK(profile); + ipfs::InterRequestState::CreateForBrowserContext(profile, profile->GetPrefs()); +} diff --git a/chromium_edits/131.0.6738.0/chrome/browser/ipfs_extra_parts.h b/chromium_edits/131.0.6738.0/chrome/browser/ipfs_extra_parts.h new file mode 100644 index 00000000..2059c437 --- /dev/null +++ b/chromium_edits/131.0.6738.0/chrome/browser/ipfs_extra_parts.h @@ -0,0 +1,10 @@ +#ifndef IPFS_EXTRA_PART_H_ +#define IPFS_EXTRA_PART_H_ + +#include + +class IpfsExtraParts : public ChromeBrowserMainExtraParts { + void PostProfileInit(Profile* profile, bool is_initial_profile) override; +}; + +#endif // IPFS_EXTRA_PART_H_ diff --git a/chromium_edits/131.0.6738.0/chrome/browser/prefs/browser_prefs.cc.patch b/chromium_edits/131.0.6738.0/chrome/browser/prefs/browser_prefs.cc.patch new file mode 100644 index 00000000..a7818f8a --- /dev/null +++ b/chromium_edits/131.0.6738.0/chrome/browser/prefs/browser_prefs.cc.patch @@ -0,0 +1,36 @@ +diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc +index 55dc9f1366185..56d64775cd256 100644 +--- a/chrome/browser/prefs/browser_prefs.cc ++++ b/chrome/browser/prefs/browser_prefs.cc +@@ -202,6 +202,7 @@ + #include "ppapi/buildflags/buildflags.h" + #include "printing/buildflags/buildflags.h" + #include "rlz/buildflags/buildflags.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + + #if BUILDFLAG(ENABLE_BACKGROUND_MODE) + #include "chrome/browser/background/background_mode_manager.h" +@@ -250,6 +251,11 @@ + #include "chrome/browser/pdf/pdf_pref_names.h" + #endif // BUILDFLAG(ENABLE_PDF) + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "components/ipfs/ipfs_features.h" ++#include "components/ipfs/preferences.h" ++#endif ++ + #if BUILDFLAG(IS_ANDROID) + #include "chrome/browser/accessibility/accessibility_prefs/android/accessibility_prefs_controller.h" + #include "chrome/browser/android/bookmarks/partner_bookmarks_shim.h" +@@ -1913,6 +1919,11 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry, + IncognitoModePrefs::RegisterProfilePrefs(registry); + invalidation::PerUserTopicSubscriptionManager::RegisterProfilePrefs(registry); + invalidation::InvalidatorRegistrarWithMemory::RegisterProfilePrefs(registry); ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ ipfs::RegisterPreferences(registry); ++ } ++#endif + language::LanguagePrefs::RegisterProfilePrefs(registry); + login_detection::prefs::RegisterProfilePrefs(registry); + lookalikes::RegisterProfilePrefs(registry); diff --git a/chromium_edits/131.0.6738.0/chrome/browser/shell_integration_mac.mm.patch b/chromium_edits/131.0.6738.0/chrome/browser/shell_integration_mac.mm.patch new file mode 100644 index 00000000..220e2546 --- /dev/null +++ b/chromium_edits/131.0.6738.0/chrome/browser/shell_integration_mac.mm.patch @@ -0,0 +1,13 @@ +diff --git a/chrome/browser/shell_integration_mac.mm b/chrome/browser/shell_integration_mac.mm +index c6bb768979453..c0d0abb9c78f3 100644 +--- a/chrome/browser/shell_integration_mac.mm ++++ b/chrome/browser/shell_integration_mac.mm +@@ -79,6 +79,8 @@ bool SetAsDefaultBrowser() { + if (LSSetDefaultHandlerForURLScheme(CFSTR("https"), identifier) != noErr) { + return false; + } ++ LSSetDefaultHandlerForURLScheme(CFSTR("ipfs"), identifier); ++ LSSetDefaultHandlerForURLScheme(CFSTR("ipns"), identifier); + if (LSSetDefaultRoleHandlerForContentType(kUTTypeHTML, kLSRolesViewer, + identifier) != noErr) { + return false; diff --git a/chromium_edits/131.0.6738.0/chrome/common/chrome_content_client.cc.patch b/chromium_edits/131.0.6738.0/chrome/common/chrome_content_client.cc.patch new file mode 100644 index 00000000..d34894b4 --- /dev/null +++ b/chromium_edits/131.0.6738.0/chrome/common/chrome_content_client.cc.patch @@ -0,0 +1,17 @@ +diff --git a/chrome/common/chrome_content_client.cc b/chrome/common/chrome_content_client.cc +index 60515232467d7..14d5e12a76c76 100644 +--- a/chrome/common/chrome_content_client.cc ++++ b/chrome/common/chrome_content_client.cc +@@ -314,6 +314,12 @@ void ChromeContentClient::AddAdditionalSchemes(Schemes* schemes) { + #if BUILDFLAG(IS_ANDROID) + schemes->local_schemes.push_back(url::kContentScheme); + #endif ++ for ( const char* ip_s : {"ipfs", "ipns"} ) { ++ schemes->standard_schemes.push_back(ip_s); ++ schemes->cors_enabled_schemes.push_back(ip_s); ++ schemes->secure_schemes.push_back(ip_s); ++ schemes->csp_bypassing_schemes.push_back(ip_s); ++ } + } + + std::u16string ChromeContentClient::GetLocalizedString(int message_id) { diff --git a/chromium_edits/131.0.6738.0/chrome/installer/linux/common/desktop.template.patch b/chromium_edits/131.0.6738.0/chrome/installer/linux/common/desktop.template.patch new file mode 100644 index 00000000..dcd9460b --- /dev/null +++ b/chromium_edits/131.0.6738.0/chrome/installer/linux/common/desktop.template.patch @@ -0,0 +1,13 @@ +diff --git a/chrome/installer/linux/common/desktop.template b/chrome/installer/linux/common/desktop.template +index 2eb13ee1aba46..9af65726bde89 100644 +--- a/chrome/installer/linux/common/desktop.template ++++ b/chrome/installer/linux/common/desktop.template +@@ -111,7 +111,7 @@ Terminal=false + Icon=@@PACKAGE@@ + Type=Application + Categories=Network;WebBrowser; +-MimeType=application/pdf;application/rdf+xml;application/rss+xml;application/xhtml+xml;application/xhtml_xml;application/xml;image/gif;image/jpeg;image/png;image/webp;text/html;text/xml;x-scheme-handler/http;x-scheme-handler/https; ++MimeType=application/pdf;application/rdf+xml;application/rss+xml;application/xhtml+xml;application/xhtml_xml;application/xml;image/gif;image/jpeg;image/png;image/webp;text/html;text/xml;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/ipfs;x-scheme-handler/ipns; + Actions=new-window;new-private-window; + + [Desktop Action new-window] diff --git a/chromium_edits/131.0.6738.0/chrome/installer/util/shell_util.cc.patch b/chromium_edits/131.0.6738.0/chrome/installer/util/shell_util.cc.patch new file mode 100644 index 00000000..fccdad80 --- /dev/null +++ b/chromium_edits/131.0.6738.0/chrome/installer/util/shell_util.cc.patch @@ -0,0 +1,20 @@ +diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc +index c087d1c02bca4..382a36b9cd800 100644 +--- a/chrome/installer/util/shell_util.cc ++++ b/chrome/installer/util/shell_util.cc +@@ -1545,11 +1545,12 @@ const wchar_t* ShellUtil::kDefaultFileAssociations[] = { + const wchar_t* ShellUtil::kPotentialFileAssociations[] = { + L".htm", L".html", L".mhtml", L".pdf", L".shtml", + L".svg", L".xht", L".xhtml", L".webp", nullptr}; +-const wchar_t* ShellUtil::kBrowserProtocolAssociations[] = {L"http", L"https", +- nullptr}; ++const wchar_t* ShellUtil::kBrowserProtocolAssociations[] = { ++ L"http", L"https", L"ipfs", L"ipns", nullptr}; + const wchar_t* ShellUtil::kPotentialProtocolAssociations[] = { + L"http", L"https", L"irc", L"mailto", L"mms", L"news", L"nntp", +- L"sms", L"smsto", L"snews", L"tel", L"urn", L"webcal", nullptr}; ++ L"sms", L"smsto", L"snews", L"tel", L"urn", L"webcal", L"ipfs", ++ L"ipns", nullptr}; + const wchar_t* ShellUtil::kRegUrlProtocol = L"URL Protocol"; + const wchar_t* ShellUtil::kRegApplication = L"\\Application"; + const wchar_t* ShellUtil::kRegAppUserModelId = L"AppUserModelId"; diff --git a/chromium_edits/131.0.6738.0/components/cbor/reader.cc.patch b/chromium_edits/131.0.6738.0/components/cbor/reader.cc.patch new file mode 100644 index 00000000..88eef088 --- /dev/null +++ b/chromium_edits/131.0.6738.0/components/cbor/reader.cc.patch @@ -0,0 +1,44 @@ +diff --git a/components/cbor/reader.cc b/components/cbor/reader.cc +index 464e93937d8d7..220dd4960cd2b 100644 +--- a/components/cbor/reader.cc ++++ b/components/cbor/reader.cc +@@ -22,7 +22,7 @@ + namespace cbor { + + namespace constants { +-const char kUnsupportedMajorType[] = "Unsupported major type."; ++const char kUnsupportedMajorType[] = "Unsupported major type operation."; + } + + namespace { +@@ -156,7 +156,11 @@ std::optional Reader::DecodeCompleteDataItem(const Config& config, + case Value::Type::FLOAT_VALUE: + // Floating point values also go here since they are also type 7. + return DecodeToSimpleValueOrFloat(*header, config); +- case Value::Type::TAG: // We explicitly don't support TAG. ++ case Value::Type::TAG: ++ if (config.parse_tags) { ++ return ReadTagContent(*header, config, max_nesting_level); ++ } ++ break; + case Value::Type::NONE: + case Value::Type::INVALID_UTF8: + break; +@@ -347,6 +351,17 @@ std::optional Reader::ReadByteStringContent( + return Value(std::move(cbor_byte_string)); + } + ++std::optional Reader::ReadTagContent( ++ const Reader::DataItemHeader& header, ++ const Config& config, ++ int max_nesting_level) { ++ auto tagged_content = DecodeCompleteDataItem(config, max_nesting_level); ++ if (tagged_content.has_value()) { ++ tagged_content.value().SetTag(header.value); ++ } ++ return tagged_content; ++} ++ + std::optional Reader::ReadArrayContent( + const Reader::DataItemHeader& header, + const Config& config, diff --git a/chromium_edits/131.0.6738.0/components/cbor/reader.h.patch b/chromium_edits/131.0.6738.0/components/cbor/reader.h.patch new file mode 100644 index 00000000..2dbc0534 --- /dev/null +++ b/chromium_edits/131.0.6738.0/components/cbor/reader.h.patch @@ -0,0 +1,26 @@ +diff --git a/components/cbor/reader.h b/components/cbor/reader.h +index 5f11ba48ba494..d4c9c489da4b6 100644 +--- a/components/cbor/reader.h ++++ b/components/cbor/reader.h +@@ -131,6 +131,11 @@ class CBOR_EXPORT Reader { + // during decoding will set raise the `UNSUPPORTED_FLOATING_POINT_VALUE` + // error. + bool allow_floating_point = false; ++ ++ // If the parser encounters a TAG element, should it be parsed out and ++ // the tag value saved (true), or should the entire node and its content ++ // be discarded (false) ++ bool parse_tags = false; + }; + + Reader(const Reader&) = delete; +@@ -205,6 +210,9 @@ class CBOR_EXPORT Reader { + std::optional ReadMapContent(const DataItemHeader& header, + const Config& config, + int max_nesting_level); ++ std::optional ReadTagContent(const DataItemHeader& header, ++ const Config& config, ++ int max_nesting_level); + std::optional ReadByte(); + std::optional> ReadBytes(uint64_t num_bytes); + bool IsKeyInOrder(const Value& new_key, diff --git a/chromium_edits/131.0.6738.0/components/cbor/reader_unittest.cc.patch b/chromium_edits/131.0.6738.0/components/cbor/reader_unittest.cc.patch new file mode 100644 index 00000000..150e0c73 --- /dev/null +++ b/chromium_edits/131.0.6738.0/components/cbor/reader_unittest.cc.patch @@ -0,0 +1,47 @@ +diff --git a/components/cbor/reader_unittest.cc b/components/cbor/reader_unittest.cc +index e5c02ceea3402..f26b8e77f6da3 100644 +--- a/components/cbor/reader_unittest.cc ++++ b/components/cbor/reader_unittest.cc +@@ -1449,5 +1449,42 @@ TEST(CBORReaderTest, AllowInvalidUTF8) { + EXPECT_FALSE(cbor); + EXPECT_EQ(Reader::DecoderError::INVALID_UTF8, error); + } ++TEST(CBORReaderTest, RejectsTagUnderDefaultConfig) { ++ static const uint8_t kTaggedCbor[] = { ++ 0xd8, 0x2a, 0x58, 0x25, 0x00, 0x01, 0x71, 0x12, 0x20, 0x69, 0xea, 0x07, ++ 0x40, 0xf9, 0x80, 0x7a, 0x28, 0xf4, 0xd9, 0x32, 0xc6, 0x2e, 0x7c, 0x1c, ++ 0x83, 0xbe, 0x05, 0x5e, 0x55, 0x07, 0x2c, 0x90, 0x26, 0x6a, 0xb3, 0xe7, ++ 0x9d, 0xf6, 0x3a, 0x36, 0x5b ++ }; ++ Reader::Config config; ++ auto cbor = Reader::Read(kTaggedCbor, config); ++ EXPECT_FALSE(cbor.has_value()); ++} ++TEST(CBORReaderTest, ReadsTagWhenConfiguredToDoSo) { ++ static const uint8_t kTaggedCbor[] = { ++ 0xd8, 0x2a, 0x58, 0x25, 0x00, 0x01, 0x71, 0x12, 0x20, 0x69, 0xea, 0x07, ++ 0x40, 0xf9, 0x80, 0x7a, 0x28, 0xf4, 0xd9, 0x32, 0xc6, 0x2e, 0x7c, 0x1c, ++ 0x83, 0xbe, 0x05, 0x5e, 0x55, 0x07, 0x2c, 0x90, 0x26, 0x6a, 0xb3, 0xe7, ++ 0x9d, 0xf6, 0x3a, 0x36, 0x5b ++ }; ++ Reader::Config config; ++ config.parse_tags = true; ++ auto cbor = Reader::Read(kTaggedCbor, config); ++ EXPECT_TRUE(cbor.has_value()); ++ auto& v = cbor.value(); ++ EXPECT_TRUE(v.has_tag()); ++ EXPECT_EQ(v.GetTag(),42UL); ++ EXPECT_TRUE(v.is_bytestring()); ++ EXPECT_EQ(v.type(), Value::Type::BYTE_STRING); ++ auto& bytes = v.GetBytestring(); ++ EXPECT_EQ(bytes.size(), 37UL); ++ EXPECT_EQ(bytes.at(0), 0x00);//identity multibase (e.g. not base-encoded, bytes are themselves) ++ EXPECT_EQ(bytes.at(1), 0x01);//CID version 1 ++ EXPECT_EQ(bytes.at(2), 0x71);//codec = dag-cbor ++ EXPECT_EQ(bytes.at(3), 0x12);//multihash = 18 = sha2-256 ++ EXPECT_EQ(bytes.at(4), 0x20);//hash length = 32 bytes ++ EXPECT_EQ(bytes.at(5), 0x69);//first byte of hash digest ++ EXPECT_EQ(bytes.at(36),0x5b);//last byte of hash digest ++} + + } // namespace cbor diff --git a/chromium_edits/131.0.6738.0/components/cbor/values.cc.patch b/chromium_edits/131.0.6738.0/components/cbor/values.cc.patch new file mode 100644 index 00000000..fba23766 --- /dev/null +++ b/chromium_edits/131.0.6738.0/components/cbor/values.cc.patch @@ -0,0 +1,145 @@ +diff --git a/components/cbor/values.cc b/components/cbor/values.cc +index 303ac7fe300e3..7f796304e465a 100644 +--- a/components/cbor/values.cc ++++ b/components/cbor/values.cc +@@ -71,32 +71,34 @@ Value::Value(Type type) : type_(type) { + NOTREACHED_IN_MIGRATION(); + } + +-Value::Value(SimpleValue in_simple) +- : type_(Type::SIMPLE_VALUE), simple_value_(in_simple) { ++Value::Value(SimpleValue in_simple, uint64_t tag) ++ : type_(Type::SIMPLE_VALUE), simple_value_(in_simple), tag_(tag) { + CHECK(static_cast(in_simple) >= 20 && static_cast(in_simple) <= 23); + } + +-Value::Value(bool boolean_value) : type_(Type::SIMPLE_VALUE) { ++Value::Value(bool boolean_value, uint64_t tag) : type_(Type::SIMPLE_VALUE), tag_(tag) { + simple_value_ = boolean_value ? Value::SimpleValue::TRUE_VALUE + : Value::SimpleValue::FALSE_VALUE; + } + +-Value::Value(double float_value) +- : type_(Type::FLOAT_VALUE), float_value_(float_value) {} ++Value::Value(double float_value, uint64_t tag) ++ : type_(Type::FLOAT_VALUE), float_value_(float_value), tag_(tag) {} + +-Value::Value(int integer_value) +- : Value(base::checked_cast(integer_value)) {} ++Value::Value(int integer_value, uint64_t tag) ++ : Value(base::checked_cast(integer_value), tag) {} + +-Value::Value(int64_t integer_value) : integer_value_(integer_value) { ++Value::Value(int64_t integer_value, uint64_t tag) : integer_value_(integer_value), tag_(tag) { + type_ = integer_value >= 0 ? Type::UNSIGNED : Type::NEGATIVE; + } + +-Value::Value(base::span in_bytes) ++Value::Value(base::span in_bytes, uint64_t tag) + : type_(Type::BYTE_STRING), +- bytestring_value_(in_bytes.begin(), in_bytes.end()) {} ++ bytestring_value_(in_bytes.begin(), in_bytes.end()), ++ tag_(tag) ++ {} + +-Value::Value(base::span in_bytes, Type type) +- : type_(type), bytestring_value_(in_bytes.begin(), in_bytes.end()) { ++Value::Value(base::span in_bytes, Type type, uint64_t tag) ++ : type_(type), bytestring_value_(in_bytes.begin(), in_bytes.end()), tag_(tag) { + DCHECK(type_ == Type::BYTE_STRING || type_ == Type::INVALID_UTF8); + } + +@@ -122,7 +124,8 @@ Value::Value(std::string&& in_string, Type type) noexcept : type_(type) { + } + } + +-Value::Value(std::string_view in_string, Type type) : type_(type) { ++Value::Value(std::string_view in_string, Type type, uint64_t tag) ++: type_(type), tag_(tag) { + switch (type_) { + case Type::STRING: + new (&string_value_) std::string(); +@@ -138,16 +141,18 @@ Value::Value(std::string_view in_string, Type type) : type_(type) { + } + } + +-Value::Value(const ArrayValue& in_array) : type_(Type::ARRAY), array_value_() { ++Value::Value(const ArrayValue& in_array, uint64_t tag) ++: type_(Type::ARRAY), array_value_(), tag_(tag) { + array_value_.reserve(in_array.size()); + for (const auto& val : in_array) + array_value_.emplace_back(val.Clone()); + } + +-Value::Value(ArrayValue&& in_array) noexcept +- : type_(Type::ARRAY), array_value_(std::move(in_array)) {} ++Value::Value(ArrayValue&& in_array, uint64_t tag) noexcept ++ : type_(Type::ARRAY), array_value_(std::move(in_array)), tag_(tag) {} + +-Value::Value(const MapValue& in_map) : type_(Type::MAP), map_value_() { ++Value::Value(const MapValue& in_map, uint64_t tag) ++: type_(Type::MAP), map_value_(), tag_(tag) { + map_value_.reserve(in_map.size()); + for (const auto& it : in_map) + map_value_.emplace_hint(map_value_.end(), it.first.Clone(), +@@ -173,31 +178,36 @@ Value Value::Clone() const { + case Type::NONE: + return Value(); + case Type::INVALID_UTF8: +- return Value(bytestring_value_, Type::INVALID_UTF8); ++ return Value(bytestring_value_, Type::INVALID_UTF8, tag_); + case Type::UNSIGNED: + case Type::NEGATIVE: +- return Value(integer_value_); ++ return Value(integer_value_, tag_); + case Type::BYTE_STRING: +- return Value(bytestring_value_); ++ return Value(bytestring_value_, tag_); + case Type::STRING: +- return Value(string_value_); ++ return Value(string_value_, Type::STRING, tag_); + case Type::ARRAY: +- return Value(array_value_); ++ return Value(array_value_, tag_); + case Type::MAP: +- return Value(map_value_); ++ return Value(map_value_, tag_); + case Type::TAG: + NOTREACHED_IN_MIGRATION() << constants::kUnsupportedMajorType; + return Value(); + case Type::SIMPLE_VALUE: +- return Value(simple_value_); ++ return Value(simple_value_, tag_); + case Type::FLOAT_VALUE: +- return Value(float_value_); ++ return Value(float_value_, tag_); + } + + NOTREACHED_IN_MIGRATION(); + return Value(); + } + ++Value& Value::SetTag(uint64_t tag) noexcept { ++ tag_ = tag; ++ return *this; ++} ++ + Value::SimpleValue Value::GetSimpleValue() const { + CHECK(is_simple()); + return simple_value_; +@@ -263,9 +273,14 @@ const Value::BinaryValue& Value::GetInvalidUTF8() const { + return bytestring_value_; + } + ++uint64_t Value::GetTag() const { ++ CHECK(has_tag()); ++ return tag_; ++} ++ + void Value::InternalMoveConstructFrom(Value&& that) { + type_ = that.type_; +- ++ tag_ = that.tag_; + switch (type_) { + case Type::UNSIGNED: + case Type::NEGATIVE: diff --git a/chromium_edits/131.0.6738.0/components/cbor/values.h.patch b/chromium_edits/131.0.6738.0/components/cbor/values.h.patch new file mode 100644 index 00000000..5556e8c5 --- /dev/null +++ b/chromium_edits/131.0.6738.0/components/cbor/values.h.patch @@ -0,0 +1,79 @@ +diff --git a/components/cbor/values.h b/components/cbor/values.h +index d55369f1a71bf..7dabb368c51d6 100644 +--- a/components/cbor/values.h ++++ b/components/cbor/values.h +@@ -125,28 +125,29 @@ class CBOR_EXPORT Value { + + explicit Value(Type type); + +- explicit Value(SimpleValue in_simple); +- explicit Value(bool boolean_value); +- explicit Value(double in_float); ++ explicit Value(SimpleValue in_simple, uint64_t tag = NO_TAG); ++ explicit Value(bool boolean_value, uint64_t tag = NO_TAG); ++ explicit Value(double in_float, uint64_t tag = NO_TAG); + +- explicit Value(int integer_value); +- explicit Value(int64_t integer_value); ++ explicit Value(int integer_value, uint64_t tag = NO_TAG); ++ explicit Value(int64_t integer_value, uint64_t tag = NO_TAG); + explicit Value(uint64_t integer_value) = delete; + +- explicit Value(base::span in_bytes); ++ explicit Value(base::span in_bytes, uint64_t tag = NO_TAG); + explicit Value(BinaryValue&& in_bytes) noexcept; + + explicit Value(const char* in_string, Type type = Type::STRING); + explicit Value(std::string&& in_string, Type type = Type::STRING) noexcept; +- explicit Value(std::string_view in_string, Type type = Type::STRING); ++ explicit Value(std::string_view in_string, Type type = Type::STRING, uint64_t tag = NO_TAG); + +- explicit Value(const ArrayValue& in_array); +- explicit Value(ArrayValue&& in_array) noexcept; ++ explicit Value(const ArrayValue& in_array, uint64_t tag = NO_TAG); ++ explicit Value(ArrayValue&& in_array, uint64_t tag = NO_TAG) noexcept; + +- explicit Value(const MapValue& in_map); ++ explicit Value(const MapValue& in_map, uint64_t tag = NO_TAG); + explicit Value(MapValue&& in_map) noexcept; + + Value& operator=(Value&& that) noexcept; ++ Value& SetTag(uint64_t) noexcept; + + Value(const Value&) = delete; + Value& operator=(const Value&) = delete; +@@ -177,6 +178,7 @@ class CBOR_EXPORT Value { + bool is_string() const { return type() == Type::STRING; } + bool is_array() const { return type() == Type::ARRAY; } + bool is_map() const { return type() == Type::MAP; } ++ bool has_tag() const { return tag_ != NO_TAG; } + + // These will all fatally assert if the type doesn't match. + SimpleValue GetSimpleValue() const; +@@ -192,12 +194,13 @@ class CBOR_EXPORT Value { + const ArrayValue& GetArray() const; + const MapValue& GetMap() const; + const BinaryValue& GetInvalidUTF8() const; ++ uint64_t GetTag() const; + + private: + friend class Reader; + // This constructor allows INVALID_UTF8 values to be created, which only + // |Reader| and InvalidUTF8StringValueForTesting() may do. +- Value(base::span in_bytes, Type type); ++ Value(base::span in_bytes, Type type, uint64_t tag = NO_TAG); + + Type type_; + +@@ -211,6 +214,11 @@ class CBOR_EXPORT Value { + MapValue map_value_; + }; + ++ //This value specified as Invalid, ++ // used here to represent absence of TAG ++ constexpr static uint64_t NO_TAG = 0xFFFF; ++ uint64_t tag_ = NO_TAG; ++ + void InternalMoveConstructFrom(Value&& that); + void InternalCleanup(); + }; diff --git a/chromium_edits/131.0.6738.0/components/cbor/writer.cc.patch b/chromium_edits/131.0.6738.0/components/cbor/writer.cc.patch new file mode 100644 index 00000000..150c3fca --- /dev/null +++ b/chromium_edits/131.0.6738.0/components/cbor/writer.cc.patch @@ -0,0 +1,14 @@ +diff --git a/components/cbor/writer.cc b/components/cbor/writer.cc +index e7e47774abe9a..4c085d5693a38 100644 +--- a/components/cbor/writer.cc ++++ b/components/cbor/writer.cc +@@ -47,6 +47,9 @@ bool Writer::EncodeCBOR(const Value& node, + if (max_nesting_level < 0) + return false; + ++ if (node.has_tag()) { ++ StartItem(Value::Type::TAG, node.GetTag()); ++ } + switch (node.type()) { + case Value::Type::NONE: { + StartItem(Value::Type::BYTE_STRING, 0); diff --git a/chromium_edits/131.0.6738.0/components/cbor/writer_unittest.cc.patch b/chromium_edits/131.0.6738.0/components/cbor/writer_unittest.cc.patch new file mode 100644 index 00000000..1acf5f7f --- /dev/null +++ b/chromium_edits/131.0.6738.0/components/cbor/writer_unittest.cc.patch @@ -0,0 +1,36 @@ +diff --git a/components/cbor/writer_unittest.cc b/components/cbor/writer_unittest.cc +index ee11e7cb86712..b8942f1829a37 100644 +--- a/components/cbor/writer_unittest.cc ++++ b/components/cbor/writer_unittest.cc +@@ -523,4 +523,31 @@ TEST(CBORWriterTest, OverlyNestedCBOR) { + EXPECT_FALSE(Writer::Write(Value(map), 4).has_value()); + } + ++TEST(CBORWriterTest, CanWriteTag) { ++ std::array content{ ++ 0x00, 0x01, 0x71, 0x12, 0x20, ++ 0x69, 0xea, 0x07, 0x40, 0xf9, ++ 0x80, 0x7a, 0x28, 0xf4, 0xd9, ++ 0x32, 0xc6, 0x2e, 0x7c, 0x1c, ++ 0x83, 0xbe, 0x05, 0x5e, 0x55, ++ 0x07, 0x2c, 0x90, 0x26, 0x6a, ++ 0xb3, 0xe7, 0x9d, 0xf6, 0x3a, ++ 0x36, 0x5b ++ }; ++ Value to_write(content); ++ to_write.SetTag(42); ++ auto result = Writer::Write(to_write); ++ EXPECT_TRUE(result.has_value()); ++ auto& bytes = result.value(); ++ EXPECT_EQ(bytes.size(), 41UL); ++ EXPECT_EQ(bytes.at(0), 0xd8); ++ EXPECT_EQ(bytes.at(1), 0x2a); ++ EXPECT_EQ(bytes.at(2), 0x58); ++ EXPECT_EQ(bytes.at(3), 0x25); ++ for (auto i = 0UL; i < content.size(); ++i) { ++ ASSERT_LT(i + 4UL, bytes.size()); ++ ASSERT_EQ(content.at(i), bytes.at(i+4UL)); ++ } ++} ++ + } // namespace cbor diff --git a/chromium_edits/131.0.6738.0/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch b/chromium_edits/131.0.6738.0/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch new file mode 100644 index 00000000..ee376ce1 --- /dev/null +++ b/chromium_edits/131.0.6738.0/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch @@ -0,0 +1,13 @@ +diff --git a/components/open_from_clipboard/clipboard_recent_content_generic.cc b/components/open_from_clipboard/clipboard_recent_content_generic.cc +index 3683fadcc0914..440d4be132e5c 100644 +--- a/components/open_from_clipboard/clipboard_recent_content_generic.cc ++++ b/components/open_from_clipboard/clipboard_recent_content_generic.cc +@@ -20,7 +20,7 @@ + namespace { + // Schemes appropriate for suggestion by ClipboardRecentContent. + const char* kAuthorizedSchemes[] = { +- url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme, ++ url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme, "ipfs", "ipns" + // TODO(mpearson): add support for chrome:// URLs. Right now the scheme + // for that lives in content and is accessible via + // GetEmbedderRepresentationOfAboutScheme() or content::kChromeUIScheme diff --git a/chromium_edits/131.0.6738.0/net/dns/dns_config_service_linux.cc.patch b/chromium_edits/131.0.6738.0/net/dns/dns_config_service_linux.cc.patch new file mode 100644 index 00000000..fd7227a5 --- /dev/null +++ b/chromium_edits/131.0.6738.0/net/dns/dns_config_service_linux.cc.patch @@ -0,0 +1,18 @@ +diff --git a/net/dns/dns_config_service_linux.cc b/net/dns/dns_config_service_linux.cc +index 7aaf9fa5b0b78..5a9f5b5a70dd9 100644 +--- a/net/dns/dns_config_service_linux.cc ++++ b/net/dns/dns_config_service_linux.cc +@@ -276,11 +276,11 @@ bool IsNsswitchConfigCompatible( + // Ignore any entries after `kDns` because Chrome will fallback to the + // system resolver if a result was not found in DNS. + return true; +- ++ case NsswitchReader::Service::kResolve: ++ break; + case NsswitchReader::Service::kMdns: + case NsswitchReader::Service::kMdns4: + case NsswitchReader::Service::kMdns6: +- case NsswitchReader::Service::kResolve: + case NsswitchReader::Service::kNis: + RecordIncompatibleNsswitchReason( + IncompatibleNsswitchReason::kIncompatibleService, diff --git a/chromium_edits/131.0.6738.0/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch b/chromium_edits/131.0.6738.0/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch new file mode 100644 index 00000000..663fe49e --- /dev/null +++ b/chromium_edits/131.0.6738.0/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch @@ -0,0 +1,15 @@ +diff --git a/third_party/blink/renderer/platform/weborigin/scheme_registry.cc b/third_party/blink/renderer/platform/weborigin/scheme_registry.cc +index e1bc209c337c5..6fbac29fcddfd 100644 +--- a/third_party/blink/renderer/platform/weborigin/scheme_registry.cc ++++ b/third_party/blink/renderer/platform/weborigin/scheme_registry.cc +@@ -68,8 +68,8 @@ class URLSchemesRegistry final { + // is considered secure. Additional checks are performed to ensure that + // other http pages are filtered out. + service_worker_schemes({"http", "https"}), +- fetch_api_schemes({"http", "https"}), +- allowed_in_referrer_schemes({"http", "https"}) { ++ fetch_api_schemes({"http", "https", "ipfs", "ipns"}), ++ allowed_in_referrer_schemes({"http", "https", "ipfs", "ipns"}) { + for (auto& scheme : url::GetCorsEnabledSchemes()) + cors_enabled_schemes.insert(scheme.c_str()); + for (auto& scheme : url::GetCSPBypassingSchemes()) { diff --git a/chromium_edits/131.0.6738.0/url/BUILD.gn.patch b/chromium_edits/131.0.6738.0/url/BUILD.gn.patch new file mode 100644 index 00000000..be4bfca8 --- /dev/null +++ b/chromium_edits/131.0.6738.0/url/BUILD.gn.patch @@ -0,0 +1,32 @@ +diff --git a/url/BUILD.gn b/url/BUILD.gn +index f22b73bc29f06..df36977322ec7 100644 +--- a/url/BUILD.gn ++++ b/url/BUILD.gn +@@ -5,6 +5,7 @@ + import("//build/buildflag_header.gni") + import("//testing/libfuzzer/fuzzer_test.gni") + import("//testing/test.gni") ++import("//third_party/ipfs_client/args.gni") + import("features.gni") + + import("//build/config/cronet/config.gni") +@@ -67,6 +68,7 @@ component("url") { + public_deps = [ + "//base", + "//build:robolectric_buildflags", ++ "//third_party/ipfs_client:ipfs_buildflags", + ] + + configs += [ "//build/config/compiler:wexit_time_destructors" ] +@@ -89,6 +91,11 @@ component("url") { + public_configs = [ "//third_party/jdk" ] + } + ++ if (enable_ipfs) { ++ sources += [ "url_canon_ipfs.cc" ] ++ deps += [ "//third_party/ipfs_client:ipfs_client" ] ++ } ++ + if (is_win) { + # Don't conflict with Windows' "url.dll". + output_name = "url_lib" diff --git a/chromium_edits/131.0.6738.0/url/url_canon.h.patch b/chromium_edits/131.0.6738.0/url/url_canon.h.patch new file mode 100644 index 00000000..ffe72eea --- /dev/null +++ b/chromium_edits/131.0.6738.0/url/url_canon.h.patch @@ -0,0 +1,26 @@ +diff --git a/url/url_canon.h b/url/url_canon.h +index 22def4917fdd0..40dda81954a56 100644 +--- a/url/url_canon.h ++++ b/url/url_canon.h +@@ -821,6 +821,21 @@ bool CanonicalizeMailtoURL(const char16_t* spec, + CanonOutput* output, + Parsed* new_parsed); + ++COMPONENT_EXPORT(URL) ++bool CanonicalizeIpfsURL(std::string_view spec, ++ const Parsed& parsed, ++ SchemeType scheme_type, ++ CharsetConverter* query_converter, ++ CanonOutput* output, ++ Parsed* new_parsed); ++COMPONENT_EXPORT(URL) ++bool CanonicalizeIpfsURL(std::basic_string_view spec, ++ const Parsed& parsed, ++ SchemeType scheme_type, ++ CharsetConverter* query_converter, ++ CanonOutput* output, ++ Parsed* new_parsed); ++ + // Part replacer -------------------------------------------------------------- + + // Internal structure used for storing separate strings for each component. diff --git a/chromium_edits/131.0.6738.0/url/url_canon_ipfs.cc b/chromium_edits/131.0.6738.0/url/url_canon_ipfs.cc new file mode 100644 index 00000000..e40732ee --- /dev/null +++ b/chromium_edits/131.0.6738.0/url/url_canon_ipfs.cc @@ -0,0 +1,54 @@ +#include "url_canon_internal.h" + +#include +#include + +#include + +bool url::CanonicalizeIpfsURL(std::string_view spec, + const Parsed& parsed, + SchemeType scheme_type, + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed) { + if (spec.size() < 1) { + return false; + } + if ( parsed.host.len < 1 ) { + return false; + } + auto cid_str = spec.substr( parsed.host.begin, static_cast(parsed.host.len) ); + auto cid = ipfs::Cid(cid_str); + if ( !cid.valid() ) { + cid = ipfs::id_cid::forText( std::string{cid_str} + " is not a valid CID." ); + } + auto as_str = cid.to_string(); + if ( as_str.empty() ) { + return false; + } + std::string stdurl{ spec.substr(0UL, static_cast(parsed.host.begin)) }; + stdurl.append( as_str ); + spec.remove_prefix(parsed.host.end()); + stdurl.append(spec); + auto len = static_cast(stdurl.size()); + Parsed parsed_input; + ParseStandardURL(stdurl.data(), len, &parsed_input); + return CanonicalizeStandardURL( + stdurl.data(), + parsed_input, + scheme_type, + charset_converter, + output, output_parsed + ); +} +bool url::CanonicalizeIpfsURL(std::basic_string_view spec, + const Parsed& parsed, + SchemeType scheme_type, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* new_parsed) { + RawCanonOutput<2048> as8; + ConvertUTF16ToUTF8(spec.data(), spec.size(), &as8); + return CanonicalizeIpfsURL({as8.data(), as8.length()}, parsed, scheme_type, + query_converter, output, new_parsed); +} diff --git a/chromium_edits/131.0.6738.0/url/url_util.cc.patch b/chromium_edits/131.0.6738.0/url/url_util.cc.patch new file mode 100644 index 00000000..988797b0 --- /dev/null +++ b/chromium_edits/131.0.6738.0/url/url_util.cc.patch @@ -0,0 +1,45 @@ +diff --git a/url/url_util.cc b/url/url_util.cc +index ce5225e121f5d..79e33208f728e 100644 +--- a/url/url_util.cc ++++ b/url/url_util.cc +@@ -76,6 +76,8 @@ struct SchemeRegistry { + std::vector referrer_schemes = { + {kHttpsScheme, SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION}, + {kHttpScheme, SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION}, ++ {"ipfs", SCHEME_WITH_HOST}, ++ {"ipns", SCHEME_WITH_HOST}, + }; + + // Schemes that do not trigger mixed content warning. +@@ -84,6 +86,8 @@ struct SchemeRegistry { + kWssScheme, + kDataScheme, + kAboutScheme, ++ {"ipfs", SCHEME_WITH_HOST}, ++ {"ipns", SCHEME_WITH_HOST}, + }; + + // Schemes that normal pages cannot link to or access (i.e., with the same +@@ -105,6 +109,8 @@ struct SchemeRegistry { + kHttpsScheme, + kHttpScheme, + kDataScheme, ++ {"ipfs", SCHEME_WITH_HOST}, ++ {"ipns", SCHEME_WITH_HOST}, + }; + + // Schemes that can be used by web to store data (local storage, etc). +@@ -308,7 +314,12 @@ bool DoCanonicalize(const CHAR* spec, + success = CanonicalizeFileSystemURL( + spec, ParseFileSystemURL(std::basic_string_view(spec, spec_len)), + charset_converter, output, output_parsed); +- ++ } else if (DoCompareSchemeComponent(spec, scheme, "ipfs")) { ++ auto spec_view = std::basic_string_view(spec, spec_len); ++ // Switch multibase away from case-sensitive ones before continuing canonicalization. ++ auto parsed_input = ParseStandardURL(spec_view); ++ success = CanonicalizeIpfsURL(spec_view, parsed_input, scheme_type, ++ charset_converter, output, output_parsed); + } else if (DoIsStandard(spec, scheme, &scheme_type)) { + // All "normal" URLs. + success = CanonicalizeStandardURL( diff --git a/chromium_edits/131.0.6753.0/chrome/browser/BUILD.gn.patch b/chromium_edits/131.0.6753.0/chrome/browser/BUILD.gn.patch new file mode 100644 index 00000000..fa75df62 --- /dev/null +++ b/chromium_edits/131.0.6753.0/chrome/browser/BUILD.gn.patch @@ -0,0 +1,27 @@ +diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn +index 46825792cd5b9..2e8217c79e965 100644 +--- a/chrome/browser/BUILD.gn ++++ b/chrome/browser/BUILD.gn +@@ -40,6 +40,7 @@ import("//sandbox/features.gni") + import("//services/screen_ai/buildflags/features.gni") + import("//testing/libfuzzer/fuzzer_test.gni") + import("//third_party/blink/public/public_features.gni") ++import("//third_party/ipfs_client/args.gni") + import("//third_party/protobuf/proto_library.gni") + import("//third_party/webrtc/webrtc.gni") + import("//third_party/widevine/cdm/widevine.gni") +@@ -2494,6 +2495,14 @@ static_library("browser") { + "//ui/webui", + ] + ++ if (enable_ipfs) { ++ sources += [ ++ "ipfs_extra_parts.cc", ++ "ipfs_extra_parts.h", ++ ] ++ deps += [ "//components/ipfs" ] ++ } ++ + # Platforms that have a network diagnostics dialog. All others fall through + # to the stub which is not implemented. + if (is_chromeos_ash) { diff --git a/chromium_edits/131.0.6753.0/chrome/browser/about_flags.cc.patch b/chromium_edits/131.0.6753.0/chrome/browser/about_flags.cc.patch new file mode 100644 index 00000000..869ff9f7 --- /dev/null +++ b/chromium_edits/131.0.6753.0/chrome/browser/about_flags.cc.patch @@ -0,0 +1,38 @@ +diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc +index ea0d83cc85495..a3e1a8262b7c1 100644 +--- a/chrome/browser/about_flags.cc ++++ b/chrome/browser/about_flags.cc +@@ -227,6 +227,7 @@ + #include "third_party/blink/public/common/features_generated.h" + #include "third_party/blink/public/common/forcedark/forcedark_switches.h" + #include "third_party/blink/public/common/switches.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + #include "ui/accessibility/accessibility_features.h" + #include "ui/accessibility/accessibility_switches.h" + #include "ui/base/ozone_buildflags.h" +@@ -327,6 +328,10 @@ + #include "extensions/common/switches.h" + #endif // BUILDFLAG(ENABLE_EXTENSIONS) + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "components/ipfs/ipfs_features.h" ++#endif ++ + #if BUILDFLAG(ENABLE_PDF) + #include "pdf/pdf_features.h" + #endif +@@ -9670,6 +9675,14 @@ const FeatureEntry kFeatureEntries[] = { + flag_descriptions::kOmitCorsClientCertDescription, kOsAll, + FEATURE_VALUE_TYPE(network::features::kOmitCorsClientCert)}, + ++#if BUILDFLAG(ENABLE_IPFS) ++ {"enable-ipfs", ++ flag_descriptions::kEnableIpfsName, ++ flag_descriptions::kEnableIpfsDescription, ++ kOsMac | kOsWin | kOsLinux,//TODO: These are the only variants currently getting built, but that is not likely to remain the case ++ FEATURE_VALUE_TYPE(ipfs::kEnableIpfs)}, ++#endif ++ + {"use-idna2008-non-transitional", + flag_descriptions::kUseIDNA2008NonTransitionalName, + flag_descriptions::kUseIDNA2008NonTransitionalDescription, kOsAll, diff --git a/chromium_edits/131.0.6753.0/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch b/chromium_edits/131.0.6753.0/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch new file mode 100644 index 00000000..f9965a24 --- /dev/null +++ b/chromium_edits/131.0.6753.0/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch @@ -0,0 +1,51 @@ +diff --git a/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc b/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc +index 9f234a2a7d41d..a9378ca80dc1e 100644 +--- a/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc ++++ b/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc +@@ -13,6 +13,7 @@ + #include "chrome/browser/profiles/profile_io_data.h" + #include "components/custom_handlers/protocol_handler_registry.h" + #include "content/public/common/url_constants.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + #include "url/url_util.h" + + #if BUILDFLAG(IS_ANDROID) +@@ -20,6 +21,11 @@ + #include "chrome/browser/ui/android/omnibox/jni_headers/ChromeAutocompleteSchemeClassifier_jni.h" + #endif + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "components/ipfs/ipfs_features.h" ++#endif ++ ++ + #if BUILDFLAG(IS_ANDROID) + static jlong + JNI_ChromeAutocompleteSchemeClassifier_CreateAutocompleteClassifier( +@@ -53,12 +59,20 @@ ChromeAutocompleteSchemeClassifier::GetInputTypeForScheme( + if (scheme.empty()) { + return metrics::OmniboxInputType::EMPTY; + } +- if (base::IsStringASCII(scheme) && +- (ProfileIOData::IsHandledProtocol(scheme) || +- base::EqualsCaseInsensitiveASCII(scheme, content::kViewSourceScheme) || +- base::EqualsCaseInsensitiveASCII(scheme, url::kJavaScriptScheme) || +- base::EqualsCaseInsensitiveASCII(scheme, url::kDataScheme))) { +- return metrics::OmniboxInputType::URL; ++ if (base::IsStringASCII(scheme)) { ++ if (ProfileIOData::IsHandledProtocol(scheme) || ++ base::EqualsCaseInsensitiveASCII(scheme, content::kViewSourceScheme) || ++ base::EqualsCaseInsensitiveASCII(scheme, url::kJavaScriptScheme) || ++ base::EqualsCaseInsensitiveASCII(scheme, url::kDataScheme)) { ++ return metrics::OmniboxInputType::URL; ++ } ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs) && ++ (base::EqualsCaseInsensitiveASCII(scheme, "ipfs") || base::EqualsCaseInsensitiveASCII(scheme, "ipns")) ++ ) { ++ return metrics::OmniboxInputType::URL; ++ } ++#endif + } + + // Also check for schemes registered via registerProtocolHandler(), which diff --git a/chromium_edits/131.0.6753.0/chrome/browser/chrome_content_browser_client.cc.patch b/chromium_edits/131.0.6753.0/chrome/browser/chrome_content_browser_client.cc.patch new file mode 100644 index 00000000..b8afa9b7 --- /dev/null +++ b/chromium_edits/131.0.6753.0/chrome/browser/chrome_content_browser_client.cc.patch @@ -0,0 +1,81 @@ +diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc +index fe6dae6984ae5..74e6fb018f168 100644 +--- a/chrome/browser/chrome_content_browser_client.cc ++++ b/chrome/browser/chrome_content_browser_client.cc +@@ -408,6 +408,7 @@ + #include "third_party/blink/public/mojom/browsing_topics/browsing_topics.mojom.h" + #include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom.h" + #include "third_party/blink/public/public_buildflags.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + #include "third_party/widevine/cdm/buildflags.h" + #include "ui/base/clipboard/clipboard_format_type.h" + #include "ui/base/l10n/l10n_util.h" +@@ -534,6 +535,13 @@ + #include "chrome/browser/chrome_browser_main_posix.h" + #endif + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "chrome/browser/ipfs_extra_parts.h" ++#include "components/ipfs/interceptor.h" ++#include "components/ipfs/ipfs_features.h" ++#include "components/ipfs/url_loader_factory.h" ++#endif ++ + #if !BUILDFLAG(IS_ANDROID) + #include "chrome/browser/digital_credentials/digital_identity_provider_desktop.h" + #include "chrome/browser/preloading/preview/preview_navigation_throttle.h" +@@ -1864,6 +1872,11 @@ ChromeContentBrowserClient::CreateBrowserMainParts(bool is_integration_test) { + main_parts->AddParts( + std::make_unique()); + ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ main_parts->AddParts(std::make_unique()); ++ } ++#endif + return main_parts; + } + +@@ -6558,12 +6571,29 @@ void ChromeContentBrowserClient:: + const std::optional& request_initiator_origin, + NonNetworkURLLoaderFactoryMap* factories) { + #if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS) || \ +- !BUILDFLAG(IS_ANDROID) ++ !BUILDFLAG(IS_ANDROID) || BUILDFLAG(ENABLE_IPFS) + content::RenderFrameHost* frame_host = + RenderFrameHost::FromID(render_process_id, render_frame_id); + WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host); + #endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS) || \ + // !BUILDFLAG(IS_ANDROID) ++#if BUILDFLAG(ENABLE_IPFS) ++ if (!web_contents) { ++ VLOG(2) << "No web contents, can't register url loader factory."; ++ } else if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ network::mojom::URLLoaderFactory* default_factory = g_browser_process->system_network_context_manager()->GetURLLoaderFactory(); ++ auto* context = web_contents->GetBrowserContext(); ++ ipfs::IpfsURLLoaderFactory::Create( ++ factories, ++ context, ++ default_factory, ++ GetSystemNetworkContext(), ++ Profile::FromBrowserContext(context)->GetPrefs() ++ ); ++ } else { ++ LOG(INFO) << "IPFS disabled."; ++ } ++#endif // BUILDFLAG(ENABLE_IPFS) + + #if BUILDFLAG(IS_CHROMEOS_ASH) + if (web_contents) { +@@ -6711,6 +6741,11 @@ ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors( + scoped_refptr navigation_response_task_runner) { + std::vector> + interceptors; ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ interceptors.push_back(std::make_unique(g_browser_process->system_network_context_manager()->GetURLLoaderFactory(), GetSystemNetworkContext())); ++ } ++#endif + #if BUILDFLAG(ENABLE_OFFLINE_PAGES) + interceptors.push_back( + std::make_unique( diff --git a/chromium_edits/131.0.6753.0/chrome/browser/flag-metadata.json.patch b/chromium_edits/131.0.6753.0/chrome/browser/flag-metadata.json.patch new file mode 100644 index 00000000..1de4c998 --- /dev/null +++ b/chromium_edits/131.0.6753.0/chrome/browser/flag-metadata.json.patch @@ -0,0 +1,16 @@ +diff --git a/chrome/browser/flag-metadata.json b/chrome/browser/flag-metadata.json +index 41e6c54e36b06..ffdc506f21b25 100644 +--- a/chrome/browser/flag-metadata.json ++++ b/chrome/browser/flag-metadata.json +@@ -3424,6 +3424,11 @@ + "owners": [ "adamta@google.com", "bling-get-set-up@google.com" ], + "expiry_milestone": 140 + }, ++ { ++ "name": "enable-ipfs", ++ "owners": [ "//components/ipfs/OWNERS" ], ++ "expiry_milestone": 150 ++ }, + { + "name": "enable-isolated-sandboxed-iframes", + "owners": [ "wjmaclean@chromium.org", "alexmos@chromium.org", "creis@chromium.org" ], diff --git a/chromium_edits/131.0.6753.0/chrome/browser/flag_descriptions.cc.patch b/chromium_edits/131.0.6753.0/chrome/browser/flag_descriptions.cc.patch new file mode 100644 index 00000000..10016a7c --- /dev/null +++ b/chromium_edits/131.0.6753.0/chrome/browser/flag_descriptions.cc.patch @@ -0,0 +1,16 @@ +diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc +index 16ab3e65e4ad9..8c56463ddef15 100644 +--- a/chrome/browser/flag_descriptions.cc ++++ b/chrome/browser/flag_descriptions.cc +@@ -362,6 +362,11 @@ const char kEnableBookmarksSelectedTypeOnSigninForTestingDescription[] = + "sync-enable-bookmarks-in-transport-mode. Enables the bookmarks " + "UserSelectableType upon sign-in"; + ++#if BUILDFLAG(ENABLE_IPFS) ++extern const char kEnableIpfsName[] = "Enable IPFS"; ++extern const char kEnableIpfsDescription[] = "Enable ipfs:// and ipns:// URLs"; ++#endif ++ + const char kPreloadingOnPerformancePageName[] = + "Preloading Settings on Performance Page"; + const char kPreloadingOnPerformancePageDescription[] = diff --git a/chromium_edits/131.0.6753.0/chrome/browser/flag_descriptions.h.patch b/chromium_edits/131.0.6753.0/chrome/browser/flag_descriptions.h.patch new file mode 100644 index 00000000..84df3ad6 --- /dev/null +++ b/chromium_edits/131.0.6753.0/chrome/browser/flag_descriptions.h.patch @@ -0,0 +1,24 @@ +diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h +index fddbc31b5506c..8970d1f416ee1 100644 +--- a/chrome/browser/flag_descriptions.h ++++ b/chrome/browser/flag_descriptions.h +@@ -24,6 +24,7 @@ + #include "pdf/buildflags.h" + #include "printing/buildflags/buildflags.h" + #include "third_party/blink/public/common/buildflags.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + + // This file declares strings used in chrome://flags. These messages are not + // translated, because instead of end-users they target Chromium developers and +@@ -225,6 +226,11 @@ extern const char kEnableBenchmarkingChoiceMatchFieldTrialTestingConfig[]; + extern const char kEnableBookmarksSelectedTypeOnSigninForTestingName[]; + extern const char kEnableBookmarksSelectedTypeOnSigninForTestingDescription[]; + ++#if BUILDFLAG(ENABLE_IPFS) ++extern const char kEnableIpfsName[]; ++extern const char kEnableIpfsDescription[]; ++#endif ++ + extern const char kFontationsFontBackendName[]; + extern const char kFontationsFontBackendDescription[]; + diff --git a/chromium_edits/131.0.6753.0/chrome/browser/ipfs_extra_parts.cc b/chromium_edits/131.0.6753.0/chrome/browser/ipfs_extra_parts.cc new file mode 100644 index 00000000..90d2596f --- /dev/null +++ b/chromium_edits/131.0.6753.0/chrome/browser/ipfs_extra_parts.cc @@ -0,0 +1,10 @@ +#include "ipfs_extra_parts.h" + +#include "profiles/profile.h" + +#include + +void IpfsExtraParts::PostProfileInit(Profile* profile, bool /* is_initial_profile */ ) { + DCHECK(profile); + ipfs::InterRequestState::CreateForBrowserContext(profile, profile->GetPrefs()); +} diff --git a/chromium_edits/131.0.6753.0/chrome/browser/ipfs_extra_parts.h b/chromium_edits/131.0.6753.0/chrome/browser/ipfs_extra_parts.h new file mode 100644 index 00000000..2059c437 --- /dev/null +++ b/chromium_edits/131.0.6753.0/chrome/browser/ipfs_extra_parts.h @@ -0,0 +1,10 @@ +#ifndef IPFS_EXTRA_PART_H_ +#define IPFS_EXTRA_PART_H_ + +#include + +class IpfsExtraParts : public ChromeBrowserMainExtraParts { + void PostProfileInit(Profile* profile, bool is_initial_profile) override; +}; + +#endif // IPFS_EXTRA_PART_H_ diff --git a/chromium_edits/131.0.6753.0/chrome/browser/prefs/browser_prefs.cc.patch b/chromium_edits/131.0.6753.0/chrome/browser/prefs/browser_prefs.cc.patch new file mode 100644 index 00000000..d4394b35 --- /dev/null +++ b/chromium_edits/131.0.6753.0/chrome/browser/prefs/browser_prefs.cc.patch @@ -0,0 +1,36 @@ +diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc +index 8cbedb551be9a..9436be19fd933 100644 +--- a/chrome/browser/prefs/browser_prefs.cc ++++ b/chrome/browser/prefs/browser_prefs.cc +@@ -201,6 +201,7 @@ + #include "ppapi/buildflags/buildflags.h" + #include "printing/buildflags/buildflags.h" + #include "rlz/buildflags/buildflags.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + + #if BUILDFLAG(ENABLE_BACKGROUND_MODE) + #include "chrome/browser/background/background_mode_manager.h" +@@ -249,6 +250,11 @@ + #include "chrome/browser/pdf/pdf_pref_names.h" + #endif // BUILDFLAG(ENABLE_PDF) + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "components/ipfs/ipfs_features.h" ++#include "components/ipfs/preferences.h" ++#endif ++ + #if BUILDFLAG(IS_ANDROID) + #include "chrome/browser/accessibility/accessibility_prefs/android/accessibility_prefs_controller.h" + #include "chrome/browser/android/bookmarks/partner_bookmarks_shim.h" +@@ -1924,6 +1930,11 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry, + IncognitoModePrefs::RegisterProfilePrefs(registry); + invalidation::PerUserTopicSubscriptionManager::RegisterProfilePrefs(registry); + invalidation::InvalidatorRegistrarWithMemory::RegisterProfilePrefs(registry); ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ ipfs::RegisterPreferences(registry); ++ } ++#endif + language::LanguagePrefs::RegisterProfilePrefs(registry); + login_detection::prefs::RegisterProfilePrefs(registry); + lookalikes::RegisterProfilePrefs(registry); diff --git a/chromium_edits/131.0.6753.0/chrome/browser/shell_integration_mac.mm.patch b/chromium_edits/131.0.6753.0/chrome/browser/shell_integration_mac.mm.patch new file mode 100644 index 00000000..220e2546 --- /dev/null +++ b/chromium_edits/131.0.6753.0/chrome/browser/shell_integration_mac.mm.patch @@ -0,0 +1,13 @@ +diff --git a/chrome/browser/shell_integration_mac.mm b/chrome/browser/shell_integration_mac.mm +index c6bb768979453..c0d0abb9c78f3 100644 +--- a/chrome/browser/shell_integration_mac.mm ++++ b/chrome/browser/shell_integration_mac.mm +@@ -79,6 +79,8 @@ bool SetAsDefaultBrowser() { + if (LSSetDefaultHandlerForURLScheme(CFSTR("https"), identifier) != noErr) { + return false; + } ++ LSSetDefaultHandlerForURLScheme(CFSTR("ipfs"), identifier); ++ LSSetDefaultHandlerForURLScheme(CFSTR("ipns"), identifier); + if (LSSetDefaultRoleHandlerForContentType(kUTTypeHTML, kLSRolesViewer, + identifier) != noErr) { + return false; diff --git a/chromium_edits/131.0.6753.0/chrome/common/chrome_content_client.cc.patch b/chromium_edits/131.0.6753.0/chrome/common/chrome_content_client.cc.patch new file mode 100644 index 00000000..d34894b4 --- /dev/null +++ b/chromium_edits/131.0.6753.0/chrome/common/chrome_content_client.cc.patch @@ -0,0 +1,17 @@ +diff --git a/chrome/common/chrome_content_client.cc b/chrome/common/chrome_content_client.cc +index 60515232467d7..14d5e12a76c76 100644 +--- a/chrome/common/chrome_content_client.cc ++++ b/chrome/common/chrome_content_client.cc +@@ -314,6 +314,12 @@ void ChromeContentClient::AddAdditionalSchemes(Schemes* schemes) { + #if BUILDFLAG(IS_ANDROID) + schemes->local_schemes.push_back(url::kContentScheme); + #endif ++ for ( const char* ip_s : {"ipfs", "ipns"} ) { ++ schemes->standard_schemes.push_back(ip_s); ++ schemes->cors_enabled_schemes.push_back(ip_s); ++ schemes->secure_schemes.push_back(ip_s); ++ schemes->csp_bypassing_schemes.push_back(ip_s); ++ } + } + + std::u16string ChromeContentClient::GetLocalizedString(int message_id) { diff --git a/chromium_edits/131.0.6753.0/chrome/installer/linux/common/desktop.template.patch b/chromium_edits/131.0.6753.0/chrome/installer/linux/common/desktop.template.patch new file mode 100644 index 00000000..dcd9460b --- /dev/null +++ b/chromium_edits/131.0.6753.0/chrome/installer/linux/common/desktop.template.patch @@ -0,0 +1,13 @@ +diff --git a/chrome/installer/linux/common/desktop.template b/chrome/installer/linux/common/desktop.template +index 2eb13ee1aba46..9af65726bde89 100644 +--- a/chrome/installer/linux/common/desktop.template ++++ b/chrome/installer/linux/common/desktop.template +@@ -111,7 +111,7 @@ Terminal=false + Icon=@@PACKAGE@@ + Type=Application + Categories=Network;WebBrowser; +-MimeType=application/pdf;application/rdf+xml;application/rss+xml;application/xhtml+xml;application/xhtml_xml;application/xml;image/gif;image/jpeg;image/png;image/webp;text/html;text/xml;x-scheme-handler/http;x-scheme-handler/https; ++MimeType=application/pdf;application/rdf+xml;application/rss+xml;application/xhtml+xml;application/xhtml_xml;application/xml;image/gif;image/jpeg;image/png;image/webp;text/html;text/xml;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/ipfs;x-scheme-handler/ipns; + Actions=new-window;new-private-window; + + [Desktop Action new-window] diff --git a/chromium_edits/131.0.6753.0/chrome/installer/util/shell_util.cc.patch b/chromium_edits/131.0.6753.0/chrome/installer/util/shell_util.cc.patch new file mode 100644 index 00000000..fccdad80 --- /dev/null +++ b/chromium_edits/131.0.6753.0/chrome/installer/util/shell_util.cc.patch @@ -0,0 +1,20 @@ +diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc +index c087d1c02bca4..382a36b9cd800 100644 +--- a/chrome/installer/util/shell_util.cc ++++ b/chrome/installer/util/shell_util.cc +@@ -1545,11 +1545,12 @@ const wchar_t* ShellUtil::kDefaultFileAssociations[] = { + const wchar_t* ShellUtil::kPotentialFileAssociations[] = { + L".htm", L".html", L".mhtml", L".pdf", L".shtml", + L".svg", L".xht", L".xhtml", L".webp", nullptr}; +-const wchar_t* ShellUtil::kBrowserProtocolAssociations[] = {L"http", L"https", +- nullptr}; ++const wchar_t* ShellUtil::kBrowserProtocolAssociations[] = { ++ L"http", L"https", L"ipfs", L"ipns", nullptr}; + const wchar_t* ShellUtil::kPotentialProtocolAssociations[] = { + L"http", L"https", L"irc", L"mailto", L"mms", L"news", L"nntp", +- L"sms", L"smsto", L"snews", L"tel", L"urn", L"webcal", nullptr}; ++ L"sms", L"smsto", L"snews", L"tel", L"urn", L"webcal", L"ipfs", ++ L"ipns", nullptr}; + const wchar_t* ShellUtil::kRegUrlProtocol = L"URL Protocol"; + const wchar_t* ShellUtil::kRegApplication = L"\\Application"; + const wchar_t* ShellUtil::kRegAppUserModelId = L"AppUserModelId"; diff --git a/chromium_edits/131.0.6753.0/components/cbor/reader.cc.patch b/chromium_edits/131.0.6753.0/components/cbor/reader.cc.patch new file mode 100644 index 00000000..88eef088 --- /dev/null +++ b/chromium_edits/131.0.6753.0/components/cbor/reader.cc.patch @@ -0,0 +1,44 @@ +diff --git a/components/cbor/reader.cc b/components/cbor/reader.cc +index 464e93937d8d7..220dd4960cd2b 100644 +--- a/components/cbor/reader.cc ++++ b/components/cbor/reader.cc +@@ -22,7 +22,7 @@ + namespace cbor { + + namespace constants { +-const char kUnsupportedMajorType[] = "Unsupported major type."; ++const char kUnsupportedMajorType[] = "Unsupported major type operation."; + } + + namespace { +@@ -156,7 +156,11 @@ std::optional Reader::DecodeCompleteDataItem(const Config& config, + case Value::Type::FLOAT_VALUE: + // Floating point values also go here since they are also type 7. + return DecodeToSimpleValueOrFloat(*header, config); +- case Value::Type::TAG: // We explicitly don't support TAG. ++ case Value::Type::TAG: ++ if (config.parse_tags) { ++ return ReadTagContent(*header, config, max_nesting_level); ++ } ++ break; + case Value::Type::NONE: + case Value::Type::INVALID_UTF8: + break; +@@ -347,6 +351,17 @@ std::optional Reader::ReadByteStringContent( + return Value(std::move(cbor_byte_string)); + } + ++std::optional Reader::ReadTagContent( ++ const Reader::DataItemHeader& header, ++ const Config& config, ++ int max_nesting_level) { ++ auto tagged_content = DecodeCompleteDataItem(config, max_nesting_level); ++ if (tagged_content.has_value()) { ++ tagged_content.value().SetTag(header.value); ++ } ++ return tagged_content; ++} ++ + std::optional Reader::ReadArrayContent( + const Reader::DataItemHeader& header, + const Config& config, diff --git a/chromium_edits/131.0.6753.0/components/cbor/reader.h.patch b/chromium_edits/131.0.6753.0/components/cbor/reader.h.patch new file mode 100644 index 00000000..2dbc0534 --- /dev/null +++ b/chromium_edits/131.0.6753.0/components/cbor/reader.h.patch @@ -0,0 +1,26 @@ +diff --git a/components/cbor/reader.h b/components/cbor/reader.h +index 5f11ba48ba494..d4c9c489da4b6 100644 +--- a/components/cbor/reader.h ++++ b/components/cbor/reader.h +@@ -131,6 +131,11 @@ class CBOR_EXPORT Reader { + // during decoding will set raise the `UNSUPPORTED_FLOATING_POINT_VALUE` + // error. + bool allow_floating_point = false; ++ ++ // If the parser encounters a TAG element, should it be parsed out and ++ // the tag value saved (true), or should the entire node and its content ++ // be discarded (false) ++ bool parse_tags = false; + }; + + Reader(const Reader&) = delete; +@@ -205,6 +210,9 @@ class CBOR_EXPORT Reader { + std::optional ReadMapContent(const DataItemHeader& header, + const Config& config, + int max_nesting_level); ++ std::optional ReadTagContent(const DataItemHeader& header, ++ const Config& config, ++ int max_nesting_level); + std::optional ReadByte(); + std::optional> ReadBytes(uint64_t num_bytes); + bool IsKeyInOrder(const Value& new_key, diff --git a/chromium_edits/131.0.6753.0/components/cbor/reader_unittest.cc.patch b/chromium_edits/131.0.6753.0/components/cbor/reader_unittest.cc.patch new file mode 100644 index 00000000..150e0c73 --- /dev/null +++ b/chromium_edits/131.0.6753.0/components/cbor/reader_unittest.cc.patch @@ -0,0 +1,47 @@ +diff --git a/components/cbor/reader_unittest.cc b/components/cbor/reader_unittest.cc +index e5c02ceea3402..f26b8e77f6da3 100644 +--- a/components/cbor/reader_unittest.cc ++++ b/components/cbor/reader_unittest.cc +@@ -1449,5 +1449,42 @@ TEST(CBORReaderTest, AllowInvalidUTF8) { + EXPECT_FALSE(cbor); + EXPECT_EQ(Reader::DecoderError::INVALID_UTF8, error); + } ++TEST(CBORReaderTest, RejectsTagUnderDefaultConfig) { ++ static const uint8_t kTaggedCbor[] = { ++ 0xd8, 0x2a, 0x58, 0x25, 0x00, 0x01, 0x71, 0x12, 0x20, 0x69, 0xea, 0x07, ++ 0x40, 0xf9, 0x80, 0x7a, 0x28, 0xf4, 0xd9, 0x32, 0xc6, 0x2e, 0x7c, 0x1c, ++ 0x83, 0xbe, 0x05, 0x5e, 0x55, 0x07, 0x2c, 0x90, 0x26, 0x6a, 0xb3, 0xe7, ++ 0x9d, 0xf6, 0x3a, 0x36, 0x5b ++ }; ++ Reader::Config config; ++ auto cbor = Reader::Read(kTaggedCbor, config); ++ EXPECT_FALSE(cbor.has_value()); ++} ++TEST(CBORReaderTest, ReadsTagWhenConfiguredToDoSo) { ++ static const uint8_t kTaggedCbor[] = { ++ 0xd8, 0x2a, 0x58, 0x25, 0x00, 0x01, 0x71, 0x12, 0x20, 0x69, 0xea, 0x07, ++ 0x40, 0xf9, 0x80, 0x7a, 0x28, 0xf4, 0xd9, 0x32, 0xc6, 0x2e, 0x7c, 0x1c, ++ 0x83, 0xbe, 0x05, 0x5e, 0x55, 0x07, 0x2c, 0x90, 0x26, 0x6a, 0xb3, 0xe7, ++ 0x9d, 0xf6, 0x3a, 0x36, 0x5b ++ }; ++ Reader::Config config; ++ config.parse_tags = true; ++ auto cbor = Reader::Read(kTaggedCbor, config); ++ EXPECT_TRUE(cbor.has_value()); ++ auto& v = cbor.value(); ++ EXPECT_TRUE(v.has_tag()); ++ EXPECT_EQ(v.GetTag(),42UL); ++ EXPECT_TRUE(v.is_bytestring()); ++ EXPECT_EQ(v.type(), Value::Type::BYTE_STRING); ++ auto& bytes = v.GetBytestring(); ++ EXPECT_EQ(bytes.size(), 37UL); ++ EXPECT_EQ(bytes.at(0), 0x00);//identity multibase (e.g. not base-encoded, bytes are themselves) ++ EXPECT_EQ(bytes.at(1), 0x01);//CID version 1 ++ EXPECT_EQ(bytes.at(2), 0x71);//codec = dag-cbor ++ EXPECT_EQ(bytes.at(3), 0x12);//multihash = 18 = sha2-256 ++ EXPECT_EQ(bytes.at(4), 0x20);//hash length = 32 bytes ++ EXPECT_EQ(bytes.at(5), 0x69);//first byte of hash digest ++ EXPECT_EQ(bytes.at(36),0x5b);//last byte of hash digest ++} + + } // namespace cbor diff --git a/chromium_edits/131.0.6753.0/components/cbor/values.cc.patch b/chromium_edits/131.0.6753.0/components/cbor/values.cc.patch new file mode 100644 index 00000000..fba23766 --- /dev/null +++ b/chromium_edits/131.0.6753.0/components/cbor/values.cc.patch @@ -0,0 +1,145 @@ +diff --git a/components/cbor/values.cc b/components/cbor/values.cc +index 303ac7fe300e3..7f796304e465a 100644 +--- a/components/cbor/values.cc ++++ b/components/cbor/values.cc +@@ -71,32 +71,34 @@ Value::Value(Type type) : type_(type) { + NOTREACHED_IN_MIGRATION(); + } + +-Value::Value(SimpleValue in_simple) +- : type_(Type::SIMPLE_VALUE), simple_value_(in_simple) { ++Value::Value(SimpleValue in_simple, uint64_t tag) ++ : type_(Type::SIMPLE_VALUE), simple_value_(in_simple), tag_(tag) { + CHECK(static_cast(in_simple) >= 20 && static_cast(in_simple) <= 23); + } + +-Value::Value(bool boolean_value) : type_(Type::SIMPLE_VALUE) { ++Value::Value(bool boolean_value, uint64_t tag) : type_(Type::SIMPLE_VALUE), tag_(tag) { + simple_value_ = boolean_value ? Value::SimpleValue::TRUE_VALUE + : Value::SimpleValue::FALSE_VALUE; + } + +-Value::Value(double float_value) +- : type_(Type::FLOAT_VALUE), float_value_(float_value) {} ++Value::Value(double float_value, uint64_t tag) ++ : type_(Type::FLOAT_VALUE), float_value_(float_value), tag_(tag) {} + +-Value::Value(int integer_value) +- : Value(base::checked_cast(integer_value)) {} ++Value::Value(int integer_value, uint64_t tag) ++ : Value(base::checked_cast(integer_value), tag) {} + +-Value::Value(int64_t integer_value) : integer_value_(integer_value) { ++Value::Value(int64_t integer_value, uint64_t tag) : integer_value_(integer_value), tag_(tag) { + type_ = integer_value >= 0 ? Type::UNSIGNED : Type::NEGATIVE; + } + +-Value::Value(base::span in_bytes) ++Value::Value(base::span in_bytes, uint64_t tag) + : type_(Type::BYTE_STRING), +- bytestring_value_(in_bytes.begin(), in_bytes.end()) {} ++ bytestring_value_(in_bytes.begin(), in_bytes.end()), ++ tag_(tag) ++ {} + +-Value::Value(base::span in_bytes, Type type) +- : type_(type), bytestring_value_(in_bytes.begin(), in_bytes.end()) { ++Value::Value(base::span in_bytes, Type type, uint64_t tag) ++ : type_(type), bytestring_value_(in_bytes.begin(), in_bytes.end()), tag_(tag) { + DCHECK(type_ == Type::BYTE_STRING || type_ == Type::INVALID_UTF8); + } + +@@ -122,7 +124,8 @@ Value::Value(std::string&& in_string, Type type) noexcept : type_(type) { + } + } + +-Value::Value(std::string_view in_string, Type type) : type_(type) { ++Value::Value(std::string_view in_string, Type type, uint64_t tag) ++: type_(type), tag_(tag) { + switch (type_) { + case Type::STRING: + new (&string_value_) std::string(); +@@ -138,16 +141,18 @@ Value::Value(std::string_view in_string, Type type) : type_(type) { + } + } + +-Value::Value(const ArrayValue& in_array) : type_(Type::ARRAY), array_value_() { ++Value::Value(const ArrayValue& in_array, uint64_t tag) ++: type_(Type::ARRAY), array_value_(), tag_(tag) { + array_value_.reserve(in_array.size()); + for (const auto& val : in_array) + array_value_.emplace_back(val.Clone()); + } + +-Value::Value(ArrayValue&& in_array) noexcept +- : type_(Type::ARRAY), array_value_(std::move(in_array)) {} ++Value::Value(ArrayValue&& in_array, uint64_t tag) noexcept ++ : type_(Type::ARRAY), array_value_(std::move(in_array)), tag_(tag) {} + +-Value::Value(const MapValue& in_map) : type_(Type::MAP), map_value_() { ++Value::Value(const MapValue& in_map, uint64_t tag) ++: type_(Type::MAP), map_value_(), tag_(tag) { + map_value_.reserve(in_map.size()); + for (const auto& it : in_map) + map_value_.emplace_hint(map_value_.end(), it.first.Clone(), +@@ -173,31 +178,36 @@ Value Value::Clone() const { + case Type::NONE: + return Value(); + case Type::INVALID_UTF8: +- return Value(bytestring_value_, Type::INVALID_UTF8); ++ return Value(bytestring_value_, Type::INVALID_UTF8, tag_); + case Type::UNSIGNED: + case Type::NEGATIVE: +- return Value(integer_value_); ++ return Value(integer_value_, tag_); + case Type::BYTE_STRING: +- return Value(bytestring_value_); ++ return Value(bytestring_value_, tag_); + case Type::STRING: +- return Value(string_value_); ++ return Value(string_value_, Type::STRING, tag_); + case Type::ARRAY: +- return Value(array_value_); ++ return Value(array_value_, tag_); + case Type::MAP: +- return Value(map_value_); ++ return Value(map_value_, tag_); + case Type::TAG: + NOTREACHED_IN_MIGRATION() << constants::kUnsupportedMajorType; + return Value(); + case Type::SIMPLE_VALUE: +- return Value(simple_value_); ++ return Value(simple_value_, tag_); + case Type::FLOAT_VALUE: +- return Value(float_value_); ++ return Value(float_value_, tag_); + } + + NOTREACHED_IN_MIGRATION(); + return Value(); + } + ++Value& Value::SetTag(uint64_t tag) noexcept { ++ tag_ = tag; ++ return *this; ++} ++ + Value::SimpleValue Value::GetSimpleValue() const { + CHECK(is_simple()); + return simple_value_; +@@ -263,9 +273,14 @@ const Value::BinaryValue& Value::GetInvalidUTF8() const { + return bytestring_value_; + } + ++uint64_t Value::GetTag() const { ++ CHECK(has_tag()); ++ return tag_; ++} ++ + void Value::InternalMoveConstructFrom(Value&& that) { + type_ = that.type_; +- ++ tag_ = that.tag_; + switch (type_) { + case Type::UNSIGNED: + case Type::NEGATIVE: diff --git a/chromium_edits/131.0.6753.0/components/cbor/values.h.patch b/chromium_edits/131.0.6753.0/components/cbor/values.h.patch new file mode 100644 index 00000000..5556e8c5 --- /dev/null +++ b/chromium_edits/131.0.6753.0/components/cbor/values.h.patch @@ -0,0 +1,79 @@ +diff --git a/components/cbor/values.h b/components/cbor/values.h +index d55369f1a71bf..7dabb368c51d6 100644 +--- a/components/cbor/values.h ++++ b/components/cbor/values.h +@@ -125,28 +125,29 @@ class CBOR_EXPORT Value { + + explicit Value(Type type); + +- explicit Value(SimpleValue in_simple); +- explicit Value(bool boolean_value); +- explicit Value(double in_float); ++ explicit Value(SimpleValue in_simple, uint64_t tag = NO_TAG); ++ explicit Value(bool boolean_value, uint64_t tag = NO_TAG); ++ explicit Value(double in_float, uint64_t tag = NO_TAG); + +- explicit Value(int integer_value); +- explicit Value(int64_t integer_value); ++ explicit Value(int integer_value, uint64_t tag = NO_TAG); ++ explicit Value(int64_t integer_value, uint64_t tag = NO_TAG); + explicit Value(uint64_t integer_value) = delete; + +- explicit Value(base::span in_bytes); ++ explicit Value(base::span in_bytes, uint64_t tag = NO_TAG); + explicit Value(BinaryValue&& in_bytes) noexcept; + + explicit Value(const char* in_string, Type type = Type::STRING); + explicit Value(std::string&& in_string, Type type = Type::STRING) noexcept; +- explicit Value(std::string_view in_string, Type type = Type::STRING); ++ explicit Value(std::string_view in_string, Type type = Type::STRING, uint64_t tag = NO_TAG); + +- explicit Value(const ArrayValue& in_array); +- explicit Value(ArrayValue&& in_array) noexcept; ++ explicit Value(const ArrayValue& in_array, uint64_t tag = NO_TAG); ++ explicit Value(ArrayValue&& in_array, uint64_t tag = NO_TAG) noexcept; + +- explicit Value(const MapValue& in_map); ++ explicit Value(const MapValue& in_map, uint64_t tag = NO_TAG); + explicit Value(MapValue&& in_map) noexcept; + + Value& operator=(Value&& that) noexcept; ++ Value& SetTag(uint64_t) noexcept; + + Value(const Value&) = delete; + Value& operator=(const Value&) = delete; +@@ -177,6 +178,7 @@ class CBOR_EXPORT Value { + bool is_string() const { return type() == Type::STRING; } + bool is_array() const { return type() == Type::ARRAY; } + bool is_map() const { return type() == Type::MAP; } ++ bool has_tag() const { return tag_ != NO_TAG; } + + // These will all fatally assert if the type doesn't match. + SimpleValue GetSimpleValue() const; +@@ -192,12 +194,13 @@ class CBOR_EXPORT Value { + const ArrayValue& GetArray() const; + const MapValue& GetMap() const; + const BinaryValue& GetInvalidUTF8() const; ++ uint64_t GetTag() const; + + private: + friend class Reader; + // This constructor allows INVALID_UTF8 values to be created, which only + // |Reader| and InvalidUTF8StringValueForTesting() may do. +- Value(base::span in_bytes, Type type); ++ Value(base::span in_bytes, Type type, uint64_t tag = NO_TAG); + + Type type_; + +@@ -211,6 +214,11 @@ class CBOR_EXPORT Value { + MapValue map_value_; + }; + ++ //This value specified as Invalid, ++ // used here to represent absence of TAG ++ constexpr static uint64_t NO_TAG = 0xFFFF; ++ uint64_t tag_ = NO_TAG; ++ + void InternalMoveConstructFrom(Value&& that); + void InternalCleanup(); + }; diff --git a/chromium_edits/131.0.6753.0/components/cbor/writer.cc.patch b/chromium_edits/131.0.6753.0/components/cbor/writer.cc.patch new file mode 100644 index 00000000..150c3fca --- /dev/null +++ b/chromium_edits/131.0.6753.0/components/cbor/writer.cc.patch @@ -0,0 +1,14 @@ +diff --git a/components/cbor/writer.cc b/components/cbor/writer.cc +index e7e47774abe9a..4c085d5693a38 100644 +--- a/components/cbor/writer.cc ++++ b/components/cbor/writer.cc +@@ -47,6 +47,9 @@ bool Writer::EncodeCBOR(const Value& node, + if (max_nesting_level < 0) + return false; + ++ if (node.has_tag()) { ++ StartItem(Value::Type::TAG, node.GetTag()); ++ } + switch (node.type()) { + case Value::Type::NONE: { + StartItem(Value::Type::BYTE_STRING, 0); diff --git a/chromium_edits/131.0.6753.0/components/cbor/writer_unittest.cc.patch b/chromium_edits/131.0.6753.0/components/cbor/writer_unittest.cc.patch new file mode 100644 index 00000000..1acf5f7f --- /dev/null +++ b/chromium_edits/131.0.6753.0/components/cbor/writer_unittest.cc.patch @@ -0,0 +1,36 @@ +diff --git a/components/cbor/writer_unittest.cc b/components/cbor/writer_unittest.cc +index ee11e7cb86712..b8942f1829a37 100644 +--- a/components/cbor/writer_unittest.cc ++++ b/components/cbor/writer_unittest.cc +@@ -523,4 +523,31 @@ TEST(CBORWriterTest, OverlyNestedCBOR) { + EXPECT_FALSE(Writer::Write(Value(map), 4).has_value()); + } + ++TEST(CBORWriterTest, CanWriteTag) { ++ std::array content{ ++ 0x00, 0x01, 0x71, 0x12, 0x20, ++ 0x69, 0xea, 0x07, 0x40, 0xf9, ++ 0x80, 0x7a, 0x28, 0xf4, 0xd9, ++ 0x32, 0xc6, 0x2e, 0x7c, 0x1c, ++ 0x83, 0xbe, 0x05, 0x5e, 0x55, ++ 0x07, 0x2c, 0x90, 0x26, 0x6a, ++ 0xb3, 0xe7, 0x9d, 0xf6, 0x3a, ++ 0x36, 0x5b ++ }; ++ Value to_write(content); ++ to_write.SetTag(42); ++ auto result = Writer::Write(to_write); ++ EXPECT_TRUE(result.has_value()); ++ auto& bytes = result.value(); ++ EXPECT_EQ(bytes.size(), 41UL); ++ EXPECT_EQ(bytes.at(0), 0xd8); ++ EXPECT_EQ(bytes.at(1), 0x2a); ++ EXPECT_EQ(bytes.at(2), 0x58); ++ EXPECT_EQ(bytes.at(3), 0x25); ++ for (auto i = 0UL; i < content.size(); ++i) { ++ ASSERT_LT(i + 4UL, bytes.size()); ++ ASSERT_EQ(content.at(i), bytes.at(i+4UL)); ++ } ++} ++ + } // namespace cbor diff --git a/chromium_edits/131.0.6753.0/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch b/chromium_edits/131.0.6753.0/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch new file mode 100644 index 00000000..ee376ce1 --- /dev/null +++ b/chromium_edits/131.0.6753.0/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch @@ -0,0 +1,13 @@ +diff --git a/components/open_from_clipboard/clipboard_recent_content_generic.cc b/components/open_from_clipboard/clipboard_recent_content_generic.cc +index 3683fadcc0914..440d4be132e5c 100644 +--- a/components/open_from_clipboard/clipboard_recent_content_generic.cc ++++ b/components/open_from_clipboard/clipboard_recent_content_generic.cc +@@ -20,7 +20,7 @@ + namespace { + // Schemes appropriate for suggestion by ClipboardRecentContent. + const char* kAuthorizedSchemes[] = { +- url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme, ++ url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme, "ipfs", "ipns" + // TODO(mpearson): add support for chrome:// URLs. Right now the scheme + // for that lives in content and is accessible via + // GetEmbedderRepresentationOfAboutScheme() or content::kChromeUIScheme diff --git a/chromium_edits/131.0.6753.0/net/dns/dns_config_service_linux.cc.patch b/chromium_edits/131.0.6753.0/net/dns/dns_config_service_linux.cc.patch new file mode 100644 index 00000000..fd7227a5 --- /dev/null +++ b/chromium_edits/131.0.6753.0/net/dns/dns_config_service_linux.cc.patch @@ -0,0 +1,18 @@ +diff --git a/net/dns/dns_config_service_linux.cc b/net/dns/dns_config_service_linux.cc +index 7aaf9fa5b0b78..5a9f5b5a70dd9 100644 +--- a/net/dns/dns_config_service_linux.cc ++++ b/net/dns/dns_config_service_linux.cc +@@ -276,11 +276,11 @@ bool IsNsswitchConfigCompatible( + // Ignore any entries after `kDns` because Chrome will fallback to the + // system resolver if a result was not found in DNS. + return true; +- ++ case NsswitchReader::Service::kResolve: ++ break; + case NsswitchReader::Service::kMdns: + case NsswitchReader::Service::kMdns4: + case NsswitchReader::Service::kMdns6: +- case NsswitchReader::Service::kResolve: + case NsswitchReader::Service::kNis: + RecordIncompatibleNsswitchReason( + IncompatibleNsswitchReason::kIncompatibleService, diff --git a/chromium_edits/131.0.6753.0/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch b/chromium_edits/131.0.6753.0/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch new file mode 100644 index 00000000..663fe49e --- /dev/null +++ b/chromium_edits/131.0.6753.0/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch @@ -0,0 +1,15 @@ +diff --git a/third_party/blink/renderer/platform/weborigin/scheme_registry.cc b/third_party/blink/renderer/platform/weborigin/scheme_registry.cc +index e1bc209c337c5..6fbac29fcddfd 100644 +--- a/third_party/blink/renderer/platform/weborigin/scheme_registry.cc ++++ b/third_party/blink/renderer/platform/weborigin/scheme_registry.cc +@@ -68,8 +68,8 @@ class URLSchemesRegistry final { + // is considered secure. Additional checks are performed to ensure that + // other http pages are filtered out. + service_worker_schemes({"http", "https"}), +- fetch_api_schemes({"http", "https"}), +- allowed_in_referrer_schemes({"http", "https"}) { ++ fetch_api_schemes({"http", "https", "ipfs", "ipns"}), ++ allowed_in_referrer_schemes({"http", "https", "ipfs", "ipns"}) { + for (auto& scheme : url::GetCorsEnabledSchemes()) + cors_enabled_schemes.insert(scheme.c_str()); + for (auto& scheme : url::GetCSPBypassingSchemes()) { diff --git a/chromium_edits/131.0.6753.0/url/BUILD.gn.patch b/chromium_edits/131.0.6753.0/url/BUILD.gn.patch new file mode 100644 index 00000000..be4bfca8 --- /dev/null +++ b/chromium_edits/131.0.6753.0/url/BUILD.gn.patch @@ -0,0 +1,32 @@ +diff --git a/url/BUILD.gn b/url/BUILD.gn +index f22b73bc29f06..df36977322ec7 100644 +--- a/url/BUILD.gn ++++ b/url/BUILD.gn +@@ -5,6 +5,7 @@ + import("//build/buildflag_header.gni") + import("//testing/libfuzzer/fuzzer_test.gni") + import("//testing/test.gni") ++import("//third_party/ipfs_client/args.gni") + import("features.gni") + + import("//build/config/cronet/config.gni") +@@ -67,6 +68,7 @@ component("url") { + public_deps = [ + "//base", + "//build:robolectric_buildflags", ++ "//third_party/ipfs_client:ipfs_buildflags", + ] + + configs += [ "//build/config/compiler:wexit_time_destructors" ] +@@ -89,6 +91,11 @@ component("url") { + public_configs = [ "//third_party/jdk" ] + } + ++ if (enable_ipfs) { ++ sources += [ "url_canon_ipfs.cc" ] ++ deps += [ "//third_party/ipfs_client:ipfs_client" ] ++ } ++ + if (is_win) { + # Don't conflict with Windows' "url.dll". + output_name = "url_lib" diff --git a/chromium_edits/131.0.6753.0/url/url_canon.h.patch b/chromium_edits/131.0.6753.0/url/url_canon.h.patch new file mode 100644 index 00000000..ffe72eea --- /dev/null +++ b/chromium_edits/131.0.6753.0/url/url_canon.h.patch @@ -0,0 +1,26 @@ +diff --git a/url/url_canon.h b/url/url_canon.h +index 22def4917fdd0..40dda81954a56 100644 +--- a/url/url_canon.h ++++ b/url/url_canon.h +@@ -821,6 +821,21 @@ bool CanonicalizeMailtoURL(const char16_t* spec, + CanonOutput* output, + Parsed* new_parsed); + ++COMPONENT_EXPORT(URL) ++bool CanonicalizeIpfsURL(std::string_view spec, ++ const Parsed& parsed, ++ SchemeType scheme_type, ++ CharsetConverter* query_converter, ++ CanonOutput* output, ++ Parsed* new_parsed); ++COMPONENT_EXPORT(URL) ++bool CanonicalizeIpfsURL(std::basic_string_view spec, ++ const Parsed& parsed, ++ SchemeType scheme_type, ++ CharsetConverter* query_converter, ++ CanonOutput* output, ++ Parsed* new_parsed); ++ + // Part replacer -------------------------------------------------------------- + + // Internal structure used for storing separate strings for each component. diff --git a/chromium_edits/131.0.6753.0/url/url_canon_ipfs.cc b/chromium_edits/131.0.6753.0/url/url_canon_ipfs.cc new file mode 100644 index 00000000..e40732ee --- /dev/null +++ b/chromium_edits/131.0.6753.0/url/url_canon_ipfs.cc @@ -0,0 +1,54 @@ +#include "url_canon_internal.h" + +#include +#include + +#include + +bool url::CanonicalizeIpfsURL(std::string_view spec, + const Parsed& parsed, + SchemeType scheme_type, + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed) { + if (spec.size() < 1) { + return false; + } + if ( parsed.host.len < 1 ) { + return false; + } + auto cid_str = spec.substr( parsed.host.begin, static_cast(parsed.host.len) ); + auto cid = ipfs::Cid(cid_str); + if ( !cid.valid() ) { + cid = ipfs::id_cid::forText( std::string{cid_str} + " is not a valid CID." ); + } + auto as_str = cid.to_string(); + if ( as_str.empty() ) { + return false; + } + std::string stdurl{ spec.substr(0UL, static_cast(parsed.host.begin)) }; + stdurl.append( as_str ); + spec.remove_prefix(parsed.host.end()); + stdurl.append(spec); + auto len = static_cast(stdurl.size()); + Parsed parsed_input; + ParseStandardURL(stdurl.data(), len, &parsed_input); + return CanonicalizeStandardURL( + stdurl.data(), + parsed_input, + scheme_type, + charset_converter, + output, output_parsed + ); +} +bool url::CanonicalizeIpfsURL(std::basic_string_view spec, + const Parsed& parsed, + SchemeType scheme_type, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* new_parsed) { + RawCanonOutput<2048> as8; + ConvertUTF16ToUTF8(spec.data(), spec.size(), &as8); + return CanonicalizeIpfsURL({as8.data(), as8.length()}, parsed, scheme_type, + query_converter, output, new_parsed); +} diff --git a/chromium_edits/131.0.6753.0/url/url_util.cc.patch b/chromium_edits/131.0.6753.0/url/url_util.cc.patch new file mode 100644 index 00000000..988797b0 --- /dev/null +++ b/chromium_edits/131.0.6753.0/url/url_util.cc.patch @@ -0,0 +1,45 @@ +diff --git a/url/url_util.cc b/url/url_util.cc +index ce5225e121f5d..79e33208f728e 100644 +--- a/url/url_util.cc ++++ b/url/url_util.cc +@@ -76,6 +76,8 @@ struct SchemeRegistry { + std::vector referrer_schemes = { + {kHttpsScheme, SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION}, + {kHttpScheme, SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION}, ++ {"ipfs", SCHEME_WITH_HOST}, ++ {"ipns", SCHEME_WITH_HOST}, + }; + + // Schemes that do not trigger mixed content warning. +@@ -84,6 +86,8 @@ struct SchemeRegistry { + kWssScheme, + kDataScheme, + kAboutScheme, ++ {"ipfs", SCHEME_WITH_HOST}, ++ {"ipns", SCHEME_WITH_HOST}, + }; + + // Schemes that normal pages cannot link to or access (i.e., with the same +@@ -105,6 +109,8 @@ struct SchemeRegistry { + kHttpsScheme, + kHttpScheme, + kDataScheme, ++ {"ipfs", SCHEME_WITH_HOST}, ++ {"ipns", SCHEME_WITH_HOST}, + }; + + // Schemes that can be used by web to store data (local storage, etc). +@@ -308,7 +314,12 @@ bool DoCanonicalize(const CHAR* spec, + success = CanonicalizeFileSystemURL( + spec, ParseFileSystemURL(std::basic_string_view(spec, spec_len)), + charset_converter, output, output_parsed); +- ++ } else if (DoCompareSchemeComponent(spec, scheme, "ipfs")) { ++ auto spec_view = std::basic_string_view(spec, spec_len); ++ // Switch multibase away from case-sensitive ones before continuing canonicalization. ++ auto parsed_input = ParseStandardURL(spec_view); ++ success = CanonicalizeIpfsURL(spec_view, parsed_input, scheme_type, ++ charset_converter, output, output_parsed); + } else if (DoIsStandard(spec, scheme, &scheme_type)) { + // All "normal" URLs. + success = CanonicalizeStandardURL( diff --git a/chromium_edits/131.0.6776.0/chrome/browser/BUILD.gn.patch b/chromium_edits/131.0.6776.0/chrome/browser/BUILD.gn.patch new file mode 100644 index 00000000..4f43e799 --- /dev/null +++ b/chromium_edits/131.0.6776.0/chrome/browser/BUILD.gn.patch @@ -0,0 +1,27 @@ +diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn +index 46219ca4fbc09..f8b65570a2b3e 100644 +--- a/chrome/browser/BUILD.gn ++++ b/chrome/browser/BUILD.gn +@@ -40,6 +40,7 @@ import("//sandbox/features.gni") + import("//services/screen_ai/buildflags/features.gni") + import("//testing/libfuzzer/fuzzer_test.gni") + import("//third_party/blink/public/public_features.gni") ++import("//third_party/ipfs_client/args.gni") + import("//third_party/protobuf/proto_library.gni") + import("//third_party/webrtc/webrtc.gni") + import("//third_party/widevine/cdm/widevine.gni") +@@ -2497,6 +2498,14 @@ static_library("browser") { + "//ui/webui", + ] + ++ if (enable_ipfs) { ++ sources += [ ++ "ipfs_extra_parts.cc", ++ "ipfs_extra_parts.h", ++ ] ++ deps += [ "//components/ipfs" ] ++ } ++ + # Platforms that have a network diagnostics dialog. All others fall through + # to the stub which is not implemented. + if (is_chromeos_ash) { diff --git a/chromium_edits/131.0.6776.0/chrome/browser/about_flags.cc.patch b/chromium_edits/131.0.6776.0/chrome/browser/about_flags.cc.patch new file mode 100644 index 00000000..9dfe7a96 --- /dev/null +++ b/chromium_edits/131.0.6776.0/chrome/browser/about_flags.cc.patch @@ -0,0 +1,38 @@ +diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc +index a755fa936b8fc..5629acfc4c723 100644 +--- a/chrome/browser/about_flags.cc ++++ b/chrome/browser/about_flags.cc +@@ -228,6 +228,7 @@ + #include "third_party/blink/public/common/features_generated.h" + #include "third_party/blink/public/common/forcedark/forcedark_switches.h" + #include "third_party/blink/public/common/switches.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + #include "ui/accessibility/accessibility_features.h" + #include "ui/accessibility/accessibility_switches.h" + #include "ui/base/ozone_buildflags.h" +@@ -329,6 +330,10 @@ + #include "extensions/common/switches.h" + #endif // BUILDFLAG(ENABLE_EXTENSIONS) + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "components/ipfs/ipfs_features.h" ++#endif ++ + #if BUILDFLAG(ENABLE_PDF) + #include "pdf/pdf_features.h" + #endif +@@ -9783,6 +9788,14 @@ const FeatureEntry kFeatureEntries[] = { + flag_descriptions::kOmitCorsClientCertDescription, kOsAll, + FEATURE_VALUE_TYPE(network::features::kOmitCorsClientCert)}, + ++#if BUILDFLAG(ENABLE_IPFS) ++ {"enable-ipfs", ++ flag_descriptions::kEnableIpfsName, ++ flag_descriptions::kEnableIpfsDescription, ++ kOsMac | kOsWin | kOsLinux,//TODO: These are the only variants currently getting built, but that is not likely to remain the case ++ FEATURE_VALUE_TYPE(ipfs::kEnableIpfs)}, ++#endif ++ + {"use-idna2008-non-transitional", + flag_descriptions::kUseIDNA2008NonTransitionalName, + flag_descriptions::kUseIDNA2008NonTransitionalDescription, kOsAll, diff --git a/chromium_edits/131.0.6776.0/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch b/chromium_edits/131.0.6776.0/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch new file mode 100644 index 00000000..f9965a24 --- /dev/null +++ b/chromium_edits/131.0.6776.0/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch @@ -0,0 +1,51 @@ +diff --git a/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc b/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc +index 9f234a2a7d41d..a9378ca80dc1e 100644 +--- a/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc ++++ b/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc +@@ -13,6 +13,7 @@ + #include "chrome/browser/profiles/profile_io_data.h" + #include "components/custom_handlers/protocol_handler_registry.h" + #include "content/public/common/url_constants.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + #include "url/url_util.h" + + #if BUILDFLAG(IS_ANDROID) +@@ -20,6 +21,11 @@ + #include "chrome/browser/ui/android/omnibox/jni_headers/ChromeAutocompleteSchemeClassifier_jni.h" + #endif + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "components/ipfs/ipfs_features.h" ++#endif ++ ++ + #if BUILDFLAG(IS_ANDROID) + static jlong + JNI_ChromeAutocompleteSchemeClassifier_CreateAutocompleteClassifier( +@@ -53,12 +59,20 @@ ChromeAutocompleteSchemeClassifier::GetInputTypeForScheme( + if (scheme.empty()) { + return metrics::OmniboxInputType::EMPTY; + } +- if (base::IsStringASCII(scheme) && +- (ProfileIOData::IsHandledProtocol(scheme) || +- base::EqualsCaseInsensitiveASCII(scheme, content::kViewSourceScheme) || +- base::EqualsCaseInsensitiveASCII(scheme, url::kJavaScriptScheme) || +- base::EqualsCaseInsensitiveASCII(scheme, url::kDataScheme))) { +- return metrics::OmniboxInputType::URL; ++ if (base::IsStringASCII(scheme)) { ++ if (ProfileIOData::IsHandledProtocol(scheme) || ++ base::EqualsCaseInsensitiveASCII(scheme, content::kViewSourceScheme) || ++ base::EqualsCaseInsensitiveASCII(scheme, url::kJavaScriptScheme) || ++ base::EqualsCaseInsensitiveASCII(scheme, url::kDataScheme)) { ++ return metrics::OmniboxInputType::URL; ++ } ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs) && ++ (base::EqualsCaseInsensitiveASCII(scheme, "ipfs") || base::EqualsCaseInsensitiveASCII(scheme, "ipns")) ++ ) { ++ return metrics::OmniboxInputType::URL; ++ } ++#endif + } + + // Also check for schemes registered via registerProtocolHandler(), which diff --git a/chromium_edits/131.0.6776.0/chrome/browser/chrome_content_browser_client.cc.patch b/chromium_edits/131.0.6776.0/chrome/browser/chrome_content_browser_client.cc.patch new file mode 100644 index 00000000..3128f8d2 --- /dev/null +++ b/chromium_edits/131.0.6776.0/chrome/browser/chrome_content_browser_client.cc.patch @@ -0,0 +1,81 @@ +diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc +index 66b561195b79f..a8c23e3e7c308 100644 +--- a/chrome/browser/chrome_content_browser_client.cc ++++ b/chrome/browser/chrome_content_browser_client.cc +@@ -408,6 +408,7 @@ + #include "third_party/blink/public/mojom/browsing_topics/browsing_topics.mojom.h" + #include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom.h" + #include "third_party/blink/public/public_buildflags.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + #include "third_party/widevine/cdm/buildflags.h" + #include "ui/base/clipboard/clipboard_format_type.h" + #include "ui/base/l10n/l10n_util.h" +@@ -535,6 +536,13 @@ + #include "chrome/browser/chrome_browser_main_posix.h" + #endif + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "chrome/browser/ipfs_extra_parts.h" ++#include "components/ipfs/interceptor.h" ++#include "components/ipfs/ipfs_features.h" ++#include "components/ipfs/url_loader_factory.h" ++#endif ++ + #if !BUILDFLAG(IS_ANDROID) + #include "chrome/browser/digital_credentials/digital_identity_provider_desktop.h" + #include "chrome/browser/preloading/preview/preview_navigation_throttle.h" +@@ -1864,6 +1872,11 @@ ChromeContentBrowserClient::CreateBrowserMainParts(bool is_integration_test) { + main_parts->AddParts( + std::make_unique()); + ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ main_parts->AddParts(std::make_unique()); ++ } ++#endif + return main_parts; + } + +@@ -6554,12 +6567,29 @@ void ChromeContentBrowserClient:: + const std::optional& request_initiator_origin, + NonNetworkURLLoaderFactoryMap* factories) { + #if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS) || \ +- !BUILDFLAG(IS_ANDROID) ++ !BUILDFLAG(IS_ANDROID) || BUILDFLAG(ENABLE_IPFS) + content::RenderFrameHost* frame_host = + RenderFrameHost::FromID(render_process_id, render_frame_id); + WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host); + #endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS) || \ + // !BUILDFLAG(IS_ANDROID) ++#if BUILDFLAG(ENABLE_IPFS) ++ if (!web_contents) { ++ VLOG(2) << "No web contents, can't register url loader factory."; ++ } else if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ network::mojom::URLLoaderFactory* default_factory = g_browser_process->system_network_context_manager()->GetURLLoaderFactory(); ++ auto* context = web_contents->GetBrowserContext(); ++ ipfs::IpfsURLLoaderFactory::Create( ++ factories, ++ context, ++ default_factory, ++ GetSystemNetworkContext(), ++ Profile::FromBrowserContext(context)->GetPrefs() ++ ); ++ } else { ++ LOG(INFO) << "IPFS disabled."; ++ } ++#endif // BUILDFLAG(ENABLE_IPFS) + + #if BUILDFLAG(IS_CHROMEOS_ASH) + if (web_contents) { +@@ -6707,6 +6737,11 @@ ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors( + scoped_refptr navigation_response_task_runner) { + std::vector> + interceptors; ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ interceptors.push_back(std::make_unique(g_browser_process->system_network_context_manager()->GetURLLoaderFactory(), GetSystemNetworkContext())); ++ } ++#endif + #if BUILDFLAG(ENABLE_OFFLINE_PAGES) + interceptors.push_back( + std::make_unique( diff --git a/chromium_edits/131.0.6776.0/chrome/browser/flag-metadata.json.patch b/chromium_edits/131.0.6776.0/chrome/browser/flag-metadata.json.patch new file mode 100644 index 00000000..1551e225 --- /dev/null +++ b/chromium_edits/131.0.6776.0/chrome/browser/flag-metadata.json.patch @@ -0,0 +1,16 @@ +diff --git a/chrome/browser/flag-metadata.json b/chrome/browser/flag-metadata.json +index 02f8c959d96dd..74f33b7beef75 100644 +--- a/chrome/browser/flag-metadata.json ++++ b/chrome/browser/flag-metadata.json +@@ -3427,6 +3427,11 @@ + "owners": [ "adamta@google.com", "bling-get-set-up@google.com" ], + "expiry_milestone": 140 + }, ++ { ++ "name": "enable-ipfs", ++ "owners": [ "//components/ipfs/OWNERS" ], ++ "expiry_milestone": 150 ++ }, + { + "name": "enable-isolated-sandboxed-iframes", + "owners": [ "wjmaclean@chromium.org", "alexmos@chromium.org", "creis@chromium.org" ], diff --git a/chromium_edits/131.0.6776.0/chrome/browser/flag_descriptions.cc.patch b/chromium_edits/131.0.6776.0/chrome/browser/flag_descriptions.cc.patch new file mode 100644 index 00000000..9810bae3 --- /dev/null +++ b/chromium_edits/131.0.6776.0/chrome/browser/flag_descriptions.cc.patch @@ -0,0 +1,16 @@ +diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc +index 1084018867824..033c8620f824b 100644 +--- a/chrome/browser/flag_descriptions.cc ++++ b/chrome/browser/flag_descriptions.cc +@@ -352,6 +352,11 @@ const char kEnableBookmarksSelectedTypeOnSigninForTestingDescription[] = + "sync-enable-bookmarks-in-transport-mode. Enables the bookmarks " + "UserSelectableType upon sign-in"; + ++#if BUILDFLAG(ENABLE_IPFS) ++extern const char kEnableIpfsName[] = "Enable IPFS"; ++extern const char kEnableIpfsDescription[] = "Enable ipfs:// and ipns:// URLs"; ++#endif ++ + const char kPreloadingOnPerformancePageName[] = + "Preloading Settings on Performance Page"; + const char kPreloadingOnPerformancePageDescription[] = diff --git a/chromium_edits/131.0.6776.0/chrome/browser/flag_descriptions.h.patch b/chromium_edits/131.0.6776.0/chrome/browser/flag_descriptions.h.patch new file mode 100644 index 00000000..dbaf4ab6 --- /dev/null +++ b/chromium_edits/131.0.6776.0/chrome/browser/flag_descriptions.h.patch @@ -0,0 +1,24 @@ +diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h +index d35590543a605..6d858fdc345a7 100644 +--- a/chrome/browser/flag_descriptions.h ++++ b/chrome/browser/flag_descriptions.h +@@ -25,6 +25,7 @@ + #include "printing/buildflags/buildflags.h" + #include "skia/buildflags.h" + #include "third_party/blink/public/common/buildflags.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + + // This file declares strings used in chrome://flags. These messages are not + // translated, because instead of end-users they target Chromium developers and +@@ -219,6 +220,11 @@ extern const char kEnableBenchmarkingChoiceMatchFieldTrialTestingConfig[]; + extern const char kEnableBookmarksSelectedTypeOnSigninForTestingName[]; + extern const char kEnableBookmarksSelectedTypeOnSigninForTestingDescription[]; + ++#if BUILDFLAG(ENABLE_IPFS) ++extern const char kEnableIpfsName[]; ++extern const char kEnableIpfsDescription[]; ++#endif ++ + extern const char kFontationsFontBackendName[]; + extern const char kFontationsFontBackendDescription[]; + diff --git a/chromium_edits/131.0.6776.0/chrome/browser/ipfs_extra_parts.cc b/chromium_edits/131.0.6776.0/chrome/browser/ipfs_extra_parts.cc new file mode 100644 index 00000000..90d2596f --- /dev/null +++ b/chromium_edits/131.0.6776.0/chrome/browser/ipfs_extra_parts.cc @@ -0,0 +1,10 @@ +#include "ipfs_extra_parts.h" + +#include "profiles/profile.h" + +#include + +void IpfsExtraParts::PostProfileInit(Profile* profile, bool /* is_initial_profile */ ) { + DCHECK(profile); + ipfs::InterRequestState::CreateForBrowserContext(profile, profile->GetPrefs()); +} diff --git a/chromium_edits/131.0.6776.0/chrome/browser/ipfs_extra_parts.h b/chromium_edits/131.0.6776.0/chrome/browser/ipfs_extra_parts.h new file mode 100644 index 00000000..2059c437 --- /dev/null +++ b/chromium_edits/131.0.6776.0/chrome/browser/ipfs_extra_parts.h @@ -0,0 +1,10 @@ +#ifndef IPFS_EXTRA_PART_H_ +#define IPFS_EXTRA_PART_H_ + +#include + +class IpfsExtraParts : public ChromeBrowserMainExtraParts { + void PostProfileInit(Profile* profile, bool is_initial_profile) override; +}; + +#endif // IPFS_EXTRA_PART_H_ diff --git a/chromium_edits/131.0.6776.0/chrome/browser/prefs/browser_prefs.cc.patch b/chromium_edits/131.0.6776.0/chrome/browser/prefs/browser_prefs.cc.patch new file mode 100644 index 00000000..0e229a98 --- /dev/null +++ b/chromium_edits/131.0.6776.0/chrome/browser/prefs/browser_prefs.cc.patch @@ -0,0 +1,36 @@ +diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc +index feedbe2257601..e3f6ea1a0d6b0 100644 +--- a/chrome/browser/prefs/browser_prefs.cc ++++ b/chrome/browser/prefs/browser_prefs.cc +@@ -201,6 +201,7 @@ + #include "ppapi/buildflags/buildflags.h" + #include "printing/buildflags/buildflags.h" + #include "rlz/buildflags/buildflags.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + + #if BUILDFLAG(ENABLE_BACKGROUND_MODE) + #include "chrome/browser/background/background_mode_manager.h" +@@ -249,6 +250,11 @@ + #include "chrome/browser/pdf/pdf_pref_names.h" + #endif // BUILDFLAG(ENABLE_PDF) + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "components/ipfs/ipfs_features.h" ++#include "components/ipfs/preferences.h" ++#endif ++ + #if BUILDFLAG(IS_ANDROID) + #include "chrome/browser/accessibility/accessibility_prefs/android/accessibility_prefs_controller.h" + #include "chrome/browser/android/bookmarks/partner_bookmarks_shim.h" +@@ -1960,6 +1966,11 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry, + IncognitoModePrefs::RegisterProfilePrefs(registry); + invalidation::PerUserTopicSubscriptionManager::RegisterProfilePrefs(registry); + invalidation::InvalidatorRegistrarWithMemory::RegisterProfilePrefs(registry); ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ ipfs::RegisterPreferences(registry); ++ } ++#endif + language::LanguagePrefs::RegisterProfilePrefs(registry); + login_detection::prefs::RegisterProfilePrefs(registry); + lookalikes::RegisterProfilePrefs(registry); diff --git a/chromium_edits/131.0.6776.0/chrome/browser/shell_integration_mac.mm.patch b/chromium_edits/131.0.6776.0/chrome/browser/shell_integration_mac.mm.patch new file mode 100644 index 00000000..220e2546 --- /dev/null +++ b/chromium_edits/131.0.6776.0/chrome/browser/shell_integration_mac.mm.patch @@ -0,0 +1,13 @@ +diff --git a/chrome/browser/shell_integration_mac.mm b/chrome/browser/shell_integration_mac.mm +index c6bb768979453..c0d0abb9c78f3 100644 +--- a/chrome/browser/shell_integration_mac.mm ++++ b/chrome/browser/shell_integration_mac.mm +@@ -79,6 +79,8 @@ bool SetAsDefaultBrowser() { + if (LSSetDefaultHandlerForURLScheme(CFSTR("https"), identifier) != noErr) { + return false; + } ++ LSSetDefaultHandlerForURLScheme(CFSTR("ipfs"), identifier); ++ LSSetDefaultHandlerForURLScheme(CFSTR("ipns"), identifier); + if (LSSetDefaultRoleHandlerForContentType(kUTTypeHTML, kLSRolesViewer, + identifier) != noErr) { + return false; diff --git a/chromium_edits/131.0.6776.0/chrome/common/chrome_content_client.cc.patch b/chromium_edits/131.0.6776.0/chrome/common/chrome_content_client.cc.patch new file mode 100644 index 00000000..d34894b4 --- /dev/null +++ b/chromium_edits/131.0.6776.0/chrome/common/chrome_content_client.cc.patch @@ -0,0 +1,17 @@ +diff --git a/chrome/common/chrome_content_client.cc b/chrome/common/chrome_content_client.cc +index 60515232467d7..14d5e12a76c76 100644 +--- a/chrome/common/chrome_content_client.cc ++++ b/chrome/common/chrome_content_client.cc +@@ -314,6 +314,12 @@ void ChromeContentClient::AddAdditionalSchemes(Schemes* schemes) { + #if BUILDFLAG(IS_ANDROID) + schemes->local_schemes.push_back(url::kContentScheme); + #endif ++ for ( const char* ip_s : {"ipfs", "ipns"} ) { ++ schemes->standard_schemes.push_back(ip_s); ++ schemes->cors_enabled_schemes.push_back(ip_s); ++ schemes->secure_schemes.push_back(ip_s); ++ schemes->csp_bypassing_schemes.push_back(ip_s); ++ } + } + + std::u16string ChromeContentClient::GetLocalizedString(int message_id) { diff --git a/chromium_edits/131.0.6776.0/chrome/installer/linux/common/desktop.template.patch b/chromium_edits/131.0.6776.0/chrome/installer/linux/common/desktop.template.patch new file mode 100644 index 00000000..dcd9460b --- /dev/null +++ b/chromium_edits/131.0.6776.0/chrome/installer/linux/common/desktop.template.patch @@ -0,0 +1,13 @@ +diff --git a/chrome/installer/linux/common/desktop.template b/chrome/installer/linux/common/desktop.template +index 2eb13ee1aba46..9af65726bde89 100644 +--- a/chrome/installer/linux/common/desktop.template ++++ b/chrome/installer/linux/common/desktop.template +@@ -111,7 +111,7 @@ Terminal=false + Icon=@@PACKAGE@@ + Type=Application + Categories=Network;WebBrowser; +-MimeType=application/pdf;application/rdf+xml;application/rss+xml;application/xhtml+xml;application/xhtml_xml;application/xml;image/gif;image/jpeg;image/png;image/webp;text/html;text/xml;x-scheme-handler/http;x-scheme-handler/https; ++MimeType=application/pdf;application/rdf+xml;application/rss+xml;application/xhtml+xml;application/xhtml_xml;application/xml;image/gif;image/jpeg;image/png;image/webp;text/html;text/xml;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/ipfs;x-scheme-handler/ipns; + Actions=new-window;new-private-window; + + [Desktop Action new-window] diff --git a/chromium_edits/131.0.6776.0/chrome/installer/util/shell_util.cc.patch b/chromium_edits/131.0.6776.0/chrome/installer/util/shell_util.cc.patch new file mode 100644 index 00000000..fccdad80 --- /dev/null +++ b/chromium_edits/131.0.6776.0/chrome/installer/util/shell_util.cc.patch @@ -0,0 +1,20 @@ +diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc +index c087d1c02bca4..382a36b9cd800 100644 +--- a/chrome/installer/util/shell_util.cc ++++ b/chrome/installer/util/shell_util.cc +@@ -1545,11 +1545,12 @@ const wchar_t* ShellUtil::kDefaultFileAssociations[] = { + const wchar_t* ShellUtil::kPotentialFileAssociations[] = { + L".htm", L".html", L".mhtml", L".pdf", L".shtml", + L".svg", L".xht", L".xhtml", L".webp", nullptr}; +-const wchar_t* ShellUtil::kBrowserProtocolAssociations[] = {L"http", L"https", +- nullptr}; ++const wchar_t* ShellUtil::kBrowserProtocolAssociations[] = { ++ L"http", L"https", L"ipfs", L"ipns", nullptr}; + const wchar_t* ShellUtil::kPotentialProtocolAssociations[] = { + L"http", L"https", L"irc", L"mailto", L"mms", L"news", L"nntp", +- L"sms", L"smsto", L"snews", L"tel", L"urn", L"webcal", nullptr}; ++ L"sms", L"smsto", L"snews", L"tel", L"urn", L"webcal", L"ipfs", ++ L"ipns", nullptr}; + const wchar_t* ShellUtil::kRegUrlProtocol = L"URL Protocol"; + const wchar_t* ShellUtil::kRegApplication = L"\\Application"; + const wchar_t* ShellUtil::kRegAppUserModelId = L"AppUserModelId"; diff --git a/chromium_edits/131.0.6776.0/components/cbor/reader.cc.patch b/chromium_edits/131.0.6776.0/components/cbor/reader.cc.patch new file mode 100644 index 00000000..de3d0b36 --- /dev/null +++ b/chromium_edits/131.0.6776.0/components/cbor/reader.cc.patch @@ -0,0 +1,44 @@ +diff --git a/components/cbor/reader.cc b/components/cbor/reader.cc +index 24d852e45f2ba..4dfec34caabd7 100644 +--- a/components/cbor/reader.cc ++++ b/components/cbor/reader.cc +@@ -22,7 +22,7 @@ + namespace cbor { + + namespace constants { +-const char kUnsupportedMajorType[] = "Unsupported major type."; ++const char kUnsupportedMajorType[] = "Unsupported major type operation."; + } + + namespace { +@@ -156,7 +156,11 @@ std::optional Reader::DecodeCompleteDataItem(const Config& config, + case Value::Type::FLOAT_VALUE: + // Floating point values also go here since they are also type 7. + return DecodeToSimpleValueOrFloat(*header, config); +- case Value::Type::TAG: // We explicitly don't support TAG. ++ case Value::Type::TAG: ++ if (config.parse_tags) { ++ return ReadTagContent(*header, config, max_nesting_level); ++ } ++ break; + case Value::Type::NONE: + case Value::Type::INVALID_UTF8: + break; +@@ -347,6 +351,17 @@ std::optional Reader::ReadByteStringContent( + return Value(std::move(cbor_byte_string)); + } + ++std::optional Reader::ReadTagContent( ++ const Reader::DataItemHeader& header, ++ const Config& config, ++ int max_nesting_level) { ++ auto tagged_content = DecodeCompleteDataItem(config, max_nesting_level); ++ if (tagged_content.has_value()) { ++ tagged_content.value().SetTag(header.value); ++ } ++ return tagged_content; ++} ++ + std::optional Reader::ReadArrayContent( + const Reader::DataItemHeader& header, + const Config& config, diff --git a/chromium_edits/131.0.6776.0/components/cbor/reader.h.patch b/chromium_edits/131.0.6776.0/components/cbor/reader.h.patch new file mode 100644 index 00000000..2dbc0534 --- /dev/null +++ b/chromium_edits/131.0.6776.0/components/cbor/reader.h.patch @@ -0,0 +1,26 @@ +diff --git a/components/cbor/reader.h b/components/cbor/reader.h +index 5f11ba48ba494..d4c9c489da4b6 100644 +--- a/components/cbor/reader.h ++++ b/components/cbor/reader.h +@@ -131,6 +131,11 @@ class CBOR_EXPORT Reader { + // during decoding will set raise the `UNSUPPORTED_FLOATING_POINT_VALUE` + // error. + bool allow_floating_point = false; ++ ++ // If the parser encounters a TAG element, should it be parsed out and ++ // the tag value saved (true), or should the entire node and its content ++ // be discarded (false) ++ bool parse_tags = false; + }; + + Reader(const Reader&) = delete; +@@ -205,6 +210,9 @@ class CBOR_EXPORT Reader { + std::optional ReadMapContent(const DataItemHeader& header, + const Config& config, + int max_nesting_level); ++ std::optional ReadTagContent(const DataItemHeader& header, ++ const Config& config, ++ int max_nesting_level); + std::optional ReadByte(); + std::optional> ReadBytes(uint64_t num_bytes); + bool IsKeyInOrder(const Value& new_key, diff --git a/chromium_edits/131.0.6776.0/components/cbor/reader_unittest.cc.patch b/chromium_edits/131.0.6776.0/components/cbor/reader_unittest.cc.patch new file mode 100644 index 00000000..150e0c73 --- /dev/null +++ b/chromium_edits/131.0.6776.0/components/cbor/reader_unittest.cc.patch @@ -0,0 +1,47 @@ +diff --git a/components/cbor/reader_unittest.cc b/components/cbor/reader_unittest.cc +index e5c02ceea3402..f26b8e77f6da3 100644 +--- a/components/cbor/reader_unittest.cc ++++ b/components/cbor/reader_unittest.cc +@@ -1449,5 +1449,42 @@ TEST(CBORReaderTest, AllowInvalidUTF8) { + EXPECT_FALSE(cbor); + EXPECT_EQ(Reader::DecoderError::INVALID_UTF8, error); + } ++TEST(CBORReaderTest, RejectsTagUnderDefaultConfig) { ++ static const uint8_t kTaggedCbor[] = { ++ 0xd8, 0x2a, 0x58, 0x25, 0x00, 0x01, 0x71, 0x12, 0x20, 0x69, 0xea, 0x07, ++ 0x40, 0xf9, 0x80, 0x7a, 0x28, 0xf4, 0xd9, 0x32, 0xc6, 0x2e, 0x7c, 0x1c, ++ 0x83, 0xbe, 0x05, 0x5e, 0x55, 0x07, 0x2c, 0x90, 0x26, 0x6a, 0xb3, 0xe7, ++ 0x9d, 0xf6, 0x3a, 0x36, 0x5b ++ }; ++ Reader::Config config; ++ auto cbor = Reader::Read(kTaggedCbor, config); ++ EXPECT_FALSE(cbor.has_value()); ++} ++TEST(CBORReaderTest, ReadsTagWhenConfiguredToDoSo) { ++ static const uint8_t kTaggedCbor[] = { ++ 0xd8, 0x2a, 0x58, 0x25, 0x00, 0x01, 0x71, 0x12, 0x20, 0x69, 0xea, 0x07, ++ 0x40, 0xf9, 0x80, 0x7a, 0x28, 0xf4, 0xd9, 0x32, 0xc6, 0x2e, 0x7c, 0x1c, ++ 0x83, 0xbe, 0x05, 0x5e, 0x55, 0x07, 0x2c, 0x90, 0x26, 0x6a, 0xb3, 0xe7, ++ 0x9d, 0xf6, 0x3a, 0x36, 0x5b ++ }; ++ Reader::Config config; ++ config.parse_tags = true; ++ auto cbor = Reader::Read(kTaggedCbor, config); ++ EXPECT_TRUE(cbor.has_value()); ++ auto& v = cbor.value(); ++ EXPECT_TRUE(v.has_tag()); ++ EXPECT_EQ(v.GetTag(),42UL); ++ EXPECT_TRUE(v.is_bytestring()); ++ EXPECT_EQ(v.type(), Value::Type::BYTE_STRING); ++ auto& bytes = v.GetBytestring(); ++ EXPECT_EQ(bytes.size(), 37UL); ++ EXPECT_EQ(bytes.at(0), 0x00);//identity multibase (e.g. not base-encoded, bytes are themselves) ++ EXPECT_EQ(bytes.at(1), 0x01);//CID version 1 ++ EXPECT_EQ(bytes.at(2), 0x71);//codec = dag-cbor ++ EXPECT_EQ(bytes.at(3), 0x12);//multihash = 18 = sha2-256 ++ EXPECT_EQ(bytes.at(4), 0x20);//hash length = 32 bytes ++ EXPECT_EQ(bytes.at(5), 0x69);//first byte of hash digest ++ EXPECT_EQ(bytes.at(36),0x5b);//last byte of hash digest ++} + + } // namespace cbor diff --git a/chromium_edits/131.0.6776.0/components/cbor/values.cc.patch b/chromium_edits/131.0.6776.0/components/cbor/values.cc.patch new file mode 100644 index 00000000..fba23766 --- /dev/null +++ b/chromium_edits/131.0.6776.0/components/cbor/values.cc.patch @@ -0,0 +1,145 @@ +diff --git a/components/cbor/values.cc b/components/cbor/values.cc +index 303ac7fe300e3..7f796304e465a 100644 +--- a/components/cbor/values.cc ++++ b/components/cbor/values.cc +@@ -71,32 +71,34 @@ Value::Value(Type type) : type_(type) { + NOTREACHED_IN_MIGRATION(); + } + +-Value::Value(SimpleValue in_simple) +- : type_(Type::SIMPLE_VALUE), simple_value_(in_simple) { ++Value::Value(SimpleValue in_simple, uint64_t tag) ++ : type_(Type::SIMPLE_VALUE), simple_value_(in_simple), tag_(tag) { + CHECK(static_cast(in_simple) >= 20 && static_cast(in_simple) <= 23); + } + +-Value::Value(bool boolean_value) : type_(Type::SIMPLE_VALUE) { ++Value::Value(bool boolean_value, uint64_t tag) : type_(Type::SIMPLE_VALUE), tag_(tag) { + simple_value_ = boolean_value ? Value::SimpleValue::TRUE_VALUE + : Value::SimpleValue::FALSE_VALUE; + } + +-Value::Value(double float_value) +- : type_(Type::FLOAT_VALUE), float_value_(float_value) {} ++Value::Value(double float_value, uint64_t tag) ++ : type_(Type::FLOAT_VALUE), float_value_(float_value), tag_(tag) {} + +-Value::Value(int integer_value) +- : Value(base::checked_cast(integer_value)) {} ++Value::Value(int integer_value, uint64_t tag) ++ : Value(base::checked_cast(integer_value), tag) {} + +-Value::Value(int64_t integer_value) : integer_value_(integer_value) { ++Value::Value(int64_t integer_value, uint64_t tag) : integer_value_(integer_value), tag_(tag) { + type_ = integer_value >= 0 ? Type::UNSIGNED : Type::NEGATIVE; + } + +-Value::Value(base::span in_bytes) ++Value::Value(base::span in_bytes, uint64_t tag) + : type_(Type::BYTE_STRING), +- bytestring_value_(in_bytes.begin(), in_bytes.end()) {} ++ bytestring_value_(in_bytes.begin(), in_bytes.end()), ++ tag_(tag) ++ {} + +-Value::Value(base::span in_bytes, Type type) +- : type_(type), bytestring_value_(in_bytes.begin(), in_bytes.end()) { ++Value::Value(base::span in_bytes, Type type, uint64_t tag) ++ : type_(type), bytestring_value_(in_bytes.begin(), in_bytes.end()), tag_(tag) { + DCHECK(type_ == Type::BYTE_STRING || type_ == Type::INVALID_UTF8); + } + +@@ -122,7 +124,8 @@ Value::Value(std::string&& in_string, Type type) noexcept : type_(type) { + } + } + +-Value::Value(std::string_view in_string, Type type) : type_(type) { ++Value::Value(std::string_view in_string, Type type, uint64_t tag) ++: type_(type), tag_(tag) { + switch (type_) { + case Type::STRING: + new (&string_value_) std::string(); +@@ -138,16 +141,18 @@ Value::Value(std::string_view in_string, Type type) : type_(type) { + } + } + +-Value::Value(const ArrayValue& in_array) : type_(Type::ARRAY), array_value_() { ++Value::Value(const ArrayValue& in_array, uint64_t tag) ++: type_(Type::ARRAY), array_value_(), tag_(tag) { + array_value_.reserve(in_array.size()); + for (const auto& val : in_array) + array_value_.emplace_back(val.Clone()); + } + +-Value::Value(ArrayValue&& in_array) noexcept +- : type_(Type::ARRAY), array_value_(std::move(in_array)) {} ++Value::Value(ArrayValue&& in_array, uint64_t tag) noexcept ++ : type_(Type::ARRAY), array_value_(std::move(in_array)), tag_(tag) {} + +-Value::Value(const MapValue& in_map) : type_(Type::MAP), map_value_() { ++Value::Value(const MapValue& in_map, uint64_t tag) ++: type_(Type::MAP), map_value_(), tag_(tag) { + map_value_.reserve(in_map.size()); + for (const auto& it : in_map) + map_value_.emplace_hint(map_value_.end(), it.first.Clone(), +@@ -173,31 +178,36 @@ Value Value::Clone() const { + case Type::NONE: + return Value(); + case Type::INVALID_UTF8: +- return Value(bytestring_value_, Type::INVALID_UTF8); ++ return Value(bytestring_value_, Type::INVALID_UTF8, tag_); + case Type::UNSIGNED: + case Type::NEGATIVE: +- return Value(integer_value_); ++ return Value(integer_value_, tag_); + case Type::BYTE_STRING: +- return Value(bytestring_value_); ++ return Value(bytestring_value_, tag_); + case Type::STRING: +- return Value(string_value_); ++ return Value(string_value_, Type::STRING, tag_); + case Type::ARRAY: +- return Value(array_value_); ++ return Value(array_value_, tag_); + case Type::MAP: +- return Value(map_value_); ++ return Value(map_value_, tag_); + case Type::TAG: + NOTREACHED_IN_MIGRATION() << constants::kUnsupportedMajorType; + return Value(); + case Type::SIMPLE_VALUE: +- return Value(simple_value_); ++ return Value(simple_value_, tag_); + case Type::FLOAT_VALUE: +- return Value(float_value_); ++ return Value(float_value_, tag_); + } + + NOTREACHED_IN_MIGRATION(); + return Value(); + } + ++Value& Value::SetTag(uint64_t tag) noexcept { ++ tag_ = tag; ++ return *this; ++} ++ + Value::SimpleValue Value::GetSimpleValue() const { + CHECK(is_simple()); + return simple_value_; +@@ -263,9 +273,14 @@ const Value::BinaryValue& Value::GetInvalidUTF8() const { + return bytestring_value_; + } + ++uint64_t Value::GetTag() const { ++ CHECK(has_tag()); ++ return tag_; ++} ++ + void Value::InternalMoveConstructFrom(Value&& that) { + type_ = that.type_; +- ++ tag_ = that.tag_; + switch (type_) { + case Type::UNSIGNED: + case Type::NEGATIVE: diff --git a/chromium_edits/131.0.6776.0/components/cbor/values.h.patch b/chromium_edits/131.0.6776.0/components/cbor/values.h.patch new file mode 100644 index 00000000..5556e8c5 --- /dev/null +++ b/chromium_edits/131.0.6776.0/components/cbor/values.h.patch @@ -0,0 +1,79 @@ +diff --git a/components/cbor/values.h b/components/cbor/values.h +index d55369f1a71bf..7dabb368c51d6 100644 +--- a/components/cbor/values.h ++++ b/components/cbor/values.h +@@ -125,28 +125,29 @@ class CBOR_EXPORT Value { + + explicit Value(Type type); + +- explicit Value(SimpleValue in_simple); +- explicit Value(bool boolean_value); +- explicit Value(double in_float); ++ explicit Value(SimpleValue in_simple, uint64_t tag = NO_TAG); ++ explicit Value(bool boolean_value, uint64_t tag = NO_TAG); ++ explicit Value(double in_float, uint64_t tag = NO_TAG); + +- explicit Value(int integer_value); +- explicit Value(int64_t integer_value); ++ explicit Value(int integer_value, uint64_t tag = NO_TAG); ++ explicit Value(int64_t integer_value, uint64_t tag = NO_TAG); + explicit Value(uint64_t integer_value) = delete; + +- explicit Value(base::span in_bytes); ++ explicit Value(base::span in_bytes, uint64_t tag = NO_TAG); + explicit Value(BinaryValue&& in_bytes) noexcept; + + explicit Value(const char* in_string, Type type = Type::STRING); + explicit Value(std::string&& in_string, Type type = Type::STRING) noexcept; +- explicit Value(std::string_view in_string, Type type = Type::STRING); ++ explicit Value(std::string_view in_string, Type type = Type::STRING, uint64_t tag = NO_TAG); + +- explicit Value(const ArrayValue& in_array); +- explicit Value(ArrayValue&& in_array) noexcept; ++ explicit Value(const ArrayValue& in_array, uint64_t tag = NO_TAG); ++ explicit Value(ArrayValue&& in_array, uint64_t tag = NO_TAG) noexcept; + +- explicit Value(const MapValue& in_map); ++ explicit Value(const MapValue& in_map, uint64_t tag = NO_TAG); + explicit Value(MapValue&& in_map) noexcept; + + Value& operator=(Value&& that) noexcept; ++ Value& SetTag(uint64_t) noexcept; + + Value(const Value&) = delete; + Value& operator=(const Value&) = delete; +@@ -177,6 +178,7 @@ class CBOR_EXPORT Value { + bool is_string() const { return type() == Type::STRING; } + bool is_array() const { return type() == Type::ARRAY; } + bool is_map() const { return type() == Type::MAP; } ++ bool has_tag() const { return tag_ != NO_TAG; } + + // These will all fatally assert if the type doesn't match. + SimpleValue GetSimpleValue() const; +@@ -192,12 +194,13 @@ class CBOR_EXPORT Value { + const ArrayValue& GetArray() const; + const MapValue& GetMap() const; + const BinaryValue& GetInvalidUTF8() const; ++ uint64_t GetTag() const; + + private: + friend class Reader; + // This constructor allows INVALID_UTF8 values to be created, which only + // |Reader| and InvalidUTF8StringValueForTesting() may do. +- Value(base::span in_bytes, Type type); ++ Value(base::span in_bytes, Type type, uint64_t tag = NO_TAG); + + Type type_; + +@@ -211,6 +214,11 @@ class CBOR_EXPORT Value { + MapValue map_value_; + }; + ++ //This value specified as Invalid, ++ // used here to represent absence of TAG ++ constexpr static uint64_t NO_TAG = 0xFFFF; ++ uint64_t tag_ = NO_TAG; ++ + void InternalMoveConstructFrom(Value&& that); + void InternalCleanup(); + }; diff --git a/chromium_edits/131.0.6776.0/components/cbor/writer.cc.patch b/chromium_edits/131.0.6776.0/components/cbor/writer.cc.patch new file mode 100644 index 00000000..1950e174 --- /dev/null +++ b/chromium_edits/131.0.6776.0/components/cbor/writer.cc.patch @@ -0,0 +1,14 @@ +diff --git a/components/cbor/writer.cc b/components/cbor/writer.cc +index c4bfcfb602949..b92885a30971c 100644 +--- a/components/cbor/writer.cc ++++ b/components/cbor/writer.cc +@@ -47,6 +47,9 @@ bool Writer::EncodeCBOR(const Value& node, + if (max_nesting_level < 0) + return false; + ++ if (node.has_tag()) { ++ StartItem(Value::Type::TAG, node.GetTag()); ++ } + switch (node.type()) { + case Value::Type::NONE: { + StartItem(Value::Type::BYTE_STRING, 0); diff --git a/chromium_edits/131.0.6776.0/components/cbor/writer_unittest.cc.patch b/chromium_edits/131.0.6776.0/components/cbor/writer_unittest.cc.patch new file mode 100644 index 00000000..1acf5f7f --- /dev/null +++ b/chromium_edits/131.0.6776.0/components/cbor/writer_unittest.cc.patch @@ -0,0 +1,36 @@ +diff --git a/components/cbor/writer_unittest.cc b/components/cbor/writer_unittest.cc +index ee11e7cb86712..b8942f1829a37 100644 +--- a/components/cbor/writer_unittest.cc ++++ b/components/cbor/writer_unittest.cc +@@ -523,4 +523,31 @@ TEST(CBORWriterTest, OverlyNestedCBOR) { + EXPECT_FALSE(Writer::Write(Value(map), 4).has_value()); + } + ++TEST(CBORWriterTest, CanWriteTag) { ++ std::array content{ ++ 0x00, 0x01, 0x71, 0x12, 0x20, ++ 0x69, 0xea, 0x07, 0x40, 0xf9, ++ 0x80, 0x7a, 0x28, 0xf4, 0xd9, ++ 0x32, 0xc6, 0x2e, 0x7c, 0x1c, ++ 0x83, 0xbe, 0x05, 0x5e, 0x55, ++ 0x07, 0x2c, 0x90, 0x26, 0x6a, ++ 0xb3, 0xe7, 0x9d, 0xf6, 0x3a, ++ 0x36, 0x5b ++ }; ++ Value to_write(content); ++ to_write.SetTag(42); ++ auto result = Writer::Write(to_write); ++ EXPECT_TRUE(result.has_value()); ++ auto& bytes = result.value(); ++ EXPECT_EQ(bytes.size(), 41UL); ++ EXPECT_EQ(bytes.at(0), 0xd8); ++ EXPECT_EQ(bytes.at(1), 0x2a); ++ EXPECT_EQ(bytes.at(2), 0x58); ++ EXPECT_EQ(bytes.at(3), 0x25); ++ for (auto i = 0UL; i < content.size(); ++i) { ++ ASSERT_LT(i + 4UL, bytes.size()); ++ ASSERT_EQ(content.at(i), bytes.at(i+4UL)); ++ } ++} ++ + } // namespace cbor diff --git a/chromium_edits/131.0.6776.0/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch b/chromium_edits/131.0.6776.0/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch new file mode 100644 index 00000000..ee376ce1 --- /dev/null +++ b/chromium_edits/131.0.6776.0/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch @@ -0,0 +1,13 @@ +diff --git a/components/open_from_clipboard/clipboard_recent_content_generic.cc b/components/open_from_clipboard/clipboard_recent_content_generic.cc +index 3683fadcc0914..440d4be132e5c 100644 +--- a/components/open_from_clipboard/clipboard_recent_content_generic.cc ++++ b/components/open_from_clipboard/clipboard_recent_content_generic.cc +@@ -20,7 +20,7 @@ + namespace { + // Schemes appropriate for suggestion by ClipboardRecentContent. + const char* kAuthorizedSchemes[] = { +- url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme, ++ url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme, "ipfs", "ipns" + // TODO(mpearson): add support for chrome:// URLs. Right now the scheme + // for that lives in content and is accessible via + // GetEmbedderRepresentationOfAboutScheme() or content::kChromeUIScheme diff --git a/chromium_edits/131.0.6776.0/net/dns/dns_config_service_linux.cc.patch b/chromium_edits/131.0.6776.0/net/dns/dns_config_service_linux.cc.patch new file mode 100644 index 00000000..fd7227a5 --- /dev/null +++ b/chromium_edits/131.0.6776.0/net/dns/dns_config_service_linux.cc.patch @@ -0,0 +1,18 @@ +diff --git a/net/dns/dns_config_service_linux.cc b/net/dns/dns_config_service_linux.cc +index 7aaf9fa5b0b78..5a9f5b5a70dd9 100644 +--- a/net/dns/dns_config_service_linux.cc ++++ b/net/dns/dns_config_service_linux.cc +@@ -276,11 +276,11 @@ bool IsNsswitchConfigCompatible( + // Ignore any entries after `kDns` because Chrome will fallback to the + // system resolver if a result was not found in DNS. + return true; +- ++ case NsswitchReader::Service::kResolve: ++ break; + case NsswitchReader::Service::kMdns: + case NsswitchReader::Service::kMdns4: + case NsswitchReader::Service::kMdns6: +- case NsswitchReader::Service::kResolve: + case NsswitchReader::Service::kNis: + RecordIncompatibleNsswitchReason( + IncompatibleNsswitchReason::kIncompatibleService, diff --git a/chromium_edits/131.0.6776.0/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch b/chromium_edits/131.0.6776.0/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch new file mode 100644 index 00000000..663fe49e --- /dev/null +++ b/chromium_edits/131.0.6776.0/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch @@ -0,0 +1,15 @@ +diff --git a/third_party/blink/renderer/platform/weborigin/scheme_registry.cc b/third_party/blink/renderer/platform/weborigin/scheme_registry.cc +index e1bc209c337c5..6fbac29fcddfd 100644 +--- a/third_party/blink/renderer/platform/weborigin/scheme_registry.cc ++++ b/third_party/blink/renderer/platform/weborigin/scheme_registry.cc +@@ -68,8 +68,8 @@ class URLSchemesRegistry final { + // is considered secure. Additional checks are performed to ensure that + // other http pages are filtered out. + service_worker_schemes({"http", "https"}), +- fetch_api_schemes({"http", "https"}), +- allowed_in_referrer_schemes({"http", "https"}) { ++ fetch_api_schemes({"http", "https", "ipfs", "ipns"}), ++ allowed_in_referrer_schemes({"http", "https", "ipfs", "ipns"}) { + for (auto& scheme : url::GetCorsEnabledSchemes()) + cors_enabled_schemes.insert(scheme.c_str()); + for (auto& scheme : url::GetCSPBypassingSchemes()) { diff --git a/chromium_edits/131.0.6776.0/url/BUILD.gn.patch b/chromium_edits/131.0.6776.0/url/BUILD.gn.patch new file mode 100644 index 00000000..be4bfca8 --- /dev/null +++ b/chromium_edits/131.0.6776.0/url/BUILD.gn.patch @@ -0,0 +1,32 @@ +diff --git a/url/BUILD.gn b/url/BUILD.gn +index f22b73bc29f06..df36977322ec7 100644 +--- a/url/BUILD.gn ++++ b/url/BUILD.gn +@@ -5,6 +5,7 @@ + import("//build/buildflag_header.gni") + import("//testing/libfuzzer/fuzzer_test.gni") + import("//testing/test.gni") ++import("//third_party/ipfs_client/args.gni") + import("features.gni") + + import("//build/config/cronet/config.gni") +@@ -67,6 +68,7 @@ component("url") { + public_deps = [ + "//base", + "//build:robolectric_buildflags", ++ "//third_party/ipfs_client:ipfs_buildflags", + ] + + configs += [ "//build/config/compiler:wexit_time_destructors" ] +@@ -89,6 +91,11 @@ component("url") { + public_configs = [ "//third_party/jdk" ] + } + ++ if (enable_ipfs) { ++ sources += [ "url_canon_ipfs.cc" ] ++ deps += [ "//third_party/ipfs_client:ipfs_client" ] ++ } ++ + if (is_win) { + # Don't conflict with Windows' "url.dll". + output_name = "url_lib" diff --git a/chromium_edits/131.0.6776.0/url/url_canon.h.patch b/chromium_edits/131.0.6776.0/url/url_canon.h.patch new file mode 100644 index 00000000..0f667205 --- /dev/null +++ b/chromium_edits/131.0.6776.0/url/url_canon.h.patch @@ -0,0 +1,26 @@ +diff --git a/url/url_canon.h b/url/url_canon.h +index 3b84d686ba0f0..c18cb750c6de1 100644 +--- a/url/url_canon.h ++++ b/url/url_canon.h +@@ -855,6 +855,21 @@ bool CanonicalizeMailtoURL(const char16_t* spec, + CanonOutput* output, + Parsed* new_parsed); + ++COMPONENT_EXPORT(URL) ++bool CanonicalizeIpfsURL(std::string_view spec, ++ const Parsed& parsed, ++ SchemeType scheme_type, ++ CharsetConverter* query_converter, ++ CanonOutput* output, ++ Parsed* new_parsed); ++COMPONENT_EXPORT(URL) ++bool CanonicalizeIpfsURL(std::basic_string_view spec, ++ const Parsed& parsed, ++ SchemeType scheme_type, ++ CharsetConverter* query_converter, ++ CanonOutput* output, ++ Parsed* new_parsed); ++ + // Part replacer -------------------------------------------------------------- + + // Internal structure used for storing separate strings for each component. diff --git a/chromium_edits/131.0.6776.0/url/url_canon_ipfs.cc b/chromium_edits/131.0.6776.0/url/url_canon_ipfs.cc new file mode 100644 index 00000000..e40732ee --- /dev/null +++ b/chromium_edits/131.0.6776.0/url/url_canon_ipfs.cc @@ -0,0 +1,54 @@ +#include "url_canon_internal.h" + +#include +#include + +#include + +bool url::CanonicalizeIpfsURL(std::string_view spec, + const Parsed& parsed, + SchemeType scheme_type, + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed) { + if (spec.size() < 1) { + return false; + } + if ( parsed.host.len < 1 ) { + return false; + } + auto cid_str = spec.substr( parsed.host.begin, static_cast(parsed.host.len) ); + auto cid = ipfs::Cid(cid_str); + if ( !cid.valid() ) { + cid = ipfs::id_cid::forText( std::string{cid_str} + " is not a valid CID." ); + } + auto as_str = cid.to_string(); + if ( as_str.empty() ) { + return false; + } + std::string stdurl{ spec.substr(0UL, static_cast(parsed.host.begin)) }; + stdurl.append( as_str ); + spec.remove_prefix(parsed.host.end()); + stdurl.append(spec); + auto len = static_cast(stdurl.size()); + Parsed parsed_input; + ParseStandardURL(stdurl.data(), len, &parsed_input); + return CanonicalizeStandardURL( + stdurl.data(), + parsed_input, + scheme_type, + charset_converter, + output, output_parsed + ); +} +bool url::CanonicalizeIpfsURL(std::basic_string_view spec, + const Parsed& parsed, + SchemeType scheme_type, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* new_parsed) { + RawCanonOutput<2048> as8; + ConvertUTF16ToUTF8(spec.data(), spec.size(), &as8); + return CanonicalizeIpfsURL({as8.data(), as8.length()}, parsed, scheme_type, + query_converter, output, new_parsed); +} diff --git a/chromium_edits/131.0.6776.0/url/url_util.cc.patch b/chromium_edits/131.0.6776.0/url/url_util.cc.patch new file mode 100644 index 00000000..988797b0 --- /dev/null +++ b/chromium_edits/131.0.6776.0/url/url_util.cc.patch @@ -0,0 +1,45 @@ +diff --git a/url/url_util.cc b/url/url_util.cc +index ce5225e121f5d..79e33208f728e 100644 +--- a/url/url_util.cc ++++ b/url/url_util.cc +@@ -76,6 +76,8 @@ struct SchemeRegistry { + std::vector referrer_schemes = { + {kHttpsScheme, SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION}, + {kHttpScheme, SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION}, ++ {"ipfs", SCHEME_WITH_HOST}, ++ {"ipns", SCHEME_WITH_HOST}, + }; + + // Schemes that do not trigger mixed content warning. +@@ -84,6 +86,8 @@ struct SchemeRegistry { + kWssScheme, + kDataScheme, + kAboutScheme, ++ {"ipfs", SCHEME_WITH_HOST}, ++ {"ipns", SCHEME_WITH_HOST}, + }; + + // Schemes that normal pages cannot link to or access (i.e., with the same +@@ -105,6 +109,8 @@ struct SchemeRegistry { + kHttpsScheme, + kHttpScheme, + kDataScheme, ++ {"ipfs", SCHEME_WITH_HOST}, ++ {"ipns", SCHEME_WITH_HOST}, + }; + + // Schemes that can be used by web to store data (local storage, etc). +@@ -308,7 +314,12 @@ bool DoCanonicalize(const CHAR* spec, + success = CanonicalizeFileSystemURL( + spec, ParseFileSystemURL(std::basic_string_view(spec, spec_len)), + charset_converter, output, output_parsed); +- ++ } else if (DoCompareSchemeComponent(spec, scheme, "ipfs")) { ++ auto spec_view = std::basic_string_view(spec, spec_len); ++ // Switch multibase away from case-sensitive ones before continuing canonicalization. ++ auto parsed_input = ParseStandardURL(spec_view); ++ success = CanonicalizeIpfsURL(spec_view, parsed_input, scheme_type, ++ charset_converter, output, output_parsed); + } else if (DoIsStandard(spec, scheme, &scheme_type)) { + // All "normal" URLs. + success = CanonicalizeStandardURL( diff --git a/chromium_edits/132.0.6779.0/chrome/browser/BUILD.gn.patch b/chromium_edits/132.0.6779.0/chrome/browser/BUILD.gn.patch new file mode 100644 index 00000000..10eb32a0 --- /dev/null +++ b/chromium_edits/132.0.6779.0/chrome/browser/BUILD.gn.patch @@ -0,0 +1,27 @@ +diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn +index a662f8e18d5d5..032e290e7175b 100644 +--- a/chrome/browser/BUILD.gn ++++ b/chrome/browser/BUILD.gn +@@ -40,6 +40,7 @@ import("//sandbox/features.gni") + import("//services/screen_ai/buildflags/features.gni") + import("//testing/libfuzzer/fuzzer_test.gni") + import("//third_party/blink/public/public_features.gni") ++import("//third_party/ipfs_client/args.gni") + import("//third_party/protobuf/proto_library.gni") + import("//third_party/webrtc/webrtc.gni") + import("//third_party/widevine/cdm/widevine.gni") +@@ -2511,6 +2512,14 @@ static_library("browser") { + "//ui/webui", + ] + ++ if (enable_ipfs) { ++ sources += [ ++ "ipfs_extra_parts.cc", ++ "ipfs_extra_parts.h", ++ ] ++ deps += [ "//components/ipfs" ] ++ } ++ + # Platforms that have a network diagnostics dialog. All others fall through + # to the stub which is not implemented. + if (is_chromeos_ash) { diff --git a/chromium_edits/132.0.6779.0/chrome/browser/about_flags.cc.patch b/chromium_edits/132.0.6779.0/chrome/browser/about_flags.cc.patch new file mode 100644 index 00000000..58a21491 --- /dev/null +++ b/chromium_edits/132.0.6779.0/chrome/browser/about_flags.cc.patch @@ -0,0 +1,38 @@ +diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc +index 0c1684bb316d3..239491ca74c64 100644 +--- a/chrome/browser/about_flags.cc ++++ b/chrome/browser/about_flags.cc +@@ -229,6 +229,7 @@ + #include "third_party/blink/public/common/features_generated.h" + #include "third_party/blink/public/common/forcedark/forcedark_switches.h" + #include "third_party/blink/public/common/switches.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + #include "ui/accessibility/accessibility_features.h" + #include "ui/accessibility/accessibility_switches.h" + #include "ui/base/ozone_buildflags.h" +@@ -330,6 +331,10 @@ + #include "extensions/common/switches.h" + #endif // BUILDFLAG(ENABLE_EXTENSIONS) + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "components/ipfs/ipfs_features.h" ++#endif ++ + #if BUILDFLAG(ENABLE_PDF) + #include "pdf/pdf_features.h" + #endif +@@ -9780,6 +9785,14 @@ const FeatureEntry kFeatureEntries[] = { + flag_descriptions::kOmitCorsClientCertDescription, kOsAll, + FEATURE_VALUE_TYPE(network::features::kOmitCorsClientCert)}, + ++#if BUILDFLAG(ENABLE_IPFS) ++ {"enable-ipfs", ++ flag_descriptions::kEnableIpfsName, ++ flag_descriptions::kEnableIpfsDescription, ++ kOsMac | kOsWin | kOsLinux,//TODO: These are the only variants currently getting built, but that is not likely to remain the case ++ FEATURE_VALUE_TYPE(ipfs::kEnableIpfs)}, ++#endif ++ + {"use-idna2008-non-transitional", + flag_descriptions::kUseIDNA2008NonTransitionalName, + flag_descriptions::kUseIDNA2008NonTransitionalDescription, kOsAll, diff --git a/chromium_edits/132.0.6779.0/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch b/chromium_edits/132.0.6779.0/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch new file mode 100644 index 00000000..f9965a24 --- /dev/null +++ b/chromium_edits/132.0.6779.0/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc.patch @@ -0,0 +1,51 @@ +diff --git a/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc b/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc +index 9f234a2a7d41d..a9378ca80dc1e 100644 +--- a/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc ++++ b/chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.cc +@@ -13,6 +13,7 @@ + #include "chrome/browser/profiles/profile_io_data.h" + #include "components/custom_handlers/protocol_handler_registry.h" + #include "content/public/common/url_constants.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + #include "url/url_util.h" + + #if BUILDFLAG(IS_ANDROID) +@@ -20,6 +21,11 @@ + #include "chrome/browser/ui/android/omnibox/jni_headers/ChromeAutocompleteSchemeClassifier_jni.h" + #endif + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "components/ipfs/ipfs_features.h" ++#endif ++ ++ + #if BUILDFLAG(IS_ANDROID) + static jlong + JNI_ChromeAutocompleteSchemeClassifier_CreateAutocompleteClassifier( +@@ -53,12 +59,20 @@ ChromeAutocompleteSchemeClassifier::GetInputTypeForScheme( + if (scheme.empty()) { + return metrics::OmniboxInputType::EMPTY; + } +- if (base::IsStringASCII(scheme) && +- (ProfileIOData::IsHandledProtocol(scheme) || +- base::EqualsCaseInsensitiveASCII(scheme, content::kViewSourceScheme) || +- base::EqualsCaseInsensitiveASCII(scheme, url::kJavaScriptScheme) || +- base::EqualsCaseInsensitiveASCII(scheme, url::kDataScheme))) { +- return metrics::OmniboxInputType::URL; ++ if (base::IsStringASCII(scheme)) { ++ if (ProfileIOData::IsHandledProtocol(scheme) || ++ base::EqualsCaseInsensitiveASCII(scheme, content::kViewSourceScheme) || ++ base::EqualsCaseInsensitiveASCII(scheme, url::kJavaScriptScheme) || ++ base::EqualsCaseInsensitiveASCII(scheme, url::kDataScheme)) { ++ return metrics::OmniboxInputType::URL; ++ } ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs) && ++ (base::EqualsCaseInsensitiveASCII(scheme, "ipfs") || base::EqualsCaseInsensitiveASCII(scheme, "ipns")) ++ ) { ++ return metrics::OmniboxInputType::URL; ++ } ++#endif + } + + // Also check for schemes registered via registerProtocolHandler(), which diff --git a/chromium_edits/132.0.6779.0/chrome/browser/chrome_content_browser_client.cc.patch b/chromium_edits/132.0.6779.0/chrome/browser/chrome_content_browser_client.cc.patch new file mode 100644 index 00000000..b2d5551b --- /dev/null +++ b/chromium_edits/132.0.6779.0/chrome/browser/chrome_content_browser_client.cc.patch @@ -0,0 +1,81 @@ +diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc +index 938311b47a211..e343d1db68777 100644 +--- a/chrome/browser/chrome_content_browser_client.cc ++++ b/chrome/browser/chrome_content_browser_client.cc +@@ -408,6 +408,7 @@ + #include "third_party/blink/public/mojom/browsing_topics/browsing_topics.mojom.h" + #include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom.h" + #include "third_party/blink/public/public_buildflags.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + #include "third_party/widevine/cdm/buildflags.h" + #include "ui/base/clipboard/clipboard_format_type.h" + #include "ui/base/l10n/l10n_util.h" +@@ -535,6 +536,13 @@ + #include "chrome/browser/chrome_browser_main_posix.h" + #endif + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "chrome/browser/ipfs_extra_parts.h" ++#include "components/ipfs/interceptor.h" ++#include "components/ipfs/ipfs_features.h" ++#include "components/ipfs/url_loader_factory.h" ++#endif ++ + #if !BUILDFLAG(IS_ANDROID) + #include "chrome/browser/digital_credentials/digital_identity_provider_desktop.h" + #include "chrome/browser/preloading/preview/preview_navigation_throttle.h" +@@ -1864,6 +1872,11 @@ ChromeContentBrowserClient::CreateBrowserMainParts(bool is_integration_test) { + main_parts->AddParts( + std::make_unique()); + ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ main_parts->AddParts(std::make_unique()); ++ } ++#endif + return main_parts; + } + +@@ -6559,12 +6572,29 @@ void ChromeContentBrowserClient:: + const std::optional& request_initiator_origin, + NonNetworkURLLoaderFactoryMap* factories) { + #if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS) || \ +- !BUILDFLAG(IS_ANDROID) ++ !BUILDFLAG(IS_ANDROID) || BUILDFLAG(ENABLE_IPFS) + content::RenderFrameHost* frame_host = + RenderFrameHost::FromID(render_process_id, render_frame_id); + WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host); + #endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS) || \ + // !BUILDFLAG(IS_ANDROID) ++#if BUILDFLAG(ENABLE_IPFS) ++ if (!web_contents) { ++ VLOG(2) << "No web contents, can't register url loader factory."; ++ } else if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ network::mojom::URLLoaderFactory* default_factory = g_browser_process->system_network_context_manager()->GetURLLoaderFactory(); ++ auto* context = web_contents->GetBrowserContext(); ++ ipfs::IpfsURLLoaderFactory::Create( ++ factories, ++ context, ++ default_factory, ++ GetSystemNetworkContext(), ++ Profile::FromBrowserContext(context)->GetPrefs() ++ ); ++ } else { ++ LOG(INFO) << "IPFS disabled."; ++ } ++#endif // BUILDFLAG(ENABLE_IPFS) + + #if BUILDFLAG(IS_CHROMEOS_ASH) + if (web_contents) { +@@ -6712,6 +6742,11 @@ ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors( + scoped_refptr navigation_response_task_runner) { + std::vector> + interceptors; ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ interceptors.push_back(std::make_unique(g_browser_process->system_network_context_manager()->GetURLLoaderFactory(), GetSystemNetworkContext())); ++ } ++#endif + #if BUILDFLAG(ENABLE_OFFLINE_PAGES) + interceptors.push_back( + std::make_unique( diff --git a/chromium_edits/132.0.6779.0/chrome/browser/flag-metadata.json.patch b/chromium_edits/132.0.6779.0/chrome/browser/flag-metadata.json.patch new file mode 100644 index 00000000..b3c10ee9 --- /dev/null +++ b/chromium_edits/132.0.6779.0/chrome/browser/flag-metadata.json.patch @@ -0,0 +1,16 @@ +diff --git a/chrome/browser/flag-metadata.json b/chrome/browser/flag-metadata.json +index 41a311667c969..aa2979675dc41 100644 +--- a/chrome/browser/flag-metadata.json ++++ b/chrome/browser/flag-metadata.json +@@ -3407,6 +3407,11 @@ + "owners": [ "adamta@google.com", "bling-get-set-up@google.com" ], + "expiry_milestone": 140 + }, ++ { ++ "name": "enable-ipfs", ++ "owners": [ "//components/ipfs/OWNERS" ], ++ "expiry_milestone": 150 ++ }, + { + "name": "enable-isolated-sandboxed-iframes", + "owners": [ "wjmaclean@chromium.org", "alexmos@chromium.org", "creis@chromium.org" ], diff --git a/chromium_edits/132.0.6779.0/chrome/browser/flag_descriptions.cc.patch b/chromium_edits/132.0.6779.0/chrome/browser/flag_descriptions.cc.patch new file mode 100644 index 00000000..30eb5456 --- /dev/null +++ b/chromium_edits/132.0.6779.0/chrome/browser/flag_descriptions.cc.patch @@ -0,0 +1,16 @@ +diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc +index 9d8f25557ff78..9240b244f4361 100644 +--- a/chrome/browser/flag_descriptions.cc ++++ b/chrome/browser/flag_descriptions.cc +@@ -345,6 +345,11 @@ const char kEnableBookmarksSelectedTypeOnSigninForTestingDescription[] = + "sync-enable-bookmarks-in-transport-mode. Enables the bookmarks " + "UserSelectableType upon sign-in"; + ++#if BUILDFLAG(ENABLE_IPFS) ++extern const char kEnableIpfsName[] = "Enable IPFS"; ++extern const char kEnableIpfsDescription[] = "Enable ipfs:// and ipns:// URLs"; ++#endif ++ + const char kPreloadingOnPerformancePageName[] = + "Preloading Settings on Performance Page"; + const char kPreloadingOnPerformancePageDescription[] = diff --git a/chromium_edits/132.0.6779.0/chrome/browser/flag_descriptions.h.patch b/chromium_edits/132.0.6779.0/chrome/browser/flag_descriptions.h.patch new file mode 100644 index 00000000..cf1a2f3c --- /dev/null +++ b/chromium_edits/132.0.6779.0/chrome/browser/flag_descriptions.h.patch @@ -0,0 +1,24 @@ +diff --git a/chrome/browser/flag_descriptions.h b/chrome/browser/flag_descriptions.h +index 45bff4cff3005..918c70e101b02 100644 +--- a/chrome/browser/flag_descriptions.h ++++ b/chrome/browser/flag_descriptions.h +@@ -25,6 +25,7 @@ + #include "printing/buildflags/buildflags.h" + #include "skia/buildflags.h" + #include "third_party/blink/public/common/buildflags.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + + // This file declares strings used in chrome://flags. These messages are not + // translated, because instead of end-users they target Chromium developers and +@@ -212,6 +213,11 @@ extern const char kEnableBenchmarkingChoiceMatchFieldTrialTestingConfig[]; + extern const char kEnableBookmarksSelectedTypeOnSigninForTestingName[]; + extern const char kEnableBookmarksSelectedTypeOnSigninForTestingDescription[]; + ++#if BUILDFLAG(ENABLE_IPFS) ++extern const char kEnableIpfsName[]; ++extern const char kEnableIpfsDescription[]; ++#endif ++ + extern const char kFontationsFontBackendName[]; + extern const char kFontationsFontBackendDescription[]; + diff --git a/chromium_edits/132.0.6779.0/chrome/browser/ipfs_extra_parts.cc b/chromium_edits/132.0.6779.0/chrome/browser/ipfs_extra_parts.cc new file mode 100644 index 00000000..90d2596f --- /dev/null +++ b/chromium_edits/132.0.6779.0/chrome/browser/ipfs_extra_parts.cc @@ -0,0 +1,10 @@ +#include "ipfs_extra_parts.h" + +#include "profiles/profile.h" + +#include + +void IpfsExtraParts::PostProfileInit(Profile* profile, bool /* is_initial_profile */ ) { + DCHECK(profile); + ipfs::InterRequestState::CreateForBrowserContext(profile, profile->GetPrefs()); +} diff --git a/chromium_edits/132.0.6779.0/chrome/browser/ipfs_extra_parts.h b/chromium_edits/132.0.6779.0/chrome/browser/ipfs_extra_parts.h new file mode 100644 index 00000000..2059c437 --- /dev/null +++ b/chromium_edits/132.0.6779.0/chrome/browser/ipfs_extra_parts.h @@ -0,0 +1,10 @@ +#ifndef IPFS_EXTRA_PART_H_ +#define IPFS_EXTRA_PART_H_ + +#include + +class IpfsExtraParts : public ChromeBrowserMainExtraParts { + void PostProfileInit(Profile* profile, bool is_initial_profile) override; +}; + +#endif // IPFS_EXTRA_PART_H_ diff --git a/chromium_edits/132.0.6779.0/chrome/browser/prefs/browser_prefs.cc.patch b/chromium_edits/132.0.6779.0/chrome/browser/prefs/browser_prefs.cc.patch new file mode 100644 index 00000000..875a345d --- /dev/null +++ b/chromium_edits/132.0.6779.0/chrome/browser/prefs/browser_prefs.cc.patch @@ -0,0 +1,36 @@ +diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc +index 203bc46e39973..eb93524bf6053 100644 +--- a/chrome/browser/prefs/browser_prefs.cc ++++ b/chrome/browser/prefs/browser_prefs.cc +@@ -202,6 +202,7 @@ + #include "ppapi/buildflags/buildflags.h" + #include "printing/buildflags/buildflags.h" + #include "rlz/buildflags/buildflags.h" ++#include "third_party/ipfs_client/ipfs_buildflags.h" + + #if BUILDFLAG(ENABLE_BACKGROUND_MODE) + #include "chrome/browser/background/background_mode_manager.h" +@@ -250,6 +251,11 @@ + #include "chrome/browser/pdf/pdf_pref_names.h" + #endif // BUILDFLAG(ENABLE_PDF) + ++#if BUILDFLAG(ENABLE_IPFS) ++#include "components/ipfs/ipfs_features.h" ++#include "components/ipfs/preferences.h" ++#endif ++ + #if BUILDFLAG(IS_ANDROID) + #include "chrome/browser/accessibility/accessibility_prefs/android/accessibility_prefs_controller.h" + #include "chrome/browser/android/bookmarks/partner_bookmarks_shim.h" +@@ -1980,6 +1986,11 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry, + IncognitoModePrefs::RegisterProfilePrefs(registry); + invalidation::PerUserTopicSubscriptionManager::RegisterProfilePrefs(registry); + invalidation::InvalidatorRegistrarWithMemory::RegisterProfilePrefs(registry); ++#if BUILDFLAG(ENABLE_IPFS) ++ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) { ++ ipfs::RegisterPreferences(registry); ++ } ++#endif + language::LanguagePrefs::RegisterProfilePrefs(registry); + login_detection::prefs::RegisterProfilePrefs(registry); + lookalikes::RegisterProfilePrefs(registry); diff --git a/chromium_edits/132.0.6779.0/chrome/browser/shell_integration_mac.mm.patch b/chromium_edits/132.0.6779.0/chrome/browser/shell_integration_mac.mm.patch new file mode 100644 index 00000000..220e2546 --- /dev/null +++ b/chromium_edits/132.0.6779.0/chrome/browser/shell_integration_mac.mm.patch @@ -0,0 +1,13 @@ +diff --git a/chrome/browser/shell_integration_mac.mm b/chrome/browser/shell_integration_mac.mm +index c6bb768979453..c0d0abb9c78f3 100644 +--- a/chrome/browser/shell_integration_mac.mm ++++ b/chrome/browser/shell_integration_mac.mm +@@ -79,6 +79,8 @@ bool SetAsDefaultBrowser() { + if (LSSetDefaultHandlerForURLScheme(CFSTR("https"), identifier) != noErr) { + return false; + } ++ LSSetDefaultHandlerForURLScheme(CFSTR("ipfs"), identifier); ++ LSSetDefaultHandlerForURLScheme(CFSTR("ipns"), identifier); + if (LSSetDefaultRoleHandlerForContentType(kUTTypeHTML, kLSRolesViewer, + identifier) != noErr) { + return false; diff --git a/chromium_edits/132.0.6779.0/chrome/common/chrome_content_client.cc.patch b/chromium_edits/132.0.6779.0/chrome/common/chrome_content_client.cc.patch new file mode 100644 index 00000000..d34894b4 --- /dev/null +++ b/chromium_edits/132.0.6779.0/chrome/common/chrome_content_client.cc.patch @@ -0,0 +1,17 @@ +diff --git a/chrome/common/chrome_content_client.cc b/chrome/common/chrome_content_client.cc +index 60515232467d7..14d5e12a76c76 100644 +--- a/chrome/common/chrome_content_client.cc ++++ b/chrome/common/chrome_content_client.cc +@@ -314,6 +314,12 @@ void ChromeContentClient::AddAdditionalSchemes(Schemes* schemes) { + #if BUILDFLAG(IS_ANDROID) + schemes->local_schemes.push_back(url::kContentScheme); + #endif ++ for ( const char* ip_s : {"ipfs", "ipns"} ) { ++ schemes->standard_schemes.push_back(ip_s); ++ schemes->cors_enabled_schemes.push_back(ip_s); ++ schemes->secure_schemes.push_back(ip_s); ++ schemes->csp_bypassing_schemes.push_back(ip_s); ++ } + } + + std::u16string ChromeContentClient::GetLocalizedString(int message_id) { diff --git a/chromium_edits/132.0.6779.0/chrome/installer/linux/common/desktop.template.patch b/chromium_edits/132.0.6779.0/chrome/installer/linux/common/desktop.template.patch new file mode 100644 index 00000000..dcd9460b --- /dev/null +++ b/chromium_edits/132.0.6779.0/chrome/installer/linux/common/desktop.template.patch @@ -0,0 +1,13 @@ +diff --git a/chrome/installer/linux/common/desktop.template b/chrome/installer/linux/common/desktop.template +index 2eb13ee1aba46..9af65726bde89 100644 +--- a/chrome/installer/linux/common/desktop.template ++++ b/chrome/installer/linux/common/desktop.template +@@ -111,7 +111,7 @@ Terminal=false + Icon=@@PACKAGE@@ + Type=Application + Categories=Network;WebBrowser; +-MimeType=application/pdf;application/rdf+xml;application/rss+xml;application/xhtml+xml;application/xhtml_xml;application/xml;image/gif;image/jpeg;image/png;image/webp;text/html;text/xml;x-scheme-handler/http;x-scheme-handler/https; ++MimeType=application/pdf;application/rdf+xml;application/rss+xml;application/xhtml+xml;application/xhtml_xml;application/xml;image/gif;image/jpeg;image/png;image/webp;text/html;text/xml;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/ipfs;x-scheme-handler/ipns; + Actions=new-window;new-private-window; + + [Desktop Action new-window] diff --git a/chromium_edits/132.0.6779.0/chrome/installer/util/shell_util.cc.patch b/chromium_edits/132.0.6779.0/chrome/installer/util/shell_util.cc.patch new file mode 100644 index 00000000..fccdad80 --- /dev/null +++ b/chromium_edits/132.0.6779.0/chrome/installer/util/shell_util.cc.patch @@ -0,0 +1,20 @@ +diff --git a/chrome/installer/util/shell_util.cc b/chrome/installer/util/shell_util.cc +index c087d1c02bca4..382a36b9cd800 100644 +--- a/chrome/installer/util/shell_util.cc ++++ b/chrome/installer/util/shell_util.cc +@@ -1545,11 +1545,12 @@ const wchar_t* ShellUtil::kDefaultFileAssociations[] = { + const wchar_t* ShellUtil::kPotentialFileAssociations[] = { + L".htm", L".html", L".mhtml", L".pdf", L".shtml", + L".svg", L".xht", L".xhtml", L".webp", nullptr}; +-const wchar_t* ShellUtil::kBrowserProtocolAssociations[] = {L"http", L"https", +- nullptr}; ++const wchar_t* ShellUtil::kBrowserProtocolAssociations[] = { ++ L"http", L"https", L"ipfs", L"ipns", nullptr}; + const wchar_t* ShellUtil::kPotentialProtocolAssociations[] = { + L"http", L"https", L"irc", L"mailto", L"mms", L"news", L"nntp", +- L"sms", L"smsto", L"snews", L"tel", L"urn", L"webcal", nullptr}; ++ L"sms", L"smsto", L"snews", L"tel", L"urn", L"webcal", L"ipfs", ++ L"ipns", nullptr}; + const wchar_t* ShellUtil::kRegUrlProtocol = L"URL Protocol"; + const wchar_t* ShellUtil::kRegApplication = L"\\Application"; + const wchar_t* ShellUtil::kRegAppUserModelId = L"AppUserModelId"; diff --git a/chromium_edits/132.0.6779.0/components/cbor/reader.cc.patch b/chromium_edits/132.0.6779.0/components/cbor/reader.cc.patch new file mode 100644 index 00000000..de3d0b36 --- /dev/null +++ b/chromium_edits/132.0.6779.0/components/cbor/reader.cc.patch @@ -0,0 +1,44 @@ +diff --git a/components/cbor/reader.cc b/components/cbor/reader.cc +index 24d852e45f2ba..4dfec34caabd7 100644 +--- a/components/cbor/reader.cc ++++ b/components/cbor/reader.cc +@@ -22,7 +22,7 @@ + namespace cbor { + + namespace constants { +-const char kUnsupportedMajorType[] = "Unsupported major type."; ++const char kUnsupportedMajorType[] = "Unsupported major type operation."; + } + + namespace { +@@ -156,7 +156,11 @@ std::optional Reader::DecodeCompleteDataItem(const Config& config, + case Value::Type::FLOAT_VALUE: + // Floating point values also go here since they are also type 7. + return DecodeToSimpleValueOrFloat(*header, config); +- case Value::Type::TAG: // We explicitly don't support TAG. ++ case Value::Type::TAG: ++ if (config.parse_tags) { ++ return ReadTagContent(*header, config, max_nesting_level); ++ } ++ break; + case Value::Type::NONE: + case Value::Type::INVALID_UTF8: + break; +@@ -347,6 +351,17 @@ std::optional Reader::ReadByteStringContent( + return Value(std::move(cbor_byte_string)); + } + ++std::optional Reader::ReadTagContent( ++ const Reader::DataItemHeader& header, ++ const Config& config, ++ int max_nesting_level) { ++ auto tagged_content = DecodeCompleteDataItem(config, max_nesting_level); ++ if (tagged_content.has_value()) { ++ tagged_content.value().SetTag(header.value); ++ } ++ return tagged_content; ++} ++ + std::optional Reader::ReadArrayContent( + const Reader::DataItemHeader& header, + const Config& config, diff --git a/chromium_edits/132.0.6779.0/components/cbor/reader.h.patch b/chromium_edits/132.0.6779.0/components/cbor/reader.h.patch new file mode 100644 index 00000000..2dbc0534 --- /dev/null +++ b/chromium_edits/132.0.6779.0/components/cbor/reader.h.patch @@ -0,0 +1,26 @@ +diff --git a/components/cbor/reader.h b/components/cbor/reader.h +index 5f11ba48ba494..d4c9c489da4b6 100644 +--- a/components/cbor/reader.h ++++ b/components/cbor/reader.h +@@ -131,6 +131,11 @@ class CBOR_EXPORT Reader { + // during decoding will set raise the `UNSUPPORTED_FLOATING_POINT_VALUE` + // error. + bool allow_floating_point = false; ++ ++ // If the parser encounters a TAG element, should it be parsed out and ++ // the tag value saved (true), or should the entire node and its content ++ // be discarded (false) ++ bool parse_tags = false; + }; + + Reader(const Reader&) = delete; +@@ -205,6 +210,9 @@ class CBOR_EXPORT Reader { + std::optional ReadMapContent(const DataItemHeader& header, + const Config& config, + int max_nesting_level); ++ std::optional ReadTagContent(const DataItemHeader& header, ++ const Config& config, ++ int max_nesting_level); + std::optional ReadByte(); + std::optional> ReadBytes(uint64_t num_bytes); + bool IsKeyInOrder(const Value& new_key, diff --git a/chromium_edits/132.0.6779.0/components/cbor/reader_unittest.cc.patch b/chromium_edits/132.0.6779.0/components/cbor/reader_unittest.cc.patch new file mode 100644 index 00000000..150e0c73 --- /dev/null +++ b/chromium_edits/132.0.6779.0/components/cbor/reader_unittest.cc.patch @@ -0,0 +1,47 @@ +diff --git a/components/cbor/reader_unittest.cc b/components/cbor/reader_unittest.cc +index e5c02ceea3402..f26b8e77f6da3 100644 +--- a/components/cbor/reader_unittest.cc ++++ b/components/cbor/reader_unittest.cc +@@ -1449,5 +1449,42 @@ TEST(CBORReaderTest, AllowInvalidUTF8) { + EXPECT_FALSE(cbor); + EXPECT_EQ(Reader::DecoderError::INVALID_UTF8, error); + } ++TEST(CBORReaderTest, RejectsTagUnderDefaultConfig) { ++ static const uint8_t kTaggedCbor[] = { ++ 0xd8, 0x2a, 0x58, 0x25, 0x00, 0x01, 0x71, 0x12, 0x20, 0x69, 0xea, 0x07, ++ 0x40, 0xf9, 0x80, 0x7a, 0x28, 0xf4, 0xd9, 0x32, 0xc6, 0x2e, 0x7c, 0x1c, ++ 0x83, 0xbe, 0x05, 0x5e, 0x55, 0x07, 0x2c, 0x90, 0x26, 0x6a, 0xb3, 0xe7, ++ 0x9d, 0xf6, 0x3a, 0x36, 0x5b ++ }; ++ Reader::Config config; ++ auto cbor = Reader::Read(kTaggedCbor, config); ++ EXPECT_FALSE(cbor.has_value()); ++} ++TEST(CBORReaderTest, ReadsTagWhenConfiguredToDoSo) { ++ static const uint8_t kTaggedCbor[] = { ++ 0xd8, 0x2a, 0x58, 0x25, 0x00, 0x01, 0x71, 0x12, 0x20, 0x69, 0xea, 0x07, ++ 0x40, 0xf9, 0x80, 0x7a, 0x28, 0xf4, 0xd9, 0x32, 0xc6, 0x2e, 0x7c, 0x1c, ++ 0x83, 0xbe, 0x05, 0x5e, 0x55, 0x07, 0x2c, 0x90, 0x26, 0x6a, 0xb3, 0xe7, ++ 0x9d, 0xf6, 0x3a, 0x36, 0x5b ++ }; ++ Reader::Config config; ++ config.parse_tags = true; ++ auto cbor = Reader::Read(kTaggedCbor, config); ++ EXPECT_TRUE(cbor.has_value()); ++ auto& v = cbor.value(); ++ EXPECT_TRUE(v.has_tag()); ++ EXPECT_EQ(v.GetTag(),42UL); ++ EXPECT_TRUE(v.is_bytestring()); ++ EXPECT_EQ(v.type(), Value::Type::BYTE_STRING); ++ auto& bytes = v.GetBytestring(); ++ EXPECT_EQ(bytes.size(), 37UL); ++ EXPECT_EQ(bytes.at(0), 0x00);//identity multibase (e.g. not base-encoded, bytes are themselves) ++ EXPECT_EQ(bytes.at(1), 0x01);//CID version 1 ++ EXPECT_EQ(bytes.at(2), 0x71);//codec = dag-cbor ++ EXPECT_EQ(bytes.at(3), 0x12);//multihash = 18 = sha2-256 ++ EXPECT_EQ(bytes.at(4), 0x20);//hash length = 32 bytes ++ EXPECT_EQ(bytes.at(5), 0x69);//first byte of hash digest ++ EXPECT_EQ(bytes.at(36),0x5b);//last byte of hash digest ++} + + } // namespace cbor diff --git a/chromium_edits/132.0.6779.0/components/cbor/values.cc.patch b/chromium_edits/132.0.6779.0/components/cbor/values.cc.patch new file mode 100644 index 00000000..fba23766 --- /dev/null +++ b/chromium_edits/132.0.6779.0/components/cbor/values.cc.patch @@ -0,0 +1,145 @@ +diff --git a/components/cbor/values.cc b/components/cbor/values.cc +index 303ac7fe300e3..7f796304e465a 100644 +--- a/components/cbor/values.cc ++++ b/components/cbor/values.cc +@@ -71,32 +71,34 @@ Value::Value(Type type) : type_(type) { + NOTREACHED_IN_MIGRATION(); + } + +-Value::Value(SimpleValue in_simple) +- : type_(Type::SIMPLE_VALUE), simple_value_(in_simple) { ++Value::Value(SimpleValue in_simple, uint64_t tag) ++ : type_(Type::SIMPLE_VALUE), simple_value_(in_simple), tag_(tag) { + CHECK(static_cast(in_simple) >= 20 && static_cast(in_simple) <= 23); + } + +-Value::Value(bool boolean_value) : type_(Type::SIMPLE_VALUE) { ++Value::Value(bool boolean_value, uint64_t tag) : type_(Type::SIMPLE_VALUE), tag_(tag) { + simple_value_ = boolean_value ? Value::SimpleValue::TRUE_VALUE + : Value::SimpleValue::FALSE_VALUE; + } + +-Value::Value(double float_value) +- : type_(Type::FLOAT_VALUE), float_value_(float_value) {} ++Value::Value(double float_value, uint64_t tag) ++ : type_(Type::FLOAT_VALUE), float_value_(float_value), tag_(tag) {} + +-Value::Value(int integer_value) +- : Value(base::checked_cast(integer_value)) {} ++Value::Value(int integer_value, uint64_t tag) ++ : Value(base::checked_cast(integer_value), tag) {} + +-Value::Value(int64_t integer_value) : integer_value_(integer_value) { ++Value::Value(int64_t integer_value, uint64_t tag) : integer_value_(integer_value), tag_(tag) { + type_ = integer_value >= 0 ? Type::UNSIGNED : Type::NEGATIVE; + } + +-Value::Value(base::span in_bytes) ++Value::Value(base::span in_bytes, uint64_t tag) + : type_(Type::BYTE_STRING), +- bytestring_value_(in_bytes.begin(), in_bytes.end()) {} ++ bytestring_value_(in_bytes.begin(), in_bytes.end()), ++ tag_(tag) ++ {} + +-Value::Value(base::span in_bytes, Type type) +- : type_(type), bytestring_value_(in_bytes.begin(), in_bytes.end()) { ++Value::Value(base::span in_bytes, Type type, uint64_t tag) ++ : type_(type), bytestring_value_(in_bytes.begin(), in_bytes.end()), tag_(tag) { + DCHECK(type_ == Type::BYTE_STRING || type_ == Type::INVALID_UTF8); + } + +@@ -122,7 +124,8 @@ Value::Value(std::string&& in_string, Type type) noexcept : type_(type) { + } + } + +-Value::Value(std::string_view in_string, Type type) : type_(type) { ++Value::Value(std::string_view in_string, Type type, uint64_t tag) ++: type_(type), tag_(tag) { + switch (type_) { + case Type::STRING: + new (&string_value_) std::string(); +@@ -138,16 +141,18 @@ Value::Value(std::string_view in_string, Type type) : type_(type) { + } + } + +-Value::Value(const ArrayValue& in_array) : type_(Type::ARRAY), array_value_() { ++Value::Value(const ArrayValue& in_array, uint64_t tag) ++: type_(Type::ARRAY), array_value_(), tag_(tag) { + array_value_.reserve(in_array.size()); + for (const auto& val : in_array) + array_value_.emplace_back(val.Clone()); + } + +-Value::Value(ArrayValue&& in_array) noexcept +- : type_(Type::ARRAY), array_value_(std::move(in_array)) {} ++Value::Value(ArrayValue&& in_array, uint64_t tag) noexcept ++ : type_(Type::ARRAY), array_value_(std::move(in_array)), tag_(tag) {} + +-Value::Value(const MapValue& in_map) : type_(Type::MAP), map_value_() { ++Value::Value(const MapValue& in_map, uint64_t tag) ++: type_(Type::MAP), map_value_(), tag_(tag) { + map_value_.reserve(in_map.size()); + for (const auto& it : in_map) + map_value_.emplace_hint(map_value_.end(), it.first.Clone(), +@@ -173,31 +178,36 @@ Value Value::Clone() const { + case Type::NONE: + return Value(); + case Type::INVALID_UTF8: +- return Value(bytestring_value_, Type::INVALID_UTF8); ++ return Value(bytestring_value_, Type::INVALID_UTF8, tag_); + case Type::UNSIGNED: + case Type::NEGATIVE: +- return Value(integer_value_); ++ return Value(integer_value_, tag_); + case Type::BYTE_STRING: +- return Value(bytestring_value_); ++ return Value(bytestring_value_, tag_); + case Type::STRING: +- return Value(string_value_); ++ return Value(string_value_, Type::STRING, tag_); + case Type::ARRAY: +- return Value(array_value_); ++ return Value(array_value_, tag_); + case Type::MAP: +- return Value(map_value_); ++ return Value(map_value_, tag_); + case Type::TAG: + NOTREACHED_IN_MIGRATION() << constants::kUnsupportedMajorType; + return Value(); + case Type::SIMPLE_VALUE: +- return Value(simple_value_); ++ return Value(simple_value_, tag_); + case Type::FLOAT_VALUE: +- return Value(float_value_); ++ return Value(float_value_, tag_); + } + + NOTREACHED_IN_MIGRATION(); + return Value(); + } + ++Value& Value::SetTag(uint64_t tag) noexcept { ++ tag_ = tag; ++ return *this; ++} ++ + Value::SimpleValue Value::GetSimpleValue() const { + CHECK(is_simple()); + return simple_value_; +@@ -263,9 +273,14 @@ const Value::BinaryValue& Value::GetInvalidUTF8() const { + return bytestring_value_; + } + ++uint64_t Value::GetTag() const { ++ CHECK(has_tag()); ++ return tag_; ++} ++ + void Value::InternalMoveConstructFrom(Value&& that) { + type_ = that.type_; +- ++ tag_ = that.tag_; + switch (type_) { + case Type::UNSIGNED: + case Type::NEGATIVE: diff --git a/chromium_edits/132.0.6779.0/components/cbor/values.h.patch b/chromium_edits/132.0.6779.0/components/cbor/values.h.patch new file mode 100644 index 00000000..5556e8c5 --- /dev/null +++ b/chromium_edits/132.0.6779.0/components/cbor/values.h.patch @@ -0,0 +1,79 @@ +diff --git a/components/cbor/values.h b/components/cbor/values.h +index d55369f1a71bf..7dabb368c51d6 100644 +--- a/components/cbor/values.h ++++ b/components/cbor/values.h +@@ -125,28 +125,29 @@ class CBOR_EXPORT Value { + + explicit Value(Type type); + +- explicit Value(SimpleValue in_simple); +- explicit Value(bool boolean_value); +- explicit Value(double in_float); ++ explicit Value(SimpleValue in_simple, uint64_t tag = NO_TAG); ++ explicit Value(bool boolean_value, uint64_t tag = NO_TAG); ++ explicit Value(double in_float, uint64_t tag = NO_TAG); + +- explicit Value(int integer_value); +- explicit Value(int64_t integer_value); ++ explicit Value(int integer_value, uint64_t tag = NO_TAG); ++ explicit Value(int64_t integer_value, uint64_t tag = NO_TAG); + explicit Value(uint64_t integer_value) = delete; + +- explicit Value(base::span in_bytes); ++ explicit Value(base::span in_bytes, uint64_t tag = NO_TAG); + explicit Value(BinaryValue&& in_bytes) noexcept; + + explicit Value(const char* in_string, Type type = Type::STRING); + explicit Value(std::string&& in_string, Type type = Type::STRING) noexcept; +- explicit Value(std::string_view in_string, Type type = Type::STRING); ++ explicit Value(std::string_view in_string, Type type = Type::STRING, uint64_t tag = NO_TAG); + +- explicit Value(const ArrayValue& in_array); +- explicit Value(ArrayValue&& in_array) noexcept; ++ explicit Value(const ArrayValue& in_array, uint64_t tag = NO_TAG); ++ explicit Value(ArrayValue&& in_array, uint64_t tag = NO_TAG) noexcept; + +- explicit Value(const MapValue& in_map); ++ explicit Value(const MapValue& in_map, uint64_t tag = NO_TAG); + explicit Value(MapValue&& in_map) noexcept; + + Value& operator=(Value&& that) noexcept; ++ Value& SetTag(uint64_t) noexcept; + + Value(const Value&) = delete; + Value& operator=(const Value&) = delete; +@@ -177,6 +178,7 @@ class CBOR_EXPORT Value { + bool is_string() const { return type() == Type::STRING; } + bool is_array() const { return type() == Type::ARRAY; } + bool is_map() const { return type() == Type::MAP; } ++ bool has_tag() const { return tag_ != NO_TAG; } + + // These will all fatally assert if the type doesn't match. + SimpleValue GetSimpleValue() const; +@@ -192,12 +194,13 @@ class CBOR_EXPORT Value { + const ArrayValue& GetArray() const; + const MapValue& GetMap() const; + const BinaryValue& GetInvalidUTF8() const; ++ uint64_t GetTag() const; + + private: + friend class Reader; + // This constructor allows INVALID_UTF8 values to be created, which only + // |Reader| and InvalidUTF8StringValueForTesting() may do. +- Value(base::span in_bytes, Type type); ++ Value(base::span in_bytes, Type type, uint64_t tag = NO_TAG); + + Type type_; + +@@ -211,6 +214,11 @@ class CBOR_EXPORT Value { + MapValue map_value_; + }; + ++ //This value specified as Invalid, ++ // used here to represent absence of TAG ++ constexpr static uint64_t NO_TAG = 0xFFFF; ++ uint64_t tag_ = NO_TAG; ++ + void InternalMoveConstructFrom(Value&& that); + void InternalCleanup(); + }; diff --git a/chromium_edits/132.0.6779.0/components/cbor/writer.cc.patch b/chromium_edits/132.0.6779.0/components/cbor/writer.cc.patch new file mode 100644 index 00000000..1950e174 --- /dev/null +++ b/chromium_edits/132.0.6779.0/components/cbor/writer.cc.patch @@ -0,0 +1,14 @@ +diff --git a/components/cbor/writer.cc b/components/cbor/writer.cc +index c4bfcfb602949..b92885a30971c 100644 +--- a/components/cbor/writer.cc ++++ b/components/cbor/writer.cc +@@ -47,6 +47,9 @@ bool Writer::EncodeCBOR(const Value& node, + if (max_nesting_level < 0) + return false; + ++ if (node.has_tag()) { ++ StartItem(Value::Type::TAG, node.GetTag()); ++ } + switch (node.type()) { + case Value::Type::NONE: { + StartItem(Value::Type::BYTE_STRING, 0); diff --git a/chromium_edits/132.0.6779.0/components/cbor/writer_unittest.cc.patch b/chromium_edits/132.0.6779.0/components/cbor/writer_unittest.cc.patch new file mode 100644 index 00000000..1acf5f7f --- /dev/null +++ b/chromium_edits/132.0.6779.0/components/cbor/writer_unittest.cc.patch @@ -0,0 +1,36 @@ +diff --git a/components/cbor/writer_unittest.cc b/components/cbor/writer_unittest.cc +index ee11e7cb86712..b8942f1829a37 100644 +--- a/components/cbor/writer_unittest.cc ++++ b/components/cbor/writer_unittest.cc +@@ -523,4 +523,31 @@ TEST(CBORWriterTest, OverlyNestedCBOR) { + EXPECT_FALSE(Writer::Write(Value(map), 4).has_value()); + } + ++TEST(CBORWriterTest, CanWriteTag) { ++ std::array content{ ++ 0x00, 0x01, 0x71, 0x12, 0x20, ++ 0x69, 0xea, 0x07, 0x40, 0xf9, ++ 0x80, 0x7a, 0x28, 0xf4, 0xd9, ++ 0x32, 0xc6, 0x2e, 0x7c, 0x1c, ++ 0x83, 0xbe, 0x05, 0x5e, 0x55, ++ 0x07, 0x2c, 0x90, 0x26, 0x6a, ++ 0xb3, 0xe7, 0x9d, 0xf6, 0x3a, ++ 0x36, 0x5b ++ }; ++ Value to_write(content); ++ to_write.SetTag(42); ++ auto result = Writer::Write(to_write); ++ EXPECT_TRUE(result.has_value()); ++ auto& bytes = result.value(); ++ EXPECT_EQ(bytes.size(), 41UL); ++ EXPECT_EQ(bytes.at(0), 0xd8); ++ EXPECT_EQ(bytes.at(1), 0x2a); ++ EXPECT_EQ(bytes.at(2), 0x58); ++ EXPECT_EQ(bytes.at(3), 0x25); ++ for (auto i = 0UL; i < content.size(); ++i) { ++ ASSERT_LT(i + 4UL, bytes.size()); ++ ASSERT_EQ(content.at(i), bytes.at(i+4UL)); ++ } ++} ++ + } // namespace cbor diff --git a/chromium_edits/132.0.6779.0/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch b/chromium_edits/132.0.6779.0/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch new file mode 100644 index 00000000..ee376ce1 --- /dev/null +++ b/chromium_edits/132.0.6779.0/components/open_from_clipboard/clipboard_recent_content_generic.cc.patch @@ -0,0 +1,13 @@ +diff --git a/components/open_from_clipboard/clipboard_recent_content_generic.cc b/components/open_from_clipboard/clipboard_recent_content_generic.cc +index 3683fadcc0914..440d4be132e5c 100644 +--- a/components/open_from_clipboard/clipboard_recent_content_generic.cc ++++ b/components/open_from_clipboard/clipboard_recent_content_generic.cc +@@ -20,7 +20,7 @@ + namespace { + // Schemes appropriate for suggestion by ClipboardRecentContent. + const char* kAuthorizedSchemes[] = { +- url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme, ++ url::kAboutScheme, url::kDataScheme, url::kHttpScheme, url::kHttpsScheme, "ipfs", "ipns" + // TODO(mpearson): add support for chrome:// URLs. Right now the scheme + // for that lives in content and is accessible via + // GetEmbedderRepresentationOfAboutScheme() or content::kChromeUIScheme diff --git a/chromium_edits/132.0.6779.0/net/dns/dns_config_service_linux.cc.patch b/chromium_edits/132.0.6779.0/net/dns/dns_config_service_linux.cc.patch new file mode 100644 index 00000000..fd7227a5 --- /dev/null +++ b/chromium_edits/132.0.6779.0/net/dns/dns_config_service_linux.cc.patch @@ -0,0 +1,18 @@ +diff --git a/net/dns/dns_config_service_linux.cc b/net/dns/dns_config_service_linux.cc +index 7aaf9fa5b0b78..5a9f5b5a70dd9 100644 +--- a/net/dns/dns_config_service_linux.cc ++++ b/net/dns/dns_config_service_linux.cc +@@ -276,11 +276,11 @@ bool IsNsswitchConfigCompatible( + // Ignore any entries after `kDns` because Chrome will fallback to the + // system resolver if a result was not found in DNS. + return true; +- ++ case NsswitchReader::Service::kResolve: ++ break; + case NsswitchReader::Service::kMdns: + case NsswitchReader::Service::kMdns4: + case NsswitchReader::Service::kMdns6: +- case NsswitchReader::Service::kResolve: + case NsswitchReader::Service::kNis: + RecordIncompatibleNsswitchReason( + IncompatibleNsswitchReason::kIncompatibleService, diff --git a/chromium_edits/132.0.6779.0/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch b/chromium_edits/132.0.6779.0/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch new file mode 100644 index 00000000..663fe49e --- /dev/null +++ b/chromium_edits/132.0.6779.0/third_party/blink/renderer/platform/weborigin/scheme_registry.cc.patch @@ -0,0 +1,15 @@ +diff --git a/third_party/blink/renderer/platform/weborigin/scheme_registry.cc b/third_party/blink/renderer/platform/weborigin/scheme_registry.cc +index e1bc209c337c5..6fbac29fcddfd 100644 +--- a/third_party/blink/renderer/platform/weborigin/scheme_registry.cc ++++ b/third_party/blink/renderer/platform/weborigin/scheme_registry.cc +@@ -68,8 +68,8 @@ class URLSchemesRegistry final { + // is considered secure. Additional checks are performed to ensure that + // other http pages are filtered out. + service_worker_schemes({"http", "https"}), +- fetch_api_schemes({"http", "https"}), +- allowed_in_referrer_schemes({"http", "https"}) { ++ fetch_api_schemes({"http", "https", "ipfs", "ipns"}), ++ allowed_in_referrer_schemes({"http", "https", "ipfs", "ipns"}) { + for (auto& scheme : url::GetCorsEnabledSchemes()) + cors_enabled_schemes.insert(scheme.c_str()); + for (auto& scheme : url::GetCSPBypassingSchemes()) { diff --git a/chromium_edits/132.0.6779.0/url/BUILD.gn.patch b/chromium_edits/132.0.6779.0/url/BUILD.gn.patch new file mode 100644 index 00000000..be4bfca8 --- /dev/null +++ b/chromium_edits/132.0.6779.0/url/BUILD.gn.patch @@ -0,0 +1,32 @@ +diff --git a/url/BUILD.gn b/url/BUILD.gn +index f22b73bc29f06..df36977322ec7 100644 +--- a/url/BUILD.gn ++++ b/url/BUILD.gn +@@ -5,6 +5,7 @@ + import("//build/buildflag_header.gni") + import("//testing/libfuzzer/fuzzer_test.gni") + import("//testing/test.gni") ++import("//third_party/ipfs_client/args.gni") + import("features.gni") + + import("//build/config/cronet/config.gni") +@@ -67,6 +68,7 @@ component("url") { + public_deps = [ + "//base", + "//build:robolectric_buildflags", ++ "//third_party/ipfs_client:ipfs_buildflags", + ] + + configs += [ "//build/config/compiler:wexit_time_destructors" ] +@@ -89,6 +91,11 @@ component("url") { + public_configs = [ "//third_party/jdk" ] + } + ++ if (enable_ipfs) { ++ sources += [ "url_canon_ipfs.cc" ] ++ deps += [ "//third_party/ipfs_client:ipfs_client" ] ++ } ++ + if (is_win) { + # Don't conflict with Windows' "url.dll". + output_name = "url_lib" diff --git a/chromium_edits/132.0.6779.0/url/url_canon.h.patch b/chromium_edits/132.0.6779.0/url/url_canon.h.patch new file mode 100644 index 00000000..0f667205 --- /dev/null +++ b/chromium_edits/132.0.6779.0/url/url_canon.h.patch @@ -0,0 +1,26 @@ +diff --git a/url/url_canon.h b/url/url_canon.h +index 3b84d686ba0f0..c18cb750c6de1 100644 +--- a/url/url_canon.h ++++ b/url/url_canon.h +@@ -855,6 +855,21 @@ bool CanonicalizeMailtoURL(const char16_t* spec, + CanonOutput* output, + Parsed* new_parsed); + ++COMPONENT_EXPORT(URL) ++bool CanonicalizeIpfsURL(std::string_view spec, ++ const Parsed& parsed, ++ SchemeType scheme_type, ++ CharsetConverter* query_converter, ++ CanonOutput* output, ++ Parsed* new_parsed); ++COMPONENT_EXPORT(URL) ++bool CanonicalizeIpfsURL(std::basic_string_view spec, ++ const Parsed& parsed, ++ SchemeType scheme_type, ++ CharsetConverter* query_converter, ++ CanonOutput* output, ++ Parsed* new_parsed); ++ + // Part replacer -------------------------------------------------------------- + + // Internal structure used for storing separate strings for each component. diff --git a/chromium_edits/132.0.6779.0/url/url_canon_ipfs.cc b/chromium_edits/132.0.6779.0/url/url_canon_ipfs.cc new file mode 100644 index 00000000..e40732ee --- /dev/null +++ b/chromium_edits/132.0.6779.0/url/url_canon_ipfs.cc @@ -0,0 +1,54 @@ +#include "url_canon_internal.h" + +#include +#include + +#include + +bool url::CanonicalizeIpfsURL(std::string_view spec, + const Parsed& parsed, + SchemeType scheme_type, + CharsetConverter* charset_converter, + CanonOutput* output, + Parsed* output_parsed) { + if (spec.size() < 1) { + return false; + } + if ( parsed.host.len < 1 ) { + return false; + } + auto cid_str = spec.substr( parsed.host.begin, static_cast(parsed.host.len) ); + auto cid = ipfs::Cid(cid_str); + if ( !cid.valid() ) { + cid = ipfs::id_cid::forText( std::string{cid_str} + " is not a valid CID." ); + } + auto as_str = cid.to_string(); + if ( as_str.empty() ) { + return false; + } + std::string stdurl{ spec.substr(0UL, static_cast(parsed.host.begin)) }; + stdurl.append( as_str ); + spec.remove_prefix(parsed.host.end()); + stdurl.append(spec); + auto len = static_cast(stdurl.size()); + Parsed parsed_input; + ParseStandardURL(stdurl.data(), len, &parsed_input); + return CanonicalizeStandardURL( + stdurl.data(), + parsed_input, + scheme_type, + charset_converter, + output, output_parsed + ); +} +bool url::CanonicalizeIpfsURL(std::basic_string_view spec, + const Parsed& parsed, + SchemeType scheme_type, + CharsetConverter* query_converter, + CanonOutput* output, + Parsed* new_parsed) { + RawCanonOutput<2048> as8; + ConvertUTF16ToUTF8(spec.data(), spec.size(), &as8); + return CanonicalizeIpfsURL({as8.data(), as8.length()}, parsed, scheme_type, + query_converter, output, new_parsed); +} diff --git a/chromium_edits/132.0.6779.0/url/url_util.cc.patch b/chromium_edits/132.0.6779.0/url/url_util.cc.patch new file mode 100644 index 00000000..988797b0 --- /dev/null +++ b/chromium_edits/132.0.6779.0/url/url_util.cc.patch @@ -0,0 +1,45 @@ +diff --git a/url/url_util.cc b/url/url_util.cc +index ce5225e121f5d..79e33208f728e 100644 +--- a/url/url_util.cc ++++ b/url/url_util.cc +@@ -76,6 +76,8 @@ struct SchemeRegistry { + std::vector referrer_schemes = { + {kHttpsScheme, SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION}, + {kHttpScheme, SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION}, ++ {"ipfs", SCHEME_WITH_HOST}, ++ {"ipns", SCHEME_WITH_HOST}, + }; + + // Schemes that do not trigger mixed content warning. +@@ -84,6 +86,8 @@ struct SchemeRegistry { + kWssScheme, + kDataScheme, + kAboutScheme, ++ {"ipfs", SCHEME_WITH_HOST}, ++ {"ipns", SCHEME_WITH_HOST}, + }; + + // Schemes that normal pages cannot link to or access (i.e., with the same +@@ -105,6 +109,8 @@ struct SchemeRegistry { + kHttpsScheme, + kHttpScheme, + kDataScheme, ++ {"ipfs", SCHEME_WITH_HOST}, ++ {"ipns", SCHEME_WITH_HOST}, + }; + + // Schemes that can be used by web to store data (local storage, etc). +@@ -308,7 +314,12 @@ bool DoCanonicalize(const CHAR* spec, + success = CanonicalizeFileSystemURL( + spec, ParseFileSystemURL(std::basic_string_view(spec, spec_len)), + charset_converter, output, output_parsed); +- ++ } else if (DoCompareSchemeComponent(spec, scheme, "ipfs")) { ++ auto spec_view = std::basic_string_view(spec, spec_len); ++ // Switch multibase away from case-sensitive ones before continuing canonicalization. ++ auto parsed_input = ParseStandardURL(spec_view); ++ success = CanonicalizeIpfsURL(spec_view, parsed_input, scheme_type, ++ charset_converter, output, output_parsed); + } else if (DoIsStandard(spec, scheme, &scheme_type)) { + // All "normal" URLs. + success = CanonicalizeStandardURL( diff --git a/cmake/AppleClang.cmake b/cmake/AppleClang.cmake index 3e0ba35c..0764dc38 100644 --- a/cmake/AppleClang.cmake +++ b/cmake/AppleClang.cmake @@ -1,2 +1,2 @@ -set(CHROMIUM_COMPILER_FLAGS -nostdinc++ -fno-rtti) + set(WARNING_FLAGS -Wall -Wextra -Werror=return-type -Wno-error=enum-constexpr-conversion ) diff --git a/cmake/Clang.cmake b/cmake/Clang.cmake index 3e0ba35c..0764dc38 100644 --- a/cmake/Clang.cmake +++ b/cmake/Clang.cmake @@ -1,2 +1,2 @@ -set(CHROMIUM_COMPILER_FLAGS -nostdinc++ -fno-rtti) + set(WARNING_FLAGS -Wall -Wextra -Werror=return-type -Wno-error=enum-constexpr-conversion ) diff --git a/cmake/CodeCoverage.cmake b/cmake/CodeCoverage.cmake index 00867801..946e4a48 100644 --- a/cmake/CodeCoverage.cmake +++ b/cmake/CodeCoverage.cmake @@ -271,15 +271,21 @@ function(setup_target_for_coverage_lcov) ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} -directory . -b ${BASEDIR} --zerocounters ) # Create baseline to make sure untouched files show up in the report - set(LCOV_BASELINE_CMD ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} -c --no-external -i -d . -b ${BASEDIR} -o ${Coverage_NAME}.base ) + set(LCOV_BASELINE_CMD ${LCOV_PATH} ${Coverage_LCOV_ARGS} + --gcov-tool ${GCOV_PATH} -c --no-external -i -d . + --ignore-errors mismatch + --ignore-errors unused + -b ${BASEDIR} + -o ${Coverage_NAME}.base ) # Run tests set(LCOV_EXEC_TESTS_CMD ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS} ) # Capturing lcov counters and generating report set(LCOV_CAPTURE_CMD - ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} --directory . -b - ${BASEDIR} --capture --no-external --output-file ${Coverage_NAME}.capture + ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} --directory . + -b ${BASEDIR} --capture --no-external --ignore-errors mismatch + --output-file ${Coverage_NAME}.capture ) # add baseline counters set(LCOV_BASELINE_COUNT_CMD @@ -296,8 +302,8 @@ function(setup_target_for_coverage_lcov) ${GENHTML_PATH} ${GENHTML_EXTRA_ARGS} ${Coverage_GENHTML_ARGS} - --rc genhtml_hi_limit=88 - --rc genhtml_med_limit=74 + --rc genhtml_hi_limit=89 + --rc genhtml_med_limit=78 --prefix "${BASEDIR}" -o ${Coverage_NAME} ${Coverage_NAME}.info diff --git a/cmake/GNU.cmake b/cmake/GNU.cmake index ec80247a..a91ac14d 100644 --- a/cmake/GNU.cmake +++ b/cmake/GNU.cmake @@ -1,3 +1,3 @@ -set(CHROMIUM_COMPILER_FLAGS -nostdinc++ -fno-rtti) + set(WARNING_FLAGS -Wall -Wextra -Wpedantic -Werror=switch-enum -Werror=return-type -Werror=reorder -Werror=implicit-fallthrough -Werror=missing-field-initializers -fmax-errors=3) set(coverage_debug_flags -fno-inline -g3 -ggdb3 -O0 ) diff --git a/cmake/MSVC.cmake b/cmake/MSVC.cmake index 41670152..6f424760 100644 --- a/cmake/MSVC.cmake +++ b/cmake/MSVC.cmake @@ -1,2 +1,2 @@ -set(CHROMIUM_COMPILER_FLAGS "TODO") + set(WARNING_FLAGS /W4) diff --git a/cmake/inc_link.py b/cmake/inc_link.py index 6bb31369..6eef1418 100755 --- a/cmake/inc_link.py +++ b/cmake/inc_link.py @@ -6,7 +6,7 @@ from glob import glob import os from os import listdir, readlink, set_blocking, symlink -from os.path import basename, dirname, exists, getmtime, isdir, isfile, islink, join, pathsep, relpath, splitext +from os.path import dirname, exists, isdir, isfile, islink, join, relpath, splitext from subprocess import DEVNULL, Popen, PIPE, TimeoutExpired from sys import executable, stderr @@ -124,23 +124,18 @@ def eval_line(self, line) -> bool: unfound_count += 1 return False + preempt = False + + def search() -> bool: global link_count global unfound_count global preempt link_count = 0 unfound_count = 0 - # ipfs_client_gen = join(gen_dir,'third_party','ipfs_client') - # for h in listdir(ipfs_client_gen): - # if h.endswith('.h'): - # source = join(ipfs_client_gen, h) - # target = join(inc_link, 'third_party', 'ipfs_client', h) - # if isfile(source) and not exists(target): - # print("linked our gen file ",source,target) - # symlink(source, target) - # link_count += 1 - compile_commands = json.load(open(join(build_dir,'compile_commands.json'))) + comp_comm_json = join(build_dir, 'compile_commands.json') + compile_commands = json.load(open(comp_comm_json, encoding='utf-8')) commands = [] for command_obj in compile_commands: artifact = command_obj['output'] @@ -196,6 +191,7 @@ def search() -> bool: print('Linked',link_count,'new headers. Trouble with',unfound_count,'others.',file=stderr) return link_count > unfound_count + def flesh_out() -> bool: existing = glob(inc_link+'/**/*.h',recursive=True) existing_dir_map = set() @@ -207,8 +203,8 @@ def flesh_out() -> bool: if not isdir(f): continue for entry in listdir(f): - source = join(f,entry) - target = join(t,entry) + source = join(f, entry) + target = join(t, entry) if exists(target): continue if isfile(source) and splitext(entry)[-1] == '.h': diff --git a/cmake/patch.py b/cmake/patch.py index e50db11c..8a40184b 100755 --- a/cmake/patch.py +++ b/cmake/patch.py @@ -28,7 +28,7 @@ verbose('Installed requests because of', ex) -VERSION_CLOSE_ENOUGH = 30113 +VERSION_CLOSE_ENOUGH = 30119 LARGE_INT = 9876543210 here = dirname(__file__) @@ -189,6 +189,13 @@ def apply(self): verbose(f"{to_path} already copied") verbose("Done patching") + @staticmethod + def edit_evidence(text: str): + for tok in ['ipfs', 'ReadTagContent', 'SetTag(']: + if tok in text: + return True + return False + def check_patch(self, patch_path: str, relative: str, target_path: str): if 0 == self.git( ["apply", "--check", "--reverse", "--verbose", patch_path], @@ -204,11 +211,12 @@ def check_patch(self, patch_path: str, relative: str, target_path: str): else: with open(join(self.csrc, src)) as target_file: text = target_file.read() - if "ipfs" in text or "ReadTagContent" in text or "SetTag(" in text: + if self.edit_evidence(text): print( - "Patch file", + "Patch file ", patch_path, - "may have already been applied, or otherwise hand-edited. Ignoring.", + " may have already been applied, ", + "or otherwise hand-edited. Ignoring.", ) else: print( @@ -224,19 +232,17 @@ def check_patch(self, patch_path: str, relative: str, target_path: str): def git(self, args: list[str], result: Result) -> str: a = [self.gbin, "-C", self.csrc] + args verbose("Running", a) - match result: - case Result.RawOutput: - return check_output(a, text=True) - case Result.StrippedOutput: - return check_output(a, text=True).strip() - case Result.OrDie: - check_call(a) - case Result.ExitCode: - return call(a) - case Result.ExitCodeOnly: - return call(a, stdout=DEVNULL, stderr=DEVNULL) - case _: - raise RuntimeError("result type not handled") + if result == Result.RawOutput: + return check_output(a, text=True) + if result == Result.StrippedOutput: + return check_output(a, text=True).strip() + if result == Result.OrDie: + return check_call(a) + if result == Result.ExitCode: + return call(a) + if result == Result.ExitCodeOnly: + return call(a, stdout=DEVNULL, stderr=DEVNULL) + raise RuntimeError("result type not handled") def tag_name(self) -> str: return self.git(["describe", "--tags", "--abbrev=0"], Result.Output) @@ -308,7 +314,7 @@ def release_versions(self, channel, pfrm=None): return self.up_rels[key] parms = {"platform": pfrm, "channel": channel} chrom_url = "https://chromiumdash.appspot.com/fetch_releases" - resp = requests.get(url=chrom_url, params=parms) + resp = requests.get(url=chrom_url, params=parms, timeout=999) result = list(map(lambda x: (x["time"] / 1000, x["version"]), resp.json())) elec_url = "https://raw.githubusercontent.com/electron/electron/main/DEPS" resp = requests.get(url=elec_url) @@ -411,11 +417,11 @@ def check(version, version_set, s, close): try: when, version = self.release_versions(channel, pfrm)[0] s = f"{channel}-{pfrm}-{when}" - close = VERSION_CLOSE_ENOUGH * (ci + 0.001) * (pi + 1) + close = VERSION_CLOSE_ENOUGH * (ci + 1) * (pi + 1) check(version, version_set, s, close) except IndexError: pass # One may assume this is Linux Extended - close = VERSION_CLOSE_ENOUGH / 100 + close = VERSION_CLOSE_ENOUGH for ev, e in self.electron_versions().items(): close += VERSION_CLOSE_ENOUGH * 2 check(e, version_set, f"electron-{ev}", close) @@ -514,22 +520,23 @@ def list_ood(self, to_check: list[str], sense: bool, both: bool = False): if __name__ == "__main__": + chromium_src_dir = os.environ['CHROMIUM_SOURCE_TREE'] if len(argv) < 2: print("Give an argument to indicate what you'd like to do.") elif argv[1] == "apply": - Patcher("/mnt/big/lbl/code/chromium/src", "git", "Debug").apply() + Patcher(chromium_src_dir, "git", "Debug").apply() elif argv[1] == "rec": print(osname()) BT = "Release" if len(argv) == 2 else argv[2] - print(Patcher("/mnt/big/lbl/code/chromium/src", "git", BT).recommend()) + print(Patcher(chromium_src_dir, "git", BT).recommend()) elif argv[1] == "missing": missing = Patcher( - "/mnt/big/lbl/code/chromium/src", "git", "Debug" + chromium_src_dir, "git", "Debug" ).unavailable() for m in missing: print(m) elif argv[1] == "releases": - per = Patcher("/mnt/big/lbl/code/chromium/src", "git", "Debug") + per = Patcher(chromium_src_dir, "git", "Debug") for chan in ["Dev", "Beta", "Stable", "Extended"]: for osn in ["Linux", "Mac", "Windows"]: rels = per.release_versions(chan, osn) @@ -543,23 +550,23 @@ def list_ood(self, to_check: list[str], sense: bool, both: bool = False): n = per.newest() print("Development at:", n[1], f"({ctime(n[2])})") elif argv[1] == "available": - pr = Patcher("/mnt/big/lbl/code/chromium/src", "git", "Debug") + pr = Patcher(chromium_src_dir, "git", "Debug") print(list(pr.available())) print(pr.edir) elif argv[1] == "old": - pr = Patcher("/mnt/big/lbl/code/chromium/src", "git", "Debug") + pr = Patcher(chromium_src_dir, "git", "Debug") if len(argv) > 2: pr.list_ood(argv[2:], True) else: pr.list_ood(list(pr.available()), True) elif argv[1] == "new": - pr = Patcher("/mnt/big/lbl/code/chromium/src", "git", "Debug") + pr = Patcher(chromium_src_dir, "git", "Debug") if len(argv) > 2: pr.list_ood(argv[2:], False) else: pr.list_ood(list(pr.available()), False) elif argv[1] == "oldnew": - pr = Patcher("/mnt/big/lbl/code/chromium/src", "git", "Debug") + pr = Patcher(chromium_src_dir, "git", "Debug") pr.list_ood(list(pr.available()), False, True) elif argv[1] == "git": pr = Patcher(realpath(join(dirname(__file__), "..")), "git", "Debug") diff --git a/cmake/recent-electron.txt b/cmake/recent-electron.txt index dc7b54ad..3e932fe8 100644 --- a/cmake/recent-electron.txt +++ b/cmake/recent-electron.txt @@ -1 +1 @@ -33 \ No newline at end of file +34 \ No newline at end of file diff --git a/component/cache_requestor.cc b/component/cache_requestor.cc index dc1d69c8..0bc307ce 100644 --- a/component/cache_requestor.cc +++ b/component/cache_requestor.cc @@ -55,7 +55,7 @@ auto Self::handle(RequestPtr req) -> HandleOutcome { return HandleOutcome::NOT_HANDLED; } Task task; - task.key = req->main_param; // req->Key(); + task.key = req->root_component(); task.request = req; StartFetch(task, net::MAXIMUM_PRIORITY); return HandleOutcome::PENDING; diff --git a/component/chromium_http.h b/component/chromium_http.h index 761e3232..0bf5d78c 100644 --- a/component/chromium_http.h +++ b/component/chromium_http.h @@ -10,6 +10,8 @@ class URLLoaderFactory; } // namespace network::mojom namespace ipfs { +/*! Using Chromium's URLLoader mechanisms to issue HTTP requests + */ class ChromiumHttp : public ctx::HttpApi { raw_ptr loader_factory_ = nullptr; diff --git a/doc/0.0.1.2_blog.md b/doc/0.0.1.2_blog.md index e747c708..7a87b3eb 100644 --- a/doc/0.0.1.2_blog.md +++ b/doc/0.0.1.2_blog.md @@ -1,61 +1,61 @@ -# IPFS-Chromium Version 0.0.1.2 Released +# IPFS-Chromium updates: New Release, IPFS-Electron, Standardization -Recently we cut a new release of [IPFS-Chromium](https://github.com/little-bear-labs/ipfs-chromium/), -so this is a good milestone to update on what's been going on since the [last time](https://blog.ipfs.tech/2023-05-multigateway-chromium-client/) -we discussed this project. +It's well past time to talk about things that have happened since the +[last time](https://blog.ipfs.tech/2023-05-multigateway-chromium-client/) +you heard about this project. -## WICG Discussion +## IPFS-Chromium Version 0.0.1.2 Released -The very beginning of a discussion about standarizing IPFS functionality in browsers, -of which this would be one implementation, is started over [here](https://github.com/WICG/proposals/issues/143). +Recently we cut a new release of +[IPFS-Chromium](https://github.com/little-bear-labs/ipfs-chromium/), +which has some more steps along the way to being a practical approach to native multi-[trustless-gateway](https://specs.ipfs.tech/http-gateways/trustless-gateway/) support for `ipfs://` and `ipns://` URLs. -Naturally the suggestion isn't to adopt everything we've done here exactly as-is, -but to look for a reasonable subset of functionality that would give a good level of interoperability. -Feel free to read the [explainer](https://little-bear-labs.github.io/ipfs-chromium/md_doc_explainer.html) -on what we arrived at, and join in the discussion. +### Enhancements -## IPFS-Electron +#### Feature-control switches -While it may be [unlikely](https://github.com/electron/electron/issues/41539) to get IPFS -support in vanilla Electron by default, there are a number of use cases for slightly modified -[spins](TODO - link to blog post) on Electron, and if we get those -[extension points](https://github.com/electron/electron/issues/42455) IPFS-enabled Electron could -be one. +For those who might consider dipping a toe rather than diving head-first. -And with that in mind, this repo now builds an IPFS-enabled electron as well, if you're using -[this](https://github.com/little-bear-labs/ipfs-electron) fork of Electron rather than the -upstream where the extension points are not-yet-adopted. You can find some build artifacts in the -release if you'd like to give it a try without building it yourself. +* Chromium build flag ( `ENABLE_IPFS` ) so a codebase containing these changes can still be built without IPFS support, to ease adoption. +* A feature flag, ("Enable IPFS") so Chromium built with this (and the build flag on) can still have IPFS turned off with about://flags if the user wishes. -## Enhancements +#### IPFS Features -As mentioned previously, this is an experimental proof-of-concept. There are features from some corners of the IPFS ecosystem not everyone needs, naturally they did not get prioritized at first. -Now, we've implemented some of that, making things more complete. -Also, we've added conveniences that make adoption easier, -and some considerations for the end user. +Now we've implemented some more features, making things more complete. * Handling [inline CIDs](https://github.com/ipfs/specs/blob/6c70fc240fb14f3022177af55f1dcbe1ab8f35c6/UNIXFS.md#deduplication-and-inlining) locally. -* Using [delegated routing](https://specs.ipfs.tech/routing/http-routing-v1/#get-routing-v1-providers-cid) gateway API to discover additional gateways -* Support for the environment variable [IPFS_GATEWAY](https://curl.se/docs/ipfs.html), though this project supports a superset: it's a whitespace-delimited list of gateways instead of just 1. * [DAG-JSON](https://ipld.io/docs/codecs/known/dag-json/) * [DAG-CBOR](https://ipld.io/docs/codecs/known/dag-cbor/) -* Partial ([dag-scope=entity](https://specs.ipfs.tech/http-gateways/trustless-gateway/#dag-scope-request-query-parameter)) CAR requests, for fetching multiple blocks in one round trip. * Support for [base-16](https://github.com/multiformats/multibase?tab=readme-ov-file#multibase-table) URLs and a fix for dealing with unsupported bases (no longer crashes the process). * Handling of content root [_redirects](https://specs.ipfs.tech/http-gateways/web-redirects-file/) * Handling [UnixFS symbolic links](https://github.com/ipfs/specs/blob/9131a7cfb56bf2ef4fb916feec53836c75ba1a05/src/unixfs-data-format.md#symlink-type) -* Some response headers for use in devtools, including some Server-Timing -* Chromium build flag, so a codebase containing these changes can still be built without IPFS support, to ease adoption. -* A feature flag, so Chromium built with this (and the build flag on) can still have IPFS turned off with about://flags if the user wishes. -* Cache entries for IPNS records expire based on the date contained in the record -* Proper URL canonicalization for IPFS URLs (switching multibase) so that it surives lowercasing. +* Preview page for a sharded directory that contains no index.html. It's ugly, but usable. Screenshots of the top and bottom of such a page, before "Load more" is clicked: + +![wiki_top](https://hackmd.io/_uploads/BkJDxB31yg.png) + +![wiki_end](https://hackmd.io/_uploads/Sk6Pxrn1yl.png) + +#### Gateway interaction improvements + +* Using [delegated routing](https://specs.ipfs.tech/routing/http-routing-v1/#get-routing-v1-providers-cid) gateway API to discover additional gateways +* Partial ([dag-scope=entity](https://specs.ipfs.tech/http-gateways/trustless-gateway/#dag-scope-request-query-parameter)) CAR requests, for fetching multiple blocks in one round trip. +* Support for the environment variable [IPFS_GATEWAY](https://curl.se/docs/ipfs.html), though this project supports a superset: it's a whitespace-delimited list of gateways instead of just 1. * Gateway rate (soft) limits persisted to user preferences -* Some user preferences where performance trades off against privacy concerns. -* Preview page for a sharded directory that contains no index.html. It's ugly, but usable. * Option to fallback to gateway for DNSLink-like roots. Helps when there's a DNS problem or if you need a resolver your system doesn't use but the gateway does, like ENS. -## Dev & maintenance updates +#### Browser features + +* Some response headers for use in devtools, including some [Server-Timing](https://specs.ipfs.tech/http-gateways/path-gateway/#server-timing-response-header) keys. +* Cache entries for IPNS records expire based on the date contained in the record +* Proper URL canonicalization for IPFS URLs (switching multibase) so that it surives lowercasing. +* Some user preferences where performance trades off against privacy concerns. + - Controlling whether the [Routing V1 API](https://specs.ipfs.tech/routing/http-routing-v1/) is used to discover additional gateways + - If so, are http:// (insecure) gateways included? + - Whether DNSLink can fallback to gateway resolution when `DNSClient` is unavailable or unsuccessful (but requires trusting your gateways to resolve honestly) + +### Dev & maintenance updates The basics. They always gotta get done. @@ -65,3 +65,49 @@ The basics. They always gotta get done. * Patches for new versions of Chromium. * CI for library artifacts in releases (see ipfs-client* [here](https://github.com/little-bear-labs/ipfs-chromium/releases/latest)) * A bug fix in default URL escaping of ipfs::Client (not in Chromium) + +## IPFS-Electron + +![persianroomguardianinelectron](https://hackmd.io/_uploads/HJpxkfLlA.png) + +While it may be [unlikely](https://github.com/electron/electron/issues/41539) to get IPFS +support in vanilla Electron by default, there are a number of use cases for slightly modified +[spins](https://littlebearlabs.io/perspectives/electron-spins-a-special-case-of-chromium-mods) on Electron, and if we get those +[extension points](https://github.com/electron/electron/issues/42455) IPFS-enabled Electron could +be one. + +And with that in mind, this repo now builds an IPFS-enabled electron as well, if you're using +[this](https://github.com/little-bear-labs/ipfs-electron) fork of Electron rather than the +upstream where the extension points are not-yet-adopted. + +You can find some build artifacts +[in the release](https://github.com/little-bear-labs/ipfs-chromium/releases/tag/0.0.1.2) +if you'd like to give it a try without building it yourself. + +_In particular, one could download the equivalent of_ `dist.zip`: +* [ipfs-ipfs-electron.linux.zip](https://github.com/little-bear-labs/ipfs-chromium/releases/download/0.0.1.2/ipfs-electron.linux.zip) +* [ipfs-ipfs-electron.win.zip](https://github.com/little-bear-labs/ipfs-chromium/releases/download/0.0.1.2/ipfs-electron.win.zip) +* [ipfs-ipfs-electron.mac.zip](https://github.com/little-bear-labs/ipfs-chromium/releases/download/0.0.1.2/ipfs-electron.mac.zip) +* [ipfs-electron.framework.mac.zip](https://github.com/little-bear-labs/ipfs-chromium/releases/download/0.0.1.2/ipfs-electron.framework.mac.zip) + +## WICG Discussion + +The very beginning of a discussion about standarizing IPFS functionality in browsers, +of which this would be one implementation, is started over [here](https://github.com/WICG/proposals/issues/143). + +Naturally the suggestion isn't to adopt everything we've done here exactly as-is, +but to look for a reasonable subset of functionality that would give a good level of interoperability. +Feel free to read the [explainer](https://little-bear-labs.github.io/ipfs-chromium/md_doc_explainer.html) +on what we arrived at, and join in the discussion. + +# Next Steps + +The future is yet to be written. +Where in the ecosystem would you like to see native support for multi-gateway IPFS clients? +Feel free to comment on +the [WICG ticket](https://github.com/WICG/proposals/issues/143) + for comment on web standardization, + the [Chromium ticket](https://issues.chromium.org/issues/40909350), + the [Electron ticket](https://github.com/electron/electron/issues/42455), + or open an [issue on IPFS-Chromium](https://github.com/little-bear-labs/ipfs-chromium/issues) + for your own ideas & concerns. diff --git a/library/.clang-tidy b/library/.clang-tidy index 40eb32c2..b309fa8c 100644 --- a/library/.clang-tidy +++ b/library/.clang-tidy @@ -1,41 +1,27 @@ - Checks: '-*, - bugprone-a*, - bugprone-b*, - bugprone-dangling-handle, - bugprone-forward-declaration-namespace, - bugprone-inaccurate-erase, - bugprone-string-constructor, - bugprone-string-integer-assignment, - bugprone-undefined-memory-manipulation, - bugprone-unique-ptr-array-mismatch, - bugprone-unused-raii, - bugprone-use-after-move, - bugprone-virtual-near-miss, - google-build-explicit-make-pair, - google-default-arguments, - google-explicit-constructor, - google-objc-avoid-nsobject-new, - google-upgrade-googletest-case, - misc-misleading-identifier, - misc-homoglyph, - modernize-avoid-bind, - modernize-concat-nested-namespaces, - modernize-loop-convert, - modernize-make-shared, - modernize-make-unique, - modernize-redundant-void-arg, - modernize-replace-random-shuffle, - modernize-shrink-to-fit, - modernize-use-bool-literals, - modernize-use-default-member-init, - modernize-use-emplace, - modernize-use-equals-default, - modernize-use-equals-delete, - modernize-use-noexcept, - modernize-use-nullptr, - modernize-use-override, - modernize-use-transparent-functors, - readability-redundant-member-init' +# bugprone-unc* takes too long +# misc-include-cleaner finds includes that are directly used, thinks they're not, and removes them breaking code +# readability-else-after-return is oftentimes not more readable +# reability-named-parameter complains about parameters whose names are commented out because they're unused +# readability-qualified-auto can cause iterators (especially into std::array) to be declared as auto* which is both generally wrong, but also causes it to not build when array is defined slightly differently e.g. when the iterator is std::__wrap_iter + Checks: 'bugpr*, + -bugprone-unc*, + -bugprone-m*, + -bugprone-n*, + -bugprone-o*, + -bugprone-p*, + -bugprone-r*, + -bugprone-s*, + -bugprone-t*, + -bugprone-und*, + -bugprone-unh*, + -bugprone-uni*, + misc-*, + -misc-include-cleaner, + moder*, + reada*, + -readability-else-after-return, + -readability-named-parameter, + -readability-qualified-auto' CheckOptions: - key: bugprone-assert-side-effect.AssertMacros value: assert,DCHECK @@ -54,5 +40,7 @@ # https://groups.google.com/a/chromium.org/g/cxx/c/noMMTNYiM0w . - key: modernize-use-emplace.IgnoreImplicitConstructors value: 1 -WarningsAsErrors: '*' +CompileFlags: + Add: -Wno-unknown-warning-option + Remove: -fprofile-abs-path ... diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 17ad2739..470e3dc1 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -258,10 +258,9 @@ if(GTest_FOUND AND IN_WORKSPACE) endif() if(LCOV_PATH) setup_target_for_coverage_lcov( - NAME cov - DEPENDENCIES run_tests - EXECUTABLE $ - EXCLUDE ${unit_test_sources} ${pb_gen} + NAME cov + DEPENDENCIES run_tests + EXECUTABLE $ ) else() message(WARNING "Cannot provide coverage report without lcov") diff --git a/library/conanfile.py b/library/conanfile.py index e2c6726c..0d520d32 100644 --- a/library/conanfile.py +++ b/library/conanfile.py @@ -50,7 +50,6 @@ class IpfsChromium(ConanFile): exports = 'version.txt' package_type = 'static-library' - def generate(self): tc = CMakeToolchain(self, 'Ninja') tc.generate() @@ -60,9 +59,9 @@ def generate(self): def build(self): cmake = CMake(self) if self.settings.compiler.cppstd: - stdver = self.settings.compiler.cppstd + stdver = self.settings.compiler.cppstd else: - stdver = 20 + stdver = 20 cmake.configure(variables={ "CXX_VERSION": stdver, "INSIDE_CONAN": True diff --git a/library/include/ipfs_client/client.h b/library/include/ipfs_client/client.h index 1942b213..6bdb1bf4 100644 --- a/library/include/ipfs_client/client.h +++ b/library/include/ipfs_client/client.h @@ -45,6 +45,8 @@ class Client : public std::enable_shared_from_this { using MimeTypeDeduction = std::function< std::string(std::string, std::string_view, std::string const&)>; using UrlUnescaping = std::function; + + //TODO this should probably with GatewayConfig stuff using DnslinkFallbackSwitch = std::function; Client(); diff --git a/library/include/ipfs_client/crypto/identity_hasher.h b/library/include/ipfs_client/crypto/identity_hasher.h new file mode 100644 index 00000000..b89277e2 --- /dev/null +++ b/library/include/ipfs_client/crypto/identity_hasher.h @@ -0,0 +1,14 @@ +#ifndef IDENTITY_HASHER_H +#define IDENTITY_HASHER_H + +#include "hasher.h" + +namespace ipfs::crypto { +class IdentityHasher final : public Hasher { + std::optional> hash(ByteView bytes) { + return std::vector(bytes.begin(), bytes.end()); + } +}; +} + +#endif // IDENTITY_HASHER_H diff --git a/library/include/ipfs_client/ctx/dns_txt_lookup.cc b/library/include/ipfs_client/ctx/dns_txt_lookup.cc deleted file mode 100644 index 4f926e60..00000000 --- a/library/include/ipfs_client/ctx/dns_txt_lookup.cc +++ /dev/null @@ -1 +0,0 @@ -#include "dns_txt_lookup.h" diff --git a/library/include/ipfs_client/ctx/dns_txt_lookup.h b/library/include/ipfs_client/ctx/dns_txt_lookup.h index 3c4285cf..7da94ca6 100644 --- a/library/include/ipfs_client/ctx/dns_txt_lookup.h +++ b/library/include/ipfs_client/ctx/dns_txt_lookup.h @@ -17,7 +17,7 @@ class DnsTxtLookup { DnsTextResultsCallback, DnsTextCompleteCallback) = 0; - virtual ~DnsTxtLookup() noexcept {} + virtual ~DnsTxtLookup() noexcept; }; } // namespace ipfs::ctx diff --git a/library/include/ipfs_client/ctx/transitory_gateway_config.h b/library/include/ipfs_client/ctx/transitory_gateway_config.h index f5aa129e..23958fb3 100644 --- a/library/include/ipfs_client/ctx/transitory_gateway_config.h +++ b/library/include/ipfs_client/ctx/transitory_gateway_config.h @@ -6,12 +6,17 @@ #include namespace ipfs::ctx { +/*! Takes the place of a configuration, but it's not persisted + */ class TransitoryGatewayConfig : public GatewayConfig { std::vector gateways_; std::vector::iterator FindGateway(std::string_view); public: + /* @param index 0-based index into list + * @return The spec at index, or nullopt if index is out-of-bounds + */ std::optional GetGateway(std::size_t index) const override; unsigned GetGatewayRate(std::string_view) override; void SetGatewayRate(std::string_view, unsigned) override; @@ -24,6 +29,8 @@ class TransitoryGatewayConfig : public GatewayConfig { gw::GatewayRequestType, int) override; + /*! Loads gateways from IPFS_GATEWAY environment or a static list + */ TransitoryGatewayConfig(); }; } // namespace ipfs::ctx diff --git a/library/include/ipfs_client/gw/block_request_splitter.h b/library/include/ipfs_client/gw/block_request_splitter.h index 0459df53..ab81d645 100644 --- a/library/include/ipfs_client/gw/block_request_splitter.h +++ b/library/include/ipfs_client/gw/block_request_splitter.h @@ -15,7 +15,8 @@ namespace ipfs::gw { * But for a CAR request will output both the original request and also a block request for the root */ class BlockRequestSplitter final : public Requestor { - std::array recent_provider_requests; + using RequestQ = std::array; + RequestQ recent_provider_requests; std::size_t old_provider_request = 0UL; HandleOutcome handle(RequestPtr) override; std::string_view name() const override; diff --git a/library/include/ipfs_client/gw/gateway_request.h b/library/include/ipfs_client/gw/gateway_request.h index 55d02369..b3d0f57f 100644 --- a/library/include/ipfs_client/gw/gateway_request.h +++ b/library/include/ipfs_client/gw/gateway_request.h @@ -1,19 +1,19 @@ #ifndef IPFS_TRUSTLESS_REQUEST_H_ #define IPFS_TRUSTLESS_REQUEST_H_ -#include +#include "gateway_request_type.h" +#include #include #include -#include #include #include #include #include #include -#include "gateway_request_type.h" +#include namespace ipfs { class IpfsRequest; @@ -28,8 +28,8 @@ class Requestor; std::string_view name(GatewayRequestType); -constexpr std::size_t BLOCK_RESPONSE_BUFFER_SIZE = 2 * 1024 * 1024; -constexpr std::size_t CAR_RESPONSE_BUFFER_SIZE = 64 * 1024 * 1024; +constexpr std::size_t BLOCK_RESPONSE_BUFFER_SIZE = 2UL * 1024UL * 1024UL; +constexpr std::size_t CAR_RESPONSE_BUFFER_SIZE = 5UL * 1024UL * 1024UL; /*! Information about a request that needs to be sent to an IPFS HTTP Gateway * @todo this class has gotten large enough that it should probably be a base @@ -43,6 +43,7 @@ class GatewayRequest : public std::enable_shared_from_this { private: std::shared_ptr orchestrator_; std::vector bytes_received_hooks; + std::string main_param; ///< CID, IPNS name, hostname void FleshOut(ipld::BlockSource&) const; void AddDnsLink(std::string_view target, bool& success, ipld::BlockSource src); @@ -55,14 +56,13 @@ class GatewayRequest : public std::enable_shared_from_this { public: GatewayRequestType type = GatewayRequestType::Zombie; - // TODO - encapsulate. It's not that these public data members are directly accessed everywhere - std::string main_param; ///< CID, IPNS name, hostname + // TODO - encapsulate. Hopefully these public data members aren't directly accessed everywhere std::string path; ///< For CAR requests std::shared_ptr dependent; std::optional cid; short parallel = 0; std::string affinity; - flat_set failures; + std::unordered_set failures; std::string url_suffix() const; std::string_view accept() const; @@ -74,6 +74,8 @@ class GatewayRequest : public std::enable_shared_from_this { std::string debug_string() const; void orchestrator(std::shared_ptr const&); bool cachable() const; + std::string_view root_component() const; + void root_component(std::string_view); bool RespondSuccessfully(std::string_view, std::shared_ptr const& api, diff --git a/library/include/ipfs_client/gw/inline_request_handler.h b/library/include/ipfs_client/gw/inline_request_handler.h index 0301c561..ed298730 100644 --- a/library/include/ipfs_client/gw/inline_request_handler.h +++ b/library/include/ipfs_client/gw/inline_request_handler.h @@ -4,6 +4,10 @@ #include "requestor.h" namespace ipfs::gw { +/*! Handles requests for inline requests, + * i.e. /ipfs/ with hash = identity + * @note The CID contains the response + */ class InlineRequestHandler final : public Requestor { public: HandleOutcome handle(RequestPtr) override; diff --git a/library/include/ipfs_client/gw/requestor.h b/library/include/ipfs_client/gw/requestor.h index f00a14f1..7eac8db6 100644 --- a/library/include/ipfs_client/gw/requestor.h +++ b/library/include/ipfs_client/gw/requestor.h @@ -17,6 +17,8 @@ namespace ipfs::gw { class GatewayRequest; using RequestPtr = std::shared_ptr; +/*! Interface for classes that respond to IPFSRequest + */ class Requestor : public std::enable_shared_from_this { public: enum class HandleOutcome : char { @@ -32,7 +34,7 @@ class Requestor : public std::enable_shared_from_this { virtual HandleOutcome handle(RequestPtr) = 0; - void definitive_failure(RequestPtr) const; + static void definitive_failure(RequestPtr) ; void forward(RequestPtr) const; std::shared_ptr api_; diff --git a/library/include/multibase/algorithm.h b/library/include/multibase/algorithm.h index ac0fbaa9..2bf2675f 100644 --- a/library/include/multibase/algorithm.h +++ b/library/include/multibase/algorithm.h @@ -1,5 +1,7 @@ #pragma once +// LCOV_EXCL_START + #include namespace multibase { @@ -26,3 +28,5 @@ class algorithm { }; } // namespace multibase + +// LCOV_EXCL_STOP diff --git a/library/include/multibase/basic_algorithm.h b/library/include/multibase/basic_algorithm.h index 5da225c8..01381f02 100644 --- a/library/include/multibase/basic_algorithm.h +++ b/library/include/multibase/basic_algorithm.h @@ -4,6 +4,8 @@ */ #pragma once +// LCOV_EXCL_START + #include #include @@ -320,3 +322,5 @@ struct traits { using base_64 = basic_algorithm; } // namespace multibase + +// LCOV_EXCL_STOP diff --git a/library/src/ipfs_client/block_requestor.cc b/library/src/ipfs_client/block_requestor.cc index 8a63e6f7..e69de29b 100644 --- a/library/src/ipfs_client/block_requestor.cc +++ b/library/src/ipfs_client/block_requestor.cc @@ -1 +0,0 @@ -#include diff --git a/library/src/ipfs_client/car.cc b/library/src/ipfs_client/car.cc index d3c0bcc4..c1037c28 100644 --- a/library/src/ipfs_client/car.cc +++ b/library/src/ipfs_client/car.cc @@ -1,12 +1,20 @@ #include "car.h" #include +#include "ipfs_client/ctx/cbor_parser.h" #include +#include +#include "vocab/byte_view.h" #include "log_macros.h" +#include +#include + #include +#include +#include using Self = ipfs::Car; using Byte = ipfs::Byte; @@ -14,8 +22,8 @@ using ByteView = ipfs::ByteView; using VarInt = libp2p::multi::UVarint; namespace { -short ReadHeader(ByteView&, ipfs::ctx::CborParser&); -std::pair GetV1PayloadPos(ByteView); +auto ReadHeader(ByteView& /*bytes*/, ipfs::ctx::CborParser& /*cbor_parser*/) -> short; +auto GetV1PayloadPos(ByteView /*bytes*/) -> std::pair; } // namespace Self::Car(ByteView bytes, ctx::CborParser& cbor_parser) { @@ -71,7 +79,7 @@ auto Self::NextBlock() -> std::optional { namespace { // https://ipld.io/specs/transport/car/carv2/ -short ReadHeader(ByteView& bytes, ipfs::ctx::CborParser& cbor_parser) { +auto ReadHeader(ByteView& bytes, ipfs::ctx::CborParser& cbor_parser) -> short { auto header_len = VarInt::create(bytes); if (!header_len || header_len->toUInt64() + header_len->size() > bytes.size()) { @@ -90,11 +98,12 @@ short ReadHeader(ByteView& bytes, ipfs::ctx::CborParser& cbor_parser) { auto version = version_node->as_unsigned(); if (version) { bytes = bytes.subspan(header_len->toUInt64()); - return version.value(); + assert(version.value() < 0x8000U); + return static_cast(version.value()); } return 0; } -std::uint64_t read_le_u64(ByteView bytes, unsigned& off) { +auto read_le_u64(ByteView bytes, unsigned& off) -> std::uint64_t { auto b = bytes.subspan(off, off + 8); off += 8U; auto shift_in = [](std::uint64_t i, Byte y) { @@ -102,7 +111,7 @@ std::uint64_t read_le_u64(ByteView bytes, unsigned& off) { }; return std::accumulate(b.rbegin(), b.rend(), 0UL, shift_in); } -std::pair GetV1PayloadPos(ByteView bytes) { +auto GetV1PayloadPos(ByteView bytes) -> std::pair { // Following the 11 byte pragma, the CARv2 [header] is a fixed-length sequence // of 40 bytes, broken into the following sections: if (bytes.size() < 40) { diff --git a/library/src/ipfs_client/car_unittest.cc b/library/src/ipfs_client/car_unittest.cc index d3552c4a..ecfdedd2 100644 --- a/library/src/ipfs_client/car_unittest.cc +++ b/library/src/ipfs_client/car_unittest.cc @@ -37,6 +37,8 @@ struct CarTest : public testing::Test { }; } // namespace +TEST_F(CarTest,Noop) {} + #if HAS_JSON_CBOR_ADAPTER TEST_F(CarTest, SmallishDirectoryAndAllItsContents) { diff --git a/library/src/ipfs_client/cid.cc b/library/src/ipfs_client/cid.cc index da2a693d..4f67ef67 100644 --- a/library/src/ipfs_client/cid.cc +++ b/library/src/ipfs_client/cid.cc @@ -1,15 +1,24 @@ #include #include +#include #include +#include +#include +#include +#include +#include "ipfs_client/multicodec.h" +#include "ipfs_client/multi_hash.h" #include "log_macros.h" +#include "vocab/byte_view.h" +#include "vocab/byte.h" using Self = ipfs::Cid; using VarInt = libp2p::multi::UVarint; Self::Cid(ipfs::MultiCodec cdc, ipfs::MultiHash hsh) - : codec_{cdc}, hash_{hsh} {} + : codec_{cdc}, hash_{std::move(hsh)} {} Self::Cid(ipfs::ByteView bytes) { ReadStart(bytes); @@ -28,7 +37,7 @@ Self::Cid(std::string_view s) { } } -bool Self::ReadStart(ByteView& bytes) { +auto Self::ReadStart(ByteView& bytes) -> bool { if (bytes.size() >= 34 && bytes[0] == ipfs::Byte{0x12} && bytes[1] == ipfs::Byte{0x20}) { hash_ = MultiHash{bytes}; @@ -55,7 +64,7 @@ bool Self::ReadStart(ByteView& bytes) { return hash_.ReadPrefix(bytes); } -bool Self::valid() const { +auto Self::valid() const -> bool { return codec_ != MultiCodec::INVALID && hash_.valid(); } @@ -66,11 +75,11 @@ auto Self::hash_type() const -> HashType { return multi_hash().type(); } -std::string Self::to_string() const { +auto Self::to_string() const -> std::string { std::vector binary; auto append_varint = [&binary](auto x) { auto i = static_cast(x); - VarInt v{i}; + VarInt const v{i}; auto b = v.toBytes(); binary.insert(binary.end(), b.begin(), b.end()); }; diff --git a/library/src/ipfs_client/client.cc b/library/src/ipfs_client/client.cc index 4940c03f..cc253d58 100644 --- a/library/src/ipfs_client/client.cc +++ b/library/src/ipfs_client/client.cc @@ -1,8 +1,22 @@ #include +#include +#include +#include +#include +#include +#include +#include #include "crypto/openssl_sha2_256.h" #include "ipfs_client/crypto/openssl_signature_verifier.h" -#include "ipfs_client/ctx/boost_beast_http.h" +#include "ipfs_client/crypto/identity_hasher.h" +#include "ipfs_client/crypto/signing_key_type.h" +#include "ipfs_client/crypto/signature_verifier.h" +#include "ipfs_client/ctx/http_api.h" +#include "ipfs_client/ctx/dns_txt_lookup.h" +#include "ipfs_client/ctx/gateway_config.h" +#include "ipfs_client/ctx/json_parser.h" +#include "ipfs_client/ctx/cbor_parser.h" #include "ipfs_client/ctx/nlohmann_cbor_parser.h" #include "ipfs_client/ctx/nlohmann_json_parser.h" #include "ipfs_client/ctx/null_dns_txt_lookup.h" @@ -10,10 +24,14 @@ #include "ipfs_client/ctx/transitory_gateway_config.h" #include "ipfs_client/gw/default_requestor.h" +#include "ipfs_client/multi_hash.h" +#include "ipfs_client/json_cbor_adapter.h" +#include "ipfs_client/gw/requestor.h" #include "ipfs_client/partition.h" #include "ipfs_client/web_util.h" #include "log_macros.h" +#include "vocab/byte.h" using Self = ipfs::Client; @@ -22,6 +40,7 @@ Self::Client() { hashers_.emplace(HashType::SHA2_256, std::make_unique()); #endif + hashers_.emplace(HashType::IDENTITY, std::make_unique()); #if HAS_OPENSSL_EVP with(SigningKeyType::RSA, std::make_unique(EVP_PKEY_RSA)); @@ -38,10 +57,10 @@ auto Self::Hash(HashType ht, ByteView data) } return it->second->hash(data); } -bool Self::VerifyKeySignature(SigningKeyType typ, +auto Self::VerifyKeySignature(SigningKeyType typ, ByteView signature, ByteView data, - ByteView key_bytes) const { + ByteView key_bytes) const -> bool { auto it = verifiers_.find(typ); if (verifiers_.end() == it || !(it->second)) { LOG(ERROR) @@ -51,9 +70,9 @@ bool Self::VerifyKeySignature(SigningKeyType typ, } return it->second->VerifySignature(signature, data, key_bytes); } -std::string Self::MimeType(std::string extension, +auto Self::MimeType(std::string extension, std::string_view content, - std::string const& url) { + std::string const& url) -> std::string { if (!deduce_mime_type_) { LOG(WARNING) << "No mime-type deduction algo provided. Will do something " "trivial/inaccurate."; @@ -61,7 +80,7 @@ std::string Self::MimeType(std::string extension, } return deduce_mime_type_(extension, content, url); } -std::string Self::UnescapeUrlComponent(std::string_view url_comp) { +auto Self::UnescapeUrlComponent(std::string_view url_comp) -> std::string { if (!unescape_) { LOG(WARNING) << "No URL (un)escaping algo provided. Will do something simple/wrong."; @@ -69,7 +88,7 @@ std::string Self::UnescapeUrlComponent(std::string_view url_comp) { } return unescape_(url_comp); } -bool Self::DnslinkFallback() const { +auto Self::DnslinkFallback() const -> bool { if (dns_fb_) { return dns_fb_(); } @@ -132,24 +151,24 @@ auto Self::requestor() -> std::shared_ptr { } return rtor_; } -Self& Self::with(std::unique_ptr p) { +auto Self::with(std::unique_ptr p) -> Self& { json_parser_ = std::move(p); return *this; } -Self& Self::with(std::unique_ptr p) { +auto Self::with(std::unique_ptr p) -> Self& { cbor_parser_ = std::move(p); return *this; } -Self& Self::with(std::unique_ptr p) { +auto Self::with(std::unique_ptr p) -> Self& { http_api_ = std::move(p); return *this; } -Self& Self::with(std::unique_ptr p) { +auto Self::with(std::unique_ptr p) -> Self& { dns_txt_ = std::move(p); return *this; } -Self& Self::with(SigningKeyType t, - std::unique_ptr p) { +auto Self::with(SigningKeyType t, + std::unique_ptr p) -> Self& { if (p) { verifiers_[t] = std::move(p); } else { @@ -157,23 +176,23 @@ Self& Self::with(SigningKeyType t, } return *this; } -Self& Self::with(ipfs::Client::MimeTypeDeduction deduce_mime_type) { +auto Self::with(ipfs::Client::MimeTypeDeduction deduce_mime_type) -> Self& { deduce_mime_type_ = deduce_mime_type; return *this; } -Self& Self::with(ipfs::Client::UrlUnescaping unescape) { +auto Self::with(ipfs::Client::UrlUnescaping unescape) -> Self& { unescape_ = unescape; return *this; } -Self& Self::with(std::unique_ptr p) { +auto Self::with(std::unique_ptr p) -> Self& { gateway_config_ = std::move(p); return *this; } -Self& Self::with(std::shared_ptr p) { +auto Self::with(std::shared_ptr p) -> Self& { rtor_ = p; return *this; } -Self& Self::with(DnslinkFallbackSwitch sw) { +auto Self::with(DnslinkFallbackSwitch sw) -> Self& { dns_fb_ = sw; return *this; } diff --git a/library/src/ipfs_client/crypto/openssl_sha2_256.cc b/library/src/ipfs_client/crypto/openssl_sha2_256.cc index 5da1ea07..04ade2b0 100644 --- a/library/src/ipfs_client/crypto/openssl_sha2_256.cc +++ b/library/src/ipfs_client/crypto/openssl_sha2_256.cc @@ -1,4 +1,8 @@ #include "openssl_sha2_256.h" +#include "vocab/byte_view.h" +#include +#include +#include "vocab/byte.h" using Self = ipfs::crypto::OpensslSha2_256; @@ -6,7 +10,6 @@ using Self = ipfs::crypto::OpensslSha2_256; #if HAS_OPENSSL_SHA -#include #include Self::~OpensslSha2_256() noexcept = default; @@ -21,7 +24,7 @@ auto Self::hash(ipfs::ByteView data) -> std::optional> { return {}; } std::vector rv(SHA256_DIGEST_LENGTH, Byte{}); - auto p = reinterpret_cast(rv.data()); + auto *p = reinterpret_cast(rv.data()); if (1 == SHA256_Final(p, &ctx)) { return rv; } else { diff --git a/library/src/ipfs_client/crypto/openssl_signature_verifier.cc b/library/src/ipfs_client/crypto/openssl_signature_verifier.cc index 69ca7104..4ff917ca 100644 --- a/library/src/ipfs_client/crypto/openssl_signature_verifier.cc +++ b/library/src/ipfs_client/crypto/openssl_signature_verifier.cc @@ -1,8 +1,11 @@ #include "ipfs_client/crypto/openssl_signature_verifier.h" +#include +#include #include #include "log_macros.h" +#include "vocab/byte_view.h" #if HAS_OPENSSL_EVP @@ -10,19 +13,19 @@ using Self = ipfs::crypto::OpensslSignatureVerifier; Self::OpensslSignatureVerifier(int key_type) : openssl_key_type_{key_type} {} Self::~OpensslSignatureVerifier() noexcept = default; -bool Self::VerifySignature(ipfs::ByteView signature, +auto Self::VerifySignature(ipfs::ByteView signature, ipfs::ByteView data, - ipfs::ByteView key_bytes) { - auto* key_p = reinterpret_cast(key_bytes.data()); - auto* data_p = reinterpret_cast(data.data()); - auto* sig_p = reinterpret_cast(signature.data()); + ipfs::ByteView key_bytes) -> bool { + const auto* key_p = reinterpret_cast(key_bytes.data()); + const auto* data_p = reinterpret_cast(data.data()); + const auto* sig_p = reinterpret_cast(signature.data()); auto kt = openssl_key_type_; - std::unique_ptr ctx{EVP_MD_CTX_new(), + std::unique_ptr const ctx{EVP_MD_CTX_new(), &EVP_MD_CTX_free}; - std::unique_ptr key{ + std::unique_ptr const key{ EVP_PKEY_new_raw_public_key(kt, nullptr, key_p, key_bytes.size()), &EVP_PKEY_free}; - if (!EVP_DigestVerifyInit(ctx.get(), nullptr, nullptr, nullptr, key.get())) { + if (EVP_DigestVerifyInit(ctx.get(), nullptr, nullptr, nullptr, key.get()) == 0) { LOG(ERROR) << "EVP_DigestVerifyInit failed"; return false; } diff --git a/library/src/ipfs_client/crypto/signing_key_type.cc b/library/src/ipfs_client/crypto/signing_key_type.cc index ca0b797d..f60638a3 100644 --- a/library/src/ipfs_client/crypto/signing_key_type.cc +++ b/library/src/ipfs_client/crypto/signing_key_type.cc @@ -1,6 +1,10 @@ #include "ipfs_client/crypto/signing_key_type.h" -#include +#if __has_include() +#include +#else +#include "ipfs_client/keys.pb.h" +#endif using T = ipfs::crypto::SigningKeyType; namespace n = ipfs::ipns; diff --git a/library/src/ipfs_client/ctx/boost_beast_http.cc b/library/src/ipfs_client/ctx/boost_beast_http.cc index 0ea692fa..d07db82d 100644 --- a/library/src/ipfs_client/ctx/boost_beast_http.cc +++ b/library/src/ipfs_client/ctx/boost_beast_http.cc @@ -15,6 +15,7 @@ #include #include +#include using Self = ipfs::ctx::BoostBeastHttp; @@ -48,7 +49,7 @@ class HttpSession : public std::enable_shared_from_this { auto status = ec.value() == 1 ? 408 : 500; cb_(static_cast(status), "", [](auto) { return std::string{}; }); } - std::string parse_url() { + auto parse_url() -> std::string { ipfs::SlashDelimited ss{desc_.url}; auto scheme = ss.pop(); if (port_.empty()) { @@ -81,7 +82,7 @@ class HttpSession : public std::enable_shared_from_this { resolver_(strand_), ssl_ctx_(ssc), stream_(strand_, ssc), - cb_{cb}, + cb_{std::move(cb)}, desc_{desc} { if (auto sz = desc_.max_response_size) { response_parser_.body_limit(*sz * 2); @@ -89,7 +90,7 @@ class HttpSession : public std::enable_shared_from_this { response_parser_.body_limit(boost::none); } } - tcp::resolver::results_type& resolution() { + auto resolution() -> tcp::resolver::results_type& { return resolutions_[host_ + port_]; } // Start the asynchronous operation @@ -100,7 +101,7 @@ class HttpSession : public std::enable_shared_from_this { } // Set SNI Hostname (many hosts need this to handshake successfully) if (!SSL_set_tlsext_host_name(stream_.native_handle(), host_.c_str())) { - boost::beast::error_code ec{static_cast(::ERR_get_error()), + boost::beast::error_code const ec{static_cast(::ERR_get_error()), boost::asio::error::get_ssl_category()}; LOG(ERROR) << "SSL early fail: " << ec.message(); return; @@ -110,7 +111,7 @@ class HttpSession : public std::enable_shared_from_this { req_.method(http::verb::get); req_.target(target_); req_.set(http::field::host, parsed_host_); - if (desc_.accept.size()) { + if (static_cast(!desc_.accept.empty()) != 0U) { req_.set("Accept", desc_.accept); } extend_time(); @@ -132,10 +133,11 @@ class HttpSession : public std::enable_shared_from_this { } void on_resolve(boost::beast::error_code ec, tcp::resolver::results_type results) { - if (ec) + if (ec) { return fail(ec, "resolve"); +} resolution() = results; - for (auto& ep : results) { + for (const auto& ep : results) { VLOG(1) << desc_.url << " Resolved " << host_ << ", now connecting to " << req_[http::field::host] << " aka " << ep.host_name() << ':' << ep.service_name() << " for " << target_; @@ -148,8 +150,9 @@ class HttpSession : public std::enable_shared_from_this { void on_connect(boost::beast::error_code ec, tcp::resolver::results_type::endpoint_type) { - if (ec) + if (ec) { return fail(ec, "connect"); +} extend_time(); LOG(INFO) << desc_.url << " connected."; if (use_ssl()) { @@ -165,7 +168,7 @@ class HttpSession : public std::enable_shared_from_this { shared_from_this())); } } - bool use_ssl() const { return port_ == "443" || port_ == "https"; } + auto use_ssl() const -> bool { return port_ == "443" || port_ == "https"; } void extend_time() { expiry_seconds_ += desc_.timeout_seconds + 1; VLOG(2) << "expiry_seconds_ = " << expiry_seconds_ << '\n'; @@ -173,8 +176,9 @@ class HttpSession : public std::enable_shared_from_this { std::chrono::seconds(expiry_seconds_)); } void on_handshake(boost::beast::error_code ec) { - if (ec) + if (ec) { return fail(ec, "handshake"); +} extend_time(); http::async_write(stream_, req_, boost::beast::bind_front_handler(&HttpSession::on_write, @@ -182,8 +186,9 @@ class HttpSession : public std::enable_shared_from_this { } void on_write(boost::beast::error_code ec, std::size_t) { - if (ec) + if (ec) { return fail(ec, "write"); +} VLOG(2) << desc_.url << " request written."; extend_time(); if (use_ssl()) { @@ -199,10 +204,11 @@ class HttpSession : public std::enable_shared_from_this { } void on_read(boost::beast::error_code ec, std::size_t bytes_transferred) { - if (ec) + if (ec) { return fail(ec, "read"); +} res_ = response_parser_.release(); - api::Hdrs get_hdr = [this](std::string_view k) -> std::string { + api::Hdrs const get_hdr = [this](std::string_view k) -> std::string { std::string rv{(*res_)[k]}; return rv; }; @@ -213,8 +219,8 @@ class HttpSession : public std::enable_shared_from_this { if (res_->result_int() == 400) { LOG(WARNING) << "Got that annoying 400 status: " << res_->body(); } - for (auto& h : *res_) { - auto& n = h.name_string(); + for (const auto& h : *res_) { + const auto& n = h.name_string(); if (n.substr(0, 6) != "Access") { VLOG(1) << "\t Header=" << h.name_string() << ": " << h.value(); } @@ -254,7 +260,7 @@ class HttpSession : public std::enable_shared_from_this { boost::asio::defer(strand_, respond); close(); } - int redirect_count(std::string_view comp) { + auto redirect_count(std::string_view comp) -> int { if (comp == desc_.url) { LOG(ERROR) << "Redirect loop on " << comp; return 0xFF; @@ -277,8 +283,7 @@ class HttpSession : public std::enable_shared_from_this { ll.close(); } void on_shutdown(boost::beast::error_code ec) { - namespace E = boost::asio::error; - switch (ec.value()) { + switch (ec.value()) { case 0: case 1: case 2: @@ -296,7 +301,7 @@ std::map auto Self::SendHttpRequest(ReqDesc desc, OnComplete cb) const -> Canceller { auto sess = std::make_shared(io_, ssl_ctx_, desc, cb); sess->run(); - std::weak_ptr w = sess; + std::weak_ptr const w = sess; return [w](){ if (auto p = w.lock()) { p->close(); diff --git a/library/src/ipfs_client/ctx/boost_beast_http_unittest.cc b/library/src/ipfs_client/ctx/boost_beast_http_unittest.cc index 1b27c39e..eb36cfd9 100644 --- a/library/src/ipfs_client/ctx/boost_beast_http_unittest.cc +++ b/library/src/ipfs_client/ctx/boost_beast_http_unittest.cc @@ -5,6 +5,10 @@ #include TEST(BoostBeastHttpTest, GoogleHomePage) { + auto off = std::getenv("OFFLINE"); + if (off && *off == '1') { + return; + } boost::asio::ssl::context ssl_sux{boost::asio::ssl::context::sslv23_client}; boost::asio::io_context io; ipfs::ctx::BoostBeastHttp t{io}; diff --git a/library/src/ipfs_client/ctx/default_gateways.cc b/library/src/ipfs_client/ctx/default_gateways.cc index 438f2257..29c52e28 100644 --- a/library/src/ipfs_client/ctx/default_gateways.cc +++ b/library/src/ipfs_client/ctx/default_gateways.cc @@ -2,13 +2,17 @@ #include +#include #include +#include +#include +#include namespace ctx = ipfs::ctx; -bool ctx::LoadGatewaysFromEnvironmentVariable(ipfs::ctx::GatewayConfig& cfg) { +auto ctx::LoadGatewaysFromEnvironmentVariable(ipfs::ctx::GatewayConfig& cfg) -> bool { auto* ovr = std::getenv("IPFS_GATEWAY"); - if (!ovr) { + if (ovr == nullptr) { return false; } std::istringstream user_override{ovr}; @@ -29,24 +33,24 @@ bool ctx::LoadGatewaysFromEnvironmentVariable(ipfs::ctx::GatewayConfig& cfg) { void ctx::LoadStaticGatewayList(ipfs::ctx::GatewayConfig& cfg) { auto static_list = { - std::pair{"http://127.0.0.1:8080/", 1029}, - {"https://ipfs.io/", 1008}, - {"https://dweb.link/", 955}, + std::pair{"http://127.0.0.1:8080/", 1036}, + {"https://ipfs.io/", 977}, + {"https://dweb.link/", 949}, {"https://trustless-gateway.link/", 945}, - {"https://hardbin.com/", 935}, - {"https://ipfs.joaoleitao.org/", 873}, - {"https://ipfs.greyh.at/", 872}, - {"https://dlunar.net/", 713}, - {"https://flk-ipfs.io/", 697}, - {"https://ipfs.cyou/", 483}, - {"https://human.mypinata.cloud/", 424}, - {"https://jcsl.hopto.org/", 386}, - {"https://delegated-ipfs.dev/", 336}, - {"https://4everland.io/", 310}, - {"https://ipfs.runfission.com/", 280}, - {"https://gateway.pinata.cloud/", 153}, - {"https://dag.w3s.link/", 147}, - {"https://ipfs.eth.aragon.network/", 12}, + {"https://hardbin.com/", 924}, + {"https://ipfs.greyh.at/", 865}, + {"https://ipfs.joaoleitao.org/", 861}, + {"https://dlunar.net/", 702}, + {"https://flk-ipfs.io/", 686}, + {"https://ipfs.cyou/", 477}, + {"https://human.mypinata.cloud/", 418}, + {"https://jcsl.hopto.org/", 375}, + {"https://delegated-ipfs.dev/", 330}, + {"https://4everland.io/", 303}, + {"https://ipfs.runfission.com/", 274}, + {"https://gateway.pinata.cloud/", 147}, + {"https://dag.w3s.link/", 141}, + {"https://ipfs.eth.aragon.network/", 14}, {"https://data.filstorage.io/", 10}, {"https://storry.tv/", 9}, diff --git a/library/src/ipfs_client/ctx/dns_txt_lookup.cc b/library/src/ipfs_client/ctx/dns_txt_lookup.cc new file mode 100644 index 00000000..be88069f --- /dev/null +++ b/library/src/ipfs_client/ctx/dns_txt_lookup.cc @@ -0,0 +1,3 @@ +#include + +ipfs::ctx::DnsTxtLookup::~DnsTxtLookup() noexcept = default; diff --git a/library/src/ipfs_client/ctx/nlohmann_cbor_parser.cc b/library/src/ipfs_client/ctx/nlohmann_cbor_parser.cc index baac3a69..2642193b 100644 --- a/library/src/ipfs_client/ctx/nlohmann_cbor_parser.cc +++ b/library/src/ipfs_client/ctx/nlohmann_cbor_parser.cc @@ -1,5 +1,9 @@ #include +#include + +#include + #if HAS_JSON_CBOR_ADAPTER using Self = ipfs::ctx::NlohmannCborParser; diff --git a/library/src/ipfs_client/ctx/nlohmann_json_parser.cc b/library/src/ipfs_client/ctx/nlohmann_json_parser.cc index c4209ec4..a5bc5e7d 100644 --- a/library/src/ipfs_client/ctx/nlohmann_json_parser.cc +++ b/library/src/ipfs_client/ctx/nlohmann_json_parser.cc @@ -1,5 +1,10 @@ #include +#include +#include +#include +#include + #if HAS_JSON_CBOR_ADAPTER #include "log_macros.h" diff --git a/library/src/ipfs_client/ctx/null_dns_txt_lookup.cc b/library/src/ipfs_client/ctx/null_dns_txt_lookup.cc index c1fb0a33..10582cac 100644 --- a/library/src/ipfs_client/ctx/null_dns_txt_lookup.cc +++ b/library/src/ipfs_client/ctx/null_dns_txt_lookup.cc @@ -1,13 +1,14 @@ #include +#include #include "log_macros.h" using Self = ipfs::ctx::NullDnsTxtLookup; -void Self::SendDnsTextRequest(std::string, - DnsTextResultsCallback, - DnsTextCompleteCallback cb) { +void Self::SendDnsTextRequest(std::string /*hostname*/, + DnsTextResultsCallback /*unused*/, + DnsTextCompleteCallback callback) { LOG(ERROR) << "DNS TXT lookup provider not instantiated. DNSLink will not work."; - cb(); + callback(); } diff --git a/library/src/ipfs_client/ctx/null_http_provider.cc b/library/src/ipfs_client/ctx/null_http_provider.cc index 347013fd..5f7fa430 100644 --- a/library/src/ipfs_client/ctx/null_http_provider.cc +++ b/library/src/ipfs_client/ctx/null_http_provider.cc @@ -1,4 +1,5 @@ #include "ipfs_client/ctx/null_http_provider.h" +#include using Self = ipfs::ctx::NullHttpProvider; diff --git a/library/src/ipfs_client/ctx/transitory_gateway_config.cc b/library/src/ipfs_client/ctx/transitory_gateway_config.cc index 93adc105..9e2d9399 100644 --- a/library/src/ipfs_client/ctx/transitory_gateway_config.cc +++ b/library/src/ipfs_client/ctx/transitory_gateway_config.cc @@ -1,9 +1,16 @@ #include #include "ipfs_client/ctx/default_gateways.h" +#include "ipfs_client/gateway_spec.h" +#include "ipfs_client/gw/gateway_request_type.h" #include "log_macros.h" #include +#include +#include +#include +#include +#include using Self = ipfs::ctx::TransitoryGatewayConfig; @@ -15,7 +22,7 @@ Self::TransitoryGatewayConfig() { [](auto& a, auto& b) { return a.prefix < b.prefix; }); } -std::optional Self::GetGateway(std::size_t index) const { +auto Self::GetGateway(std::size_t index) const -> std::optional { if (index < gateways_.size()) { return gateways_.at(index); } @@ -42,7 +49,7 @@ void Self::SetGatewayRate(std::string_view prefix, unsigned int rate) { << " to " << rate; } } -unsigned Self::GetGatewayRate(std::string_view prefix) { +auto Self::GetGatewayRate(std::string_view prefix) -> unsigned { auto i = FindGateway(prefix); return gateways_.end() == i ? 60U : i->rate; } @@ -51,13 +58,13 @@ auto Self::FindGateway(std::string_view prefix) auto cmp = [](auto& g, std::string_view p) { return g.prefix < p; }; return std::lower_bound(gateways_.begin(), gateways_.end(), prefix, cmp); } -unsigned Self::RoutingApiDiscoveryDefaultRate() const { +auto Self::RoutingApiDiscoveryDefaultRate() const -> unsigned { return 60U; } -bool Self::RoutingApiDiscoveryOfUnencryptedGateways() const { +auto Self::RoutingApiDiscoveryOfUnencryptedGateways() const -> bool { return true; } -int Self::GetTypeAffinity(std::string_view, gw::GatewayRequestType) const { +auto Self::GetTypeAffinity(std::string_view, gw::GatewayRequestType) const -> int { return 9; } void Self::SetTypeAffinity(std::string_view, gw::GatewayRequestType, int) {} diff --git a/library/src/ipfs_client/dag_cbor_value.cc b/library/src/ipfs_client/dag_cbor_value.cc index 20a6fc71..7c157048 100644 --- a/library/src/ipfs_client/dag_cbor_value.cc +++ b/library/src/ipfs_client/dag_cbor_value.cc @@ -2,9 +2,13 @@ #include -#include "log_macros.h" +#include +#include +#include +#include #include +#include using Self = ipfs::DagCborValue; @@ -23,7 +27,7 @@ void Self::html(std::ostream& str) const { str << ""

\n"; } else if (auto cid = as_link()) { auto cs = cid.value().to_string(); - if (cs.size()) { + if (static_cast(!cs.empty()) != 0U) { str << "" << cs << "\n"; } else { @@ -53,14 +57,14 @@ void Self::html(std::ostream& str) const { }); str << "\n"; } else if (auto bul = as_bool()) { - auto val = (bul.value() ? "True" : "False"); + const auto *val = (bul.value() ? "True" : "False"); str << " " << val << "\n"; } else { str << "\n"; } } -std::string Self::html() const { +auto Self::html() const -> std::string { std::ostringstream oss; oss << "DAG-CBOR Preview\n"; html(oss); diff --git a/library/src/ipfs_client/dag_json_value.cc b/library/src/ipfs_client/dag_json_value.cc index fb5f370e..6c0d8e81 100644 --- a/library/src/ipfs_client/dag_json_value.cc +++ b/library/src/ipfs_client/dag_json_value.cc @@ -1,6 +1,7 @@ #include #include +#include using Self = ipfs::DagJsonValue; diff --git a/library/src/ipfs_client/generated_directory_listing.cc b/library/src/ipfs_client/generated_directory_listing.cc index 5a7c4fce..a02201bd 100644 --- a/library/src/ipfs_client/generated_directory_listing.cc +++ b/library/src/ipfs_client/generated_directory_listing.cc @@ -1,6 +1,7 @@ #include "generated_directory_listing.h" +#include +#include -#include "log_macros.h" ipfs::GeneratedDirectoryListing::GeneratedDirectoryListing( std::string_view base_path) @@ -40,6 +41,6 @@ void ipfs::GeneratedDirectoryListing::AddLink(std::string_view name, .append(" \n"); } -std::string const& ipfs::GeneratedDirectoryListing::Finish() { +auto ipfs::GeneratedDirectoryListing::Finish() -> std::string const& { return html_.append(" \n").append(" \n").append("\n"); } \ No newline at end of file diff --git a/library/src/ipfs_client/gw/block_request_splitter.cc b/library/src/ipfs_client/gw/block_request_splitter.cc index 894dab13..ce5f882c 100644 --- a/library/src/ipfs_client/gw/block_request_splitter.cc +++ b/library/src/ipfs_client/gw/block_request_splitter.cc @@ -3,13 +3,16 @@ #include #include +#include "ipfs_client/gw/requestor.h" #include "log_macros.h" #include +#include +#include using Self = ipfs::gw::BlockRequestSplitter; -std::string_view Self::name() const { +auto Self::name() const -> std::string_view { return "BlockRequestSplitter"; } auto Self::handle(ipfs::gw::RequestPtr r) -> HandleOutcome { @@ -22,9 +25,11 @@ auto Self::handle(ipfs::gw::RequestPtr r) -> HandleOutcome { br->path.clear(); forward(br); } - if (api_ && api_->gw_cfg().RoutingApiDiscoveryDefaultRate()) { - auto it = std::find(recent_provider_requests.begin(), - recent_provider_requests.end(), r->affinity); + if (api_ && (api_->gw_cfg().RoutingApiDiscoveryDefaultRate() != 0U)) { + auto it = std::find( + recent_provider_requests.begin(), + recent_provider_requests.end(), + r->affinity); if (recent_provider_requests.end() == it) { auto i = old_provider_request % recent_provider_requests.size(); recent_provider_requests[i] = r->affinity; diff --git a/library/src/ipfs_client/gw/block_request_splitter_unittest.cc b/library/src/ipfs_client/gw/block_request_splitter_unittest.cc index 39cba001..511dad6c 100644 --- a/library/src/ipfs_client/gw/block_request_splitter_unittest.cc +++ b/library/src/ipfs_client/gw/block_request_splitter_unittest.cc @@ -29,7 +29,7 @@ TEST(BlockRequestSplitterTest, split2three) { tested.or_else(rec); auto req = std::make_shared(); req->type = RT::Car; - req->main_param = "cid"; + req->root_component( "cid"); req->path = "path"; req->parallel = 123; req->affinity = __func__; @@ -38,16 +38,16 @@ TEST(BlockRequestSplitterTest, split2three) { EXPECT_EQ(rec->requests_received.size(), 3U); EXPECT_TRUE(rec->requests_received.at(0)->type == RT::Block) << static_cast(rec->requests_received.at(0)->type); - EXPECT_EQ(rec->requests_received.at(0)->main_param, "cid"); + EXPECT_EQ(rec->requests_received.at(0)->root_component(), "cid"); EXPECT_EQ(rec->requests_received.at(0)->path, ""); EXPECT_TRUE(rec->requests_received.at(1)->type == RT::Providers) << static_cast(rec->requests_received.at(2)->type); - EXPECT_EQ(rec->requests_received.at(1)->main_param, "cid"); + EXPECT_EQ(rec->requests_received.at(1)->root_component(), "cid"); EXPECT_EQ(rec->requests_received.at(1)->path, ""); EXPECT_TRUE(rec->requests_received.at(2)->type == RT::Car) << static_cast(rec->requests_received.at(2)->type); - EXPECT_EQ(rec->requests_received.at(2)->main_param, "cid"); + EXPECT_EQ(rec->requests_received.at(2)->root_component(), "cid"); EXPECT_EQ(rec->requests_received.at(2)->path, "path"); } diff --git a/library/src/ipfs_client/gw/default_requestor.cc b/library/src/ipfs_client/gw/default_requestor.cc index be2976e7..3982583c 100644 --- a/library/src/ipfs_client/gw/default_requestor.cc +++ b/library/src/ipfs_client/gw/default_requestor.cc @@ -5,6 +5,8 @@ #include #include #include +#include +#include "ipfs_client/gw/requestor.h" auto ipfs::gw::default_requestor(std::shared_ptr early, std::shared_ptr api) diff --git a/library/src/ipfs_client/gw/dnslink_requestor.cc b/library/src/ipfs_client/gw/dnslink_requestor.cc index 9bac1289..3d015f5e 100644 --- a/library/src/ipfs_client/gw/dnslink_requestor.cc +++ b/library/src/ipfs_client/gw/dnslink_requestor.cc @@ -1,8 +1,8 @@ #include -#include "ipfs_client/ipld/dnslink_name.h" +#include "ipfs_client/ipld/block_source.h" +#include "ipfs_client/gw/requestor.h" -#include #include #include @@ -12,7 +12,11 @@ #include "ipfs_client/gw/gateway_request_type.h" #include "log_macros.h" -#include +#include +#include +#include +#include +#include using Self = ipfs::gw::DnsLinkRequestor; using Source = ipfs::ipld::BlockSource; @@ -21,14 +25,14 @@ using namespace std::literals; Self::DnsLinkRequestor(std::shared_ptr api) { api_ = api; } -std::string_view Self::name() const { +auto Self::name() const -> std::string_view { return "DNSLink requestor"; } namespace { -bool parse_results(ipfs::gw::RequestPtr req, +auto parse_results(ipfs::gw::RequestPtr req, std::vector const& results, - std::shared_ptr const&, - Source::Clock::time_point); + std::shared_ptr const& /*api*/, + Source::Clock::time_point /*start*/) -> bool; } auto Self::handle(ipfs::gw::RequestPtr req) -> HandleOutcome { if (req->type != GatewayRequestType::DnsLink) { @@ -37,10 +41,10 @@ auto Self::handle(ipfs::gw::RequestPtr req) -> HandleOutcome { // std::function requires target be copy-constructible auto success = std::make_shared(); *success = false; - auto a = api_; + auto api = api_;//Copy for lambda bind auto start = Source::Clock::now(); - auto res = [req, success, a, start](std::vector const& results) { - *success = *success || parse_results(req, results, a, start); + auto res = [req, success, api, start](std::vector const& results) { + *success = *success || parse_results(req, results, api, start); }; auto don = [this,success, req]() { if (!*success) { @@ -51,22 +55,23 @@ auto Self::handle(ipfs::gw::RequestPtr req) -> HandleOutcome { } } }; - api_->dns_txt().SendDnsTextRequest("_dnslink." + req->main_param, res, - std::move(don)); + std::string host{"_dnslink."}; + host.append(req->root_component()); + api_->dns_txt().SendDnsTextRequest(host, res, std::move(don)); return HandleOutcome::PENDING; } namespace { -bool parse_results(ipfs::gw::RequestPtr req, +auto parse_results(ipfs::gw::RequestPtr req, std::vector const& results, std::shared_ptr const& api, - Source::Clock::time_point start) { + Source::Clock::time_point start) -> bool { constexpr auto prefix = "dnslink="sv; - auto t = Source::Clock::now(); - for (auto& result : results) { - if (starts_with(result, prefix)) { + auto fetched_at = Source::Clock::now(); + for (const auto& result : results) { + if (result.starts_with(prefix)) { Source src; - src.fetched_at = t; - src.load_duration = t - start; + src.fetched_at = fetched_at; + src.load_duration = fetched_at - start; req->RespondSuccessfully(result.substr(prefix.size()), api, src); return true; } else { diff --git a/library/src/ipfs_client/gw/gateway_request.cc b/library/src/ipfs_client/gw/gateway_request.cc index f9e22256..0f3241c2 100644 --- a/library/src/ipfs_client/gw/gateway_request.cc +++ b/library/src/ipfs_client/gw/gateway_request.cc @@ -5,24 +5,35 @@ #include #include #include - -#include #include +#include #include #include #include -#include +#include +#include +#include +#include -#include "log_macros.h" +#include +#include +#include -#include +#include + +#include +#include +#include #include +#include +#include +#include using namespace std::literals; using Self = ipfs::gw::GatewayRequest; -std::shared_ptr Self::fromIpfsPath(ipfs::SlashDelimited p) { +auto Self::fromIpfsPath(ipfs::SlashDelimited p) -> std::shared_ptr { auto name_space = p.pop(); auto r = std::make_shared(); r->main_param = p.pop(); @@ -59,14 +70,13 @@ std::shared_ptr Self::fromIpfsPath(ipfs::SlashDelimited p) { return r; } -std::string Self::url_suffix() const { +auto Self::url_suffix() const -> std::string { switch (type) { case GatewayRequestType::Block: return "/ipfs/" + main_param; case GatewayRequestType::Car: - // return "/ipfs/" + main_param + "/" + path + "?dag-scope=entity"; return "/ipfs/" + main_param + "/" + path + - "?entity-bytes=0:" + std::to_string(BLOCK_RESPONSE_BUFFER_SIZE); + "?entity-bytes=0:" + std::to_string(2UL*CAR_RESPONSE_BUFFER_SIZE/3UL); case GatewayRequestType::Ipns: return "/ipns/" + main_param; case GatewayRequestType::Providers: @@ -83,7 +93,7 @@ std::string Self::url_suffix() const { #endif return {}; } -std::string_view Self::accept() const { +auto Self::accept() const -> std::string_view { switch (type) { case GatewayRequestType::Block: return "application/vnd.ipld.raw"sv; @@ -102,7 +112,7 @@ std::string_view Self::accept() const { LOG(FATAL) << "Invalid gateway request type: " << static_cast(type); return {}; } -short Self::timeout_seconds() const { +auto Self::timeout_seconds() const -> short { switch (type) { case GatewayRequestType::DnsLink: return 33; @@ -128,11 +138,11 @@ auto Self::identity_data() const -> std::string_view { return ""; } auto hash = cid.value().hash(); - auto d = reinterpret_cast(hash.data()); + const auto *d = reinterpret_cast(hash.data()); return std::string_view{d, hash.size()}; } -bool Self::is_http() const { +auto Self::is_http() const -> bool { switch (type) { case GatewayRequestType::Ipns: case GatewayRequestType::Car: @@ -162,7 +172,7 @@ auto Self::describe_http(std::string_view prefix) const return HttpRequestDescription{url, timeout_seconds(), std::string{accept()}, max_response_size()}; } -std::optional Self::max_response_size() const { +auto Self::max_response_size() const -> std::optional { switch (type) { case GatewayRequestType::Identity: return 0; @@ -190,7 +200,7 @@ std::optional Self::max_response_size() const { LOG(ERROR) << "Invalid gateway request type " << static_cast(type); return std::nullopt; } -bool Self::cachable() const { +auto Self::cachable() const -> bool { using ipfs::gw::GatewayRequestType; switch (type) { // case GatewayRequestType::Car: @@ -208,7 +218,7 @@ bool Self::cachable() const { LOG(ERROR) << "Unhandled request type: " << debug_string(); return false; } -std::string Self::debug_string() const { +auto Self::debug_string() const -> std::string { std::ostringstream oss; oss << "Request{Type=" << type << ' ' << main_param; if (!path.empty()) { @@ -220,19 +230,25 @@ std::string Self::debug_string() const { oss << " plel=" << parallel << '}'; return oss.str(); } -std::string Self::Key() const { +auto Self::Key() const -> std::string { auto rv = main_param; // rv.append(" ").append(name(type)).append(" ").append(path); return rv; } -bool Self::RespondSuccessfully(std::string_view bytes, +auto Self::root_component() const -> std::string_view { + return main_param; +} +void Self::root_component(std::string_view val) { + main_param.assign(val); +} +auto Self::RespondSuccessfully(std::string_view bytes, std::shared_ptr const& api, ipld::BlockSource src, std::string_view roots, - bool* valid) { + bool* valid) -> bool { using namespace ipfs::ipld; bool success = false; - if (valid) { + if (valid != nullptr) { *valid = false; } FleshOut(src); @@ -246,25 +262,25 @@ bool Self::RespondSuccessfully(std::string_view bytes, node->source(src); } success = orchestrator_->add_node(main_param, node); - if (valid) { + if (valid != nullptr) { *valid = true; } } break; case GatewayRequestType::Ipns: if (cid.has_value()) { DCHECK(api); - auto byte_ptr = reinterpret_cast(bytes.data()); + const auto *byte_ptr = reinterpret_cast(bytes.data()); auto rec = ipfs::ValidateIpnsRecord({byte_ptr, bytes.size()}, cid.value(), *api); if (rec.has_value()) { - ValidatedIpns validated{rec.value()}; + ValidatedIpns const validated{rec.value()}; auto node = std::make_shared(validated); if (!node || node->expired()) { return false; } node->source(src); success = orchestrator_->add_node(main_param, node); - if (valid) { + if (valid != nullptr) { *valid = !node->expired(); } } else { @@ -274,7 +290,7 @@ bool Self::RespondSuccessfully(std::string_view bytes, } break; case GatewayRequestType::DnsLink: { - Cid c{roots}; + Cid const c{roots}; if (c.valid()) { AddDnsLink("/ipfs/" + c.to_string(), success, src); cid = c; @@ -293,7 +309,7 @@ bool Self::RespondSuccessfully(std::string_view bytes, LOG(ERROR) << "Unable to handle block from CAR: " << cid_s; continue; } - if (valid) { + if (valid != nullptr) { *valid = true; } if (n) { @@ -310,7 +326,7 @@ bool Self::RespondSuccessfully(std::string_view bytes, } case GatewayRequestType::Providers: success = providers::ProcessResponse(bytes, *api); - if (valid) { + if (valid != nullptr) { *valid = success; } break; @@ -338,7 +354,7 @@ void Self::Hook(BytesReceivedHook f) { void Self::orchestrator(std::shared_ptr const& orc) { orchestrator_ = orc; } -bool Self::PartiallyRedundant() const { +auto Self::PartiallyRedundant() const -> bool { if (Finished()) { return true; } @@ -347,7 +363,7 @@ bool Self::PartiallyRedundant() const { } return orchestrator_->has_key(main_param); } -bool Self::Finished() const { +auto Self::Finished() const -> bool { if (type == GatewayRequestType::Zombie) { return true; } @@ -400,7 +416,7 @@ void Self::AddBlock(std::string_view bytes, success = false; } else { node->source(src); - if (valid) { + if (valid != nullptr) { *valid = true; } success = orchestrator_->add_node(main_param, node) || success; diff --git a/library/src/ipfs_client/gw/gateway_request_type.cc b/library/src/ipfs_client/gw/gateway_request_type.cc index d67efe19..048cbe0a 100644 --- a/library/src/ipfs_client/gw/gateway_request_type.cc +++ b/library/src/ipfs_client/gw/gateway_request_type.cc @@ -1,9 +1,10 @@ #include -#include #include #include +#include +#include auto ipfs::gw::from_name(std::string_view name) -> std::optional { @@ -32,7 +33,7 @@ auto ipfs::gw::from_name(std::string_view name) } return std::nullopt; } -std::string_view ipfs::gw::name(GatewayRequestType t) { +auto ipfs::gw::name(GatewayRequestType t) -> std::string_view { using ipfs::gw::GatewayRequestType; switch (t) { case GatewayRequestType::Block: diff --git a/library/src/ipfs_client/gw/gateway_request_unittest.cc b/library/src/ipfs_client/gw/gateway_request_unittest.cc index 3db88b4e..a8fe97de 100644 --- a/library/src/ipfs_client/gw/gateway_request_unittest.cc +++ b/library/src/ipfs_client/gw/gateway_request_unittest.cc @@ -59,7 +59,7 @@ struct GatewayRequestTest : public testing::Test { GatewayRequestTest() { orc = api->with(rtor).partition({}); t_.orchestrator(orc); - t_.main_param = "main"; + t_.root_component("main"); } short timeout(RT t) { T gr; @@ -91,7 +91,7 @@ TEST_F(GatewayRequestTest, RespondsToCar) { } TEST_F(GatewayRequestTest, suffices) { t_.type = RT::Car; - EXPECT_EQ(t_.url_suffix(), "/ipfs/main/?entity-bytes=0:2097152"); + EXPECT_EQ(t_.url_suffix(), "/ipfs/main/?entity-bytes=0:3495253"); t_.type = RT::Ipns; EXPECT_EQ(t_.url_suffix(), "/ipns/main"); t_.type = RT::DnsLink; diff --git a/library/src/ipfs_client/gw/gateway_state.cc b/library/src/ipfs_client/gw/gateway_state.cc index 602b49ac..30ab3bac 100644 --- a/library/src/ipfs_client/gw/gateway_state.cc +++ b/library/src/ipfs_client/gw/gateway_state.cc @@ -1,72 +1,81 @@ #include "gateway_state.h" #include +#include +#include +#include +#include +#include +#include +#include + +#include "ipfs_client/gw/gateway_request_type.h" #include "log_macros.h" using Self = ipfs::gw::GatewayState; Self::GatewayState(std::string_view prefix, std::shared_ptr api) - : prefix_{prefix}, api_{api} { + : prefix_{prefix}, api_{std::move(api)} { DCHECK(!prefix_.empty()); last_hist_update = std::time({}); sent_counts.fill(0U); } -long Self::score(GatewayRequest const& req, unsigned baseline) const { +auto Self::score(GatewayRequest const& req, unsigned baseline) const -> long { auto result = static_cast(baseline); result += 7L * cfg().GetTypeAffinity(prefix_, req.type); - auto i = affinity_success.find(req.affinity); - if (i != affinity_success.end()) { - result += 8L * i->second; + auto aff = affinity_success.find(req.affinity); + if (aff != affinity_success.end()) { + result += 8L * aff->second; } return result; } -bool Self::over_rate(unsigned req_per_min) { +auto Self::over_rate(unsigned req_per_min) -> bool { return total_sent + current_bucket() > static_cast(req_per_min) * MinutesTracked; } -bool Self::over_rate() { +auto Self::over_rate() -> bool { return over_rate(cfg().GetGatewayRate(prefix_)); } -bool Self::bored() const { +auto Self::bored() const -> bool { return total_sent == 0UL; } void Self::just_sent_one() { current_bucket()++; ++total_sent; } -unsigned int& Self::current_bucket() { +auto Self::current_bucket() -> unsigned int& { auto now = std::time({}); while (last_hist_update < now) { ++last_hist_update; - auto& c = sent_counts[last_hist_update % sent_counts.size()]; - total_sent -= c; - c = 0; + auto& count = sent_counts[last_hist_update % sent_counts.size()]; + total_sent -= count; + count = 0; } return sent_counts[last_hist_update % sent_counts.size()]; } void Self::hit(GatewayRequestType grt, GatewayRequest const& req) { - auto& c = cfg(); - auto typaff = c.GetTypeAffinity(prefix_, grt); - c.SetTypeAffinity(prefix_, grt, std::max(typaff + 9, 1)); + auto& config = cfg(); + auto typaff = config.GetTypeAffinity(prefix_, grt); + config.SetTypeAffinity(prefix_, grt, std::max(typaff + 9, 1)); affinity_success[req.affinity] += 9; - auto rpm = c.GetGatewayRate(prefix_); - for (auto i = 8; i; --i) { + auto rpm = config.GetGatewayRate(prefix_); + for (auto i = 7; i != 0; --i) { if (over_rate(++rpm / i)) { ++rpm; } else { break; } } - c.SetGatewayRate(prefix_, rpm); + config.SetGatewayRate(prefix_, rpm); } -bool Self::miss(GatewayRequestType grt, GatewayRequest const& req) { +auto Self::miss(GatewayRequestType grt, GatewayRequest const& req) -> bool { auto& c = cfg(); auto aff = c.GetTypeAffinity(prefix_, grt); if (aff > std::numeric_limits::min()) { c.SetTypeAffinity(prefix_, grt, --aff); } auto rpm = c.GetGatewayRate(prefix_); - if (!rpm) { + if (rpm == 0U) { for (auto i = 0U;; ++i) { if (auto gw = c.GetGateway(i)) { auto& p = gw->prefix; @@ -89,7 +98,7 @@ void Self::timed_out() { if (over_rate(rpm)) { return; } - if (--rpm && !over_rate(rpm / 2)) { + if ((--rpm != 0U) && !over_rate(rpm / 2)) { --rpm; } c.SetGatewayRate(prefix_, rpm); diff --git a/library/src/ipfs_client/gw/gateway_state.h b/library/src/ipfs_client/gw/gateway_state.h index 990189e2..dd64c112 100644 --- a/library/src/ipfs_client/gw/gateway_state.h +++ b/library/src/ipfs_client/gw/gateway_state.h @@ -2,13 +2,13 @@ #define IPFS_GATEWAY_STATE_H_ #include -#include #include #include #include #include +#include namespace ipfs { class Client; @@ -25,7 +25,7 @@ class GatewayRequest; class GatewayState { std::string prefix_; std::shared_ptr api_; - flat_map affinity_success; + std::unordered_map affinity_success; static constexpr short MinutesTracked = 4; std::array sent_counts; std::size_t total_sent = 0UL; diff --git a/library/src/ipfs_client/gw/inline_request_handler.cc b/library/src/ipfs_client/gw/inline_request_handler.cc index 863f2def..d6c2961b 100644 --- a/library/src/ipfs_client/gw/inline_request_handler.cc +++ b/library/src/ipfs_client/gw/inline_request_handler.cc @@ -1,23 +1,26 @@ #include +#include +#include #include -#include -#include -#include "ipfs_client/gw/gateway_request_type.h" +#include +#include + #include "log_macros.h" using Self = ipfs::gw::InlineRequestHandler; -std::string_view Self::name() const { +auto Self::name() const -> std::string_view { return "InlineRequestHandler"; } -auto Self::handle(ipfs::gw::RequestPtr req) -> HandleOutcome { - if (req->type != GatewayRequestType::Identity) { +auto Self::handle(RequestPtr reqp) -> HandleOutcome { + GatewayRequest& req = *reqp; + if (req.type != GatewayRequestType::Identity) { return HandleOutcome::NOT_HANDLED; } - std::string data{req->identity_data()}; + std::string const data{req.identity_data()}; VLOG(2) << "Responding to inline CID without using network."; - req->RespondSuccessfully(data, api_, {}); + req.RespondSuccessfully(data, api_, {}); return HandleOutcome::DONE; } diff --git a/library/src/ipfs_client/gw/multi_gateway_requestor.cc b/library/src/ipfs_client/gw/multi_gateway_requestor.cc index 9d00cb89..4fbc8621 100644 --- a/library/src/ipfs_client/gw/multi_gateway_requestor.cc +++ b/library/src/ipfs_client/gw/multi_gateway_requestor.cc @@ -1,19 +1,34 @@ #include "multi_gateway_requestor.h" -#include #include #include +#include +#include +#include +#include +#include + #include "log_macros.h" +#include +#include +#include +#include + #include #include +#include +#include +#include +#include +#include using Self = ipfs::gw::MultiGatewayRequestor; namespace ch = std::chrono; -std::string_view Self::name() const { +auto Self::name() const -> std::string_view { return "multi-gateway requestor"; } auto Self::handle(RequestPtr r) -> HandleOutcome { @@ -35,7 +50,7 @@ void Self::Next() { Process(popped); } } -bool Self::Process(RequestPtr const& req) { +auto Self::Process(RequestPtr const& req) -> bool { if (!req->is_http()) { return false; } @@ -76,7 +91,7 @@ bool Self::Process(RequestPtr const& req) { } std::advance(state_iter, 1); } - if (std::get<2>(over_rate)) { + if (std::get<2>(over_rate) != nullptr) { candidates.push_back(over_rate); } if (candidates.empty() && config_idx <= req->failures.size()) { @@ -116,12 +131,12 @@ void Self::DoSend(RequestPtr req, std::string const& gw, GatewayState& state) { << req->debug_string(); return; } - if (state.extra_ms()) { + if (state.extra_ms() != 0) { desc->timeout_seconds += state.extra_ms() / 1000L + 1L; } auto start = ch::system_clock::now(); auto timeout_threshold = - ch::seconds(desc->timeout_seconds ? desc->timeout_seconds : 300) - + ch::seconds(desc->timeout_seconds != 0 ? desc->timeout_seconds : 300) - ch::milliseconds(1); auto hold_alive = shared_from_this(); auto cb = [this, hold_alive, req, gw, timeout_threshold, desc, start]( @@ -149,7 +164,7 @@ void Self::HandleResponse(HttpRequestDescription const& desc, return; } auto i = state_.find(gw); - if (status == 200 || !status) { + if (status == 200 || (status == 0)) { auto ct = hdrs("content-type"); auto roots = hdrs("X-Ipfs-Roots"); std::transform(ct.begin(), ct.end(), ct.begin(), ::tolower); @@ -158,9 +173,9 @@ void Self::HandleResponse(HttpRequestDescription const& desc, src.cat.gateway_url = gw; if (ct.empty()) { LOG(ERROR) << "No content-type header?"; - } else if (desc.accept.size() && + } else if ((!desc.accept.empty()) && ct.find(desc.accept) == std::string::npos) { - if (roots.size() && req->type == GatewayRequestType::DnsLink && req->RespondSuccessfully("", api_, src, roots)) { + if ((!roots.empty()) && req->type == GatewayRequestType::DnsLink && req->RespondSuccessfully("", api_, src, roots)) { LOG(INFO) << "Wrong accept on a DNSLink request, but we still got the resolution."; return; } diff --git a/library/src/ipfs_client/gw/multi_gateway_requestor.h b/library/src/ipfs_client/gw/multi_gateway_requestor.h index c7e6c7d8..f3b9397b 100644 --- a/library/src/ipfs_client/gw/multi_gateway_requestor.h +++ b/library/src/ipfs_client/gw/multi_gateway_requestor.h @@ -12,6 +12,8 @@ #include namespace ipfs::gw { +/*! Sends requests to multiple gateways + */ class MultiGatewayRequestor : public Requestor { std::map state_; std::deque q; diff --git a/library/src/ipfs_client/gw/multi_gateway_requestor_unittest.cc b/library/src/ipfs_client/gw/multi_gateway_requestor_unittest.cc index 7a63fb0c..d7daca74 100644 --- a/library/src/ipfs_client/gw/multi_gateway_requestor_unittest.cc +++ b/library/src/ipfs_client/gw/multi_gateway_requestor_unittest.cc @@ -9,8 +9,8 @@ namespace { ig::RequestPtr block_req() { auto rv = std::make_shared(); rv->type = RT::Block; - rv->main_param = - "bafybeid4dzlxm6h4r6kfvx6jp6vj4nteplmbve224lx2s3lgjubyufsuo4"; + rv->root_component( + "bafybeid4dzlxm6h4r6kfvx6jp6vj4nteplmbve224lx2s3lgjubyufsuo4"); return rv; } } // namespace diff --git a/library/src/ipfs_client/gw/providers_response.cc b/library/src/ipfs_client/gw/providers_response.cc index 5816e947..35a3d362 100644 --- a/library/src/ipfs_client/gw/providers_response.cc +++ b/library/src/ipfs_client/gw/providers_response.cc @@ -4,6 +4,8 @@ #include #include +#include +#include #include "log_macros.h" @@ -12,40 +14,47 @@ using namespace std::literals; namespace prov = ipfs::providers; namespace { -bool default_port(std::string_view scheme, std::string_view port) { - if (scheme == "http") { - return port == "80"; - } else if (scheme == "https") { - return port == "443"; - } else { - LOG(ERROR) - << "Expected gateway's scheme to be either http or https, but it was '" - << scheme << "'."; - return false; +class Scheme { + char last_ = '!'; + public: + Scheme(std::string_view const name) + { + if (name.starts_with("http")) { + last_ = name.back(); + } } -} -std::string MultiaddrToGatewayPrefix(ipfs::SlashDelimited ma, bool http) { - /* auto addr_proto = */ ma.pop(); - auto host = ma.pop(); - auto tcp = ma.pop(); + [[nodiscard]] auto is_default_port(std::string_view port) const -> bool { + switch (last_) { + case 'p': return port == "80"; + case 's': return port == "443"; + default: return false; + } + } +}; + +auto MultiaddrToGatewayPrefix(ipfs::SlashDelimited maddr, bool http) -> std::string { + /* auto addr_proto = */ maddr.pop(); + auto host = maddr.pop(); + auto tcp = maddr.pop(); DCHECK_EQ(tcp, "tcp"); - auto port = ma.pop(); - auto app_proto = ma.pop(); + auto port = maddr.pop(); + auto app_proto = maddr.pop(); if (app_proto == "http" && !http) { LOG(INFO) << "Rejecting http:// gateway discovery due to config."; return ""; } DCHECK_EQ(app_proto.substr(0, 4), "http"); - std::string rv{app_proto}; - rv.append("://").append(host); - if (!default_port(app_proto, port)) { - rv.append(":").append(port); + std::string prefix{app_proto}; + prefix.append("://").append(host); + Scheme const schm{app_proto}; + if (!schm.is_default_port(port)) { + prefix.append(":").append(port); } - rv.append("/").append(ma.to_view()); - return rv; + prefix.append("/").append(maddr.to_view()); + return prefix; } -bool ParseProvider(ipfs::DagJsonValue const& provider, ipfs::Client& api) { +auto ParseProvider(ipfs::DagJsonValue const& provider, ipfs::Client& api) -> bool { auto proto = provider["Protocol"sv]; if (!proto) { // Perhaps Schema == peer. Not an error, but not used as of now. @@ -71,9 +80,9 @@ bool ParseProvider(ipfs::DagJsonValue const& provider, ipfs::Client& api) { if (auto s = addr.get_if_string()) { auto& c = api.gw_cfg(); auto http = c.RoutingApiDiscoveryOfUnencryptedGateways(); - ipfs::SlashDelimited sd{s.value()}; + ipfs::SlashDelimited const sd{s.value()}; auto gw_pre = MultiaddrToGatewayPrefix(sd, http); - if (gw_pre.size()) { + if (static_cast(!gw_pre.empty()) != 0U) { c.AddGateway(gw_pre, c.RoutingApiDiscoveryDefaultRate()); rv = true; } @@ -91,7 +100,7 @@ bool ParseProvider(ipfs::DagJsonValue const& provider, ipfs::Client& api) { } } // namespace -bool prov::ProcessResponse(std::string_view json_str, Client& api) { +auto prov::ProcessResponse(std::string_view json_str, Client& api) -> bool { if (json_str.empty()) { LOG(ERROR) << "Empty body in response to routing/v1 providers request."; return false; diff --git a/library/src/ipfs_client/gw/requestor.cc b/library/src/ipfs_client/gw/requestor.cc index c10ef491..2a750d98 100644 --- a/library/src/ipfs_client/gw/requestor.cc +++ b/library/src/ipfs_client/gw/requestor.cc @@ -7,13 +7,15 @@ #include #include #include +#include +#include "ipfs_client/gw/gateway_request_type.h" #include "log_macros.h" using Self = ipfs::gw::Requestor; using ReqPtr = std::shared_ptr; -Self& Self::or_else(std::shared_ptr p) { +auto Self::or_else(std::shared_ptr p) -> Self& { if (next_) { next_->or_else(p); } else { @@ -56,7 +58,7 @@ void Self::request(ReqPtr req) { break; } } -void Self::definitive_failure(ipfs::gw::RequestPtr r) const { +void Self::definitive_failure(ipfs::gw::RequestPtr r) { if (!r) { LOG(ERROR) << "nullptr definitively failing?"; } else if (!(r->dependent)) { @@ -73,7 +75,7 @@ void Self::forward(ipfs::gw::RequestPtr req) const { next_->request(req); } } -Self& Self::api(std::shared_ptr a) { +auto Self::api(std::shared_ptr a) -> Self& { api_ = a; return *this; } diff --git a/library/src/ipfs_client/gw/requestor_pool.h b/library/src/ipfs_client/gw/requestor_pool.h deleted file mode 100644 index 86104319..00000000 --- a/library/src/ipfs_client/gw/requestor_pool.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef IPFS_REQUESTOR_POOL_H_ -#define IPFS_REQUESTOR_POOL_H_ - -#include - -#include - -#include -#include -#include - -namespace ipfs::gw { -class RequestorPool : public Requestor { - std::string_view name() const override; - HandleOutcome handle(RequestPtr) override; - - std::vector> pool_; - struct Waiting { - RequestPtr req; - std::size_t at_idx; - std::time_t when; - }; - std::queue waiting_; - - HandleOutcome check(Waiting); - - public: - RequestorPool& add(std::shared_ptr); -}; -} // namespace ipfs::gw - -#endif // IPFS_REQUESTOR_POOL_H_ diff --git a/library/src/ipfs_client/gw/terminating_requestor.cc b/library/src/ipfs_client/gw/terminating_requestor.cc index f23c3426..0ec5d55e 100644 --- a/library/src/ipfs_client/gw/terminating_requestor.cc +++ b/library/src/ipfs_client/gw/terminating_requestor.cc @@ -1,25 +1,29 @@ #include "ipfs_client/gw/terminating_requestor.h" +#include +#include #include -#include "ipfs_client/gw/gateway_request_type.h" #include "log_macros.h" +#include + using Self = ipfs::gw::TerminatingRequestor; -std::string_view Self::name() const { +auto Self::name() const -> std::string_view { return "Terminating requestor"; } -auto Self::handle(ipfs::gw::RequestPtr r) -> HandleOutcome { - if (r->Finished()) { +auto Self::handle(RequestPtr reqp) -> HandleOutcome { + GatewayRequest& req = *reqp; + if (req.Finished()) { return HandleOutcome::DONE; - } else if (r->parallel) { + } else if (req.parallel != 0) { return HandleOutcome::PENDING; } else { LOG(ERROR) << "Out of options, giving up on gateway request " - << r->debug_string(); - definitive_failure(r); - r->type = GatewayRequestType::Zombie; + << req.debug_string(); + definitive_failure(reqp); + req.type = GatewayRequestType::Zombie; return HandleOutcome::DONE; } } diff --git a/library/src/ipfs_client/http_request_description.cc b/library/src/ipfs_client/http_request_description.cc index 19b29d0c..0ff18cf6 100644 --- a/library/src/ipfs_client/http_request_description.cc +++ b/library/src/ipfs_client/http_request_description.cc @@ -2,11 +2,11 @@ using Self = ipfs::HttpRequestDescription; -bool Self::operator==(HttpRequestDescription const& r) const { +auto Self::operator==(HttpRequestDescription const& r) const -> bool { // The concept of identity does NOT involve feedback-looping timeout fudge // Nor is the acceptable size of a response necessary to distinguish. return url == r.url && accept == r.accept; } -bool Self::operator<(HttpRequestDescription const& r) const { +auto Self::operator<(HttpRequestDescription const& r) const -> bool { return url == r.url ? accept < r.accept : url < r.url; } \ No newline at end of file diff --git a/library/src/ipfs_client/identity_cid.cc b/library/src/ipfs_client/identity_cid.cc index 0964f8d8..efc7b452 100644 --- a/library/src/ipfs_client/identity_cid.cc +++ b/library/src/ipfs_client/identity_cid.cc @@ -1,14 +1,20 @@ #include #include +#include +#include "ipfs_client/cid.h" +#include "ipfs_client/multi_hash.h" +#include "vocab/byte.h" +#include "vocab/byte_view.h" +#include "ipfs_client/multicodec.h" namespace Self = ipfs::id_cid; auto Self::forText(std::string_view txt) -> Cid { txt = txt.substr(0UL, MaximumHashLength); - auto p = reinterpret_cast(txt.data()); + const auto *p = reinterpret_cast(txt.data()); auto b = ByteView{p, txt.size()}; - MultiHash mh(HashType::IDENTITY, b); + MultiHash const mh(HashType::IDENTITY, b); if (mh.valid()) { return Cid{MultiCodec::RAW, mh}; } else { diff --git a/library/src/ipfs_client/ipfs_request.cc b/library/src/ipfs_client/ipfs_request.cc index 3fcd7b39..7807ac76 100644 --- a/library/src/ipfs_client/ipfs_request.cc +++ b/library/src/ipfs_client/ipfs_request.cc @@ -2,14 +2,17 @@ #include -#include "log_macros.h" +#include "ipfs_client/response_semantic.h" #include +#include +#include +#include using Self = ipfs::IpfsRequest; Self::IpfsRequest(std::string path_p, Finisher f) - : path_{path_p}, callback_{f}, semantic_{ResponseSemantic::Http} {} + : path_{std::move(path_p)}, callback_{std::move(f)}, semantic_{ResponseSemantic::Http} {} Self::~IpfsRequest() noexcept { for (auto& cleanup : cleanups_) { @@ -23,7 +26,7 @@ Self::~IpfsRequest() noexcept { } } -std::shared_ptr Self::fromUrl(std::string url, ipfs::IpfsRequest::Finisher f) { +auto Self::fromUrl(std::string url, ipfs::IpfsRequest::Finisher f) -> std::shared_ptr { url.erase(4UL, 2UL ); url.insert(0UL, 1UL, '/'); return std::make_shared(std::move(url), std::move(f)); @@ -42,10 +45,10 @@ void Self::finish(ipfs::Response& r) { void Self::new_path(std::string_view sv) { path_.assign(sv); } -bool Self::done() const { +auto Self::done() const -> bool { return !callback_; } -Self& Self::semantic(std::string_view sem) { +auto Self::semantic(std::string_view sem) -> Self& { if (sem.find("isting") == 1UL) { semantic_ = ResponseSemantic::Listing; } else { diff --git a/library/src/ipfs_client/ipld/block_source.cc b/library/src/ipfs_client/ipld/block_source.cc index 92cc0b66..f9e2b753 100644 --- a/library/src/ipfs_client/ipld/block_source.cc +++ b/library/src/ipfs_client/ipld/block_source.cc @@ -1,11 +1,13 @@ #include +#include #include -#include +#include +#include +#include "ipfs_client/gw/gateway_request_type.h" using Self = ipfs::ipld::BlockSource; -namespace c = std::chrono; /* namespace { @@ -19,7 +21,7 @@ static_assert(a < b); } // namespace */ -std::string Self::Serialize() const { +auto Self::Serialize() const -> std::string { std::ostringstream result; result << name(cat.request_type) << ' ' << cat.cached << ' ' << cid << ' ' << Clock::to_time_t(fetched_at) << ' ' << cat.gateway_url; diff --git a/library/src/ipfs_client/ipld/chunk.cc b/library/src/ipfs_client/ipld/chunk.cc index 2737a448..f2985024 100644 --- a/library/src/ipfs_client/ipld/chunk.cc +++ b/library/src/ipfs_client/ipld/chunk.cc @@ -1,15 +1,25 @@ #include "chunk.h" +#include +#include +#include + #include "log_macros.h" +#include +#include +#include + +constexpr std::uint16_t cSuccess = 200U; + using Chunk = ipfs::ipld::Chunk; -Chunk::Chunk(std::string data) : data_{data} {} +Chunk::Chunk(std::string data) : data_{std::move(data)} {} Chunk::~Chunk() noexcept = default; auto Chunk::resolve(ResolutionState& params) -> ResolveResult { if (params.IsFinalComponent()) { - return Response{"", 200, data_, params.MyPath().to_string(), {}}; + return Response{"", cSuccess, data_, params.MyPath().to_string(), {}}; } else { VLOG(2) << "Can't resolve a path (" << params.MyPath() << ") inside of a file chunk!"; diff --git a/library/src/ipfs_client/ipld/dag_cbor_node.cc b/library/src/ipfs_client/ipld/dag_cbor_node.cc index 57ae0858..e257d023 100644 --- a/library/src/ipfs_client/ipld/dag_cbor_node.cc +++ b/library/src/ipfs_client/ipld/dag_cbor_node.cc @@ -1,16 +1,24 @@ #include "dag_cbor_node.h" +#include +#include +#include +#include -#include "log_macros.h" +#include "ipfs_client/ipld/resolution_state.h" +#include "ipfs_client/ipld/dag_node.h" +#include "ipfs_client/response.h" using Self = ipfs::ipld::DagCborNode; +constexpr std::uint16_t cSuccess = 200U; + auto Self::resolve(ResolutionState& params) -> ResolveResult { if (auto cid = doc_->as_link()) { auto cid_str = cid.value().to_string(); return CallChild(params, "", cid_str); } if (params.IsFinalComponent()) { - return Response{"text/html", 200, doc_->html(), params.PathToResolve().to_string(), {}}; + return Response{"text/html", cSuccess, doc_->html(), params.PathToResolve().to_string(), {}}; } return CallChild(params, [this](std::string_view element_name) -> NodePtr { if (auto child = doc_->at(element_name)) { @@ -20,5 +28,5 @@ auto Self::resolve(ResolutionState& params) -> ResolveResult { }); } -Self::DagCborNode(std::unique_ptr p) : doc_{std::move(p)} {} +Self::DagCborNode(std::unique_ptr docptr) : doc_{std::move(docptr)} {} Self::~DagCborNode() noexcept = default; diff --git a/library/src/ipfs_client/ipld/dag_headers.cc b/library/src/ipfs_client/ipld/dag_headers.cc index 363215b8..129e1eb2 100644 --- a/library/src/ipfs_client/ipld/dag_headers.cc +++ b/library/src/ipfs_client/ipld/dag_headers.cc @@ -1,15 +1,19 @@ #include +#include #include +#include +#include -#include "log_macros.h" +#include "ipfs_client/gw/gateway_request_type.h" +#include "ipfs_client/ipld/block_source.h" using Self = ipfs::ipld::DagHeaders; using ReqTyp = ipfs::gw::GatewayRequestType; namespace c = std::chrono; namespace { -std::string_view describe(ReqTyp t) { +auto describe(ReqTyp t) -> std::string_view { switch (t) { case ReqTyp::DnsLink: return "Resolving a DNSLink via DNS TXT record"; @@ -49,14 +53,14 @@ void Self::Add(BlockSource const& src) { value << "\";dur=" << c::duration_cast(src.load_duration).count(); headers_.emplace_back("Server-Timing", value.str()); - if (src.cid.size()) { + if (static_cast(!src.cid.empty()) != 0U) { auto from = src.cat.cached ? std::string{"cache"} : src.cat.gateway_url; headers_.emplace_back("IPFS-Source-" + src.cid, from); } } } void Self::Finish() { - if (!other_count_) { + if (other_count_ == 0U) { return; } std::ostringstream value; diff --git a/library/src/ipfs_client/ipld/dag_json_node.cc b/library/src/ipfs_client/ipld/dag_json_node.cc index ee1ef5eb..37e94437 100644 --- a/library/src/ipfs_client/ipld/dag_json_node.cc +++ b/library/src/ipfs_client/ipld/dag_json_node.cc @@ -2,7 +2,18 @@ #include +#include +#include #include +#include "ipfs_client/dag_json_value.h" +#include +#include "ipfs_client/ipld/link.h" +#include "ipfs_client/ipld/resolution_state.h" +#include "ipfs_client/ipld/dag_node.h" +#include +#include "ipfs_client/response.h" +#include +#include using Self = ipfs::ipld::DagJsonNode; @@ -12,7 +23,7 @@ Self::DagJsonNode(std::unique_ptr j) : data_(std::move(j)) { return; } auto cid_str = cid->to_string(); - if (cid_str.size()) { + if (static_cast(!cid_str.empty()) != 0U) { links_.emplace_back("", Link(cid_str)); } } @@ -20,7 +31,7 @@ Self::~DagJsonNode() noexcept = default; auto Self::resolve(ResolutionState& params) -> ResolveResult { auto respond_as_link = CallChild(params, ""); - if (!std::get_if(&respond_as_link)) { + if (std::get_if(&respond_as_link) == nullptr) { return respond_as_link; } if (params.IsFinalComponent()) { @@ -83,7 +94,7 @@ void write_body(std::ostream& str, ipfs::DagJsonValue const& val) { } } } // namespace -std::string const& Self::html() { +auto Self::html() -> std::string const& { if (html_.empty()) { std::ostringstream html; html << "Preview of DAG-JSON\n"; diff --git a/library/src/ipfs_client/ipld/dag_node.cc b/library/src/ipfs_client/ipld/dag_node.cc index 51e5e83f..a626d4d9 100644 --- a/library/src/ipfs_client/ipld/dag_node.cc +++ b/library/src/ipfs_client/ipld/dag_node.cc @@ -4,7 +4,9 @@ #include "dag_cbor_node.h" #include "dag_json_node.h" #include "directory_shard.h" -#include "dnslink_name.h" +#include "ipfs_client/multicodec.h" +#include "ipfs_client/ipld/resolution_state.h" +#include "ipfs_client/ipld/link.h" #include "root.h" #include "small_directory.h" #include "symlink.h" @@ -15,16 +17,26 @@ #include #include "log_macros.h" +#include "vocab/byte_view.h" +#include "vocab/byte.h" #include +#include +#include +#include +#include +#include #include +#include +#include +#include using Node = ipfs::ipld::DagNode; Node::~DagNode() noexcept = default; -std::shared_ptr Node::fromBytes(std::shared_ptr const& api, +auto Node::fromBytes(std::shared_ptr const& api, Cid const& cid, - std::string_view bytes) { + std::string_view bytes) -> std::shared_ptr { return fromBytes(api, cid, as_bytes(bytes)); } auto Node::fromBytes(std::shared_ptr const& api, @@ -56,7 +68,7 @@ auto Node::fromBytes(std::shared_ptr const& api, } switch (cid.codec()) { case MultiCodec::DAG_CBOR: { - auto p = reinterpret_cast(bytes.data()); + const auto *p = reinterpret_cast(bytes.data()); auto cbor = api->cbor().Parse({p, bytes.size()}); if (cbor) { result = std::make_shared(std::move(cbor)); @@ -66,7 +78,7 @@ auto Node::fromBytes(std::shared_ptr const& api, } } break; case MultiCodec::DAG_JSON: { - auto p = reinterpret_cast(bytes.data()); + const auto *p = reinterpret_cast(bytes.data()); auto json = api->json().Parse({p, bytes.size()}); if (json) { result = std::make_shared(std::move(json)); @@ -77,7 +89,7 @@ auto Node::fromBytes(std::shared_ptr const& api, } break; case MultiCodec::RAW: case MultiCodec::DAG_PB: { - ipfs::PbDag b{cid, bytes}; + ipfs::PbDag const b{cid, bytes}; if (b.valid()) { result = fromBlock(b); } else { @@ -104,7 +116,7 @@ auto Node::fromBytes(std::shared_ptr const& api, } return result; } -std::shared_ptr Node::fromBlock(ipfs::PbDag const& block) { +auto Node::fromBlock(ipfs::PbDag const& block) -> std::shared_ptr { std::shared_ptr result; switch (block.type()) { case PbDag::Type::FileChunk: @@ -147,10 +159,10 @@ std::shared_ptr Node::fromBlock(ipfs::PbDag const& block) { return result; } -std::shared_ptr Node::deroot() { +auto Node::deroot() -> std::shared_ptr { return shared_from_this(); } -std::shared_ptr Node::rooted() { +auto Node::rooted() -> std::shared_ptr { return std::make_shared(shared_from_this()); } void Node::set_api(std::shared_ptr api) { @@ -164,7 +176,7 @@ auto Node::resolve(SlashDelimited initial_path, BlockLookup blu) } */ auto Node::Resolve(ResolutionState& params) -> ResolveResult { - if (source_.cid.size()) { + if (static_cast(!source_.cid.empty()) != 0U) { params.headers.Add(source_); } return resolve(params); @@ -175,8 +187,8 @@ auto Node::CallChild(ipfs::ipld::ResolutionState& state) -> ResolveResult { auto Node::CallChild(ipfs::ipld::ResolutionState& state, std::string_view link_key, std::string_view block_key) -> ResolveResult { - auto child = FindChild(link_key); - if (!child) { + auto *child = FindChild(link_key); + if (child == nullptr) { links_.emplace_back(link_key, Link{std::string{block_key}, {}}); } return CallChild(state, link_key); @@ -184,7 +196,7 @@ auto Node::CallChild(ipfs::ipld::ResolutionState& state, auto Node::CallChild(ResolutionState& state, std::string_view link_key) -> ResolveResult { auto* child = FindChild(link_key); - if (!child) { + if (child == nullptr) { return ProvenAbsent{}; } auto& node = child->node; @@ -198,7 +210,7 @@ auto Node::CallChild(ResolutionState& state, std::string_view link_key) std::string needed{"/ipfs/"}; needed.append(child->cid); auto more = state.PathToResolve().to_view(); - if (more.size()) { + if (static_cast(!more.empty()) != 0U) { if (more.front() != '/') { needed.push_back('/'); } @@ -211,8 +223,8 @@ auto Node::CallChild(ResolutionState& state, std::function gen_child) -> ResolveResult { auto link_key = state.NextComponent(api_.get()); - auto child = FindChild(link_key); - if (!child) { + auto *child = FindChild(link_key); + if (child == nullptr) { links_.emplace_back(link_key, Link{{}, {}}); child = &links_.back().second; } @@ -234,13 +246,13 @@ auto Node::FindChild(std::string_view link_key) -> Link* { } return nullptr; } -bool Node::expired() const { +auto Node::expired() const -> bool { return false; } -bool Node::PreferOver(Node const&) const { +auto Node::PreferOver(Node const& /*unused*/) const -> bool { return false; } -std::ostream& operator<<(std::ostream& s, ipfs::ipld::PathChange const& c) { +auto operator<<(std::ostream& s, ipfs::ipld::PathChange const& c) -> std::ostream& { return s << "PathChange{" << c.new_path << '}'; } diff --git a/library/src/ipfs_client/ipld/dag_node_unittest.cc b/library/src/ipfs_client/ipld/dag_node_unittest.cc new file mode 100644 index 00000000..88ad109f --- /dev/null +++ b/library/src/ipfs_client/ipld/dag_node_unittest.cc @@ -0,0 +1,37 @@ +#include +#include + +#include +#include + +using T = ii::DagNode; + +namespace { +struct DagNodeTest : public ::testing::Test { + std::shared_ptr api = std::make_shared(); +}; +} + +TEST_F(DagNodeTest,ConstructDagJson) { + i::Cid cid{"baguqeaaeejugsiq"}; + auto p = T::fromBytes(api, cid, "\"hi\""); + ASSERT_TRUE(p); + auto d = dynamic_cast(p.get()); + ASSERT_TRUE(d); +} +TEST_F(DagNodeTest,DnsLinkIs) { + ii::DnsLinkName d{"/ipfs/baguqeaaeejugsiq"}; + auto p = static_cast(&d); + ASSERT_TRUE(p); + auto down = p->as_dnslink(); + EXPECT_TRUE(down); + EXPECT_TRUE(down == &d); +} +TEST_F(DagNodeTest,DagJsonIsNotOtherTHings) { + i::Cid cid{"baguqeaaeejugsiq"}; + auto p = T::fromBytes(api, cid, "\"hi\""); + ASSERT_TRUE(p); + EXPECT_FALSE(p->as_dnslink()); + EXPECT_FALSE(p->as_hamt()); + EXPECT_FALSE(p->as_ipns()); +} diff --git a/library/src/ipfs_client/ipld/directory_shard.cc b/library/src/ipfs_client/ipld/directory_shard.cc index c1f25267..db48e121 100644 --- a/library/src/ipfs_client/ipld/directory_shard.cc +++ b/library/src/ipfs_client/ipld/directory_shard.cc @@ -1,22 +1,33 @@ #include "directory_shard.h" +#include "ipfs_client/response.h" +#include "ipfs_client/ipld/resolution_state.h" +#include "ipfs_client/ipld/dag_node.h" +#include "ipfs_client/response_semantic.h" #include "log_macros.h" -#include #include #include #include +#include +#include #include +#include +#include #include +#include +#include +#include +#include using namespace std::literals; using Self = ipfs::ipld::DirShard; namespace { - ipfs::Response DynamicListingHtml(std::string_view path); + auto DynamicListingHtml(std::string_view path) -> ipfs::Response; } auto Self::resolve(ResolutionState& parms) -> ResolveResult { @@ -27,15 +38,15 @@ auto Self::resolve(ResolutionState& parms) -> ResolveResult { // index.html hashes A0 6D 7E C8 78 79 38 1D B3 8D 36 0D 76 FA 7B BF auto index_parm = parms.WithPath("index.html"sv); auto result = resolve(index_parm); - auto resp = std::get_if(&result); - if (resp) { + auto *resp = std::get_if(&result); + if (resp != nullptr) { resp->mime_ = "text/html"; } else if (std::holds_alternative(result)){ return DynamicListingHtml(parms.MyPath().to_view()); } return result; } - std::string name{parms.NextComponent(api_.get())}; + std::string const name{parms.NextComponent(api_.get())}; auto hash = hexhash(name); return resolve_internal(hash.begin(), hash.end(), name, parms); } @@ -46,10 +57,10 @@ auto Self::resolve_internal(ipfs::ipld::DirShard::HashIter hash_b, auto hash_chunk = hash_b == hash_e ? std::string{} : *hash_b; auto needed_size = hash_chunk.size() + human_name.size(); for (auto& [name, link] : links_) { - if (!starts_with(name, hash_chunk)) { + if (!name.starts_with(hash_chunk)) { continue; } - if (name.size() == needed_size && ends_with(name, human_name)) { + if (name.size() == needed_size && name.ends_with(human_name)) { return CallChild(parms, name); } auto node = parms.GetBlock(link.cid); @@ -60,8 +71,8 @@ auto Self::resolve_internal(ipfs::ipld::DirShard::HashIter hash_b, // partially-consumed hash return MoreDataNeeded{{"/ipfs/" + link.cid}}; } - auto downcast = node->as_hamt(); - if (downcast) { + auto *downcast = node->as_hamt(); + if (downcast != nullptr) { if (hash_b == hash_e) { LOG(ERROR) << "Ran out of hash bits."; return ProvenAbsent{}; @@ -74,11 +85,11 @@ auto Self::resolve_internal(ipfs::ipld::DirShard::HashIter hash_b, } return ProvenAbsent{}; } -std::string Self::listing_json() const { +auto Self::listing_json() const -> std::string { std::string result{"{"}; auto first = true; auto const w = hex_width(); - for (auto& [index, link] : links_) { + for (const auto& [index, link] : links_) { auto hash_bits = std::string_view{index}.substr(0, w); if (first) { first = false; @@ -87,7 +98,7 @@ std::string Self::listing_json() const { } result.append("\n ").push_back('"'); result.append(hash_bits) - .append("\": {\"cid\": \"") + .append(R"(": {"cid": ")") .append(link.cid) .push_back('"'); if (index.size() > w) { @@ -96,7 +107,7 @@ std::string Self::listing_json() const { while ((quot = name.find('"')) < name.size()) { name.insert(quot, 1UL, '\\'); } - result.append(", \"name\": \"") + result.append(R"(, "name": ")") .append(name) .push_back('"'); } @@ -105,7 +116,7 @@ std::string Self::listing_json() const { result.append("\n}"); return result; } -std::size_t Self::hex_width() const { +auto Self::hex_width() const -> std::size_t { auto rv = 0U; for (auto x = fanout_; x > 1; ++rv) { x >>= 4; @@ -116,14 +127,14 @@ std::size_t Self::hex_width() const { return rv; } -std::vector Self::hexhash(std::string_view path_element) const { +auto Self::hexhash(std::string_view path_element) const -> std::vector { std::array digest = {0U, 0U}; MurmurHash3_x64_128(path_element.data(), static_cast(path_element.size()), 0, digest.data()); std::vector result; for (auto d : digest) { auto hash_bits = htobe64(d); - while (hash_bits) { + while (hash_bits != 0U) { // 2. Pop the log2(fanout_) lowest bits from the path component hash // digest,... auto popped = hash_bits % fanout_; @@ -140,12 +151,12 @@ std::vector Self::hexhash(std::string_view path_element) const { Self::DirShard(std::uint64_t fanout) : fanout_{fanout} {} Self::~DirShard() noexcept = default; -Self* Self::as_hamt() { +auto Self::as_hamt() -> Self* { return this; } namespace { - ipfs::Response DynamicListingHtml(std::string_view path) { + auto DynamicListingHtml(std::string_view path) -> ipfs::Response { std::string body = "\n\t\n\t\tDirectory Listing for "; body.append(path); if (!path.ends_with('/')) { diff --git a/library/src/ipfs_client/ipld/dnslink_name.cc b/library/src/ipfs_client/ipld/dnslink_name.cc index 77331d7e..3ec60c3a 100644 --- a/library/src/ipfs_client/ipld/dnslink_name.cc +++ b/library/src/ipfs_client/ipld/dnslink_name.cc @@ -1,6 +1,13 @@ #include "dnslink_name.h" +#include <string_view> +#include <chrono> +#include <variant> +#include "ipfs_client/ipld/link.h" +#include "ipfs_client/ipld/resolution_state.h" +#include "ipfs_client/ipld/dag_node.h" #include "log_macros.h" +#include "vocab/slash_delimited.h" using Self = ipfs::ipld::DnsLinkName; namespace ch = std::chrono; @@ -42,12 +49,12 @@ auto Self::resolve(ResolutionState& params) -> ResolveResult { } return lower; } -bool Self::expired() const { +auto Self::expired() const -> bool { return expiration_ < ch::system_clock::now(); } -bool Self::PreferOver(DagNode const& another) const { - auto* other = another.as_dnslink(); - if (!other) { +auto Self::PreferOver(DagNode const& another) const -> bool { + const auto* other = another.as_dnslink(); + if (other == nullptr) { return true; } return expiration_ > other->expiration_ + ch::seconds(1); diff --git a/library/src/ipfs_client/ipld/ipns_name.cc b/library/src/ipfs_client/ipld/ipns_name.cc index 941902f7..c9827cfa 100644 --- a/library/src/ipfs_client/ipld/ipns_name.cc +++ b/library/src/ipfs_client/ipld/ipns_name.cc @@ -1,8 +1,15 @@ #include "ipns_name.h" #include <ipfs_client/ipns_record.h> +#include <chrono> +#include <algorithm> +#include <variant> +#include "ipfs_client/ipld/link.h" +#include "ipfs_client/ipld/resolution_state.h" +#include "ipfs_client/ipld/dag_node.h" #include "log_macros.h" +#include "vocab/slash_delimited.h" using Self = ipfs::ipld::IpnsName; namespace ch = std::chrono; @@ -47,12 +54,12 @@ auto Self::resolve(ResolutionState& params) -> ResolveResult { } return lower; } -bool Self::expired() const { +auto Self::expired() const -> bool { return expiration_ < ch::system_clock::now(); } -bool Self::PreferOver(DagNode const& another) const { - auto other = another.as_ipns(); - if (!other) { +auto Self::PreferOver(DagNode const& another) const -> bool { + const auto *other = another.as_ipns(); + if (other == nullptr) { return true; } return serial_ > other->serial_; diff --git a/library/src/ipfs_client/ipld/link.cc b/library/src/ipfs_client/ipld/link.cc index f9dad98e..b645cc12 100644 --- a/library/src/ipfs_client/ipld/link.cc +++ b/library/src/ipfs_client/ipld/link.cc @@ -1,6 +1,10 @@ #include "ipfs_client/ipld/link.h" +#include <utility> +#include <string> +#include <memory> + using Self = ipfs::ipld::Link; -Self::Link(std::string cid_s) : cid{cid_s} {} -Self::Link(std::string s, std::shared_ptr<DagNode> n) : cid{s}, node{n} {} +Self::Link(std::string cid_s) : cid{std::move(cid_s)} {} +Self::Link(std::string s, std::shared_ptr<DagNode> n) : cid{std::move(s)}, node{std::move(n)} {} diff --git a/library/src/ipfs_client/ipld/resolution_state.cc b/library/src/ipfs_client/ipld/resolution_state.cc index e11740ae..d0a0f5ed 100644 --- a/library/src/ipfs_client/ipld/resolution_state.cc +++ b/library/src/ipfs_client/ipld/resolution_state.cc @@ -1,6 +1,12 @@ #include <ipfs_client/ipld/resolution_state.h> #include <ipfs_client/client.h> +#include "vocab/slash_delimited.h" +#include "ipfs_client/response_semantic.h" + +#include <utility> +#include <string> +#include <string_view> using Self = ipfs::ipld::ResolutionState; @@ -10,9 +16,9 @@ Self::ResolutionState(SlashDelimited path_to_resolve, : unresolved_path(path_to_resolve), semantic_{sem}, - get_available_block(blu) {} + get_available_block(std::move(blu)) {} -bool Self::IsFinalComponent() const { +auto Self::IsFinalComponent() const -> bool { return !unresolved_path; } auto Self::PathToResolve() const -> SlashDelimited { @@ -21,9 +27,9 @@ auto Self::PathToResolve() const -> SlashDelimited { auto Self::MyPath() const -> SlashDelimited { return SlashDelimited{resolved_path_components}; } -std::string Self::NextComponent(Client* api) const { +auto Self::NextComponent(Client* api) const -> std::string { auto copy = unresolved_path; - if (api) { + if (api != nullptr) { return api->UnescapeUrlComponent(copy.pop()); } else { return std::string{copy.pop()}; @@ -32,15 +38,15 @@ std::string Self::NextComponent(Client* api) const { auto Self::GetBlock(std::string const& block_key) const -> NodePtr { return get_available_block(block_key); } -Self Self::WithPath(std::string_view p) const { - auto rv = *this; - rv.unresolved_path = SlashDelimited{p}; - return rv; +auto Self::WithPath(std::string_view new_path) const -> Self { + auto result = *this; + result.unresolved_path = SlashDelimited{new_path}; + return result; } auto Self::RestartResolvedPath() const -> ResolutionState { - auto rv = *this; - rv.resolved_path_components.clear(); - return rv; + auto newme = *this; + newme.resolved_path_components.clear(); + return newme; } void Self::Descend() { auto next = unresolved_path.pop(); diff --git a/library/src/ipfs_client/ipld/root.cc b/library/src/ipfs_client/ipld/root.cc index def01f2b..36c60cac 100644 --- a/library/src/ipfs_client/ipld/root.cc +++ b/library/src/ipfs_client/ipld/root.cc @@ -1,5 +1,12 @@ #include "root.h" +#include <memory> +#include <variant> +#include "ipfs_client/ipld/dag_node.h" +#include "ipfs_client/ipld/link.h" +#include "ipfs_client/ipld/resolution_state.h" +#include "ipfs_client/response.h" +#include "ipfs_client/redirects.h" #include "log_macros.h" using namespace std::literals; @@ -12,13 +19,13 @@ Self::Root(std::shared_ptr<DagNode> under) { } Self::~Root() noexcept = default; -Ptr Self::deroot() { +auto Self::deroot() -> Ptr { return links_.at(0).second.node; } -Ptr Self::rooted() { +auto Self::rooted() -> Ptr { return shared_from_this(); } -bool Self::expired() const { +auto Self::expired() const -> bool { auto n = links_.at(0).second.node; return n ? n->expired() : true; } @@ -27,19 +34,19 @@ auto Self::resolve(ResolutionState& params) -> ResolveResult { auto location = params.PathToResolve().to_string(); auto result = deroot()->Resolve(params); params.headers.Finish(); - if (auto pc = std::get_if<PathChange>(&result)) { + if (auto *pc = std::get_if<PathChange>(&result)) { auto lower = params.WithPath(pc->new_path); result = resolve(lower); location.assign(lower.MyPath().to_view()); - } else if (std::get_if<ProvenAbsent>(&result)) { + } else if (std::get_if<ProvenAbsent>(&result) != nullptr) { if (params.NextComponent(api_.get()) == "_redirects") { return result; } if (!redirects_.has_value()) { auto redirects_path = params.WithPath("_redirects"); result = resolve(redirects_path); - auto redirect_resp = std::get_if<Response>(&result); - if (redirect_resp && redirect_resp->status_ == 200) { + auto *redirect_resp = std::get_if<Response>(&result); + if ((redirect_resp != nullptr) && redirect_resp->status_ == 200) { redirects_ = redirects::File(redirect_resp->body_); } else { // Either this is ProvenAbsent, in which case this will be interpreted @@ -70,11 +77,11 @@ auto Self::resolve(ResolutionState& params) -> ResolveResult { case 4: { result = deroot()->Resolve(lower_parm); location.assign(lower_parm.MyPath().to_view()); - if (std::get_if<ProvenAbsent>(&result)) { + if (std::get_if<ProvenAbsent>(&result) != nullptr) { return Response{"", 500, "", location, params.headers}; } resp = std::get_if<Response>(&result); - if (resp) { + if (resp != nullptr) { resp->status_ = status; resp->headers_ = params.headers; return *resp; @@ -88,8 +95,8 @@ auto Self::resolve(ResolutionState& params) -> ResolveResult { } } } - auto resp = std::get_if<Response>(&result); - if (resp) { + auto *resp = std::get_if<Response>(&result); + if (resp != nullptr) { if (resp->location_.empty()) { resp->location_ = location; } diff --git a/library/src/ipfs_client/ipld/small_directory.cc b/library/src/ipfs_client/ipld/small_directory.cc index ce6a187f..4375793f 100644 --- a/library/src/ipfs_client/ipld/small_directory.cc +++ b/library/src/ipfs_client/ipld/small_directory.cc @@ -1,24 +1,26 @@ #include "small_directory.h" -#include <ipfs_client/client.h> -#include "ipfs_client/generated_directory_listing.h" -#include "ipfs_client/path2url.h" +#include <ipfs_client/generated_directory_listing.h> +#include <ipfs_client/ipld/resolution_state.h> +#include <ipfs_client/ipld/dag_node.h> +#include <ipfs_client/response.h> -#include "log_macros.h" - -#include <numeric> +#include <cstdint> +#include <variant> using namespace std::literals; using Self = ipfs::ipld::SmallDirectory; +constexpr std::uint16_t cSuccess = 200U; + auto Self::resolve(ResolutionState& params) -> ResolveResult { if (params.IsFinalComponent()) { auto result = CallChild(params, "index.html"); - if (auto resp = std::get_if<Response>(&result)) { + if (auto *resp = std::get_if<Response>(&result)) { resp->mime_ = "text/html"; } - if (!std::get_if<ProvenAbsent>(&result)) { + if (std::get_if<ProvenAbsent>(&result) == nullptr) { return result; } auto dir_path = params.MyPath().to_view(); @@ -26,7 +28,7 @@ auto Self::resolve(ResolutionState& params) -> ResolveResult { for (auto& [name, link] : links_) { index_html.AddEntry(name); } - return Response{"text/html", 200, index_html.Finish(), "", {}}; + return Response{"text/html", cSuccess, index_html.Finish(), "", {}}; } return CallChild(params); } diff --git a/library/src/ipfs_client/ipld/symlink.cc b/library/src/ipfs_client/ipld/symlink.cc index 155c37af..e6214460 100644 --- a/library/src/ipfs_client/ipld/symlink.cc +++ b/library/src/ipfs_client/ipld/symlink.cc @@ -1,10 +1,18 @@ #include "symlink.h" +#include <utility> +#include <string> +#include <string_view> +#include <cstddef> + +#include "ipfs_client/ipld/resolution_state.h" +#include "ipfs_client/ipld/dag_node.h" #include "log_macros.h" +#include "vocab/slash_delimited.h" using Self = ipfs::ipld::Symlink; -Self::Symlink(std::string target) : target_{target} {} +Self::Symlink(std::string target) : target_{std::move(target)} {} Self::~Symlink() noexcept = default; @@ -17,7 +25,7 @@ auto Self::resolve(ResolutionState& params) -> ResolveResult { result.assign(left_path.to_view()); } SlashDelimited target{target_}; - for (std::string_view component; (component = target.pop()).size();) { + for (std::string_view component; static_cast<unsigned int>(!(component = target.pop()).empty()) != 0U;) { if (component == "..") { auto slash = result.rfind('/'); DCHECK(slash < result.size()); @@ -33,9 +41,9 @@ auto Self::resolve(ResolutionState& params) -> ResolveResult { if (!params.IsFinalComponent()) { result.append("/").append(params.PathToResolve().to_string()); } - std::size_t i; - while ((i = result.find("//")) != std::string::npos) { - result.erase(i, 1); + std::size_t pos; + while ((pos = result.find("//")) != std::string::npos) { + result.erase(pos, 1); } if (result.empty()) { result.assign(1UL, '/'); @@ -46,6 +54,6 @@ auto Self::resolve(ResolutionState& params) -> ResolveResult { return PathChange{result}; } -bool Self::is_absolute() const { +auto Self::is_absolute() const -> bool { return target_.at(0) == '/'; } diff --git a/library/src/ipfs_client/ipld/unixfs_file.cc b/library/src/ipfs_client/ipld/unixfs_file.cc index f02fe98e..fabbbb5b 100644 --- a/library/src/ipfs_client/ipld/unixfs_file.cc +++ b/library/src/ipfs_client/ipld/unixfs_file.cc @@ -1,11 +1,20 @@ #include "unixfs_file.h" +#include <cstdint> +#include <vector> +#include <string> +#include <variant> +#include "ipfs_client/ipld/resolution_state.h" +#include "ipfs_client/ipld/dag_node.h" +#include "ipfs_client/response.h" #include "log_macros.h" using namespace std::literals; using Self = ipfs::ipld::UnixfsFile; +constexpr std::uint16_t cSuccess = 200U; + auto Self::resolve(ResolutionState& params) -> ResolveResult { if (!params.IsFinalComponent()) { LOG(ERROR) << "Can't path through a file, (at " << params.MyPath() @@ -21,8 +30,8 @@ auto Self::resolve(ResolutionState& params) -> ResolveResult { } if (link.node) { auto recurse = link.node->Resolve(params); - auto mdn = std::get_if<MoreDataNeeded>(&recurse); - if (mdn) { + auto *mdn = std::get_if<MoreDataNeeded>(&recurse); + if (mdn != nullptr) { missing.insert(missing.end(), mdn->ipfs_abs_paths_.begin(), mdn->ipfs_abs_paths_.end()); continue; @@ -37,7 +46,7 @@ auto Self::resolve(ResolutionState& params) -> ResolveResult { if (missing.empty()) { return Response{ "", - 200, + cSuccess, body, params.MyPath().to_string(), {}, }; diff --git a/library/src/ipfs_client/ipns_names.cc b/library/src/ipfs_client/ipns_names.cc index da595cc7..82667851 100644 --- a/library/src/ipfs_client/ipns_names.cc +++ b/library/src/ipfs_client/ipns_names.cc @@ -1,7 +1,12 @@ #include <ipfs_client/ipns_names.h> #include <ipfs_client/cid.h> +#include <string> +#include <utility> +#include <string_view> +#include <ctime> +#include "ipfs_client/ipns_record.h" #include "log_macros.h" using Self = ipfs::IpnsNames; @@ -11,7 +16,7 @@ void Self::NoSuchName(std::string const& name) { } void Self::AssignName(std::string const& name, ValidatedIpns entry) { auto& res = entry.value; - if (res.size() && res.front() == '/') { + if ((static_cast<unsigned int>(!res.empty()) != 0U) && res.front() == '/') { res.erase(0, 1); } auto endofcid = res.find_first_of("/?#", 6); @@ -53,9 +58,9 @@ void Self::AssignDnsLink(std::string const& name, std::string_view target) { AssignName(name, std::move(v)); } -std::string_view Self::NameResolvedTo(std::string_view original_name) const { +auto Self::NameResolvedTo(std::string_view original_name) const -> std::string_view { std::string name{original_name}; - std::string_view prev = ""; + std::string_view prev; auto trailer = names_.end(); auto trail_step = false; auto now = std::time(nullptr); @@ -70,7 +75,7 @@ std::string_view Self::NameResolvedTo(std::string_view original_name) const { << ' ' << name; return ""; } - auto& target = it->second.value; + const auto& target = it->second.value; if (target.empty()) { return kNoSuchName; } diff --git a/library/src/ipfs_client/ipns_record.cc b/library/src/ipfs_client/ipns_record.cc index 462ca3c9..64be401d 100644 --- a/library/src/ipfs_client/ipns_record.cc +++ b/library/src/ipfs_client/ipns_record.cc @@ -4,10 +4,19 @@ #include <ipfs_client/client.h> #include <ipfs_client/dag_cbor_value.h> -#include "log_macros.h" - +#include <cstdint> #include <ctime> + +#include <algorithm> +#include <iomanip> +#include <ios> +#include <limits> +#include <optional> #include <sstream> +#include <string> +#include <string_view> + +#include "log_macros.h" #if __has_include(<third_party/ipfs_client/ipns_record.pb.h>) #include <third_party/ipfs_client/ipns_record.pb.h> @@ -16,9 +25,9 @@ #endif namespace { -bool matches(ipfs::MultiHash const& hash, +auto matches(ipfs::MultiHash const& hash, ipfs::ByteView pubkey_bytes, - ipfs::Client& api) { + ipfs::Client& api) -> bool { auto result = api.Hash(hash.type(), pubkey_bytes); if (!result.has_value()) { return false; @@ -29,16 +38,16 @@ bool matches(ipfs::MultiHash const& hash, void assign(std::string& out, ipfs::DagCborValue& top, std::string_view key) { - auto p = top.at(key); - if (!p) { + auto ptr = top.at(key); + if (!ptr) { out.assign("Key '").append(key).append("' not present in IPNS CBOR!"); } else { // YEP! as_bytes() . There are only 2 string values here, they are logically // text, but they are defined in the spec to be bytes. - auto o = p->as_bytes(); - if (o.has_value()) { - auto chars = reinterpret_cast<char const*>(o.value().data()); - out.assign(chars, o.value().size()); + auto byted = ptr->as_bytes(); + if (byted.has_value()) { + const auto *chars = reinterpret_cast<char const*>(byted.value().data()); + out.assign(chars, byted.value().size()); } else { out.assign("Key '").append(key).append( "' was not a string in IPNS CBOR!"); @@ -136,13 +145,13 @@ auto ipfs::ValidateIpnsRecord(ipfs::ByteView top_level_bytes, return {}; } ipfs::ipns::PublicKey pk; - auto* pkbp = reinterpret_cast<char const*>(public_key.data()); + const auto* pkbp = reinterpret_cast<char const*>(public_key.data()); if (!pk.ParseFromArray(pkbp, public_key.size())) { LOG(ERROR) << "Failed to parse public key bytes"; return {}; } - auto& signature_str = entry.signaturev2(); - ByteView signature{reinterpret_cast<ipfs::Byte const*>(signature_str.data()), + const auto& signature_str = entry.signaturev2(); + ByteView const signature{reinterpret_cast<ipfs::Byte const*>(signature_str.data()), signature_str.size()}; // https://specs.ipfs.tech/ipns/ipns-record/#record-verification // Create bytes for signature verification by concatenating @@ -150,10 +159,10 @@ auto ipfs::ValidateIpnsRecord(ipfs::ByteView top_level_bytes, // 69706e732d7369676e61747572653a) with raw CBOR bytes from IpnsEntry.data auto bytes_str = entry.data(); bytes_str.insert( - 0, "\x69\x70\x6e\x73\x2d\x73\x69\x67\x6e\x61\x74\x75\x72\x65\x3a"); - ByteView bytes{reinterpret_cast<ipfs::Byte const*>(bytes_str.data()), + 0, R"(ipns-signature:)"); + ByteView const bytes{reinterpret_cast<ipfs::Byte const*>(bytes_str.data()), bytes_str.size()}; - ByteView key_bytes{reinterpret_cast<ipfs::Byte const*>(pk.data().data()), + ByteView const key_bytes{reinterpret_cast<ipfs::Byte const*>(pk.data().data()), pk.data().size()}; if (!api.VerifyKeySignature(static_cast<crypto::SigningKeyType>(pk.type()), signature, bytes, key_bytes)) { @@ -208,7 +217,7 @@ ipfs::ValidatedIpns::ValidatedIpns(IpnsCborEntry const& e) std::istringstream ss{e.validity}; std::tm t = {}; ss >> std::get_time(&t, "%Y-%m-%dT%H:%M:%S"); - long ttl = static_cast<long>(e.ttl / 1'000'000'000UL) + 1; + long const ttl = static_cast<long>(e.ttl / 1'000'000'000UL) + 1; #ifdef _MSC_VER use_until = _mkgmtime(&t); #else @@ -217,7 +226,7 @@ ipfs::ValidatedIpns::ValidatedIpns(IpnsCborEntry const& e) cache_until = std::time(nullptr) + ttl; } -std::string ipfs::ValidatedIpns::Serialize() const { +auto ipfs::ValidatedIpns::Serialize() const -> std::string { DCHECK_EQ(value.find(' '), std::string::npos); DCHECK_EQ(gateway_source.find(' '), std::string::npos); std::ostringstream ss; diff --git a/library/src/ipfs_client/logger.cc b/library/src/ipfs_client/logger.cc index de9ced84..01d2e133 100644 --- a/library/src/ipfs_client/logger.cc +++ b/library/src/ipfs_client/logger.cc @@ -3,6 +3,8 @@ #include <google/protobuf/stubs/logging.h> #include <iostream> +#include <string> +#include <string_view> namespace lg = ipfs::log; @@ -18,7 +20,7 @@ void CheckLevel(google::protobuf::LogLevel lv, if (lev < static_cast<int>(current_level)) { return; } - if (!current_handler) { + if (current_handler == nullptr) { return; } current_handler(m, f, l, static_cast<lg::Level>(lev)); @@ -46,7 +48,7 @@ void lg::DefaultHandler(std::string const& message, } } -std::string_view lg::LevelDescriptor(Level l) { +auto lg::LevelDescriptor(Level l) -> std::string_view { switch (l) { case Level::Trace: return "trace"; @@ -67,8 +69,8 @@ std::string_view lg::LevelDescriptor(Level l) { } } -bool lg::IsInitialized() noexcept { - if (current_handler) { +auto lg::IsInitialized() noexcept -> bool { + if (current_handler != nullptr) { return true; } SetHandler(&DefaultHandler); diff --git a/library/src/ipfs_client/multi_base.cc b/library/src/ipfs_client/multi_base.cc index 63a51e7f..82d8405d 100644 --- a/library/src/ipfs_client/multi_base.cc +++ b/library/src/ipfs_client/multi_base.cc @@ -4,8 +4,14 @@ #include "bases/b32.h" #include <multibase/basic_algorithm.h> +#include <string_view> +#include <string> +#include <vector> +#include <optional> #include "log_macros.h" +#include "vocab/byte_view.h" +#include "vocab/byte.h" using namespace std::literals; @@ -14,14 +20,14 @@ namespace { constexpr std::string_view UnsupportedMultibase = "unsupported-multibase"; template <class Target> -std::string encode_adapt(ipfs::ByteView bytes) { - auto p = reinterpret_cast<char const*>(bytes.data()); +auto encode_adapt(ipfs::ByteView bytes) -> std::string { + const auto *p = reinterpret_cast<char const*>(bytes.data()); typename Target::encoder target; return target.process({p, bytes.size()}); } enum class EncodedCase { lower, UPPER, Sensitive }; template <class Target, EncodedCase const ec> -std::vector<ipfs::Byte> decode_adapt(std::string_view encoded_sv) { +auto decode_adapt(std::string_view encoded_sv) -> std::vector<ipfs::Byte> { typename Target::decoder target; std::string encoded_s{encoded_sv}; switch (ec) { @@ -43,12 +49,12 @@ std::vector<ipfs::Byte> decode_adapt(std::string_view encoded_sv) { break; } auto s = target.process(encoded_s); - auto b = reinterpret_cast<ipfs::Byte const*>(s.data()); + const auto *b = reinterpret_cast<ipfs::Byte const*>(s.data()); auto e = b + s.size(); return std::vector<ipfs::Byte>(b, e); } template <class BasicAlgoSpecl, EncodedCase const ec> -constexpr imb::Codec adapt(std::string_view name) { +constexpr auto adapt(std::string_view name) -> imb::Codec { return imb::Codec{&decode_adapt<BasicAlgoSpecl, ec>, &encode_adapt<BasicAlgoSpecl>, name}; } @@ -97,28 +103,28 @@ auto imb::Codec::Get(Code c) -> Codec const* { } return nullptr; } -std::string_view imb::GetName(Code c) { - if (auto codec = Codec::Get(c)) { +auto imb::GetName(Code c) -> std::string_view { + if (const auto *codec = Codec::Get(c)) { return codec->name; } return UnsupportedMultibase; } auto imb::CodeFromPrefix(char ch) -> Code { auto c = static_cast<Code>(ch); - return Codec::Get(c) ? Code::UNSUPPORTED : c; + return Codec::Get(c) != nullptr ? Code::UNSUPPORTED : c; } auto imb::decode(std::string_view mb_str) -> std::optional<std::vector<Byte>> { if (mb_str.empty()) { return std::nullopt; } - if (auto* codec = Codec::Get(static_cast<Code>(mb_str[0]))) { + if (const auto* codec = Codec::Get(static_cast<Code>(mb_str[0]))) { return codec->decode(mb_str.substr(1)); } else { return std::nullopt; } } -std::string imb::encode(Code c, ByteView bs) { - if (auto codec = Codec::Get(c)) { +auto imb::encode(Code c, ByteView bs) -> std::string { + if (const auto *codec = Codec::Get(c)) { auto rv = codec->encode(bs); if (rv.size() >= bs.size()) { rv.insert(0UL, 1UL, static_cast<char>(c)); diff --git a/library/src/ipfs_client/multi_hash.cc b/library/src/ipfs_client/multi_hash.cc index 20cf5b19..e713b1ba 100644 --- a/library/src/ipfs_client/multi_hash.cc +++ b/library/src/ipfs_client/multi_hash.cc @@ -1,6 +1,9 @@ #include <ipfs_client/multi_hash.h> +#include <iterator> #include <libp2p/multi/uvarint.hpp> +#include "vocab/byte_view.h" +#include <string_view> using Self = ipfs::MultiHash; using VarInt = libp2p::multi::UVarint; @@ -11,7 +14,7 @@ Self::MultiHash(ipfs::HashType t, ipfs::ByteView digest) Self::MultiHash(ipfs::ByteView bytes) { ReadPrefix(bytes); } -bool Self::ReadPrefix(ipfs::ByteView& bytes) { +auto Self::ReadPrefix(ipfs::ByteView& bytes) -> bool { auto i = VarInt::create(bytes); if (!i) { return false; @@ -32,13 +35,13 @@ bool Self::ReadPrefix(ipfs::ByteView& bytes) { type_ = type; return true; } -bool Self::valid() const { - return type_ != HashType::INVALID && hash_.size() > 0UL; +auto Self::valid() const -> bool { + return type_ != HashType::INVALID && !hash_.empty(); } namespace { constexpr std::string_view InvalidHashTypeName; } -std::string_view ipfs::GetName(HashType t) { +auto ipfs::GetName(HashType t) -> std::string_view { switch (t) { case HashType::INVALID: return InvalidHashTypeName; diff --git a/library/src/ipfs_client/multicodec.cc b/library/src/ipfs_client/multicodec.cc index 68cad03e..924627ae 100644 --- a/library/src/ipfs_client/multicodec.cc +++ b/library/src/ipfs_client/multicodec.cc @@ -1,4 +1,5 @@ #include <ipfs_client/multicodec.h> +#include <string_view> using Cdc = ipfs::MultiCodec; @@ -6,8 +7,8 @@ namespace { constexpr std::string_view InvalidMulticodecLabel{"invalid-multicodec"}; } -std::string_view ipfs::GetName(Cdc c) { - switch (c) { +auto ipfs::GetName(Cdc codec) -> std::string_view { + switch (codec) { case Cdc::INVALID: return InvalidMulticodecLabel; case Cdc::IDENTITY: @@ -25,9 +26,9 @@ std::string_view ipfs::GetName(Cdc c) { } return InvalidMulticodecLabel; } -Cdc ipfs::Validate(Cdc c) { +auto ipfs::Validate(Cdc c) -> Cdc { if (GetName(c) == InvalidMulticodecLabel) { return Cdc::INVALID; } return c; -} \ No newline at end of file +} diff --git a/library/src/ipfs_client/opinionated_context.cc b/library/src/ipfs_client/opinionated_context.cc index 36e560ac..ae6d394a 100644 --- a/library/src/ipfs_client/opinionated_context.cc +++ b/library/src/ipfs_client/opinionated_context.cc @@ -1,6 +1,13 @@ #include <ipfs_client/opinionated_context.h> #include <ipfs_client/gw/default_requestor.h> +#include <memory> +#include "ipfs_client/client.h" +#include "ipfs_client/crypto/signing_key_type.h" +#include "ipfs_client/ctx/boost_beast_http.h" +#include "ipfs_client/ctx/ares_dns_txt_lookup.h" +#include "ipfs_client/crypto/openssl_signature_verifier.h" +#include <openssl/evp.h> #if HAS_OPINIONATED_CONTEXT diff --git a/library/src/ipfs_client/partition.cc b/library/src/ipfs_client/partition.cc index d2448e24..cc2ce646 100644 --- a/library/src/ipfs_client/partition.cc +++ b/library/src/ipfs_client/partition.cc @@ -3,10 +3,19 @@ #include <ipfs_client/client.h> #include <ipfs_client/ipfs_request.h> +#include "ipfs_client/gw/requestor.h" +#include "ipfs_client/ipld/dag_node.h" +#include "ipfs_client/ipld/resolution_state.h" +#include "ipfs_client/gw/gateway_request.h" #include "log_macros.h" #include "path2url.h" +#include "vocab/slash_delimited.h" #include <algorithm> +#include <memory> +#include <utility> +#include <string> +#include <variant> using namespace std::literals; @@ -14,7 +23,7 @@ using Self = ipfs::Partition; Self::Partition(std::shared_ptr<gw::Requestor> requestor, std::shared_ptr<Client> api) - : api_{api}, requestor_{requestor} { + : api_{std::move(api)}, requestor_{requestor} { DCHECK(requestor); } @@ -25,7 +34,7 @@ void Self::build_response(std::shared_ptr<IpfsRequest> req) { } auto req_path = req->path(); req_path.pop(); // discard namespace ipfs or ipns - std::string affinity{req_path.pop()}; + std::string const affinity{req_path.pop()}; auto it = dags_.find(affinity); if (dags_.end() == it) { if (gw_request(req, req->path(), affinity)) { @@ -51,8 +60,8 @@ void Self::from_tree(std::shared_ptr<IpfsRequest> req, auto start = std::string{req->path().pop_n(2)}; ipfs::ipld::ResolutionState state{relative_path, req->semantic(), block_look_up}; auto result = root->Resolve(state); - auto response = std::get_if<Response>(&result); - if (response) { + auto *response = std::get_if<Response>(&result); + if (response != nullptr) { if (response->mime_.empty() && !response->body_.empty()) { if (response->location_.empty()) { response->mime_ = sniff(req->path(), response->body_); @@ -77,7 +86,7 @@ void Self::from_tree(std::shared_ptr<IpfsRequest> req, LOG(ERROR) << "Should not be getting a PathChange in orchestrator - " "should've been handled in the root, but got " << pc->new_path << " for " << req->path(); - } else if (std::get_if<ipld::ProvenAbsent>(&result)) { + } else if (std::get_if<ipld::ProvenAbsent>(&result) != nullptr) { req->finish(Response::IMMUTABLY_GONE); } else { auto& mps = std::get<ipld::MoreDataNeeded>(result).ipfs_abs_paths_; @@ -88,9 +97,9 @@ void Self::from_tree(std::shared_ptr<IpfsRequest> req, } } } -bool Self::gw_request(std::shared_ptr<IpfsRequest> ir, +auto Self::gw_request(std::shared_ptr<IpfsRequest> ir, ipfs::SlashDelimited path, - std::string const& aff) { + std::string const& aff) -> bool { auto req = gw::GatewayRequest::fromIpfsPath(path); if (req) { req->dependent = ir; @@ -103,7 +112,7 @@ bool Self::gw_request(std::shared_ptr<IpfsRequest> ir, return false; } -bool Self::add_node(std::string key, ipfs::ipld::NodePtr p) { +auto Self::add_node(std::string key, ipfs::ipld::NodePtr p) -> bool { if (!p) { LOG(INFO) << "NULL block attempted to be added for " << key; return false; @@ -120,11 +129,11 @@ bool Self::add_node(std::string key, ipfs::ipld::NodePtr p) { return true; } -std::string Self::sniff(ipfs::SlashDelimited p, std::string const& body) const { +auto Self::sniff(ipfs::SlashDelimited p, std::string const& body) const -> std::string { auto fake_url = path2url(p.to_string()); auto file_name = p.peek_back(); auto dot = file_name.find_last_of('.'); - std::string ext = ""; + std::string ext; if (dot < file_name.size()) { ext.assign(file_name, dot + 1); } @@ -132,6 +141,6 @@ std::string Self::sniff(ipfs::SlashDelimited p, std::string const& body) const { return result; } -bool Self::has_key(std::string const& k) const { - return dags_.count(k); +auto Self::has_key(std::string const& k) const -> bool { + return dags_.count(k) != 0U; } diff --git a/library/src/ipfs_client/partition_unittest.cc b/library/src/ipfs_client/partition_unittest.cc index 11f4439e..6037cc21 100644 --- a/library/src/ipfs_client/partition_unittest.cc +++ b/library/src/ipfs_client/partition_unittest.cc @@ -69,7 +69,7 @@ struct TestRequestor final : public ig::Requestor { TestRequestor() { api_ = std::make_shared<MockApi>(); } std::string_view name() const { return "return test requestor"; } HandleOutcome handle(ig::RequestPtr r) { - auto cid = r->main_param; + std::string cid{r->root_component()}; auto base_dir = std::filesystem::path{__FILE__}; while (!is_directory(base_dir / "test_data" / "blocks") && base_dir.generic_string().size() > 2) { diff --git a/library/src/ipfs_client/path2url.cc b/library/src/ipfs_client/path2url.cc index 0d7cf305..4ba70975 100644 --- a/library/src/ipfs_client/path2url.cc +++ b/library/src/ipfs_client/path2url.cc @@ -1,8 +1,9 @@ #include "path2url.h" +#include <string> #include "log_macros.h" -std::string ipfs::path2url(std::string p) { +auto ipfs::path2url(std::string p) -> std::string { while (!p.empty() && p[0] == '/') { p.erase(0UL, 1UL); } diff --git a/library/src/ipfs_client/pb_dag.cc b/library/src/ipfs_client/pb_dag.cc index c7399ceb..282545e0 100644 --- a/library/src/ipfs_client/pb_dag.cc +++ b/library/src/ipfs_client/pb_dag.cc @@ -2,9 +2,26 @@ #include <ipfs_client/client.h> +#include "ipfs_client/multicodec.h" +#include "ipfs_client/cid.h" +#include "ipfs_client/multi_hash.h" #include "log_macros.h" +#include "vocab/byte_view.h" +#include "vocab/byte.h" #include <algorithm> +#include <string> +#include <istream> +#include <iterator> +#include <utility> +#include <memory> +#include <tuple> +#include <string_view> +#include <vector> +#include <functional> +#include <optional> +#include <cstdint> +#include <ostream> #if __has_include(<third_party/ipfs_client/pb_dag.pb.h>) #include <third_party/ipfs_client/pb_dag.pb.h> @@ -15,27 +32,27 @@ #endif namespace { -std::string get_bytes(std::string const& s) { - return s; +auto get_bytes(std::string const& already_string) -> std::string { + return already_string; } -std::string get_bytes(std::istream& is) { - return std::string(std::istreambuf_iterator<char>(is), {}); +auto get_bytes(std::istream& strm) -> std::string { + return std::string(std::istreambuf_iterator<char>(strm), {}); } -bool parse(ipfs::pb_dag::PBNode& n, std::istream& s) { - return n.ParseFromIstream(&s); +auto parse(ipfs::pb_dag::PBNode& n, std::istream& strm) -> bool { + return n.ParseFromIstream(&strm); } -bool parse(ipfs::pb_dag::PBNode& n, std::string const& s) { +auto parse(ipfs::pb_dag::PBNode& n, std::string const& s) -> bool { return n.ParseFromString(s); } template <class From> -std::pair<bool, bool> InitBlock(ipfs::MultiCodec c, +auto InitBlock(ipfs::MultiCodec c, From& from, ipfs::pb_dag::PBNode& n, - ipfs::unix_fs::Data& d) { + ipfs::unix_fs::Data& d) -> std::pair<bool, bool> { using Cdc = ipfs::MultiCodec; switch (c) { case Cdc::DAG_PB: @@ -70,10 +87,10 @@ struct ipfs::PbDag::Data { unix_fs::Data fsdata_; }; -ipfs::PbDag::PbDag(Cid const& c, std::istream& s) - : pimpl_{std::make_unique<Data>()}, cid_(c) { +ipfs::PbDag::PbDag(Cid const& cid, std::istream& stream) + : pimpl_{std::make_unique<Data>()}, cid_(cid) { std::tie(valid_, fs_node_) = - InitBlock(c.codec(), s, pimpl_->node_, pimpl_->fsdata_); + InitBlock(cid.codec(), stream, pimpl_->node_, pimpl_->fsdata_); } ipfs::PbDag::PbDag(Cid const& c, ByteView s) @@ -97,7 +114,7 @@ ipfs::PbDag::PbDag() = default; ipfs::PbDag::~PbDag() noexcept = default; -bool ipfs::PbDag::valid() const { +auto ipfs::PbDag::valid() const -> bool { return valid_; } @@ -115,22 +132,22 @@ auto ipfs::PbDag::type() const -> Type { return Type::FileChunk; } } - if (pimpl_->fsdata_.type()) { + if (pimpl_->fsdata_.type() != 0) { return static_cast<Type>(pimpl_->fsdata_.type()); } return Type::Invalid; } -bool ipfs::PbDag::is_file() const { +auto ipfs::PbDag::is_file() const -> bool { return valid() && fs_node_ && pimpl_->fsdata_.type() == unix_fs::Data_DataType_File; } -std::string const& ipfs::PbDag::chunk_data() const { +auto ipfs::PbDag::chunk_data() const -> std::string const& { return pimpl_->fsdata_.data(); } -std::string const& ipfs::PbDag::unparsed() const { +auto ipfs::PbDag::unparsed() const -> std::string const& { return pimpl_->node_.data(); } @@ -139,8 +156,8 @@ auto ipfs::PbDag::cid() const -> Cid const& { return cid_.value(); } -std::string ipfs::PbDag::LinkCid(ipfs::ByteView binary_link_hash) const { - Cid result(binary_link_hash); +auto ipfs::PbDag::LinkCid(ipfs::ByteView binary_link_hash) const -> std::string { + Cid const result(binary_link_hash); if (!result.valid()) { LOG(FATAL) << "Failed to decode link CID as binary ( link from " << cid().to_string() << ")"; @@ -153,7 +170,7 @@ std::string ipfs::PbDag::LinkCid(ipfs::ByteView binary_link_hash) const { return str_res; } -bool ipfs::PbDag::cid_matches_data(Client& api) const { +auto ipfs::PbDag::cid_matches_data(Client& api) const -> bool { if (!cid_) { return true; } @@ -171,8 +188,8 @@ bool ipfs::PbDag::cid_matches_data(Client& api) const { hashed.end()); } -std::vector<ipfs::Byte> ipfs::PbDag::binary_hash(Client& api, - HashType algo) const { +auto ipfs::PbDag::binary_hash(Client& api, + HashType algo) const -> std::vector<ipfs::Byte> { if (algo == HashType::INVALID) { algo = cid().hash_type(); } @@ -186,7 +203,7 @@ std::vector<ipfs::Byte> ipfs::PbDag::binary_hash(Client& api, void ipfs::PbDag::List( std::function<bool(std::string const&, std::string)> foo) const { - for (auto& link : pimpl_->node_.links()) { + for (const auto& link : pimpl_->node_.links()) { // protobuf uses string for binary data, too auto hash = as_bytes(link.hash()); if (!foo(link.name(), LinkCid(hash))) { @@ -194,14 +211,14 @@ void ipfs::PbDag::List( } } } -std::optional<std::uint64_t> ipfs::PbDag::Fanout() const { +auto ipfs::PbDag::Fanout() const -> std::optional<std::uint64_t> { if (pimpl_ && fs_node_ && pimpl_->fsdata_.has_fanout()) { return pimpl_->fsdata_.fanout(); } return std::nullopt; } -std::ostream& operator<<(std::ostream& s, ipfs::PbDag::Type t) { +auto operator<<(std::ostream& s, ipfs::PbDag::Type t) -> std::ostream& { switch (t) { case ipfs::PbDag::Type::Raw: return s << "Raw"; diff --git a/library/src/ipfs_client/redirects.cc b/library/src/ipfs_client/redirects.cc index 813b5ef1..a380d4c0 100644 --- a/library/src/ipfs_client/redirects.cc +++ b/library/src/ipfs_client/redirects.cc @@ -4,8 +4,12 @@ #include <vocab/slash_delimited.h> -#include <numeric> +#include <cstddef> +#include <cstdint> +#include <string_view> +#include <string> #include <unordered_set> +#include <utility> namespace r = ipfs::redirects; using namespace std::literals; @@ -47,7 +51,7 @@ r::Directive::Directive(std::string_view from, std::string_view to, int status) } } } -std::uint16_t r::Directive::rewrite(std::string& path) const { +auto r::Directive::rewrite(std::string& path) const -> std::uint16_t { auto input = SlashDelimited{path}; auto result = to_; auto replace = [&result](std::string_view ph, std::string_view val) { @@ -81,8 +85,8 @@ std::uint16_t r::Directive::rewrite(std::string& path) const { return status_; } } -std::string r::Directive::error() const { - if (starts_with(to_, "ERROR: ")) { +auto r::Directive::error() const -> std::string { + if (to_.starts_with("ERROR: ")) { return to_; } if (status_ < 200 || status_ > 451) { @@ -100,10 +104,10 @@ std::string r::Directive::error() const { return {}; } -std::uint16_t r::File::rewrite(std::string& missing_path) const { - for (auto& directive : directives_) { +auto r::File::rewrite(std::string& missing_path) const -> std::uint16_t { + for (const auto& directive : directives_) { auto status = directive.rewrite(missing_path); - if (status) { + if (status != 0U) { return status; } } @@ -114,7 +118,7 @@ r::File::File(std::string_view to_parse) { error_ = "INPUT FILE TOO LARGE " + std::to_string(to_parse.size()); return; } - for (auto line_number = 1; valid() && to_parse.size(); ++line_number) { + for (auto line_number = 1; valid() && (static_cast<unsigned int>(!to_parse.empty()) != 0U); ++line_number) { auto line_end = to_parse.find('\n'); auto line = to_parse.substr(0UL, line_end); if (!parse_line(line, line_number)) { @@ -129,7 +133,7 @@ r::File::File(std::string_view to_parse) { .append(" [") .append(line) .push_back(']'); - LOG(ERROR) << error_; + LOG(WARNING) << error_; return; } if (line_end < to_parse.size()) { @@ -145,10 +149,10 @@ r::File::File(std::string_view to_parse) { } namespace { -std::pair<int, std::string> parse_status(std::string_view line, - std::size_t col); +auto parse_status(std::string_view line, + std::size_t col) -> std::pair<int, std::string>; } -bool r::File::parse_line(std::string_view line, int line_number) { +auto r::File::parse_line(std::string_view line, int line_number) -> bool { if (line.empty()) { // empty line is not a directive return false; @@ -197,8 +201,8 @@ bool r::File::parse_line(std::string_view line, int line_number) { namespace { -std::pair<int, std::string> parse_status(std::string_view line, - std::size_t col) { +auto parse_status(std::string_view line, + std::size_t col) -> std::pair<int, std::string> { if (col >= line.size()) { return {DEFAULT_STATUS, ""}; } diff --git a/library/src/ipfs_client/response.cc b/library/src/ipfs_client/response.cc index e9078383..889e83c5 100644 --- a/library/src/ipfs_client/response.cc +++ b/library/src/ipfs_client/response.cc @@ -1,4 +1,6 @@ #include "ipfs_client/response.h" +#include <string> +#include <string_view> using Self = ipfs::Response; @@ -16,6 +18,6 @@ Self Self::HOST_NOT_FOUND_RESPONSE{ std::string{}, {}}; -Self Self::html(std::string_view body, std::string_view location) { +auto Self::html(std::string_view body, std::string_view location) -> Self { return {"text/html", 200, std::string{body}, std::string{location}, {}}; } diff --git a/library/src/ipfs_client/web_util.cc b/library/src/ipfs_client/web_util.cc index 29da0aef..43e1d4ce 100644 --- a/library/src/ipfs_client/web_util.cc +++ b/library/src/ipfs_client/web_util.cc @@ -1,10 +1,13 @@ #include "web_util.h" +#include <string> +#include <string_view> +#include <cctype> namespace u = ipfs::util; -std::string u::TrivialMimeGuess(std::string ext, +auto u::TrivialMimeGuess(std::string ext, std::string_view, - std::string const&) { + std::string const&) -> std::string { if (ext.starts_with("htm")) { return "text/html"; } @@ -19,7 +22,7 @@ std::string u::TrivialMimeGuess(std::string ext, } return "application/octet-stream"; } -std::string u::RoughlyUnescapeUrlComponent(std::string_view url_comp) { +auto u::RoughlyUnescapeUrlComponent(std::string_view url_comp) -> std::string { std::string rv{url_comp}; auto xval = [](char c) { if (c <= '9') { @@ -42,11 +45,11 @@ std::string u::RoughlyUnescapeUrlComponent(std::string_view url_comp) { if (i + 2UL >= rv.size()) { break; } - if (!std::isxdigit(a)) { + if (std::isxdigit(a) == 0) { continue; } auto b = rv[i + 2UL]; - if (std::isxdigit(b)) { + if (std::isxdigit(b) != 0) { rv[i] = xval(a) * 16 + xval(b); rv.erase(i + 1UL, 2); } diff --git a/library/src/libp2p/multi/uvarint.cc b/library/src/libp2p/multi/uvarint.cc index 7d4ea757..4df27fa3 100644 --- a/library/src/libp2p/multi/uvarint.cc +++ b/library/src/libp2p/multi/uvarint.cc @@ -3,7 +3,14 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include <cstdint> +#include <cstddef> +#include <algorithm> #include <libp2p/multi/uvarint.hpp> +#include "vocab/byte.h" +#include "vocab/byte_view.h" +#include <optional> +#include <vector> namespace libp2p::multi { @@ -29,15 +36,15 @@ UVarint::UVarint(ipfs::ByteView varint_bytes) { UVarint::UVarint(ipfs::ByteView varint_bytes, size_t varint_size) : bytes_(varint_bytes.begin(), varint_bytes.begin() + varint_size) {} -std::optional<UVarint> UVarint::create(ipfs::ByteView varint_bytes) { - size_t size = calculateSize(varint_bytes); +auto UVarint::create(ipfs::ByteView varint_bytes) -> std::optional<UVarint> { + size_t const size = calculateSize(varint_bytes); if (size > 0 && size <= varint_bytes.size()) { return UVarint{varint_bytes, size}; } return {}; } -uint64_t UVarint::toUInt64() const { +auto UVarint::toUInt64() const -> uint64_t { uint64_t res = 0; size_t index = 0; for (const auto& byte : bytes_) { @@ -47,45 +54,45 @@ uint64_t UVarint::toUInt64() const { return res; } -ipfs::ByteView UVarint::toBytes() const { +auto UVarint::toBytes() const -> ipfs::ByteView { return ipfs::ByteView{bytes_.data(), bytes_.size()}; } -std::vector<ipfs::Byte> const& UVarint::toVector() const { +auto UVarint::toVector() const -> std::vector<ipfs::Byte> const& { return bytes_; } -size_t UVarint::size() const { +auto UVarint::size() const -> size_t { return bytes_.size(); } -UVarint& UVarint::operator=(UVarint const& rhs) = default; -UVarint& UVarint::operator=(uint64_t n) { +auto UVarint::operator=(UVarint const& rhs) -> UVarint& = default; +auto UVarint::operator=(uint64_t n) -> UVarint& { *this = UVarint(n); return *this; } -bool UVarint::operator==(const UVarint& r) const { +auto UVarint::operator==(const UVarint& r) const -> bool { return std::equal(bytes_.begin(), bytes_.end(), r.bytes_.begin(), r.bytes_.end()); } -bool UVarint::operator!=(const UVarint& r) const { +auto UVarint::operator!=(const UVarint& r) const -> bool { return !(*this == r); } -bool UVarint::operator<(const UVarint& r) const { +auto UVarint::operator<(const UVarint& r) const -> bool { return toUInt64() < r.toUInt64(); } -size_t UVarint::calculateSize(ipfs::ByteView varint_bytes) { +auto UVarint::calculateSize(ipfs::ByteView varint_bytes) -> size_t { size_t size = 0; size_t shift = 0; constexpr size_t capacity = sizeof(uint64_t) * 8; bool last_byte_found = false; for (const auto& byte : varint_bytes) { ++size; - std::uint_least64_t slice = to_integer(byte) & 0x7f; + std::uint_least64_t const slice = to_integer(byte) & 0x7f; if (shift >= capacity || ((slice << shift) >> shift) != slice) { size = 0; break; diff --git a/library/src/log_macros.h b/library/src/log_macros.h index 312eb4ad..361107ab 100644 --- a/library/src/log_macros.h +++ b/library/src/log_macros.h @@ -37,17 +37,4 @@ static bool const is_logging_initialized = ::ipfs::log::IsInitialized(); #define L_VAR(X) LOG(INFO) << "VAR " << #X << "='" << (X) << '\''; -inline auto starts_with(std::string_view full_text, std::string_view prefix) -> bool { - if (prefix.size() > full_text.size()) { - return false; - } - return full_text.substr(0UL, prefix.size()) == prefix; -} -inline auto ends_with(std::string_view full_text, std::string_view suffix) -> bool { - if (suffix.size() > full_text.size()) { - return false; - } - return full_text.substr(full_text.size() - suffix.size()) == suffix; -} - #endif // IPFS_LOG_MACROS_H_ diff --git a/library/src/smhasher/MurmurHash3.cc b/library/src/smhasher/MurmurHash3.cc index 677aedf1..5129e11d 100644 --- a/library/src/smhasher/MurmurHash3.cc +++ b/library/src/smhasher/MurmurHash3.cc @@ -8,6 +8,7 @@ // non-native version will be less than optimal. #include "smhasher/MurmurHash3.h" +#include <cstdint> #ifdef __GNUG__ #pragma GCC diagnostic ignored "-Wimplicit-fallthrough" #endif @@ -37,11 +38,11 @@ #define FORCE_INLINE inline __attribute__((always_inline)) -inline uint32_t rotl32(uint32_t x, int8_t r) { +inline auto rotl32(uint32_t x, int8_t r) -> uint32_t { return (x << r) | (x >> (32 - r)); } -inline uint64_t rotl64(uint64_t x, int8_t r) { +inline auto rotl64(uint64_t x, int8_t r) -> uint64_t { return (x << r) | (x >> (64 - r)); } @@ -92,7 +93,7 @@ FORCE_INLINE uint64_t fmix64(uint64_t k) { //----------------------------------------------------------------------------- void MurmurHash3_x86_32(const void* key, int len, uint32_t seed, void* out) { - const uint8_t* data = (const uint8_t*)key; + const auto* data = (const uint8_t*)key; const int nblocks = len / 4; uint32_t h1 = seed; @@ -103,9 +104,9 @@ void MurmurHash3_x86_32(const void* key, int len, uint32_t seed, void* out) { //---------- // body - const uint32_t* blocks = (const uint32_t*)(data + nblocks * 4); + const auto* blocks = (const uint32_t*)(data + nblocks * 4); - for (int i = -nblocks; i; i++) { + for (int i = -nblocks; i != 0; i++) { uint32_t k1 = getblock32(blocks, i); k1 *= c1; @@ -120,7 +121,7 @@ void MurmurHash3_x86_32(const void* key, int len, uint32_t seed, void* out) { //---------- // tail - const uint8_t* tail = (const uint8_t*)(data + nblocks * 4); + const auto* tail = (const uint8_t*)(data + nblocks * 4); uint32_t k1 = 0; @@ -153,7 +154,7 @@ void MurmurHash3_x86_128(const void* key, const int len, uint32_t seed, void* out) { - const uint8_t* data = (const uint8_t*)key; + const auto* data = (const uint8_t*)key; const int nblocks = len / 16; uint32_t h1 = seed; @@ -169,9 +170,9 @@ void MurmurHash3_x86_128(const void* key, //---------- // body - const uint32_t* blocks = (const uint32_t*)(data + nblocks * 16); + const auto* blocks = (const uint32_t*)(data + nblocks * 16); - for (int i = -nblocks; i; i++) { + for (int i = -nblocks; i != 0; i++) { uint32_t k1 = getblock32(blocks, i * 4 + 0); uint32_t k2 = getblock32(blocks, i * 4 + 1); uint32_t k3 = getblock32(blocks, i * 4 + 2); @@ -217,7 +218,7 @@ void MurmurHash3_x86_128(const void* key, //---------- // tail - const uint8_t* tail = (const uint8_t*)(data + nblocks * 16); + const auto* tail = (const uint8_t*)(data + nblocks * 16); uint32_t k1 = 0; uint32_t k2 = 0; @@ -315,7 +316,7 @@ void MurmurHash3_x64_128(const void* key, const int len, const uint32_t seed, void* out) { - const uint8_t* data = (const uint8_t*)key; + const auto* data = (const uint8_t*)key; const int nblocks = len / 16; uint64_t h1 = seed; @@ -327,7 +328,7 @@ void MurmurHash3_x64_128(const void* key, //---------- // body - const uint64_t* blocks = (const uint64_t*)(data); + const auto* blocks = (const uint64_t*)(data); for (int i = 0; i < nblocks; i++) { uint64_t k1 = getblock64(blocks, i * 2 + 0); @@ -355,7 +356,7 @@ void MurmurHash3_x64_128(const void* key, //---------- // tail - const uint8_t* tail = (const uint8_t*)(data + nblocks * 16); + const auto* tail = (const uint8_t*)(data + nblocks * 16); uint64_t k1 = 0; uint64_t k2 = 0; diff --git a/library/src/vocab/byte_view.cc b/library/src/vocab/byte_view.cc index f71dcaa0..8b137891 100644 --- a/library/src/vocab/byte_view.cc +++ b/library/src/vocab/byte_view.cc @@ -1,2 +1 @@ -#include "vocab/byte_view.h" diff --git a/library/src/vocab/slash_delimited.cc b/library/src/vocab/slash_delimited.cc index 48aa806e..2dffa19c 100644 --- a/library/src/vocab/slash_delimited.cc +++ b/library/src/vocab/slash_delimited.cc @@ -1,20 +1,19 @@ #include <vocab/slash_delimited.h> -#include <iostream> +#include <cstddef> -#if __has_include(<base/strings/string_piece.h>) -#include <base/strings/string_piece.h> -#define HAS_STRINGPIECE 1 -#endif +#include <iostream> +#include <string> +#include <string_view> using Self = ipfs::SlashDelimited; Self::SlashDelimited(std::string_view unowned) : remainder_{unowned} {} Self::operator bool() const { - return remainder_.find_first_not_of("/") < remainder_.size(); + return remainder_.find_first_not_of('/') < remainder_.size(); } -std::string_view Self::pop() { +auto Self::pop() -> std::string_view { if (remainder_.empty()) { return remainder_; } @@ -30,16 +29,16 @@ std::string_view Self::pop() { return result; } } -std::string_view Self::pop_all() { +auto Self::pop_all() -> std::string_view { auto result = remainder_; remainder_ = ""; return result; } -std::string_view Self::pop_n(std::size_t n) { - std::size_t a = 0UL; - while (n) { - auto slash = remainder_.find('/', a); - auto non_slash = remainder_.find_first_not_of("/", a); +auto Self::pop_n(std::size_t n) -> std::string_view { + std::size_t idx = 0UL; + while (n > 0UL) { + auto slash = remainder_.find('/', idx); + auto non_slash = remainder_.find_first_not_of('/', idx); if (slash == std::string_view::npos) { auto result = remainder_; remainder_ = ""; @@ -48,46 +47,45 @@ std::string_view Self::pop_n(std::size_t n) { if (non_slash < slash) { --n; } - a = slash + 1UL; + idx = slash + 1UL; } - auto result = remainder_.substr(0UL, a - 1); - remainder_.remove_prefix(a); + auto result = remainder_.substr(0UL, idx - 1); + remainder_.remove_prefix(idx); return result; } -std::string_view Self::peek_back() const { - auto s = remainder_; - while (!s.empty() && s.back() == '/') { - s.remove_suffix(1); +auto Self::peek_back() const -> std::string_view { + auto rem = remainder_; + while (!rem.empty() && rem.back() == '/') { + rem.remove_suffix(1); } - if (s.empty()) { - return s; + if (rem.empty()) { + return rem; } - auto last_slash = s.find_last_of('/'); - if (last_slash < remainder_.size()) { - return remainder_.substr(last_slash + 1); - } else { - return s; + auto last_slash = rem.find_last_of('/'); + if (last_slash < rem.size()) { + rem.remove_prefix(last_slash + 1); } + return rem; } -std::string Self::pop_back() { +auto Self::pop_back() -> std::string { auto non_slash = remainder_.find_last_not_of('/'); if (non_slash == std::string_view::npos) { return ""; } auto slash = remainder_.find_last_of('/', non_slash); - std::string rv; + std::string result; if (slash == std::string_view::npos) { - rv = remainder_; + result = remainder_; remainder_ = ""; } else { - rv = remainder_.substr(slash + 1, non_slash - slash); + result = remainder_.substr(slash + 1, non_slash - slash); remainder_ = remainder_.substr(0UL, slash); } - return rv; + return result; } -std::ostream& operator<<(std::ostream& str, ipfs::SlashDelimited const& sd) { - return str << sd.to_view(); +auto operator<<(std::ostream& stream, ipfs::SlashDelimited const& sdp) -> std::ostream& { + return stream << sdp.to_view(); } #ifndef NACL_TC_REV @@ -99,17 +97,17 @@ using namespace google::protobuf; #if PROTOBUF_VERSION >= 3020000 #include <google/protobuf/stubs/stringpiece.h> -LogMessage& operator<<(LogMessage& str, ipfs::SlashDelimited const& sd) { - return str << sd.to_view(); +LogMessage& operator<<(LogMessage& str, ipfs::SlashDelimited const& sdp) { + return str << sdp.to_view(); } #elif __has_include(<google/protobuf/stubs/stringpiece.h>) #include <google/protobuf/stubs/stringpiece.h> -LogMessage& operator<<(LogMessage& str, ipfs::SlashDelimited const& sd) { - return str << StringPiece{sd.to_view()}; +auto operator<<(LogMessage& str, ipfs::SlashDelimited const& sdp) -> LogMessage& { + return str << StringPiece{sdp.to_view()}; } #else -LogMessage& operator<<(LogMessage& str, ipfs::SlashDelimited const& sd) { - return str << std::string{sd.to_view()}; +LogMessage& operator<<(LogMessage& str, ipfs::SlashDelimited const& sdp) { + return str << std::string{sdp.to_view()}; } #endif diff --git a/test_data/blocks/QmaP752pbiB9G4PpvZbTyBxt9akY7sJF3GvSnnWpRuop9M b/test_data/blocks/QmaP752pbiB9G4PpvZbTyBxt9akY7sJF3GvSnnWpRuop9M deleted file mode 100644 index d4b5a7e2..00000000 --- a/test_data/blocks/QmaP752pbiB9G4PpvZbTyBxt9akY7sJF3GvSnnWpRuop9M +++ /dev/null @@ -1,2 +0,0 @@ - -˜Or6 Or7 Or8 Or9 Os0 Os1 Os2 Os3 Os4 Os5 Os6 Os7 Os8 Os9 Ot0 Ot1 Ot2 Ot3 Ot4 Ot5 Ot6 Ot7 Ot8 Ot9 Ou0 Ou1 Ou2 Ou3 Ou4 Ou5 Ou6 Ou7 Ou8 Ou9 Ov0 Ov1  \ No newline at end of file diff --git a/test_data/blocks/QmaYgBpvEnsjKcsPTYoQv57WahtZg6q4g3QV7sRbe2Ro4V b/test_data/blocks/QmaYgBpvEnsjKcsPTYoQv57WahtZg6q4g3QV7sRbe2Ro4V deleted file mode 100644 index 67a10297..00000000 --- a/test_data/blocks/QmaYgBpvEnsjKcsPTYoQv57WahtZg6q4g3QV7sRbe2Ro4V +++ /dev/null @@ -1,2 +0,0 @@ - -˜Bk0 Bk1 Bk2 Bk3 Bk4 Bk5 Bk6 Bk7 Bk8 Bk9 Bl0 Bl1 Bl2 Bl3 Bl4 Bl5 Bl6 Bl7 Bl8 Bl9 Bm0 Bm1 Bm2 Bm3 Bm4 Bm5 Bm6 Bm7 Bm8 Bm9 Bn0 Bn1 Bn2 Bn3 Bn4 Bn5  \ No newline at end of file diff --git a/test_data/blocks/QmasHhQWRBG41NoHky1gwyBLcV6ADu563uVwyNQy8hcbHT b/test_data/blocks/QmasHhQWRBG41NoHky1gwyBLcV6ADu563uVwyNQy8hcbHT deleted file mode 100644 index 697bcecd..00000000 --- a/test_data/blocks/QmasHhQWRBG41NoHky1gwyBLcV6ADu563uVwyNQy8hcbHT +++ /dev/null @@ -1,2 +0,0 @@ - -˜Xy8 Xy9 Xz0 Xz1 Xz2 Xz3 Xz4 Xz5 Xz6 Xz7 Xz8 Xz9 Ya0 Ya1 Ya2 Ya3 Ya4 Ya5 Ya6 Ya7 Ya8 Ya9 Yb0 Yb1 Yb2 Yb3 Yb4 Yb5 Yb6 Yb7 Yb8 Yb9 Yc0 Yc1 Yc2 Yc3  \ No newline at end of file diff --git a/test_data/blocks/Qmaw3MGQPiduqek71sDXQBC9XJRNvihuRgg5sh7N8x1K9o b/test_data/blocks/Qmaw3MGQPiduqek71sDXQBC9XJRNvihuRgg5sh7N8x1K9o deleted file mode 100644 index b8f26857..00000000 --- a/test_data/blocks/Qmaw3MGQPiduqek71sDXQBC9XJRNvihuRgg5sh7N8x1K9o +++ /dev/null @@ -1,2 +0,0 @@ - -˜Eo8 Eo9 Ep0 Ep1 Ep2 Ep3 Ep4 Ep5 Ep6 Ep7 Ep8 Ep9 Eq0 Eq1 Eq2 Eq3 Eq4 Eq5 Eq6 Eq7 Eq8 Eq9 Er0 Er1 Er2 Er3 Er4 Er5 Er6 Er7 Er8 Er9 Es0 Es1 Es2 Es3  \ No newline at end of file diff --git a/test_data/blocks/bafkreifj6ukwnplhax36u2wvjo455ncj66kvqllffgqoeiqhxcmbem7mla b/test_data/blocks/bafkreifj6ukwnplhax36u2wvjo455ncj66kvqllffgqoeiqhxcmbem7mla deleted file mode 100644 index 9fb75b8d..00000000 --- a/test_data/blocks/bafkreifj6ukwnplhax36u2wvjo455ncj66kvqllffgqoeiqhxcmbem7mla +++ /dev/null @@ -1 +0,0 @@ -E \ No newline at end of file diff --git a/test_data/blocks/bafkreifkvfacmzhruqpub254klezspvwnlvtmzqcswh57krihny6mtnrem b/test_data/blocks/bafkreifkvfacmzhruqpub254klezspvwnlvtmzqcswh57krihny6mtnrem deleted file mode 100644 index be54354a..00000000 --- a/test_data/blocks/bafkreifkvfacmzhruqpub254klezspvwnlvtmzqcswh57krihny6mtnrem +++ /dev/null @@ -1 +0,0 @@ -h \ No newline at end of file