grpc 1.74.1 → 1.75.0.pre1

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 (368) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +83 -41
  3. data/include/grpc/credentials.h +7 -1
  4. data/src/core/call/client_call.cc +4 -4
  5. data/src/core/call/filter_fusion.h +1230 -0
  6. data/src/core/call/metadata.cc +22 -0
  7. data/src/core/call/metadata.h +24 -2
  8. data/src/core/channelz/channelz.cc +10 -17
  9. data/src/core/channelz/channelz.h +58 -19
  10. data/src/core/channelz/channelz_registry.cc +0 -162
  11. data/src/core/channelz/channelz_registry.h +14 -7
  12. data/src/core/channelz/property_list.cc +19 -23
  13. data/src/core/channelz/property_list.h +3 -1
  14. data/src/core/channelz/v2tov1/convert.cc +683 -0
  15. data/src/core/channelz/v2tov1/convert.h +58 -0
  16. data/src/core/channelz/v2tov1/legacy_api.cc +425 -0
  17. data/src/core/channelz/v2tov1/legacy_api.h +32 -0
  18. data/src/core/channelz/v2tov1/property_list.cc +118 -0
  19. data/src/core/channelz/v2tov1/property_list.h +52 -0
  20. data/src/core/client_channel/client_channel_filter.cc +5 -4
  21. data/src/core/client_channel/client_channel_filter.h +2 -2
  22. data/src/core/client_channel/client_channel_internal.h +2 -1
  23. data/src/core/client_channel/load_balanced_call_destination.cc +6 -5
  24. data/src/core/client_channel/subchannel.cc +14 -6
  25. data/src/core/client_channel/subchannel.h +2 -0
  26. data/src/core/config/core_configuration.cc +3 -1
  27. data/src/core/config/core_configuration.h +12 -0
  28. data/src/core/credentials/transport/alts/alts_credentials.cc +5 -0
  29. data/src/core/credentials/transport/alts/check_gcp_environment_windows.cc +2 -0
  30. data/src/core/credentials/transport/channel_creds_registry_init.cc +3 -1
  31. data/src/core/credentials/transport/ssl/ssl_credentials.cc +1 -1
  32. data/src/core/credentials/transport/ssl/ssl_security_connector.cc +8 -3
  33. data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.cc +29 -24
  34. data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.h +19 -8
  35. data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.cc +96 -54
  36. data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.h +15 -2
  37. data/src/core/credentials/transport/tls/spiffe_utils.cc +371 -0
  38. data/src/core/credentials/transport/tls/spiffe_utils.h +171 -0
  39. data/src/core/credentials/transport/tls/ssl_utils.cc +11 -10
  40. data/src/core/credentials/transport/tls/ssl_utils.h +4 -2
  41. data/src/core/credentials/transport/tls/tls_credentials.cc +2 -0
  42. data/src/core/credentials/transport/tls/tls_security_connector.cc +11 -26
  43. data/src/core/credentials/transport/tls/tls_security_connector.h +12 -12
  44. data/src/core/ext/filters/backend_metrics/backend_metric_filter.cc +1 -2
  45. data/src/core/ext/filters/http/client/http_client_filter.cc +3 -6
  46. data/src/core/ext/filters/http/client_authority_filter.cc +1 -2
  47. data/src/core/ext/filters/http/message_compress/compression_filter.cc +8 -8
  48. data/src/core/ext/filters/http/server/http_server_filter.cc +3 -6
  49. data/src/core/ext/filters/message_size/message_size_filter.cc +4 -4
  50. data/src/core/ext/filters/rbac/rbac_filter.cc +1 -1
  51. data/src/core/ext/filters/stateful_session/stateful_session_filter.cc +3 -5
  52. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +3 -2
  53. data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -0
  54. data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -0
  55. data/src/core/ext/transport/chttp2/transport/frame.cc +89 -6
  56. data/src/core/ext/transport/chttp2/transport/frame.h +38 -0
  57. data/src/core/ext/transport/chttp2/transport/header_assembler.h +5 -14
  58. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +4 -1
  59. data/src/core/ext/transport/chttp2/transport/http2_client_transport.cc +294 -78
  60. data/src/core/ext/transport/chttp2/transport/http2_client_transport.h +128 -9
  61. data/src/core/ext/transport/chttp2/transport/http2_settings.cc +11 -38
  62. data/src/core/ext/transport/chttp2/transport/http2_settings.h +52 -35
  63. data/src/core/ext/transport/chttp2/transport/http2_settings_manager.cc +61 -0
  64. data/src/core/ext/transport/chttp2/transport/http2_settings_manager.h +142 -0
  65. data/src/core/ext/transport/chttp2/transport/http2_transport.cc +81 -3
  66. data/src/core/ext/transport/chttp2/transport/http2_transport.h +12 -1
  67. data/src/core/ext/transport/chttp2/transport/message_assembler.h +2 -2
  68. data/src/core/ext/transport/chttp2/transport/parsing.cc +2 -1
  69. data/src/core/ext/transport/chttp2/transport/ping_promise.cc +2 -1
  70. data/src/core/ext/transport/chttp2/transport/ping_promise.h +22 -5
  71. data/src/core/ext/transport/chttp2/transport/stream_data_queue.h +607 -0
  72. data/src/core/ext/transport/chttp2/transport/writable_streams.h +254 -0
  73. data/src/core/ext/transport/chttp2/transport/writing.cc +6 -4
  74. data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb.h +4959 -0
  75. data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb_minitable.c +1111 -0
  76. data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb_minitable.h +108 -0
  77. data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb.h +142 -54
  78. data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb_minitable.c +18 -14
  79. data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb_minitable.h +2 -2
  80. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/channelz.upbdefs.c +716 -0
  81. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/channelz.upbdefs.h +227 -0
  82. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/property_list.upbdefs.c +86 -88
  83. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/property_list.upbdefs.h +2 -2
  84. data/src/core/filter/auth/auth_filters.h +2 -2
  85. data/src/core/filter/fused_filters.cc +154 -0
  86. data/src/core/handshaker/security/legacy_secure_endpoint.cc +1 -1
  87. data/src/core/handshaker/security/pipelined_secure_endpoint.cc +965 -0
  88. data/src/core/handshaker/security/secure_endpoint.cc +28 -13
  89. data/src/core/handshaker/security/secure_endpoint.h +8 -0
  90. data/src/core/lib/channel/promise_based_filter.cc +15 -25
  91. data/src/core/lib/channel/promise_based_filter.h +6 -5
  92. data/src/core/lib/event_engine/ares_resolver.h +3 -1
  93. data/src/core/lib/event_engine/cf_engine/cf_engine.cc +9 -5
  94. data/src/core/lib/event_engine/cf_engine/cf_engine.h +2 -1
  95. data/src/core/lib/event_engine/cf_engine/cfsocket_listener.cc +263 -0
  96. data/src/core/lib/event_engine/cf_engine/cfsocket_listener.h +107 -0
  97. data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc +31 -3
  98. data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.h +12 -0
  99. data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +12 -10
  100. data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.h +6 -4
  101. data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +15 -14
  102. data/src/core/lib/event_engine/posix_engine/ev_poll_posix.h +7 -5
  103. data/src/core/lib/event_engine/posix_engine/event_poller.h +0 -8
  104. data/src/core/lib/event_engine/posix_engine/event_poller_posix_default.cc +11 -5
  105. data/src/core/lib/event_engine/posix_engine/event_poller_posix_default.h +3 -2
  106. data/src/core/lib/event_engine/posix_engine/grpc_polled_fd_posix.h +1 -0
  107. data/src/core/lib/event_engine/posix_engine/lockfree_event.cc +4 -4
  108. data/src/core/lib/event_engine/posix_engine/lockfree_event.h +3 -4
  109. data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +2 -2
  110. data/src/core/lib/event_engine/posix_engine/posix_engine.cc +188 -199
  111. data/src/core/lib/event_engine/posix_engine/posix_engine.h +30 -45
  112. data/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc +1 -1
  113. data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h +1 -1
  114. data/src/core/lib/event_engine/windows/grpc_polled_fd_windows.cc +2 -1
  115. data/src/core/lib/experiments/experiments.cc +120 -6
  116. data/src/core/lib/experiments/experiments.h +46 -3
  117. data/src/core/lib/iomgr/combiner.cc +1 -1
  118. data/src/core/lib/iomgr/exec_ctx.h +3 -9
  119. data/src/core/lib/iomgr/socket_mutator.cc +1 -1
  120. data/src/core/lib/iomgr/socket_utils_posix.cc +1 -1
  121. data/src/core/lib/iomgr/socket_utils_posix.h +1 -1
  122. data/src/core/lib/iomgr/tcp_client_posix.cc +1 -1
  123. data/src/core/lib/iomgr/tcp_posix.cc +3 -3
  124. data/src/core/lib/promise/activity.h +2 -2
  125. data/src/core/lib/promise/mpsc.cc +8 -8
  126. data/src/core/lib/promise/party.cc +7 -7
  127. data/src/core/lib/promise/party.h +4 -4
  128. data/src/core/lib/promise/poll.h +10 -0
  129. data/src/core/lib/resource_quota/memory_quota.cc +90 -3
  130. data/src/core/lib/resource_quota/memory_quota.h +20 -9
  131. data/src/core/lib/resource_quota/periodic_update.cc +14 -0
  132. data/src/core/lib/resource_quota/periodic_update.h +8 -0
  133. data/src/core/lib/resource_quota/resource_quota.cc +15 -4
  134. data/src/core/lib/resource_quota/resource_quota.h +3 -0
  135. data/src/core/lib/security/authorization/grpc_server_authz_filter.cc +1 -2
  136. data/src/core/lib/surface/call.cc +5 -5
  137. data/src/core/lib/surface/call.h +6 -5
  138. data/src/core/lib/surface/completion_queue.cc +2 -4
  139. data/src/core/lib/surface/filter_stack_call.cc +1 -1
  140. data/src/core/lib/surface/version.cc +2 -2
  141. data/src/core/lib/transport/promise_endpoint.cc +2 -2
  142. data/src/core/lib/transport/promise_endpoint.h +3 -3
  143. data/src/core/load_balancing/endpoint_list.cc +29 -2
  144. data/src/core/load_balancing/grpclb/client_load_reporting_filter.cc +3 -3
  145. data/src/core/load_balancing/grpclb/client_load_reporting_filter.h +1 -1
  146. data/src/core/load_balancing/pick_first/pick_first.cc +12 -5
  147. data/src/core/load_balancing/xds/xds_cluster_impl.cc +5 -3
  148. data/src/core/net/socket_mutator.cc +19 -0
  149. data/src/core/net/socket_mutator.h +25 -0
  150. data/src/core/plugin_registry/grpc_plugin_registry.cc +6 -0
  151. data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h +6 -1
  152. data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +2 -1
  153. data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc +8 -5
  154. data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
  155. data/src/core/resolver/xds/xds_dependency_manager.cc +1 -1
  156. data/src/core/server/server.cc +1 -1
  157. data/src/core/server/server_call_tracer_filter.cc +0 -66
  158. data/src/core/server/server_call_tracer_filter.h +64 -0
  159. data/src/core/server/server_config_selector_filter.cc +1 -1
  160. data/src/core/service_config/service_config_channel_arg_filter.cc +3 -60
  161. data/src/core/service_config/service_config_channel_arg_filter.h +82 -0
  162. data/src/core/telemetry/call_tracer.cc +20 -14
  163. data/src/core/telemetry/call_tracer.h +22 -17
  164. data/src/core/telemetry/metrics.h +8 -8
  165. data/src/core/telemetry/stats_data.cc +151 -151
  166. data/src/core/telemetry/stats_data.h +87 -87
  167. data/src/core/transport/auth_context.cc +20 -0
  168. data/src/core/transport/auth_context.h +4 -0
  169. data/src/core/transport/auth_context_comparator_registry.h +69 -0
  170. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +2 -3
  171. data/src/core/tsi/ssl_transport_security.cc +202 -32
  172. data/src/core/tsi/ssl_transport_security.h +19 -10
  173. data/src/core/tsi/ssl_transport_security_utils.cc +21 -0
  174. data/src/core/tsi/ssl_transport_security_utils.h +4 -0
  175. data/src/core/util/http_client/httpcli_security_connector.cc +3 -1
  176. data/src/core/util/latent_see.cc +178 -146
  177. data/src/core/util/latent_see.h +245 -188
  178. data/src/core/util/single_set_ptr.h +5 -2
  179. data/src/core/util/useful.h +91 -0
  180. data/src/core/util/windows/directory_reader.cc +1 -0
  181. data/src/core/util/windows/thd.cc +1 -3
  182. data/src/core/util/work_serializer.cc +1 -1
  183. data/src/core/xds/grpc/file_watcher_certificate_provider_factory.cc +32 -5
  184. data/src/core/xds/grpc/file_watcher_certificate_provider_factory.h +5 -0
  185. data/src/core/xds/grpc/xds_certificate_provider.cc +5 -6
  186. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
  187. data/src/ruby/lib/grpc/version.rb +1 -1
  188. data/third_party/cares/cares/include/ares.h +925 -460
  189. data/third_party/cares/cares/include/ares_dns.h +86 -71
  190. data/third_party/cares/cares/include/ares_dns_record.h +1118 -0
  191. data/third_party/cares/cares/include/ares_nameser.h +215 -189
  192. data/third_party/cares/cares/include/ares_version.h +37 -14
  193. data/third_party/cares/cares/src/lib/ares_addrinfo2hostent.c +305 -0
  194. data/third_party/cares/cares/src/lib/ares_addrinfo_localhost.c +245 -0
  195. data/third_party/cares/cares/src/lib/ares_android.c +216 -164
  196. data/third_party/cares/cares/src/lib/ares_android.h +25 -14
  197. data/third_party/cares/cares/src/lib/ares_cancel.c +68 -44
  198. data/third_party/cares/cares/src/lib/ares_close_sockets.c +137 -0
  199. data/third_party/cares/cares/src/lib/ares_conn.c +511 -0
  200. data/third_party/cares/cares/src/lib/ares_conn.h +196 -0
  201. data/third_party/cares/cares/src/lib/ares_cookie.c +461 -0
  202. data/third_party/cares/cares/src/lib/ares_data.c +93 -181
  203. data/third_party/cares/cares/src/lib/ares_data.h +50 -39
  204. data/third_party/cares/cares/src/lib/ares_destroy.c +127 -89
  205. data/third_party/cares/cares/src/lib/ares_free_hostent.c +35 -24
  206. data/third_party/cares/cares/src/lib/ares_free_string.c +24 -16
  207. data/third_party/cares/cares/src/lib/ares_freeaddrinfo.c +45 -38
  208. data/third_party/cares/cares/src/lib/ares_getaddrinfo.c +549 -663
  209. data/third_party/cares/cares/src/lib/ares_getenv.c +25 -15
  210. data/third_party/cares/cares/src/lib/ares_getenv.h +26 -18
  211. data/third_party/cares/cares/src/lib/ares_gethostbyaddr.c +163 -221
  212. data/third_party/cares/cares/src/lib/ares_gethostbyname.c +222 -223
  213. data/third_party/cares/cares/src/lib/ares_getnameinfo.c +328 -338
  214. data/third_party/cares/cares/src/lib/ares_hosts_file.c +952 -0
  215. data/third_party/cares/cares/src/lib/ares_inet_net_pton.h +25 -19
  216. data/third_party/cares/cares/src/lib/ares_init.c +425 -2091
  217. data/third_party/cares/cares/src/lib/ares_ipv6.h +63 -33
  218. data/third_party/cares/cares/src/lib/ares_library_init.c +110 -54
  219. data/third_party/cares/cares/src/lib/ares_metrics.c +261 -0
  220. data/third_party/cares/cares/src/lib/ares_options.c +418 -332
  221. data/third_party/cares/cares/src/lib/ares_parse_into_addrinfo.c +179 -0
  222. data/third_party/cares/cares/src/lib/ares_private.h +558 -356
  223. data/third_party/cares/cares/src/lib/ares_process.c +1224 -1369
  224. data/third_party/cares/cares/src/lib/ares_qcache.c +430 -0
  225. data/third_party/cares/cares/src/lib/ares_query.c +126 -121
  226. data/third_party/cares/cares/src/lib/ares_search.c +564 -262
  227. data/third_party/cares/cares/src/lib/ares_send.c +264 -93
  228. data/third_party/cares/cares/src/lib/ares_set_socket_functions.c +588 -0
  229. data/third_party/cares/cares/src/lib/ares_setup.h +115 -111
  230. data/third_party/cares/cares/src/lib/ares_socket.c +425 -0
  231. data/third_party/cares/cares/src/lib/ares_socket.h +163 -0
  232. data/third_party/cares/cares/src/lib/ares_sortaddrinfo.c +447 -0
  233. data/third_party/cares/cares/src/lib/ares_strerror.c +83 -48
  234. data/third_party/cares/cares/src/lib/ares_sysconfig.c +639 -0
  235. data/third_party/cares/cares/src/lib/ares_sysconfig_files.c +839 -0
  236. data/third_party/cares/cares/src/lib/ares_sysconfig_mac.c +373 -0
  237. data/third_party/cares/cares/src/lib/ares_sysconfig_win.c +621 -0
  238. data/third_party/cares/cares/src/lib/ares_timeout.c +136 -73
  239. data/third_party/cares/cares/src/lib/ares_update_servers.c +1362 -0
  240. data/third_party/cares/cares/src/lib/ares_version.c +29 -4
  241. data/third_party/cares/cares/src/lib/config-dos.h +88 -89
  242. data/third_party/cares/cares/src/lib/config-win32.h +122 -77
  243. data/third_party/cares/cares/src/lib/dsa/ares_array.c +394 -0
  244. data/third_party/cares/cares/src/lib/dsa/ares_htable.c +447 -0
  245. data/third_party/cares/cares/src/lib/dsa/ares_htable.h +174 -0
  246. data/third_party/cares/cares/src/lib/dsa/ares_htable_asvp.c +224 -0
  247. data/third_party/cares/cares/src/lib/dsa/ares_htable_dict.c +228 -0
  248. data/third_party/cares/cares/src/lib/dsa/ares_htable_strvp.c +210 -0
  249. data/third_party/cares/cares/src/lib/dsa/ares_htable_szvp.c +188 -0
  250. data/third_party/cares/cares/src/lib/dsa/ares_htable_vpstr.c +186 -0
  251. data/third_party/cares/cares/src/lib/dsa/ares_htable_vpvp.c +194 -0
  252. data/third_party/cares/cares/src/lib/dsa/ares_llist.c +382 -0
  253. data/third_party/cares/cares/src/lib/dsa/ares_slist.c +479 -0
  254. data/third_party/cares/cares/src/lib/dsa/ares_slist.h +207 -0
  255. data/third_party/cares/cares/src/lib/event/ares_event.h +191 -0
  256. data/third_party/cares/cares/src/lib/event/ares_event_configchg.c +743 -0
  257. data/third_party/cares/cares/src/lib/event/ares_event_epoll.c +192 -0
  258. data/third_party/cares/cares/src/lib/event/ares_event_kqueue.c +248 -0
  259. data/third_party/cares/cares/src/lib/event/ares_event_poll.c +140 -0
  260. data/third_party/cares/cares/src/lib/event/ares_event_select.c +159 -0
  261. data/third_party/cares/cares/src/lib/event/ares_event_thread.c +567 -0
  262. data/third_party/cares/cares/src/lib/event/ares_event_wake_pipe.c +166 -0
  263. data/third_party/cares/cares/src/lib/event/ares_event_win32.c +978 -0
  264. data/third_party/cares/cares/src/lib/event/ares_event_win32.h +161 -0
  265. data/third_party/cares/cares/src/lib/include/ares_array.h +276 -0
  266. data/third_party/cares/cares/src/lib/include/ares_buf.h +732 -0
  267. data/third_party/cares/cares/src/lib/include/ares_htable_asvp.h +130 -0
  268. data/third_party/cares/cares/src/lib/include/ares_htable_dict.h +123 -0
  269. data/third_party/cares/cares/src/lib/include/ares_htable_strvp.h +130 -0
  270. data/third_party/cares/cares/src/lib/include/ares_htable_szvp.h +118 -0
  271. data/third_party/cares/cares/src/lib/include/ares_htable_vpstr.h +111 -0
  272. data/third_party/cares/cares/src/lib/include/ares_htable_vpvp.h +128 -0
  273. data/third_party/cares/cares/src/lib/include/ares_llist.h +239 -0
  274. data/third_party/cares/cares/src/lib/include/ares_mem.h +38 -0
  275. data/third_party/cares/cares/src/lib/include/ares_str.h +244 -0
  276. data/third_party/cares/cares/src/lib/inet_net_pton.c +202 -157
  277. data/third_party/cares/cares/src/lib/inet_ntop.c +87 -69
  278. data/third_party/cares/cares/src/lib/legacy/ares_create_query.c +78 -0
  279. data/third_party/cares/cares/src/lib/legacy/ares_expand_name.c +99 -0
  280. data/third_party/cares/cares/src/lib/legacy/ares_expand_string.c +107 -0
  281. data/third_party/cares/cares/src/lib/legacy/ares_fds.c +80 -0
  282. data/third_party/cares/cares/src/lib/legacy/ares_getsock.c +85 -0
  283. data/third_party/cares/cares/src/lib/legacy/ares_parse_a_reply.c +107 -0
  284. data/third_party/cares/cares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
  285. data/third_party/cares/cares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
  286. data/third_party/cares/cares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
  287. data/third_party/cares/cares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
  288. data/third_party/cares/cares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
  289. data/third_party/cares/cares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
  290. data/third_party/cares/cares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
  291. data/third_party/cares/cares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
  292. data/third_party/cares/cares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
  293. data/third_party/cares/cares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
  294. data/third_party/cares/cares/src/lib/record/ares_dns_mapping.c +982 -0
  295. data/third_party/cares/cares/src/lib/record/ares_dns_multistring.c +307 -0
  296. data/third_party/cares/cares/src/lib/record/ares_dns_multistring.h +72 -0
  297. data/third_party/cares/cares/src/lib/record/ares_dns_name.c +673 -0
  298. data/third_party/cares/cares/src/lib/record/ares_dns_parse.c +1329 -0
  299. data/third_party/cares/cares/src/lib/record/ares_dns_private.h +273 -0
  300. data/third_party/cares/cares/src/lib/record/ares_dns_record.c +1661 -0
  301. data/third_party/cares/cares/src/lib/record/ares_dns_write.c +1229 -0
  302. data/third_party/cares/cares/src/lib/str/ares_buf.c +1498 -0
  303. data/third_party/cares/cares/src/lib/str/ares_str.c +508 -0
  304. data/third_party/cares/cares/src/lib/str/ares_strsplit.c +90 -0
  305. data/third_party/cares/cares/src/lib/str/ares_strsplit.h +51 -0
  306. data/third_party/cares/cares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
  307. data/third_party/cares/cares/src/lib/util/ares_iface_ips.c +628 -0
  308. data/third_party/cares/cares/src/lib/util/ares_iface_ips.h +139 -0
  309. data/third_party/cares/cares/src/lib/util/ares_math.c +158 -0
  310. data/third_party/cares/cares/src/lib/util/ares_math.h +45 -0
  311. data/third_party/cares/cares/src/lib/util/ares_rand.c +389 -0
  312. data/third_party/cares/cares/src/lib/util/ares_rand.h +36 -0
  313. data/third_party/cares/cares/src/lib/util/ares_threads.c +614 -0
  314. data/third_party/cares/cares/src/lib/util/ares_threads.h +60 -0
  315. data/third_party/cares/cares/src/lib/util/ares_time.h +48 -0
  316. data/third_party/cares/cares/src/lib/util/ares_timeval.c +95 -0
  317. data/third_party/cares/cares/src/lib/util/ares_uri.c +1626 -0
  318. data/third_party/cares/cares/src/lib/util/ares_uri.h +252 -0
  319. data/third_party/cares/cares/src/lib/windows_port.c +16 -9
  320. metadata +121 -49
  321. data/src/core/util/ring_buffer.h +0 -122
  322. data/third_party/cares/cares/include/ares_rules.h +0 -125
  323. data/third_party/cares/cares/src/lib/ares__addrinfo2hostent.c +0 -266
  324. data/third_party/cares/cares/src/lib/ares__addrinfo_localhost.c +0 -240
  325. data/third_party/cares/cares/src/lib/ares__close_sockets.c +0 -61
  326. data/third_party/cares/cares/src/lib/ares__get_hostent.c +0 -260
  327. data/third_party/cares/cares/src/lib/ares__parse_into_addrinfo.c +0 -229
  328. data/third_party/cares/cares/src/lib/ares__read_line.c +0 -73
  329. data/third_party/cares/cares/src/lib/ares__readaddrinfo.c +0 -258
  330. data/third_party/cares/cares/src/lib/ares__sortaddrinfo.c +0 -507
  331. data/third_party/cares/cares/src/lib/ares__timeval.c +0 -111
  332. data/third_party/cares/cares/src/lib/ares_create_query.c +0 -197
  333. data/third_party/cares/cares/src/lib/ares_expand_name.c +0 -311
  334. data/third_party/cares/cares/src/lib/ares_expand_string.c +0 -67
  335. data/third_party/cares/cares/src/lib/ares_fds.c +0 -59
  336. data/third_party/cares/cares/src/lib/ares_getsock.c +0 -66
  337. data/third_party/cares/cares/src/lib/ares_iphlpapi.h +0 -221
  338. data/third_party/cares/cares/src/lib/ares_llist.c +0 -63
  339. data/third_party/cares/cares/src/lib/ares_llist.h +0 -39
  340. data/third_party/cares/cares/src/lib/ares_mkquery.c +0 -24
  341. data/third_party/cares/cares/src/lib/ares_nowarn.c +0 -260
  342. data/third_party/cares/cares/src/lib/ares_nowarn.h +0 -61
  343. data/third_party/cares/cares/src/lib/ares_parse_a_reply.c +0 -90
  344. data/third_party/cares/cares/src/lib/ares_parse_aaaa_reply.c +0 -92
  345. data/third_party/cares/cares/src/lib/ares_parse_caa_reply.c +0 -199
  346. data/third_party/cares/cares/src/lib/ares_parse_mx_reply.c +0 -164
  347. data/third_party/cares/cares/src/lib/ares_parse_naptr_reply.c +0 -183
  348. data/third_party/cares/cares/src/lib/ares_parse_ns_reply.c +0 -177
  349. data/third_party/cares/cares/src/lib/ares_parse_ptr_reply.c +0 -228
  350. data/third_party/cares/cares/src/lib/ares_parse_soa_reply.c +0 -179
  351. data/third_party/cares/cares/src/lib/ares_parse_srv_reply.c +0 -168
  352. data/third_party/cares/cares/src/lib/ares_parse_txt_reply.c +0 -214
  353. data/third_party/cares/cares/src/lib/ares_parse_uri_reply.c +0 -184
  354. data/third_party/cares/cares/src/lib/ares_platform.c +0 -11042
  355. data/third_party/cares/cares/src/lib/ares_platform.h +0 -43
  356. data/third_party/cares/cares/src/lib/ares_rand.c +0 -279
  357. data/third_party/cares/cares/src/lib/ares_strcasecmp.c +0 -66
  358. data/third_party/cares/cares/src/lib/ares_strcasecmp.h +0 -30
  359. data/third_party/cares/cares/src/lib/ares_strdup.c +0 -42
  360. data/third_party/cares/cares/src/lib/ares_strdup.h +0 -24
  361. data/third_party/cares/cares/src/lib/ares_strsplit.c +0 -94
  362. data/third_party/cares/cares/src/lib/ares_strsplit.h +0 -42
  363. data/third_party/cares/cares/src/lib/ares_writev.c +0 -79
  364. data/third_party/cares/cares/src/lib/ares_writev.h +0 -36
  365. data/third_party/cares/cares/src/lib/bitncmp.c +0 -59
  366. data/third_party/cares/cares/src/lib/bitncmp.h +0 -26
  367. data/third_party/cares/cares/src/lib/setup_once.h +0 -554
  368. data/third_party/cares/cares/src/tools/ares_getopt.h +0 -53
