summaryrefslogtreecommitdiff
path: root/src/proto.h
diff options
context:
space:
mode:
authorJesper Jensen <jesper@jnsn.dev>2024-01-28 09:01:22 +0100
committerJesper Jensen <jesper@jnsn.dev>2025-04-12 10:21:20 +0200
commitcd622b745254baafa21adf4b1b724e079652321a (patch)
treeb1faf03808a5f8729cf8a69f971c00cb9d662683 /src/proto.h
parent47d4780eb448f839fc6b0644135395f879080ba4 (diff)
I don't know
Diffstat (limited to 'src/proto.h')
-rw-r--r--src/proto.h45
1 files changed, 27 insertions, 18 deletions
diff --git a/src/proto.h b/src/proto.h
index 0ce887e..0336c0c 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -1,16 +1,36 @@
#pragma once
#include "routing.h"
+#include "sha256.h"
#include <sys/socket.h>
#include <arpa/inet.h>
+#define TOKEN_ITMO 20
+#define TOKEN_VTMO 60
+#define TOKEN_TLEN 32
+#define TOKEN_KNUM (TOKEN_VTMO/TOKEN_ITMO)
+
+#define TOK_VALI 1
+#define TOK_INVA 0
+
+struct tokens {
+ SHA256_CTX ctx;
+
+ char ticket[TOKEN_KNUM][TOKEN_TLEN];
+ time_t issued[TOKEN_KNUM];
+ size_t head;
+};
+
+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);
+
// 192.0.2.0
#define UNDEF_ADDR (struct in_addr){0xC0000200}
#define MAX_DISC 32
-#define MAX_INFLIGHT 32
+#define MAX_INFLIGHT 128
-#define PROTO_UNCTM 60
-#define PROTO_TMOUT 5
+#define PROTO_UNCTM 60*5
+#define PROTO_TMOUT 30
struct ping {
struct nodeid remote_id;
@@ -46,24 +66,13 @@ struct dht {
tmout* timeout_fun;
union message_cont cont;
} requestdata[MAX_INFLIGHT];
+
+ time_t wake;
+ struct tokens tokens;
};
-// @HACK: This isn't true anymore
-// The longest message we can send is probably a response to find_node which
-// consists of:
-// d1:t <-- 4 bytes
-// <tid length> <-- 2 bytes
-// : <-- 1 byte
-// <tid> <-- 16 bytes*
-// 1:y1:r1:r <-- 9 bytes
-// d2:id20: <-- 8 bytes
-// <our nodeid> <-- 20 bytes
-// 5:nodes208: <-- 11 bytes
-// <payload> <-- 208 bytes
-// ee <-- 2 bytes
-// TOTAL 281 bytes
struct message {
- char payload[281];
+ char payload[1024];
size_t payload_len;
struct sockaddr_storage dest;
socklen_t dest_len;