summaryrefslogtreecommitdiff
path: root/src/routing.h
blob: b0e9922abc8ce7fb1bc6b06c6a3db804212a48eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#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);
void routing_flush();
bool routing_offer(struct nodeid* id, struct entry **dest);
size_t routing_closest(struct nodeid* needle, size_t n, struct entry** res);