From 69528489cddd27b4d4b9411d00b60cccc175b0e8 Mon Sep 17 00:00:00 2001 From: Jesper Jensen Date: Fri, 18 Jul 2025 09:32:16 +0200 Subject: Add a simple API for lookups --- src/proto.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/proto.c') diff --git a/src/proto.c b/src/proto.c index bd08c23..eb68566 100644 --- a/src/proto.c +++ b/src/proto.c @@ -398,7 +398,15 @@ PROCESS_REPONSE(lookup_response) { for(size_t i = 0; i < 8; i++) { if(cont->lookup->closest_addr[i].port == 0) { match_i = i; - match_score = UINT8_MAX; // Bogus value to signal that we found something + match_score = UINT8_MAX; // Bogus value to signal that we found an empty slot + break; + } + + if(memcmp(&cont->lookup->closest[i], &id, sizeof(struct nodeid)) == 0) { + // If the nodeid is already present in the lookup, we just ignore + // it completely + match_score = 0; + match_i = i; break; } @@ -419,16 +427,6 @@ PROCESS_REPONSE(lookup_response) { dbg("Discarding response from node behind the frontier"); } - uint8_t worst_match = UINT8_MAX; - for(size_t i = 0; i < 8; i++) { - if(cont->lookup->closest_addr[i].port == 0) { - worst_match = 0; - break; - } - - worst_match = MIN(worst_match, prefix(&cont->lookup->closest[i], &cont->lookup->target)); - } - // Fan out the search if the nodes are better than the worst one in the frontier for(uint8_t i = 0; i < nodes_len; i++) { uint8_t candidate_score = prefix(&nodes[i], &cont->lookup->target); -- cgit v1.2.3