summaryrefslogtreecommitdiff
path: root/test/routing.c
diff options
context:
space:
mode:
authorJesper Jensen <jesper@slashwin.dk>2021-08-28 22:27:24 +0200
committerJesper Jensen <jesper@slashwin.dk>2021-08-28 22:27:24 +0200
commite00efb4381c5123699e4ef9807b67eba54ea06a0 (patch)
treedf2d7567a20e2313d576fb00aab61be8ee3383fa /test/routing.c
parentde3bec63c63b0c30a5a4e1d9b4a5478984b888e9 (diff)
Initial fanout implemented
Diffstat (limited to 'test/routing.c')
-rw-r--r--test/routing.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/routing.c b/test/routing.c
index c4b7730..60a7f03 100644
--- a/test/routing.c
+++ b/test/routing.c
@@ -91,3 +91,54 @@ void test_discard_offer_when_nodeid_added_twice() {
bool accept = routing_offer(&new, &entry);
TEST_ASSERT_FALSE_MESSAGE(accept, "Accepted entry when bucket was full");
}
+
+void test_interested_when_space_in_bucket() {
+ routing_flush();
+
+ struct nodeid new = self;
+ new.inner[4] ^= 0x00000001;
+
+ bool interest = routing_interested(&new);
+
+ TEST_ASSERT_TRUE_MESSAGE(interest, "Was not interested in node");
+}
+
+void test_not_interested_when_nodeid_in_table() {
+ routing_flush();
+
+ struct nodeid new = self;
+ new.inner[4] ^= 0x00000001;
+
+ struct entry* entry;
+ TEST_ASSERT_TRUE(routing_offer(&new, &entry));
+ entry->addr = (struct addr){.ip = IP(128,0,0,1), .port = 0};
+ entry->last = time(NULL);
+
+ bool interest = routing_interested(&new);
+ TEST_ASSERT_FALSE_MESSAGE(interest, "Was interested in node");
+}
+
+void test_not_interested_when_bucket_is_full() {
+ routing_flush();
+
+ // The address we are going to store
+ struct addr addr = (struct addr){.ip = IP(128,0,0,1), .port = 0};
+
+ struct nodeid new = self;
+ // Flip the top bit of the id to go into the low resolution bucket
+ new.inner[0] ^= 0x80000000;
+
+ // Fill up the bucket with entries
+ for(uint8_t i = 0; i < 8; i++) {
+ struct entry* entry;
+ TEST_ASSERT_TRUE_MESSAGE(routing_offer(&new, &entry), "Did not accept new entry");
+
+ // Set the entries
+ entry->addr = addr;
+ entry->last = time(NULL);
+
+ new.inner[4] += 1;
+ }
+
+ TEST_ASSERT_FALSE_MESSAGE(routing_interested(&new), "Still interested when bucket was full");
+}