@@ -1,29 +1,51 @@
1
-
2
- /* Copyright (C) 2005 by Dominick Meglio
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.
3
15
  *
4
- * Permission to use, copy, modify, and distribute this
5
- * software and its documentation for any purpose and without
6
- * fee is hereby granted, provided that the above copyright
7
- * notice appear in all copies and that both that copyright
8
- * notice and this permission notice appear in supporting
9
- * documentation, and that the name of M.I.T. not be used in
10
- * advertising or publicity pertaining to distribution of the
11
- * software without specific, written prior permission.
12
- * M.I.T. makes no representations about the suitability of
13
- * this software for any purpose. It is provided "as is"
14
- * without express or implied warranty.
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
15
25
  */
16
26
 
17
27
  #ifndef ARES_IPV6_H
18
28
  #define ARES_IPV6_H
19
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
+
20
43
  #ifndef HAVE_PF_INET6
21
- #define PF_INET6 AF_INET6
44
+ # define PF_INET6 AF_INET6
22
45
  #endif
23
46
 
24
47
  #ifndef HAVE_STRUCT_SOCKADDR_IN6
25
- struct sockaddr_in6
26
- {
48
+ struct sockaddr_in6 {
27
49
  unsigned short sin6_family;
28
50
  unsigned short sin6_port;
29
51
  unsigned long sin6_flowinfo;
@@ -32,21 +54,19 @@ struct sockaddr_in6
32
54
  };
33
55
  #endif
34
56
 
35
- typedef union
36
- {
57
+ typedef union {
37
58
  struct sockaddr sa;
38
59
  struct sockaddr_in sa4;
39
60
  struct sockaddr_in6 sa6;
40
61
  } ares_sockaddr;
41
62
 
42
63
  #ifndef HAVE_STRUCT_ADDRINFO
43
- struct addrinfo
44
- {
64
+ struct addrinfo {
45
65
  int ai_flags;
46
66
  int ai_family;
47
67
  int ai_socktype;
48
68
  int ai_protocol;
49
- ares_socklen_t ai_addrlen; /* Follow rfc3493 struct addrinfo */
69
+ ares_socklen_t ai_addrlen; /* Follow rfc3493 struct addrinfo */
50
70
  char *ai_canonname;
51
71
  struct sockaddr *ai_addr;
52
72
  struct addrinfo *ai_next;
@@ -54,28 +74,38 @@ struct addrinfo
54
74
  #endif
55
75
 
56
76
  #ifndef NS_IN6ADDRSZ
57
- #ifndef HAVE_STRUCT_IN6_ADDR
77
+ # ifndef HAVE_STRUCT_IN6_ADDR
58
78
  /* We cannot have it set to zero, so we pick a fixed value here */
59
- #define NS_IN6ADDRSZ 16
60
- #else
61
- #define NS_IN6ADDRSZ sizeof(struct in6_addr)
62
- #endif
79
+ # define NS_IN6ADDRSZ 16
80
+ # else
81
+ # define NS_IN6ADDRSZ sizeof(struct in6_addr)
82
+ # endif
63
83
  #endif
64
84
 
65
85
  #ifndef NS_INADDRSZ
66
- #define NS_INADDRSZ sizeof(struct in_addr)
86
+ # define NS_INADDRSZ sizeof(struct in_addr)
67
87
  #endif
68
88
 
69
89
  #ifndef NS_INT16SZ
70
- #define NS_INT16SZ 2
90
+ # define NS_INT16SZ 2
71
91
  #endif
72
92
 
73
- #ifndef IF_NAMESIZE
74
- #ifdef IFNAMSIZ
75
- #define IF_NAMESIZE IFNAMSIZ
76
- #else
77
- #define IF_NAMESIZE 256
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
78
101
  #endif
102
+
103
+ #ifndef IF_NAMESIZE
104
+ # ifdef IFNAMSIZ
105
+ # define IF_NAMESIZE IFNAMSIZ
106
+ # else
107
+ # define IF_NAMESIZE 32
108
+ # endif
79
109
  #endif
80
110
 
81
111
  /* Defined in inet_net_pton.c for no particular reason. */
@@ -1,29 +1,36 @@
1
-
2
- /* Copyright 1998 by the Massachusetts Institute of Technology.
3
- * Copyright (C) 2004-2009 by Daniel Stenberg
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.
4
24
  *
5
- * Permission to use, copy, modify, and distribute this
6
- * software and its documentation for any purpose and without
7
- * fee is hereby granted, provided that the above copyright
8
- * notice appear in all copies and that both that copyright
9
- * notice and this permission notice appear in supporting
10
- * documentation, and that the name of M.I.T. not be used in
11
- * advertising or publicity pertaining to distribution of the
12
- * software without specific, written prior permission.
13
- * M.I.T. makes no representations about the suitability of
14
- * this software for any purpose. It is provided "as is"
15
- * without express or implied warranty.
25
+ * SPDX-License-Identifier: MIT
16
26
  */
17
27
 
18
- #include "ares_setup.h"
19
-
20
- #include "ares.h"
21
28
  #include "ares_private.h"
22
29
 
23
30
  /* library-private global and unique instance vars */
24
31
 
25
32
  #if defined(ANDROID) || defined(__ANDROID__)
26
- #include "ares_android.h"
33
+ # include "ares_android.h"
27
34
  #endif
28
35
 
29
36
  /* library-private global vars with source visibility restricted to this file */
@@ -33,31 +40,77 @@ static int ares_init_flags;
33
40
 
34
41
  /* library-private global vars with visibility across the whole library */
35
42
 
36
- /* Some systems may return either NULL or a valid pointer on malloc(0). c-ares should
37
- * never call malloc(0) so lets return NULL so we're more likely to find an issue if it
38
- * were to occur. */
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. */
39
46
 
40
- static void *default_malloc(size_t size) { if (size == 0) { return NULL; } return malloc(size); }
47
+ static void *default_malloc(size_t size)
48
+ {
49
+ if (size == 0) {
50
+ return NULL;
51
+ }
52
+ return malloc(size);
53
+ }
41
54
 
42
- #if defined(WIN32)
43
- /* We need indirections to handle Windows DLL rules. */
44
- static void *default_realloc(void *p, size_t size) { return realloc(p, size); }
45
- static void default_free(void *p) { free(p); }
46
- #else
47
- # define default_realloc realloc
48
- # define default_free free
49
- #endif
50
- void *(*ares_malloc)(size_t size) = default_malloc;
51
- void *(*ares_realloc)(void *ptr, size_t size) = default_realloc;
52
- void (*ares_free)(void *ptr) = default_free;
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
+ }
53
107
 
54
108
  int ares_library_init(int flags)
55
109
  {
56
- if (ares_initialized)
57
- {
58
- ares_initialized++;
59
- return ARES_SUCCESS;
60
- }
110
+ if (ares_initialized) {
111
+ ares_initialized++;
112
+ return ARES_SUCCESS;
113
+ }
61
114
  ares_initialized++;
62
115
 
63
116
  /* NOTE: ARES_LIB_INIT_WIN32 flag no longer used */
@@ -67,28 +120,31 @@ int ares_library_init(int flags)
67
120
  return ARES_SUCCESS;
68
121
  }
69
122
 
70
- int ares_library_init_mem(int flags,
71
- void *(*amalloc)(size_t size),
123
+ int ares_library_init_mem(int flags, void *(*amalloc)(size_t size),
72
124
  void (*afree)(void *ptr),
73
125
  void *(*arealloc)(void *ptr, size_t size))
74
126
  {
75
- if (amalloc)
76
- ares_malloc = amalloc;
77
- if (arealloc)
78
- ares_realloc = arealloc;
79
- if (afree)
80
- ares_free = afree;
127
+ if (amalloc) {
128
+ __ares_malloc = amalloc;
129
+ }
130
+ if (arealloc) {
131
+ __ares_realloc = arealloc;
132
+ }
133
+ if (afree) {
134
+ __ares_free = afree;
135
+ }
81
136
  return ares_library_init(flags);
82
137
  }
83
138
 
84
-
85
139
  void ares_library_cleanup(void)
86
140
  {
87
- if (!ares_initialized)
141
+ if (!ares_initialized) {
88
142
  return;
143
+ }
89
144
  ares_initialized--;
90
- if (ares_initialized)
145
+ if (ares_initialized) {
91
146
  return;
147
+ }
92
148
 
93
149
  /* NOTE: ARES_LIB_INIT_WIN32 flag no longer used */
94
150
 
@@ -97,17 +153,17 @@ void ares_library_cleanup(void)
97
153
  #endif
98
154
 
99
155
  ares_init_flags = ARES_LIB_INIT_NONE;
100
- ares_malloc = malloc;
101
- ares_realloc = realloc;
102
- ares_free = free;
156
+ __ares_malloc = default_malloc;
157
+ __ares_realloc = default_realloc;
158
+ __ares_free = default_free;
103
159
  }
104
160
 
105
-
106
161
  int ares_library_initialized(void)
107
162
  {
108
163
  #ifdef USE_WINSOCK
109
- if (!ares_initialized)
164
+ if (!ares_initialized) {
110
165
  return ARES_ENOTINITIALIZED;
166
+ }
111
167
  #endif
112
168
  return ARES_SUCCESS;
113
169
  }
@@ -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
+ }