diff options
| author | Jesper Jensen <jesper@slashwin.dk> | 2021-08-28 22:27:24 +0200 |
|---|---|---|
| committer | Jesper Jensen <jesper@slashwin.dk> | 2021-08-28 22:27:24 +0200 |
| commit | e00efb4381c5123699e4ef9807b67eba54ea06a0 (patch) | |
| tree | df2d7567a20e2313d576fb00aab61be8ee3383fa /src/routing.c | |
| parent | de3bec63c63b0c30a5a4e1d9b4a5478984b888e9 (diff) | |
Initial fanout implemented
Diffstat (limited to 'src/routing.c')
| -rw-r--r-- | src/routing.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/routing.c b/src/routing.c index ff7eadc..b8ab037 100644 --- a/src/routing.c +++ b/src/routing.c @@ -82,6 +82,28 @@ int8_t scan(uint16_t baseIndex, struct nodeid* id) { return index; } +bool routing_interested(struct nodeid* id) { + uint16_t bucketIndex = prefix(&myID, id); + // The nodeid is the same as our own + if(bucketIndex == IDBITS) { + return false; + } + + // If they are sufficiently similar they end up in the final bucket. Clamp the index to ensure. + bucketIndex = bucketIndex > (IDBITS - BUCKETBITS) ? (IDBITS - BUCKETBITS) : bucketIndex; + assert(bucketIndex <= IDBITS - BUCKETBITS); + + uint16_t baseIndex = bucketIndex * BUCKETSIZE; + int8_t inBucketIndex = scan(baseIndex, id); + + if(inBucketIndex == -1) { + // The bucket either already contains the node, or it has no more space + return false; + } + + return true; +} + // Offer the routing table a new node bool routing_offer(struct nodeid* id, struct entry **dest) { uint16_t bucketIndex = prefix(&myID, id); |
