@dittolive/ditto 4.11.2-rc.1 → 4.12.0-experimental-untangle.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@dittolive/ditto",
3
- "version": "4.11.2-rc.1",
3
+ "version": "4.12.0-experimental-untangle.0",
4
4
  "description": "Ditto is a cross-platform SDK that allows apps to sync with and even without internet connectivity.",
5
- "homepage": "https://ditto.live",
5
+ "homepage": "https://ditto.com",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
7
7
 
8
8
  "author": {
9
9
  "name": "DittoLive Incorporated.",
10
- "email": "contact@ditto.live",
11
- "url": "https://ditto.live"
10
+ "email": "contact@ditto.com",
11
+ "url": "https://ditto.com"
12
12
  },
13
13
 
14
14
  "keywords": [
@@ -1,3 +1,4 @@
1
+ #include <ctime>
1
2
  #ifdef DITTOFFI_EXPERIMENTAL_BUS
2
3
  #include <cstring>
3
4
  #include <stdexcept>
@@ -21,6 +22,14 @@ extern "C" {
21
22
  class PeerPubkeySwig {
22
23
  void_const_ptr_2_array_t pubkey;
23
24
 
25
+ const bool is_valid() const noexcept {
26
+ return pubkey.idx[0] && pubkey.idx[1];
27
+ }
28
+ const void invalidate() noexcept {
29
+ pubkey.idx[0] = nullptr;
30
+ pubkey.idx[1] = nullptr;
31
+ }
32
+
24
33
  public:
25
34
  explicit PeerPubkeySwig(char const *peer_key_str) noexcept(false)
26
35
  : pubkey({}) {
@@ -36,9 +45,23 @@ public:
36
45
  explicit PeerPubkeySwig(void_const_ptr_2_array_t key) noexcept
37
46
  : pubkey(key) {}
38
47
 
39
- ~PeerPubkeySwig() noexcept { dittoffi_peer_pubkey_delete(pubkey); }
48
+ PeerPubkeySwig(PeerPubkeySwig const &other) noexcept : pubkey({}) {
49
+ if (other.is_valid()) {
50
+ pubkey = dittoffi_peer_pubkey_clone(&other.pubkey);
51
+ }
52
+ }
40
53
 
41
- std::string to_string() noexcept {
54
+ ~PeerPubkeySwig() noexcept {
55
+ if (this->is_valid()) {
56
+ dittoffi_peer_pubkey_delete(pubkey);
57
+ invalidate();
58
+ }
59
+ }
60
+
61
+ std::string to_string() noexcept(false) {
62
+ if (!this->is_valid()) {
63
+ throw std::runtime_error("Tried to use destroyed PeerPubkey");
64
+ }
42
65
  auto s = dittoffi_peer_pubkey_to_cstr(&pubkey);
43
66
  std::string result((const char *)s.ptr, s.len);
44
67
  return result;
@@ -90,6 +113,9 @@ public:
90
113
  class BytesSwig {
91
114
  Bytes_t bytes;
92
115
 
116
+ bool is_valid() const noexcept { return bytes.vtable != nullptr; }
117
+ void invalidate() noexcept { bytes.vtable = nullptr; }
118
+
93
119
  public:
94
120
  explicit BytesSwig(slice_ref_uint8_t slice) noexcept
95
121
  : bytes(dittoffi_bytes_copied_from_slice(slice)) {}
@@ -97,26 +123,32 @@ public:
97
123
  explicit BytesSwig(Bytes_t bytes) noexcept : bytes(bytes) {}
98
124
 
99
125
  BytesSwig(BytesSwig &&other) noexcept : bytes(other.bytes) {
100
- other.bytes.vtable = nullptr;
126
+ other.invalidate();
101
127
  }
102
128
 
103
- BytesSwig(BytesSwig const &other) noexcept
104
- : bytes(dittoffi_bytes_clone(&other.bytes)) {}
129
+ BytesSwig(BytesSwig const &other) noexcept : bytes({}) {
130
+ if (other.is_valid()) {
131
+ bytes = dittoffi_bytes_clone(&other.bytes);
132
+ }
133
+ }
105
134
 
106
135
  BytesSwig &operator=(BytesSwig const &other) noexcept = default;
107
136
 
108
137
  Bytes_t take() noexcept {
109
138
  auto result = bytes;
110
- bytes.vtable = nullptr;
139
+ invalidate();
111
140
  return result;
112
141
  }
113
142
 
114
- slice_ref_uint8_t data() const noexcept {
115
- return {.ptr = bytes.start, .len = bytes.len};
143
+ slice_ref_uint8_t data() {
144
+ if (!this->is_valid()) {
145
+ throw std::runtime_error("Tried to use destroyed Bytes");
146
+ }
147
+ return dittoffi_bytes_as_slice(&bytes);
116
148
  }
117
149
 
118
150
  virtual ~BytesSwig() noexcept {
119
- if (bytes.vtable != nullptr) {
151
+ if (this->is_valid()) {
120
152
  dittoffi_bytes_drop(&bytes);
121
153
  }
122
154
  }
@@ -226,7 +258,7 @@ public:
226
258
  .free = callback->invokeRelease});
227
259
  }
228
260
 
229
- virtual unsigned size_t max_send_size() noexcept {
261
+ virtual size_t max_send_size() noexcept {
230
262
  return stream.inner.vtable.max_send_size(stream.inner.ptr);
231
263
  }
232
264
  };
@@ -391,7 +423,7 @@ public:
391
423
  }
392
424
 
393
425
  virtual void connect(const char *peer_key_str, const char *topic,
394
- Reliability reliability,
426
+ Reliability reliability, bool request_compression,
395
427
  ConnectionResultCallbackSwig *callback) noexcept {
396
428
  callback->java_retain();
397
429
  slice_ref_uint8_t peer_key_slice = {.ptr = (const uint8_t *)peer_key_str,
@@ -405,7 +437,7 @@ public:
405
437
  bus.inner.vtable.connect(bus.inner.ptr, parsed._1,
406
438
  (slice_ref_uint8_t){.ptr = (const uint8_t *)topic,
407
439
  .len = strlen(topic)},
408
- reliability,
440
+ reliability, request_compression,
409
441
  {.env_ptr = callback,
410
442
  .call = callback->invokeCall,
411
443
  .free = callback->invokeRelease});