librats 0.8.0 → 0.9.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 +9 -4
- package/lib/index.d.ts +9 -22
- package/native-src/CMakeLists.txt +122 -48
- package/native-src/cmake/ratsConfig.cmake.in +8 -0
- package/native-src/src/crypto/sha256.c +1 -1
- package/native-src/src/dht.cpp +297 -47
- package/native-src/src/dht.h +70 -6
- package/native-src/src/file_transfer.cpp +1185 -1578
- package/native-src/src/file_transfer.h +240 -521
- package/native-src/src/io_poller.cpp +7 -0
- package/native-src/src/krpc.cpp +161 -96
- package/native-src/src/krpc.h +18 -4
- package/native-src/src/librats.cpp +3 -0
- package/native-src/src/librats.h +61 -154
- package/native-src/src/librats_c.cpp +21 -38
- package/native-src/src/librats_discovery.cpp +107 -39
- package/native-src/src/librats_file_transfer.cpp +25 -103
- package/native-src/src/librats_ice.cpp +4 -0
- package/native-src/src/librats_statistic.cpp +10 -2
- package/native-src/src/socket.cpp +15 -3
- package/package.json +1 -1
- package/scripts/build-librats.js +3 -0
- package/scripts/prepare-package.js +10 -0
- package/src/librats_node.cpp +53 -64
package/README.md
CHANGED
|
@@ -117,6 +117,12 @@ client.onFileProgress((transferId, progressPercent, status) => {
|
|
|
117
117
|
console.log(`Transfer ${transferId}: ${progressPercent}% - ${status}`);
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
+
// Accept incoming transfer offers (transfers are push-only)
|
|
121
|
+
client.onFileRequest((peerId, transferId, filename) => {
|
|
122
|
+
console.log(`Incoming offer "${filename}" from ${peerId}`);
|
|
123
|
+
client.acceptFileTransfer(transferId, `./downloads/${filename}`);
|
|
124
|
+
});
|
|
125
|
+
|
|
120
126
|
client.start();
|
|
121
127
|
|
|
122
128
|
// Send a file to a peer
|
|
@@ -181,10 +187,8 @@ client.publishJsonToTopic('general-chat', JSON.stringify(message));
|
|
|
181
187
|
#### File Transfer
|
|
182
188
|
|
|
183
189
|
- `sendFile(peerId: string, filePath: string, remoteFilename?: string): string | null` - Send file
|
|
184
|
-
- `sendDirectory(peerId: string, dirPath: string, remoteDirName?: string
|
|
185
|
-
- `
|
|
186
|
-
- `requestDirectory(peerId: string, remoteDirPath: string, localDirPath: string, recursive?: boolean): string | null` - Request directory
|
|
187
|
-
- `acceptFileTransfer(transferId: string, localPath: string): boolean` - Accept file transfer
|
|
190
|
+
- `sendDirectory(peerId: string, dirPath: string, remoteDirName?: string): string | null` - Send directory (always recursive)
|
|
191
|
+
- `acceptFileTransfer(transferId: string, localPath: string): boolean` - Accept an incoming file/directory transfer offer
|
|
188
192
|
- `rejectFileTransfer(transferId: string, reason?: string): boolean` - Reject file transfer
|
|
189
193
|
- `cancelFileTransfer(transferId: string): boolean` - Cancel file transfer
|
|
190
194
|
- `pauseFileTransfer(transferId: string): boolean` - Pause file transfer
|
|
@@ -223,6 +227,7 @@ client.publishJsonToTopic('general-chat', JSON.stringify(message));
|
|
|
223
227
|
- `onJson(callback: (peerId: string, jsonStr: string) => void): void` - Set JSON message callback
|
|
224
228
|
- `onDisconnect(callback: (peerId: string) => void): void` - Set disconnect callback
|
|
225
229
|
- `onFileProgress(callback: (transferId: string, progressPercent: number, status: string) => void): void` - Set file progress callback
|
|
230
|
+
- `onFileRequest(callback: (peerId: string, transferId: string, filename: string) => void): void` - Set incoming transfer offer callback (respond with `acceptFileTransfer`/`rejectFileTransfer`)
|
|
226
231
|
|
|
227
232
|
### Utility Functions
|
|
228
233
|
|
package/lib/index.d.ts
CHANGED
|
@@ -225,33 +225,13 @@ export class RatsClient {
|
|
|
225
225
|
sendFile(peerId: string, filePath: string, remoteFilename?: string): string | null;
|
|
226
226
|
|
|
227
227
|
/**
|
|
228
|
-
* Send a directory to a peer
|
|
228
|
+
* Send a directory to a peer. Directory transfers are always recursive.
|
|
229
229
|
* @param peerId - ID of the peer to send to
|
|
230
230
|
* @param dirPath - Local path to the directory
|
|
231
231
|
* @param remoteDirName - Optional directory name on remote side
|
|
232
|
-
* @param recursive - Whether to send recursively (default: true)
|
|
233
232
|
* @returns Transfer ID, or null if failed
|
|
234
233
|
*/
|
|
235
|
-
sendDirectory(peerId: string, dirPath: string, remoteDirName?: string
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Request a file from a peer
|
|
239
|
-
* @param peerId - ID of the peer to request from
|
|
240
|
-
* @param remoteFilePath - Path to the file on remote side
|
|
241
|
-
* @param localPath - Local path where file should be saved
|
|
242
|
-
* @returns Transfer ID, or null if failed
|
|
243
|
-
*/
|
|
244
|
-
requestFile(peerId: string, remoteFilePath: string, localPath: string): string | null;
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Request a directory from a peer
|
|
248
|
-
* @param peerId - ID of the peer to request from
|
|
249
|
-
* @param remoteDirPath - Path to the directory on remote side
|
|
250
|
-
* @param localDirPath - Local path where directory should be saved
|
|
251
|
-
* @param recursive - Whether to request recursively (default: true)
|
|
252
|
-
* @returns Transfer ID, or null if failed
|
|
253
|
-
*/
|
|
254
|
-
requestDirectory(peerId: string, remoteDirPath: string, localDirPath: string, recursive?: boolean): string | null;
|
|
234
|
+
sendDirectory(peerId: string, dirPath: string, remoteDirName?: string): string | null;
|
|
255
235
|
|
|
256
236
|
/**
|
|
257
237
|
* Accept an incoming file transfer
|
|
@@ -668,6 +648,13 @@ export class RatsClient {
|
|
|
668
648
|
* @param callback - Function to call with transfer ID, progress percentage, and status
|
|
669
649
|
*/
|
|
670
650
|
onFileProgress(callback: (transferId: string, progressPercent: number, status: string) => void): void;
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Set callback for incoming file/directory transfer offers. Respond by calling
|
|
654
|
+
* acceptFileTransfer() or rejectFileTransfer() with the given transfer ID.
|
|
655
|
+
* @param callback - Function to call with peer ID, transfer ID, and the offered file/directory name
|
|
656
|
+
*/
|
|
657
|
+
onFileRequest(callback: (peerId: string, transferId: string, filename: string) => void): void;
|
|
671
658
|
}
|
|
672
659
|
|
|
673
660
|
// ============ Utility Functions ============
|
|
@@ -1,53 +1,63 @@
|
|
|
1
|
-
cmake_minimum_required(VERSION 3.
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
|
|
5
|
-
if(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
1
|
+
cmake_minimum_required(VERSION 3.14)
|
|
2
|
+
|
|
3
|
+
# Allow consumers (vcpkg/Conan/source tarballs) to bypass git lookup by
|
|
4
|
+
# passing -DRATS_VERSION_OVERRIDE=X.Y.Z on the configure line.
|
|
5
|
+
if(DEFINED RATS_VERSION_OVERRIDE AND RATS_VERSION_OVERRIDE MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$")
|
|
6
|
+
set(VERSION_MAJOR ${CMAKE_MATCH_1})
|
|
7
|
+
set(VERSION_MINOR ${CMAKE_MATCH_2})
|
|
8
|
+
set(VERSION_PATCH ${CMAKE_MATCH_3})
|
|
9
|
+
set(GIT_DESCRIBE "${RATS_VERSION_OVERRIDE}")
|
|
10
|
+
set(GIT_REVISION_COUNT 0)
|
|
11
|
+
else()
|
|
12
|
+
# Get version from git
|
|
13
|
+
find_package(Git QUIET)
|
|
14
|
+
if(GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
|
15
|
+
# Get the current git tag/commit
|
|
16
|
+
execute_process(
|
|
17
|
+
COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty
|
|
18
|
+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
19
|
+
OUTPUT_VARIABLE GIT_DESCRIBE
|
|
20
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
21
|
+
ERROR_QUIET
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
# Extract version from git tag (format: v1.2.3 or 1.2.3)
|
|
25
|
+
execute_process(
|
|
26
|
+
COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0
|
|
27
|
+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
28
|
+
OUTPUT_VARIABLE GIT_TAG
|
|
29
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
30
|
+
ERROR_QUIET
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
# Get commit count (revision number)
|
|
34
|
+
execute_process(
|
|
35
|
+
COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD
|
|
36
|
+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
37
|
+
OUTPUT_VARIABLE GIT_REVISION_COUNT
|
|
38
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
39
|
+
ERROR_QUIET
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
# Parse version components
|
|
43
|
+
if(GIT_TAG MATCHES "^v?([0-9]+)\\.([0-9]+)\\.([0-9]+)")
|
|
44
|
+
set(VERSION_MAJOR ${CMAKE_MATCH_1})
|
|
45
|
+
set(VERSION_MINOR ${CMAKE_MATCH_2})
|
|
46
|
+
set(VERSION_PATCH ${CMAKE_MATCH_3})
|
|
47
|
+
else()
|
|
48
|
+
# Fallback to default version
|
|
49
|
+
set(VERSION_MAJOR 1)
|
|
50
|
+
set(VERSION_MINOR 0)
|
|
51
|
+
set(VERSION_PATCH 0)
|
|
52
|
+
endif()
|
|
38
53
|
else()
|
|
39
|
-
# Fallback
|
|
54
|
+
# Fallback when git is not available (e.g. source tarball builds)
|
|
40
55
|
set(VERSION_MAJOR 1)
|
|
41
56
|
set(VERSION_MINOR 0)
|
|
42
57
|
set(VERSION_PATCH 0)
|
|
58
|
+
set(GIT_DESCRIBE "unknown")
|
|
59
|
+
set(GIT_REVISION_COUNT 0)
|
|
43
60
|
endif()
|
|
44
|
-
else()
|
|
45
|
-
# Fallback when git is not available
|
|
46
|
-
set(VERSION_MAJOR 1)
|
|
47
|
-
set(VERSION_MINOR 0)
|
|
48
|
-
set(VERSION_PATCH 0)
|
|
49
|
-
set(GIT_DESCRIBE "unknown")
|
|
50
|
-
set(GIT_REVISION_COUNT 0)
|
|
51
61
|
endif()
|
|
52
62
|
|
|
53
63
|
# Set build number to revision count (commit count)
|
|
@@ -279,9 +289,21 @@ endif()
|
|
|
279
289
|
# Enable Position Independent Code for static library (required for linking into shared objects)
|
|
280
290
|
set_target_properties(rats PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
|
281
291
|
|
|
282
|
-
# Include
|
|
283
|
-
|
|
284
|
-
|
|
292
|
+
# GNUInstallDirs supplies CMAKE_INSTALL_INCLUDEDIR / LIBDIR / BINDIR. Include
|
|
293
|
+
# it unconditionally so the INSTALL_INTERFACE generator expression below
|
|
294
|
+
# resolves correctly even when RATS_INSTALL is later disabled.
|
|
295
|
+
include(GNUInstallDirs)
|
|
296
|
+
|
|
297
|
+
# Include directories. INSTALL_INTERFACE entries are only consumed via the
|
|
298
|
+
# exported target, so they are safe to declare even when RATS_INSTALL is OFF.
|
|
299
|
+
target_include_directories(rats
|
|
300
|
+
PUBLIC
|
|
301
|
+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
|
|
302
|
+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/crypto>
|
|
303
|
+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>
|
|
304
|
+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/librats>
|
|
305
|
+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/librats/crypto>
|
|
306
|
+
)
|
|
285
307
|
|
|
286
308
|
# Find and link threading support
|
|
287
309
|
find_package(Threads REQUIRED)
|
|
@@ -513,4 +535,56 @@ endif()
|
|
|
513
535
|
# Examples (basic examples always built; BT examples require RATS_SEARCH_FEATURES)
|
|
514
536
|
if(RATS_BUILD_EXAMPLES)
|
|
515
537
|
add_subdirectory(examples)
|
|
538
|
+
endif()
|
|
539
|
+
|
|
540
|
+
# -----------------------------------------------------------------------------
|
|
541
|
+
# Install / export configuration (consumed by vcpkg, Conan, and find_package)
|
|
542
|
+
# -----------------------------------------------------------------------------
|
|
543
|
+
option(RATS_INSTALL "Generate install rules and package config" ON)
|
|
544
|
+
|
|
545
|
+
if(RATS_INSTALL)
|
|
546
|
+
include(CMakePackageConfigHelpers)
|
|
547
|
+
|
|
548
|
+
install(TARGETS rats
|
|
549
|
+
EXPORT ratsTargets
|
|
550
|
+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
551
|
+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
552
|
+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
553
|
+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/librats
|
|
554
|
+
)
|
|
555
|
+
|
|
556
|
+
# Headers form a tightly coupled graph (librats.h pulls in dht/krpc/bencode/
|
|
557
|
+
# bt_*/storage/io_poller/etc.), so install the whole header tree under
|
|
558
|
+
# include/librats/. .cpp / .c / .in files are excluded.
|
|
559
|
+
install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/
|
|
560
|
+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/librats
|
|
561
|
+
FILES_MATCHING
|
|
562
|
+
PATTERN "*.h"
|
|
563
|
+
PATTERN "*.hpp"
|
|
564
|
+
)
|
|
565
|
+
install(FILES ${PROJECT_BINARY_DIR}/src/version.h
|
|
566
|
+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/librats
|
|
567
|
+
)
|
|
568
|
+
|
|
569
|
+
install(EXPORT ratsTargets
|
|
570
|
+
FILE ratsTargets.cmake
|
|
571
|
+
NAMESPACE rats::
|
|
572
|
+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/rats
|
|
573
|
+
)
|
|
574
|
+
|
|
575
|
+
configure_package_config_file(
|
|
576
|
+
${PROJECT_SOURCE_DIR}/cmake/ratsConfig.cmake.in
|
|
577
|
+
${PROJECT_BINARY_DIR}/cmake/ratsConfig.cmake
|
|
578
|
+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/rats
|
|
579
|
+
)
|
|
580
|
+
write_basic_package_version_file(
|
|
581
|
+
${PROJECT_BINARY_DIR}/cmake/ratsConfigVersion.cmake
|
|
582
|
+
VERSION ${PROJECT_VERSION}
|
|
583
|
+
COMPATIBILITY SameMajorVersion
|
|
584
|
+
)
|
|
585
|
+
install(FILES
|
|
586
|
+
${PROJECT_BINARY_DIR}/cmake/ratsConfig.cmake
|
|
587
|
+
${PROJECT_BINARY_DIR}/cmake/ratsConfigVersion.cmake
|
|
588
|
+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/rats
|
|
589
|
+
)
|
|
516
590
|
endif()
|
|
@@ -28,7 +28,7 @@ void sha256_reset(sha256_context_t *context)
|
|
|
28
28
|
context->h[0] = 0x6a09e667;
|
|
29
29
|
context->h[1] = 0xbb67ae85;
|
|
30
30
|
context->h[2] = 0x3c6ef372;
|
|
31
|
-
context->h[3] = 0xa54ff53a
|
|
31
|
+
context->h[3] = 0xa54ff53a;
|
|
32
32
|
context->h[4] = 0x510e527f;
|
|
33
33
|
context->h[5] = 0x9b05688c;
|
|
34
34
|
context->h[6] = 0x1f83d9ab;
|