visaljs 0.0.10 → 0.0.11

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.
Files changed (221) hide show
  1. package/README.md +12 -4
  2. package/THIRD_PARTY_LICENSES +31 -1
  3. package/cli.js +962 -68
  4. package/node/include/js_node.h +11 -1
  5. package/node/prelude/_http_common.js +29 -0
  6. package/node/prelude/async_hooks.js +50 -11
  7. package/node/prelude/child_process.js +31 -4
  8. package/node/prelude/console.js +311 -143
  9. package/node/prelude/crypto.js +6 -4
  10. package/node/prelude/dgram.js +1169 -0
  11. package/node/prelude/diagnostics_channel.js +3 -1
  12. package/node/prelude/dns.js +250 -45
  13. package/node/prelude/dns_promises.js +8 -2
  14. package/node/prelude/fs_promises.js +9 -1
  15. package/node/prelude/http.js +395 -86
  16. package/node/prelude/https.js +13 -4
  17. package/node/prelude/internal/console_class.js +7 -0
  18. package/node/prelude/internal/console_global.js +25 -0
  19. package/node/prelude/internal/crypto/key_encryption.js +217 -0
  20. package/node/prelude/internal/crypto/keys.js +161 -26
  21. package/node/prelude/internal/crypto/random.js +24 -0
  22. package/node/prelude/internal/crypto/util.js +2 -1
  23. package/node/prelude/internal/crypto_x509.js +161 -0
  24. package/node/prelude/internal/dns_classes.js +6 -0
  25. package/node/prelude/internal/dns_resolver.js +371 -0
  26. package/node/prelude/internal/errors.js +9 -0
  27. package/node/prelude/internal/events_on.js +82 -37
  28. package/node/prelude/internal/features.js +8 -4
  29. package/node/prelude/internal/fs_filehandle.js +10 -4
  30. package/node/prelude/internal/perf_histogram.js +1 -1
  31. package/node/prelude/internal/process_more.js +32 -17
  32. package/node/prelude/internal/process_signals.js +8 -2
  33. package/node/prelude/internal/punycode.ts +163 -0
  34. package/node/prelude/internal/readline.js +648 -274
  35. package/node/prelude/internal/readline_editor.js +1240 -0
  36. package/node/prelude/internal/string_width.js +43 -0
  37. package/node/prelude/internal/tls/common.js +145 -33
  38. package/node/prelude/internal/tls/wrap.js +182 -49
  39. package/node/prelude/internal/tls/x509.js +4 -1
  40. package/node/prelude/internal/udp.js +177 -0
  41. package/node/prelude/net.js +13 -1
  42. package/node/prelude/os.js +24 -6
  43. package/node/prelude/perf_hooks.js +37 -2
  44. package/node/prelude/punycode.js +2 -130
  45. package/node/prelude/readline.js +113 -4
  46. package/node/prelude/readline_promises.js +56 -32
  47. package/node/prelude/tls.js +21 -4
  48. package/node/prelude/util.js +3 -16
  49. package/node/src/host_dns.c +623 -0
  50. package/node/src/host_http.c +12 -0
  51. package/node/src/host_net.c +46 -0
  52. package/node/src/host_os.c +1 -6
  53. package/node/src/host_sys.c +70 -0
  54. package/node/src/host_udp.c +418 -0
  55. package/node/third_party/c-ares/LICENSE.md +24 -0
  56. package/node/third_party/c-ares/config/darwin/ares_config.h +573 -0
  57. package/node/third_party/c-ares/config/freebsd/ares_config.h +573 -0
  58. package/node/third_party/c-ares/config/linux/ares_config.h +573 -0
  59. package/node/third_party/c-ares/config/openbsd/ares_config.h +583 -0
  60. package/node/third_party/c-ares/include/ares.h +1237 -0
  61. package/node/third_party/c-ares/include/ares_build.h +202 -0
  62. package/node/third_party/c-ares/include/ares_dns.h +127 -0
  63. package/node/third_party/c-ares/include/ares_dns_record.h +1119 -0
  64. package/node/third_party/c-ares/include/ares_nameser.h +510 -0
  65. package/node/third_party/c-ares/include/ares_version.h +47 -0
  66. package/node/third_party/c-ares/src/lib/ares_addrinfo2hostent.c +305 -0
  67. package/node/third_party/c-ares/src/lib/ares_addrinfo_localhost.c +245 -0
  68. package/node/third_party/c-ares/src/lib/ares_android.c +496 -0
  69. package/node/third_party/c-ares/src/lib/ares_android.h +38 -0
  70. package/node/third_party/c-ares/src/lib/ares_cancel.c +87 -0
  71. package/node/third_party/c-ares/src/lib/ares_close_sockets.c +137 -0
  72. package/node/third_party/c-ares/src/lib/ares_conn.c +511 -0
  73. package/node/third_party/c-ares/src/lib/ares_conn.h +202 -0
  74. package/node/third_party/c-ares/src/lib/ares_cookie.c +461 -0
  75. package/node/third_party/c-ares/src/lib/ares_data.c +168 -0
  76. package/node/third_party/c-ares/src/lib/ares_data.h +92 -0
  77. package/node/third_party/c-ares/src/lib/ares_destroy.c +159 -0
  78. package/node/third_party/c-ares/src/lib/ares_free_hostent.c +54 -0
  79. package/node/third_party/c-ares/src/lib/ares_free_string.c +33 -0
  80. package/node/third_party/c-ares/src/lib/ares_freeaddrinfo.c +67 -0
  81. package/node/third_party/c-ares/src/lib/ares_getaddrinfo.c +806 -0
  82. package/node/third_party/c-ares/src/lib/ares_getenv.c +38 -0
  83. package/node/third_party/c-ares/src/lib/ares_getenv.h +34 -0
  84. package/node/third_party/c-ares/src/lib/ares_gethostbyaddr.c +229 -0
  85. package/node/third_party/c-ares/src/lib/ares_gethostbyname.c +341 -0
  86. package/node/third_party/c-ares/src/lib/ares_getnameinfo.c +437 -0
  87. package/node/third_party/c-ares/src/lib/ares_hosts_file.c +960 -0
  88. package/node/third_party/c-ares/src/lib/ares_inet_net_pton.h +31 -0
  89. package/node/third_party/c-ares/src/lib/ares_init.c +631 -0
  90. package/node/third_party/c-ares/src/lib/ares_ipv6.h +115 -0
  91. package/node/third_party/c-ares/src/lib/ares_library_init.c +190 -0
  92. package/node/third_party/c-ares/src/lib/ares_metrics.c +261 -0
  93. package/node/third_party/c-ares/src/lib/ares_options.c +492 -0
  94. package/node/third_party/c-ares/src/lib/ares_parse_into_addrinfo.c +179 -0
  95. package/node/third_party/c-ares/src/lib/ares_private.h +648 -0
  96. package/node/third_party/c-ares/src/lib/ares_process.c +1649 -0
  97. package/node/third_party/c-ares/src/lib/ares_qcache.c +442 -0
  98. package/node/third_party/c-ares/src/lib/ares_query.c +151 -0
  99. package/node/third_party/c-ares/src/lib/ares_search.c +623 -0
  100. package/node/third_party/c-ares/src/lib/ares_send.c +300 -0
  101. package/node/third_party/c-ares/src/lib/ares_set_socket_functions.c +590 -0
  102. package/node/third_party/c-ares/src/lib/ares_setup.h +224 -0
  103. package/node/third_party/c-ares/src/lib/ares_socket.c +427 -0
  104. package/node/third_party/c-ares/src/lib/ares_socket.h +163 -0
  105. package/node/third_party/c-ares/src/lib/ares_sortaddrinfo.c +447 -0
  106. package/node/third_party/c-ares/src/lib/ares_strerror.c +91 -0
  107. package/node/third_party/c-ares/src/lib/ares_sysconfig.c +642 -0
  108. package/node/third_party/c-ares/src/lib/ares_sysconfig_files.c +851 -0
  109. package/node/third_party/c-ares/src/lib/ares_sysconfig_mac.c +373 -0
  110. package/node/third_party/c-ares/src/lib/ares_sysconfig_win.c +673 -0
  111. package/node/third_party/c-ares/src/lib/ares_timeout.c +162 -0
  112. package/node/third_party/c-ares/src/lib/ares_update_servers.c +1376 -0
  113. package/node/third_party/c-ares/src/lib/ares_version.c +36 -0
  114. package/node/third_party/c-ares/src/lib/config-dos.h +114 -0
  115. package/node/third_party/c-ares/src/lib/config-win32.h +396 -0
  116. package/node/third_party/c-ares/src/lib/dsa/ares_array.c +409 -0
  117. package/node/third_party/c-ares/src/lib/dsa/ares_htable.c +451 -0
  118. package/node/third_party/c-ares/src/lib/dsa/ares_htable.h +174 -0
  119. package/node/third_party/c-ares/src/lib/dsa/ares_htable_asvp.c +224 -0
  120. package/node/third_party/c-ares/src/lib/dsa/ares_htable_dict.c +230 -0
  121. package/node/third_party/c-ares/src/lib/dsa/ares_htable_strvp.c +210 -0
  122. package/node/third_party/c-ares/src/lib/dsa/ares_htable_szvp.c +188 -0
  123. package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpstr.c +186 -0
  124. package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpvp.c +194 -0
  125. package/node/third_party/c-ares/src/lib/dsa/ares_llist.c +385 -0
  126. package/node/third_party/c-ares/src/lib/dsa/ares_slist.c +479 -0
  127. package/node/third_party/c-ares/src/lib/dsa/ares_slist.h +207 -0
  128. package/node/third_party/c-ares/src/lib/event/ares_event.h +191 -0
  129. package/node/third_party/c-ares/src/lib/event/ares_event_configchg.c +746 -0
  130. package/node/third_party/c-ares/src/lib/event/ares_event_epoll.c +192 -0
  131. package/node/third_party/c-ares/src/lib/event/ares_event_kqueue.c +248 -0
  132. package/node/third_party/c-ares/src/lib/event/ares_event_poll.c +140 -0
  133. package/node/third_party/c-ares/src/lib/event/ares_event_select.c +159 -0
  134. package/node/third_party/c-ares/src/lib/event/ares_event_thread.c +575 -0
  135. package/node/third_party/c-ares/src/lib/event/ares_event_wake_pipe.c +172 -0
  136. package/node/third_party/c-ares/src/lib/event/ares_event_win32.c +981 -0
  137. package/node/third_party/c-ares/src/lib/event/ares_event_win32.h +161 -0
  138. package/node/third_party/c-ares/src/lib/include/ares_array.h +276 -0
  139. package/node/third_party/c-ares/src/lib/include/ares_buf.h +732 -0
  140. package/node/third_party/c-ares/src/lib/include/ares_htable_asvp.h +130 -0
  141. package/node/third_party/c-ares/src/lib/include/ares_htable_dict.h +123 -0
  142. package/node/third_party/c-ares/src/lib/include/ares_htable_strvp.h +130 -0
  143. package/node/third_party/c-ares/src/lib/include/ares_htable_szvp.h +118 -0
  144. package/node/third_party/c-ares/src/lib/include/ares_htable_vpstr.h +111 -0
  145. package/node/third_party/c-ares/src/lib/include/ares_htable_vpvp.h +128 -0
  146. package/node/third_party/c-ares/src/lib/include/ares_llist.h +239 -0
  147. package/node/third_party/c-ares/src/lib/include/ares_mem.h +41 -0
  148. package/node/third_party/c-ares/src/lib/include/ares_str.h +261 -0
  149. package/node/third_party/c-ares/src/lib/inet_net_pton.c +451 -0
  150. package/node/third_party/c-ares/src/lib/inet_ntop.c +219 -0
  151. package/node/third_party/c-ares/src/lib/legacy/ares_create_query.c +78 -0
  152. package/node/third_party/c-ares/src/lib/legacy/ares_expand_name.c +99 -0
  153. package/node/third_party/c-ares/src/lib/legacy/ares_expand_string.c +107 -0
  154. package/node/third_party/c-ares/src/lib/legacy/ares_fds.c +80 -0
  155. package/node/third_party/c-ares/src/lib/legacy/ares_getsock.c +85 -0
  156. package/node/third_party/c-ares/src/lib/legacy/ares_parse_a_reply.c +107 -0
  157. package/node/third_party/c-ares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
  158. package/node/third_party/c-ares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
  159. package/node/third_party/c-ares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
  160. package/node/third_party/c-ares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
  161. package/node/third_party/c-ares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
  162. package/node/third_party/c-ares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
  163. package/node/third_party/c-ares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
  164. package/node/third_party/c-ares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
  165. package/node/third_party/c-ares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
  166. package/node/third_party/c-ares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
  167. package/node/third_party/c-ares/src/lib/record/ares_dns_mapping.c +982 -0
  168. package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.c +309 -0
  169. package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.h +72 -0
  170. package/node/third_party/c-ares/src/lib/record/ares_dns_name.c +736 -0
  171. package/node/third_party/c-ares/src/lib/record/ares_dns_parse.c +1360 -0
  172. package/node/third_party/c-ares/src/lib/record/ares_dns_private.h +273 -0
  173. package/node/third_party/c-ares/src/lib/record/ares_dns_record.c +1701 -0
  174. package/node/third_party/c-ares/src/lib/record/ares_dns_write.c +1229 -0
  175. package/node/third_party/c-ares/src/lib/str/ares_buf.c +1510 -0
  176. package/node/third_party/c-ares/src/lib/str/ares_str.c +562 -0
  177. package/node/third_party/c-ares/src/lib/str/ares_strsplit.c +90 -0
  178. package/node/third_party/c-ares/src/lib/str/ares_strsplit.h +51 -0
  179. package/node/third_party/c-ares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
  180. package/node/third_party/c-ares/src/lib/util/ares_iface_ips.c +640 -0
  181. package/node/third_party/c-ares/src/lib/util/ares_iface_ips.h +140 -0
  182. package/node/third_party/c-ares/src/lib/util/ares_math.c +167 -0
  183. package/node/third_party/c-ares/src/lib/util/ares_math.h +58 -0
  184. package/node/third_party/c-ares/src/lib/util/ares_rand.c +389 -0
  185. package/node/third_party/c-ares/src/lib/util/ares_rand.h +36 -0
  186. package/node/third_party/c-ares/src/lib/util/ares_threads.c +613 -0
  187. package/node/third_party/c-ares/src/lib/util/ares_threads.h +60 -0
  188. package/node/third_party/c-ares/src/lib/util/ares_time.h +49 -0
  189. package/node/third_party/c-ares/src/lib/util/ares_timeval.c +95 -0
  190. package/node/third_party/c-ares/src/lib/util/ares_uri.c +1627 -0
  191. package/node/third_party/c-ares/src/lib/util/ares_uri.h +252 -0
  192. package/node/third_party/c-ares/src/lib/windows_port.c +29 -0
  193. package/package.json +1 -1
  194. package/prebuilt/darwin-arm64/cares-a6286c65ca9374a3.a +0 -0
  195. package/prebuilt/darwin-x64/cares-a6286c65ca9374a3.a +0 -0
  196. package/prebuilt/linux-arm64/cares-4ba05ac8e948af8e.a +0 -0
  197. package/prebuilt/linux-arm64-musl/cares-4ba05ac8e948af8e.a +0 -0
  198. package/prebuilt/linux-x64/cares-4ba05ac8e948af8e.a +0 -0
  199. package/prebuilt/linux-x64-musl/cares-4ba05ac8e948af8e.a +0 -0
  200. package/prebuilt/win32-x64/boringssl-ce573858472b7fc9.a +0 -0
  201. package/prebuilt/win32-x64/brotli-20d86a61f30baeb3.a +0 -0
  202. package/prebuilt/win32-x64/cares-49c9ec95162b912d.a +0 -0
  203. package/prebuilt/win32-x64/uv-b11bae65d7fced82.a +0 -0
  204. package/prebuilt/win32-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
  205. package/prebuilt/win32-x64/zstd-015315ac7c784c73.a +0 -0
  206. package/runtime/include/js_builtins.h +5 -0
  207. package/runtime/include/js_crypto.h +11 -0
  208. package/runtime/include/js_gc.h +13 -10
  209. package/runtime/include/js_jobs.h +2 -0
  210. package/runtime/include/js_object.h +58 -0
  211. package/runtime/include/jscontext.h +1 -0
  212. package/runtime/src/crypto_internal.h +1 -0
  213. package/runtime/src/crypto_subtle.c +66 -7
  214. package/runtime/src/crypto_tls.c +265 -19
  215. package/runtime/src/gc.c +73 -92
  216. package/runtime/src/inspect.c +18 -1
  217. package/runtime/src/jobs.c +37 -22
  218. package/runtime/src/object.c +49 -2
  219. package/runtime/src/os.c +16 -6
  220. package/runtime/src/os.h +2 -0
  221. package/runtime/src/process.c +97 -10
