Ditto 4.13.1
 
Loading...
Searching...
No Matches
DittoConfig.hpp
1#ifndef DITTO_DITTO_CONFIG_H
2#define DITTO_DITTO_CONFIG_H
3
4#include "json.hpp"
5
6#include <memory>
7#include <string>
8
9#ifdef __ANDROID__
10#include <jni.h>
11#endif /* __ANDROID__ */
12
13namespace ditto {
14
31
41 class Connect {
42 public:
46 enum class Type { server, small_peers_only };
47
48 virtual ~Connect() = default;
49 virtual Type get_type() const = 0;
50
58 static std::shared_ptr<Connect> server(std::string url);
59
68 static std::shared_ptr<Connect>
69 small_peers_only(std::string private_key = "");
70 };
71
79 class ServerConnect : public Connect {
80 private:
81 std::string url;
82
83 public:
84 explicit ServerConnect(std::string url);
85
86 ServerConnect(const ServerConnect &other) = default;
87 ServerConnect(ServerConnect &&other) = default;
88 ServerConnect &operator=(const ServerConnect &other) = default;
89 ServerConnect &operator=(ServerConnect &&other) = default;
90 ~ServerConnect() override = default;
91
92 Type get_type() const override;
93 const std::string &get_url() const;
94 };
95
103 class SmallPeersOnlyConnect : public Connect {
104 private:
105 std::string private_key;
106
107 public:
108 explicit SmallPeersOnlyConnect(std::string private_key = "");
109
110 SmallPeersOnlyConnect(const SmallPeersOnlyConnect &other) = default;
111 SmallPeersOnlyConnect(SmallPeersOnlyConnect &&other) = default;
112 SmallPeersOnlyConnect &
113 operator=(const SmallPeersOnlyConnect &other) = default;
114 SmallPeersOnlyConnect &operator=(SmallPeersOnlyConnect &&other) = default;
115 ~SmallPeersOnlyConnect() override = default;
116
117 Type get_type() const override;
118 const std::string &get_private_key() const;
119 };
120
127 std::string database_id;
128
132 std::shared_ptr<Connect> connect;
133
140 std::string passphrase;
141
146 Experimental &set_passphrase(std::string pass) noexcept;
147 };
148
153
154#ifdef __ANDROID__
156 void *android_context = nullptr;
157#endif
158
161
163 DittoConfig() = default;
164
165 DittoConfig(const DittoConfig &other) = default;
166 DittoConfig(DittoConfig &&other) = default;
167 DittoConfig &operator=(const DittoConfig &other) = default;
168 DittoConfig &operator=(DittoConfig &&other) = default;
169 ~DittoConfig() = default;
170
178
179#ifdef __ANDROID__
184 DittoConfig &set_android_context(void *android_context) noexcept;
185#endif
186
193
201
207 DittoConfig &set_connect(std::shared_ptr<Connect> connect) noexcept;
208
215 DittoConfig &set_server_connect(std::string url) noexcept;
216
225 set_small_peers_only_connect(std::string private_key = "") noexcept;
226
233
241 static std::string default_database_id() noexcept;
242};
243
244// JSON serialization for DittoConfig
245void to_json(nlohmann::json &j, const DittoConfig &c);
246void from_json(const nlohmann::json &j, DittoConfig &c);
247
248} // namespace ditto
249
250#endif
Specifies how this instance discovers and connects to peers, including network settings and authentic...
Definition DittoConfig.hpp:41
static std::shared_ptr< Connect > server(std::string url)
Factory method to create a server connection.
static std::shared_ptr< Connect > small_peers_only(std::string private_key="")
Factory method to create a small-peers-only connection.
Type
Connection configuration type.
Definition DittoConfig.hpp:46
Namespace for the Ditto C++ SDK types and functions.
Definition AbstractDocumentPath.hpp:19
Experimental features configuration.
Definition DittoConfig.hpp:137
std::string passphrase
passphrase for data encryption at rest (empty means no encryption)
Definition DittoConfig.hpp:140
Experimental & set_passphrase(std::string pass) noexcept
Set the passphrase for data encryption at rest.
DittoConfig & set_small_peers_only_connect(std::string private_key="") noexcept
Set the connection configuration to small peers only mode.
DittoConfig & set_experimental(Experimental exp) noexcept
Set the experimental features configuration.
DittoConfig & set_connect(std::shared_ptr< Connect > connect) noexcept
Set the connection configuration.
std::string persistence_directory
the directory that will be used to persist Ditto data
Definition DittoConfig.hpp:160
std::string database_id
The unique identifier for the Ditto instance.
Definition DittoConfig.hpp:127
std::shared_ptr< Connect > connect
Connection configuration for this Ditto instance.
Definition DittoConfig.hpp:132
static std::string default_database_id() noexcept
Returns the default identifier for a Ditto instance.
DittoConfig()=default
Constructor for an empty configuration.
DittoConfig & set_server_connect(std::string url) noexcept
Set the connection configuration to server mode.
static DittoConfig default_config()
Get a usable default configuration.
DittoConfig & set_persistence_directory(std::string persistence_directory) noexcept
Set the directory that will be used to persist Ditto data.
Experimental experimental
Experimental features configuration for this Ditto instance.
Definition DittoConfig.hpp:152
DittoConfig & set_database_id(std::string database_id) noexcept
Set the unique identifier for the Ditto instance.