summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2022-12-06 16:00:47 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2022-12-06 16:00:47 +0100
commit155343068ae11dc9b80f1226499114b504e64aab (patch)
treeef6a0dc2dc0bd7f8fa6d19cf0e36e68cae36cd83
parentdelo v šoli (diff)
downloadtravnik-155343068ae11dc9b80f1226499114b504e64aab.tar
travnik-155343068ae11dc9b80f1226499114b504e64aab.tar.gz
travnik-155343068ae11dc9b80f1226499114b504e64aab.tar.bz2
travnik-155343068ae11dc9b80f1226499114b504e64aab.tar.lz
travnik-155343068ae11dc9b80f1226499114b504e64aab.tar.xz
travnik-155343068ae11dc9b80f1226499114b504e64aab.tar.zst
travnik-155343068ae11dc9b80f1226499114b504e64aab.zip
-rw-r--r--src/dht.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/dht.c b/src/dht.c
index b4b3cbf..852d2d0 100644
--- a/src/dht.c
+++ b/src/dht.c
@@ -36,7 +36,7 @@ struct node {
struct sockaddr_in6 addr;
int unanswered; /**< number of packets I've sent since last_received */
time_t last_received; /**< time when I received the last packet from it */
- time_t last_sent; /**< time when I sent the last packet to it */
+ time_t last_sent; /**< time when I sent the last query to it */
struct node * next;
};
@@ -49,6 +49,7 @@ struct node * node_init () {
if (!n)
return NULL;
n->last_received = seconds();
+ n->addr.sin6_family = AF_INET;
return n;
}
@@ -1138,8 +1139,17 @@ void handle (struct dht * d, char * pkt, int len, struct sockaddr_in6 addr) {
memcpy(node->addr.sin6_addr+(n->valuelen == 4+2+20 ? 8 : 0), n->value + 20, n->valuelen == 4+2+20 ? 4 : 16);
memcpy(node->id, n->value, 20);
potential_node(d, &node->addr, id); // NOTE02 this is quite important and means that at the beginning, a lot of packets will be sent, since every reply of potential_node will generate K replies. naively this would generate an exponentially increasing number of packets, in increasing powers of 8 (8**n). to prevent an absolute resource hog, this is only done when node would be useful and would contribute to the routing table
- if (torrent)
- else
+ if (torrent) { // TODO add node into list of nodes, replacing dead nodes. if there are no dead nodes, replace the node that's farthest away if this node is closer.
+ int i = 0;
+ struct node ** replaceable = NULL;
+ struct node ** index = &torrent->nodes;
+ while (*index) {
+ if (node_grade(*index) != good) {
+ *
+ }
+ *index = &(*index)->next;
+ }
+ } else
node_free(node);
}
case 'E':