MCPcopy Create free account
hub / github.com/nodejs/node / pickFamily

Method pickFamily

deps/undici/src/lib/interceptor/dns.js:321–351  ·  view source on GitHub ↗
(origin, ipFamily)

Source from the content-addressed store, hash-verified

319 }
320
321 pickFamily (origin, ipFamily) {
322 const records = this.storage.get(origin.hostname)?.records
323 if (!records) {
324 return null
325 }
326
327 const family = records[ipFamily]
328 if (!family) {
329 return null
330 }
331
332 if (family.offset == null || family.offset === maxInt) {
333 family.offset = 0
334 } else {
335 family.offset++
336 }
337
338 const position = family.offset % family.ips.length
339 const ip = family.ips[position] ?? null
340 if (ip == null) {
341 return ip
342 }
343
344 if (Date.now() - ip.timestamp > ip.ttl) { // record TTL is already in ms
345 // We delete expired records
346 // It is possible that they have different TTL, so we manage them individually
347 family.ips.splice(position, 1)
348 }
349
350 return ip
351 }
352
353 setRecords (origin, addresses) {
354 const timestamp = Date.now()

Callers 1

onResponseErrorMethod · 0.80

Calls 2

nowMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected