diff --git a/chromium_edits/123.0.6272.0/components/cbor/reader.cc.patch b/chromium_edits/123.0.6272.0/components/cbor/reader.cc.patch index a998ff58..1b19203f 100644 --- a/chromium_edits/123.0.6272.0/components/cbor/reader.cc.patch +++ b/chromium_edits/123.0.6272.0/components/cbor/reader.cc.patch @@ -14,7 +14,8 @@ index 3c31e3d05e5d3..b0cf411b350e2 100644 @@ -157,6 +157,10 @@ std::optional Reader::DecodeCompleteDataItem(const Config& config, // 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: // We explicitly don't support TAG. ++ case Value::Type::TAG: + if (config.parse_tags) { + return ReadTagContent(*header, config, max_nesting_level); + } diff --git a/component/chromium_ipfs_context.h b/component/chromium_ipfs_context.h index b797ca84..476c8892 100644 --- a/component/chromium_ipfs_context.h +++ b/component/chromium_ipfs_context.h @@ -5,7 +5,7 @@ #include "preferences.h" #include -#include +#include #include #include diff --git a/component/dns_txt_request.h b/component/dns_txt_request.h index de13d6b7..28171ee9 100644 --- a/component/dns_txt_request.h +++ b/component/dns_txt_request.h @@ -1,7 +1,7 @@ #ifndef IPFS_DNS_TXT_REQUEST_H_ #define IPFS_DNS_TXT_REQUEST_H_ -#include +#include #include #include diff --git a/library/README.md b/library/README.md index 0e6ffadd..f96c43dd 100644 --- a/library/README.md +++ b/library/README.md @@ -1,6 +1,66 @@ # ipfs-client -## TODO +## Usage -Need to fill out this README to explain how to use ipfs-client in other contexts. + +### Instantiate ipfs::Client + +Using code should center on the `ipfs::Client` class found in `include/ipfs_client/client.h` +There are a number of customization points for that class, particularly those things which might vary depending on +which dependencies you'd like to use and/or which behaviors you'd like. + +Some concrete classes are provided with the library, each turned off if the corresponding dependency does not appear to +be available. If you're using the Conan package, and not on Windows, all those libraries should be already linked in for you. +In that case, you may use `ipfs::start_default` found in `include/ipfs_client/opinionated_context.h` , which is suitable for some non-critical uses. + +If any of these choices don't make sense for your project, you may create a concrete class for whichever interface you need to alter, and call `with()` on the Client object, passing in an instance of your class. +If you don't call `with()`, usually you get an implementation that simply doesn't do anything (null object), or does something very simplistic. + +To see the sorts of extension points available, look at the various `with()` methods in `ipfs::Client`. For example: + +| Interface | Function | Provided example implementation | Design choice in example | +|-----------------------------------|----------------------------------------------------------------------|---------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------| +| ipfs::ctx::HttpApi | Make HTTP(s) requests | ipfs::ctx::BoostBeastHttp | Uses [Boost.Beast](https://www.boost.org/doc/libs/1_84_0/libs/beast/doc/html/index.html) | +| ipfs::ctx::DnsTxtLookup | DNS TXT requests (not name resolution) | ipfs::ctx::AresDnsTxtLookup | Uses [c-ares](https://c-ares.org/) | +| ipfs::ctx::GatewayConfig | Configures which IPFS gateways you use and how | ipfs::ctx::TransitoryGatewayConfig | Loads IPFS_GATEWAY environment variable, or if not set a static list of gateways. Changes at runtime are not persisted. | +| ipfs::ctx::JsonParser | Parses JSON (String -> ipfs::DagJsonValue) | ipfs::ctx::NlohmannJsonParser | Uses N. Lohmann's [JSON for Modern C++](https://github.com/nlohmann/json) | +| ipfs::ctx::CborParser | Parses CBOR (Bytes -> ipfs::DagCborValue) | ipfs::ctx::NlohmannCborParser | Uses N. Lohmann's [JSON for Modern C++](https://github.com/nlohmann/json), but for CBOR | +| ipfs::gw::Requestor | A chain-of-responsibility for processing IPFS requests | ipfs::gw::default_requestor() returns common requestors | If you don't provide an argument, this chain does no caching. | +| MimeTypeDeduction | A function that guesses the mime type of a doc given its head & path | ipfs::util::TrivialMimeGuess | Doesn't even look at file content, just uses extension. Fine for cases that don't really need the mime type. | +| UrlUnescaping | Given a URL component (i.e. in-between `/`s), deal with % escaping | ipfs::util::RoughlyUnescapeUrlComponent | Not a complete implementation, but deals with some common cases. | +| ipfs::crypto::SignatureVerifier | Verifies a public key signature for a particular type of key | ipfs::crypto::OpensslSignatureVerifier | Uses OpenSSL, but only for RSA & Ed25519 keys (others are dropped) | + +### Get a partition + +`ipfs::Client::partition()` takes an arbitrary string to use as a key for that partition. +The scheme for the keys is whatever you'd like it to be, but if you pass in an identical key you'll get the same partition back each time. +If it's the first time for that key, a new object is created, including an isolated view of the DAGs. + +If you are not in a security-critical case, it's entirely reasonable to pass in `""` every time. +You might also consider using URL origins to define partitioning. + +### Make a request + +`std::make_shared(path, callback)` + +* path - A string of the form /ipfs//path/to/file or /ipns//path/to/file +* callback - What to call when a final response is formed. + +Pass the request to `partition->build_response()` + +### Drive your HttpApi and DnsTxtLookup implementations + +Many implementations will need some sort of event loop. Do that. + +### Handle response + +The callback you passed to create the request. +Be sure to check the second parameter's (the response's) status_ field, which contains HTTP statuses like: + +* 200 - success +* 404 - unable to find it from known gateways (possibly timed out) +* 410 - That path does not exist in that DAG, provably. +* 503 - Unable to resolve IPNS name (either DNSLink failed to resolve or gateways didn't have the IPNS record, as appropriate) + +Depending on quirks of your various implementations you may need to do extra logic here. diff --git a/library/include/ipfs_client/context_api.h b/library/include/ipfs_client/client.h similarity index 99% rename from library/include/ipfs_client/context_api.h rename to library/include/ipfs_client/client.h index 655c172c..27334335 100644 --- a/library/include/ipfs_client/context_api.h +++ b/library/include/ipfs_client/client.h @@ -56,6 +56,7 @@ class Client : public std::enable_shared_from_this { ctx::JsonParser& json(); ctx::CborParser& cbor(); std::shared_ptr requestor(); + Client& with(std::unique_ptr); Client& with(std::unique_ptr); Client& with(std::unique_ptr); diff --git a/library/include/ipfs_client/gw/gateway_request.h b/library/include/ipfs_client/gw/gateway_request.h index b5c6069a..a5a5939e 100644 --- a/library/include/ipfs_client/gw/gateway_request.h +++ b/library/include/ipfs_client/gw/gateway_request.h @@ -2,7 +2,7 @@ #define IPFS_TRUSTLESS_REQUEST_H_ #include -#include +#include #include #include diff --git a/library/include/ipfs_client/opinionated_context.h b/library/include/ipfs_client/opinionated_context.h index 5c5e0114..a7863b25 100644 --- a/library/include/ipfs_client/opinionated_context.h +++ b/library/include/ipfs_client/opinionated_context.h @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include diff --git a/library/src/ipfs_client/car.cc b/library/src/ipfs_client/car.cc index be9a24a7..9e3123f2 100644 --- a/library/src/ipfs_client/car.cc +++ b/library/src/ipfs_client/car.cc @@ -1,6 +1,6 @@ #include "car.h" -#include +#include #include diff --git a/library/src/ipfs_client/context_api.cc b/library/src/ipfs_client/client.cc similarity index 99% rename from library/src/ipfs_client/context_api.cc rename to library/src/ipfs_client/client.cc index f4014743..c50de381 100644 --- a/library/src/ipfs_client/context_api.cc +++ b/library/src/ipfs_client/client.cc @@ -1,4 +1,4 @@ -#include +#include #include "crypto/openssl_sha2_256.h" #include "ipfs_client/crypto/openssl_signature_verifier.h" diff --git a/library/src/ipfs_client/context_api_unittest.cc b/library/src/ipfs_client/context_api_unittest.cc index 0a1c373a..012d9106 100644 --- a/library/src/ipfs_client/context_api_unittest.cc +++ b/library/src/ipfs_client/context_api_unittest.cc @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/library/src/ipfs_client/gw/dnslink_requestor.cc b/library/src/ipfs_client/gw/dnslink_requestor.cc index 1b06c9ed..d44c35a5 100644 --- a/library/src/ipfs_client/gw/dnslink_requestor.cc +++ b/library/src/ipfs_client/gw/dnslink_requestor.cc @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include diff --git a/library/src/ipfs_client/gw/multi_gateway_requestor.h b/library/src/ipfs_client/gw/multi_gateway_requestor.h index d76aa43b..eab40591 100644 --- a/library/src/ipfs_client/gw/multi_gateway_requestor.h +++ b/library/src/ipfs_client/gw/multi_gateway_requestor.h @@ -5,7 +5,7 @@ #include -#include +#include #include #include diff --git a/library/src/ipfs_client/gw/providers_response.cc b/library/src/ipfs_client/gw/providers_response.cc index 1fd8a3a1..15c7a62e 100644 --- a/library/src/ipfs_client/gw/providers_response.cc +++ b/library/src/ipfs_client/gw/providers_response.cc @@ -1,6 +1,6 @@ #include "providers_response.h" -#include +#include #include #include diff --git a/library/src/ipfs_client/ipld/dag_cbor_node.h b/library/src/ipfs_client/ipld/dag_cbor_node.h index c9ba5333..663e30cb 100644 --- a/library/src/ipfs_client/ipld/dag_cbor_node.h +++ b/library/src/ipfs_client/ipld/dag_cbor_node.h @@ -3,7 +3,7 @@ #include -#include +#include namespace ipfs::ipld { class DagCborNode final : public DagNode { diff --git a/library/src/ipfs_client/ipld/dag_node.cc b/library/src/ipfs_client/ipld/dag_node.cc index c7daefd2..aef890a2 100644 --- a/library/src/ipfs_client/ipld/dag_node.cc +++ b/library/src/ipfs_client/ipld/dag_node.cc @@ -10,7 +10,7 @@ #include "symlink.h" #include "unixfs_file.h" -#include +#include #include #include diff --git a/library/src/ipfs_client/ipld/directory_shard.cc b/library/src/ipfs_client/ipld/directory_shard.cc index a225601d..f0638269 100644 --- a/library/src/ipfs_client/ipld/directory_shard.cc +++ b/library/src/ipfs_client/ipld/directory_shard.cc @@ -2,7 +2,7 @@ #include "log_macros.h" -#include +#include #include #include diff --git a/library/src/ipfs_client/ipld/resolution_state.cc b/library/src/ipfs_client/ipld/resolution_state.cc index a0c277ec..3cb0f476 100644 --- a/library/src/ipfs_client/ipld/resolution_state.cc +++ b/library/src/ipfs_client/ipld/resolution_state.cc @@ -1,6 +1,6 @@ #include -#include +#include using Self = ipfs::ipld::ResolutionState; diff --git a/library/src/ipfs_client/ipld/small_directory.cc b/library/src/ipfs_client/ipld/small_directory.cc index 39c66f22..f7af5e3d 100644 --- a/library/src/ipfs_client/ipld/small_directory.cc +++ b/library/src/ipfs_client/ipld/small_directory.cc @@ -1,6 +1,6 @@ #include "small_directory.h" -#include +#include #include "ipfs_client/generated_directory_listing.h" #include "ipfs_client/path2url.h" diff --git a/library/src/ipfs_client/ipns_record.cc b/library/src/ipfs_client/ipns_record.cc index f5404a7c..f1a6988f 100644 --- a/library/src/ipfs_client/ipns_record.cc +++ b/library/src/ipfs_client/ipns_record.cc @@ -1,7 +1,7 @@ #include #include -#include +#include #include #include "log_macros.h" diff --git a/library/src/ipfs_client/partition.cc b/library/src/ipfs_client/partition.cc index 56ec70e0..81dd94ea 100644 --- a/library/src/ipfs_client/partition.cc +++ b/library/src/ipfs_client/partition.cc @@ -1,6 +1,6 @@ #include "ipfs_client/partition.h" -#include +#include #include #include "log_macros.h" diff --git a/library/src/ipfs_client/pb_dag.cc b/library/src/ipfs_client/pb_dag.cc index 15bd19bf..1529a9b4 100644 --- a/library/src/ipfs_client/pb_dag.cc +++ b/library/src/ipfs_client/pb_dag.cc @@ -1,6 +1,6 @@ #include "ipfs_client/pb_dag.h" -#include +#include #include "log_macros.h" diff --git a/test_data/include/mock_api.h b/test_data/include/mock_api.h index b65aa57e..0a2849c5 100644 --- a/test_data/include/mock_api.h +++ b/test_data/include/mock_api.h @@ -3,7 +3,7 @@ #include -#include +#include #include #include "mock_gw_cfg.h" diff --git a/test_data/include/mock_cbor.h b/test_data/include/mock_cbor.h index 5cdcb9cd..2a0dfc7d 100644 --- a/test_data/include/mock_cbor.h +++ b/test_data/include/mock_cbor.h @@ -1,7 +1,7 @@ #ifndef IPFS_MOCK_BOR_H_ #define IPFS_MOCK_BOR_H_ -#include "ipfs_client/context_api.h" +#include "ipfs_client/client.h" #include diff --git a/test_data/include/mock_requestor.h b/test_data/include/mock_requestor.h index 5914ae7a..22b9e343 100644 --- a/test_data/include/mock_requestor.h +++ b/test_data/include/mock_requestor.h @@ -1,7 +1,7 @@ #ifndef IPFS_TEST_REQUESTOR_H_ #define IPFS_TEST_REQUESTOR_H_ -#include +#include #include #include