summaryrefslogtreecommitdiff
path: root/src/routing.h
diff options
context:
space:
mode:
authorJesper Jensen <jesper@slashwin.dk>2021-06-17 00:04:36 +0200
committerJesper Jensen <jesper@slashwin.dk>2021-06-17 00:04:36 +0200
commit23359fd5d5a89360b22e986c9bdbeb2c370a4bcb (patch)
treece57c9b7d36d6023febc0ba92a7b263a8473c03d /src/routing.h
parent8ded9142c1514ab04905e623247a84313a773fa7 (diff)
Add tests and test running
Diffstat (limited to 'src/routing.h')
-rw-r--r--src/routing.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/routing.h b/src/routing.h
new file mode 100644
index 0000000..dc40aa9
--- /dev/null
+++ b/src/routing.h
@@ -0,0 +1,39 @@
+#pragma once
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <time.h>
+#include <stdio.h>
+
+#define dbg(format, ...) \
+ dbgl(format "\n", ## __VA_ARGS__)
+
+#define dbgl(format, ...) \
+ printf(format, ## __VA_ARGS__); \
+ fflush(stderr)
+
+#define err(format, ...) \
+ printf(format "\n", ## __VA_ARGS__); \
+ fflush(stderr)
+
+
+struct addr {
+ uint32_t ip;
+ uint16_t port;
+};
+
+struct nodeid {
+ uint32_t inner[5];
+};
+
+struct entry {
+ bool set;
+ struct nodeid id;
+ time_t last;
+ struct addr addr;
+};
+
+void routing_init(struct nodeid* myid);
+bool routing_offer(struct nodeid* id, struct entry **dest);
+size_t rounting_closest(struct nodeid* needle, size_t n, struct entry** res);