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
package/lib/index.js CHANGED
@@ -1,82 +1,82 @@
1
- /**
2
- * LibRats Node.js Bindings
3
- *
4
- * High-performance peer-to-peer networking library with support for DHT, GossipSub,
5
- * file transfer, NAT traversal, and more.
6
- */
7
-
8
- const path = require('path');
9
- const fs = require('fs');
10
-
11
- // Try to load the native addon from the build directory
12
- let addon;
13
- let addonPath;
14
-
15
- // Possible locations for the built addon
16
- const possiblePaths = [
17
- // Standard node-gyp build location
18
- path.join(__dirname, '..', 'build', 'Release', 'librats.node'),
19
- path.join(__dirname, '..', 'build', 'Debug', 'librats.node'),
20
- // Alternative build locations
21
- path.join(__dirname, '..', 'build', 'librats.node'),
22
- ];
23
-
24
- // Try each path
25
- for (const tryPath of possiblePaths) {
26
- try {
27
- if (fs.existsSync(tryPath)) {
28
- addon = require(tryPath);
29
- addonPath = tryPath;
30
- break;
31
- }
32
- } catch (err) {
33
- // Continue to next path
34
- }
35
- }
36
-
37
- if (!addon) {
38
- throw new Error(
39
- 'Could not load librats native addon. ' +
40
- 'Make sure the package is installed correctly and the native library is built. ' +
41
- 'Try running: npm rebuild librats'
42
- );
43
- }
44
-
45
- // Export all native bindings
46
- module.exports = {
47
- // Main class
48
- RatsClient: addon.RatsClient,
49
-
50
- // Version functions
51
- getVersionString: addon.getVersionString,
52
- getVersion: addon.getVersion,
53
- getGitDescribe: addon.getGitDescribe,
54
- getAbi: addon.getAbi,
55
-
56
- // Constants
57
- ConnectionStrategy: {
58
- DIRECT_ONLY: 0,
59
- STUN_ASSISTED: 1,
60
- ICE_FULL: 2,
61
- TURN_RELAY: 3,
62
- AUTO_ADAPTIVE: 4
63
- },
64
-
65
- ErrorCodes: {
66
- SUCCESS: 0,
67
- INVALID_HANDLE: -1,
68
- INVALID_PARAMETER: -2,
69
- NOT_RUNNING: -3,
70
- OPERATION_FAILED: -4,
71
- PEER_NOT_FOUND: -5,
72
- MEMORY_ALLOCATION: -6,
73
- JSON_PARSE: -7
74
- }
75
- };
76
-
77
- // Log successful load for debugging
78
- if (process.env.LIBRATS_DEBUG) {
79
- console.log(`[librats] Loaded native addon from: ${addonPath}`);
80
- console.log(`[librats] Version: ${addon.getVersionString()}`);
81
- }
82
-
1
+ /**
2
+ * LibRats Node.js Bindings
3
+ *
4
+ * High-performance peer-to-peer networking library with support for DHT, GossipSub,
5
+ * file transfer, NAT traversal, and more.
6
+ */
7
+
8
+ const path = require('path');
9
+ const fs = require('fs');
10
+
11
+ // Try to load the native addon from the build directory
12
+ let addon;
13
+ let addonPath;
14
+
15
+ // Possible locations for the built addon
16
+ const possiblePaths = [
17
+ // Standard node-gyp build location
18
+ path.join(__dirname, '..', 'build', 'Release', 'librats.node'),
19
+ path.join(__dirname, '..', 'build', 'Debug', 'librats.node'),
20
+ // Alternative build locations
21
+ path.join(__dirname, '..', 'build', 'librats.node'),
22
+ ];
23
+
24
+ // Try each path
25
+ for (const tryPath of possiblePaths) {
26
+ try {
27
+ if (fs.existsSync(tryPath)) {
28
+ addon = require(tryPath);
29
+ addonPath = tryPath;
30
+ break;
31
+ }
32
+ } catch (err) {
33
+ // Continue to next path
34
+ }
35
+ }
36
+
37
+ if (!addon) {
38
+ throw new Error(
39
+ 'Could not load librats native addon. ' +
40
+ 'Make sure the package is installed correctly and the native library is built. ' +
41
+ 'Try running: npm rebuild librats'
42
+ );
43
+ }
44
+
45
+ // Export all native bindings
46
+ module.exports = {
47
+ // Main class
48
+ RatsClient: addon.RatsClient,
49
+
50
+ // Version functions
51
+ getVersionString: addon.getVersionString,
52
+ getVersion: addon.getVersion,
53
+ getGitDescribe: addon.getGitDescribe,
54
+ getAbi: addon.getAbi,
55
+
56
+ // Constants
57
+ ConnectionStrategy: {
58
+ DIRECT_ONLY: 0,
59
+ STUN_ASSISTED: 1,
60
+ ICE_FULL: 2,
61
+ TURN_RELAY: 3,
62
+ AUTO_ADAPTIVE: 4
63
+ },
64
+
65
+ ErrorCodes: {
66
+ SUCCESS: 0,
67
+ INVALID_HANDLE: -1,
68
+ INVALID_PARAMETER: -2,
69
+ NOT_RUNNING: -3,
70
+ OPERATION_FAILED: -4,
71
+ PEER_NOT_FOUND: -5,
72
+ MEMORY_ALLOCATION: -6,
73
+ JSON_PARSE: -7
74
+ }
75
+ };
76
+
77
+ // Log successful load for debugging
78
+ if (process.env.LIBRATS_DEBUG) {
79
+ console.log(`[librats] Loaded native addon from: ${addonPath}`);
80
+ console.log(`[librats] Version: ${addon.getVersionString()}`);
81
+ }
82
+