@minip2p/react-native 0.4.5 → 0.4.7

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.
Files changed (37) hide show
  1. package/Minip2p.podspec +1 -1
  2. package/android/src/main/java/com/minip2p/Minip2pPackage.kt +2 -2
  3. package/android/src/main/jniLibs/arm64-v8a/libminip2p_ffi.so +0 -0
  4. package/android/src/main/jniLibs/x86_64/libminip2p_ffi.so +0 -0
  5. package/build/Minip2pFfi.xcframework/ios-arm64/libminip2p_ffi.a +0 -0
  6. package/build/Minip2pFfi.xcframework/ios-arm64-simulator/libminip2p_ffi.a +0 -0
  7. package/cpp/generated/minip2p_ffi.cpp +263 -205
  8. package/cpp/generated/minip2p_ffi.hpp +8 -6
  9. package/lib/module/adapter.js +11 -10
  10. package/lib/module/adapter.js.map +1 -1
  11. package/lib/module/event-drain.js +71 -0
  12. package/lib/module/event-drain.js.map +1 -0
  13. package/lib/module/generated/minip2p_ffi-ffi.js.map +1 -1
  14. package/lib/module/generated/minip2p_ffi.js +665 -693
  15. package/lib/module/generated/minip2p_ffi.js.map +1 -1
  16. package/lib/typescript/src/NativeMinip2p.d.ts.map +1 -1
  17. package/lib/typescript/src/adapter.d.ts.map +1 -1
  18. package/lib/typescript/src/event-drain.d.ts +10 -0
  19. package/lib/typescript/src/event-drain.d.ts.map +1 -0
  20. package/lib/typescript/src/generated/minip2p_ffi-ffi.d.ts +16 -14
  21. package/lib/typescript/src/generated/minip2p_ffi-ffi.d.ts.map +1 -1
  22. package/lib/typescript/src/generated/minip2p_ffi.d.ts +785 -782
  23. package/lib/typescript/src/generated/minip2p_ffi.d.ts.map +1 -1
  24. package/lib/typescript/src/hook-lifecycle.d.ts.map +1 -1
  25. package/lib/typescript/src/hooks.d.ts.map +1 -1
  26. package/lib/typescript/src/native.d.ts.map +1 -1
  27. package/lib/typescript/tests/adapter-event-drain.test.d.ts +2 -0
  28. package/lib/typescript/tests/adapter-event-drain.test.d.ts.map +1 -0
  29. package/lib/typescript/tests/event-drain.test.d.ts +2 -0
  30. package/lib/typescript/tests/event-drain.test.d.ts.map +1 -0
  31. package/lib/typescript/vitest.built.config.d.ts +3 -0
  32. package/lib/typescript/vitest.built.config.d.ts.map +1 -0
  33. package/package.json +18 -18
  34. package/src/adapter.ts +15 -11
  35. package/src/event-drain.ts +80 -0
  36. package/src/generated/minip2p_ffi-ffi.ts +16 -14
  37. package/src/generated/minip2p_ffi.ts +665 -705
@@ -12,28 +12,6 @@
12
12
  namespace react = facebook::react;
13
13
  namespace jsi = facebook::jsi;
14
14
 
15
- namespace minip2p_callback_context {
16
- thread_local unsigned int depth = 0;
17
-
18
- class Scope final {
19
- public:
20
- Scope() noexcept {
21
- depth += 1;
22
- }
23
-
24
- ~Scope() {
25
- depth -= 1;
26
- }
27
-
28
- Scope(const Scope&) = delete;
29
- Scope& operator=(const Scope&) = delete;
30
- };
31
-
32
- bool active() noexcept {
33
- return depth != 0;
34
- }
35
- } // namespace minip2p_callback_context
36
-
37
15
  // Calling into Rust.
