librats 1.0.2 → 2.1.4
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 +137 -332
- package/binding.gyp +16 -3
- package/lib/index.d.ts +271 -696
- package/lib/index.js +383 -44
- package/native-src/3rdparty/android/ifaddrs-android.c +1 -0
- package/native-src/3rdparty/android/ifaddrs-android.h +1 -0
- package/native-src/CMakeLists.txt +396 -179
- package/native-src/LICENSE +1 -1
- package/native-src/src/librats/bindings/rats.cpp +731 -0
- package/native-src/src/librats/bindings/rats.h +352 -0
- package/native-src/src/librats/bittorrent/bencode.cpp +437 -0
- package/native-src/src/librats/bittorrent/bencode.h +176 -0
- package/native-src/src/librats/bittorrent/bitfield.cpp +97 -0
- package/native-src/src/librats/bittorrent/bitfield.h +76 -0
- package/native-src/src/librats/bittorrent/byte_io.h +58 -0
- package/native-src/src/librats/bittorrent/choker.cpp +25 -0
- package/native-src/src/librats/bittorrent/choker.h +46 -0
- package/native-src/src/librats/bittorrent/client.cpp +413 -0
- package/native-src/src/librats/bittorrent/client.h +227 -0
- package/native-src/src/librats/bittorrent/disk_io.cpp +209 -0
- package/native-src/src/librats/bittorrent/disk_io.h +150 -0
- package/native-src/src/librats/bittorrent/extensions.cpp +191 -0
- package/native-src/src/librats/bittorrent/extensions.h +94 -0
- package/native-src/src/librats/bittorrent/file_storage.cpp +77 -0
- package/native-src/src/librats/bittorrent/file_storage.h +79 -0
- package/native-src/src/librats/bittorrent/log.h +42 -0
- package/native-src/src/librats/bittorrent/magnet_uri.cpp +98 -0
- package/native-src/src/librats/bittorrent/magnet_uri.h +35 -0
- package/native-src/src/librats/bittorrent/peer_connection.cpp +502 -0
- package/native-src/src/librats/bittorrent/peer_connection.h +194 -0
- package/native-src/src/librats/bittorrent/peer_list.cpp +68 -0
- package/native-src/src/librats/bittorrent/peer_list.h +75 -0
- package/native-src/src/librats/bittorrent/piece_picker.cpp +352 -0
- package/native-src/src/librats/bittorrent/piece_picker.h +201 -0
- package/native-src/src/librats/bittorrent/reactor.cpp +97 -0
- package/native-src/src/librats/bittorrent/reactor.h +89 -0
- package/native-src/src/librats/bittorrent/resume_data.cpp +72 -0
- package/native-src/src/librats/bittorrent/resume_data.h +41 -0
- package/native-src/src/librats/bittorrent/store_buffer.cpp +48 -0
- package/native-src/src/librats/bittorrent/store_buffer.h +47 -0
- package/native-src/src/librats/bittorrent/torrent.cpp +870 -0
- package/native-src/src/librats/bittorrent/torrent.h +260 -0
- package/native-src/src/librats/bittorrent/torrent_creator.cpp +129 -0
- package/native-src/src/librats/bittorrent/torrent_creator.h +58 -0
- package/native-src/src/librats/bittorrent/torrent_info.cpp +314 -0
- package/native-src/src/librats/bittorrent/torrent_info.h +118 -0
- package/native-src/src/librats/bittorrent/tracker.cpp +374 -0
- package/native-src/src/librats/bittorrent/tracker.h +108 -0
- package/native-src/src/librats/bittorrent/types.cpp +206 -0
- package/native-src/src/librats/bittorrent/types.h +86 -0
- package/native-src/src/librats/core/address.cpp +35 -0
- package/native-src/src/librats/core/address.h +78 -0
- package/native-src/src/librats/core/bytes.h +69 -0
- package/native-src/src/librats/core/chained_send_buffer.cpp +172 -0
- package/native-src/src/librats/core/chained_send_buffer.h +183 -0
- package/native-src/src/librats/core/endpoint_parse.cpp +41 -0
- package/native-src/src/librats/core/endpoint_parse.h +31 -0
- package/native-src/src/librats/core/event_bus.h +70 -0
- package/native-src/src/librats/core/host_endpoint.h +56 -0
- package/native-src/src/{io_poller.cpp → librats/core/io_poller.cpp} +520 -65
- package/native-src/src/{io_poller.h → librats/core/io_poller.h} +12 -6
- package/native-src/src/librats/core/ip_address.cpp +120 -0
- package/native-src/src/librats/core/ip_address.h +109 -0
- package/native-src/src/librats/core/mpsc_queue.h +47 -0
- package/native-src/src/librats/core/notifier.h +74 -0
- package/native-src/src/librats/core/receive_buffer.cpp +219 -0
- package/native-src/src/librats/core/receive_buffer.h +171 -0
- package/native-src/src/librats/core/service_registry.h +58 -0
- package/native-src/src/{socket.cpp → librats/core/socket.cpp} +625 -118
- package/native-src/src/librats/core/socket.h +496 -0
- package/native-src/src/librats/core/timer_queue.h +105 -0
- package/native-src/src/librats/core/types.cpp +42 -0
- package/native-src/src/librats/core/types.h +93 -0
- package/native-src/src/librats/core/wakeup_pipe.h +83 -0
- package/native-src/src/{crypto → librats/crypto}/blake2_endian.h +21 -23
- package/native-src/src/{crypto → librats/crypto}/blake2b.c +34 -33
- package/native-src/src/{crypto → librats/crypto}/blake2b.h +7 -6
- package/native-src/src/{crypto → librats/crypto}/blake2s.c +55 -54
- package/native-src/src/{crypto → librats/crypto}/blake2s.h +13 -12
- package/native-src/src/{crypto → librats/crypto}/chacha.c +22 -21
- package/native-src/src/{crypto → librats/crypto}/chacha.h +14 -13
- package/native-src/src/{crypto → librats/crypto}/chachapoly.c +56 -56
- package/native-src/src/{crypto → librats/crypto}/chachapoly.h +24 -17
- package/native-src/src/{crc32.cpp → librats/crypto/crc32.cpp} +1 -1
- package/native-src/src/{crc32.h → librats/crypto/crc32.h} +3 -1
- package/native-src/src/{crypto → librats/crypto}/curve25519.c +6 -4
- package/native-src/src/{crypto → librats/crypto}/curve25519.h +6 -3
- package/native-src/src/librats/crypto/hkdf.c +266 -0
- package/native-src/src/{crypto → librats/crypto}/hkdf.h +19 -19
- package/native-src/src/{noise.cpp → librats/crypto/noise.cpp} +84 -73
- package/native-src/src/{noise.h → librats/crypto/noise.h} +18 -8
- package/native-src/src/{crypto → librats/crypto}/poly1305.c +47 -46
- package/native-src/src/librats/crypto/poly1305.h +37 -0
- package/native-src/src/{sha1.cpp → librats/crypto/sha1.cpp} +33 -1
- package/native-src/src/{sha1.h → librats/crypto/sha1.h} +14 -6
- package/native-src/src/{crypto → librats/crypto}/sha256.c +15 -14
- package/native-src/src/{crypto → librats/crypto}/sha256.h +8 -7
- package/native-src/src/{crypto → librats/crypto}/sha512.c +15 -14
- package/native-src/src/{crypto → librats/crypto}/sha512.h +8 -7
- package/native-src/src/librats/dht/announce.cpp +37 -0
- package/native-src/src/librats/dht/announce.h +41 -0
- package/native-src/src/librats/dht/bep42.cpp +109 -0
- package/native-src/src/librats/dht/bep42.h +48 -0
- package/native-src/src/librats/dht/dht.cpp +501 -0
- package/native-src/src/librats/dht/dht.h +119 -0
- package/native-src/src/librats/dht/dht_runner.cpp +103 -0
- package/native-src/src/librats/dht/dht_runner.h +71 -0
- package/native-src/src/librats/dht/dos_blocker.cpp +42 -0
- package/native-src/src/librats/dht/dos_blocker.h +47 -0
- package/native-src/src/librats/dht/find_peers.cpp +52 -0
- package/native-src/src/librats/dht/find_peers.h +73 -0
- package/native-src/src/librats/dht/id.h +167 -0
- package/native-src/src/{krpc.cpp → librats/dht/krpc.cpp} +32 -81
- package/native-src/src/{krpc.h → librats/dht/krpc.h} +19 -23
- package/native-src/src/librats/dht/log.h +38 -0
- package/native-src/src/librats/dht/node.cpp +473 -0
- package/native-src/src/librats/dht/node.h +164 -0
- package/native-src/src/librats/dht/node_entry.h +81 -0
- package/native-src/src/librats/dht/observer.h +72 -0
- package/native-src/src/librats/dht/persistence.cpp +90 -0
- package/native-src/src/librats/dht/persistence.h +32 -0
- package/native-src/src/librats/dht/routing_table.cpp +559 -0
- package/native-src/src/librats/dht/routing_table.h +185 -0
- package/native-src/src/librats/dht/rpc_manager.cpp +127 -0
- package/native-src/src/librats/dht/rpc_manager.h +77 -0
- package/native-src/src/librats/dht/storage.cpp +92 -0
- package/native-src/src/librats/dht/storage.h +74 -0
- package/native-src/src/librats/dht/transport.h +27 -0
- package/native-src/src/librats/dht/traversal.cpp +326 -0
- package/native-src/src/librats/dht/traversal.h +120 -0
- package/native-src/src/librats/dht/udp_transport.cpp +49 -0
- package/native-src/src/librats/dht/udp_transport.h +51 -0
- package/native-src/src/librats/mdns/log.h +22 -0
- package/native-src/src/{mdns.cpp → librats/mdns/mdns.cpp} +75 -40
- package/native-src/src/{mdns.h → librats/mdns/mdns.h} +9 -8
- package/native-src/src/{natpmp.cpp → librats/nat/natpmp.cpp} +12 -9
- package/native-src/src/{natpmp.h → librats/nat/natpmp.h} +3 -3
- package/native-src/src/{port_mapping.h → librats/nat/port_mapping.h} +3 -2
- package/native-src/src/{stun.cpp → librats/nat/stun.cpp} +4 -4
- package/native-src/src/{stun.h → librats/nat/stun.h} +1 -1
- package/native-src/src/{upnp.cpp → librats/nat/upnp.cpp} +6 -6
- package/native-src/src/{upnp.h → librats/nat/upnp.h} +2 -2
- package/native-src/src/librats/node/config.h +110 -0
- package/native-src/src/librats/node/dial_service.h +54 -0
- package/native-src/src/librats/node/dialer.cpp +264 -0
- package/native-src/src/librats/node/dialer.h +188 -0
- package/native-src/src/librats/node/host_events.h +26 -0
- package/native-src/src/librats/node/identify.cpp +130 -0
- package/native-src/src/librats/node/identify.h +71 -0
- package/native-src/src/librats/node/nat_status.cpp +103 -0
- package/native-src/src/librats/node/nat_status.h +118 -0
- package/native-src/src/librats/node/node.cpp +826 -0
- package/native-src/src/librats/node/node.h +333 -0
- package/native-src/src/librats/node/node_context.h +33 -0
- package/native-src/src/librats/node/peer_network.h +91 -0
- package/native-src/src/librats/peer/peer.h +49 -0
- package/native-src/src/librats/peer/peer_book.cpp +181 -0
- package/native-src/src/librats/peer/peer_book.h +88 -0
- package/native-src/src/librats/peer/peer_id.cpp +72 -0
- package/native-src/src/librats/peer/peer_id.h +62 -0
- package/native-src/src/librats/peer/peer_info.h +37 -0
- package/native-src/src/librats/peer/peer_table.cpp +137 -0
- package/native-src/src/librats/peer/peer_table.h +148 -0
- package/native-src/src/librats/security/handshaker.h +66 -0
- package/native-src/src/librats/security/identity.h +43 -0
- package/native-src/src/librats/security/noise_security.cpp +122 -0
- package/native-src/src/librats/security/noise_security.h +37 -0
- package/native-src/src/librats/security/plaintext_security.h +106 -0
- package/native-src/src/librats/security/session.h +37 -0
- package/native-src/src/{storage.cpp → librats/storage/storage.cpp} +369 -522
- package/native-src/src/{storage.h → librats/storage/storage.h} +135 -299
- package/native-src/src/librats/subsystems/bittorrent.cpp +211 -0
- package/native-src/src/librats/subsystems/bittorrent.h +136 -0
- package/native-src/src/librats/subsystems/dht_discovery.cpp +202 -0
- package/native-src/src/librats/subsystems/dht_discovery.h +123 -0
- package/native-src/src/librats/subsystems/dht_service.h +36 -0
- package/native-src/src/librats/subsystems/file_transfer.cpp +972 -0
- package/native-src/src/librats/subsystems/file_transfer.h +367 -0
- package/native-src/src/librats/subsystems/hole_punch.cpp +532 -0
- package/native-src/src/librats/subsystems/hole_punch.h +266 -0
- package/native-src/src/librats/subsystems/hole_punch_service.h +38 -0
- package/native-src/src/librats/subsystems/mdns_discovery.cpp +66 -0
- package/native-src/src/librats/subsystems/mdns_discovery.h +55 -0
- package/native-src/src/librats/subsystems/message_json.cpp +112 -0
- package/native-src/src/librats/subsystems/message_json.h +88 -0
- package/native-src/src/librats/subsystems/peer_exchange.cpp +241 -0
- package/native-src/src/librats/subsystems/peer_exchange.h +136 -0
- package/native-src/src/librats/subsystems/ping_service.cpp +98 -0
- package/native-src/src/librats/subsystems/ping_service.h +66 -0
- package/native-src/src/librats/subsystems/port_mapping_service.cpp +192 -0
- package/native-src/src/librats/subsystems/port_mapping_service.h +84 -0
- package/native-src/src/librats/subsystems/pubsub.cpp +567 -0
- package/native-src/src/librats/subsystems/pubsub.h +175 -0
- package/native-src/src/librats/subsystems/reconnection.cpp +239 -0
- package/native-src/src/librats/subsystems/reconnection.h +126 -0
- package/native-src/src/librats/transport/connection.cpp +343 -0
- package/native-src/src/librats/transport/connection.h +283 -0
- package/native-src/src/librats/transport/link.h +96 -0
- package/native-src/src/librats/transport/reactor.cpp +540 -0
- package/native-src/src/librats/transport/reactor.h +224 -0
- package/native-src/src/librats/transport/reactor_pool.h +81 -0
- package/native-src/src/librats/transport/tcp_link.cpp +49 -0
- package/native-src/src/librats/transport/tcp_link.h +43 -0
- package/native-src/src/librats/transport/udp_mux.cpp +617 -0
- package/native-src/src/librats/transport/udp_mux.h +363 -0
- package/native-src/src/librats/transport/udp_packet.cpp +121 -0
- package/native-src/src/librats/transport/udp_packet.h +190 -0
- package/native-src/src/librats/transport/udp_stream.cpp +1194 -0
- package/native-src/src/librats/transport/udp_stream.h +614 -0
- package/native-src/src/librats/util/features.h.in +51 -0
- package/native-src/src/{fs.cpp → librats/util/fs.cpp} +51 -3
- package/native-src/src/librats/util/fs.h +136 -0
- package/native-src/src/librats/util/json.cpp +1002 -0
- package/native-src/src/librats/util/json.h +444 -0
- package/native-src/src/{logger.cpp → librats/util/logger.cpp} +1 -1
- package/native-src/src/{logger.h → librats/util/logger.h} +43 -31
- package/native-src/src/{network_monitor.cpp → librats/util/network_monitor.cpp} +12 -4
- package/native-src/src/{network_monitor.h → librats/util/network_monitor.h} +2 -1
- package/native-src/src/{network_utils.cpp → librats/util/network_utils.cpp} +38 -23
- package/native-src/src/{network_utils.h → librats/util/network_utils.h} +15 -8
- package/native-src/src/{os.cpp → librats/util/os.cpp} +48 -18
- package/native-src/src/librats/util/rats_export.h +69 -0
- package/native-src/src/{version.cpp → librats/util/version.cpp} +2 -2
- package/native-src/src/{version.h.in → librats/util/version.h.in} +1 -1
- package/native-src/src/librats/wire/frame.cpp +76 -0
- package/native-src/src/librats/wire/frame.h +110 -0
- package/native-src/src/librats/wire/message_router.cpp +45 -0
- package/native-src/src/librats/wire/message_router.h +47 -0
- package/package.json +5 -4
- package/scripts/build-librats.js +1 -0
- package/scripts/postinstall.js +3 -3
- package/scripts/prepare-package.js +4 -4
- package/scripts/verify-installation.js +63 -105
- package/src/librats_node.cpp +1042 -1324
- package/native-src/src/bencode.cpp +0 -485
- package/native-src/src/bencode.h +0 -145
- package/native-src/src/bittorrent.cpp +0 -14
- package/native-src/src/bittorrent.h +0 -74
- package/native-src/src/bt_bitfield.cpp +0 -372
- package/native-src/src/bt_bitfield.h +0 -316
- package/native-src/src/bt_choker.cpp +0 -228
- package/native-src/src/bt_choker.h +0 -147
- package/native-src/src/bt_client.cpp +0 -1047
- package/native-src/src/bt_client.h +0 -445
- package/native-src/src/bt_create_torrent.cpp +0 -677
- package/native-src/src/bt_create_torrent.h +0 -473
- package/native-src/src/bt_extension.cpp +0 -469
- package/native-src/src/bt_extension.h +0 -309
- package/native-src/src/bt_file_storage.cpp +0 -261
- package/native-src/src/bt_file_storage.h +0 -298
- package/native-src/src/bt_handshake.cpp +0 -134
- package/native-src/src/bt_handshake.h +0 -157
- package/native-src/src/bt_messages.cpp +0 -364
- package/native-src/src/bt_messages.h +0 -324
- package/native-src/src/bt_network.cpp +0 -1007
- package/native-src/src/bt_network.h +0 -417
- package/native-src/src/bt_peer_connection.cpp +0 -742
- package/native-src/src/bt_peer_connection.h +0 -592
- package/native-src/src/bt_piece_picker.cpp +0 -786
- package/native-src/src/bt_piece_picker.h +0 -473
- package/native-src/src/bt_resume_data.cpp +0 -410
- package/native-src/src/bt_resume_data.h +0 -249
- package/native-src/src/bt_torrent.cpp +0 -2120
- package/native-src/src/bt_torrent.h +0 -641
- package/native-src/src/bt_torrent_info.cpp +0 -659
- package/native-src/src/bt_torrent_info.h +0 -418
- package/native-src/src/bt_types.h +0 -621
- package/native-src/src/chained_send_buffer.cpp +0 -75
- package/native-src/src/chained_send_buffer.h +0 -137
- package/native-src/src/crypto/hkdf.c +0 -266
- package/native-src/src/crypto/poly1305.h +0 -36
- package/native-src/src/dht.cpp +0 -3311
- package/native-src/src/dht.h +0 -717
- package/native-src/src/disk_io.cpp +0 -632
- package/native-src/src/disk_io.h +0 -315
- package/native-src/src/file_transfer.cpp +0 -1415
- package/native-src/src/file_transfer.h +0 -286
- package/native-src/src/fs.h +0 -108
- package/native-src/src/gossipsub.cpp +0 -1139
- package/native-src/src/gossipsub.h +0 -403
- package/native-src/src/ice.cpp +0 -893
- package/native-src/src/ice.h +0 -559
- package/native-src/src/json.hpp +0 -25526
- package/native-src/src/librats.cpp +0 -2378
- package/native-src/src/librats.h +0 -2324
- package/native-src/src/librats_bittorrent.cpp +0 -601
- package/native-src/src/librats_c.cpp +0 -1557
- package/native-src/src/librats_c.h +0 -323
- package/native-src/src/librats_discovery.cpp +0 -402
- package/native-src/src/librats_encryption.cpp +0 -275
- package/native-src/src/librats_file_transfer.cpp +0 -144
- package/native-src/src/librats_gossipsub.cpp +0 -289
- package/native-src/src/librats_ice.cpp +0 -213
- package/native-src/src/librats_log_macros.h +0 -36
- package/native-src/src/librats_logging.cpp +0 -173
- package/native-src/src/librats_mdns.cpp +0 -166
- package/native-src/src/librats_persistence.cpp +0 -796
- package/native-src/src/librats_portmap.cpp +0 -419
- package/native-src/src/librats_reconnection.cpp +0 -218
- package/native-src/src/librats_statistic.cpp +0 -105
- package/native-src/src/librats_storage.cpp +0 -189
- package/native-src/src/rats_export.h +0 -17
- package/native-src/src/receive_buffer.cpp +0 -82
- package/native-src/src/receive_buffer.h +0 -127
- package/native-src/src/socket.h +0 -228
- package/native-src/src/threadmanager.cpp +0 -105
- package/native-src/src/threadmanager.h +0 -53
- package/native-src/src/tracker.cpp +0 -1264
- package/native-src/src/tracker.h +0 -319
- package/native-src/src/turn.cpp +0 -762
- package/native-src/src/turn.h +0 -460
- package/native-src/src/wakeup_pipe.h +0 -60
- /package/native-src/src/{os.h → librats/util/os.h} +0 -0
package/lib/index.d.ts
CHANGED
|
@@ -1,700 +1,275 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* TypeScript definitions for librats — Node.js bindings.
|
|
3
|
+
*
|
|
4
|
+
* A `RatsNode` is one librats node: secure transport (Noise XX over TCP or the
|
|
5
|
+
* library's reliable stream over UDP), a self-certifying peer id, and raw
|
|
6
|
+
* messaging on named channels. Everything else is an opt-in subsystem enabled
|
|
7
|
+
* BEFORE `start()`.
|
|
6
8
|
*/
|
|
7
9
|
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
10
|
+
/// <reference types="node" />
|
|
11
|
+
|
|
12
|
+
declare module 'librats' {
|
|
13
|
+
/** Transport security selector (`rats_security_t`). */
|
|
14
|
+
export const Security: {
|
|
15
|
+
/** Noise XX, encrypted + authenticated (default). */
|
|
16
|
+
readonly NOISE: 0;
|
|
17
|
+
/** Unencrypted; ids exchanged in the clear. */
|
|
18
|
+
readonly PLAINTEXT: 1;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Which wire a peer connection runs on. Both carry the identical protocol and
|
|
23
|
+
* the identical encrypted handshake; they differ only in how the ordered,
|
|
24
|
+
* reliable byte stream underneath is obtained.
|
|
25
|
+
*/
|
|
26
|
+
export const Transport: {
|
|
27
|
+
/** One kernel socket per peer. */
|
|
28
|
+
readonly TCP: 0;
|
|
29
|
+
/** Reliable stream over the shared UDP socket. */
|
|
30
|
+
readonly UDP: 1;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** Bitmask flags used by `node.transports` and `node.peerTransports()`. */
|
|
34
|
+
export const TransportMask: {
|
|
35
|
+
readonly TCP: 0x1;
|
|
36
|
+
readonly UDP: 0x2;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** What the mesh has shown about this node's own NAT. */
|
|
40
|
+
export const NatMapping: {
|
|
41
|
+
/** Not enough independent observations yet. */
|
|
42
|
+
readonly UNKNOWN: 0;
|
|
43
|
+
/** No NAT in the path. */
|
|
44
|
+
readonly OPEN: 1;
|
|
45
|
+
/** One external port for every peer — punchable. */
|
|
46
|
+
readonly ENDPOINT_INDEPENDENT: 2;
|
|
47
|
+
/** A fresh mapping per peer (symmetric) — not punchable. */
|
|
48
|
+
readonly ENDPOINT_DEPENDENT: 3;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** Process-global log levels. */
|
|
52
|
+
export const LogLevel: {
|
|
53
|
+
readonly DEBUG: 0;
|
|
54
|
+
readonly INFO: 1;
|
|
55
|
+
readonly WARN: 2;
|
|
56
|
+
readonly ERROR: 3;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type SecurityValue = 0 | 1;
|
|
60
|
+
export type TransportValue = 0 | 1;
|
|
61
|
+
export type NatMappingValue = 0 | 1 | 2 | 3;
|
|
62
|
+
export type LogLevelValue = 0 | 1 | 2 | 3;
|
|
63
|
+
|
|
64
|
+
/** Full node configuration; mirrors `rats_config_t`. Every field is optional. */
|
|
65
|
+
export interface RatsNodeConfig {
|
|
66
|
+
/** Inbound port shared by both transports; 0 = ephemeral. */
|
|
67
|
+
listenPort?: number;
|
|
68
|
+
/** `false` makes a dial-only node (no listener). Default `true`. */
|
|
69
|
+
enableListen?: boolean;
|
|
70
|
+
/** Bind address; omitted selects the `"::"` dual-stack wildcard. */
|
|
71
|
+
bindAddress?: string;
|
|
72
|
+
/** Default `Security.NOISE`. */
|
|
73
|
+
security?: SecurityValue;
|
|
74
|
+
/** Persistent state dir; omitted gives an ephemeral identity per run. */
|
|
75
|
+
dataDir?: string;
|
|
76
|
+
/** Handshake app id, e.g. `"myapp/1.0"`. Peers whose protocol differs cannot connect. */
|
|
77
|
+
protocol?: string;
|
|
78
|
+
/** Established-peer cap; 0 = unlimited. */
|
|
79
|
+
maxPeers?: number;
|
|
80
|
+
/** Accept and dial over TCP. Default `true`. */
|
|
81
|
+
enableTcp?: boolean;
|
|
82
|
+
/** Accept and dial over the datagram transport. Default `true`. */
|
|
83
|
+
enableUdp?: boolean;
|
|
84
|
+
/** Which transport a dial tries first. Default `Transport.UDP`. */
|
|
85
|
+
preferredTransport?: TransportValue;
|
|
86
|
+
/** Delay before the other transport is raced alongside; 0 disables. Default 1200. */
|
|
87
|
+
transportFallbackMs?: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type PeerHandler = (peerId: string) => void;
|
|
91
|
+
export type MessageHandler = (peerId: string, data: Buffer) => void;
|
|
92
|
+
export type TopicHandler = (peerId: string, topic: string, data: Buffer) => void;
|
|
93
|
+
export type JsonHandler = (peerId: string, value: any) => void;
|
|
94
|
+
export type FileOfferHandler = (
|
|
95
|
+
peerId: string,
|
|
96
|
+
transferId: number,
|
|
97
|
+
name: string,
|
|
98
|
+
size: number,
|
|
99
|
+
isDirectory: boolean
|
|
100
|
+
) => void;
|
|
101
|
+
export type FileProgressHandler = (
|
|
102
|
+
transferId: number,
|
|
103
|
+
peerId: string,
|
|
104
|
+
bytesTransferred: number,
|
|
105
|
+
totalBytes: number,
|
|
106
|
+
status: number
|
|
107
|
+
) => void;
|
|
108
|
+
export type FileCompleteHandler = (
|
|
109
|
+
transferId: number,
|
|
110
|
+
success: boolean,
|
|
111
|
+
path: string
|
|
112
|
+
) => void;
|
|
113
|
+
|
|
114
|
+
/** Library version components. */
|
|
115
|
+
export interface VersionInfo {
|
|
116
|
+
major: number;
|
|
117
|
+
minor: number;
|
|
118
|
+
patch: number;
|
|
119
|
+
build: number;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A librats node.
|
|
124
|
+
*
|
|
125
|
+
* Enable subsystems and register callbacks BEFORE `start()`. Failures throw an
|
|
126
|
+
* `Error` whose message is `librats: <CODE>`.
|
|
127
|
+
*/
|
|
128
|
+
export class RatsNode {
|
|
129
|
+
/**
|
|
130
|
+
* @param portOrConfig listen port (0 = ephemeral) or a config object.
|
|
131
|
+
*/
|
|
132
|
+
constructor(portOrConfig?: number | RatsNodeConfig);
|
|
133
|
+
|
|
134
|
+
// ---- lifecycle ----
|
|
135
|
+
|
|
136
|
+
/** Bring the node up: bind the listener and start enabled subsystems. */
|
|
137
|
+
start(): void;
|
|
138
|
+
/** Tear the node down and close all connections. Idempotent. */
|
|
139
|
+
stop(): void;
|
|
140
|
+
/** Release the native node; the instance is inert afterwards. */
|
|
141
|
+
destroy(): void;
|
|
142
|
+
|
|
143
|
+
// ---- identity / info ----
|
|
144
|
+
|
|
145
|
+
/** The bound listen port (resolved when 0 was requested). */
|
|
146
|
+
readonly listenPort: number;
|
|
147
|
+
/** Our self-certifying peer id (64-char lowercase hex). */
|
|
148
|
+
readonly localId: string | null;
|
|
149
|
+
/** The app protocol bound into the handshake, e.g. `"librats/1.0"`. */
|
|
150
|
+
readonly protocol: string | null;
|
|
151
|
+
/**
|
|
152
|
+
* Transports actually running, as a `TransportMask` bitmask. May be narrower
|
|
153
|
+
* than the config asked for. 0 before `start()` and after `stop()`.
|
|
154
|
+
*/
|
|
155
|
+
readonly transports: number;
|
|
156
|
+
|
|
157
|
+
// ---- connections ----
|
|
158
|
+
|
|
159
|
+
/** Dial a peer. Non-blocking: success surfaces as `onPeerConnected`. */
|
|
160
|
+
connect(host: string, port: number): void;
|
|
161
|
+
/** Count of currently-connected peers. */
|
|
162
|
+
readonly peerCount: number;
|
|
163
|
+
/** Hex ids of currently-connected peers. */
|
|
164
|
+
readonly peerIds: string[];
|
|
165
|
+
/** Cap on established peers (0 = unlimited). Settable at any time. */
|
|
166
|
+
maxPeers: number;
|
|
167
|
+
/** Which wire a connected peer's link runs on, or `null` if not connected. */
|
|
168
|
+
peerTransport(peerId: string): TransportValue | null;
|
|
169
|
+
/**
|
|
170
|
+
* Transports a connected peer advertised, as a `TransportMask` bitmask, or
|
|
171
|
+
* `null` if not connected. 0 means the peer did not say (an older build).
|
|
172
|
+
*/
|
|
173
|
+
peerTransports(peerId: string): number | null;
|
|
174
|
+
|
|
175
|
+
// ---- raw channel messaging ----
|
|
176
|
+
|
|
177
|
+
/** Send raw bytes on a named channel to one peer. */
|
|
178
|
+
send(peerId: string, channel: string, data: string | Buffer): void;
|
|
179
|
+
/** Broadcast raw bytes on a named channel to every connected peer. */
|
|
180
|
+
broadcast(channel: string, data: string | Buffer): void;
|
|
181
|
+
/** Register a handler for a named channel. Additive; register before `start()`. */
|
|
182
|
+
on(channel: string, handler: MessageHandler): void;
|
|
183
|
+
|
|
184
|
+
// ---- peer events (register before start) ----
|
|
185
|
+
|
|
186
|
+
onPeerConnected(handler: PeerHandler): void;
|
|
187
|
+
onPeerDisconnected(handler: PeerHandler): void;
|
|
188
|
+
|
|
189
|
+
// ---- discovery (enable before start) ----
|
|
190
|
+
|
|
191
|
+
/** Enable DHT discovery. `discoveryKey` defaults to the node's protocol. */
|
|
192
|
+
enableDht(dhtPort?: number, discoveryKey?: string): void;
|
|
193
|
+
/** Enable local-network mDNS discovery. */
|
|
194
|
+
enableMdns(): void;
|
|
195
|
+
|
|
196
|
+
// ---- NAT traversal (enable before start) ----
|
|
197
|
+
|
|
198
|
+
/** Enable automatic NAT port forwarding for the listen port. */
|
|
199
|
+
enablePortMapping(enableUpnp?: boolean, enableNatpmp?: boolean): void;
|
|
200
|
+
/**
|
|
201
|
+
* Enable UDP hole punching. `serveAsRelay` (default `true`) also carries
|
|
202
|
+
* other peers' rendezvous — a mesh in which nobody relays cannot punch.
|
|
203
|
+
*/
|
|
204
|
+
enableHolePunch(serveAsRelay?: boolean): void;
|
|
205
|
+
/**
|
|
206
|
+
* Try to reach a peer by punching. Non-blocking: success arrives as an
|
|
207
|
+
* ordinary `onPeerConnected`.
|
|
208
|
+
*/
|
|
209
|
+
punchPeer(peerId: string): void;
|
|
210
|
+
/** A `NatMapping` value describing this node's own NAT. */
|
|
211
|
+
readonly natMapping: NatMappingValue;
|
|
212
|
+
|
|
213
|
+
// ---- pub/sub (enable before start) ----
|
|
214
|
+
|
|
215
|
+
enablePubsub(): void;
|
|
216
|
+
subscribe(topic: string, handler: TopicHandler): void;
|
|
217
|
+
unsubscribe(topic: string): void;
|
|
218
|
+
publish(topic: string, data: string | Buffer): void;
|
|
219
|
+
|
|
220
|
+
// ---- typed JSON messaging (enable before start) ----
|
|
221
|
+
|
|
222
|
+
enableJson(): void;
|
|
223
|
+
/** Register an additive handler; the handler receives the parsed value. */
|
|
224
|
+
onJson(type: string, handler: JsonHandler): void;
|
|
225
|
+
/** Like `onJson`, but the handler is removed after it fires once. */
|
|
226
|
+
onceJson(type: string, handler: JsonHandler): void;
|
|
227
|
+
offJson(type: string): void;
|
|
228
|
+
/** `value` is serialized with `JSON.stringify` unless it is already a string. */
|
|
229
|
+
sendJson(peerId: string, type: string, value: any): void;
|
|
230
|
+
broadcastJson(type: string, value: any): void;
|
|
231
|
+
|
|
232
|
+
// ---- file transfer (enable + register callbacks before start) ----
|
|
233
|
+
|
|
234
|
+
enableFileTransfer(tempDir?: string): void;
|
|
235
|
+
onFileOffer(handler: FileOfferHandler): void;
|
|
236
|
+
onFileProgress(handler: FileProgressHandler): void;
|
|
237
|
+
onFileComplete(handler: FileCompleteHandler): void;
|
|
238
|
+
/** @returns the transfer id, or 0 on failure. */
|
|
239
|
+
sendFile(peerId: string, filePath: string): number;
|
|
240
|
+
/** @returns the transfer id, or 0 on failure. */
|
|
241
|
+
sendDirectory(peerId: string, dirPath: string): number;
|
|
242
|
+
/** `destPath` is the file path for a single file, else the destination directory. */
|
|
243
|
+
acceptFile(peerId: string, transferId: number, destPath: string): void;
|
|
244
|
+
rejectFile(peerId: string, transferId: number): void;
|
|
245
|
+
cancelFile(peerId: string, transferId: number): void;
|
|
246
|
+
pauseFile(peerId: string, transferId: number): void;
|
|
247
|
+
resumeFile(peerId: string, transferId: number): void;
|
|
248
|
+
|
|
249
|
+
// ---- liveness / reconnection (enable before start) ----
|
|
250
|
+
|
|
251
|
+
enablePing(): void;
|
|
252
|
+
/** Last measured RTT in ms, or -1 if unknown. */
|
|
253
|
+
peerRttMs(peerId: string): number;
|
|
254
|
+
enableReconnect(): void;
|
|
255
|
+
addReconnect(host: string, port: number): void;
|
|
256
|
+
removeReconnect(host: string, port: number): void;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// ---- library info (process-global) ----
|
|
260
|
+
|
|
261
|
+
/** Library version as a string, e.g. `"1.2.3"`. */
|
|
262
|
+
export function version(): string;
|
|
263
|
+
/** Library version components. */
|
|
264
|
+
export function versionInfo(): VersionInfo;
|
|
265
|
+
/** Git describe of the build, e.g. `"v1.2.3-4-gabcdef"`. */
|
|
266
|
+
export function gitDescribe(): string;
|
|
267
|
+
/** Packed ABI id as `(major << 16) | (minor << 8) | patch`. */
|
|
268
|
+
export function abi(): number;
|
|
269
|
+
|
|
270
|
+
// ---- process-global logging ----
|
|
271
|
+
|
|
272
|
+
export function setLogLevel(level: LogLevelValue): void;
|
|
273
|
+
/** Mirror logs to a file; omitted/empty disables file logging. */
|
|
274
|
+
export function setLogFile(path?: string): void;
|
|
52
275
|
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* ICE gathering states
|
|
56
|
-
*/
|
|
57
|
-
export enum IceGatheringState {
|
|
58
|
-
NEW = 0,
|
|
59
|
-
GATHERING = 1,
|
|
60
|
-
COMPLETE = 2
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* ICE candidate types
|
|
65
|
-
*/
|
|
66
|
-
export enum IceCandidateType {
|
|
67
|
-
HOST = 0,
|
|
68
|
-
SRFLX = 1,
|
|
69
|
-
PRFLX = 2,
|
|
70
|
-
RELAY = 3
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Main RatsClient class for peer-to-peer networking
|
|
75
|
-
*/
|
|
76
|
-
export class RatsClient {
|
|
77
|
-
/**
|
|
78
|
-
* Create a new RatsClient instance
|
|
79
|
-
* @param listenPort - Port to listen on for incoming connections
|
|
80
|
-
*/
|
|
81
|
-
constructor(listenPort: number);
|
|
82
|
-
|
|
83
|
-
// ============ Basic Operations ============
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Start the client
|
|
87
|
-
* @returns true if started successfully, false otherwise
|
|
88
|
-
*/
|
|
89
|
-
start(): boolean;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Stop the client
|
|
93
|
-
*/
|
|
94
|
-
stop(): void;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Connect to a peer
|
|
98
|
-
* @param host - IP address or hostname of the peer
|
|
99
|
-
* @param port - Port number of the peer
|
|
100
|
-
* @returns true if connection initiated successfully
|
|
101
|
-
*/
|
|
102
|
-
connect(host: string, port: number): boolean;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Disconnect from a peer
|
|
106
|
-
* @param peerId - ID of the peer to disconnect from
|
|
107
|
-
*/
|
|
108
|
-
disconnect(peerId: string): void;
|
|
109
|
-
|
|
110
|
-
// ============ Information ============
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Get the port the client is listening on
|
|
114
|
-
* @returns Listen port number
|
|
115
|
-
*/
|
|
116
|
-
getListenPort(): number;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Get the number of connected peers
|
|
120
|
-
* @returns Number of connected peers
|
|
121
|
-
*/
|
|
122
|
-
getPeerCount(): number;
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Get our own peer ID
|
|
126
|
-
* @returns Our peer ID, or null if not started
|
|
127
|
-
*/
|
|
128
|
-
getOurPeerId(): string | null;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Get list of connected peer IDs
|
|
132
|
-
* @returns Array of peer IDs
|
|
133
|
-
*/
|
|
134
|
-
getPeerIds(): string[];
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Get connection statistics as JSON string
|
|
138
|
-
* @returns JSON string with statistics, or null if unavailable
|
|
139
|
-
*/
|
|
140
|
-
getConnectionStatistics(): string | null;
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Get file transfer statistics as JSON string
|
|
144
|
-
* @returns JSON string with statistics, or null if unavailable
|
|
145
|
-
*/
|
|
146
|
-
getFileTransferStatistics(): string | null;
|
|
147
|
-
|
|
148
|
-
// ============ Peer Management ============
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Set maximum number of peers
|
|
152
|
-
* @param maxPeers - Maximum number of peers to allow
|
|
153
|
-
* @returns true if set successfully
|
|
154
|
-
*/
|
|
155
|
-
setMaxPeers(maxPeers: number): boolean;
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Get maximum number of peers
|
|
159
|
-
* @returns Maximum number of peers allowed
|
|
160
|
-
*/
|
|
161
|
-
getMaxPeers(): number;
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Check if peer limit has been reached
|
|
165
|
-
* @returns true if at or over peer limit
|
|
166
|
-
*/
|
|
167
|
-
isPeerLimitReached(): boolean;
|
|
168
|
-
|
|
169
|
-
// ============ Messaging ============
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Send a string message to a peer
|
|
173
|
-
* @param peerId - ID of the peer to send to
|
|
174
|
-
* @param message - String message to send
|
|
175
|
-
* @returns true if sent successfully
|
|
176
|
-
*/
|
|
177
|
-
sendString(peerId: string, message: string): boolean;
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Send binary data to a peer
|
|
181
|
-
* @param peerId - ID of the peer to send to
|
|
182
|
-
* @param data - Buffer containing binary data
|
|
183
|
-
* @returns true if sent successfully
|
|
184
|
-
*/
|
|
185
|
-
sendBinary(peerId: string, data: Buffer): boolean;
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Send JSON data to a peer
|
|
189
|
-
* @param peerId - ID of the peer to send to
|
|
190
|
-
* @param jsonStr - JSON string to send
|
|
191
|
-
* @returns true if sent successfully
|
|
192
|
-
*/
|
|
193
|
-
sendJson(peerId: string, jsonStr: string): boolean;
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Broadcast a string message to all connected peers
|
|
197
|
-
* @param message - String message to broadcast
|
|
198
|
-
* @returns Number of peers the message was sent to
|
|
199
|
-
*/
|
|
200
|
-
broadcastString(message: string): number;
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Broadcast binary data to all connected peers
|
|
204
|
-
* @param data - Buffer containing binary data
|
|
205
|
-
* @returns Number of peers the data was sent to
|
|
206
|
-
*/
|
|
207
|
-
broadcastBinary(data: Buffer): number;
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Broadcast JSON data to all connected peers
|
|
211
|
-
* @param jsonStr - JSON string to broadcast
|
|
212
|
-
* @returns Number of peers the data was sent to
|
|
213
|
-
*/
|
|
214
|
-
broadcastJson(jsonStr: string): number;
|
|
215
|
-
|
|
216
|
-
// ============ File Transfer ============
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Send a file to a peer
|
|
220
|
-
* @param peerId - ID of the peer to send to
|
|
221
|
-
* @param filePath - Local path to the file
|
|
222
|
-
* @param remoteFilename - Optional filename on remote side
|
|
223
|
-
* @returns Transfer ID, or null if failed
|
|
224
|
-
*/
|
|
225
|
-
sendFile(peerId: string, filePath: string, remoteFilename?: string): string | null;
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Send a directory to a peer. Directory transfers are always recursive.
|
|
229
|
-
* @param peerId - ID of the peer to send to
|
|
230
|
-
* @param dirPath - Local path to the directory
|
|
231
|
-
* @param remoteDirName - Optional directory name on remote side
|
|
232
|
-
* @returns Transfer ID, or null if failed
|
|
233
|
-
*/
|
|
234
|
-
sendDirectory(peerId: string, dirPath: string, remoteDirName?: string): string | null;
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Accept an incoming file transfer
|
|
238
|
-
* @param transferId - ID of the transfer to accept
|
|
239
|
-
* @param localPath - Local path where file should be saved
|
|
240
|
-
* @returns true if accepted successfully
|
|
241
|
-
*/
|
|
242
|
-
acceptFileTransfer(transferId: string, localPath: string): boolean;
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Reject an incoming file transfer
|
|
246
|
-
* @param transferId - ID of the transfer to reject
|
|
247
|
-
* @param reason - Optional reason for rejection
|
|
248
|
-
* @returns true if rejected successfully
|
|
249
|
-
*/
|
|
250
|
-
rejectFileTransfer(transferId: string, reason?: string): boolean;
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Cancel an ongoing file transfer
|
|
254
|
-
* @param transferId - ID of the transfer to cancel
|
|
255
|
-
* @returns true if cancelled successfully
|
|
256
|
-
*/
|
|
257
|
-
cancelFileTransfer(transferId: string): boolean;
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Pause a file transfer
|
|
261
|
-
* @param transferId - ID of the transfer to pause
|
|
262
|
-
* @returns true if paused successfully
|
|
263
|
-
*/
|
|
264
|
-
pauseFileTransfer(transferId: string): boolean;
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Resume a paused file transfer
|
|
268
|
-
* @param transferId - ID of the transfer to resume
|
|
269
|
-
* @returns true if resumed successfully
|
|
270
|
-
*/
|
|
271
|
-
resumeFileTransfer(transferId: string): boolean;
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Get file transfer progress information as JSON string
|
|
275
|
-
* @param transferId - ID of the transfer to query
|
|
276
|
-
* @returns JSON string with progress info, or null if not found
|
|
277
|
-
*/
|
|
278
|
-
getFileTransferProgress(transferId: string): string | null;
|
|
279
|
-
|
|
280
|
-
// ============ GossipSub ============
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Check if GossipSub is available
|
|
284
|
-
* @returns true if GossipSub is available
|
|
285
|
-
*/
|
|
286
|
-
isGossipsubAvailable(): boolean;
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Check if GossipSub is running
|
|
290
|
-
* @returns true if GossipSub is running
|
|
291
|
-
*/
|
|
292
|
-
isGossipsubRunning(): boolean;
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Subscribe to a topic
|
|
296
|
-
* @param topic - Topic name to subscribe to
|
|
297
|
-
* @returns true if subscribed successfully
|
|
298
|
-
*/
|
|
299
|
-
subscribeToTopic(topic: string): boolean;
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Unsubscribe from a topic
|
|
303
|
-
* @param topic - Topic name to unsubscribe from
|
|
304
|
-
* @returns true if unsubscribed successfully
|
|
305
|
-
*/
|
|
306
|
-
unsubscribeFromTopic(topic: string): boolean;
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Check if subscribed to a topic
|
|
310
|
-
* @param topic - Topic name to check
|
|
311
|
-
* @returns true if subscribed
|
|
312
|
-
*/
|
|
313
|
-
isSubscribedToTopic(topic: string): boolean;
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Publish a message to a topic
|
|
317
|
-
* @param topic - Topic name to publish to
|
|
318
|
-
* @param message - Message to publish
|
|
319
|
-
* @returns true if published successfully
|
|
320
|
-
*/
|
|
321
|
-
publishToTopic(topic: string, message: string): boolean;
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* Publish JSON data to a topic
|
|
325
|
-
* @param topic - Topic name to publish to
|
|
326
|
-
* @param jsonStr - JSON string to publish
|
|
327
|
-
* @returns true if published successfully
|
|
328
|
-
*/
|
|
329
|
-
publishJsonToTopic(topic: string, jsonStr: string): boolean;
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Get list of subscribed topics
|
|
333
|
-
* @returns Array of topic names
|
|
334
|
-
*/
|
|
335
|
-
getSubscribedTopics(): string[];
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Get peers subscribed to a topic
|
|
339
|
-
* @param topic - Topic name
|
|
340
|
-
* @returns Array of peer IDs
|
|
341
|
-
*/
|
|
342
|
-
getTopicPeers(topic: string): string[];
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Get GossipSub statistics as JSON string
|
|
346
|
-
* @returns JSON string with statistics, or null if unavailable
|
|
347
|
-
*/
|
|
348
|
-
getGossipsubStatistics(): string | null;
|
|
349
|
-
|
|
350
|
-
// ============ DHT ============
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Start DHT discovery
|
|
354
|
-
* @param dhtPort - Port to use for DHT
|
|
355
|
-
* @returns true if started successfully
|
|
356
|
-
*/
|
|
357
|
-
startDhtDiscovery(dhtPort: number): boolean;
|
|
358
|
-
|
|
359
|
-
/**
|
|
360
|
-
* Stop DHT discovery
|
|
361
|
-
*/
|
|
362
|
-
stopDhtDiscovery(): void;
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Check if DHT is running
|
|
366
|
-
* @returns true if DHT is running
|
|
367
|
-
*/
|
|
368
|
-
isDhtRunning(): boolean;
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Get DHT routing table size
|
|
372
|
-
* @returns Number of entries in the routing table
|
|
373
|
-
*/
|
|
374
|
-
getDhtRoutingTableSize(): number;
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* Announce availability for a content hash
|
|
378
|
-
* @param contentHash - Hash to announce for
|
|
379
|
-
* @param port - Port to announce
|
|
380
|
-
* @param callback - Optional callback to receive discovered peers during DHT traversal
|
|
381
|
-
* @returns true if announced successfully
|
|
382
|
-
*/
|
|
383
|
-
announceForHash(contentHash: string, port: number, callback?: (peers: string[]) => void): boolean;
|
|
384
|
-
|
|
385
|
-
// ============ mDNS ============
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Start mDNS discovery
|
|
389
|
-
* @param serviceName - Service name to advertise
|
|
390
|
-
* @returns true if started successfully
|
|
391
|
-
*/
|
|
392
|
-
startMdnsDiscovery(serviceName: string): boolean;
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* Stop mDNS discovery
|
|
396
|
-
*/
|
|
397
|
-
stopMdnsDiscovery(): void;
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Check if mDNS is running
|
|
401
|
-
* @returns true if mDNS is running
|
|
402
|
-
*/
|
|
403
|
-
isMdnsRunning(): boolean;
|
|
404
|
-
|
|
405
|
-
/**
|
|
406
|
-
* Query for mDNS services
|
|
407
|
-
* @returns true if query sent successfully
|
|
408
|
-
*/
|
|
409
|
-
queryMdnsServices(): boolean;
|
|
410
|
-
|
|
411
|
-
// ============ Address Blocking ============
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* Add an IP address to the ignore list
|
|
415
|
-
* @param ipAddress - IP address to ignore
|
|
416
|
-
*/
|
|
417
|
-
addIgnoredAddress(ipAddress: string): void;
|
|
418
|
-
|
|
419
|
-
// ============ Encryption ============
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Enable or disable encryption
|
|
423
|
-
* @param enabled - Whether encryption should be enabled
|
|
424
|
-
* @returns true if set successfully
|
|
425
|
-
*/
|
|
426
|
-
setEncryptionEnabled(enabled: boolean): boolean;
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* Check if encryption is enabled
|
|
430
|
-
* @returns true if encryption is enabled
|
|
431
|
-
*/
|
|
432
|
-
isEncryptionEnabled(): boolean;
|
|
433
|
-
|
|
434
|
-
/**
|
|
435
|
-
* Initialize encryption system
|
|
436
|
-
* @param enable - Whether to enable encryption
|
|
437
|
-
* @returns true if initialized successfully
|
|
438
|
-
*/
|
|
439
|
-
initializeEncryption(enable: boolean): boolean;
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* Check if a specific peer connection is encrypted
|
|
443
|
-
* @param peerId - Peer ID to check
|
|
444
|
-
* @returns true if peer connection is encrypted
|
|
445
|
-
*/
|
|
446
|
-
isPeerEncrypted(peerId: string): boolean;
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* Set custom Noise Protocol static keypair
|
|
450
|
-
* @param privateKeyHex - 32-byte private key as 64-char hex string
|
|
451
|
-
* @returns true if set successfully
|
|
452
|
-
*/
|
|
453
|
-
setNoiseStaticKeypair(privateKeyHex: string): boolean;
|
|
454
|
-
|
|
455
|
-
/**
|
|
456
|
-
* Get our Noise Protocol static public key
|
|
457
|
-
* @returns 64-char hex string, or null if not available
|
|
458
|
-
*/
|
|
459
|
-
getNoiseStaticPublicKey(): string | null;
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* Get remote peer's Noise static public key
|
|
463
|
-
* @param peerId - Peer ID to query
|
|
464
|
-
* @returns 64-char hex string, or null if not available
|
|
465
|
-
*/
|
|
466
|
-
getPeerNoisePublicKey(peerId: string): string | null;
|
|
467
|
-
|
|
468
|
-
/**
|
|
469
|
-
* Get handshake hash for channel binding
|
|
470
|
-
* @param peerId - Peer ID to query
|
|
471
|
-
* @returns 64-char hex string, or null if not available
|
|
472
|
-
*/
|
|
473
|
-
getPeerHandshakeHash(peerId: string): string | null;
|
|
474
|
-
|
|
475
|
-
// ============ ICE (NAT Traversal) ============
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Check if ICE is available
|
|
479
|
-
* @returns true if ICE is available
|
|
480
|
-
*/
|
|
481
|
-
isIceAvailable(): boolean;
|
|
482
|
-
|
|
483
|
-
/**
|
|
484
|
-
* Add a STUN server for NAT traversal
|
|
485
|
-
* @param host - STUN server hostname or IP
|
|
486
|
-
* @param port - STUN server port (default: 3478)
|
|
487
|
-
*/
|
|
488
|
-
addStunServer(host: string, port?: number): void;
|
|
489
|
-
|
|
490
|
-
/**
|
|
491
|
-
* Add a TURN server for relay-based NAT traversal
|
|
492
|
-
* @param host - TURN server hostname or IP
|
|
493
|
-
* @param port - TURN server port
|
|
494
|
-
* @param username - TURN username
|
|
495
|
-
* @param password - TURN password
|
|
496
|
-
*/
|
|
497
|
-
addTurnServer(host: string, port: number, username: string, password: string): void;
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Clear all ICE (STUN/TURN) servers
|
|
501
|
-
*/
|
|
502
|
-
clearIceServers(): void;
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* Start gathering ICE candidates
|
|
506
|
-
* @returns true if gathering started successfully
|
|
507
|
-
*/
|
|
508
|
-
gatherIceCandidates(): boolean;
|
|
509
|
-
|
|
510
|
-
/**
|
|
511
|
-
* Get local ICE candidates as JSON string
|
|
512
|
-
* @returns JSON string of candidates, or null if unavailable
|
|
513
|
-
*/
|
|
514
|
-
getIceCandidates(): string | null;
|
|
515
|
-
|
|
516
|
-
/**
|
|
517
|
-
* Check if ICE candidate gathering is complete
|
|
518
|
-
* @returns true if gathering is complete
|
|
519
|
-
*/
|
|
520
|
-
isIceGatheringComplete(): boolean;
|
|
521
|
-
|
|
522
|
-
/**
|
|
523
|
-
* Get public address discovered via STUN
|
|
524
|
-
* @returns Address string (ip:port), or null if not discovered
|
|
525
|
-
*/
|
|
526
|
-
getPublicAddress(): string | null;
|
|
527
|
-
|
|
528
|
-
/**
|
|
529
|
-
* Perform a simple STUN binding request to discover public address
|
|
530
|
-
* @param stunServer - STUN server hostname (default: "stun.l.google.com")
|
|
531
|
-
* @param port - STUN server port (default: 19302)
|
|
532
|
-
* @param timeoutMs - Timeout in milliseconds (default: 5000)
|
|
533
|
-
* @returns Address string (ip:port), or null on failure
|
|
534
|
-
*/
|
|
535
|
-
discoverPublicAddress(stunServer?: string, port?: number, timeoutMs?: number): string | null;
|
|
536
|
-
|
|
537
|
-
/**
|
|
538
|
-
* Add a remote ICE candidate from SDP
|
|
539
|
-
* @param candidateSdp - SDP candidate string
|
|
540
|
-
*/
|
|
541
|
-
addRemoteIceCandidate(candidateSdp: string): void;
|
|
542
|
-
|
|
543
|
-
/**
|
|
544
|
-
* Signal end of remote ICE candidates (trickle ICE complete)
|
|
545
|
-
*/
|
|
546
|
-
endOfRemoteIceCandidates(): void;
|
|
547
|
-
|
|
548
|
-
/**
|
|
549
|
-
* Start ICE connectivity checks
|
|
550
|
-
*/
|
|
551
|
-
startIceChecks(): void;
|
|
552
|
-
|
|
553
|
-
/**
|
|
554
|
-
* Get current ICE connection state
|
|
555
|
-
* @returns ICE connection state value
|
|
556
|
-
*/
|
|
557
|
-
getIceConnectionState(): number;
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* Get ICE gathering state
|
|
561
|
-
* @returns ICE gathering state value
|
|
562
|
-
*/
|
|
563
|
-
getIceGatheringState(): number;
|
|
564
|
-
|
|
565
|
-
/**
|
|
566
|
-
* Check if ICE is connected
|
|
567
|
-
* @returns true if ICE connection is established
|
|
568
|
-
*/
|
|
569
|
-
isIceConnected(): boolean;
|
|
570
|
-
|
|
571
|
-
/**
|
|
572
|
-
* Get the selected ICE candidate pair as JSON string
|
|
573
|
-
* @returns JSON string of selected pair, or null if unavailable
|
|
574
|
-
*/
|
|
575
|
-
getIceSelectedPair(): string | null;
|
|
576
|
-
|
|
577
|
-
/**
|
|
578
|
-
* Close ICE manager and release resources
|
|
579
|
-
*/
|
|
580
|
-
closeIce(): void;
|
|
581
|
-
|
|
582
|
-
/**
|
|
583
|
-
* Restart ICE (re-gather candidates and restart checks)
|
|
584
|
-
*/
|
|
585
|
-
restartIce(): void;
|
|
586
|
-
|
|
587
|
-
// ============ Configuration Persistence ============
|
|
588
|
-
|
|
589
|
-
/**
|
|
590
|
-
* Set data directory for configuration files
|
|
591
|
-
* @param directory - Path to data directory
|
|
592
|
-
* @returns true if set successfully
|
|
593
|
-
*/
|
|
594
|
-
setDataDirectory(directory: string): boolean;
|
|
595
|
-
|
|
596
|
-
/**
|
|
597
|
-
* Get current data directory
|
|
598
|
-
* @returns Path to data directory, or null if not set
|
|
599
|
-
*/
|
|
600
|
-
getDataDirectory(): string | null;
|
|
601
|
-
|
|
602
|
-
/**
|
|
603
|
-
* Save current configuration to disk
|
|
604
|
-
* @returns true if saved successfully
|
|
605
|
-
*/
|
|
606
|
-
saveConfiguration(): boolean;
|
|
607
|
-
|
|
608
|
-
/**
|
|
609
|
-
* Load configuration from disk
|
|
610
|
-
* @returns true if loaded successfully
|
|
611
|
-
*/
|
|
612
|
-
loadConfiguration(): boolean;
|
|
613
|
-
|
|
614
|
-
// ============ Event Handlers ============
|
|
615
|
-
|
|
616
|
-
/**
|
|
617
|
-
* Set callback for when a peer connects
|
|
618
|
-
* @param callback - Function to call with peer ID
|
|
619
|
-
*/
|
|
620
|
-
onConnection(callback: (peerId: string) => void): void;
|
|
621
|
-
|
|
622
|
-
/**
|
|
623
|
-
* Set callback for string messages
|
|
624
|
-
* @param callback - Function to call with peer ID and message
|
|
625
|
-
*/
|
|
626
|
-
onString(callback: (peerId: string, message: string) => void): void;
|
|
627
|
-
|
|
628
|
-
/**
|
|
629
|
-
* Set callback for binary messages
|
|
630
|
-
* @param callback - Function to call with peer ID and data
|
|
631
|
-
*/
|
|
632
|
-
onBinary(callback: (peerId: string, data: Buffer) => void): void;
|
|
633
|
-
|
|
634
|
-
/**
|
|
635
|
-
* Set callback for JSON messages
|
|
636
|
-
* @param callback - Function to call with peer ID and JSON string
|
|
637
|
-
*/
|
|
638
|
-
onJson(callback: (peerId: string, jsonStr: string) => void): void;
|
|
639
|
-
|
|
640
|
-
/**
|
|
641
|
-
* Set callback for when a peer disconnects
|
|
642
|
-
* @param callback - Function to call with peer ID
|
|
643
|
-
*/
|
|
644
|
-
onDisconnect(callback: (peerId: string) => void): void;
|
|
645
|
-
|
|
646
|
-
/**
|
|
647
|
-
* Set callback for file transfer progress updates
|
|
648
|
-
* @param callback - Function to call with transfer ID, progress percentage, and status
|
|
649
|
-
*/
|
|
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;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
// ============ Utility Functions ============
|
|
661
|
-
|
|
662
|
-
/**
|
|
663
|
-
* Get the library version as a string
|
|
664
|
-
* @returns Version string (e.g., "1.0.0.123")
|
|
665
|
-
*/
|
|
666
|
-
export function getVersionString(): string;
|
|
667
|
-
|
|
668
|
-
/**
|
|
669
|
-
* Get the library version components
|
|
670
|
-
* @returns Version information object
|
|
671
|
-
*/
|
|
672
|
-
export function getVersion(): VersionInfo;
|
|
673
|
-
|
|
674
|
-
/**
|
|
675
|
-
* Get git describe string
|
|
676
|
-
* @returns Git describe string
|
|
677
|
-
*/
|
|
678
|
-
export function getGitDescribe(): string;
|
|
679
|
-
|
|
680
|
-
/**
|
|
681
|
-
* Get ABI version number
|
|
682
|
-
* @returns ABI version
|
|
683
|
-
*/
|
|
684
|
-
export function getAbi(): number;
|
|
685
|
-
|
|
686
|
-
// ============ Logging Control Functions ============
|
|
687
|
-
|
|
688
|
-
/**
|
|
689
|
-
* Enable or disable console logging.
|
|
690
|
-
* When disabled, log messages will not be printed to stdout/stderr.
|
|
691
|
-
* File logging (if enabled) will still work.
|
|
692
|
-
* @param enabled - Whether to enable console logging (default: true)
|
|
693
|
-
*/
|
|
694
|
-
export function setConsoleLoggingEnabled(enabled: boolean): void;
|
|
695
|
-
|
|
696
|
-
/**
|
|
697
|
-
* Check if console logging is currently enabled.
|
|
698
|
-
* @returns true if console logging is enabled
|
|
699
|
-
*/
|
|
700
|
-
export function isConsoleLoggingEnabled(): boolean;
|