diff options
| author | Jesper Jensen <jesper@jnsn.dev> | 2025-05-10 16:40:42 +0200 |
|---|---|---|
| committer | Jesper Jensen <jesper@jnsn.dev> | 2025-05-10 16:40:42 +0200 |
| commit | 89ef4c5c3bdc65862bffcffb7e9e21103d4e8bb4 (patch) | |
| tree | 925515267f0634c5586c6f3cc1c5b496be56f856 | |
| parent | 84ac4433045ba3ccd389ce0d3a9e573c1da30f7c (diff) | |
Run the lookup once in a while
| -rw-r--r-- | src/main.c | 8 | ||||
| -rw-r--r-- | src/proto.c | 4 |
2 files changed, 9 insertions, 3 deletions
@@ -178,7 +178,7 @@ int main(int argc, char** argv) { // Init the lookup dht.lookup.target = (struct nodeid){.inner={0x19b8a941, 0x38fa0191, 0x1403fac2, 0x581000ab, 0x19583cda}}; - dht.lookup.state = OP_EMPTY; // We want this to run at some point. + dht.lookup.state = OP_PENDING; // We want this to run at some point. #define RECV_BUFF_SIZE 4096 char buff_storage[RECV_BUFF_SIZE+1]; @@ -238,6 +238,12 @@ int main(int argc, char** argv) { rc = proto_run(&dht, buff, recv_len, (struct sockaddr_in*)&remote, remote_len, now, &message_cursor, outbuff+OUTBOX_SIZE); flush_messages(dht.sfd, outbuff, message_cursor); + if(dht.lookup.state == OP_COMPLETED && difftime(dht.lookup.timeout, now) < 0.0) { + dbg("Restart LOOKUP"); + // Restart the lookup periodically + dht.lookup.state = OP_PENDING; + } + save_config(); } diff --git a/src/proto.c b/src/proto.c index cff3a6a..df47cbb 100644 --- a/src/proto.c +++ b/src/proto.c @@ -919,8 +919,6 @@ int proto_run(struct dht* dht, char* buff, size_t recv_len, struct sockaddr_in* } 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; } @@ -939,9 +937,11 @@ int proto_run(struct dht* dht, char* buff, size_t recv_len, struct sockaddr_in* assert(rc == 0); } + dht->lookup.timeout = now + 120; dht->lookup.state = OP_ACTIVE; prom_counter_inc(lookup_count, NULL); } else if(dht->lookup.state == OP_ACTIVE && dht->lookup.timeout <= now) { + dht->lookup.timeout = now + 3600; dht->lookup.state = OP_COMPLETED; } |
