master
1#ifndef HEADER_CURL_DNSCACHE_H
2#define HEADER_CURL_DNSCACHE_H
3/***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
9 *
10 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11 *
12 * This software is licensed as described in the file COPYING, which
13 * you should have received as part of this distribution. The terms
14 * are also available at https://curl.se/docs/copyright.html.
15 *
16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17 * copies of the Software, and permit persons to whom the Software is
18 * furnished to do so, under the terms of the COPYING file.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 * SPDX-License-Identifier: curl
24 *
25 ***************************************************************************/
26#include "curl_setup.h"
28#include "hash.h"
29#include "curlx/timeval.h"
30#include "curlx/strparse.h"
32struct addrinfo;
33struct hostent;
34struct Curl_easy;
35struct connectdata;
36struct easy_pollset;
37struct Curl_https_rrinfo;
38struct Curl_multi;
39struct Curl_peer;
41#define CURL_DNST_INIT '\0'
42#define CURL_DNST_ADDR 'A'
43#define CURL_DNST_HTTPS 'H'
45struct Curl_dns_entry {
46 struct Curl_addrinfo *addr;
47#ifdef USE_HTTPSRR
48 struct Curl_https_rrinfo *hinfo;
49#endif
50 struct curltime added; /* time this entry was added to the cache */
51 uint32_t refcount; /* reference counter, entry is freed on reaching 0 */
52 uint16_t hostlen; /* length of hostname */
53 uint16_t port; /* host port */
54 char type; /* CURL_DNST_ADDR or CURL_DNST_HTTPS */
55 uint8_t dns_queries; /* CURL_DNSQ_* type of queries performed for this */
56 uint8_t dns_responses; /* CURL_DNSQ_* type this entry has responses for */
57 BIT(permanent); /* entry is permanent, e.g. does not time out */
58 /* hostname that resolved to addr. may be NULL (Unix domain sockets). */
59 char hostname[1];
60};
62struct dnsc_id {
63 struct Curl_str name;
64 uint16_t port;
65 char type;
66};
68#define MAX_HOSTCACHE_LEN (255 + 3) /* max FQDN + type + port */
70struct dnsc_key {
71 uint8_t data[MAX_HOSTCACHE_LEN];
72 size_t len;
73};
75/*
76 * Create a `Curl_dns_entry` with a reference count of 1.
77 * Use `Curl_dns_entry_unlink()` to release your hold on it.
78 *
79 * The call takes ownership of `paddr`, even in case of failure, and always
80 * clears `*paddr`. It makes a copy of `hostname`.
81 *
82 * Returns entry or NULL on OOM.
83 */
84struct Curl_dns_entry *Curl_dnsc_mk_addr(struct Curl_easy *data,
85 uint8_t dns_queries,
86 struct Curl_addrinfo **paddr,
87 struct Curl_peer *peer);
89struct Curl_dns_entry *Curl_dnsc_mk_addr2(struct Curl_easy *data,
90 uint8_t dns_queries,
91 struct Curl_addrinfo **paddr1,
92 struct Curl_addrinfo **paddr2,
93 struct Curl_peer *peer);
95#ifdef USE_HTTPSRR
96struct Curl_dns_entry *Curl_dnsc_mk_https(struct Curl_easy *data,
97 struct Curl_https_rrinfo **phinfo,
98 struct Curl_peer *peer);
99#endif /* USE_HTTPSRR */
101/* unlink a dns entry, frees all resources if it was the last reference.
102 * Always clears `*pdns`` */
103void Curl_dns_entry_unlink(struct Curl_easy *data,
104 struct Curl_dns_entry **pdns);
106struct Curl_dnscache {
107 struct Curl_hash entries;
108};
110/* init a new dns cache */
111void Curl_dnscache_init(struct Curl_dnscache *dns, size_t size);
113void Curl_dnscache_destroy(struct Curl_dnscache *dns);
115/* prune old entries from the DNS cache */
116void Curl_dnscache_prune(struct Curl_easy *data, const struct curltime *pnow);
118/* clear the DNS cache */
119void Curl_dnscache_clear(struct Curl_easy *data);
121/*
122 * Curl_dnscache_get() fetches a 'Curl_dns_entry' already in the DNS cache.
123 *
124 * Returns the Curl_dns_entry entry pointer or NULL if not in the cache.
125 *
126 * The returned data *MUST* be "released" with Curl_dns_entry_unlink() after
127 * use, or we will leak memory!
128 * Returns CURLE_OK or CURLE_COULDNT_RESOLVE_HOST when a negative
129 * entry was in the cache.
130 */
131CURLcode Curl_dnscache_get(struct Curl_easy *data,
132 uint8_t dns_queries,
133 struct Curl_peer *peer,
134 struct Curl_dns_entry **pentry);
136/*
137 * Curl_dnscache_addr() adds `entry` to the cache, increasing its
138 * reference count on success.
139 */
140CURLcode Curl_dnscache_add(struct Curl_easy *data,
141 struct Curl_dns_entry *entry);
143/* Store a "negative" entry for host:port, e.g. remember that
144 * it could not be resolved. */
145CURLcode Curl_dnscache_add_negative(struct Curl_easy *data,
146 uint8_t dns_queries,
147 struct Curl_peer *peer);
149/*
150 * Populate the cache with specified entries from CURLOPT_RESOLVE.
151 */
152CURLcode Curl_loadhostpairs(struct Curl_easy *data);
154#endif /* HEADER_CURL_DNSCACHE_H */
Diagnostics4 git calls · 31 ms
CallStatusSizeTime031 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2001.9 KiB · hit26 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=26 git.response.bytes=1919 git.response.cache=HIT git.response.duration_ms=26 git.fetch.wants=0b47710b7f1da34c3925c6be4cd365125dcecd39 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1919 git.pkt.payload.max=1898 git.sideband.band1.bytes=1897 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e9efb54f870acb
- Request
- c9dd3fff…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format