librats 1.0.2 → 2.2.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 +145 -331
- package/binding.gyp +16 -3
- package/lib/index.d.ts +288 -696
- package/lib/index.js +407 -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 +404 -179
- package/native-src/LICENSE +1 -1
- package/native-src/src/librats/bindings/rats.cpp +762 -0
- package/native-src/src/librats/bindings/rats.h +380 -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 +43 -0
- package/native-src/src/librats/core/types.h +103 -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/circuit_service.h +84 -0
- 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 +865 -0
- package/native-src/src/librats/node/node.h +344 -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 +170 -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 +605 -0
- package/native-src/src/librats/subsystems/hole_punch.h +290 -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/subsystems/relay.cpp +1142 -0
- package/native-src/src/librats/subsystems/relay.h +211 -0
- package/native-src/src/librats/subsystems/relay_service.h +46 -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 +588 -0
- package/native-src/src/librats/transport/reactor.h +262 -0
- package/native-src/src/librats/transport/reactor_pool.h +81 -0
- package/native-src/src/librats/transport/relay_link.cpp +208 -0
- package/native-src/src/librats/transport/relay_link.h +303 -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 +111 -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 +1067 -1323
- 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/README.md
CHANGED
|
@@ -1,410 +1,224 @@
|
|
|
1
|
-
#
|
|
1
|
+
# librats — Node.js bindings
|
|
2
2
|
|
|
3
|
-
Node.js bindings for librats
|
|
3
|
+
Node.js bindings for [librats](../README.md), a C++17 peer-to-peer networking
|
|
4
|
+
library: encrypted transport, DHT/mDNS discovery, NAT traversal, pub/sub, typed
|
|
5
|
+
JSON messaging and file transfer.
|
|
4
6
|
|
|
5
|
-
##
|
|
7
|
+
## The model
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- **Encryption** - End-to-end encryption using Noise protocol
|
|
14
|
-
- **Message Exchange** - String, binary, and JSON message types
|
|
15
|
-
- **Configuration Persistence** - Save and restore client settings
|
|
9
|
+
A `RatsNode` is one librats node. On its own it gives you secure transport
|
|
10
|
+
(Noise XX over TCP **or** the library's reliable stream over UDP, both on the
|
|
11
|
+
same port), a self-certifying peer id, manual dialing, and raw messaging on named
|
|
12
|
+
channels — nothing else. Discovery, pub/sub, JSON messaging, file transfer, NAT
|
|
13
|
+
port mapping, hole punching, RTT probing and reconnection are **opt-in
|
|
14
|
+
subsystems**: you pay only for what you turn on.
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
Two rules follow from that:
|
|
17
|
+
|
|
18
|
+
- **Enable subsystems and register callbacks before `start()`.** Enabling after
|
|
19
|
+
start throws `RATS_ERR_ALREADY_STARTED`; using a subsystem before its enable
|
|
20
|
+
throws `RATS_ERR_NOT_ENABLED`.
|
|
21
|
+
- **Callbacks are marshalled onto the JS thread** from a librats reactor thread.
|
|
22
|
+
Keep them short anyway — a slow handler backs up the reactor's queue.
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
Fallible calls **throw** an `Error` whose message is `librats: <CODE>`; pure
|
|
25
|
+
getters are properties.
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
## Installation
|
|
22
28
|
|
|
23
29
|
```bash
|
|
24
30
|
npm install librats
|
|
25
31
|
```
|
|
26
32
|
|
|
27
|
-
The
|
|
28
|
-
|
|
29
|
-
2. Build the native librats library using CMake
|
|
30
|
-
3. Build the Node.js native addon
|
|
31
|
-
4. Set up the bindings
|
|
32
|
-
|
|
33
|
-
**No additional build steps required!**
|
|
33
|
+
The install builds the native librats library with CMake, then compiles the
|
|
34
|
+
Node.js addon against it. You need:
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
- **Node.js** 20+
|
|
37
|
+
- **CMake** 3.14+ ([download](https://cmake.org/download/))
|
|
38
|
+
- a **C++17 toolchain** — Visual Studio Build Tools 2017+ (Windows),
|
|
39
|
+
`build-essential` (Linux), `xcode-select --install` (macOS)
|
|
36
40
|
|
|
37
|
-
|
|
41
|
+
See [INSTALLATION.md](INSTALLATION.md) for what runs during install and how to
|
|
42
|
+
troubleshoot it.
|
|
38
43
|
|
|
39
|
-
|
|
40
|
-
- **CMake**: Version 3.10 or higher ([download here](https://cmake.org/download/))
|
|
41
|
-
- **C++ Compiler and Build Tools**:
|
|
42
|
-
- **Windows**: Visual Studio Build Tools 2017 or later ([download here](https://visualstudio.microsoft.com/downloads/))
|
|
43
|
-
- **Linux**: `build-essential` and `cmake` packages
|
|
44
|
-
```bash
|
|
45
|
-
sudo apt install build-essential cmake
|
|
46
|
-
```
|
|
47
|
-
- **macOS**: Xcode Command Line Tools
|
|
48
|
-
```bash
|
|
49
|
-
xcode-select --install
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### Verifying Installation
|
|
53
|
-
|
|
54
|
-
After installation, you can verify everything is working:
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
npm run verify
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
This will check that the native addon is built correctly and all features are available.
|
|
61
|
-
|
|
62
|
-
### Building from Source
|
|
63
|
-
|
|
64
|
-
If you're developing or need to rebuild:
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
# Clone the repository
|
|
68
|
-
git clone https://github.com/librats/librats.git
|
|
69
|
-
cd librats/nodejs
|
|
70
|
-
|
|
71
|
-
# Install (builds everything automatically)
|
|
72
|
-
npm install
|
|
73
|
-
|
|
74
|
-
# Verify the installation
|
|
75
|
-
npm run verify
|
|
76
|
-
|
|
77
|
-
# Or build manually
|
|
78
|
-
npm run build
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
## Quick Start
|
|
82
|
-
|
|
83
|
-
### Basic Example
|
|
44
|
+
## Quick start
|
|
84
45
|
|
|
85
46
|
```javascript
|
|
86
|
-
const {
|
|
47
|
+
const { RatsNode } = require('librats');
|
|
87
48
|
|
|
88
|
-
|
|
89
|
-
const client = new RatsClient(8080);
|
|
49
|
+
const node = new RatsNode({ listenPort: 8080, dataDir: './state' });
|
|
90
50
|
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
console.log(
|
|
94
|
-
|
|
51
|
+
// Everything below happens before start().
|
|
52
|
+
node.onPeerConnected((peerId) => {
|
|
53
|
+
console.log(`+ ${peerId}`);
|
|
54
|
+
node.send(peerId, 'chat', 'Hello from Node.js!');
|
|
95
55
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
console.log(`Received: ${message} from ${peerId}`);
|
|
56
|
+
node.on('chat', (peerId, data) => {
|
|
57
|
+
console.log(`[chat] ${peerId}: ${data.toString('utf8')}`);
|
|
99
58
|
});
|
|
59
|
+
node.enableDht(); // find peers on the mainline DHT
|
|
60
|
+
node.enableMdns(); // …and on the local network
|
|
100
61
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
// Connect to another peer
|
|
105
|
-
client.connect('127.0.0.1', 8081);
|
|
62
|
+
node.start();
|
|
63
|
+
console.log(node.localId, 'listening on', node.listenPort);
|
|
106
64
|
```
|
|
107
65
|
|
|
108
|
-
###
|
|
66
|
+
### Pub/sub
|
|
109
67
|
|
|
110
68
|
```javascript
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
// Set up file transfer progress monitoring
|
|
116
|
-
client.onFileProgress((transferId, progressPercent, status) => {
|
|
117
|
-
console.log(`Transfer ${transferId}: ${progressPercent}% - ${status}`);
|
|
69
|
+
node.enablePubsub();
|
|
70
|
+
node.subscribe('lobby', (peerId, topic, data) => {
|
|
71
|
+
console.log(`[${topic}] ${peerId}: ${data.toString('utf8')}`);
|
|
118
72
|
});
|
|
73
|
+
node.start();
|
|
74
|
+
node.publish('lobby', 'hi everyone');
|
|
75
|
+
```
|
|
119
76
|
|
|
120
|
-
|
|
121
|
-
client.onFileRequest((peerId, transferId, filename) => {
|
|
122
|
-
console.log(`Incoming offer "${filename}" from ${peerId}`);
|
|
123
|
-
client.acceptFileTransfer(transferId, `./downloads/${filename}`);
|
|
124
|
-
});
|
|
77
|
+
### Typed JSON messaging
|
|
125
78
|
|
|
126
|
-
|
|
79
|
+
Values are serialized and parsed for you — handlers receive the parsed value.
|
|
127
80
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
console.log(
|
|
81
|
+
```javascript
|
|
82
|
+
node.enableJson();
|
|
83
|
+
node.onJson('greeting', (peerId, value) => console.log(peerId, value.hello));
|
|
84
|
+
node.start();
|
|
85
|
+
node.broadcastJson('greeting', { hello: 'world' });
|
|
131
86
|
```
|
|
132
87
|
|
|
133
|
-
###
|
|
88
|
+
### File transfer
|
|
134
89
|
|
|
135
90
|
```javascript
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const client = new RatsClient(8080);
|
|
139
|
-
client.start();
|
|
140
|
-
|
|
141
|
-
// Subscribe to a topic
|
|
142
|
-
client.subscribeToTopic('general-chat');
|
|
91
|
+
node.enableFileTransfer('./tmp'); // in-progress downloads live here
|
|
143
92
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
93
|
+
node.onFileOffer((peerId, transferId, name, size, isDirectory) => {
|
|
94
|
+
node.acceptFile(peerId, transferId, `./downloads/${name}`);
|
|
95
|
+
});
|
|
96
|
+
node.onFileProgress((transferId, peerId, done, total) => {
|
|
97
|
+
console.log(`${transferId}: ${done}/${total}`);
|
|
98
|
+
});
|
|
99
|
+
node.onFileComplete((transferId, success, path) => {
|
|
100
|
+
console.log(`${transferId} ${success ? 'done' : 'failed'} ${path}`);
|
|
101
|
+
});
|
|
151
102
|
|
|
152
|
-
|
|
103
|
+
node.start();
|
|
104
|
+
const transferId = node.sendFile(peerId, './myfile.txt'); // 0 on failure
|
|
153
105
|
```
|
|
154
106
|
|
|
155
|
-
|
|
107
|
+
### NAT traversal
|
|
156
108
|
|
|
157
|
-
|
|
109
|
+
Port forwarding is the easy path; hole punching covers the networks where it
|
|
110
|
+
fails. Both are opt-in, and punching needs peers that relay the rendezvous.
|
|
158
111
|
|
|
159
|
-
|
|
112
|
+
```javascript
|
|
113
|
+
node.enablePortMapping(); // UPnP IGD + NAT-PMP
|
|
114
|
+
node.enableHolePunch(true); // true = also relay other peers' rendezvous
|
|
115
|
+
node.enableRelay(false); // last resort; true = also carry others' connections
|
|
116
|
+
node.start();
|
|
160
117
|
|
|
161
|
-
|
|
118
|
+
node.punchPeer(peerId); // success arrives as onPeerConnected
|
|
119
|
+
console.log(node.natMapping); // NatMapping.ENDPOINT_INDEPENDENT ⇒ punchable
|
|
120
|
+
```
|
|
162
121
|
|
|
163
|
-
|
|
122
|
+
A symmetric NAT cannot be punched at all, and that is what `enableRelay` is for: the
|
|
123
|
+
connection itself is routed through a node both ends already reach. It stays
|
|
124
|
+
encrypted end to end — the relay moves ciphertext — and the peer behaves like any
|
|
125
|
+
other, except that `peerTransport(peerId)` reports `Transport.RELAY`. With both
|
|
126
|
+
enabled the ladder runs itself: a punch that cannot work falls back to a relay, and
|
|
127
|
+
a relayed peer keeps trying to become a direct one.
|
|
164
128
|
|
|
165
|
-
|
|
166
|
-
- `stop(): void` - Stop the client
|
|
167
|
-
- `connect(host: string, port: number): boolean` - Connect to a peer
|
|
168
|
-
- `connectWithStrategy(host: string, port: number, strategy: number): boolean` - Connect with specific strategy
|
|
169
|
-
- `disconnect(peerId: string): void` - Disconnect from a peer
|
|
129
|
+
## API
|
|
170
130
|
|
|
171
|
-
|
|
131
|
+
### Construction
|
|
172
132
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
- `broadcastBinary(data: Buffer): number` - Broadcast binary to all peers
|
|
178
|
-
- `broadcastJson(jsonStr: string): number` - Broadcast JSON to all peers
|
|
133
|
+
```javascript
|
|
134
|
+
new RatsNode(port) // listen on port (0 = ephemeral)
|
|
135
|
+
new RatsNode(config) // full config
|
|
136
|
+
```
|
|
179
137
|
|
|
180
|
-
|
|
138
|
+
| config field | default | meaning |
|
|
139
|
+
|---|---|---|
|
|
140
|
+
| `listenPort` | `0` | inbound port shared by both transports; 0 = ephemeral |
|
|
141
|
+
| `enableListen` | `true` | `false` makes a dial-only node |
|
|
142
|
+
| `bindAddress` | `"::"` | dual-stack wildcard by default |
|
|
143
|
+
| `security` | `Security.NOISE` | or `Security.PLAINTEXT` |
|
|
144
|
+
| `dataDir` | — | persistent identity + subsystem state; omit for an ephemeral identity |
|
|
145
|
+
| `protocol` | `"librats/1.0"` | handshake app id; peers whose protocol differs cannot connect |
|
|
146
|
+
| `maxPeers` | `0` | established-peer cap; 0 = unlimited |
|
|
147
|
+
| `enableTcp` / `enableUdp` | `true` | which wires to accept and dial on |
|
|
148
|
+
| `preferredTransport` | `Transport.UDP` | which one a dial tries first |
|
|
149
|
+
| `transportFallbackMs` | `1200` | delay before racing the other; 0 disables |
|
|
181
150
|
|
|
182
|
-
|
|
183
|
-
- `getOurPeerId(): string | null` - Get our peer ID
|
|
184
|
-
- `getPeerIds(): string[]` - Get list of connected peer IDs
|
|
185
|
-
- `getConnectionStatistics(): string | null` - Get connection statistics as JSON
|
|
151
|
+
### Lifecycle
|
|
186
152
|
|
|
187
|
-
|
|
153
|
+
`start()` · `stop()` · `destroy()`
|
|
188
154
|
|
|
189
|
-
|
|
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
|
|
192
|
-
- `rejectFileTransfer(transferId: string, reason?: string): boolean` - Reject file transfer
|
|
193
|
-
- `cancelFileTransfer(transferId: string): boolean` - Cancel file transfer
|
|
194
|
-
- `pauseFileTransfer(transferId: string): boolean` - Pause file transfer
|
|
195
|
-
- `resumeFileTransfer(transferId: string): boolean` - Resume file transfer
|
|
155
|
+
### Properties
|
|
196
156
|
|
|
197
|
-
|
|
157
|
+
`listenPort` · `localId` · `protocol` · `transports` · `peerCount` · `peerIds` ·
|
|
158
|
+
`maxPeers` *(settable)* · `natMapping`
|
|
198
159
|
|
|
199
|
-
|
|
200
|
-
- `subscribeToTopic(topic: string): boolean` - Subscribe to topic
|
|
201
|
-
- `unsubscribeFromTopic(topic: string): boolean` - Unsubscribe from topic
|
|
202
|
-
- `publishToTopic(topic: string, message: string): boolean` - Publish message
|
|
203
|
-
- `publishJsonToTopic(topic: string, jsonStr: string): boolean` - Publish JSON
|
|
204
|
-
- `getSubscribedTopics(): string[]` - Get subscribed topics
|
|
205
|
-
- `getTopicPeers(topic: string): string[]` - Get peers in topic
|
|
160
|
+
### Connections
|
|
206
161
|
|
|
207
|
-
|
|
162
|
+
`connect(host, port)` · `peerTransport(peerId)` · `peerTransports(peerId)`
|
|
208
163
|
|
|
209
|
-
|
|
210
|
-
- `stopDhtDiscovery(): void` - Stop DHT discovery
|
|
211
|
-
- `isDhtRunning(): boolean` - Check if DHT is running
|
|
212
|
-
- `announceForHash(contentHash: string, port: number, callback?: (peers: string[]) => void): boolean` - Announce for hash with optional peer discovery callback
|
|
164
|
+
### Raw channel messaging
|
|
213
165
|
|
|
214
|
-
|
|
166
|
+
`send(peerId, channel, data)` · `broadcast(channel, data)` ·
|
|
167
|
+
`on(channel, (peerId, data) => …)` — `data` is a `Buffer` in, `string | Buffer` out
|
|
215
168
|
|
|
216
|
-
|
|
217
|
-
- `isEncryptionEnabled(): boolean` - Check if encryption is enabled
|
|
218
|
-
- `generateEncryptionKey(): string | null` - Generate new encryption key
|
|
219
|
-
- `setEncryptionKey(keyHex: string): boolean` - Set encryption key
|
|
220
|
-
- `getEncryptionKey(): string | null` - Get current encryption key
|
|
169
|
+
### Peer events *(before start)*
|
|
221
170
|
|
|
222
|
-
|
|
171
|
+
`onPeerConnected(cb)` · `onPeerDisconnected(cb)`
|
|
223
172
|
|
|
224
|
-
|
|
225
|
-
- `onString(callback: (peerId: string, message: string) => void): void` - Set string message callback
|
|
226
|
-
- `onBinary(callback: (peerId: string, data: Buffer) => void): void` - Set binary message callback
|
|
227
|
-
- `onJson(callback: (peerId: string, jsonStr: string) => void): void` - Set JSON message callback
|
|
228
|
-
- `onDisconnect(callback: (peerId: string) => void): void` - Set disconnect callback
|
|
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`)
|
|
173
|
+
### Subsystems *(enable before start)*
|
|
231
174
|
|
|
232
|
-
|
|
175
|
+
| subsystem | enable | then |
|
|
176
|
+
|---|---|---|
|
|
177
|
+
| DHT discovery | `enableDht(dhtPort?, discoveryKey?)` | — |
|
|
178
|
+
| mDNS discovery | `enableMdns()` | — |
|
|
179
|
+
| NAT port mapping | `enablePortMapping(upnp?, natpmp?)` | — |
|
|
180
|
+
| Hole punching | `enableHolePunch(serveAsRelay?)` | `punchPeer(peerId)`, `natMapping` |
|
|
181
|
+
| Relaying | `enableRelay(serveAsRelay?)` | `connectViaRelay(peerId)` |
|
|
182
|
+
| Pub/sub | `enablePubsub()` | `subscribe(topic, cb)`, `unsubscribe(topic)`, `publish(topic, data)` |
|
|
183
|
+
| Typed JSON | `enableJson()` | `onJson(type, cb)`, `onceJson(type, cb)`, `offJson(type)`, `sendJson(peerId, type, value)`, `broadcastJson(type, value)` |
|
|
184
|
+
| File transfer | `enableFileTransfer(tempDir?)` | `onFileOffer/onFileProgress/onFileComplete`, `sendFile`, `sendDirectory`, `acceptFile`, `rejectFile`, `cancelFile`, `pauseFile`, `resumeFile` |
|
|
185
|
+
| Liveness | `enablePing()` | `peerRttMs(peerId)` — ms, or -1 if unknown |
|
|
186
|
+
| Reconnection | `enableReconnect()` | `addReconnect(host, port)`, `removeReconnect(host, port)` |
|
|
233
187
|
|
|
234
|
-
|
|
235
|
-
- `getVersion(): VersionInfo` - Get version components
|
|
236
|
-
- `getGitDescribe(): string` - Get git describe string
|
|
237
|
-
- `getAbi(): number` - Get ABI version
|
|
188
|
+
### Module level
|
|
238
189
|
|
|
239
|
-
|
|
190
|
+
`version()` · `versionInfo()` · `gitDescribe()` · `abi()` ·
|
|
191
|
+
`setLogLevel(level)` · `setLogFile(path?)` ·
|
|
192
|
+
`Security` · `Transport` · `TransportMask` · `NatMapping` · `LogLevel`
|
|
240
193
|
|
|
241
|
-
|
|
194
|
+
## TypeScript
|
|
242
195
|
|
|
243
|
-
|
|
244
|
-
- `ConnectionStrategy.STUN_ASSISTED` - STUN-assisted connection
|
|
245
|
-
- `ConnectionStrategy.ICE_FULL` - Full ICE negotiation
|
|
246
|
-
- `ConnectionStrategy.TURN_RELAY` - TURN relay connection
|
|
247
|
-
- `ConnectionStrategy.AUTO_ADAPTIVE` - Automatic strategy selection
|
|
196
|
+
Definitions ship with the package.
|
|
248
197
|
|
|
249
|
-
|
|
198
|
+
```typescript
|
|
199
|
+
import { RatsNode, Security } from 'librats';
|
|
250
200
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
- `ErrorCodes.NOT_RUNNING` - Client not running
|
|
255
|
-
- `ErrorCodes.OPERATION_FAILED` - Operation failed
|
|
256
|
-
- `ErrorCodes.PEER_NOT_FOUND` - Peer not found
|
|
257
|
-
- `ErrorCodes.MEMORY_ALLOCATION` - Memory allocation error
|
|
258
|
-
- `ErrorCodes.JSON_PARSE` - JSON parsing error
|
|
201
|
+
const node = new RatsNode({ listenPort: 8080, security: Security.NOISE });
|
|
202
|
+
node.start();
|
|
203
|
+
```
|
|
259
204
|
|
|
260
205
|
## Examples
|
|
261
206
|
|
|
262
|
-
The `examples/` directory contains comprehensive examples:
|
|
263
|
-
|
|
264
|
-
- **`basic_client.js`** - Basic peer-to-peer networking and messaging
|
|
265
|
-
- **`file_transfer.js`** - File and directory transfer with interactive CLI
|
|
266
|
-
- **`gossipsub_chat.js`** - Topic-based chat using GossipSub
|
|
267
|
-
|
|
268
|
-
### Running Examples
|
|
269
|
-
|
|
270
207
|
```bash
|
|
271
|
-
|
|
272
|
-
node examples/basic_client.js
|
|
273
|
-
|
|
274
|
-
# Basic client connecting to another peer
|
|
208
|
+
node examples/basic_client.js 8080
|
|
275
209
|
node examples/basic_client.js 8081 127.0.0.1 8080
|
|
276
|
-
|
|
277
|
-
# File transfer client
|
|
278
210
|
node examples/file_transfer.js 8080
|
|
279
|
-
|
|
280
|
-
# GossipSub chat
|
|
281
|
-
node examples/gossipsub_chat.js 8080 Alice
|
|
211
|
+
node examples/gossipsub_chat.js 8080 Alice lobby
|
|
282
212
|
```
|
|
283
213
|
|
|
284
214
|
## Testing
|
|
285
215
|
|
|
286
|
-
Run the test suite:
|
|
287
|
-
|
|
288
216
|
```bash
|
|
289
217
|
npm test
|
|
218
|
+
npm run verify # check a fresh install end-to-end
|
|
219
|
+
LIBRATS_DEBUG=1 node examples/basic_client.js # log which addon was loaded
|
|
290
220
|
```
|
|
291
221
|
|
|
292
|
-
Or run the simple test script:
|
|
293
|
-
|
|
294
|
-
```bash
|
|
295
|
-
node test/test.js
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
## Building from Source
|
|
299
|
-
|
|
300
|
-
### Debug Build
|
|
301
|
-
|
|
302
|
-
```bash
|
|
303
|
-
npm run build
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
### Clean Build
|
|
307
|
-
|
|
308
|
-
```bash
|
|
309
|
-
npm run clean
|
|
310
|
-
npm run build
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
## TypeScript Support
|
|
314
|
-
|
|
315
|
-
Full TypeScript definitions are included. Import types:
|
|
316
|
-
|
|
317
|
-
```typescript
|
|
318
|
-
import { RatsClient, ConnectionStrategy, ErrorCodes, VersionInfo } from 'librats';
|
|
319
|
-
|
|
320
|
-
const client: RatsClient = new RatsClient(8080);
|
|
321
|
-
client.start();
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
## Error Handling
|
|
325
|
-
|
|
326
|
-
Most operations return boolean values indicating success/failure. For detailed error information, check the console output or use the statistics functions:
|
|
327
|
-
|
|
328
|
-
```javascript
|
|
329
|
-
const stats = client.getConnectionStatistics();
|
|
330
|
-
if (stats) {
|
|
331
|
-
const parsed = JSON.parse(stats);
|
|
332
|
-
console.log('Connection stats:', parsed);
|
|
333
|
-
}
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
## Performance Considerations
|
|
337
|
-
|
|
338
|
-
- Use binary messages for large data transfers
|
|
339
|
-
- Enable encryption only when needed (adds overhead)
|
|
340
|
-
- Monitor file transfer progress for large files
|
|
341
|
-
- Use appropriate connection strategies for your network environment
|
|
342
|
-
|
|
343
|
-
## Platform Support
|
|
344
|
-
|
|
345
|
-
- **Windows** - Requires Visual Studio Build Tools
|
|
346
|
-
- **Linux** - Requires build-essential
|
|
347
|
-
- **macOS** - Requires Xcode Command Line Tools
|
|
348
|
-
- **Android** - Supported via native Android bindings (separate package)
|
|
349
|
-
|
|
350
|
-
## Contributing
|
|
351
|
-
|
|
352
|
-
1. Fork the repository
|
|
353
|
-
2. Create a feature branch
|
|
354
|
-
3. Make your changes
|
|
355
|
-
4. Add tests for new functionality
|
|
356
|
-
5. Submit a pull request
|
|
357
|
-
|
|
358
222
|
## License
|
|
359
223
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
## Troubleshooting
|
|
363
|
-
|
|
364
|
-
### Build Issues
|
|
365
|
-
|
|
366
|
-
**Windows**: Ensure Visual Studio Build Tools are installed
|
|
367
|
-
```bash
|
|
368
|
-
npm install --global windows-build-tools
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
**Linux**: Install build dependencies
|
|
372
|
-
```bash
|
|
373
|
-
sudo apt install build-essential python3
|
|
374
|
-
```
|
|
375
|
-
|
|
376
|
-
**macOS**: Install Xcode Command Line Tools
|
|
377
|
-
```bash
|
|
378
|
-
xcode-select --install
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
### Runtime Issues
|
|
382
|
-
|
|
383
|
-
**Port already in use**: Choose a different port or kill the process using the port
|
|
384
|
-
```bash
|
|
385
|
-
# Find process using port
|
|
386
|
-
netstat -tulpn | grep :8080
|
|
387
|
-
|
|
388
|
-
# Kill process
|
|
389
|
-
kill -9 <pid>
|
|
390
|
-
```
|
|
391
|
-
|
|
392
|
-
**Permission denied**: Run with appropriate permissions or use ports > 1024
|
|
393
|
-
|
|
394
|
-
**Connection timeout**: Check firewall settings and ensure peers are reachable
|
|
395
|
-
|
|
396
|
-
### Debug Mode
|
|
397
|
-
|
|
398
|
-
Enable debug logging by setting environment variable:
|
|
399
|
-
```bash
|
|
400
|
-
export LIBRATS_DEBUG=1
|
|
401
|
-
node examples/basic_client.js
|
|
402
|
-
```
|
|
403
|
-
|
|
404
|
-
## Support
|
|
405
|
-
|
|
406
|
-
- [GitHub Issues](https://github.com/librats/librats/issues)
|
|
407
|
-
- [Documentation](https://librats.github.io/)
|
|
408
|
-
- [Examples Repository](https://github.com/librats/librats/tree/main/nodejs/examples)
|
|
409
|
-
|
|
410
|
-
For more advanced usage, see the [C API documentation](../docs/) and the [main project README](../README.md).
|
|
224
|
+
MIT — see [LICENSE](../LICENSE).
|
package/binding.gyp
CHANGED
|
@@ -8,8 +8,15 @@
|
|
|
8
8
|
],
|
|
9
9
|
"include_dirs": [
|
|
10
10
|
"<!@(node -p \"require('node-addon-api').include\")",
|
|
11
|
+
# librats headers. "librats/bindings/rats.h" is the canonical C ABI; it
|
|
12
|
+
# pulls in librats/util/rats_export.h. These paths are the include ROOT
|
|
13
|
+
# (the parent of librats/), matching CMakeLists.txt. native-src/src is
|
|
14
|
+
# used when the package is installed from npm (sources bundled there);
|
|
15
|
+
# ../src in dev.
|
|
11
16
|
"native-src/src",
|
|
12
17
|
"../src",
|
|
18
|
+
# Generated headers (version.h, features.h) produced by the CMake build into
|
|
19
|
+
# build-native/src/. Mirrors PROJECT_BINARY_DIR/src in CMakeLists.txt.
|
|
13
20
|
"build-native/src"
|
|
14
21
|
],
|
|
15
22
|
"dependencies": [
|
|
@@ -17,20 +24,26 @@
|
|
|
17
24
|
],
|
|
18
25
|
"cflags!": [ "-fno-exceptions" ],
|
|
19
26
|
"cflags_cc!": [ "-fno-exceptions" ],
|
|
27
|
+
"cflags_cc": [ "-std=c++17" ],
|
|
20
28
|
"xcode_settings": {
|
|
21
29
|
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
|
22
30
|
"CLANG_CXX_LIBRARY": "libc++",
|
|
23
|
-
"
|
|
31
|
+
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
|
|
32
|
+
"MACOSX_DEPLOYMENT_TARGET": "10.13"
|
|
24
33
|
},
|
|
25
34
|
"msvs_settings": {
|
|
26
|
-
"VCCLCompilerTool": {
|
|
35
|
+
"VCCLCompilerTool": {
|
|
27
36
|
"ExceptionHandling": 1,
|
|
28
|
-
"RuntimeLibrary": 2
|
|
37
|
+
"RuntimeLibrary": 2,
|
|
38
|
+
"AdditionalOptions": [ "/std:c++17" ]
|
|
29
39
|
}
|
|
30
40
|
},
|
|
31
41
|
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
|
|
32
42
|
"conditions": [
|
|
33
43
|
["OS=='win'", {
|
|
44
|
+
# Link the prebuilt static archive produced by scripts/build-librats.js
|
|
45
|
+
# (CMake builds rats.lib with RATS_BINDINGS=ON, so the rats_* C ABI is
|
|
46
|
+
# already inside). Plus the platform networking/crypto libs.
|
|
34
47
|
"configurations": {
|
|
35
48
|
"Debug": {
|
|
36
49
|
"msvs_settings": {
|