38
16
  extern "C" {
39
17
  typedef void
@@ -152,15 +130,29 @@ extern "C" {
152
130
  UniffiForeignFutureResultVoid result
153
131
  );
154
132
  typedef void
155
- (*UniffiCallbackInterfaceP2pEventListenerMethod0)(
133
+ (*UniffiCallbackInterfaceP2pEventDoorbellMethod0)(
156
134
  uint64_t uniffi_handle,
157
- RustBuffer event,
158
135
  void * uniffi_out_return, RustCallStatus* rust_call_status
159
- );typedef struct UniffiVTableCallbackInterfaceP2pEventListener {
136
+ );typedef struct UniffiVTableCallbackInterfaceP2pEventDoorbell {
160
137
  UniffiCallbackInterfaceFree uniffi_free;
161
138
  UniffiCallbackInterfaceClone uniffi_clone;
162
- UniffiCallbackInterfaceP2pEventListenerMethod0 on_event;
163
- } UniffiVTableCallbackInterfaceP2pEventListener;
139
+ UniffiCallbackInterfaceP2pEventDoorbellMethod0 on_events_ready;
140
+ } UniffiVTableCallbackInterfaceP2pEventDoorbell;
141
+ /*handle*/ uint64_t uniffi_minip2p_ffi_fn_clone_p2peventdoorbell(
142
+ /*handle*/ uint64_t handle,
143
+ RustCallStatus *uniffi_out_err
144
+ );
145
+ void uniffi_minip2p_ffi_fn_free_p2peventdoorbell(
146
+ /*handle*/ uint64_t handle,
147
+ RustCallStatus *uniffi_out_err
148
+ );
149
+ void uniffi_minip2p_ffi_fn_init_callback_vtable_p2peventdoorbell(
150
+ UniffiVTableCallbackInterfaceP2pEventDoorbell * vtable
151
+ );
152
+ void uniffi_minip2p_ffi_fn_method_p2peventdoorbell_on_events_ready(
153
+ /*handle*/ uint64_t ptr,
154
+ RustCallStatus *uniffi_out_err
155
+ );
164
156
  /*handle*/ uint64_t uniffi_minip2p_ffi_fn_clone_p2pendpoint(
165
157
  /*handle*/ uint64_t handle,
166
158
  RustCallStatus *uniffi_out_err
@@ -244,6 +236,11 @@ extern "C" {
244
236
  /*handle*/ uint64_t ptr,
245
237
  RustCallStatus *uniffi_out_err
246
238
  );
239
+ RustBuffer uniffi_minip2p_ffi_fn_method_p2pendpoint_drain_events(
240
+ /*handle*/ uint64_t ptr,
241
+ uint32_t limit,
242
+ RustCallStatus *uniffi_out_err
243
+ );
247
244
  int8_t uniffi_minip2p_ffi_fn_method_p2pendpoint_is_peer_ready(
248
245
  /*handle*/ uint64_t ptr,
249
246
  RustBuffer peer_id,
@@ -316,7 +313,7 @@ extern "C" {
316
313
  );
317
314
  void uniffi_minip2p_ffi_fn_method_p2pendpoint_start(
318
315
  /*handle*/ uint64_t ptr,
319
- /*handle*/ uint64_t listener,
316
+ /*handle*/ uint64_t doorbell,
320
317
  RustCallStatus *uniffi_out_err
321
318
  );
322
319
  void uniffi_minip2p_ffi_fn_method_p2pendpoint_stop(
@@ -338,22 +335,6 @@ extern "C" {
338
335
  uint64_t timeout_ms,
339
336
  RustCallStatus *uniffi_out_err
340
337
  );
341
- /*handle*/ uint64_t uniffi_minip2p_ffi_fn_clone_p2peventlistener(
342
- /*handle*/ uint64_t handle,
343
- RustCallStatus *uniffi_out_err
344
- );
345
- void uniffi_minip2p_ffi_fn_free_p2peventlistener(
346
- /*handle*/ uint64_t handle,
347
- RustCallStatus *uniffi_out_err
348
- );
349
- void uniffi_minip2p_ffi_fn_init_callback_vtable_p2peventlistener(
350
- UniffiVTableCallbackInterfaceP2pEventListener * vtable
351
- );
352
- void uniffi_minip2p_ffi_fn_method_p2peventlistener_on_event(
353
- /*handle*/ uint64_t ptr,
354
- RustBuffer event,
355
- RustCallStatus *uniffi_out_err
356
- );
357
338
  RustBuffer uniffi_minip2p_ffi_fn_func_circuit_address(
358
339
  RustBuffer relay_addr,
359
340
  RustBuffer peer_id,
@@ -568,6 +549,8 @@ extern "C" {
568
549
  );
569
550
  uint16_t uniffi_minip2p_ffi_checksum_func_peer_id_from_secret_key(
570
551
  );
552
+ uint16_t uniffi_minip2p_ffi_checksum_method_p2peventdoorbell_on_events_ready(
553
+ );
571
554
  uint16_t uniffi_minip2p_ffi_checksum_method_p2pendpoint_abandon_stream(
572
555
  );
573
556
  uint16_t uniffi_minip2p_ffi_checksum_method_p2pendpoint_active_reservation(
@@ -596,6 +579,8 @@ extern "C" {
596
579
  );
597
580
  uint16_t uniffi_minip2p_ffi_checksum_method_p2pendpoint_discovery_now_ms(
598
581
  );
582
+ uint16_t uniffi_minip2p_ffi_checksum_method_p2pendpoint_drain_events(
583
+ );
599
584
  uint16_t uniffi_minip2p_ffi_checksum_method_p2pendpoint_is_peer_ready(
600
585
  );
601
586
  uint16_t uniffi_minip2p_ffi_checksum_method_p2pendpoint_is_running(
@@ -634,8 +619,6 @@ extern "C" {
634
619
  );
635
620
  uint16_t uniffi_minip2p_ffi_checksum_method_p2pendpoint_wait_stopped(
636
621
  );
637
- uint16_t uniffi_minip2p_ffi_checksum_method_p2peventlistener_on_event(
638
- );
639
622
  uint16_t uniffi_minip2p_ffi_checksum_constructor_p2pendpoint_new(
640
623
  );
641
624
  uint32_t ffi_minip2p_ffi_uniffi_contract_version(
@@ -700,18 +683,58 @@ template <> struct Bridging<RustBuffer> {
700
683
  static RustBuffer fromJs(jsi::Runtime &rt, std::shared_ptr<CallInvoker>,
701
684
  const jsi::Value &value) {
702
685
  try {
686
+ auto obj = value.asObject(rt);
687
+
688
+ // Adoption vs copy. Two kinds of view arrive here:
689
+ //
690
+ // * Library-owned views from `rustbuffer_alloc`. Codegen allocates one,
691
+ // fills it in place, and ships it as an argument — and never frees a
692
+ // lowered argument, while the view's backing `CMutableBuffer` is
693
+ // non-owning (its destructor leaves `data` alone). Such a view carries
694
+ // a capacity hint (stamped by `rustbuffer_alloc` in the wrapper). We
695
+ // *adopt* it: hand the existing allocation to the callee, which frees
696
+ // it. Copying instead would orphan the allocation and leak one whole
697
+ // payload per call.
698
+ // * Ordinary JS-owned arrays, which carry no hint. These are *copied*
699
+ // into a fresh library allocation — they are not ours to give away.
700
+ //
701
+ // On adoption we reset the hint to 0 so a later `rustbuffer_free(view)` is
702
+ // a no-op rather than a double free.
703
+ if (obj.hasProperty(rt, uniffi_jsi::kUbrnRustCapacity)) {
704
+ auto capacity = static_cast<uint64_t>(
705
+ obj.getProperty(rt, uniffi_jsi::kUbrnRustCapacity).asNumber());
706
+ if (capacity == 0) {
707
+ // Hint present but zeroed: the view was already adopted by a previous
708
+ // call and its memory has been freed. Reading it would be a
709
+ // use-after-free, so refuse rather than hand over a dangling pointer.
710
+ throw jsi::JSError(
711
+ rt,
712
+ "RustBuffer argument was already consumed by a previous FFI call");
713
+ }
714
+ auto arrayBuffer =
715
+ obj.getPropertyAsObject(rt, "buffer").getArrayBuffer(rt);
716
+ auto byteOffset =
717
+ static_cast<size_t>(obj.getProperty(rt, "byteOffset").asNumber());
718
+ auto byteLength =
719
+ static_cast<size_t>(obj.getProperty(rt, "byteLength").asNumber());
720
+ obj.setProperty(rt, uniffi_jsi::kUbrnRustCapacity, jsi::Value(0));
721
+ return RustBuffer{
722
+ .capacity = capacity,
723
+ .len = static_cast<uint64_t>(byteLength),
724
+ .data = arrayBuffer.data(rt) + byteOffset,
725
+ };
726
+ }
727
+
703
728
  auto buffer = uniffi_jsi::Bridging<jsi::ArrayBuffer>::value_to_arraybuffer(rt, value);
704
729
  auto bytes = ForeignBytes{
705
730
  .len = static_cast<int32_t>(buffer.length(rt)),
706
731
  .data = buffer.data(rt),
707
732
  };
708
733
 
709
- // This buffer is constructed from foreign bytes. Rust scaffolding copies
710
- // the bytes, to make the RustBuffer.
734
+ // No hint: an ordinary JS-owned array. Rust scaffolding copies the bytes
735
+ // to make the RustBuffer; the copy is destroyed when the callee
736
+ // deserializes its arguments.
711
737
  auto buf = rustbuffer_from_bytes(bytes);
712
- // Once it leaves this function, the buffer is immediately passed back
713
- // into Rust, where it's used to deserialize into the Rust versions of the
714
- // arguments. At that point, the copy is destroyed.
715
738
  return buf;
716
739
  } catch (const std::logic_error &e) {
717
740
  throw jsi::JSError(rt, e.what());
@@ -1118,7 +1141,7 @@ namespace uniffi::minip2p_ffi::cb::foreignfuturedroppedcallback {
1118
1141
  // Implementation of free callback function CallbackInterfaceFree
1119
1142
 
1120
1143
 
1121
- // Callback function: uniffi::minip2p_ffi::st::vtablecallbackinterfacep2peventlistener::vtablecallbackinterfacep2peventlistener::free::UniffiCallbackInterfaceFree
1144
+ // Callback function: uniffi::minip2p_ffi::st::vtablecallbackinterfacep2peventdoorbell::vtablecallbackinterfacep2peventdoorbell::free::UniffiCallbackInterfaceFree
1122
1145
  //
1123
1146
  // We have the following constraints:
1124
1147
  // - we need to pass a function pointer to Rust.
@@ -1130,7 +1153,7 @@ namespace uniffi::minip2p_ffi::cb::foreignfuturedroppedcallback {
1130
1153
  //
1131
1154
  // We then give the `callback` function pointer to Rust which will call the lambda sometime in the
1132
1155
  // future.
1133
- namespace uniffi::minip2p_ffi::st::vtablecallbackinterfacep2peventlistener::vtablecallbackinterfacep2peventlistener::free {
1156
+ namespace uniffi::minip2p_ffi::st::vtablecallbackinterfacep2peventdoorbell::vtablecallbackinterfacep2peventdoorbell::free {
1134
1157
  using namespace facebook;
1135
1158
 
1136
1159
  // We need to store a lambda in a global so we can call it from
@@ -1188,7 +1211,7 @@ namespace uniffi::minip2p_ffi::st::vtablecallbackinterfacep2peventlistener::vtab
1188
1211
  }
1189
1212
 
1190
1213
  [[maybe_unused]] static UniffiCallbackInterfaceFree
1191
- makeCallbackFunction( // uniffi::minip2p_ffi::st::vtablecallbackinterfacep2peventlistener::vtablecallbackinterfacep2peventlistener::free
1214
+ makeCallbackFunction( // uniffi::minip2p_ffi::st::vtablecallbackinterfacep2peventdoorbell::vtablecallbackinterfacep2peventdoorbell::free
1192
1215
  jsi::Runtime &rt,
1193
1216
  std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
1194
1217
  const jsi::Value &value) {
@@ -1231,7 +1254,7 @@ namespace uniffi::minip2p_ffi::st::vtablecallbackinterfacep2peventlistener::vtab
1231
1254
  // then the pointer will no longer be left dangling.
1232
1255
  rsLambda = nullptr;
1233
1256
  }
1234
- } // namespace uniffi::minip2p_ffi::st::vtablecallbackinterfacep2peventlistener::vtablecallbackinterfacep2peventlistener::free
1257
+ } // namespace uniffi::minip2p_ffi::st::vtablecallbackinterfacep2peventdoorbell::vtablecallbackinterfacep2peventdoorbell::free
1235
1258
  namespace uniffi::minip2p_ffi {
1236
1259
  using namespace facebook;
1237
1260
  using CallInvoker = uniffi_runtime::UniffiCallInvoker;
@@ -2150,10 +2173,10 @@ template <> struct Bridging<UniffiForeignFutureCompleteVoid> {
2150
2173
  }
2151
2174
  };
2152
2175
  } // namespace uniffi::minip2p_ffi
2153
- // Implementation of CallbackInterfaceClone for vtable field uniffi_clone in VTableCallbackInterfaceP2pEventListener
2176
+ // Implementation of CallbackInterfaceClone for vtable field uniffi_clone in VTableCallbackInterfaceP2pEventDoorbell
2154
2177
 
2155
2178
 
2156
- // Callback function: uniffi::minip2p_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacep2peventlistener::UniffiCallbackInterfaceClone
2179
+ // Callback function: uniffi::minip2p_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacep2peventdoorbell::UniffiCallbackInterfaceClone
2157
2180
  //
2158
2181
  // We have the following constraints:
2159
2182
  // - we need to pass a function pointer to Rust.
@@ -2165,7 +2188,7 @@ template <> struct Bridging<UniffiForeignFutureCompleteVoid> {
2165
2188
  //
2166
2189
  // We then give the `callback` function pointer to Rust which will call the lambda sometime in the
2167
2190
  // future.
2168
- namespace uniffi::minip2p_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacep2peventlistener {
2191
+ namespace uniffi::minip2p_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacep2peventdoorbell {
2169
2192
  using namespace facebook;
2170
2193
 
2171
2194
  // We need to store a lambda in a global so we can call it from
@@ -2233,7 +2256,7 @@ namespace uniffi::minip2p_ffi::cb::callbackinterfaceclone::vtablecallbackinterfa
2233
2256
  }
2234
2257
 
2235
2258
  [[maybe_unused]] static UniffiCallbackInterfaceClone
2236
- makeCallbackFunction( // uniffi::minip2p_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacep2peventlistener
2259
+ makeCallbackFunction( // uniffi::minip2p_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacep2peventdoorbell
2237
2260
  jsi::Runtime &rt,
2238
2261
  std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
2239
2262
  const jsi::Value &value) {
@@ -2275,11 +2298,11 @@ namespace uniffi::minip2p_ffi::cb::callbackinterfaceclone::vtablecallbackinterfa
2275
2298
  // then the pointer will no longer be left dangling.
2276
2299
  rsLambda = nullptr;
2277
2300
  }
2278
- } // namespace uniffi::minip2p_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacep2peventlistener
2279
- // Implementation of CallbackInterfaceP2pEventListenerMethod0 for vtable field on_event in VTableCallbackInterfaceP2pEventListener
2301
+ } // namespace uniffi::minip2p_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacep2peventdoorbell
2302
+ // Implementation of CallbackInterfaceP2pEventDoorbellMethod0 for vtable field on_events_ready in VTableCallbackInterfaceP2pEventDoorbell
2280
2303
 
2281
2304
 
2282
- // Callback function: uniffi::minip2p_ffi::cb::callbackinterfacep2peventlistenermethod0::vtablecallbackinterfacep2peventlistener::UniffiCallbackInterfaceP2pEventListenerMethod0
2305
+ // Callback function: uniffi::minip2p_ffi::cb::callbackinterfacep2peventdoorbellmethod0::vtablecallbackinterfacep2peventdoorbell::UniffiCallbackInterfaceP2pEventDoorbellMethod0
2283
2306
  //
2284
2307
  // We have the following constraints:
2285
2308
  // - we need to pass a function pointer to Rust.
@@ -2291,12 +2314,12 @@ namespace uniffi::minip2p_ffi::cb::callbackinterfaceclone::vtablecallbackinterfa
2291
2314
  //
2292
2315
  // We then give the `callback` function pointer to Rust which will call the lambda sometime in the
2293
2316
  // future.
2294
- namespace uniffi::minip2p_ffi::cb::callbackinterfacep2peventlistenermethod0::vtablecallbackinterfacep2peventlistener {
2317
+ namespace uniffi::minip2p_ffi::cb::callbackinterfacep2peventdoorbellmethod0::vtablecallbackinterfacep2peventdoorbell {
2295
2318
  using namespace facebook;
2296
2319
 
2297
2320
  // We need to store a lambda in a global so we can call it from
2298
2321
  // a function pointer. The function pointer is passed to Rust.
2299
- static std::function<void(uint64_t, RustBuffer, void *, RustCallStatus*)> rsLambda = nullptr;
2322
+ static std::function<void(uint64_t, void *, RustCallStatus*)> rsLambda = nullptr;
2300
2323
 
2301
2324
  // This is the main body of the callback. It's called from the lambda,
2302
2325
  // which itself is called from the callback function which is passed to Rust.
@@ -2304,14 +2327,11 @@ namespace uniffi::minip2p_ffi::cb::callbackinterfacep2peventlistenermethod0::vta
2304
2327
  std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
2305
2328
  std::shared_ptr<jsi::Value> callbackValue
2306
2329
  ,uint64_t rs_uniffiHandle
2307
- ,RustBuffer rs_event
2308
2330
  ,void * rs_uniffiOutReturn, RustCallStatus* uniffi_call_status) {
2309
2331
 
2310
2332
  // Convert the arguments from Rust, into jsi::Values.
2311
2333
  // We'll use the Bridging class to do this…
2312
2334
  auto js_uniffiHandle = uniffi_jsi::Bridging<uint64_t>::toJs(rt, callInvoker, rs_uniffiHandle);
2313
- auto js_event = uniffi::minip2p_ffi::Bridging<RustBuffer>::toJs(rt, callInvoker, rs_event);
2314
- minip2p_callback_context::Scope callbackScope;
2315
2335
 
2316
2336
  // Now we are ready to call the callback.
2317
2337
  // We are already on the JS thread, because this `body` function was
@@ -2319,7 +2339,7 @@ namespace uniffi::minip2p_ffi::cb::callbackinterfacep2peventlistenermethod0::vta
2319
2339
  try {
2320
2340
  // Getting the callback function
2321
2341
  auto cb = callbackValue->asObject(rt).asFunction(rt);
2322
- auto uniffiResult = cb.call(rt, js_uniffiHandle, js_event
2342
+ auto uniffiResult = cb.call(rt, js_uniffiHandle
2323
2343
  );
2324
2344
 
2325
2345
  // Now copy the result back from JS into the RustCallStatus object.
@@ -2332,13 +2352,13 @@ namespace uniffi::minip2p_ffi::cb::callbackinterfacep2peventlistenermethod0::vta
2332
2352
 
2333
2353
 
2334
2354
  } catch (const jsi::JSError &error) {
2335
- std::cout << "Error in callback UniffiCallbackInterfaceP2pEventListenerMethod0: "
2355
+ std::cout << "Error in callback UniffiCallbackInterfaceP2pEventDoorbellMethod0: "
2336
2356
  << error.what() << std::endl;
2337
2357
  throw error;
2338
2358
  }
2339
2359
  }
2340
2360
 
2341
- static void callback(uint64_t rs_uniffiHandle, RustBuffer rs_event, void * rs_uniffiOutReturn, RustCallStatus* uniffi_call_status) {
2361
+ static void callback(uint64_t rs_uniffiHandle, void * rs_uniffiOutReturn, RustCallStatus* uniffi_call_status) {
2342
2362
  // If the runtime has shutdown, then there is no point in trying to
2343
2363
  // call into Javascript. BUT how do we tell if the runtime has shutdown?
2344
2364
  //
@@ -2356,12 +2376,11 @@ namespace uniffi::minip2p_ffi::cb::callbackinterfacep2peventlistenermethod0::vta
2356
2376
  // are all in the lambda.
2357
2377
  rsLambda(
2358
2378
  rs_uniffiHandle,
2359
- rs_event,
2360
2379
  rs_uniffiOutReturn, uniffi_call_status);
2361
2380
  }
2362
2381
 
2363
- [[maybe_unused]] static UniffiCallbackInterfaceP2pEventListenerMethod0
2364
- makeCallbackFunction( // uniffi::minip2p_ffi::cb::callbackinterfacep2peventlistenermethod0::vtablecallbackinterfacep2peventlistener
2382
+ [[maybe_unused]] static UniffiCallbackInterfaceP2pEventDoorbellMethod0
2383
+ makeCallbackFunction( // uniffi::minip2p_ffi::cb::callbackinterfacep2peventdoorbellmethod0::vtablecallbackinterfacep2peventdoorbell
2365
2384
  jsi::Runtime &rt,
2366
2385
  std::shared_ptr<uniffi_runtime::UniffiCallInvoker> callInvoker,
2367
2386
  const jsi::Value &value) {
@@ -2379,18 +2398,16 @@ namespace uniffi::minip2p_ffi::cb::callbackinterfacep2peventlistenermethod0::vta
2379
2398
  }
2380
2399
  auto callbackFunction = value.asObject(rt).asFunction(rt);
2381
2400
  auto callbackValue = std::make_shared<jsi::Value>(rt, callbackFunction);
2382
- rsLambda = [&rt, callInvoker, callbackValue](uint64_t rs_uniffiHandle, RustBuffer rs_event, void * rs_uniffiOutReturn, RustCallStatus* uniffi_call_status) {
2401
+ rsLambda = [&rt, callInvoker, callbackValue](uint64_t rs_uniffiHandle, void * rs_uniffiOutReturn, RustCallStatus* uniffi_call_status) {
2383
2402
  // We immediately make a lambda which will do the work of transforming the
2384
2403
  // arguments into JSI values and calling the callback.
2385
2404
  uniffi_runtime::UniffiCallFunc jsLambda = [
2386
2405
  callInvoker,
2387
2406
  callbackValue
2388
2407
  , rs_uniffiHandle
2389
- , rs_event
2390
2408
  , rs_uniffiOutReturn, uniffi_call_status](jsi::Runtime &rt) mutable {
2391
2409
  body(rt, callInvoker, callbackValue
2392
2410
  , rs_uniffiHandle
2393
- , rs_event
2394
2411
  , rs_uniffiOutReturn, uniffi_call_status);
2395
2412
  };
2396
2413
  // We'll then call that lambda from the callInvoker which will
@@ -2407,36 +2424,36 @@ namespace uniffi::minip2p_ffi::cb::callbackinterfacep2peventlistenermethod0::vta
2407
2424
  // then the pointer will no longer be left dangling.
2408
2425
  rsLambda = nullptr;
2409
2426
  }
2410
- } // namespace uniffi::minip2p_ffi::cb::callbackinterfacep2peventlistenermethod0::vtablecallbackinterfacep2peventlistener
2427
+ } // namespace uniffi::minip2p_ffi::cb::callbackinterfacep2peventdoorbellmethod0::vtablecallbackinterfacep2peventdoorbell
2411
2428
  namespace uniffi::minip2p_ffi {
2412
2429
  using namespace facebook;
2413
2430
  using CallInvoker = uniffi_runtime::UniffiCallInvoker;
2414
2431
 
2415
- template <> struct Bridging<UniffiVTableCallbackInterfaceP2pEventListener> {
2416
- static UniffiVTableCallbackInterfaceP2pEventListener fromJs(jsi::Runtime &rt,
2432
+ template <> struct Bridging<UniffiVTableCallbackInterfaceP2pEventDoorbell> {
2433
+ static UniffiVTableCallbackInterfaceP2pEventDoorbell fromJs(jsi::Runtime &rt,
2417
2434
  std::shared_ptr<CallInvoker> callInvoker,
2418
2435
  const jsi::Value &jsValue
2419
2436
  ) {
2420
2437
  // Check if the input is an object
2421
2438
  if (!jsValue.isObject()) {
2422
- throw jsi::JSError(rt, "Expected an object for UniffiVTableCallbackInterfaceP2pEventListener");
2439
+ throw jsi::JSError(rt, "Expected an object for UniffiVTableCallbackInterfaceP2pEventDoorbell");
2423
2440
  }
2424
2441
 
2425
2442
  // Get the object from the jsi::Value
2426
2443
  auto jsObject = jsValue.getObject(rt);
2427
2444
 
2428
2445
  // Create the vtable struct
2429
- UniffiVTableCallbackInterfaceP2pEventListener rsObject;
2446
+ UniffiVTableCallbackInterfaceP2pEventDoorbell rsObject;
2430
2447
 
2431
2448
  // Create the vtable from the js callbacks.
2432
- rsObject.uniffi_free = uniffi::minip2p_ffi::st::vtablecallbackinterfacep2peventlistener::vtablecallbackinterfacep2peventlistener::free::makeCallbackFunction(
2449
+ rsObject.uniffi_free = uniffi::minip2p_ffi::st::vtablecallbackinterfacep2peventdoorbell::vtablecallbackinterfacep2peventdoorbell::free::makeCallbackFunction(
2433
2450
  rt, callInvoker, jsObject.getProperty(rt, "uniffi_free")
2434
2451
  );
2435
- rsObject.uniffi_clone = uniffi::minip2p_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacep2peventlistener::makeCallbackFunction(
2452
+ rsObject.uniffi_clone = uniffi::minip2p_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacep2peventdoorbell::makeCallbackFunction(
2436
2453
  rt, callInvoker, jsObject.getProperty(rt, "uniffi_clone")
2437
2454
  );
2438
- rsObject.on_event = uniffi::minip2p_ffi::cb::callbackinterfacep2peventlistenermethod0::vtablecallbackinterfacep2peventlistener::makeCallbackFunction(
2439
- rt, callInvoker, jsObject.getProperty(rt, "on_event")
2455
+ rsObject.on_events_ready = uniffi::minip2p_ffi::cb::callbackinterfacep2peventdoorbellmethod0::vtablecallbackinterfacep2peventdoorbell::makeCallbackFunction(
2456
+ rt, callInvoker, jsObject.getProperty(rt, "on_events_ready")
2440
2457
  );
2441
2458
 
2442
2459
  return rsObject;
@@ -2507,6 +2524,38 @@ NativeMinip2pFfi::NativeMinip2pFfi(
2507
2524
  return this->cpp_uniffi_internal_fn_func_ffi__read_string_from_buffer(rt, thisVal, args, count);
2508
2525
  }
2509
2526
  );
2527
+ props["ubrn_uniffi_minip2p_ffi_fn_clone_p2peventdoorbell"] = jsi::Function::createFromHostFunction(
2528
+ rt,
2529
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_fn_clone_p2peventdoorbell"),
2530
+ 1,
2531
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2532
+ return this->cpp_uniffi_minip2p_ffi_fn_clone_p2peventdoorbell(rt, thisVal, args, count);
2533
+ }
2534
+ );
2535
+ props["ubrn_uniffi_minip2p_ffi_fn_free_p2peventdoorbell"] = jsi::Function::createFromHostFunction(
2536
+ rt,
2537
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_fn_free_p2peventdoorbell"),
2538
+ 1,
2539
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2540
+ return this->cpp_uniffi_minip2p_ffi_fn_free_p2peventdoorbell(rt, thisVal, args, count);
2541
+ }
2542
+ );
2543
+ props["ubrn_uniffi_minip2p_ffi_fn_init_callback_vtable_p2peventdoorbell"] = jsi::Function::createFromHostFunction(
2544
+ rt,
2545
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_fn_init_callback_vtable_p2peventdoorbell"),
2546
+ 1,
2547
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2548
+ return this->cpp_uniffi_minip2p_ffi_fn_init_callback_vtable_p2peventdoorbell(rt, thisVal, args, count);
2549
+ }
2550
+ );
2551
+ props["ubrn_uniffi_minip2p_ffi_fn_method_p2peventdoorbell_on_events_ready"] = jsi::Function::createFromHostFunction(
2552
+ rt,
2553
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_fn_method_p2peventdoorbell_on_events_ready"),
2554
+ 1,
2555
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2556
+ return this->cpp_uniffi_minip2p_ffi_fn_method_p2peventdoorbell_on_events_ready(rt, thisVal, args, count);
2557
+ }
2558
+ );
2510
2559
  props["ubrn_uniffi_minip2p_ffi_fn_clone_p2pendpoint"] = jsi::Function::createFromHostFunction(
2511
2560
  rt,
2512
2561
  jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_fn_clone_p2pendpoint"),
@@ -2643,6 +2692,14 @@ NativeMinip2pFfi::NativeMinip2pFfi(
2643
2692
  return this->cpp_uniffi_minip2p_ffi_fn_method_p2pendpoint_discovery_now_ms(rt, thisVal, args, count);
2644
2693
  }
2645
2694
  );
2695
+ props["ubrn_uniffi_minip2p_ffi_fn_method_p2pendpoint_drain_events"] = jsi::Function::createFromHostFunction(
2696
+ rt,
2697
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_fn_method_p2pendpoint_drain_events"),
2698
+ 2,
2699
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2700
+ return this->cpp_uniffi_minip2p_ffi_fn_method_p2pendpoint_drain_events(rt, thisVal, args, count);
2701
+ }
2702
+ );
2646
2703
  props["ubrn_uniffi_minip2p_ffi_fn_method_p2pendpoint_is_peer_ready"] = jsi::Function::createFromHostFunction(
2647
2704
  rt,
2648
2705
  jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_fn_method_p2pendpoint_is_peer_ready"),
@@ -2795,38 +2852,6 @@ NativeMinip2pFfi::NativeMinip2pFfi(
2795
2852
  return this->cpp_uniffi_minip2p_ffi_fn_method_p2pendpoint_wait_stopped(rt, thisVal, args, count);
2796
2853
  }
2797
2854
  );
2798
- props["ubrn_uniffi_minip2p_ffi_fn_clone_p2peventlistener"] = jsi::Function::createFromHostFunction(
2799
- rt,
2800
- jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_fn_clone_p2peventlistener"),
2801
- 1,
2802
- [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2803
- return this->cpp_uniffi_minip2p_ffi_fn_clone_p2peventlistener(rt, thisVal, args, count);
2804
- }
2805
- );
2806
- props["ubrn_uniffi_minip2p_ffi_fn_free_p2peventlistener"] = jsi::Function::createFromHostFunction(
2807
- rt,
2808
- jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_fn_free_p2peventlistener"),
2809
- 1,
2810
- [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2811
- return this->cpp_uniffi_minip2p_ffi_fn_free_p2peventlistener(rt, thisVal, args, count);
2812
- }
2813
- );
2814
- props["ubrn_uniffi_minip2p_ffi_fn_init_callback_vtable_p2peventlistener"] = jsi::Function::createFromHostFunction(
2815
- rt,
2816
- jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_fn_init_callback_vtable_p2peventlistener"),
2817
- 1,
2818
- [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2819
- return this->cpp_uniffi_minip2p_ffi_fn_init_callback_vtable_p2peventlistener(rt, thisVal, args, count);
2820
- }
2821
- );
2822
- props["ubrn_uniffi_minip2p_ffi_fn_method_p2peventlistener_on_event"] = jsi::Function::createFromHostFunction(
2823
- rt,
2824
- jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_fn_method_p2peventlistener_on_event"),
2825
- 2,
2826
- [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2827
- return this->cpp_uniffi_minip2p_ffi_fn_method_p2peventlistener_on_event(rt, thisVal, args, count);
2828
- }
2829
- );
2830
2855
  props["ubrn_uniffi_minip2p_ffi_fn_func_circuit_address"] = jsi::Function::createFromHostFunction(
2831
2856
  rt,
2832
2857
  jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_fn_func_circuit_address"),
@@ -2875,6 +2900,14 @@ NativeMinip2pFfi::NativeMinip2pFfi(
2875
2900
  return this->cpp_uniffi_minip2p_ffi_checksum_func_peer_id_from_secret_key(rt, thisVal, args, count);
2876
2901
  }
2877
2902
  );
2903
+ props["ubrn_uniffi_minip2p_ffi_checksum_method_p2peventdoorbell_on_events_ready"] = jsi::Function::createFromHostFunction(
2904
+ rt,
2905
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_checksum_method_p2peventdoorbell_on_events_ready"),
2906
+ 0,
2907
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
2908
+ return this->cpp_uniffi_minip2p_ffi_checksum_method_p2peventdoorbell_on_events_ready(rt, thisVal, args, count);
2909
+ }
2910
+ );
2878
2911
  props["ubrn_uniffi_minip2p_ffi_checksum_method_p2pendpoint_abandon_stream"] = jsi::Function::createFromHostFunction(
2879
2912
  rt,
2880
2913
  jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_checksum_method_p2pendpoint_abandon_stream"),
@@ -2987,6 +3020,14 @@ NativeMinip2pFfi::NativeMinip2pFfi(
2987
3020
  return this->cpp_uniffi_minip2p_ffi_checksum_method_p2pendpoint_discovery_now_ms(rt, thisVal, args, count);
2988
3021
  }
2989
3022
  );
3023
+ props["ubrn_uniffi_minip2p_ffi_checksum_method_p2pendpoint_drain_events"] = jsi::Function::createFromHostFunction(
3024
+ rt,
3025
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_checksum_method_p2pendpoint_drain_events"),
3026
+ 0,
3027
+ [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
3028
+ return this->cpp_uniffi_minip2p_ffi_checksum_method_p2pendpoint_drain_events(rt, thisVal, args, count);
3029
+ }
3030
+ );
2990
3031
  props["ubrn_uniffi_minip2p_ffi_checksum_method_p2pendpoint_is_peer_ready"] = jsi::Function::createFromHostFunction(
2991
3032
  rt,
2992
3033
  jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_checksum_method_p2pendpoint_is_peer_ready"),
@@ -3139,14 +3180,6 @@ NativeMinip2pFfi::NativeMinip2pFfi(
3139
3180
  return this->cpp_uniffi_minip2p_ffi_checksum_method_p2pendpoint_wait_stopped(rt, thisVal, args, count);
3140
3181
  }
3141
3182
  );
3142
- props["ubrn_uniffi_minip2p_ffi_checksum_method_p2peventlistener_on_event"] = jsi::Function::createFromHostFunction(
3143
- rt,
3144
- jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_checksum_method_p2peventlistener_on_event"),
3145
- 0,
3146
- [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
3147
- return this->cpp_uniffi_minip2p_ffi_checksum_method_p2peventlistener_on_event(rt, thisVal, args, count);
3148
- }
3149
- );
3150
3183
  props["ubrn_uniffi_minip2p_ffi_checksum_constructor_p2pendpoint_new"] = jsi::Function::createFromHostFunction(
3151
3184
  rt,
3152
3185
  jsi::PropNameID::forAscii(rt, "ubrn_uniffi_minip2p_ffi_checksum_constructor_p2pendpoint_new"),
@@ -3163,20 +3196,20 @@ NativeMinip2pFfi::NativeMinip2pFfi(
3163
3196
  return this->cpp_ffi_minip2p_ffi_uniffi_contract_version(rt, thisVal, args, count);
3164
3197
  }
3165
3198
  );
3166
- props["ubrn_uniffi_internal_fn_method_p2pendpoint_ffi__bless_pointer"] = jsi::Function::createFromHostFunction(
3199
+ props["ubrn_uniffi_internal_fn_method_p2peventdoorbell_ffi__bless_pointer"] = jsi::Function::createFromHostFunction(
3167
3200
  rt,
3168
- jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_method_p2pendpoint_ffi__bless_pointer"),
3201
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_method_p2peventdoorbell_ffi__bless_pointer"),
3169
3202
  1,
3170
3203
  [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
3171
- return this->cpp_uniffi_internal_fn_method_p2pendpoint_ffi__bless_pointer(rt, thisVal, args, count);
3204
+ return this->cpp_uniffi_internal_fn_method_p2peventdoorbell_ffi__bless_pointer(rt, thisVal, args, count);
3172
3205
  }
3173
3206
  );
3174
- props["ubrn_uniffi_internal_fn_method_p2peventlistener_ffi__bless_pointer"] = jsi::Function::createFromHostFunction(
3207
+ props["ubrn_uniffi_internal_fn_method_p2pendpoint_ffi__bless_pointer"] = jsi::Function::createFromHostFunction(
3175
3208
  rt,
3176
- jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_method_p2peventlistener_ffi__bless_pointer"),
3209
+ jsi::PropNameID::forAscii(rt, "ubrn_uniffi_internal_fn_method_p2pendpoint_ffi__bless_pointer"),
3177
3210
  1,
3178
3211
  [this](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
3179
- return this->cpp_uniffi_internal_fn_method_p2peventlistener_ffi__bless_pointer(rt, thisVal, args, count);
3212
+ return this->cpp_uniffi_internal_fn_method_p2pendpoint_ffi__bless_pointer(rt, thisVal, args, count);
3180
3213
  }
3181
3214
  );
3182
3215
 
@@ -3204,14 +3237,24 @@ NativeMinip2pFfi::NativeMinip2pFfi(
3204
3237
  throw jsi::JSError(rt, "rustbuffer_alloc failed: alloc returned null");
3205
3238
  }
3206
3239
  // Non-owning view over Rust-allocated memory; CMutableBuffer's destructor
3207
- // is the default and does not free `rb.data`. JS must call rustbuffer_free
3208
- // explicitly before dropping the reference.
3240
+ // is the default and does not free `rb.data`. The allocation is released
3241
+ // either by an explicit `rustbuffer_free(view)` or by being adopted when
3242
+ // the view is lowered as an FFI argument.
3209
3243
  auto payload = std::make_shared<uniffi_jsi::CMutableBuffer>(
3210
3244
  rb.data, static_cast<size_t>(rb.capacity));
3211
3245
  // Wrap as Uint8Array so JS can index/assign bytes directly.
3212
- return jsi::Value(
3213
- rt, uniffi_jsi::arraybufferToUint8Array(
3214
- rt, jsi::ArrayBuffer(rt, payload)));
3246
+ auto view = uniffi_jsi::arraybufferToUint8Array(
3247
+ rt, jsi::ArrayBuffer(rt, payload));
3248
+ // Stamp the capacity so the argument-lowering path
3249
+ // (`Bridging<RustBuffer>::fromJs`) recognises this view as
3250
+ // library-owned and adopts the allocation instead of copying it.
3251
+ // Without the stamp, a lowered argument is copied and this
3252
+ // allocation is orphaned — one leaked payload per call.
3253
+ if (rb.capacity > 0) {
3254
+ view.setProperty(rt, uniffi_jsi::kUbrnRustCapacity,
3255
+ jsi::Value(static_cast<double>(rb.capacity)));
3256
+ }
3257
+ return jsi::Value(rt, view);
3215
3258
  }
3216
3259
  );
3217
3260
 
@@ -3245,6 +3288,12 @@ NativeMinip2pFfi::NativeMinip2pFfi(
3245
3288
  capacity = static_cast<size_t>(
3246
3289
  view.getProperty(rt, uniffi_jsi::kUbrnRustCapacity).asNumber());
3247
3290
  }
3291
+ // A zero capacity marks a view already adopted as an FFI argument
3292
+ // (its hint was reset to 0) and freed by the callee. Freeing again
3293
+ // would be a double free, so this is a no-op.
3294
+ if (capacity == 0) {
3295
+ return jsi::Value::undefined();
3296
+ }
3248
3297
  auto buffer = view.getPropertyAsObject(rt, "buffer").getArrayBuffer(rt);
3249
3298
  auto byteOffset =
3250
3299
  static_cast<size_t>(view.getProperty(rt, "byteOffset").asNumber());
@@ -3298,9 +3347,9 @@ uniffi::minip2p_ffi::cb::rustfuturecontinuationcallback::cleanup();
3298
3347
  // Cleanup for callback function ForeignFutureDroppedCallback
3299
3348
  uniffi::minip2p_ffi::cb::foreignfuturedroppedcallback::cleanup();
3300
3349
  // Cleanup for "free" callback function CallbackInterfaceFree
3301
- uniffi::minip2p_ffi::st::vtablecallbackinterfacep2peventlistener::vtablecallbackinterfacep2peventlistener::free::cleanup();
3302
- uniffi::minip2p_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacep2peventlistener::cleanup();
3303
- uniffi::minip2p_ffi::cb::callbackinterfacep2peventlistenermethod0::vtablecallbackinterfacep2peventlistener::cleanup();
3350
+ uniffi::minip2p_ffi::st::vtablecallbackinterfacep2peventdoorbell::vtablecallbackinterfacep2peventdoorbell::free::cleanup();
3351
+ uniffi::minip2p_ffi::cb::callbackinterfaceclone::vtablecallbackinterfacep2peventdoorbell::cleanup();
3352
+ uniffi::minip2p_ffi::cb::callbackinterfacep2peventdoorbellmethod0::vtablecallbackinterfacep2peventdoorbell::cleanup();
3304
3353
  }
3305
3354
 
3306
3355
  // Utility functions for serialization/deserialization of strings.
@@ -3318,20 +3367,20 @@ jsi::Value NativeMinip2pFfi::cpp_uniffi_internal_fn_func_ffi__string_from_buffer
3318
3367
 
3319
3368
  jsi::Value NativeMinip2pFfi::cpp_uniffi_internal_fn_func_ffi__read_string_from_buffer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3320
3369
  return uniffi_jsi::Bridging<std::string>::read_string_from_buffer(rt, args[0], args[1], args[2]);
3321
- }jsi::Value NativeMinip2pFfi::cpp_uniffi_internal_fn_method_p2pendpoint_ffi__bless_pointer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3370
+ }jsi::Value NativeMinip2pFfi::cpp_uniffi_internal_fn_method_p2peventdoorbell_ffi__bless_pointer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3322
3371
  auto pointer = uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]);
3323
3372
  auto static destructor = [](uint64_t p) {
3324
3373
  RustCallStatus status = {0};
3325
- uniffi_minip2p_ffi_fn_free_p2pendpoint(p, &status);
3374
+ uniffi_minip2p_ffi_fn_free_p2peventdoorbell(p, &status);
3326
3375
  };
3327
3376
  auto ptrObj = std::make_shared<uniffi_jsi::DestructibleObject>(pointer, destructor);
3328
3377
  auto obj = jsi::Object::createFromHostObject(rt, ptrObj);
3329
3378
  return jsi::Value(rt, obj);
3330
- }jsi::Value NativeMinip2pFfi::cpp_uniffi_internal_fn_method_p2peventlistener_ffi__bless_pointer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3379
+ }jsi::Value NativeMinip2pFfi::cpp_uniffi_internal_fn_method_p2pendpoint_ffi__bless_pointer(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3331
3380
  auto pointer = uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[0]);
3332
3381
  auto static destructor = [](uint64_t p) {
3333
3382
  RustCallStatus status = {0};
3334
- uniffi_minip2p_ffi_fn_free_p2peventlistener(p, &status);
3383
+ uniffi_minip2p_ffi_fn_free_p2pendpoint(p, &status);
3335
3384
  };
3336
3385
  auto ptrObj = std::make_shared<uniffi_jsi::DestructibleObject>(pointer, destructor);
3337
3386
  auto obj = jsi::Object::createFromHostObject(rt, ptrObj);
@@ -3339,6 +3388,53 @@ jsi::Value NativeMinip2pFfi::cpp_uniffi_internal_fn_func_ffi__read_string_from_b
3339
3388
  }
3340
3389
 
3341
3390
  // Methods calling directly into the uniffi generated C API of the Rust crate.
3391
+ jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_fn_clone_p2peventdoorbell(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3392
+ RustCallStatus status = uniffi::minip2p_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
3393
+ auto value = uniffi_minip2p_ffi_fn_clone_p2peventdoorbell(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]),
3394
+ &status
3395
+ );
3396
+ uniffi::minip2p_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
3397
+
3398
+
3399
+ return uniffi_jsi::Bridging</*handle*/ uint64_t>::toJs(rt, callInvoker, value);
3400
+ }
3401
+ jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_fn_free_p2peventdoorbell(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3402
+ RustCallStatus status = uniffi::minip2p_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
3403
+ uniffi_minip2p_ffi_fn_free_p2peventdoorbell(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]),
3404
+ &status
3405
+ );
3406
+ uniffi::minip2p_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
3407
+
3408
+
3409
+ return jsi::Value::undefined();
3410
+ }
3411
+ jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_fn_init_callback_vtable_p2peventdoorbell(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3412
+ auto vtableInstance =
3413
+ uniffi::minip2p_ffi::Bridging<UniffiVTableCallbackInterfaceP2pEventDoorbell>::fromJs(
3414
+ rt,
3415
+ callInvoker,
3416
+ args[0]
3417
+ );
3418
+
3419
+ std::lock_guard<std::mutex> lock(uniffi::minip2p_ffi::registry::vtableMutex);
3420
+ uniffi_minip2p_ffi_fn_init_callback_vtable_p2peventdoorbell(
3421
+ uniffi::minip2p_ffi::registry::putTable(
3422
+ "UniffiVTableCallbackInterfaceP2pEventDoorbell",
3423
+ vtableInstance
3424
+ )
3425
+ );
3426
+ return jsi::Value::undefined();
3427
+ }
3428
+ jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_fn_method_p2peventdoorbell_on_events_ready(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3429
+ RustCallStatus status = uniffi::minip2p_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
3430
+ uniffi_minip2p_ffi_fn_method_p2peventdoorbell_on_events_ready(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]),
3431
+ &status
3432
+ );
3433
+ uniffi::minip2p_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
3434
+
3435
+
3436
+ return jsi::Value::undefined();
3437
+ }
3342
3438
  jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_fn_clone_p2pendpoint(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3343
3439
  RustCallStatus status = uniffi::minip2p_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
3344
3440
  auto value = uniffi_minip2p_ffi_fn_clone_p2pendpoint(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]),
@@ -3507,6 +3603,16 @@ jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_fn_method_p2pendpoint_discov
3507
3603
  uniffi::minip2p_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
3508
3604
 
3509
3605
 
3606
+ return uniffi::minip2p_ffi::Bridging<RustBuffer>::toJs(rt, callInvoker, value);
3607
+ }
3608
+ jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_fn_method_p2pendpoint_drain_events(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3609
+ RustCallStatus status = uniffi::minip2p_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
3610
+ auto value = uniffi_minip2p_ffi_fn_method_p2pendpoint_drain_events(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi_jsi::Bridging<uint32_t>::fromJs(rt, callInvoker, args[1]),
3611
+ &status
3612
+ );
3613
+ uniffi::minip2p_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
3614
+
3615
+
3510
3616
  return uniffi::minip2p_ffi::Bridging<RustBuffer>::toJs(rt, callInvoker, value);
3511
3617
  }
3512
3618
  jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_fn_method_p2pendpoint_is_peer_ready(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
@@ -3690,14 +3796,6 @@ jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_fn_method_p2pendpoint_unsubs
3690
3796
  return uniffi_jsi::Bridging<int8_t>::toJs(rt, callInvoker, value);
3691
3797
  }
3692
3798
  jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_fn_method_p2pendpoint_wait_stopped(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3693
- if (minip2p_callback_context::active()) {
3694
- RustCallStatus status = uniffi::minip2p_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
3695
- // clonePointer creates a per-call Arc handle that Rust normally consumes.
3696
- // This early return must release that clone without calling wait_stopped.
3697
- uniffi_minip2p_ffi_fn_free_p2pendpoint(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]), &status);
3698
- uniffi::minip2p_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
3699
- return uniffi_jsi::Bridging<int8_t>::toJs(rt, callInvoker, int8_t{0});
3700
- }
3701
3799
  RustCallStatus status = uniffi::minip2p_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
3702
3800
  auto value = uniffi_minip2p_ffi_fn_method_p2pendpoint_wait_stopped(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi_jsi::Bridging<uint64_t>::fromJs(rt, callInvoker, args[1]),
3703
3801
  &status
@@ -3707,53 +3805,6 @@ jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_fn_method_p2pendpoint_wait_s
3707
3805
 
3708
3806
  return uniffi_jsi::Bridging<int8_t>::toJs(rt, callInvoker, value);
3709
3807
  }
3710
- jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_fn_clone_p2peventlistener(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3711
- RustCallStatus status = uniffi::minip2p_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
3712
- auto value = uniffi_minip2p_ffi_fn_clone_p2peventlistener(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]),
3713
- &status
3714
- );
3715
- uniffi::minip2p_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
3716
-
3717
-
3718
- return uniffi_jsi::Bridging</*handle*/ uint64_t>::toJs(rt, callInvoker, value);
3719
- }
3720
- jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_fn_free_p2peventlistener(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3721
- RustCallStatus status = uniffi::minip2p_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
3722
- uniffi_minip2p_ffi_fn_free_p2peventlistener(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]),
3723
- &status
3724
- );
3725
- uniffi::minip2p_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
3726
-
3727
-
3728
- return jsi::Value::undefined();
3729
- }
3730
- jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_fn_init_callback_vtable_p2peventlistener(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3731
- auto vtableInstance =
3732
- uniffi::minip2p_ffi::Bridging<UniffiVTableCallbackInterfaceP2pEventListener>::fromJs(
3733
- rt,
3734
- callInvoker,
3735
- args[0]
3736
- );
3737
-
3738
- std::lock_guard<std::mutex> lock(uniffi::minip2p_ffi::registry::vtableMutex);
3739
- uniffi_minip2p_ffi_fn_init_callback_vtable_p2peventlistener(
3740
- uniffi::minip2p_ffi::registry::putTable(
3741
- "UniffiVTableCallbackInterfaceP2pEventListener",
3742
- vtableInstance
3743
- )
3744
- );
3745
- return jsi::Value::undefined();
3746
- }
3747
- jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_fn_method_p2peventlistener_on_event(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3748
- RustCallStatus status = uniffi::minip2p_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
3749
- uniffi_minip2p_ffi_fn_method_p2peventlistener_on_event(uniffi_jsi::Bridging</*handle*/ uint64_t>::fromJs(rt, callInvoker, args[0]), uniffi::minip2p_ffi::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[1]),
3750
- &status
3751
- );
3752
- uniffi::minip2p_ffi::Bridging<RustCallStatus>::copyIntoJs(rt, callInvoker, status, args[count - 1]);
3753
-
3754
-
3755
- return jsi::Value::undefined();
3756
- }
3757
3808
  jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_fn_func_circuit_address(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3758
3809
  RustCallStatus status = uniffi::minip2p_ffi::Bridging<RustCallStatus>::rustSuccess(rt);
3759
3810
  auto value = uniffi_minip2p_ffi_fn_func_circuit_address(uniffi::minip2p_ffi::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[0]), uniffi::minip2p_ffi::Bridging<RustBuffer>::fromJs(rt, callInvoker, args[1]),
@@ -3802,6 +3853,13 @@ jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_checksum_func_peer_id_from_s
3802
3853
  );
