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.
- package/README.md +405 -405
- package/binding.gyp +96 -95
- package/lib/index.d.ts +522 -522
- package/lib/index.js +82 -82
- package/native-src/3rdparty/android/ifaddrs-android.c +600 -0
- package/native-src/3rdparty/android/ifaddrs-android.h +54 -0
- package/native-src/CMakeLists.txt +360 -0
- package/native-src/LICENSE +21 -0
- package/native-src/src/bencode.cpp +485 -0
- package/native-src/src/bencode.h +145 -0
- package/native-src/src/bittorrent.cpp +3682 -0
- package/native-src/src/bittorrent.h +731 -0
- package/native-src/src/dht.cpp +2342 -0
- package/native-src/src/dht.h +501 -0
- package/native-src/src/encrypted_socket.cpp +817 -0
- package/native-src/src/encrypted_socket.h +239 -0
- package/native-src/src/file_transfer.cpp +1808 -0
- package/native-src/src/file_transfer.h +567 -0
- package/native-src/src/fs.cpp +639 -0
- package/native-src/src/fs.h +108 -0
- package/native-src/src/gossipsub.cpp +1137 -0
- package/native-src/src/gossipsub.h +403 -0
- package/native-src/src/ice.cpp +1386 -0
- package/native-src/src/ice.h +328 -0
- package/native-src/src/json.hpp +25526 -0
- package/native-src/src/krpc.cpp +558 -0
- package/native-src/src/krpc.h +145 -0
- package/native-src/src/librats.cpp +2715 -0
- package/native-src/src/librats.h +1729 -0
- package/native-src/src/librats_bittorrent.cpp +167 -0
- package/native-src/src/librats_c.cpp +1317 -0
- package/native-src/src/librats_c.h +237 -0
- package/native-src/src/librats_encryption.cpp +123 -0
- package/native-src/src/librats_file_transfer.cpp +226 -0
- package/native-src/src/librats_gossipsub.cpp +293 -0
- package/native-src/src/librats_ice.cpp +515 -0
- package/native-src/src/librats_logging.cpp +158 -0
- package/native-src/src/librats_mdns.cpp +171 -0
- package/native-src/src/librats_nat.cpp +571 -0
- package/native-src/src/librats_persistence.cpp +815 -0
- package/native-src/src/logger.h +412 -0
- package/native-src/src/mdns.cpp +1178 -0
- package/native-src/src/mdns.h +253 -0
- package/native-src/src/network_utils.cpp +598 -0
- package/native-src/src/network_utils.h +162 -0
- package/native-src/src/noise.cpp +981 -0
- package/native-src/src/noise.h +227 -0
- package/native-src/src/os.cpp +371 -0
- package/native-src/src/os.h +40 -0
- package/native-src/src/rats_export.h +17 -0
- package/native-src/src/sha1.cpp +163 -0
- package/native-src/src/sha1.h +42 -0
- package/native-src/src/socket.cpp +1376 -0
- package/native-src/src/socket.h +309 -0
- package/native-src/src/stun.cpp +484 -0
- package/native-src/src/stun.h +349 -0
- package/native-src/src/threadmanager.cpp +105 -0
- package/native-src/src/threadmanager.h +53 -0
- package/native-src/src/tracker.cpp +1110 -0
- package/native-src/src/tracker.h +268 -0
- package/native-src/src/version.cpp +24 -0
- package/native-src/src/version.h.in +45 -0
- package/native-src/version.rc.in +31 -0
- package/package.json +62 -68
- package/scripts/build-librats.js +241 -194
- package/scripts/postinstall.js +52 -52
- package/scripts/prepare-package.js +187 -91
- package/scripts/verify-installation.js +119 -119
- package/src/librats_node.cpp +1174 -1174
|
@@ -1,91 +1,187 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Prepare package script
|
|
8
|
-
*
|
|
9
|
-
* This script runs before packing and publishing to ensure the package
|
|
10
|
-
* is ready for distribution. It
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
console.error('
|
|
52
|
-
console.error(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
console.error('\
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
console.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
console.log(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Prepare package script
|
|
8
|
+
*
|
|
9
|
+
* This script runs before packing and publishing to ensure the package
|
|
10
|
+
* is ready for distribution. It copies the native C++ source files into
|
|
11
|
+
* the nodejs package directory so they can be included in the npm package.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
console.log('Preparing package for distribution...');
|
|
15
|
+
|
|
16
|
+
const projectRoot = path.resolve(__dirname, '..', '..');
|
|
17
|
+
const nodejsRoot = path.resolve(__dirname, '..');
|
|
18
|
+
const nativeSrcDir = path.join(nodejsRoot, 'native-src');
|
|
19
|
+
|
|
20
|
+
// Helper function to copy a file
|
|
21
|
+
function copyFile(src, dest) {
|
|
22
|
+
const destDir = path.dirname(dest);
|
|
23
|
+
if (!fs.existsSync(destDir)) {
|
|
24
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
fs.copyFileSync(src, dest);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Helper function to copy a directory recursively
|
|
30
|
+
function copyDir(src, dest, filter = () => true) {
|
|
31
|
+
if (!fs.existsSync(dest)) {
|
|
32
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
36
|
+
for (const entry of entries) {
|
|
37
|
+
const srcPath = path.join(src, entry.name);
|
|
38
|
+
const destPath = path.join(dest, entry.name);
|
|
39
|
+
|
|
40
|
+
if (entry.isDirectory()) {
|
|
41
|
+
copyDir(srcPath, destPath, filter);
|
|
42
|
+
} else if (filter(entry.name)) {
|
|
43
|
+
copyFile(srcPath, destPath);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Check that we're in the project root with the source files
|
|
49
|
+
if (!fs.existsSync(path.join(projectRoot, 'CMakeLists.txt'))) {
|
|
50
|
+
console.error('\n❌ ERROR: Cannot find CMakeLists.txt in project root.');
|
|
51
|
+
console.error('This script must be run from within the librats repository.');
|
|
52
|
+
console.error(`Expected project root: ${projectRoot}`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!fs.existsSync(path.join(projectRoot, 'src'))) {
|
|
57
|
+
console.error('\n❌ ERROR: Cannot find src/ directory in project root.');
|
|
58
|
+
console.error('This script must be run from within the librats repository.');
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Clean up existing native-src directory
|
|
63
|
+
if (fs.existsSync(nativeSrcDir)) {
|
|
64
|
+
console.log('Cleaning existing native-src directory...');
|
|
65
|
+
fs.rmSync(nativeSrcDir, { recursive: true, force: true });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
console.log('\nCopying native source files to native-src/...');
|
|
69
|
+
|
|
70
|
+
// Create native-src directory
|
|
71
|
+
fs.mkdirSync(nativeSrcDir, { recursive: true });
|
|
72
|
+
|
|
73
|
+
// Copy CMakeLists.txt
|
|
74
|
+
console.log(' Copying CMakeLists.txt...');
|
|
75
|
+
copyFile(
|
|
76
|
+
path.join(projectRoot, 'CMakeLists.txt'),
|
|
77
|
+
path.join(nativeSrcDir, 'CMakeLists.txt')
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// Copy LICENSE
|
|
81
|
+
if (fs.existsSync(path.join(projectRoot, 'LICENSE'))) {
|
|
82
|
+
console.log(' Copying LICENSE...');
|
|
83
|
+
copyFile(
|
|
84
|
+
path.join(projectRoot, 'LICENSE'),
|
|
85
|
+
path.join(nativeSrcDir, 'LICENSE')
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Copy version.rc.in
|
|
90
|
+
if (fs.existsSync(path.join(projectRoot, 'version.rc.in'))) {
|
|
91
|
+
console.log(' Copying version.rc.in...');
|
|
92
|
+
copyFile(
|
|
93
|
+
path.join(projectRoot, 'version.rc.in'),
|
|
94
|
+
path.join(nativeSrcDir, 'version.rc.in')
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Copy src/ directory (only .cpp, .h, .hpp, .in files, excluding main.cpp)
|
|
99
|
+
console.log(' Copying src/ directory...');
|
|
100
|
+
const srcFilter = (name) => {
|
|
101
|
+
if (name === 'main.cpp') return false;
|
|
102
|
+
return name.endsWith('.cpp') || name.endsWith('.h') ||
|
|
103
|
+
name.endsWith('.hpp') || name.endsWith('.in');
|
|
104
|
+
};
|
|
105
|
+
copyDir(
|
|
106
|
+
path.join(projectRoot, 'src'),
|
|
107
|
+
path.join(nativeSrcDir, 'src'),
|
|
108
|
+
srcFilter
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
// Copy 3rdparty/ directory
|
|
112
|
+
if (fs.existsSync(path.join(projectRoot, '3rdparty'))) {
|
|
113
|
+
console.log(' Copying 3rdparty/ directory...');
|
|
114
|
+
copyDir(
|
|
115
|
+
path.join(projectRoot, '3rdparty'),
|
|
116
|
+
path.join(nativeSrcDir, '3rdparty')
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Count copied files
|
|
121
|
+
let cppCount = 0;
|
|
122
|
+
let hCount = 0;
|
|
123
|
+
const countFiles = (dir) => {
|
|
124
|
+
if (!fs.existsSync(dir)) return;
|
|
125
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
126
|
+
for (const entry of entries) {
|
|
127
|
+
const fullPath = path.join(dir, entry.name);
|
|
128
|
+
if (entry.isDirectory()) {
|
|
129
|
+
countFiles(fullPath);
|
|
130
|
+
} else if (entry.name.endsWith('.cpp')) {
|
|
131
|
+
cppCount++;
|
|
132
|
+
} else if (entry.name.endsWith('.h') || entry.name.endsWith('.hpp')) {
|
|
133
|
+
hCount++;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
countFiles(nativeSrcDir);
|
|
138
|
+
|
|
139
|
+
console.log(`\n✓ Copied ${cppCount} source files and ${hCount} header files`);
|
|
140
|
+
|
|
141
|
+
// Verify critical files in nodejs package
|
|
142
|
+
const criticalFiles = [
|
|
143
|
+
{ path: path.join(nodejsRoot, 'binding.gyp'), desc: 'Node.js binding configuration' },
|
|
144
|
+
{ path: path.join(nodejsRoot, 'lib', 'index.js'), desc: 'JavaScript wrapper' },
|
|
145
|
+
{ path: path.join(nodejsRoot, 'lib', 'index.d.ts'), desc: 'TypeScript definitions' },
|
|
146
|
+
{ path: path.join(nodejsRoot, 'src', 'librats_node.cpp'), desc: 'Node.js binding source' },
|
|
147
|
+
{ path: path.join(nodejsRoot, 'scripts', 'build-librats.js'), desc: 'Build script' },
|
|
148
|
+
{ path: path.join(nodejsRoot, 'scripts', 'postinstall.js'), desc: 'Post-install script' },
|
|
149
|
+
{ path: path.join(nativeSrcDir, 'CMakeLists.txt'), desc: 'CMake configuration (copied)' },
|
|
150
|
+
{ path: path.join(nativeSrcDir, 'src', 'librats.cpp'), desc: 'Librats main source (copied)' },
|
|
151
|
+
{ path: path.join(nativeSrcDir, 'src', 'librats.h'), desc: 'Librats main header (copied)' },
|
|
152
|
+
{ path: path.join(nativeSrcDir, 'src', 'librats_c.cpp'), desc: 'Librats C API (copied)' },
|
|
153
|
+
{ path: path.join(nativeSrcDir, 'src', 'librats_c.h'), desc: 'Librats C API header (copied)' },
|
|
154
|
+
];
|
|
155
|
+
|
|
156
|
+
let allFilesPresent = true;
|
|
157
|
+
let missingFiles = [];
|
|
158
|
+
|
|
159
|
+
console.log('\nVerifying required files:');
|
|
160
|
+
for (const file of criticalFiles) {
|
|
161
|
+
if (fs.existsSync(file.path)) {
|
|
162
|
+
console.log(` ✓ ${file.desc}`);
|
|
163
|
+
} else {
|
|
164
|
+
console.log(` ✗ ${file.desc} - MISSING`);
|
|
165
|
+
allFilesPresent = false;
|
|
166
|
+
missingFiles.push(file);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (!allFilesPresent) {
|
|
171
|
+
console.error('\n❌ ERROR: Some required files are missing!');
|
|
172
|
+
console.error('\nMissing files:');
|
|
173
|
+
missingFiles.forEach(file => {
|
|
174
|
+
console.error(` - ${file.path}`);
|
|
175
|
+
console.error(` (${file.desc})`);
|
|
176
|
+
});
|
|
177
|
+
console.error('\nThe package cannot be published without these files.');
|
|
178
|
+
process.exit(1);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
console.log('\n✅ Package is ready for distribution!\n');
|
|
182
|
+
console.log('The native-src/ directory now contains all C++ source files needed to build.');
|
|
183
|
+
console.log('\nWhen users install this package via npm:');
|
|
184
|
+
console.log(' 1. The preinstall script will build the librats C++ library');
|
|
185
|
+
console.log(' 2. The install script will build the Node.js native addon');
|
|
186
|
+
console.log(' 3. The postinstall script will verify the installation');
|
|
187
|
+
console.log('\nNo manual build steps are required by users!\n');
|
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Installation Verification Script
|
|
5
|
-
*
|
|
6
|
-
* Checks if librats was installed correctly and all components are working.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const fs = require('fs');
|
|
10
|
-
const path = require('path');
|
|
11
|
-
|
|
12
|
-
console.log('🔍 Verifying librats installation...\n');
|
|
13
|
-
|
|
14
|
-
let allChecksPassed = true;
|
|
15
|
-
|
|
16
|
-
// Check 1: Can we load the module?
|
|
17
|
-
console.log('1. Loading librats module...');
|
|
18
|
-
try {
|
|
19
|
-
const librats = require('../lib/index.js');
|
|
20
|
-
console.log(' ✅ Module loaded successfully\n');
|
|
21
|
-
|
|
22
|
-
// Check 2: Version info
|
|
23
|
-
console.log('2. Checking version info...');
|
|
24
|
-
try {
|
|
25
|
-
const versionString = librats.getVersionString();
|
|
26
|
-
const version = librats.getVersion();
|
|
27
|
-
console.log(` ✅ Version: ${versionString}`);
|
|
28
|
-
console.log(` ✅ Components: ${version.major}.${version.minor}.${version.patch}.${version.build}\n`);
|
|
29
|
-
} catch (err) {
|
|
30
|
-
console.log(' ❌ Failed to get version info:', err.message);
|
|
31
|
-
allChecksPassed = false;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Check 3: Constants
|
|
35
|
-
console.log('3. Checking constants...');
|
|
36
|
-
try {
|
|
37
|
-
if (typeof librats.ConnectionStrategy.DIRECT_ONLY === 'number') {
|
|
38
|
-
console.log(' ✅ ConnectionStrategy constants defined');
|
|
39
|
-
}
|
|
40
|
-
if (typeof librats.ErrorCodes.SUCCESS === 'number') {
|
|
41
|
-
console.log(' ✅ ErrorCodes constants defined\n');
|
|
42
|
-
}
|
|
43
|
-
} catch (err) {
|
|
44
|
-
console.log(' ❌ Constants check failed:', err.message);
|
|
45
|
-
allChecksPassed = false;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Check 4: Can we create a client?
|
|
49
|
-
console.log('4. Testing client creation...');
|
|
50
|
-
try {
|
|
51
|
-
const RatsClient = librats.RatsClient;
|
|
52
|
-
const testPort = 19999;
|
|
53
|
-
const client = new RatsClient(testPort);
|
|
54
|
-
console.log(' ✅ Client created successfully\n');
|
|
55
|
-
|
|
56
|
-
// Check 5: Can we start and stop?
|
|
57
|
-
console.log('5. Testing start/stop...');
|
|
58
|
-
try {
|
|
59
|
-
const started = client.start();
|
|
60
|
-
if (started) {
|
|
61
|
-
console.log(' ✅ Client started successfully');
|
|
62
|
-
|
|
63
|
-
const peerId = client.getOurPeerId();
|
|
64
|
-
if (peerId && typeof peerId === 'string') {
|
|
65
|
-
console.log(` ✅ Got peer ID: ${peerId}`);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const peerCount = client.getPeerCount();
|
|
69
|
-
console.log(` ✅ Peer count: ${peerCount}`);
|
|
70
|
-
|
|
71
|
-
client.stop();
|
|
72
|
-
console.log(' ✅ Client stopped successfully\n');
|
|
73
|
-
} else {
|
|
74
|
-
console.log(' ⚠️ Warning: Client failed to start (port may be in use)\n');
|
|
75
|
-
}
|
|
76
|
-
} catch (err) {
|
|
77
|
-
console.log(' ❌ Start/stop test failed:', err.message);
|
|
78
|
-
allChecksPassed = false;
|
|
79
|
-
}
|
|
80
|
-
} catch (err) {
|
|
81
|
-
console.log(' ❌ Client creation failed:', err.message);
|
|
82
|
-
allChecksPassed = false;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Check 6: TypeScript definitions
|
|
86
|
-
console.log('6. Checking TypeScript definitions...');
|
|
87
|
-
const tsDefsPath = path.join(__dirname, '..', 'lib', 'index.d.ts');
|
|
88
|
-
if (fs.existsSync(tsDefsPath)) {
|
|
89
|
-
console.log(' ✅ TypeScript definitions found\n');
|
|
90
|
-
} else {
|
|
91
|
-
console.log(' ⚠️ Warning: TypeScript definitions not found\n');
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
} catch (err) {
|
|
95
|
-
console.log(' ❌ Failed to load module:', err.message);
|
|
96
|
-
console.log('\nError details:');
|
|
97
|
-
console.log(err.stack);
|
|
98
|
-
allChecksPassed = false;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Summary
|
|
102
|
-
console.log('━'.repeat(60));
|
|
103
|
-
if (allChecksPassed) {
|
|
104
|
-
console.log('✅ All checks passed! Librats is installed correctly.\n');
|
|
105
|
-
console.log('You can now use librats in your project:');
|
|
106
|
-
console.log(" const { RatsClient } = require('librats');");
|
|
107
|
-
console.log(' const client = new RatsClient(8080);');
|
|
108
|
-
console.log(' client.start();\n');
|
|
109
|
-
process.exit(0);
|
|
110
|
-
} else {
|
|
111
|
-
console.log('❌ Some checks failed. Installation may be incomplete.\n');
|
|
112
|
-
console.log('Troubleshooting:');
|
|
113
|
-
console.log(' 1. Try rebuilding: npm rebuild librats');
|
|
114
|
-
console.log(' 2. Check build tools are installed (CMake, C++ compiler)');
|
|
115
|
-
console.log(' 3. Check the logs above for specific errors');
|
|
116
|
-
console.log(' 4. See: https://github.com/librats/librats/tree/main/nodejs\n');
|
|
117
|
-
process.exit(1);
|
|
118
|
-
}
|
|
119
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Installation Verification Script
|
|
5
|
+
*
|
|
6
|
+
* Checks if librats was installed correctly and all components are working.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
|
|
12
|
+
console.log('🔍 Verifying librats installation...\n');
|
|
13
|
+
|
|
14
|
+
let allChecksPassed = true;
|
|
15
|
+
|
|
16
|
+
// Check 1: Can we load the module?
|
|
17
|
+
console.log('1. Loading librats module...');
|
|
18
|
+
try {
|
|
19
|
+
const librats = require('../lib/index.js');
|
|
20
|
+
console.log(' ✅ Module loaded successfully\n');
|
|
21
|
+
|
|
22
|
+
// Check 2: Version info
|
|
23
|
+
console.log('2. Checking version info...');
|
|
24
|
+
try {
|
|
25
|
+
const versionString = librats.getVersionString();
|
|
26
|
+
const version = librats.getVersion();
|
|
27
|
+
console.log(` ✅ Version: ${versionString}`);
|
|
28
|
+
console.log(` ✅ Components: ${version.major}.${version.minor}.${version.patch}.${version.build}\n`);
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.log(' ❌ Failed to get version info:', err.message);
|
|
31
|
+
allChecksPassed = false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Check 3: Constants
|
|
35
|
+
console.log('3. Checking constants...');
|
|
36
|
+
try {
|
|
37
|
+
if (typeof librats.ConnectionStrategy.DIRECT_ONLY === 'number') {
|
|
38
|
+
console.log(' ✅ ConnectionStrategy constants defined');
|
|
39
|
+
}
|
|
40
|
+
if (typeof librats.ErrorCodes.SUCCESS === 'number') {
|
|
41
|
+
console.log(' ✅ ErrorCodes constants defined\n');
|
|
42
|
+
}
|
|
43
|
+
} catch (err) {
|
|
44
|
+
console.log(' ❌ Constants check failed:', err.message);
|
|
45
|
+
allChecksPassed = false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Check 4: Can we create a client?
|
|
49
|
+
console.log('4. Testing client creation...');
|
|
50
|
+
try {
|
|
51
|
+
const RatsClient = librats.RatsClient;
|
|
52
|
+
const testPort = 19999;
|
|
53
|
+
const client = new RatsClient(testPort);
|
|
54
|
+
console.log(' ✅ Client created successfully\n');
|
|
55
|
+
|
|
56
|
+
// Check 5: Can we start and stop?
|
|
57
|
+
console.log('5. Testing start/stop...');
|
|
58
|
+
try {
|
|
59
|
+
const started = client.start();
|
|
60
|
+
if (started) {
|
|
61
|
+
console.log(' ✅ Client started successfully');
|
|
62
|
+
|
|
63
|
+
const peerId = client.getOurPeerId();
|
|
64
|
+
if (peerId && typeof peerId === 'string') {
|
|
65
|
+
console.log(` ✅ Got peer ID: ${peerId}`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const peerCount = client.getPeerCount();
|
|
69
|
+
console.log(` ✅ Peer count: ${peerCount}`);
|
|
70
|
+
|
|
71
|
+
client.stop();
|
|
72
|
+
console.log(' ✅ Client stopped successfully\n');
|
|
73
|
+
} else {
|
|
74
|
+
console.log(' ⚠️ Warning: Client failed to start (port may be in use)\n');
|
|
75
|
+
}
|
|
76
|
+
} catch (err) {
|
|
77
|
+
console.log(' ❌ Start/stop test failed:', err.message);
|
|
78
|
+
allChecksPassed = false;
|
|
79
|
+
}
|
|
80
|
+
} catch (err) {
|
|
81
|
+
console.log(' ❌ Client creation failed:', err.message);
|
|
82
|
+
allChecksPassed = false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Check 6: TypeScript definitions
|
|
86
|
+
console.log('6. Checking TypeScript definitions...');
|
|
87
|
+
const tsDefsPath = path.join(__dirname, '..', 'lib', 'index.d.ts');
|
|
88
|
+
if (fs.existsSync(tsDefsPath)) {
|
|
89
|
+
console.log(' ✅ TypeScript definitions found\n');
|
|
90
|
+
} else {
|
|
91
|
+
console.log(' ⚠️ Warning: TypeScript definitions not found\n');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
} catch (err) {
|
|
95
|
+
console.log(' ❌ Failed to load module:', err.message);
|
|
96
|
+
console.log('\nError details:');
|
|
97
|
+
console.log(err.stack);
|
|
98
|
+
allChecksPassed = false;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Summary
|
|
102
|
+
console.log('━'.repeat(60));
|
|
103
|
+
if (allChecksPassed) {
|
|
104
|
+
console.log('✅ All checks passed! Librats is installed correctly.\n');
|
|
105
|
+
console.log('You can now use librats in your project:');
|
|
106
|
+
console.log(" const { RatsClient } = require('librats');");
|
|
107
|
+
console.log(' const client = new RatsClient(8080);');
|
|
108
|
+
console.log(' client.start();\n');
|
|
109
|
+
process.exit(0);
|
|
110
|
+
} else {
|
|
111
|
+
console.log('❌ Some checks failed. Installation may be incomplete.\n');
|
|
112
|
+
console.log('Troubleshooting:');
|
|
113
|
+
console.log(' 1. Try rebuilding: npm rebuild librats');
|
|
114
|
+
console.log(' 2. Check build tools are installed (CMake, C++ compiler)');
|
|
115
|
+
console.log(' 3. Check the logs above for specific errors');
|
|
116
|
+
console.log(' 4. See: https://github.com/librats/librats/tree/main/nodejs\n');
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
|