diff options
| author | Jesper Jensen <jesper@jnsn.dev> | 2025-04-16 23:34:03 +0200 |
|---|---|---|
| committer | Jesper Jensen <jesper@jnsn.dev> | 2025-04-16 23:34:03 +0200 |
| commit | 188666dc51233051985715b01631e069a7939442 (patch) | |
| tree | 83f9e51f431e11993eeabb763856298c0e042395 /src/proto.h | |
| parent | 78a6d2ec1fb9c61cda1a8bcdc3843b159cdd850c (diff) | |
Add a first approximation of a lookup algorithm
This isn't really "correct" but it's probably going to work. It's
a rough implementation of the Kademlia lookup algorithm, with the
modification that we don't keep track of anything behind the frontier.
We are therefore counting on peers being ok with us potentially sending
them the "same" request multiple times. If they respond in a reasonable
time, the double request rate _should_ be minimal, but that of course
carries the risk that an already overloaded peer would get even more
queries.
I don't know. It's a first try at something. I need to see it work
before I write it off completely.
Diffstat (limited to 'src/proto.h')
| -rw-r--r-- | src/proto.h | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/proto.h b/src/proto.h index 0336c0c..0e1bcbc 100644 --- a/src/proto.h +++ b/src/proto.h @@ -21,6 +21,15 @@ struct tokens { size_t head; }; +struct lookup { + struct nodeid target; + + struct nodeid closest[8]; + struct addr closest_addr[8]; + + time_t timeout; +}; + void token_create(struct tokens* tokens, time_t now, struct addr* remote, char* token); int token_validate(struct tokens* tokens, time_t now, struct addr* remote, char* token); @@ -40,10 +49,15 @@ struct ping { union message_cont { struct ping ping; + struct lookup *lookup; }; struct dht; -struct msgbuff; +struct msgbuff { + struct message** messages; + const struct message* const messages_end; +}; + #define PROCESS_REPONSE(NAME) int (NAME)(struct dht* dht, time_t now, union message_cont* cont, char* packet, size_t packet_len, int socket, struct sockaddr* remote, socklen_t remote_len, struct msgbuff* msgbuff) typedef PROCESS_REPONSE(resp); @@ -67,6 +81,8 @@ struct dht { union message_cont cont; } requestdata[MAX_INFLIGHT]; + struct lookup lookup; + time_t wake; struct tokens tokens; }; @@ -78,6 +94,8 @@ struct message { socklen_t dest_len; }; +int send_lookup(struct dht* dht, struct nodeid* target, time_t now, const struct sockaddr* dest_addr, socklen_t dest_len, struct msgbuff* msgbuff); + void proto_begin(struct dht* dht, time_t now, struct message** output, const struct message* const output_end); int proto_run(struct dht* dht, char* buffer, size_t buffer_len, struct sockaddr_in* remote, socklen_t remote_len, time_t now, struct message** output, const struct message* const output_end); void proto_end(struct dht* dht); |
