ipfs-chromium
ipns_record.h
1 #ifndef IPFS_IPNS_RECORD_H_
2 #define IPFS_IPNS_RECORD_H_
3 
4 #include <ipfs_client/ipns_cbor_entry.h>
5 
6 #include <vocab/byte_view.h>
7 
8 #if __has_include(<third_party/ipfs_client/keys.pb.h>)
9 #include <third_party/ipfs_client/keys.pb.h>
10 #else
11 #include "ipfs_client/keys.pb.h"
12 #endif
13 
14 #include <functional>
15 #include <optional>
16 
17 namespace libp2p::peer {
18 class PeerId;
19 }
20 namespace libp2p::multi {
21 struct ContentIdentifier;
22 }
23 
24 namespace ipfs {
25 
26 class Cid;
27 class Client;
28 
29 constexpr static std::size_t MAX_IPNS_PB_SERIALIZED_SIZE = 10 * 1024;
30 
31 std::optional<IpnsCborEntry> ValidateIpnsRecord(ByteView top_level_bytes,
32  Cid const& name,
33  Client&);
34 
38 struct ValidatedIpns {
39  std::string value;
40  std::time_t use_until;
41  std::time_t cache_until;
42 
47  std::uint64_t sequence;
48  std::int64_t resolution_ms;
49 
53  std::time_t fetch_time = std::time(nullptr);
54  std::string gateway_source;
55 
59  explicit ValidatedIpns(IpnsCborEntry const& entry);
62  ValidatedIpns& operator=(ValidatedIpns const&);
63 
64  std::string Serialize() const;
65 
72  static ValidatedIpns Deserialize(std::string bytes);
73 };
74 
75 } // namespace ipfs
76 
77 #endif // IPFS_IPNS_RECORD_H_
Definition: dag_node.h:28
Parsed out data contained in the CBOR data of an IPNS record.
Definition: ipns_cbor_entry.h:11
Data from IPNS record modulo the verification parts.
Definition: ipns_record.h:38
std::string Serialize() const
Turn into a well-defined list of bytes.
Definition: ipns_record.cc:229
std::uint64_t sequence
The version of the record.
Definition: ipns_record.h:47
std::time_t fetch_time
When the record was fetched.
Definition: ipns_record.h:53
ValidatedIpns()
Create an invalid default object.
std::time_t cache_until
Inspired by TTL.
Definition: ipns_record.h:41
std::string gateway_source
Who gave us this record?
Definition: ipns_record.h:54
std::int64_t resolution_ms
How long it took to fetch the record.
Definition: ipns_record.h:48
std::time_t use_until
An expiration timestamp.
Definition: ipns_record.h:40
static ValidatedIpns Deserialize(std::string bytes)
Create a ValidatedIpns from untyped bytes.
Definition: ipns_record.cc:238
std::string value
The path the record claims the IPNS name points to.
Definition: ipns_record.h:39