summaryrefslogtreecommitdiff
path: root/src/proto.c
diff options
context:
space:
mode:
authorJesper Jensen <jesper@jnsn.dev>2025-07-18 09:32:16 +0200
committerJesper Jensen <jesper@jnsn.dev>2025-07-18 09:32:33 +0200
commit69528489cddd27b4d4b9411d00b60cccc175b0e8 (patch)
treeeeed9d13f99858b3fd5660bc8d57e86bf81088a3 /src/proto.c
parenta46e9a5cbb8fc233a0ccb47708e7686c2b561ac0 (diff)
Add a simple API for lookups
Diffstat (limited to 'src/proto.c')
-rw-r--r--src/proto.c20
1 files changed, 9 insertions, 11 deletions
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);