librats 0.3.1 → 0.5.1

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 (69) hide show
  1. package/README.md +405 -405
  2. package/binding.gyp +96 -95
  3. package/lib/index.d.ts +522 -522
  4. package/lib/index.js +82 -82
  5. package/native-src/3rdparty/android/ifaddrs-android.c +600 -0
  6. package/native-src/3rdparty/android/ifaddrs-android.h +54 -0
  7. package/native-src/CMakeLists.txt +360 -0
  8. package/native-src/LICENSE +21 -0
  9. package/native-src/src/bencode.cpp +485 -0
  10. package/native-src/src/bencode.h +145 -0
  11. package/native-src/src/bittorrent.cpp +3682 -0
  12. package/native-src/src/bittorrent.h +731 -0
  13. package/native-src/src/dht.cpp +2342 -0
  14. package/native-src/src/dht.h +501 -0
  15. package/native-src/src/encrypted_socket.cpp +817 -0
  16. package/native-src/src/encrypted_socket.h +239 -0
  17. package/native-src/src/file_transfer.cpp +1808 -0
  18. package/native-src/src/file_transfer.h +567 -0
  19. package/native-src/src/fs.cpp +639 -0
  20. package/native-src/src/fs.h +108 -0
  21. package/native-src/src/gossipsub.cpp +1137 -0
  22. package/native-src/src/gossipsub.h +403 -0
  23. package/native-src/src/ice.cpp +1386 -0
  24. package/native-src/src/ice.h +328 -0
  25. package/native-src/src/json.hpp +25526 -0
  26. package/native-src/src/krpc.cpp +558 -0
  27. package/native-src/src/krpc.h +145 -0
  28. package/native-src/src/librats.cpp +2715 -0
  29. package/native-src/src/librats.h +1729 -0
  30. package/native-src/src/librats_bittorrent.cpp +167 -0
  31. package/native-src/src/librats_c.cpp +1317 -0
  32. package/native-src/src/librats_c.h +237 -0
  33. package/native-src/src/librats_encryption.cpp +123 -0
  34. package/native-src/src/librats_file_transfer.cpp +226 -0
  35. package/native-src/src/librats_gossipsub.cpp +293 -0
  36. package/native-src/src/librats_ice.cpp +515 -0
  37. package/native-src/src/librats_logging.cpp +158 -0
  38. package/native-src/src/librats_mdns.cpp +171 -0
  39. package/native-src/src/librats_nat.cpp +571 -0
  40. package/native-src/src/librats_persistence.cpp +815 -0
  41. package/native-src/src/logger.h +412 -0
  42. package/native-src/src/mdns.cpp +1178 -0
  43. package/native-src/src/mdns.h +253 -0
  44. package/native-src/src/network_utils.cpp +598 -0
  45. package/native-src/src/network_utils.h +162 -0
  46. package/native-src/src/noise.cpp +981 -0
  47. package/native-src/src/noise.h +227 -0
  48. package/native-src/src/os.cpp +371 -0
  49. package/native-src/src/os.h +40 -0
  50. package/native-src/src/rats_export.h +17 -0
  51. package/native-src/src/sha1.cpp +163 -0
  52. package/native-src/src/sha1.h +42 -0
  53. package/native-src/src/socket.cpp +1376 -0
  54. package/native-src/src/socket.h +309 -0
  55. package/native-src/src/stun.cpp +484 -0
  56. package/native-src/src/stun.h +349 -0
  57. package/native-src/src/threadmanager.cpp +105 -0
  58. package/native-src/src/threadmanager.h +53 -0
  59. package/native-src/src/tracker.cpp +1110 -0
  60. package/native-src/src/tracker.h +268 -0
  61. package/native-src/src/version.cpp +24 -0
  62. package/native-src/src/version.h.in +45 -0
  63. package/native-src/version.rc.in +31 -0
  64. package/package.json +62 -68
  65. package/scripts/build-librats.js +241 -194
  66. package/scripts/postinstall.js +52 -52
  67. package/scripts/prepare-package.js +187 -91
  68. package/scripts/verify-installation.js +119 -119
  69. package/src/librats_node.cpp +1174 -1174
