librats 0.3.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +405 -405
- package/binding.gyp +96 -95
- package/lib/index.d.ts +522 -522
- package/lib/index.js +82 -82
- package/native-src/3rdparty/android/ifaddrs-android.c +600 -0
- package/native-src/3rdparty/android/ifaddrs-android.h +54 -0
- package/native-src/CMakeLists.txt +360 -0
- package/native-src/LICENSE +21 -0
- package/native-src/src/bencode.cpp +485 -0
- package/native-src/src/bencode.h +145 -0
- package/native-src/src/bittorrent.cpp +3682 -0
- package/native-src/src/bittorrent.h +731 -0
- package/native-src/src/dht.cpp +2342 -0
- package/native-src/src/dht.h +501 -0
- package/native-src/src/encrypted_socket.cpp +817 -0
- package/native-src/src/encrypted_socket.h +239 -0
- package/native-src/src/file_transfer.cpp +1808 -0
- package/native-src/src/file_transfer.h +567 -0
- package/native-src/src/fs.cpp +639 -0
- package/native-src/src/fs.h +108 -0
- package/native-src/src/gossipsub.cpp +1137 -0
- package/native-src/src/gossipsub.h +403 -0
- package/native-src/src/ice.cpp +1386 -0
- package/native-src/src/ice.h +328 -0
- package/native-src/src/json.hpp +25526 -0
- package/native-src/src/krpc.cpp +558 -0
- package/native-src/src/krpc.h +145 -0
- package/native-src/src/librats.cpp +2715 -0
- package/native-src/src/librats.h +1729 -0
- package/native-src/src/librats_bittorrent.cpp +167 -0
- package/native-src/src/librats_c.cpp +1317 -0
- package/native-src/src/librats_c.h +237 -0
- package/native-src/src/librats_encryption.cpp +123 -0
- package/native-src/src/librats_file_transfer.cpp +226 -0
- package/native-src/src/librats_gossipsub.cpp +293 -0
- package/native-src/src/librats_ice.cpp +515 -0
- package/native-src/src/librats_logging.cpp +158 -0
- package/native-src/src/librats_mdns.cpp +171 -0
- package/native-src/src/librats_nat.cpp +571 -0
- package/native-src/src/librats_persistence.cpp +815 -0
- package/native-src/src/logger.h +412 -0
- package/native-src/src/mdns.cpp +1178 -0
- package/native-src/src/mdns.h +253 -0
- package/native-src/src/network_utils.cpp +598 -0
- package/native-src/src/network_utils.h +162 -0
- package/native-src/src/noise.cpp +981 -0
- package/native-src/src/noise.h +227 -0
- package/native-src/src/os.cpp +371 -0
- package/native-src/src/os.h +40 -0
- package/native-src/src/rats_export.h +17 -0
- package/native-src/src/sha1.cpp +163 -0
- package/native-src/src/sha1.h +42 -0
- package/native-src/src/socket.cpp +1376 -0
- package/native-src/src/socket.h +309 -0
- package/native-src/src/stun.cpp +484 -0
- package/native-src/src/stun.h +349 -0
- package/native-src/src/threadmanager.cpp +105 -0
- package/native-src/src/threadmanager.h +53 -0
- package/native-src/src/tracker.cpp +1110 -0
- package/native-src/src/tracker.h +268 -0
- package/native-src/src/version.cpp +24 -0
- package/native-src/src/version.h.in +45 -0
- package/native-src/version.rc.in +31 -0
- package/package.json +62 -68
- package/scripts/build-librats.js +241 -194
- package/scripts/postinstall.js +52 -52
- package/scripts/prepare-package.js +187 -91
- package/scripts/verify-installation.js +119 -119
- package/src/librats_node.cpp +1174 -1174
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <string>
|
|
4
|
+
#include <vector>
|
|
5
|
+
|
|
6
|
+
namespace librats {
|
|
7
|
+
namespace network_utils {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Resolve hostname to IP address
|
|
11
|
+
* @param hostname The hostname to resolve (can be hostname or IP address)
|
|
12
|
+
* @return IP address string, or empty string on error
|
|
13
|
+
*
|
|
14
|
+
* Example usage:
|
|
15
|
+
* std::string ip = network_utils::resolve_hostname("google.com");
|
|
16
|
+
* std::string ip2 = network_utils::resolve_hostname("192.168.1.1"); // returns same IP
|
|
17
|
+
*/
|
|
18
|
+
std::string resolve_hostname(const std::string& hostname);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Resolve hostname to IPv6 address
|
|
22
|
+
* @param hostname The hostname to resolve (can be hostname or IPv6 address)
|
|
23
|
+
* @return IPv6 address string, or empty string on error
|
|
24
|
+
*
|
|
25
|
+
* Example usage:
|
|
26
|
+
* std::string ipv6 = network_utils::resolve_hostname_v6("google.com");
|
|
27
|
+
* std::string ipv6_2 = network_utils::resolve_hostname_v6("::1"); // returns same IPv6
|
|
28
|
+
*/
|
|
29
|
+
std::string resolve_hostname_v6(const std::string& hostname);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Check if a string is a valid IPv4 address
|
|
33
|
+
* @param ip_str The string to validate
|
|
34
|
+
* @return true if valid IPv4 address, false otherwise
|
|
35
|
+
*
|
|
36
|
+
* Example usage:
|
|
37
|
+
* bool valid = network_utils::is_valid_ipv4("192.168.1.1"); // true
|
|
38
|
+
* bool invalid = network_utils::is_valid_ipv4("invalid.ip"); // false
|
|
39
|
+
*/
|
|
40
|
+
bool is_valid_ipv4(const std::string& ip_str);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Check if a string is a valid IPv6 address
|
|
44
|
+
* @param ip_str The string to validate
|
|
45
|
+
* @return true if valid IPv6 address, false otherwise
|
|
46
|
+
*
|
|
47
|
+
* Example usage:
|
|
48
|
+
* bool valid = network_utils::is_valid_ipv6("::1"); // true
|
|
49
|
+
* bool valid2 = network_utils::is_valid_ipv6("2001:db8::1"); // true
|
|
50
|
+
* bool invalid = network_utils::is_valid_ipv6("invalid.ip"); // false
|
|
51
|
+
*/
|
|
52
|
+
bool is_valid_ipv6(const std::string& ip_str);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Check if a string is a hostname (not an IP address)
|
|
56
|
+
* @param str The string to check
|
|
57
|
+
* @return true if it's a hostname, false if it's an IP address
|
|
58
|
+
*
|
|
59
|
+
* Example usage:
|
|
60
|
+
* bool is_host = network_utils::is_hostname("google.com"); // true
|
|
61
|
+
* bool is_ip = network_utils::is_hostname("192.168.1.1"); // false
|
|
62
|
+
* bool is_ipv6 = network_utils::is_hostname("::1"); // false
|
|
63
|
+
*/
|
|
64
|
+
bool is_hostname(const std::string& str);
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Convert hostname or IP to IP address (alias for resolve_hostname)
|
|
68
|
+
* @param host The hostname or IP address to convert
|
|
69
|
+
* @return IP address string, or empty string on error
|
|
70
|
+
*
|
|
71
|
+
* Example usage:
|
|
72
|
+
* std::string ip = network_utils::to_ip_address("example.com");
|
|
73
|
+
*/
|
|
74
|
+
std::string to_ip_address(const std::string& host);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get all IP addresses for a hostname
|
|
78
|
+
* @param hostname The hostname to resolve
|
|
79
|
+
* @return Vector of IP addresses, empty if resolution fails
|
|
80
|
+
*
|
|
81
|
+
* Example usage:
|
|
82
|
+
* auto ips = network_utils::resolve_all_addresses("google.com");
|
|
83
|
+
* for (const auto& ip : ips) {
|
|
84
|
+
* std::cout << "IP: " << ip << std::endl;
|
|
85
|
+
* }
|
|
86
|
+
*/
|
|
87
|
+
std::vector<std::string> resolve_all_addresses(const std::string& hostname);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get all IPv6 addresses for a hostname
|
|
91
|
+
* @param hostname The hostname to resolve
|
|
92
|
+
* @return Vector of IPv6 addresses, empty if resolution fails
|
|
93
|
+
*
|
|
94
|
+
* Example usage:
|
|
95
|
+
* auto ipv6s = network_utils::resolve_all_addresses_v6("google.com");
|
|
96
|
+
* for (const auto& ipv6 : ipv6s) {
|
|
97
|
+
* std::cout << "IPv6: " << ipv6 << std::endl;
|
|
98
|
+
* }
|
|
99
|
+
*/
|
|
100
|
+
std::vector<std::string> resolve_all_addresses_v6(const std::string& hostname);
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Get all IP addresses (both IPv4 and IPv6) for a hostname
|
|
104
|
+
* @param hostname The hostname to resolve
|
|
105
|
+
* @return Vector of IP addresses, empty if resolution fails
|
|
106
|
+
*
|
|
107
|
+
* Example usage:
|
|
108
|
+
* auto ips = network_utils::resolve_all_addresses_dual("google.com");
|
|
109
|
+
* for (const auto& ip : ips) {
|
|
110
|
+
* std::cout << "IP: " << ip << std::endl;
|
|
111
|
+
* }
|
|
112
|
+
*/
|
|
113
|
+
std::vector<std::string> resolve_all_addresses_dual(const std::string& hostname);
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Get all local network interface addresses (IPv4 and IPv6)
|
|
117
|
+
* @return Vector of local IP addresses from all network interfaces
|
|
118
|
+
*
|
|
119
|
+
* Example usage:
|
|
120
|
+
* auto local_ips = network_utils::get_local_interface_addresses();
|
|
121
|
+
* for (const auto& ip : local_ips) {
|
|
122
|
+
* std::cout << "Local IP: " << ip << std::endl;
|
|
123
|
+
* }
|
|
124
|
+
*/
|
|
125
|
+
std::vector<std::string> get_local_interface_addresses();
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Get all local IPv4 network interface addresses
|
|
129
|
+
* @return Vector of local IPv4 addresses from all network interfaces
|
|
130
|
+
*
|
|
131
|
+
* Example usage:
|
|
132
|
+
* auto local_ipv4s = network_utils::get_local_interface_addresses_v4();
|
|
133
|
+
* for (const auto& ip : local_ipv4s) {
|
|
134
|
+
* std::cout << "Local IPv4: " << ip << std::endl;
|
|
135
|
+
* }
|
|
136
|
+
*/
|
|
137
|
+
std::vector<std::string> get_local_interface_addresses_v4();
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Get all local IPv6 network interface addresses
|
|
141
|
+
* @return Vector of local IPv6 addresses from all network interfaces
|
|
142
|
+
*
|
|
143
|
+
* Example usage:
|
|
144
|
+
* auto local_ipv6s = network_utils::get_local_interface_addresses_v6();
|
|
145
|
+
* for (const auto& ip : local_ipv6s) {
|
|
146
|
+
* std::cout << "Local IPv6: " << ip << std::endl;
|
|
147
|
+
* }
|
|
148
|
+
*/
|
|
149
|
+
std::vector<std::string> get_local_interface_addresses_v6();
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Check if an IP address is a local interface address
|
|
153
|
+
* @param ip_address The IP address to check
|
|
154
|
+
* @return true if the IP address belongs to a local network interface
|
|
155
|
+
*
|
|
156
|
+
* Example usage:
|
|
157
|
+
* bool is_local = network_utils::is_local_interface_address("192.168.1.100");
|
|
158
|
+
*/
|
|
159
|
+
bool is_local_interface_address(const std::string& ip_address);
|
|
160
|
+
|
|
161
|
+
} // namespace network_utils
|
|
162
|
+
} // namespace librats
|