ipfs-chromium
Loading...
Searching...
No Matches
client.h
1#ifndef IPFS_CONTEXT_API_H_
2#define IPFS_CONTEXT_API_H_
3
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"
17
18#include <vocab/byte_view.h>
19
20#include <cstdint>
21#include <functional>
22#include <memory>
23#include <optional>
24#include <unordered_map>
25
26namespace boost::asio {
27class io_context;
28}
29
30namespace ipfs {
31class Partition;
32class IpfsRequest;
33class DagJsonValue;
34class DagCborValue;
35
42class Client : public std::enable_shared_from_this<Client> {
43 public:
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)>;
48
49 //TODO this should probably with GatewayConfig stuff
50 using DnslinkFallbackSwitch = std::function<bool()>;
51
52 Client();
53 virtual ~Client() noexcept {}
54
55 std::shared_ptr<Partition> partition(std::string key);
56 ctx::HttpApi& http();
57 ctx::DnsTxtLookup& dns_txt();
58 ctx::GatewayConfig& gw_cfg();
59 ctx::JsonParser& json();
60 ctx::CborParser& cbor();
61 std::shared_ptr<gw::Requestor> requestor();
62
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);
73
80 std::string MimeType(std::string extension,
81 std::string_view content,
82 std::string const& url);
83
90 std::string UnescapeUrlComponent(std::string_view url_comp);
91
92 using ByteView = ::ipfs::ByteView;
93 bool VerifyKeySignature(SigningKeyType,
94 ByteView signature,
95 ByteView data,
96 ByteView key_bytes) const;
97
98 std::optional<std::vector<Byte>> Hash(HashType, ByteView data);
99
100 bool DnslinkFallback() const;
101
102 protected:
103 std::unordered_map<HashType, std::unique_ptr<crypto::Hasher>> hashers_;
104 std::unordered_map<SigningKeyType, std::unique_ptr<crypto::SignatureVerifier>>
105 verifiers_;
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_;
116};
117
118} // namespace ipfs
119
120#endif
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