MCPcopy Create free account
hub / github.com/defold/defold / CollectProbeClaims

Function CollectProbeClaims

engine/dlib/src/dlib/mdns.cpp:1344–1385  ·  view source on GitHub ↗

Extracts and sorts only the authority records that answer one probe question. This gives the exact claim set needed for pairwise tiebreaking.

Source from the content-addressed store, hash-verified

1342 // Extracts and sorts only the authority records that answer one probe
1343 // question. This gives the exact claim set needed for pairwise tiebreaking.
1344 static bool CollectProbeClaims(const uint8_t* data, uint32_t size, uint32_t section_offset, uint16_t record_count,
1345 const char* target_name, ProbeRecord* records, uint32_t max_records, uint32_t* out_count)
1346 {
1347 *out_count = 0;
1348
1349 uint32_t offset = section_offset;
1350 for (uint16_t i = 0; i < record_count && offset < size; ++i)
1351 {
1352 char name[256];
1353 uint16_t type = 0;
1354 uint16_t klass = 0;
1355 uint32_t ttl = 0;
1356 uint16_t rdlength = 0;
1357 if (!ReadName(data, size, &offset, name, sizeof(name))
1358 || !ReadU16(data, size, &offset, &type)
1359 || !ReadU16(data, size, &offset, &klass)
1360 || !ReadU32(data, size, &offset, &ttl)
1361 || !ReadU16(data, size, &offset, &rdlength))
1362 {
1363 return false;
1364 }
1365
1366 (void) ttl;
1367
1368 if (offset + rdlength > size)
1369 return false;
1370
1371 const uint32_t rdata_offset = offset;
1372 offset += rdlength;
1373
1374 if (!NameEquals(name, target_name) || (klass & ~DNS_CLASS_FLUSH) != DNS_CLASS_IN)
1375 continue;
1376
1377 if (*out_count >= max_records || !DecodeIncomingProbeRecord(data, size, type, klass, rdata_offset, rdlength, &records[*out_count]))
1378 return false;
1379
1380 ++(*out_count);
1381 }
1382
1383 SortProbeRecords(records, *out_count);
1384 return true;
1385 }
1386
1387 // Returns true when the remote authority claims outrank our tentative data,
1388 // meaning we lost the simultaneous-probe tiebreak for this unique name.

Callers 1

Calls 6

NameEqualsFunction · 0.85
SortProbeRecordsFunction · 0.85
ReadNameFunction · 0.70
ReadU16Function · 0.70
ReadU32Function · 0.70

Tested by

no test coverage detected