librats 0.5.0 → 0.5.2

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 (66) hide show
  1. package/README.md +1 -1
  2. package/binding.gyp +1 -0
  3. package/lib/index.d.ts +2 -1
  4. package/native-src/3rdparty/android/ifaddrs-android.c +600 -0
  5. package/native-src/3rdparty/android/ifaddrs-android.h +54 -0
  6. package/native-src/CMakeLists.txt +360 -0
  7. package/native-src/LICENSE +21 -0
  8. package/native-src/src/bencode.cpp +485 -0
  9. package/native-src/src/bencode.h +145 -0
  10. package/native-src/src/bittorrent.cpp +3682 -0
  11. package/native-src/src/bittorrent.h +731 -0
  12. package/native-src/src/dht.cpp +2460 -0
  13. package/native-src/src/dht.h +508 -0
  14. package/native-src/src/encrypted_socket.cpp +817 -0
  15. package/native-src/src/encrypted_socket.h +239 -0
  16. package/native-src/src/file_transfer.cpp +1808 -0
  17. package/native-src/src/file_transfer.h +567 -0
  18. package/native-src/src/fs.cpp +639 -0
  19. package/native-src/src/fs.h +108 -0
  20. package/native-src/src/gossipsub.cpp +1137 -0
  21. package/native-src/src/gossipsub.h +403 -0
  22. package/native-src/src/ice.cpp +1386 -0
  23. package/native-src/src/ice.h +328 -0
  24. package/native-src/src/json.hpp +25526 -0
  25. package/native-src/src/krpc.cpp +558 -0
  26. package/native-src/src/krpc.h +145 -0
  27. package/native-src/src/librats.cpp +2735 -0
  28. package/native-src/src/librats.h +1732 -0
  29. package/native-src/src/librats_bittorrent.cpp +167 -0
  30. package/native-src/src/librats_c.cpp +1333 -0
  31. package/native-src/src/librats_c.h +239 -0
  32. package/native-src/src/librats_encryption.cpp +123 -0
  33. package/native-src/src/librats_file_transfer.cpp +226 -0
  34. package/native-src/src/librats_gossipsub.cpp +293 -0
  35. package/native-src/src/librats_ice.cpp +515 -0
  36. package/native-src/src/librats_logging.cpp +158 -0
  37. package/native-src/src/librats_mdns.cpp +171 -0
  38. package/native-src/src/librats_nat.cpp +571 -0
  39. package/native-src/src/librats_persistence.cpp +815 -0
  40. package/native-src/src/logger.h +412 -0
  41. package/native-src/src/mdns.cpp +1178 -0
  42. package/native-src/src/mdns.h +253 -0
  43. package/native-src/src/network_utils.cpp +598 -0
  44. package/native-src/src/network_utils.h +162 -0
  45. package/native-src/src/noise.cpp +981 -0
  46. package/native-src/src/noise.h +227 -0
  47. package/native-src/src/os.cpp +371 -0
  48. package/native-src/src/os.h +40 -0
  49. package/native-src/src/rats_export.h +17 -0
  50. package/native-src/src/sha1.cpp +163 -0
  51. package/native-src/src/sha1.h +42 -0
  52. package/native-src/src/socket.cpp +1376 -0
  53. package/native-src/src/socket.h +309 -0
  54. package/native-src/src/stun.cpp +484 -0
  55. package/native-src/src/stun.h +349 -0
  56. package/native-src/src/threadmanager.cpp +105 -0
  57. package/native-src/src/threadmanager.h +53 -0
  58. package/native-src/src/tracker.cpp +1110 -0
  59. package/native-src/src/tracker.h +268 -0
  60. package/native-src/src/version.cpp +24 -0
  61. package/native-src/src/version.h.in +45 -0
  62. package/native-src/version.rc.in +31 -0
  63. package/package.json +2 -8
  64. package/scripts/build-librats.js +59 -12
  65. package/scripts/prepare-package.js +133 -37
  66. package/src/librats_node.cpp +46 -1
@@ -0,0 +1,167 @@
1
+ #include "librats.h"
2
+
3
+ #ifdef RATS_SEARCH_FEATURES
4
+
5
+ // Logging macros for BitTorrent client
6
+ #define LOG_CLIENT_DEBUG(message) LOG_DEBUG("client", message)
7
+ #define LOG_CLIENT_INFO(message) LOG_INFO("client", message)
8
+ #define LOG_CLIENT_WARN(message) LOG_WARN("client", message)
9
+ #define LOG_CLIENT_ERROR(message) LOG_ERROR("client", message)
10
+
11
+ namespace librats {
12
+
13
+ //=============================================================================
14
+ // BitTorrent API Implementation (requires RATS_SEARCH_FEATURES)
15
+ //=============================================================================
16
+
17
+ bool RatsClient::enable_bittorrent(int listen_port) {
18
+ if (bittorrent_client_) {
19
+ LOG_CLIENT_WARN("BitTorrent is already enabled");
20
+ return true; // Already enabled
21
+ }
22
+
23
+ LOG_CLIENT_INFO("Enabling BitTorrent on port " << listen_port);
24
+
25
+ bittorrent_client_ = std::make_unique<BitTorrentClient>();
26
+
27
+ if (!bittorrent_client_->start(listen_port)) {
28
+ LOG_CLIENT_ERROR("Failed to start BitTorrent client");
29
+ bittorrent_client_.reset();
30
+ return false;
31
+ }
32
+
33
+ // Integrate with DHT if available
34
+ if (dht_client_ && dht_client_->is_running()) {
35
+ bittorrent_client_->set_dht_client(dht_client_.get());
36
+ LOG_CLIENT_INFO("BitTorrent integrated with DHT for peer discovery");
37
+ }
38
+
39
+ LOG_CLIENT_INFO("BitTorrent enabled successfully");
40
+ return true;
41
+ }
42
+
43
+ void RatsClient::disable_bittorrent() {
44
+ if (!bittorrent_client_) {
45
+ return;
46
+ }
47
+
48
+ LOG_CLIENT_INFO("Disabling BitTorrent");
49
+ bittorrent_client_->stop();
50
+ bittorrent_client_.reset();
51
+ LOG_CLIENT_INFO("BitTorrent disabled");
52
+ }
53
+
54
+ bool RatsClient::is_bittorrent_enabled() const {
55
+ return bittorrent_client_ && bittorrent_client_->is_running();
56
+ }
57
+
58
+ std::shared_ptr<TorrentDownload> RatsClient::add_torrent(const std::string& torrent_file,
59
+ const std::string& download_path) {
60
+ if (!is_bittorrent_enabled()) {
61
+ LOG_CLIENT_ERROR("BitTorrent is not enabled. Call enable_bittorrent() first.");
62
+ return nullptr;
63
+ }
64
+
65
+ return bittorrent_client_->add_torrent(torrent_file, download_path);
66
+ }
67
+
68
+ std::shared_ptr<TorrentDownload> RatsClient::add_torrent(const TorrentInfo& torrent_info,
69
+ const std::string& download_path) {
70
+ if (!is_bittorrent_enabled()) {
71
+ LOG_CLIENT_ERROR("BitTorrent is not enabled. Call enable_bittorrent() first.");
72
+ return nullptr;
73
+ }
74
+
75
+ return bittorrent_client_->add_torrent(torrent_info, download_path);
76
+ }
77
+
78
+ std::shared_ptr<TorrentDownload> RatsClient::add_torrent_by_hash(const InfoHash& info_hash,
79
+ const std::string& download_path) {
80
+ if (!is_bittorrent_enabled()) {
81
+ LOG_CLIENT_ERROR("BitTorrent is not enabled. Call enable_bittorrent() first.");
82
+ return nullptr;
83
+ }
84
+
85
+ return bittorrent_client_->add_torrent_by_hash(info_hash, download_path);
86
+ }
87
+
88
+ std::shared_ptr<TorrentDownload> RatsClient::add_torrent_by_hash(const std::string& info_hash_hex,
89
+ const std::string& download_path) {
90
+ if (!is_bittorrent_enabled()) {
91
+ LOG_CLIENT_ERROR("BitTorrent is not enabled. Call enable_bittorrent() first.");
92
+ return nullptr;
93
+ }
94
+
95
+ return bittorrent_client_->add_torrent_by_hash(info_hash_hex, download_path);
96
+ }
97
+
98
+ bool RatsClient::remove_torrent(const InfoHash& info_hash) {
99
+ if (!is_bittorrent_enabled()) {
100
+ return false;
101
+ }
102
+
103
+ return bittorrent_client_->remove_torrent(info_hash);
104
+ }
105
+
106
+ std::shared_ptr<TorrentDownload> RatsClient::get_torrent(const InfoHash& info_hash) {
107
+ if (!is_bittorrent_enabled()) {
108
+ return nullptr;
109
+ }
110
+
111
+ return bittorrent_client_->get_torrent(info_hash);
112
+ }
113
+
114
+ std::vector<std::shared_ptr<TorrentDownload>> RatsClient::get_all_torrents() {
115
+ if (!is_bittorrent_enabled()) {
116
+ return {};
117
+ }
118
+
119
+ return bittorrent_client_->get_all_torrents();
120
+ }
121
+
122
+ size_t RatsClient::get_active_torrents_count() const {
123
+ if (!is_bittorrent_enabled()) {
124
+ return 0;
125
+ }
126
+
127
+ return bittorrent_client_->get_active_torrents_count();
128
+ }
129
+
130
+ std::pair<uint64_t, uint64_t> RatsClient::get_bittorrent_stats() const {
131
+ if (!is_bittorrent_enabled()) {
132
+ return {0, 0};
133
+ }
134
+
135
+ return {bittorrent_client_->get_total_downloaded(),
136
+ bittorrent_client_->get_total_uploaded()};
137
+ }
138
+
139
+ void RatsClient::get_torrent_metadata(const InfoHash& info_hash,
140
+ std::function<void(const TorrentInfo&, bool, const std::string&)> callback) {
141
+ if (!is_bittorrent_enabled()) {
142
+ LOG_CLIENT_ERROR("BitTorrent is not enabled. Call enable_bittorrent() first.");
143
+ if (callback) {
144
+ callback(TorrentInfo(), false, "BitTorrent is not enabled");
145
+ }
146
+ return;
147
+ }
148
+
149
+ bittorrent_client_->get_torrent_metadata_by_hash(info_hash, callback);
150
+ }
151
+
152
+ void RatsClient::get_torrent_metadata(const std::string& info_hash_hex,
153
+ std::function<void(const TorrentInfo&, bool, const std::string&)> callback) {
154
+ if (!is_bittorrent_enabled()) {
155
+ LOG_CLIENT_ERROR("BitTorrent is not enabled. Call enable_bittorrent() first.");
156
+ if (callback) {
157
+ callback(TorrentInfo(), false, "BitTorrent is not enabled");
158
+ }
159
+ return;
160
+ }
161
+
162
+ bittorrent_client_->get_torrent_metadata_by_hash(info_hash_hex, callback);
163
+ }
164
+
165
+ }
166
+
167
+ #endif // RATS_SEARCH_FEATURES