Rffi.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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_FdReadableTx Rffi_FdReadableTx;
  7. typedef struct Rffi_Seeder Rffi_Seeder;
  8. typedef struct Rffi_SocketIface_t Rffi_SocketIface_t;
  9. typedef struct Rffi_SocketServer Rffi_SocketServer;
  10. /**
  11. * The handle returned to C, used to talk to the timer task.
  12. */
  13. typedef struct Rffi_TimerTx Rffi_TimerTx;
  14. typedef struct Rffi_UDPIface_pvt Rffi_UDPIface_pvt;
  15. typedef struct {
  16. Rffi_UDPIface_pvt *pvt;
  17. Iface_t *iface;
  18. Sockaddr_t *local_addr;
  19. } Rffi_UDPIface;
  20. typedef struct {
  21. uint8_t octets[16];
  22. uint8_t netmask[16];
  23. bool is_ipv6;
  24. } Rffi_Address;
  25. typedef struct {
  26. const char *name;
  27. uint8_t phys_addr[6];
  28. bool is_internal;
  29. Rffi_Address address;
  30. } Rffi_NetworkInterface;
  31. typedef void (*OnFreeFun)(void *ctx);
  32. extern const uintptr_t Rffi_CURRENT_PROTOCOL;
  33. int Rffi_CryptoAuth2_addUser_ipv6(String_t *password,
  34. String_t *login,
  35. uint8_t *ipv6,
  36. const RTypes_CryptoAuth2_t *ca);
  37. int Rffi_CryptoAuth2_removeUsers(const RTypes_CryptoAuth2_t *context, String_t *user);
  38. RTypes_StrList_t *Rffi_CryptoAuth2_getUsers(const RTypes_CryptoAuth2_t *ca, Allocator_t *alloc);
  39. RTypes_CryptoAuth2_t *Rffi_CryptoAuth2_new(Allocator_t *allocator,
  40. const uint8_t *privateKey,
  41. Random_t *random);
  42. void Rffi_CryptoAuth2_tryHandshake(const RTypes_CryptoAuth2_t *ca,
  43. Message_t *c_msg,
  44. Allocator_t *alloc,
  45. bool requireAuth,
  46. RTypes_CryptoAuth2_TryHandshake_Ret_t *ret);
  47. RTypes_CryptoAuth2_Session_t *Rffi_CryptoAuth2_newSession(const RTypes_CryptoAuth2_t *ca,
  48. Allocator_t *alloc,
  49. const uint8_t *herPublicKey,
  50. bool requireAuth,
  51. const char *name,
  52. bool useNoise);
  53. Message_t *Rffi_CryptoAuth2_noiseTick(RTypes_CryptoAuth2_Session_t *sess, Allocator_t *alloc);
  54. void Rffi_CryptoAuth2_setAuth(const String_t *password,
  55. const String_t *login,
  56. RTypes_CryptoAuth2_Session_t *caSession);
  57. void Rffi_CryptoAuth2_resetIfTimeout(RTypes_CryptoAuth2_Session_t *session);
  58. void Rffi_CryptoAuth2_reset(RTypes_CryptoAuth2_Session_t *caSession);
  59. RTypes_CryptoAuth_State_t Rffi_CryptoAuth2_getState(RTypes_CryptoAuth2_Session_t *session);
  60. void Rffi_CryptoAuth2_getHerPubKey(const RTypes_CryptoAuth2_Session_t *session, uint8_t *pkOut);
  61. void Rffi_CryptoAuth2_getHerIp6(const RTypes_CryptoAuth2_Session_t *session, uint8_t *ipOut);
  62. String_t *Rffi_CryptoAuth2_getName(const RTypes_CryptoAuth2_Session_t *session, Allocator_t *alloc);
  63. void Rffi_CryptoAuth2_getPubKey(const RTypes_CryptoAuth2_t *ca, uint8_t *pkOut);
  64. void Rffi_CryptoAuth2_stats(const RTypes_CryptoAuth2_Session_t *session,
  65. RTypes_CryptoStats_t *statsOut);
  66. uint32_t Rffi_CryptoAuth2_cjdnsVer(const RTypes_CryptoAuth2_Session_t *session);
  67. int Rffi_CryptoAuth2_getSecret(const RTypes_CryptoAuth2_t *ca,
  68. const String_t *name,
  69. uint8_t *secretOut);
  70. int Rffi_crypto_hash_sha512(unsigned char *out,
  71. const unsigned char *input,
  72. unsigned long long inlen);
  73. int Rffi_crypto_hash_sha256(unsigned char *out,
  74. const unsigned char *input,
  75. unsigned long long inlen);
  76. void Rffi_stopEventLoop(RTypes_EventLoop_t *event_loop);
  77. void Rffi_startEventLoop(RTypes_EventLoop_t *event_loop);
  78. /**
  79. * Create a new EventLoop data repository.
  80. */
  81. RTypes_EventLoop_t *Rffi_mkEventLoop(Allocator_t *alloc);
  82. /**
  83. * Get the full filesystem path of the current running executable.
  84. */
  85. int32_t Rffi_exepath(const char **out, Allocator_t *alloc);
  86. /**
  87. * Spawn a new child process, and monitors its result.
  88. */
  89. int32_t Rffi_spawn(const char *file,
  90. const char *const *args,
  91. int num_args,
  92. Allocator_t *_alloc,
  93. void (*cb)(int64_t, int));
  94. /**
  95. * Spawn a timer task for a timeout or interval, that calls some callback whenever it triggers.
  96. */
  97. void Rffi_setTimeout(Rffi_TimerTx **out_timer_tx,
  98. void (*cb)(void*),
  99. void *cb_context,
  100. unsigned long timeout_millis,
  101. bool repeat,
  102. RTypes_EventLoop_t *event_loop,
  103. Allocator_t *alloc);
  104. /**
  105. * Reset a timer task to change its timing.
  106. */
  107. int Rffi_resetTimeout(const Rffi_TimerTx *timer_tx, unsigned long timeout_millis);
  108. /**
  109. * Cancel a timer task.
  110. */
  111. int Rffi_clearTimeout(const Rffi_TimerTx *timer_tx);
  112. /**
  113. * Return 1 if a timer task is still running, 0 otherwise.
  114. */
  115. int Rffi_isTimeoutActive(const Rffi_TimerTx *timer_tx);
  116. /**
  117. * Cancel all timer tasks.
  118. */
  119. void Rffi_clearAllTimeouts(RTypes_EventLoop_t *event_loop);
  120. RTypes_Error_t *Rffi_pollFdReadable(Rffi_FdReadableTx **out,
  121. void (*cb)(void*),
  122. void *cb_context,
  123. int fd,
  124. Allocator_t *alloc);
  125. int32_t Rffi_udpIfaceGetFd(Rffi_UDPIface_pvt *iface);
  126. int32_t Rffi_udpIfaceSetBroadcast(Rffi_UDPIface_pvt *iface, bool broadcast);
  127. RTypes_Error_t *Rffi_udpIface_worker_states(Object_t **outP,
  128. Rffi_UDPIface_pvt *iface,
  129. Allocator_t *alloc);
  130. int32_t Rffi_udpIfaceSetDscp(Rffi_UDPIface_pvt *iface, uint8_t dscp);
  131. RTypes_Error_t *Rffi_udpIfaceNew(Rffi_UDPIface **outp,
  132. const Sockaddr_t *bind_addr,
  133. Allocator_t *c_alloc);
  134. RTypes_Error_t *Rffi_fileExists(bool *existsOut, const char *path, Allocator_t *errorAlloc);
  135. RTypes_Error_t *Rffi_socketWorkerStates(Object_t **outP,
  136. const Rffi_SocketIface_t *si,
  137. Allocator_t *alloc);
  138. RTypes_Error_t *Rffi_socketForFd(Iface_t **ifOut,
  139. Rffi_SocketIface_t **so_out,
  140. int fd,
  141. RTypes_SocketType st,
  142. Allocator_t *alloc);
  143. RTypes_Error_t *Rffi_unixSocketConnect(Iface_t **ifOut, const char *path, Allocator_t *alloc);
  144. void Rffi_unixSocketServerOnConnect(Rffi_SocketServer *rss,
  145. void (*f)(void*, const Sockaddr_t*),
  146. void *ctx);
  147. RTypes_Error_t *Rffi_unixSocketServer(Rffi_SocketServer **rssOut,
  148. Iface_t **ifaceOut,
  149. const char *path,
  150. Allocator_t *alloc);
  151. /**
  152. * Convert IPv4 and IPv6 addresses from binary to text form.
  153. */
  154. int32_t Rffi_inet_ntop(bool is_ip6, const void *addr, uint8_t *dst, uint32_t dst_sz);
  155. /**
  156. * Convert IPv4 and IPv6 addresses from text to binary form.
  157. */
  158. int32_t Rffi_inet_pton(bool is_ip6, const char *src, uint8_t *addr);
  159. /**
  160. * Get a list of available network interfaces for the current machine.
  161. */
  162. int32_t Rffi_interface_addresses(const Rffi_NetworkInterface **out, Allocator_t *alloc);
  163. /**
  164. * Non-monotonic nanosecond time, which has no relationship to any wall clock.
  165. */
  166. uint64_t Rffi_hrtime(void);
  167. /**
  168. * Monotonic millisecond time.
  169. */
  170. uint64_t Rffi_now_ms(void);
  171. void Rffi_sleep_ms_sync(uint64_t ms);
  172. RTypes_IfWrapper_t Rffi_testwrapper_create(Allocator_t *a);
  173. RTypes_IfWrapper_t Rffi_android_create(Allocator_t *a);
  174. void Rffi_panic(const char *msg);
  175. void Rffi_setLogger(Log_t *l);
  176. RTypes_Error_t *Rffi_error(const char *msg, Allocator_t *alloc);
  177. RTypes_Error_t *Rffi_error_fl(const char *msg, const char *file, int line, Allocator_t *alloc);
  178. char *Rffi_printError(RTypes_Error_t *e, Allocator_t *alloc);
  179. void Rffi_glock(void);
  180. void Rffi_gunlock(void);
  181. int Rffi_parseBase10(const uint8_t *buf, uint32_t max_len, int64_t *num_out, uint32_t *bytes);
  182. /**
  183. * Create a root level allocator.
  184. */
  185. Allocator_t *Rffi_allocator_newRoot(const char *file, uintptr_t line);
  186. void Rffi_allocator_free(Allocator_t *a, const char *file, uintptr_t line);
  187. int Rffi_allocator_isFreeing(Allocator_t *a);
  188. Allocator_t *Rffi_allocator_child(Allocator_t *a, const char *file, uintptr_t line);
  189. uint8_t *Rffi_allocator_malloc(Allocator_t *a, uintptr_t size);
  190. uint8_t *Rffi_allocator_calloc(Allocator_t *a, uintptr_t size);
  191. uint8_t *Rffi_allocator_realloc(Allocator_t *a, uint8_t *ptr, uintptr_t new_size);
  192. void Rffi_allocator_onFree(Allocator_t *a,
  193. OnFreeFun fun,
  194. void *ctx,
  195. const char *file,
  196. uintptr_t line);
  197. void Rffi_allocator_adopt(Allocator_t *a, Allocator_t *to_adopt);
  198. RTypes_Error_t *Rffi_Seeder_addDnsSeed(Rffi_Seeder *seeder,
  199. const String_t *dns_seed,
  200. bool trust_snode,
  201. Allocator_t *alloc);
  202. RTypes_Error_t *Rffi_Seeder_rmDnsSeed(bool *found,
  203. Rffi_Seeder *seeder,
  204. const String_t *dns_seed,
  205. Allocator_t *alloc);
  206. RTypes_Error_t *Rffi_Seeder_listDnsSeeds(RTypes_Seeder_DnsSeeds_t **seeds_out,
  207. Rffi_Seeder *seeder,
  208. Allocator_t *alloc);
  209. void Rffi_Seeder_new(Rffi_Seeder **seeder_out,
  210. Iface_t **iface_out,
  211. const uint8_t *my_pubkey,
  212. Allocator_t *alloc);
  213. bool Rffi_Seeder_got_lladdr(Rffi_Seeder *seeder, const Control_LlAddr_t *lladdr);
  214. RTypes_Error_t *Rffi_Seeder_mk_creds(Rffi_Seeder *seeder, String_t **creds, Allocator_t *alloc);
  215. RTypes_Error_t *Rffi_Seeder_public_peer(Rffi_Seeder *seeder,
  216. String_t **user_out,
  217. String_t **pass_out,
  218. uint16_t user_num,
  219. uint64_t passwd,
  220. const String_t *code,
  221. Allocator_t *alloc);
  222. RTypes_Error_t *Rffi_Seeder_public_status(Rffi_Seeder *seeder,
  223. String_t **ipv4_out,
  224. String_t **ipv6_out,
  225. String_t **peer_id_out,
  226. Allocator_t *alloc);
  227. RTypes_Error_t *Rffi_Seeder_got_peers(Rffi_Seeder *seeder,
  228. const String_t *peers,
  229. Allocator_t *alloc);
  230. bool Rffi_Seeder_has_lladdr(Rffi_Seeder *seeder);
  231. RTypes_Error_t *Rffi_Benc_decodeJson(Dict_t **out,
  232. Message_t *msg,
  233. bool lax_mode,
  234. Allocator_t *alloc);
  235. RTypes_Error_t *Rffi_Benc_encodeJson(Dict_t *input, Message_t *msg, Allocator_t *alloc);
  236. #endif /* rffi_H */