1 #ifndef IPFS_CONTEXT_API_H_
2 #define IPFS_CONTEXT_API_H_
4 #include "crypto/hasher.h"
5 #include "crypto/signature_verifier.h"
6 #include "crypto/signing_key_type.h"
7 #include "ctx/cbor_parser.h"
8 #include "ctx/dns_txt_lookup.h"
9 #include "ctx/gateway_config.h"
10 #include "ctx/http_api.h"
11 #include "ctx/json_parser.h"
12 #include "dag_cbor_value.h"
13 #include "gw/requestor.h"
14 #include "http_request_description.h"
15 #include "ipns_cbor_entry.h"
16 #include "multi_hash.h"
18 #include <vocab/byte_view.h>
24 #include <unordered_map>
26 namespace boost::asio {
42 class Client :
public std::enable_shared_from_this<Client> {
44 using SigningKeyType = ::ipfs::crypto::SigningKeyType;
45 using MimeTypeDeduction = std::function<
46 std::string(std::string, std::string_view, std::string
const&)>;
47 using UrlUnescaping = std::function<std::string(std::string_view)>;
50 using DnslinkFallbackSwitch = std::function<bool()>;
53 virtual ~
Client() noexcept {}
55 std::shared_ptr<Partition> partition(std::string key);
61 std::shared_ptr<gw::Requestor> requestor();
63 Client& with(std::unique_ptr<ctx::HttpApi>);
64 Client& with(std::unique_ptr<ctx::DnsTxtLookup>);
65 Client& with(std::unique_ptr<ctx::GatewayConfig>);
66 Client& with(std::unique_ptr<ctx::JsonParser>);
67 Client& with(std::unique_ptr<ctx::CborParser>);
68 Client& with(std::shared_ptr<gw::Requestor>);
69 Client& with(SigningKeyType, std::unique_ptr<crypto::SignatureVerifier>);
70 Client& with(MimeTypeDeduction);
71 Client& with(UrlUnescaping);
72 Client& with(DnslinkFallbackSwitch);
81 std::string_view content,
82 std::string
const& url);
92 using ByteView = ::ipfs::ByteView;
93 bool VerifyKeySignature(SigningKeyType,
96 ByteView key_bytes)
const;
98 std::optional<std::vector<Byte>> Hash(HashType, ByteView data);
100 bool DnslinkFallback()
const;
103 std::unordered_map<HashType, std::unique_ptr<crypto::Hasher>> hashers_;
104 std::unordered_map<SigningKeyType, std::unique_ptr<crypto::SignatureVerifier>>
106 std::unique_ptr<ctx::HttpApi> http_api_;
107 std::unique_ptr<ctx::DnsTxtLookup> dns_txt_;
108 std::unique_ptr<ctx::GatewayConfig> gateway_config_;
109 std::unique_ptr<ctx::JsonParser> json_parser_;
110 std::unique_ptr<ctx::CborParser> cbor_parser_;
111 MimeTypeDeduction deduce_mime_type_;
112 UrlUnescaping unescape_;
113 std::shared_ptr<gw::Requestor> rtor_;
114 std::unordered_map<std::string, std::shared_ptr<Partition>> partitions_;
115 DnslinkFallbackSwitch dns_fb_;
Interface that provides functionality from whatever environment you're using this library in.
Definition: client.h:42
std::string MimeType(std::string extension, std::string_view content, std::string const &url)
Determine a mime type for a given file.
std::string UnescapeUrlComponent(std::string_view url_comp)
Remove URL escaping, e.g. %20.
Definition: cbor_parser.h:15
Definition: dns_txt_lookup.h:11
Definition: gateway_config.h:13
Definition: http_api.h:11
Definition: json_parser.h:14