librats 0.8.0 → 0.9.0

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 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, recursive?: boolean): string | null` - Send directory
185
- - `requestFile(peerId: string, remoteFilePath: string, localPath: string): string | null` - Request file
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, recursive?: boolean): string | null;
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.10)
2
-
3
- # Get version from git
4
- find_package(Git QUIET)
5
- if(GIT_FOUND)
6
- # Get the current git tag/commit
7
- execute_process(
8
- COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty
9
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
10
- OUTPUT_VARIABLE GIT_DESCRIBE
11
- OUTPUT_STRIP_TRAILING_WHITESPACE
12
- ERROR_QUIET
13
- )
14
-
15
- # Extract version from git tag (format: v1.2.3 or 1.2.3)
16
- execute_process(
17
- COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0
18
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
19
- OUTPUT_VARIABLE GIT_TAG
20
- OUTPUT_STRIP_TRAILING_WHITESPACE
21
- ERROR_QUIET
22
- )
23
-
24
- # Get commit count (revision number)
25
- execute_process(
26
- COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD
27
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
28
- OUTPUT_VARIABLE GIT_REVISION_COUNT
29
- OUTPUT_STRIP_TRAILING_WHITESPACE
30
- ERROR_QUIET
31
- )
32
-
33
- # Parse version components
34
- if(GIT_TAG MATCHES "^v?([0-9]+)\\.([0-9]+)\\.([0-9]+)")
35
- set(VERSION_MAJOR ${CMAKE_MATCH_1})
36
- set(VERSION_MINOR ${CMAKE_MATCH_2})
37
- set(VERSION_PATCH ${CMAKE_MATCH_3})
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 to default version
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 directories
283
- target_include_directories(rats PUBLIC ${PROJECT_BINARY_DIR}/src src)
284
- target_include_directories(rats PUBLIC ${PROJECT_SOURCE_DIR}/src/crypto)
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()
@@ -0,0 +1,8 @@
1
+ @PACKAGE_INIT@
2
+
3
+ include(CMakeFindDependencyMacro)
4
+ find_dependency(Threads)
5
+
6
+ include("${CMAKE_CURRENT_LIST_DIR}/ratsTargets.cmake")
7
+
8
+ check_required_components(rats)
@@ -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;