Rffi.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #ifndef rffi_H
  2. #define rffi_H
  3. // This file is generated from src/rffi.rs using cbindgen
  4. #include "RffiPrefix.h"
  5. typedef struct RTypes_CryptoAuth2_t RTypes_CryptoAuth2_t;
  6. typedef struct Rffi_EventLoop Rffi_EventLoop;
  7. /**
  8. * The guard of an acquired [`GCL`].
  9. */
  10. typedef struct Rffi_Glock_guard Rffi_Glock_guard;
  11. /**
  12. * The handle returned to C, used to talk to the timer task.
  13. */
  14. typedef struct Rffi_TimerTx Rffi_TimerTx;
  15. typedef struct {
  16. uint8_t octets[16];
  17. uint8_t netmask[16];
  18. bool is_ipv6;
  19. } Rffi_Address;
  20. typedef struct {
  21. const char *name;
  22. uint8_t phys_addr[6];
  23. bool is_internal;
  24. Rffi_Address address;
  25. } Rffi_NetworkInterface;
  26. typedef void (*OnFreeFun)(void *ctx);
  27. extern const uintptr_t Rffi_CURRENT_PROTOCOL;
  28. int Rffi_CryptoAuth2_addUser_ipv6(String_t *password,
  29. String_t *login,
  30. uint8_t *ipv6,
  31. RTypes_CryptoAuth2_t *ca);
  32. int Rffi_CryptoAuth2_removeUsers(RTypes_CryptoAuth2_t *context, String_t *user);
  33. RTypes_StrList_t *Rffi_CryptoAuth2_getUsers(const RTypes_CryptoAuth2_t *ca, Allocator_t *alloc);
  34. RTypes_CryptoAuth2_t *Rffi_CryptoAuth2_new(Allocator_t *allocator,
  35. const uint8_t *privateKey,
  36. Random_t *random);
  37. void Rffi_CryptoAuth2_tryHandshake(RTypes_CryptoAuth2_t *ca,
  38. Message_t *c_msg,
  39. Allocator_t *alloc,
  40. bool requireAuth,
  41. RTypes_CryptoAuth2_TryHandshake_Ret_t *ret);
  42. RTypes_CryptoAuth2_Session_t *Rffi_CryptoAuth2_newSession(RTypes_CryptoAuth2_t *ca,
  43. Allocator_t *alloc,
  44. const uint8_t *herPublicKey,
  45. bool requireAuth,
  46. const char *name,
  47. bool useNoise);
  48. Message_t *Rffi_CryptoAuth2_noiseTick(RTypes_CryptoAuth2_Session_t *sess, Allocator_t *alloc);
  49. void Rffi_CryptoAuth2_setAuth(const String_t *password,
  50. const String_t *login,
  51. RTypes_CryptoAuth2_Session_t *caSession);
  52. void Rffi_CryptoAuth2_resetIfTimeout(RTypes_CryptoAuth2_Session_t *session);
  53. void Rffi_CryptoAuth2_reset(RTypes_CryptoAuth2_Session_t *caSession);
  54. RTypes_CryptoAuth_State_t Rffi_CryptoAuth2_getState(RTypes_CryptoAuth2_Session_t *session);
  55. void Rffi_CryptoAuth2_getHerPubKey(const RTypes_CryptoAuth2_Session_t *session, uint8_t *pkOut);
  56. void Rffi_CryptoAuth2_getHerIp6(const RTypes_CryptoAuth2_Session_t *session, uint8_t *ipOut);
  57. String_t *Rffi_CryptoAuth2_getName(const RTypes_CryptoAuth2_Session_t *session, Allocator_t *alloc);
  58. void Rffi_CryptoAuth2_getPubKey(const RTypes_CryptoAuth2_t *ca, uint8_t *pkOut);
  59. void Rffi_CryptoAuth2_stats(const RTypes_CryptoAuth2_Session_t *session,
  60. RTypes_CryptoStats_t *statsOut);
  61. uint32_t Rffi_CryptoAuth2_cjdnsVer(const RTypes_CryptoAuth2_Session_t *session);
  62. /**
  63. * Helper function to lock the Global C Lock, used only within libuv's core runtime (unix and windows).
  64. */
  65. Rffi_Glock_guard *Rffi_glock(void);
  66. /**
  67. * Helper function to unlock the Global C Lock, as noted above.
  68. */
  69. void Rffi_gunlock(Rffi_Glock_guard *guard);
  70. void Rffi_stopEventLoop(Rffi_EventLoop *event_loop);
  71. /**
  72. * Create a new EventLoop data repository.
  73. */
  74. Rffi_EventLoop *Rffi_mkEventLoop(Allocator_t *alloc, void *base);
  75. /**
  76. * Return some EventLoop's ref counter to C.
  77. */
  78. unsigned int Rffi_eventLoopRefCtr(Rffi_EventLoop *event_loop);
  79. /**
  80. * Get the full filesystem path of the current running executable.
  81. */
  82. int32_t Rffi_exepath(const char **out, Allocator_t *alloc);
  83. /**
  84. * Spawn a new child process, and monitors its result.
  85. */
  86. int32_t Rffi_spawn(const char *file,
  87. const char *const *args,
  88. int num_args,
  89. Allocator_t *_alloc,
  90. Rffi_EventLoop *event_loop,
  91. void (*cb)(int64_t, int));
  92. /**
  93. * Spawn a timer task for a timeout or interval, that calls some callback whenever it triggers.
  94. */
  95. void Rffi_setTimeout(Rffi_TimerTx **out_timer_tx,
  96. void (*cb)(void*),
  97. void *cb_context,
  98. unsigned long timeout_millis,
  99. bool repeat,
  100. Rffi_EventLoop *event_loop,
  101. Allocator_t *alloc);
  102. /**
  103. * Reset a timer task to change its timing.
  104. */
  105. int Rffi_resetTimeout(const Rffi_TimerTx *timer_tx, unsigned long timeout_millis);
  106. /**
  107. * Cancel a timer task.
  108. */
  109. int Rffi_clearTimeout(const Rffi_TimerTx *timer_tx);
  110. /**
  111. * Return 1 if a timer task is still running, 0 otherwise.
  112. */
  113. int Rffi_isTimeoutActive(const Rffi_TimerTx *timer_tx);
  114. /**
  115. * Cancel all timer tasks.
  116. */
  117. void Rffi_clearAllTimeouts(Rffi_EventLoop *event_loop);
  118. /**
  119. * Convert IPv4 and IPv6 addresses from binary to text form.
  120. */
  121. int32_t Rffi_inet_ntop(bool is_ip6, const void *addr, uint8_t *dst, uint32_t dst_sz);
  122. /**
  123. * Convert IPv4 and IPv6 addresses from text to binary form.
  124. */
  125. int32_t Rffi_inet_pton(bool is_ip6, const char *src, uint8_t *addr);
  126. /**
  127. * Get a list of available network interfaces for the current machine.
  128. */
  129. int32_t Rffi_interface_addresses(const Rffi_NetworkInterface **out, Allocator_t *alloc);
  130. /**
  131. * Non-monotonic nanosecond time, which has no relationship to any wall clock.
  132. */
  133. uint64_t Rffi_hrtime(void);
  134. /**
  135. * Monotonic millisecond time.
  136. */
  137. uint64_t Rffi_now_ms(void);
  138. RTypes_IfWrapper_t Rffi_testwrapper_create(Allocator_t *a);
  139. RTypes_IfWrapper_t Rffi_android_create(Allocator_t *a);
  140. void Rffi_panic(const char *msg);
  141. void Rffi_setLogger(Log_t *l);
  142. RTypes_Error_t *Rffi_error(const char *msg, Allocator_t *alloc);
  143. RTypes_Error_t *Rffi_error_fl(const char *msg, const char *file, int line, Allocator_t *alloc);
  144. const char *Rffi_printError(RTypes_Error_t *e, Allocator_t *alloc);
  145. /**
  146. * Create a root level allocator.
  147. */
  148. Allocator_t *Rffi_allocator_newRoot(const char *file, uintptr_t line);
  149. void Rffi_allocator_free(Allocator_t *a, const char *file, uintptr_t line);
  150. int Rffi_allocator_isFreeing(Allocator_t *a);
  151. Allocator_t *Rffi_allocator_child(Allocator_t *a, const char *file, uintptr_t line);
  152. uint8_t *Rffi_allocator_malloc(Allocator_t *a, uintptr_t size);
  153. uint8_t *Rffi_allocator_calloc(Allocator_t *a, uintptr_t size);
  154. uint8_t *Rffi_allocator_realloc(Allocator_t *a, uint8_t *ptr, uintptr_t new_size);
  155. void Rffi_allocator_onFree(Allocator_t *a,
  156. OnFreeFun fun,
  157. void *ctx,
  158. const char *file,
  159. uintptr_t line);
  160. void Rffi_allocator_adopt(Allocator_t *a, Allocator_t *to_adopt);
  161. #endif /* rffi_H */