From 155343068ae11dc9b80f1226499114b504e64aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Tue, 6 Dec 2022 16:00:47 +0100 Subject: =?UTF-8?q?delo=20v=20knji=C5=BEnici?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dht.c | 16 +++++++++++++--- 1 file 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': -- cgit v1.2.3