summaryrefslogtreecommitdiffstats
path: root/src/dht.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht.c')
-rw-r--r--src/dht.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/dht.c b/src/dht.c
index 996dcb1..b11580a 100644
--- a/src/dht.c
+++ b/src/dht.c
@@ -158,7 +158,6 @@ struct torrent {
enum interested type; /**< is truthy only for manually added torrents */
unsigned char hash[20]; /**< infohash */
struct peer * peers;
- time_t last; /**< last operation on this torrent, so that inactive torrents are purged */
struct node * nodes; /**< closest K DHT nodes to this hash, used only for announce, peers, info and dl torrents */
struct torrent * next;
struct torrent * prev; /**< prev is here so that we can easily pop the oldest torrent. dht->last_torrent is useful here */
@@ -590,7 +589,8 @@ struct node * find (const unsigned char * id, struct bucket ** b, struct node **
prev = node;
node = node->next;
}
- *n = prev;
+ if (n)
+ *n = prev;
return node;
}
@@ -959,7 +959,7 @@ void compact (struct dht * d, const char * value, int len, struct torrent * t) {
return;
}
struct node * node = node_init();
- memcpy(node->addr.sin6_addr.s6_addr, "\0\0\0\0\0\0\0\0\0\0\0\0\xFF\xFF\xFF\xFF", 12);
+ memcpy(node->addr.sin6_addr.s6_addr, "\0\0\0\0\0\0\0\0\0\0\xFF\xFF", 12);
node->addr.sin6_port = *((uint16_t *) (value + len-2));
memcpy(node->addr.sin6_addr.s6_addr+(len == 4+2+20 ? 8 : 0), value + 20, len == 4+2+20 ? 4 : 16);
memcpy(node->id, value, 20);
@@ -1343,7 +1343,7 @@ void handle (struct dht * d, char * pkt, int len, struct sockaddr_in6 addr) {
if (!(p->type & string) || (p->valuelen != 6 && p->valuelen != 18))
break;
struct peer * peer = calloc(1, sizeof *peer);
- memcpy(peer->addr.sin6_addr.s6_addr, "\0\0\0\0\0\0\0\0\0\0\0\0\xFF\xFF\xFF\xFF", 12);
+ memcpy(peer->addr.sin6_addr.s6_addr, "\0\0\0\0\0\0\0\0\0\0\xFF\xFF", 12);
peer->addr.sin6_port = *((uint16_t *) (p->value + p->valuelen-2));
memcpy(peer->addr.sin6_addr.s6_addr+(p->valuelen == 6 ? 8 : 0), p->value, p->valuelen == 6 ? 4 : 16);
add_peer(d, torrent, peer);
@@ -1427,14 +1427,13 @@ void handle (struct dht * d, char * pkt, int len, struct sockaddr_in6 addr) {
.sin6_family = AF_INET6,
.sin6_port = *((uint16_t *) pkt)
};
- memcpy(a.sin6_addr.s6_addr, "\0\0\0\0\0\0\0\0\xFF\xFF\xFF\xFF", 12);
+ memcpy(a.sin6_addr.s6_addr, "\0\0\0\0\0\0\0\0\0\0\xFF\xFF", 12);
memcpy(a.sin6_addr.s6_addr+12, rr.rdata, 4);
potential_node(NULL, &a, NULL);
break;
case 16:
- if (!inet_ntop(AF_INET6, rr.rdata, address, INET6_ADDRSTRLEN+INET_ADDRSTRLEN+7)) {
+ if (!inet_ntop(AF_INET6, rr.rdata, address, INET6_ADDRSTRLEN+INET_ADDRSTRLEN+7))
L(d->log, "%s !inet_ntop(AF_INET6)", remote);
- }
sprintf(address+strlen(address), ":%u", ntohs(*((uint16_t *) pkt)));
L(d->log, "%s: AAAA %s", remote, address);
struct sockaddr_in6 aaaa = {
@@ -1586,7 +1585,7 @@ void periodic (struct dht * d) {
if (!refresh(d->buckets6))
dns++;
if (dns) {
- char packet[65536];
+ char packet[512];
struct __res_state state;
if (res_ninit(&state) == -1) {
L(d->log, "res_ninit(&state) == -1");
@@ -1594,7 +1593,7 @@ void periodic (struct dht * d) {
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpointer-sign"
- int size = res_nmkquery(&state, QUERY, "_dht._udp.travnik.sijanec.eu", ns_c_in, ns_t_srv, NULL, 0, NULL, packet, 65536) != -1;
+ int size = res_nmkquery(&state, QUERY, "_dht._udp.travnik.sijanec.eu", ns_c_in, ns_t_srv, NULL, 0, NULL, packet, 512) != -1; // for some reason always returns 1
#pragma GCC diagnostic pop
if (size == -1) {
L(d->log, "res_nmkquery(SRV) == -1");
@@ -1604,7 +1603,7 @@ void periodic (struct dht * d) {
#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"
for (int i = 0; i < state.nscount; i++)
if (state.nsaddr_list[i].sin_family == AF_INET) { // leider
- if (sendto(d->socket, packet, size, MSG_DONTWAIT | MSG_NOSIGNAL, &state.nsaddr_list[i], sizeof state.nsaddr_list[i]) == -1)
+ if (sendto(d->socket, packet, 512, MSG_DONTWAIT | MSG_NOSIGNAL, &state.nsaddr_list[i], sizeof state.nsaddr_list[i]) == -1)
L(d->log, "sendto: %s", strerror(errno));
d->txp++;
d->txb += size;
@@ -1669,6 +1668,7 @@ void periodic (struct dht * d) {
*/
void work (struct dht * d) {
+ L(d->log, "work()");
char packet[65536];
struct sockaddr_in6 addr;
socklen_t addrlen = sizeof addr;
@@ -1681,8 +1681,8 @@ void work (struct dht * d) {
else if (ret > 65536)
L(d->log, "recvfrom()d larger packet than 65536, not parsing packet");
else if (ret < 0) {
- if (ret != EAGAIN)
- L(d->log, "recvfrom(): %s", strerror(errno));
+ if (errno != EAGAIN)
+ L(d->log, "recvfrom(): %s (%d)", strerror(errno), errno);
else
periodic(d);
} else {