@@ -0,0 +1,108 @@
1
+ #pragma once
2
+
3
+ #include <string>
4
+ #include <vector>
5
+ #include <cstdint>
6
+ #include <cstdio>
7
+ #include "rats_export.h"
8
+
9
+ namespace librats {
10
+
11
+ // File/Directory existence check
12
+ bool file_or_directory_exists(const char* path);
13
+ RATS_API bool directory_exists(const char* path);
14
+ bool file_exists(const char* path);
15
+
16
+ // File creation and writing
17
+ bool create_file(const char* path, const char* content);
18
+ bool create_file_binary(const char* path, const void* data, size_t size);
19
+ bool append_to_file(const char* path, const char* content);
20
+
21
+ // File reading
22
+ char* read_file_text(const char* path, size_t* size_out = nullptr);
23
+ void* read_file_binary(const char* path, size_t* size_out);
24
+
25
+ // Directory operations
26
+ bool create_directory(const char* path);
27
+ RATS_API bool create_directories(const char* path); // Create parent directories if needed
28
+
29
+ // File information
30
+ int64_t get_file_size(const char* path);
31
+ bool is_file(const char* path);
32
+ bool is_directory(const char* path);
33
+
34
+ // File operations
35
+ bool delete_file(const char* path);
36
+ bool delete_directory(const char* path);
37
+ bool copy_file(const char* src_path, const char* dest_path);
38
+ bool move_file(const char* src_path, const char* dest_path);
39
+
40
+ // File metadata operations
41
+ uint64_t get_file_modified_time(const char* path);
42
+ std::string get_file_extension(const char* path);
43
+ std::string get_filename_from_path(const char* path);
44
+ std::string get_parent_directory(const char* path);
45
+
46
+ // File chunk operations
47
+ bool write_file_chunk(const char* path, uint64_t offset, const void* data, size_t size);
48
+ bool read_file_chunk(const char* path, uint64_t offset, void* buffer, size_t size);
49
+
50
+ // Advanced file operations
51
+ bool create_file_with_size(const char* path, uint64_t size); // Pre-allocate file space
52
+ bool rename_file(const char* old_path, const char* new_path);
53
+
54
+ // Directory listing
55
+ struct DirectoryEntry {
56
+ std::string name;
57
+ std::string path;
58
+ bool is_directory;
59
+ uint64_t size;
60
+ uint64_t modified_time;
61
+ };
62
+ bool list_directory(const char* path, std::vector<DirectoryEntry>& entries);
63
+
64
+ // Path utilities
65
+ std::string combine_paths(const std::string& base, const std::string& relative);
66
+ bool validate_path(const char* path, bool check_write_access = false);
67
+
68
+ // Utility functions
69
+ void free_file_buffer(void* buffer); // Free memory allocated by read functions
70
+ bool get_current_directory(char* buffer, size_t buffer_size);
71
+ bool set_current_directory(const char* path);
72
+
73
+ // C++ convenience wrappers
74
+ inline bool file_or_directory_exists(const std::string& path) { return file_or_directory_exists(path.c_str()); }
75
+ inline bool file_exists(const std::string& path) { return file_exists(path.c_str()); }
76
+ inline bool directory_exists(const std::string& path) { return directory_exists(path.c_str()); }
77
+ inline bool create_file(const std::string& path, const std::string& content) {
78
+ return create_file(path.c_str(), content.c_str());
79
+ }
80
+ inline std::string read_file_text_cpp(const std::string& path) {
81
+ size_t size;
82
+ char* content = read_file_text(path.c_str(), &size);
83
+ if (!content) return "";
84
+ std::string result(content, size);
85
+ free_file_buffer(content);
86
+ return result;
87
+ }
88
+
89
+ // Additional C++ wrappers for new functions
90
+ inline uint64_t get_file_modified_time(const std::string& path) { return get_file_modified_time(path.c_str()); }
91
+ inline std::string get_file_extension(const std::string& path) { return get_file_extension(path.c_str()); }
92
+ inline std::string get_filename_from_path(const std::string& path) { return get_filename_from_path(path.c_str()); }
93
+ inline std::string get_parent_directory(const std::string& path) { return get_parent_directory(path.c_str()); }
94
+ inline bool write_file_chunk(const std::string& path, uint64_t offset, const void* data, size_t size) {
95
+ return write_file_chunk(path.c_str(), offset, data, size);
96
+ }
97
+ inline bool read_file_chunk(const std::string& path, uint64_t offset, void* buffer, size_t size) {
98
+ return read_file_chunk(path.c_str(), offset, buffer, size);
99
+ }
100
+ inline bool create_file_with_size(const std::string& path, uint64_t size) { return create_file_with_size(path.c_str(), size); }
101
+ inline bool rename_file(const std::string& old_path, const std::string& new_path) {
102
+ return rename_file(old_path.c_str(), new_path.c_str());
103
+ }
104
+ inline bool validate_path(const std::string& path, bool check_write_access = false) {
105
+ return validate_path(path.c_str(), check_write_access);
106
+ }
107
+
108
+ } // namespace librats