diff options
| author | Jesper Jensen <jesper@jnsn.dev> | 2025-05-04 00:39:13 +0200 |
|---|---|---|
| committer | Jesper Jensen <jesper@jnsn.dev> | 2025-05-04 00:39:13 +0200 |
| commit | 2c4af77f5f7231b560c344ccaff3cc73f0d616e9 (patch) | |
| tree | 44dbe299c49b35399fb755ef81929b32af9312fd /src/proto.c | |
| parent | bdb9db6458594d9265c86362d248e30fcf8ea26e (diff) | |
Refactor lookup init and add routing table metric
I think it would be nice to see the detailed routing table occupancy.
I've added a metric that exposes the current occupancy of each bucket.
That should provide me some insight into the current distribution of
nodes and if we need to find a way to keep the closer buckets alive.
Diffstat (limited to 'src/proto.c')
| -rw-r--r-- | src/proto.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/proto.c b/src/proto.c index 2adc52b..a0f6e94 100644 --- a/src/proto.c +++ b/src/proto.c @@ -282,6 +282,8 @@ PROCESS_REPONSE(lookup_response) { fatal("Response too short"); } + assert(cont->lookup->state == OP_ACTIVE); + struct nodeid id; uint8_t nodes_len; struct nodeid nodes[8]; @@ -586,6 +588,7 @@ PROCESS_REPONSE(getclient_response) { entry->addr.ip = ipv4->sin_addr.s_addr; entry->addr.port = ipv4->sin_port; entry->expire = now + PROTO_UNCTM; + routing_update_metrics(); } else { dbg("We are no longer interested"); } @@ -901,6 +904,33 @@ int proto_run(struct dht* dht, char* buff, size_t recv_len, struct sockaddr_in* routing_oldest(&oldest); } + if(dht->lookup.state == OP_PENDING) { + dht->lookup.timeout = now + 120; + + for(size_t i = 0; i < 8; i++) { + dht->lookup.closest_addr[i].port = 0; + } + + // Issue the first round of requests + struct entry* entry[8]; + int found = routing_closest(&dht->lookup.target, sizeof(entry)/sizeof(entry[0]), entry); + for(size_t i = 0; i < found; i++) { + struct sockaddr_in dest = { + .sin_family = AF_INET, + .sin_addr = {entry[i]->addr.ip}, + .sin_port = entry[i]->addr.port, + }; + + int rc = send_lookup(dht, &dht->lookup.target, time(NULL), (struct sockaddr*)&dest, sizeof(struct sockaddr_in), &msgbuff); + assert(rc == 0); + } + + dht->lookup.state = OP_ACTIVE; + prom_counter_inc(lookup_count, NULL); + } else if(dht->lookup.state == OP_ACTIVE && dht->lookup.timeout <= now) { + dht->lookup.state = OP_COMPLETED; + } + // @HACK 0 means unitialized, only happens in tests if(peer_table_size != 0) { expire_hashes(now); |