@@ -0,0 +1,115 @@
1
+ /* MIT License
2
+ *
3
+ * Copyright (c) 2005 Dominick Meglio
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice (including the next
13
+ * paragraph) shall be included in all copies or substantial portions of the
14
+ * Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ *
24
+ * SPDX-License-Identifier: MIT
25
+ */
26
+
27
+ #ifndef ARES_IPV6_H
28
+ #define ARES_IPV6_H
29
+
30
+ #ifdef HAVE_NETINET6_IN6_H
31
+ # include <netinet6/in6.h>
32
+ #endif
33
+
34
+ #if defined(USE_WINSOCK)
35
+ # if defined(HAVE_IPHLPAPI_H)
36
+ # include <iphlpapi.h>
37
+ # endif
38
+ # if defined(HAVE_NETIOAPI_H)
39
+ # include <netioapi.h>
40
+ # endif
41
+ #endif
42
+
43
+ #ifndef HAVE_PF_INET6
44
+ # define PF_INET6 AF_INET6
45
+ #endif
46
+
47
+ #ifndef HAVE_STRUCT_SOCKADDR_IN6
48
+ struct sockaddr_in6 {
49
+ unsigned short sin6_family;
50
+ unsigned short sin6_port;
51
+ unsigned long sin6_flowinfo;
52
+ struct ares_in6_addr sin6_addr;
53
+ unsigned int sin6_scope_id;
54
+ };
55
+ #endif
56
+
57
+ typedef union {
58
+ struct sockaddr sa;
59
+ struct sockaddr_in sa4;
60
+ struct sockaddr_in6 sa6;
61
+ } ares_sockaddr;
62
+
63
+ #ifndef HAVE_STRUCT_ADDRINFO
64
+ struct addrinfo {
65
+ int ai_flags;
66
+ int ai_family;
67
+ int ai_socktype;
68
+ int ai_protocol;
69
+ ares_socklen_t ai_addrlen; /* Follow rfc3493 struct addrinfo */
70
+ char *ai_canonname;
71
+ struct sockaddr *ai_addr;
72
+ struct addrinfo *ai_next;
73
+ };
74
+ #endif
75
+
76
+ #ifndef NS_IN6ADDRSZ
77
+ # ifndef HAVE_STRUCT_IN6_ADDR
78
+ /* We cannot have it set to zero, so we pick a fixed value here */
79
+ # define NS_IN6ADDRSZ 16
80
+ # else
81
+ # define NS_IN6ADDRSZ sizeof(struct in6_addr)
82
+ # endif
83
+ #endif
84
+
85
+ #ifndef NS_INADDRSZ
86
+ # define NS_INADDRSZ sizeof(struct in_addr)
87
+ #endif
88
+
89
+ #ifndef NS_INT16SZ
90
+ # define NS_INT16SZ 2
91
+ #endif
92
+
93
+ /* Windows XP Compatibility with later MSVC/Mingw versions */
94
+ #if defined(_WIN32)
95
+ # if !defined(IF_MAX_STRING_SIZE)
96
+ # define IF_MAX_STRING_SIZE 256 /* =256 in <ifdef.h> */
97
+ # endif
98
+ # if !defined(NDIS_IF_MAX_STRING_SIZE)
99
+ # define NDIS_IF_MAX_STRING_SIZE IF_MAX_STRING_SIZE /* =256 in <ifdef.h> */
100
+ # endif
101
+ #endif
102
+
103
+ #ifndef IF_NAMESIZE
104
+ # ifdef IFNAMSIZ
105
+ # define IF_NAMESIZE IFNAMSIZ
106
+ # else
107
+ # define IF_NAMESIZE 32
108
+ # endif
109
+ #endif
110
+
111
+ /* Defined in inet_net_pton.c for no particular reason. */
112
+ extern const struct ares_in6_addr ares_in6addr_any; /* :: */
113
+
114
+
115
+ #endif /* ARES_IPV6_H */
@@ -0,0 +1,190 @@
1
+ /* MIT License
2
+ *
3
+ * Copyright (c) 1998 Massachusetts Institute of Technology
4
+ * Copyright (c) 2004 Daniel Stenberg
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice (including the next
14
+ * paragraph) shall be included in all copies or substantial portions of the
15
+ * Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ *
25
+ * SPDX-License-Identifier: MIT
26
+ */
27
+
28
+ #include "ares_private.h"
29
+
30
+ /* library-private global and unique instance vars */
31
+
32
+ #if defined(ANDROID) || defined(__ANDROID__)
33
+ # include "ares_android.h"
34
+ #endif
35
+
36
+ /* library-private global vars with source visibility restricted to this file */
37
+
38
+ static unsigned int ares_initialized;
39
+ static int ares_init_flags;
40
+
41
+ /* library-private global vars with visibility across the whole library */
42
+
43
+ /* Some systems may return either NULL or a valid pointer on malloc(0). c-ares
44
+ * should never call malloc(0) so lets return NULL so we're more likely to find
45
+ * an issue if it were to occur. */
46
+
47
+ static void *default_malloc(size_t size)
48
+ {
49
+ if (size == 0) {
50
+ return NULL;
51
+ }
52
+ return malloc(size);
53
+ }
54
+
55
+ static void *default_realloc(void *p, size_t size)
56
+ {
57
+ return realloc(p, size);
58
+ }
59
+
60
+ static void default_free(void *p)
61
+ {
62
+ free(p);
63
+ }
64
+
65
+ static void *(*__ares_malloc)(size_t size) = default_malloc;
66
+ static void *(*__ares_realloc)(void *ptr, size_t size) = default_realloc;
67
+ static void (*__ares_free)(void *ptr) = default_free;
68
+
69
+ void *ares_malloc(size_t size)
70
+ {
71
+ return __ares_malloc(size);
72
+ }
73
+
74
+ void *ares_realloc(void *ptr, size_t size)
75
+ {
76
+ return __ares_realloc(ptr, size);
77
+ }
78
+
79
+ void ares_free(void *ptr)
80
+ {
81
+ __ares_free(ptr);
82
+ }
83
+
84
+ void *ares_malloc_zero(size_t size)
85
+ {
86
+ void *ptr = ares_malloc(size);
87
+ if (ptr != NULL) {
88
+ memset(ptr, 0, size);
89
+ }
90
+
91
+ return ptr;
92
+ }
93
+
94
+ void *ares_realloc_zero(void *ptr, size_t orig_size, size_t new_size)
95
+ {
96
+ void *p = ares_realloc(ptr, new_size);
97
+ if (p == NULL) {
98
+ return NULL;
99
+ }
100
+
101
+ if (new_size > orig_size) {
102
+ memset((unsigned char *)p + orig_size, 0, new_size - orig_size);
103
+ }
104
+
105
+ return p;
106
+ }
107
+
108
+ void *ares_malloc_zero_array(size_t num, size_t size)
109
+ {
110
+ size_t total;
111
+ if (ares_size_t_mul_overflow(num, size, &total)) {
112
+ return NULL;
113
+ }
114
+ return ares_malloc_zero(total);
115
+ }
116
+
117
+ void *ares_realloc_zero_array(void *ptr, size_t orig_num, size_t new_num,
118
+ size_t size)
119
+ {
120
+ size_t orig_total;
121
+ size_t new_total;
122
+ if (ares_size_t_mul_overflow(orig_num, size, &orig_total) ||
123
+ ares_size_t_mul_overflow(new_num, size, &new_total)) {
124
+ return NULL;
125
+ }
126
+ return ares_realloc_zero(ptr, orig_total, new_total);
127
+ }
128
+
129
+ int ares_library_init(int flags)
130
+ {
131
+ if (ares_initialized) {
132
+ ares_initialized++;
133
+ return ARES_SUCCESS;
134
+ }
135
+ ares_initialized++;
136
+
137
+ /* NOTE: ARES_LIB_INIT_WIN32 flag no longer used */
138
+
139
+ ares_init_flags = flags;
140
+
141
+ return ARES_SUCCESS;
142
+ }
143
+
144
+ int ares_library_init_mem(int flags, void *(*amalloc)(size_t size),
145
+ void (*afree)(void *ptr),
146
+ void *(*arealloc)(void *ptr, size_t size))
147
+ {
148
+ if (amalloc) {
149
+ __ares_malloc = amalloc;
150
+ }
151
+ if (arealloc) {
152
+ __ares_realloc = arealloc;
153
+ }
154
+ if (afree) {
155
+ __ares_free = afree;
156
+ }
157
+ return ares_library_init(flags);
158
+ }
159
+
160
+ void ares_library_cleanup(void)
161
+ {
162
+ if (!ares_initialized) {
163
+ return;
164
+ }
165
+ ares_initialized--;
166
+ if (ares_initialized) {
167
+ return;
168
+ }
169
+
170
+ /* NOTE: ARES_LIB_INIT_WIN32 flag no longer used */
171
+
172
+ #if defined(ANDROID) || defined(__ANDROID__)
173
+ ares_library_cleanup_android();
174
+ #endif
175
+
176
+ ares_init_flags = ARES_LIB_INIT_NONE;
177
+ __ares_malloc = default_malloc;
178
+ __ares_realloc = default_realloc;
179
+ __ares_free = default_free;
180
+ }
181
+
182
+ int ares_library_initialized(void)
183
+ {
184
+ #ifdef USE_WINSOCK
185
+ if (!ares_initialized) {
186
+ return ARES_ENOTINITIALIZED;
187
+ }
188
+ #endif
189
+ return ARES_SUCCESS;
190
+ }
@@ -0,0 +1,261 @@
1
+ /* MIT License
2
+ *
3
+ * Copyright (c) 2024 Brad House
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice (including the next
13
+ * paragraph) shall be included in all copies or substantial portions of the
14
+ * Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ *
24
+ * SPDX-License-Identifier: MIT
25
+ */
26
+
27
+
28
+ /* IMPLEMENTATION NOTES
29
+ * ====================
30
+ *
31
+ * With very little effort we should be able to determine fairly proper timeouts
32
+ * we can use based on prior query history. We track in order to be able to
33
+ * auto-scale when network conditions change (e.g. maybe there is a provider
34
+ * failover and timings change due to that). Apple appears to do this within
35
+ * their system resolver in MacOS. Obviously we should have a minimum, maximum,
36
+ * and initial value to make sure the algorithm doesn't somehow go off the
37
+ * rails.
38
+ *
39
+ * Values:
40
+ * - Minimum Timeout: 250ms (approximate RTT half-way around the globe)
41
+ * - Maximum Timeout: 5000ms (Recommended timeout in RFC 1123), can be reduced
42
+ * by ARES_OPT_MAXTIMEOUTMS, but otherwise the bound specified by the option
43
+ * caps the retry timeout.
44
+ * - Initial Timeout: User-specified via configuration or ARES_OPT_TIMEOUTMS
45
+ * - Average latency multiplier: 5x (a local DNS server returning a cached value
46
+ * will be quicker than if it needs to recurse so we need to account for this)
47
+ * - Minimum Count for Average: 3. This is the minimum number of queries we
48
+ * need to form an average for the bucket.
49
+ *
50
+ * Per-server buckets for tracking latency over time (these are ephemeral
51
+ * meaning they don't persist once a channel is destroyed). We record both the
52
+ * current timespan for the bucket and the immediate preceding timespan in case
53
+ * of roll-overs we can still maintain recent metrics for calculations:
54
+ * - 1 minute
55
+ * - 15 minutes
56
+ * - 1 hr
57
+ * - 1 day
58
+ * - since inception
59
+ *
60
+ * Each bucket would contain:
61
+ * - timestamp (divided by interval)
62
+ * - minimum latency
63
+ * - maximum latency
64
+ * - total time
65
+ * - count
66
+ * NOTE: average latency is (total time / count), we will calculate this
67
+ * dynamically when needed
68
+ *
69
+ * Basic algorithm for calculating timeout to use would be:
70
+ * - Scan from most recent bucket to least recent
71
+ * - Check timestamp of bucket, if doesn't match current time, continue to next
72
+ * bucket
73
+ * - Check count of bucket, if its not at least the "Minimum Count for Average",
74
+ * check the previous bucket, otherwise continue to next bucket
75
+ * - If we reached the end with no bucket match, use "Initial Timeout"
76
+ * - If bucket is selected, take ("total time" / count) as Average latency,
77
+ * multiply by "Average Latency Multiplier", bound by "Minimum Timeout" and
78
+ * "Maximum Timeout"
79
+ * NOTE: The timeout calculated may not be the timeout used. If we are retrying
80
+ * the query on the same server another time, then it will use a larger value
81
+ *
82
+ * On each query reply where the response is legitimate (proper response or
83
+ * NXDOMAIN) and not something like a server error:
84
+ * - Cycle through each bucket in order
85
+ * - Check timestamp of bucket against current timestamp, if out of date
86
+ * overwrite previous entry with values, clear current values
87
+ * - Compare current minimum and maximum recorded latency against query time and
88
+ * adjust if necessary
89
+ * - Increment "count" by 1 and "total time" by the query time
90
+ *
91
+ * Other Notes:
92
+ * - This is always-on, the only user-configurable value is the initial
93
+ * timeout which will simply re-uses the current option.
94
+ * - Minimum and Maximum latencies for a bucket are currently unused but are
95
+ * there in case we find a need for them in the future.
96
+ */
97
+
98
+ #include "ares_private.h"
99
+
100
+ /*! Minimum timeout value. Chosen due to it being approximately RTT half-way
101
+ * around the world */
102
+ #define MIN_TIMEOUT_MS 250
103
+
104
+ /*! Multiplier to apply to average latency to come up with an initial timeout */
105
+ #define AVG_TIMEOUT_MULTIPLIER 5
106
+
107
+ /*! Upper timeout bounds, only used if channel->maxtimeout not set */
108
+ #define MAX_TIMEOUT_MS 5000
109
+
110
+ /*! Minimum queries required to form an average */
111
+ #define MIN_COUNT_FOR_AVERAGE 3
112
+
113
+ static time_t ares_metric_timestamp(ares_server_bucket_t bucket,
114
+ const ares_timeval_t *now,
115
+ ares_bool_t is_previous)
116
+ {
117
+ time_t divisor = 1; /* Silence bogus MSVC warning by setting default value */
118
+
119
+ switch (bucket) {
120
+ case ARES_METRIC_1MINUTE:
121
+ divisor = 60;
122
+ break;
123
+ case ARES_METRIC_15MINUTES:
124
+ divisor = 15 * 60;
125
+ break;
126
+ case ARES_METRIC_1HOUR:
127
+ divisor = 60 * 60;
128
+ break;
129
+ case ARES_METRIC_1DAY:
130
+ divisor = 24 * 60 * 60;
131
+ break;
132
+ case ARES_METRIC_INCEPTION:
133
+ return is_previous ? 0 : 1;
134
+ case ARES_METRIC_COUNT:
135
+ return 0; /* Invalid! */
136
+ }
137
+
138
+ if (is_previous) {
139
+ if (divisor >= now->sec) {
140
+ return 0;
141
+ }
142
+ return (time_t)((now->sec - divisor) / divisor);
143
+ }
144
+
145
+ return (time_t)(now->sec / divisor);
146
+ }
147
+
148
+ void ares_metrics_record(const ares_query_t *query, ares_server_t *server,
149
+ ares_status_t status, const ares_dns_record_t *dnsrec)
150
+ {
151
+ ares_timeval_t now;
152
+ ares_timeval_t tvdiff;
153
+ unsigned int query_ms;
154
+ ares_dns_rcode_t rcode;
155
+ ares_server_bucket_t i;
156
+
157
+ if (status != ARES_SUCCESS) {
158
+ return;
159
+ }
160
+
161
+ if (server == NULL) {
162
+ return;
163
+ }
164
+
165
+ ares_tvnow(&now);
166
+
167
+ rcode = ares_dns_record_get_rcode(dnsrec);
168
+ if (rcode != ARES_RCODE_NOERROR && rcode != ARES_RCODE_NXDOMAIN) {
169
+ return;
170
+ }
171
+
172
+ ares_timeval_diff(&tvdiff, &query->ts, &now);
173
+ query_ms = (unsigned int)((tvdiff.sec * 1000) + (tvdiff.usec / 1000));
174
+ if (query_ms == 0) {
175
+ query_ms = 1;
176
+ }
177
+
178
+ /* Place in each bucket */
179
+ for (i = 0; i < ARES_METRIC_COUNT; i++) {
180
+ time_t ts = ares_metric_timestamp(i, &now, ARES_FALSE);
181
+
182
+ /* Copy metrics to prev and clear */
183
+ if (ts != server->metrics[i].ts) {
184
+ server->metrics[i].prev_ts = server->metrics[i].ts;
185
+ server->metrics[i].prev_total_ms = server->metrics[i].total_ms;
186
+ server->metrics[i].prev_total_count = server->metrics[i].total_count;
187
+ server->metrics[i].ts = ts;
188
+ server->metrics[i].latency_min_ms = 0;
189
+ server->metrics[i].latency_max_ms = 0;
190
+ server->metrics[i].total_ms = 0;
191
+ server->metrics[i].total_count = 0;
192
+ }
193
+
194
+ if (server->metrics[i].latency_min_ms == 0 ||
195
+ server->metrics[i].latency_min_ms > query_ms) {
196
+ server->metrics[i].latency_min_ms = query_ms;
197
+ }
198
+
199
+ if (query_ms > server->metrics[i].latency_max_ms) {
200
+ server->metrics[i].latency_max_ms = query_ms;
201
+ }
202
+
203
+ server->metrics[i].total_count++;
204
+ server->metrics[i].total_ms += (ares_uint64_t)query_ms;
205
+ }
206
+ }
207
+
208
+ size_t ares_metrics_server_timeout(const ares_server_t *server,
209
+ const ares_timeval_t *now)
210
+ {
211
+ const ares_channel_t *channel = server->channel;
212
+ ares_server_bucket_t i;
213
+ size_t timeout_ms = 0;
214
+ size_t max_timeout_ms;
215
+
216
+ for (i = 0; i < ARES_METRIC_COUNT; i++) {
217
+ time_t ts = ares_metric_timestamp(i, now, ARES_FALSE);
218
+
219
+ /* This ts has been invalidated, see if we should use the previous
220
+ * time period */
221
+ if (ts != server->metrics[i].ts ||
222
+ server->metrics[i].total_count < MIN_COUNT_FOR_AVERAGE) {
223
+ time_t prev_ts = ares_metric_timestamp(i, now, ARES_TRUE);
224
+ if (prev_ts != server->metrics[i].prev_ts ||
225
+ server->metrics[i].prev_total_count < MIN_COUNT_FOR_AVERAGE) {
226
+ /* Move onto next bucket */
227
+ continue;
228
+ }
229
+ /* Calculate average time for previous bucket */
230
+ timeout_ms = (size_t)(server->metrics[i].prev_total_ms /
231
+ server->metrics[i].prev_total_count);
232
+ } else {
233
+ /* Calculate average time for current bucket*/
234
+ timeout_ms =
235
+ (size_t)(server->metrics[i].total_ms / server->metrics[i].total_count);
236
+ }
237
+
238
+ /* Multiply average by constant to get timeout value */
239
+ timeout_ms *= AVG_TIMEOUT_MULTIPLIER;
240
+ break;
241
+ }
242
+
243
+ /* If we're here, that means its the first query for the server, so we just
244
+ * use the initial default timeout */
245
+ if (timeout_ms == 0) {
246
+ timeout_ms = channel->timeout;
247
+ }
248
+
249
+ /* don't go below lower bounds */
250
+ if (timeout_ms < MIN_TIMEOUT_MS) {
251
+ timeout_ms = MIN_TIMEOUT_MS;
252
+ }
253
+
254
+ /* don't go above upper bounds */
255
+ max_timeout_ms = channel->maxtimeout ? channel->maxtimeout : MAX_TIMEOUT_MS;
256
+ if (timeout_ms > max_timeout_ms) {
257
+ timeout_ms = max_timeout_ms;
258
+ }
259
+
260
+ return timeout_ms;
261
+ }