3803
3854
 
3804
3855
 
3856
+ return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
3857
+ }
3858
+ jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_checksum_method_p2peventdoorbell_on_events_ready(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3859
+ auto value = uniffi_minip2p_ffi_checksum_method_p2peventdoorbell_on_events_ready(
3860
+ );
3861
+
3862
+
3805
3863
  return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
3806
3864
  }
3807
3865
  jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_checksum_method_p2pendpoint_abandon_stream(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
@@ -3900,6 +3958,13 @@ jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_checksum_method_p2pendpoint_
3900
3958
  );
3901
3959
 
3902
3960
 
3961
+ return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
3962
+ }
3963
+ jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_checksum_method_p2pendpoint_drain_events(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
3964
+ auto value = uniffi_minip2p_ffi_checksum_method_p2pendpoint_drain_events(
3965
+ );
3966
+
3967
+
3903
3968
  return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
3904
3969
  }
3905
3970
  jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_checksum_method_p2pendpoint_is_peer_ready(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
@@ -4033,13 +4098,6 @@ jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_checksum_method_p2pendpoint_
4033
4098
  );
4034
4099
 
4035
4100
 
4036
- return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
4037
- }
4038
- jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_checksum_method_p2peventlistener_on_event(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
4039
- auto value = uniffi_minip2p_ffi_checksum_method_p2peventlistener_on_event(
4040
- );
4041
-
4042
-
4043
4101
  return uniffi_jsi::Bridging<uint16_t>::toJs(rt, callInvoker, value);
4044
4102
  }
4045
4103
  jsi::Value NativeMinip2pFfi::cpp_uniffi_minip2p_ffi_checksum_constructor_p2pendpoint_new(jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {