librats 1.0.2 → 2.1.4

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 (313) hide show
  1. package/README.md +137 -332
  2. package/binding.gyp +16 -3
  3. package/lib/index.d.ts +271 -696
  4. package/lib/index.js +383 -44
  5. package/native-src/3rdparty/android/ifaddrs-android.c +1 -0
  6. package/native-src/3rdparty/android/ifaddrs-android.h +1 -0
  7. package/native-src/CMakeLists.txt +396 -179
  8. package/native-src/LICENSE +1 -1
  9. package/native-src/src/librats/bindings/rats.cpp +731 -0
  10. package/native-src/src/librats/bindings/rats.h +352 -0
  11. package/native-src/src/librats/bittorrent/bencode.cpp +437 -0
  12. package/native-src/src/librats/bittorrent/bencode.h +176 -0
  13. package/native-src/src/librats/bittorrent/bitfield.cpp +97 -0
  14. package/native-src/src/librats/bittorrent/bitfield.h +76 -0
  15. package/native-src/src/librats/bittorrent/byte_io.h +58 -0
  16. package/native-src/src/librats/bittorrent/choker.cpp +25 -0
  17. package/native-src/src/librats/bittorrent/choker.h +46 -0
  18. package/native-src/src/librats/bittorrent/client.cpp +413 -0
  19. package/native-src/src/librats/bittorrent/client.h +227 -0
  20. package/native-src/src/librats/bittorrent/disk_io.cpp +209 -0
  21. package/native-src/src/librats/bittorrent/disk_io.h +150 -0
  22. package/native-src/src/librats/bittorrent/extensions.cpp +191 -0
  23. package/native-src/src/librats/bittorrent/extensions.h +94 -0
  24. package/native-src/src/librats/bittorrent/file_storage.cpp +77 -0
  25. package/native-src/src/librats/bittorrent/file_storage.h +79 -0
  26. package/native-src/src/librats/bittorrent/log.h +42 -0
  27. package/native-src/src/librats/bittorrent/magnet_uri.cpp +98 -0
  28. package/native-src/src/librats/bittorrent/magnet_uri.h +35 -0
  29. package/native-src/src/librats/bittorrent/peer_connection.cpp +502 -0
  30. package/native-src/src/librats/bittorrent/peer_connection.h +194 -0
  31. package/native-src/src/librats/bittorrent/peer_list.cpp +68 -0
  32. package/native-src/src/librats/bittorrent/peer_list.h +75 -0
  33. package/native-src/src/librats/bittorrent/piece_picker.cpp +352 -0
  34. package/native-src/src/librats/bittorrent/piece_picker.h +201 -0
  35. package/native-src/src/librats/bittorrent/reactor.cpp +97 -0
  36. package/native-src/src/librats/bittorrent/reactor.h +89 -0
  37. package/native-src/src/librats/bittorrent/resume_data.cpp +72 -0
  38. package/native-src/src/librats/bittorrent/resume_data.h +41 -0
  39. package/native-src/src/librats/bittorrent/store_buffer.cpp +48 -0
  40. package/native-src/src/librats/bittorrent/store_buffer.h +47 -0
  41. package/native-src/src/librats/bittorrent/torrent.cpp +870 -0
  42. package/native-src/src/librats/bittorrent/torrent.h +260 -0
  43. package/native-src/src/librats/bittorrent/torrent_creator.cpp +129 -0
  44. package/native-src/src/librats/bittorrent/torrent_creator.h +58 -0
  45. package/native-src/src/librats/bittorrent/torrent_info.cpp +314 -0
  46. package/native-src/src/librats/bittorrent/torrent_info.h +118 -0
  47. package/native-src/src/librats/bittorrent/tracker.cpp +374 -0
  48. package/native-src/src/librats/bittorrent/tracker.h +108 -0
  49. package/native-src/src/librats/bittorrent/types.cpp +206 -0
  50. package/native-src/src/librats/bittorrent/types.h +86 -0
  51. package/native-src/src/librats/core/address.cpp +35 -0
  52. package/native-src/src/librats/core/address.h +78 -0
  53. package/native-src/src/librats/core/bytes.h +69 -0
  54. package/native-src/src/librats/core/chained_send_buffer.cpp +172 -0
  55. package/native-src/src/librats/core/chained_send_buffer.h +183 -0
  56. package/native-src/src/librats/core/endpoint_parse.cpp +41 -0
  57. package/native-src/src/librats/core/endpoint_parse.h +31 -0
  58. package/native-src/src/librats/core/event_bus.h +70 -0
  59. package/native-src/src/librats/core/host_endpoint.h +56 -0
  60. package/native-src/src/{io_poller.cpp → librats/core/io_poller.cpp} +520 -65
  61. package/native-src/src/{io_poller.h → librats/core/io_poller.h} +12 -6
  62. package/native-src/src/librats/core/ip_address.cpp +120 -0
  63. package/native-src/src/librats/core/ip_address.h +109 -0
  64. package/native-src/src/librats/core/mpsc_queue.h +47 -0
  65. package/native-src/src/librats/core/notifier.h +74 -0
  66. package/native-src/src/librats/core/receive_buffer.cpp +219 -0
  67. package/native-src/src/librats/core/receive_buffer.h +171 -0
  68. package/native-src/src/librats/core/service_registry.h +58 -0
  69. package/native-src/src/{socket.cpp → librats/core/socket.cpp} +625 -118
  70. package/native-src/src/librats/core/socket.h +496 -0
  71. package/native-src/src/librats/core/timer_queue.h +105 -0
  72. package/native-src/src/librats/core/types.cpp +42 -0
  73. package/native-src/src/librats/core/types.h +93 -0
  74. package/native-src/src/librats/core/wakeup_pipe.h +83 -0
  75. package/native-src/src/{crypto → librats/crypto}/blake2_endian.h +21 -23
  76. package/native-src/src/{crypto → librats/crypto}/blake2b.c +34 -33
  77. package/native-src/src/{crypto → librats/crypto}/blake2b.h +7 -6
  78. package/native-src/src/{crypto → librats/crypto}/blake2s.c +55 -54
  79. package/native-src/src/{crypto → librats/crypto}/blake2s.h +13 -12
  80. package/native-src/src/{crypto → librats/crypto}/chacha.c +22 -21
  81. package/native-src/src/{crypto → librats/crypto}/chacha.h +14 -13
  82. package/native-src/src/{crypto → librats/crypto}/chachapoly.c +56 -56
  83. package/native-src/src/{crypto → librats/crypto}/chachapoly.h +24 -17
  84. package/native-src/src/{crc32.cpp → librats/crypto/crc32.cpp} +1 -1
  85. package/native-src/src/{crc32.h → librats/crypto/crc32.h} +3 -1
  86. package/native-src/src/{crypto → librats/crypto}/curve25519.c +6 -4
  87. package/native-src/src/{crypto → librats/crypto}/curve25519.h +6 -3
  88. package/native-src/src/librats/crypto/hkdf.c +266 -0
  89. package/native-src/src/{crypto → librats/crypto}/hkdf.h +19 -19
  90. package/native-src/src/{noise.cpp → librats/crypto/noise.cpp} +84 -73
  91. package/native-src/src/{noise.h → librats/crypto/noise.h} +18 -8
  92. package/native-src/src/{crypto → librats/crypto}/poly1305.c +47 -46
  93. package/native-src/src/librats/crypto/poly1305.h +37 -0
  94. package/native-src/src/{sha1.cpp → librats/crypto/sha1.cpp} +33 -1
  95. package/native-src/src/{sha1.h → librats/crypto/sha1.h} +14 -6
  96. package/native-src/src/{crypto → librats/crypto}/sha256.c +15 -14
  97. package/native-src/src/{crypto → librats/crypto}/sha256.h +8 -7
  98. package/native-src/src/{crypto → librats/crypto}/sha512.c +15 -14
  99. package/native-src/src/{crypto → librats/crypto}/sha512.h +8 -7
  100. package/native-src/src/librats/dht/announce.cpp +37 -0
  101. package/native-src/src/librats/dht/announce.h +41 -0
  102. package/native-src/src/librats/dht/bep42.cpp +109 -0
  103. package/native-src/src/librats/dht/bep42.h +48 -0
  104. package/native-src/src/librats/dht/dht.cpp +501 -0
  105. package/native-src/src/librats/dht/dht.h +119 -0
  106. package/native-src/src/librats/dht/dht_runner.cpp +103 -0
  107. package/native-src/src/librats/dht/dht_runner.h +71 -0
  108. package/native-src/src/librats/dht/dos_blocker.cpp +42 -0
  109. package/native-src/src/librats/dht/dos_blocker.h +47 -0
  110. package/native-src/src/librats/dht/find_peers.cpp +52 -0
  111. package/native-src/src/librats/dht/find_peers.h +73 -0
  112. package/native-src/src/librats/dht/id.h +167 -0
  113. package/native-src/src/{krpc.cpp → librats/dht/krpc.cpp} +32 -81
  114. package/native-src/src/{krpc.h → librats/dht/krpc.h} +19 -23
  115. package/native-src/src/librats/dht/log.h +38 -0
  116. package/native-src/src/librats/dht/node.cpp +473 -0
  117. package/native-src/src/librats/dht/node.h +164 -0
  118. package/native-src/src/librats/dht/node_entry.h +81 -0
  119. package/native-src/src/librats/dht/observer.h +72 -0
  120. package/native-src/src/librats/dht/persistence.cpp +90 -0
  121. package/native-src/src/librats/dht/persistence.h +32 -0
  122. package/native-src/src/librats/dht/routing_table.cpp +559 -0
  123. package/native-src/src/librats/dht/routing_table.h +185 -0
  124. package/native-src/src/librats/dht/rpc_manager.cpp +127 -0
  125. package/native-src/src/librats/dht/rpc_manager.h +77 -0
  126. package/native-src/src/librats/dht/storage.cpp +92 -0
  127. package/native-src/src/librats/dht/storage.h +74 -0
  128. package/native-src/src/librats/dht/transport.h +27 -0
  129. package/native-src/src/librats/dht/traversal.cpp +326 -0
  130. package/native-src/src/librats/dht/traversal.h +120 -0
  131. package/native-src/src/librats/dht/udp_transport.cpp +49 -0
  132. package/native-src/src/librats/dht/udp_transport.h +51 -0
  133. package/native-src/src/librats/mdns/log.h +22 -0
  134. package/native-src/src/{mdns.cpp → librats/mdns/mdns.cpp} +75 -40
  135. package/native-src/src/{mdns.h → librats/mdns/mdns.h} +9 -8
  136. package/native-src/src/{natpmp.cpp → librats/nat/natpmp.cpp} +12 -9
  137. package/native-src/src/{natpmp.h → librats/nat/natpmp.h} +3 -3
  138. package/native-src/src/{port_mapping.h → librats/nat/port_mapping.h} +3 -2
  139. package/native-src/src/{stun.cpp → librats/nat/stun.cpp} +4 -4
  140. package/native-src/src/{stun.h → librats/nat/stun.h} +1 -1
  141. package/native-src/src/{upnp.cpp → librats/nat/upnp.cpp} +6 -6
  142. package/native-src/src/{upnp.h → librats/nat/upnp.h} +2 -2
  143. package/native-src/src/librats/node/config.h +110 -0
  144. package/native-src/src/librats/node/dial_service.h +54 -0
  145. package/native-src/src/librats/node/dialer.cpp +264 -0
  146. package/native-src/src/librats/node/dialer.h +188 -0
  147. package/native-src/src/librats/node/host_events.h +26 -0
  148. package/native-src/src/librats/node/identify.cpp +130 -0
  149. package/native-src/src/librats/node/identify.h +71 -0
  150. package/native-src/src/librats/node/nat_status.cpp +103 -0
  151. package/native-src/src/librats/node/nat_status.h +118 -0
  152. package/native-src/src/librats/node/node.cpp +826 -0
  153. package/native-src/src/librats/node/node.h +333 -0
  154. package/native-src/src/librats/node/node_context.h +33 -0
  155. package/native-src/src/librats/node/peer_network.h +91 -0
  156. package/native-src/src/librats/peer/peer.h +49 -0
  157. package/native-src/src/librats/peer/peer_book.cpp +181 -0
  158. package/native-src/src/librats/peer/peer_book.h +88 -0
  159. package/native-src/src/librats/peer/peer_id.cpp +72 -0
  160. package/native-src/src/librats/peer/peer_id.h +62 -0
  161. package/native-src/src/librats/peer/peer_info.h +37 -0
  162. package/native-src/src/librats/peer/peer_table.cpp +137 -0
  163. package/native-src/src/librats/peer/peer_table.h +148 -0
  164. package/native-src/src/librats/security/handshaker.h +66 -0
  165. package/native-src/src/librats/security/identity.h +43 -0
  166. package/native-src/src/librats/security/noise_security.cpp +122 -0
  167. package/native-src/src/librats/security/noise_security.h +37 -0
  168. package/native-src/src/librats/security/plaintext_security.h +106 -0
  169. package/native-src/src/librats/security/session.h +37 -0
  170. package/native-src/src/{storage.cpp → librats/storage/storage.cpp} +369 -522
  171. package/native-src/src/{storage.h → librats/storage/storage.h} +135 -299
  172. package/native-src/src/librats/subsystems/bittorrent.cpp +211 -0
  173. package/native-src/src/librats/subsystems/bittorrent.h +136 -0
  174. package/native-src/src/librats/subsystems/dht_discovery.cpp +202 -0
  175. package/native-src/src/librats/subsystems/dht_discovery.h +123 -0
  176. package/native-src/src/librats/subsystems/dht_service.h +36 -0
  177. package/native-src/src/librats/subsystems/file_transfer.cpp +972 -0
  178. package/native-src/src/librats/subsystems/file_transfer.h +367 -0
  179. package/native-src/src/librats/subsystems/hole_punch.cpp +532 -0
  180. package/native-src/src/librats/subsystems/hole_punch.h +266 -0
  181. package/native-src/src/librats/subsystems/hole_punch_service.h +38 -0
  182. package/native-src/src/librats/subsystems/mdns_discovery.cpp +66 -0
  183. package/native-src/src/librats/subsystems/mdns_discovery.h +55 -0
  184. package/native-src/src/librats/subsystems/message_json.cpp +112 -0
  185. package/native-src/src/librats/subsystems/message_json.h +88 -0
  186. package/native-src/src/librats/subsystems/peer_exchange.cpp +241 -0
  187. package/native-src/src/librats/subsystems/peer_exchange.h +136 -0
  188. package/native-src/src/librats/subsystems/ping_service.cpp +98 -0
  189. package/native-src/src/librats/subsystems/ping_service.h +66 -0
  190. package/native-src/src/librats/subsystems/port_mapping_service.cpp +192 -0
  191. package/native-src/src/librats/subsystems/port_mapping_service.h +84 -0
  192. package/native-src/src/librats/subsystems/pubsub.cpp +567 -0
  193. package/native-src/src/librats/subsystems/pubsub.h +175 -0
  194. package/native-src/src/librats/subsystems/reconnection.cpp +239 -0
  195. package/native-src/src/librats/subsystems/reconnection.h +126 -0
  196. package/native-src/src/librats/transport/connection.cpp +343 -0
  197. package/native-src/src/librats/transport/connection.h +283 -0
  198. package/native-src/src/librats/transport/link.h +96 -0
  199. package/native-src/src/librats/transport/reactor.cpp +540 -0
  200. package/native-src/src/librats/transport/reactor.h +224 -0
  201. package/native-src/src/librats/transport/reactor_pool.h +81 -0
  202. package/native-src/src/librats/transport/tcp_link.cpp +49 -0
  203. package/native-src/src/librats/transport/tcp_link.h +43 -0
  204. package/native-src/src/librats/transport/udp_mux.cpp +617 -0
  205. package/native-src/src/librats/transport/udp_mux.h +363 -0
  206. package/native-src/src/librats/transport/udp_packet.cpp +121 -0
  207. package/native-src/src/librats/transport/udp_packet.h +190 -0
  208. package/native-src/src/librats/transport/udp_stream.cpp +1194 -0
  209. package/native-src/src/librats/transport/udp_stream.h +614 -0
  210. package/native-src/src/librats/util/features.h.in +51 -0
  211. package/native-src/src/{fs.cpp → librats/util/fs.cpp} +51 -3
  212. package/native-src/src/librats/util/fs.h +136 -0
  213. package/native-src/src/librats/util/json.cpp +1002 -0
  214. package/native-src/src/librats/util/json.h +444 -0
  215. package/native-src/src/{logger.cpp → librats/util/logger.cpp} +1 -1
  216. package/native-src/src/{logger.h → librats/util/logger.h} +43 -31
  217. package/native-src/src/{network_monitor.cpp → librats/util/network_monitor.cpp} +12 -4
  218. package/native-src/src/{network_monitor.h → librats/util/network_monitor.h} +2 -1
  219. package/native-src/src/{network_utils.cpp → librats/util/network_utils.cpp} +38 -23
  220. package/native-src/src/{network_utils.h → librats/util/network_utils.h} +15 -8
  221. package/native-src/src/{os.cpp → librats/util/os.cpp} +48 -18
  222. package/native-src/src/librats/util/rats_export.h +69 -0
  223. package/native-src/src/{version.cpp → librats/util/version.cpp} +2 -2
  224. package/native-src/src/{version.h.in → librats/util/version.h.in} +1 -1
  225. package/native-src/src/librats/wire/frame.cpp +76 -0
  226. package/native-src/src/librats/wire/frame.h +110 -0
  227. package/native-src/src/librats/wire/message_router.cpp +45 -0
  228. package/native-src/src/librats/wire/message_router.h +47 -0
  229. package/package.json +5 -4
  230. package/scripts/build-librats.js +1 -0
  231. package/scripts/postinstall.js +3 -3
  232. package/scripts/prepare-package.js +4 -4
  233. package/scripts/verify-installation.js +63 -105
  234. package/src/librats_node.cpp +1042 -1324
  235. package/native-src/src/bencode.cpp +0 -485
  236. package/native-src/src/bencode.h +0 -145
  237. package/native-src/src/bittorrent.cpp +0 -14
  238. package/native-src/src/bittorrent.h +0 -74
  239. package/native-src/src/bt_bitfield.cpp +0 -372
  240. package/native-src/src/bt_bitfield.h +0 -316
  241. package/native-src/src/bt_choker.cpp +0 -228
  242. package/native-src/src/bt_choker.h +0 -147
  243. package/native-src/src/bt_client.cpp +0 -1047
  244. package/native-src/src/bt_client.h +0 -445
  245. package/native-src/src/bt_create_torrent.cpp +0 -677
  246. package/native-src/src/bt_create_torrent.h +0 -473
  247. package/native-src/src/bt_extension.cpp +0 -469
  248. package/native-src/src/bt_extension.h +0 -309
  249. package/native-src/src/bt_file_storage.cpp +0 -261
  250. package/native-src/src/bt_file_storage.h +0 -298
  251. package/native-src/src/bt_handshake.cpp +0 -134
  252. package/native-src/src/bt_handshake.h +0 -157
  253. package/native-src/src/bt_messages.cpp +0 -364
  254. package/native-src/src/bt_messages.h +0 -324
  255. package/native-src/src/bt_network.cpp +0 -1007
  256. package/native-src/src/bt_network.h +0 -417
  257. package/native-src/src/bt_peer_connection.cpp +0 -742
  258. package/native-src/src/bt_peer_connection.h +0 -592
  259. package/native-src/src/bt_piece_picker.cpp +0 -786
  260. package/native-src/src/bt_piece_picker.h +0 -473
  261. package/native-src/src/bt_resume_data.cpp +0 -410
  262. package/native-src/src/bt_resume_data.h +0 -249
  263. package/native-src/src/bt_torrent.cpp +0 -2120
  264. package/native-src/src/bt_torrent.h +0 -641
  265. package/native-src/src/bt_torrent_info.cpp +0 -659
  266. package/native-src/src/bt_torrent_info.h +0 -418
  267. package/native-src/src/bt_types.h +0 -621
  268. package/native-src/src/chained_send_buffer.cpp +0 -75
  269. package/native-src/src/chained_send_buffer.h +0 -137
  270. package/native-src/src/crypto/hkdf.c +0 -266
  271. package/native-src/src/crypto/poly1305.h +0 -36
  272. package/native-src/src/dht.cpp +0 -3311
  273. package/native-src/src/dht.h +0 -717
  274. package/native-src/src/disk_io.cpp +0 -632
  275. package/native-src/src/disk_io.h +0 -315
  276. package/native-src/src/file_transfer.cpp +0 -1415
  277. package/native-src/src/file_transfer.h +0 -286
  278. package/native-src/src/fs.h +0 -108
  279. package/native-src/src/gossipsub.cpp +0 -1139
  280. package/native-src/src/gossipsub.h +0 -403
  281. package/native-src/src/ice.cpp +0 -893
  282. package/native-src/src/ice.h +0 -559
  283. package/native-src/src/json.hpp +0 -25526
  284. package/native-src/src/librats.cpp +0 -2378
  285. package/native-src/src/librats.h +0 -2324
  286. package/native-src/src/librats_bittorrent.cpp +0 -601
  287. package/native-src/src/librats_c.cpp +0 -1557
  288. package/native-src/src/librats_c.h +0 -323
  289. package/native-src/src/librats_discovery.cpp +0 -402
  290. package/native-src/src/librats_encryption.cpp +0 -275
  291. package/native-src/src/librats_file_transfer.cpp +0 -144
  292. package/native-src/src/librats_gossipsub.cpp +0 -289
  293. package/native-src/src/librats_ice.cpp +0 -213
  294. package/native-src/src/librats_log_macros.h +0 -36
  295. package/native-src/src/librats_logging.cpp +0 -173
  296. package/native-src/src/librats_mdns.cpp +0 -166
  297. package/native-src/src/librats_persistence.cpp +0 -796
  298. package/native-src/src/librats_portmap.cpp +0 -419
  299. package/native-src/src/librats_reconnection.cpp +0 -218
  300. package/native-src/src/librats_statistic.cpp +0 -105
  301. package/native-src/src/librats_storage.cpp +0 -189
  302. package/native-src/src/rats_export.h +0 -17
  303. package/native-src/src/receive_buffer.cpp +0 -82
  304. package/native-src/src/receive_buffer.h +0 -127
  305. package/native-src/src/socket.h +0 -228
  306. package/native-src/src/threadmanager.cpp +0 -105
  307. package/native-src/src/threadmanager.h +0 -53
  308. package/native-src/src/tracker.cpp +0 -1264
  309. package/native-src/src/tracker.h +0 -319
  310. package/native-src/src/turn.cpp +0 -762
  311. package/native-src/src/turn.h +0 -460
  312. package/native-src/src/wakeup_pipe.h +0 -60
  313. /package/native-src/src/{os.h → librats/util/os.h} +0 -0
@@ -1,144 +0,0 @@
1
- #include "librats.h"
2
- #include "librats_log_macros.h"
3
-
4
- namespace librats {
5
-
6
- // =============================================================================
7
- // File transfer API - thin forwarding layer over FileTransferManager
8
- // =============================================================================
9
-
10
- FileTransferManager& RatsClient::get_file_transfer_manager() {
11
- if (!file_transfer_manager_) {
12
- throw std::runtime_error("File transfer manager not initialized");
13
- }
14
- return *file_transfer_manager_;
15
- }
16
-
17
- bool RatsClient::is_file_transfer_available() const {
18
- return file_transfer_manager_ != nullptr;
19
- }
20
-
21
- std::string RatsClient::send_file(const std::string& peer_id, const std::string& file_path,
22
- const std::string& remote_filename) {
23
- if (!is_file_transfer_available()) {
24
- LOG_CLIENT_ERROR("File transfer manager not available");
25
- return "";
26
- }
27
- return file_transfer_manager_->send_file(peer_id, file_path, remote_filename);
28
- }
29
-
30
- std::string RatsClient::send_directory(const std::string& peer_id, const std::string& directory_path,
31
- const std::string& remote_name) {
32
- if (!is_file_transfer_available()) {
33
- LOG_CLIENT_ERROR("File transfer manager not available");
34
- return "";
35
- }
36
- return file_transfer_manager_->send_directory(peer_id, directory_path, remote_name);
37
- }
38
-
39
- bool RatsClient::accept_file_transfer(const std::string& transfer_id, const std::string& local_path) {
40
- if (!is_file_transfer_available()) {
41
- LOG_CLIENT_ERROR("File transfer manager not available");
42
- return false;
43
- }
44
- return file_transfer_manager_->accept(transfer_id, local_path);
45
- }
46
-
47
- bool RatsClient::reject_file_transfer(const std::string& transfer_id, const std::string& reason) {
48
- if (!is_file_transfer_available()) {
49
- LOG_CLIENT_ERROR("File transfer manager not available");
50
- return false;
51
- }
52
- return file_transfer_manager_->reject(transfer_id, reason);
53
- }
54
-
55
- bool RatsClient::pause_file_transfer(const std::string& transfer_id) {
56
- if (!is_file_transfer_available()) {
57
- LOG_CLIENT_ERROR("File transfer manager not available");
58
- return false;
59
- }
60
- return file_transfer_manager_->pause(transfer_id);
61
- }
62
-
63
- bool RatsClient::resume_file_transfer(const std::string& transfer_id) {
64
- if (!is_file_transfer_available()) {
65
- LOG_CLIENT_ERROR("File transfer manager not available");
66
- return false;
67
- }
68
- return file_transfer_manager_->resume(transfer_id);
69
- }
70
-
71
- bool RatsClient::cancel_file_transfer(const std::string& transfer_id) {
72
- if (!is_file_transfer_available()) {
73
- LOG_CLIENT_ERROR("File transfer manager not available");
74
- return false;
75
- }
76
- return file_transfer_manager_->cancel(transfer_id);
77
- }
78
-
79
- std::shared_ptr<FileTransferProgress>
80
- RatsClient::get_file_transfer_progress(const std::string& transfer_id) const {
81
- if (!is_file_transfer_available()) {
82
- LOG_CLIENT_ERROR("File transfer manager not available");
83
- return nullptr;
84
- }
85
- return file_transfer_manager_->get_progress(transfer_id);
86
- }
87
-
88
- std::vector<std::shared_ptr<FileTransferProgress>>
89
- RatsClient::get_active_file_transfers() const {
90
- if (!is_file_transfer_available()) {
91
- LOG_CLIENT_ERROR("File transfer manager not available");
92
- return {};
93
- }
94
- return file_transfer_manager_->get_active_transfers();
95
- }
96
-
97
- nlohmann::json RatsClient::get_file_transfer_statistics() const {
98
- if (!is_file_transfer_available()) {
99
- LOG_CLIENT_ERROR("File transfer manager not available");
100
- return nlohmann::json::object();
101
- }
102
- return file_transfer_manager_->get_statistics();
103
- }
104
-
105
- void RatsClient::set_file_transfer_config(const FileTransferConfig& config) {
106
- if (!is_file_transfer_available()) {
107
- LOG_CLIENT_ERROR("File transfer manager not available");
108
- return;
109
- }
110
- file_transfer_manager_->set_config(config);
111
- }
112
-
113
- FileTransferConfig RatsClient::get_file_transfer_config() const {
114
- if (!is_file_transfer_available()) {
115
- throw std::runtime_error("File transfer manager not available");
116
- }
117
- return file_transfer_manager_->get_config();
118
- }
119
-
120
- void RatsClient::on_file_transfer_progress(TransferProgressCallback callback) {
121
- if (!is_file_transfer_available()) {
122
- LOG_CLIENT_ERROR("File transfer manager not available");
123
- return;
124
- }
125
- file_transfer_manager_->set_progress_callback(std::move(callback));
126
- }
127
-
128
- void RatsClient::on_file_transfer_completed(TransferCompletedCallback callback) {
129
- if (!is_file_transfer_available()) {
130
- LOG_CLIENT_ERROR("File transfer manager not available");
131
- return;
132
- }
133
- file_transfer_manager_->set_completed_callback(std::move(callback));
134
- }
135
-
136
- void RatsClient::on_file_transfer_request(TransferOfferCallback callback) {
137
- if (!is_file_transfer_available()) {
138
- LOG_CLIENT_ERROR("File transfer manager not available");
139
- return;
140
- }
141
- file_transfer_manager_->set_offer_callback(std::move(callback));
142
- }
143
-
144
- } // namespace librats
@@ -1,289 +0,0 @@
1
- #include "librats.h"
2
- #include "librats_log_macros.h"
3
-
4
- namespace librats {
5
-
6
- //=============================================================================
7
- // GossipSub Integration Methods
8
- //=============================================================================
9
-
10
- GossipSub& RatsClient::get_gossipsub() {
11
- if (!gossipsub_) {
12
- throw std::runtime_error("GossipSub not initialized");
13
- }
14
- return *gossipsub_;
15
- }
16
-
17
- bool RatsClient::is_gossipsub_available() const {
18
- return gossipsub_ != nullptr;
19
- }
20
-
21
- //=============================================================================
22
- // GossipSub Convenience Methods - Topic Management
23
- //=============================================================================
24
-
25
- bool RatsClient::subscribe_to_topic(const std::string& topic) {
26
- if (!is_gossipsub_available()) {
27
- LOG_CLIENT_ERROR("GossipSub not available for topic subscription: " << topic);
28
- return false;
29
- }
30
-
31
- try {
32
- return gossipsub_->subscribe(topic);
33
- } catch (const std::exception& e) {
34
- LOG_CLIENT_ERROR("Failed to subscribe to topic '" << topic << "': " << e.what());
35
- return false;
36
- }
37
- }
38
-
39
- bool RatsClient::unsubscribe_from_topic(const std::string& topic) {
40
- if (!is_gossipsub_available()) {
41
- LOG_CLIENT_ERROR("GossipSub not available for topic unsubscription: " << topic);
42
- return false;
43
- }
44
-
45
- try {
46
- return gossipsub_->unsubscribe(topic);
47
- } catch (const std::exception& e) {
48
- LOG_CLIENT_ERROR("Failed to unsubscribe from topic '" << topic << "': " << e.what());
49
- return false;
50
- }
51
- }
52
-
53
- bool RatsClient::is_subscribed_to_topic(const std::string& topic) const {
54
- if (!is_gossipsub_available()) {
55
- return false;
56
- }
57
-
58
- try {
59
- return gossipsub_->is_subscribed(topic);
60
- } catch (const std::exception& e) {
61
- LOG_CLIENT_ERROR("Failed to check subscription for topic '" << topic << "': " << e.what());
62
- return false;
63
- }
64
- }
65
-
66
- std::vector<std::string> RatsClient::get_subscribed_topics() const {
67
- if (!is_gossipsub_available()) {
68
- return {};
69
- }
70
-
71
- try {
72
- return gossipsub_->get_subscribed_topics();
73
- } catch (const std::exception& e) {
74
- LOG_CLIENT_ERROR("Failed to get subscribed topics: " << e.what());
75
- return {};
76
- }
77
- }
78
-
79
- //=============================================================================
80
- // GossipSub Convenience Methods - Publishing
81
- //=============================================================================
82
-
83
- bool RatsClient::publish_to_topic(const std::string& topic, const std::string& message) {
84
- if (!is_gossipsub_available()) {
85
- LOG_CLIENT_ERROR("GossipSub not available for publishing to topic: " << topic);
86
- return false;
87
- }
88
-
89
- try {
90
- return gossipsub_->publish(topic, message);
91
- } catch (const std::exception& e) {
92
- LOG_CLIENT_ERROR("Failed to publish to topic '" << topic << "': " << e.what());
93
- return false;
94
- }
95
- }
96
-
97
- bool RatsClient::publish_json_to_topic(const std::string& topic, const nlohmann::json& message) {
98
- if (!is_gossipsub_available()) {
99
- LOG_CLIENT_ERROR("GossipSub not available for publishing JSON to topic: " << topic);
100
- return false;
101
- }
102
-
103
- try {
104
- return gossipsub_->publish(topic, message);
105
- } catch (const std::exception& e) {
106
- LOG_CLIENT_ERROR("Failed to publish JSON to topic '" << topic << "': " << e.what());
107
- return false;
108
- }
109
- }
110
-
111
- //=============================================================================
112
- // GossipSub Convenience Methods - Event Handlers (Unified API)
113
- //=============================================================================
114
-
115
- void RatsClient::on_topic_message(const std::string& topic, std::function<void(const std::string&, const std::string&, const std::string&)> callback) {
116
- if (!is_gossipsub_available()) {
117
- LOG_CLIENT_ERROR("GossipSub not available for setting message handler on topic: " << topic);
118
- return;
119
- }
120
-
121
- try {
122
- // Convert unified callback signature to GossipSub's MessageHandler signature
123
- gossipsub_->set_message_handler(topic, [callback](const std::string& topic, const std::string& message, const std::string& sender_peer_id) {
124
- callback(sender_peer_id, topic, message);
125
- });
126
- LOG_CLIENT_INFO("Set message handler for topic: " << topic);
127
- } catch (const std::exception& e) {
128
- LOG_CLIENT_ERROR("Failed to set message handler for topic '" << topic << "': " << e.what());
129
- }
130
- }
131
-
132
- void RatsClient::on_topic_json_message(const std::string& topic, std::function<void(const std::string&, const std::string&, const nlohmann::json&)> callback) {
133
- if (!is_gossipsub_available()) {
134
- LOG_CLIENT_ERROR("GossipSub not available for setting JSON message handler on topic: " << topic);
135
- return;
136
- }
137
-
138
- try {
139
- // Convert unified callback signature to GossipSub's MessageHandler signature with JSON parsing
140
- gossipsub_->set_message_handler(topic, [callback](const std::string& topic, const std::string& message, const std::string& sender_peer_id) {
141
- try {
142
- nlohmann::json json_message = nlohmann::json::parse(message);
143
- callback(sender_peer_id, topic, json_message);
144
- } catch (const nlohmann::json::exception& e) {
145
- LOG_WARN("client", "Failed to parse JSON message on topic '" << topic << "': " << e.what());
146
- // Still call callback with empty JSON object to maintain consistency
147
- callback(sender_peer_id, topic, nlohmann::json{});
148
- }
149
- });
150
- LOG_CLIENT_INFO("Set JSON message handler for topic: " << topic);
151
- } catch (const std::exception& e) {
152
- LOG_CLIENT_ERROR("Failed to set JSON message handler for topic '" << topic << "': " << e.what());
153
- }
154
- }
155
-
156
- void RatsClient::on_topic_peer_joined(const std::string& topic, std::function<void(const std::string&, const std::string&)> callback) {
157
- if (!is_gossipsub_available()) {
158
- LOG_CLIENT_ERROR("GossipSub not available for setting peer joined handler on topic: " << topic);
159
- return;
160
- }
161
-
162
- try {
163
- // Convert unified callback signature to GossipSub's PeerJoinedHandler signature
164
- gossipsub_->set_peer_joined_handler(topic, [callback](const std::string& topic, const std::string& peer_id) {
165
- callback(peer_id, topic);
166
- });
167
- LOG_CLIENT_INFO("Set peer joined handler for topic: " << topic);
168
- } catch (const std::exception& e) {
169
- LOG_CLIENT_ERROR("Failed to set peer joined handler for topic '" << topic << "': " << e.what());
170
- }
171
- }
172
-
173
- void RatsClient::on_topic_peer_left(const std::string& topic, std::function<void(const std::string&, const std::string&)> callback) {
174
- if (!is_gossipsub_available()) {
175
- LOG_CLIENT_ERROR("GossipSub not available for setting peer left handler on topic: " << topic);
176
- return;
177
- }
178
-
179
- try {
180
- // Convert unified callback signature to GossipSub's PeerLeftHandler signature
181
- gossipsub_->set_peer_left_handler(topic, [callback](const std::string& topic, const std::string& peer_id) {
182
- callback(peer_id, topic);
183
- });
184
- LOG_CLIENT_INFO("Set peer left handler for topic: " << topic);
185
- } catch (const std::exception& e) {
186
- LOG_CLIENT_ERROR("Failed to set peer left handler for topic '" << topic << "': " << e.what());
187
- }
188
- }
189
-
190
- void RatsClient::set_topic_message_validator(const std::string& topic, std::function<ValidationResult(const std::string&, const std::string&, const std::string&)> validator) {
191
- if (!is_gossipsub_available()) {
192
- LOG_CLIENT_ERROR("GossipSub not available for setting message validator on topic: " << topic);
193
- return;
194
- }
195
-
196
- try {
197
- // Convert unified callback signature to GossipSub's MessageValidator signature
198
- gossipsub_->set_message_validator(topic, [validator](const std::string& topic, const std::string& message, const std::string& sender_peer_id) {
199
- return validator(topic, message, sender_peer_id);
200
- });
201
- LOG_CLIENT_INFO("Set message validator for topic: " << topic);
202
- } catch (const std::exception& e) {
203
- LOG_CLIENT_ERROR("Failed to set message validator for topic '" << topic << "': " << e.what());
204
- }
205
- }
206
-
207
- void RatsClient::off_topic(const std::string& topic) {
208
- if (!is_gossipsub_available()) {
209
- LOG_CLIENT_ERROR("GossipSub not available for removing handlers from topic: " << topic);
210
- return;
211
- }
212
-
213
- try {
214
- // Remove all handlers by setting them to nullptr
215
- gossipsub_->set_message_handler(topic, nullptr);
216
- gossipsub_->set_peer_joined_handler(topic, nullptr);
217
- gossipsub_->set_peer_left_handler(topic, nullptr);
218
- gossipsub_->set_message_validator(topic, nullptr);
219
- LOG_CLIENT_INFO("Removed all handlers for topic: " << topic);
220
- } catch (const std::exception& e) {
221
- LOG_CLIENT_ERROR("Failed to remove handlers for topic '" << topic << "': " << e.what());
222
- }
223
- }
224
-
225
- //=============================================================================
226
- // GossipSub Convenience Methods - Information
227
- //=============================================================================
228
-
229
- std::vector<std::string> RatsClient::get_topic_peers(const std::string& topic) const {
230
- if (!is_gossipsub_available()) {
231
- return {};
232
- }
233
-
234
- try {
235
- return gossipsub_->get_topic_peers(topic);
236
- } catch (const std::exception& e) {
237
- LOG_CLIENT_ERROR("Failed to get topic peers for '" << topic << "': " << e.what());
238
- return {};
239
- }
240
- }
241
-
242
- std::vector<std::string> RatsClient::get_topic_mesh_peers(const std::string& topic) const {
243
- if (!is_gossipsub_available()) {
244
- return {};
245
- }
246
-
247
- try {
248
- return gossipsub_->get_mesh_peers(topic);
249
- } catch (const std::exception& e) {
250
- LOG_CLIENT_ERROR("Failed to get mesh peers for topic '" << topic << "': " << e.what());
251
- return {};
252
- }
253
- }
254
-
255
- nlohmann::json RatsClient::get_gossipsub_statistics() const {
256
- if (!is_gossipsub_available()) {
257
- nlohmann::json empty_stats;
258
- empty_stats["available"] = false;
259
- empty_stats["error"] = "GossipSub not initialized";
260
- return empty_stats;
261
- }
262
-
263
- try {
264
- nlohmann::json stats = gossipsub_->get_statistics();
265
- stats["available"] = true;
266
- stats["running"] = gossipsub_->is_running();
267
- return stats;
268
- } catch (const std::exception& e) {
269
- nlohmann::json error_stats;
270
- error_stats["available"] = true;
271
- error_stats["error"] = e.what();
272
- return error_stats;
273
- }
274
- }
275
-
276
- bool RatsClient::is_gossipsub_running() const {
277
- if (!is_gossipsub_available()) {
278
- return false;
279
- }
280
-
281
- try {
282
- return gossipsub_->is_running();
283
- } catch (const std::exception& e) {
284
- LOG_CLIENT_ERROR("Failed to check GossipSub running status: " << e.what());
285
- return false;
286
- }
287
- }
288
-
289
- }
@@ -1,213 +0,0 @@
1
- /**
2
- * @file librats_ice.cpp
3
- * @brief ICE (NAT Traversal) API implementation for RatsClient
4
- *
5
- * Provides STUN/TURN/ICE functionality for NAT traversal and public address discovery.
6
- */
7
-
8
- #include "librats.h"
9
- #include "logger.h"
10
-
11
- namespace librats {
12
-
13
- // ============================================================================
14
- // ICE Manager Access
15
- // ============================================================================
16
-
17
- IceManager& RatsClient::get_ice_manager() {
18
- if (!ice_manager_) {
19
- ice_manager_ = std::make_unique<IceManager>();
20
- }
21
- return *ice_manager_;
22
- }
23
-
24
- bool RatsClient::is_ice_available() const {
25
- return ice_manager_ != nullptr;
26
- }
27
-
28
- // ============================================================================
29
- // Server Configuration
30
- // ============================================================================
31
-
32
- void RatsClient::add_stun_server(const std::string& host, uint16_t port) {
33
- get_ice_manager().add_stun_server(host, port);
34
- LOG_INFO("ice", "Added STUN server: " << host << ":" << port);
35
- }
36
-
37
- void RatsClient::add_turn_server(const std::string& host, uint16_t port,
38
- const std::string& username, const std::string& password) {
39
- get_ice_manager().add_turn_server(host, port, username, password);
40
- LOG_INFO("ice", "Added TURN server: " << host << ":" << port);
41
- }
42
-
43
- void RatsClient::clear_ice_servers() {
44
- get_ice_manager().clear_ice_servers();
45
- LOG_DEBUG("ice", "Cleared all ICE servers");
46
- }
47
-
48
- // ============================================================================
49
- // Candidate Gathering
50
- // ============================================================================
51
-
52
- bool RatsClient::gather_ice_candidates() {
53
- LOG_INFO("ice", "Starting ICE candidate gathering");
54
- return get_ice_manager().gather_candidates();
55
- }
56
-
57
- std::vector<IceCandidate> RatsClient::get_ice_candidates() const {
58
- if (!ice_manager_) {
59
- return {};
60
- }
61
- return ice_manager_->get_local_candidates();
62
- }
63
-
64
- bool RatsClient::is_ice_gathering_complete() const {
65
- if (!ice_manager_) {
66
- return false;
67
- }
68
- return ice_manager_->is_gathering_complete();
69
- }
70
-
71
- // ============================================================================
72
- // Public Address Discovery
73
- // ============================================================================
74
-
75
- std::optional<std::pair<std::string, uint16_t>> RatsClient::get_public_address() const {
76
- if (!ice_manager_) {
77
- return std::nullopt;
78
- }
79
- return ice_manager_->get_public_address();
80
- }
81
-
82
- std::optional<StunMappedAddress> RatsClient::discover_public_address(
83
- const std::string& server,
84
- uint16_t port,
85
- int timeout_ms) {
86
-
87
- LOG_INFO("ice", "Discovering public address via STUN: " << server << ":" << port);
88
-
89
- StunClient stun_client;
90
- auto result = stun_client.binding_request(server, port, timeout_ms);
91
-
92
- if (result.success && result.mapped_address) {
93
- LOG_INFO("ice", "Discovered public address: " << result.mapped_address->to_string());
94
-
95
- // Add public IP to our own addresses list to prevent self-connections
96
- add_ignored_address(result.mapped_address->address);
97
-
98
- return result.mapped_address;
99
- }
100
-
101
- LOG_WARN("ice", "Failed to discover public address via STUN");
102
- return std::nullopt;
103
- }
104
-
105
- // ============================================================================
106
- // Remote Candidates
107
- // ============================================================================
108
-
109
- void RatsClient::add_remote_ice_candidate(const IceCandidate& candidate) {
110
- get_ice_manager().add_remote_candidate(candidate);
111
- }
112
-
113
- void RatsClient::add_remote_ice_candidates_from_sdp(const std::vector<std::string>& sdp_lines) {
114
- get_ice_manager().add_remote_candidates_from_sdp(sdp_lines);
115
- }
116
-
117
- void RatsClient::end_of_remote_ice_candidates() {
118
- get_ice_manager().end_of_remote_candidates();
119
- }
120
-
121
- // ============================================================================
122
- // Connectivity
123
- // ============================================================================
124
-
125
- void RatsClient::start_ice_checks() {
126
- LOG_INFO("ice", "Starting ICE connectivity checks");
127
- get_ice_manager().start_checks();
128
- }
129
-
130
- IceConnectionState RatsClient::get_ice_connection_state() const {
131
- if (!ice_manager_) {
132
- return IceConnectionState::New;
133
- }
134
- return ice_manager_->get_connection_state();
135
- }
136
-
137
- IceGatheringState RatsClient::get_ice_gathering_state() const {
138
- if (!ice_manager_) {
139
- return IceGatheringState::New;
140
- }
141
- return ice_manager_->get_gathering_state();
142
- }
143
-
144
- bool RatsClient::is_ice_connected() const {
145
- if (!ice_manager_) {
146
- return false;
147
- }
148
- return ice_manager_->is_connected();
149
- }
150
-
151
- std::optional<IceCandidatePair> RatsClient::get_ice_selected_pair() const {
152
- if (!ice_manager_) {
153
- return std::nullopt;
154
- }
155
- return ice_manager_->get_selected_pair();
156
- }
157
-
158
- // ============================================================================
159
- // Event Callbacks
160
- // ============================================================================
161
-
162
- void RatsClient::on_ice_candidates_gathered(IceCandidatesCallback callback) {
163
- get_ice_manager().set_on_candidates_gathered(std::move(callback));
164
- }
165
-
166
- void RatsClient::on_ice_new_candidate(IceNewCandidateCallback callback) {
167
- get_ice_manager().set_on_new_candidate(std::move(callback));
168
- }
169
-
170
- void RatsClient::on_ice_gathering_state_changed(IceGatheringStateCallback callback) {
171
- get_ice_manager().set_on_gathering_state_changed(std::move(callback));
172
- }
173
-
174
- void RatsClient::on_ice_connection_state_changed(IceConnectionStateCallback callback) {
175
- get_ice_manager().set_on_connection_state_changed(std::move(callback));
176
- }
177
-
178
- void RatsClient::on_ice_selected_pair(IceSelectedPairCallback callback) {
179
- get_ice_manager().set_on_selected_pair(std::move(callback));
180
- }
181
-
182
- // ============================================================================
183
- // Configuration
184
- // ============================================================================
185
-
186
- void RatsClient::set_ice_config(const IceConfig& config) {
187
- get_ice_manager().set_config(config);
188
- }
189
-
190
- IceConfig RatsClient::get_ice_config() const {
191
- // Need to cast away const to get mutable reference for lazy initialization
192
- return const_cast<RatsClient*>(this)->get_ice_manager().config();
193
- }
194
-
195
- // ============================================================================
196
- // Lifecycle
197
- // ============================================================================
198
-
199
- void RatsClient::close_ice() {
200
- if (ice_manager_) {
201
- ice_manager_->close();
202
- LOG_INFO("ice", "ICE manager closed");
203
- }
204
- }
205
-
206
- void RatsClient::restart_ice() {
207
- if (ice_manager_) {
208
- LOG_INFO("ice", "Restarting ICE");
209
- ice_manager_->restart();
210
- }
211
- }
212
-
213
- } // namespace librats
@@ -1,36 +0,0 @@
1
- /**
2
- * @file librats_log_macros.h
3
- * @brief Shared logging macros for all librats_*.cpp files.
4
- *
5
- * In TESTING builds the macros embed the `this` pointer so that
6
- * log lines from different RatsClient instances can be distinguished.
7
- */
8
-
9
- #ifndef LIBRATS_LOG_MACROS_H
10
- #define LIBRATS_LOG_MACROS_H
11
-
12
- #include "logger.h"
13
-
14
- #ifdef TESTING
15
- #define LOG_CLIENT_DEBUG(message) LOG_DEBUG("client", "[pointer: " << this << "] " << message)
16
- #define LOG_CLIENT_INFO(message) LOG_INFO("client", "[pointer: " << this << "] " << message)
17
- #define LOG_CLIENT_WARN(message) LOG_WARN("client", "[pointer: " << this << "] " << message)
18
- #define LOG_CLIENT_ERROR(message) LOG_ERROR("client", "[pointer: " << this << "] " << message)
19
-
20
- #define LOG_SERVER_DEBUG(message) LOG_DEBUG("server", "[pointer: " << this << "] " << message)
21
- #define LOG_SERVER_INFO(message) LOG_INFO("server", "[pointer: " << this << "] " << message)
22
- #define LOG_SERVER_WARN(message) LOG_WARN("server", "[pointer: " << this << "] " << message)
23
- #define LOG_SERVER_ERROR(message) LOG_ERROR("server", "[pointer: " << this << "] " << message)
24
- #else
25
- #define LOG_CLIENT_DEBUG(message) LOG_DEBUG("client", message)
26
- #define LOG_CLIENT_INFO(message) LOG_INFO("client", message)
27
- #define LOG_CLIENT_WARN(message) LOG_WARN("client", message)
28
- #define LOG_CLIENT_ERROR(message) LOG_ERROR("client", message)
29
-
30
- #define LOG_SERVER_DEBUG(message) LOG_DEBUG("server", message)
31
- #define LOG_SERVER_INFO(message) LOG_INFO("server", message)
32
- #define LOG_SERVER_WARN(message) LOG_WARN("server", message)
33
- #define LOG_SERVER_ERROR(message) LOG_ERROR("server", message)
34
- #endif
35
-
36
- #endif // LIBRATS_LOG_MACROS_H