diff --git a/third-party/dht/CHANGES b/third-party/dht/CHANGES index bc7cad1bc..451ef78bc 100644 --- a/third-party/dht/CHANGES +++ b/third-party/dht/CHANGES @@ -1,3 +1,8 @@ +9 January 2011: dht-0.17: + + * Fix a bug that prevented calling dht_init after dht_uninit. + * Remove the "dofree" parameter to dht_uninit. + 23 December 2010: dht-0.16: * Change the interface to allow sharing of the UDP socket e.g. with uTP. diff --git a/third-party/dht/README b/third-party/dht/README index 1c42fefb6..ba4e6e177 100644 --- a/third-party/dht/README +++ b/third-party/dht/README @@ -34,9 +34,7 @@ at client shutdown. * dht_uninit -This may be called at the end of the session. If dofree is true, it frees -all the memory allocated for the DHT. If dofree is false, this function -currently does nothing. +This may be called at the end of the session. Bootstrapping ************* diff --git a/third-party/dht/dht-example.c b/third-party/dht/dht-example.c index 80037123a..d05dcab4b 100644 --- a/third-party/dht/dht-example.c +++ b/third-party/dht/dht-example.c @@ -400,7 +400,7 @@ main(int argc, char **argv) printf("Found %d (%d + %d) good nodes.\n", i, num, num6); } - dht_uninit(1); + dht_uninit(); return 0; usage: diff --git a/third-party/dht/dht.c b/third-party/dht/dht.c index 723f8aaea..abb21d336 100644 --- a/third-party/dht/dht.c +++ b/third-party/dht/dht.c @@ -1,5 +1,5 @@ /* -Copyright (c) 2009, 2010 by Juliusz Chroboczek +Copyright (c) 2009-2011 by Juliusz Chroboczek Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -1659,15 +1659,15 @@ dht_init(int s, int s6, const unsigned char *id, const unsigned char *v) } int -dht_uninit(int dofree) +dht_uninit() { - if(dht_socket < 0) { + if(dht_socket < 0 && dht_socket6 < 0) { errno = EINVAL; return -1; } - if(!dofree) - return 1; + dht_socket = -1; + dht_socket6 = -1; while(buckets) { struct bucket *b = buckets; @@ -1680,6 +1680,17 @@ dht_uninit(int dofree) free(b); } + while(buckets6) { + struct bucket *b = buckets6; + buckets6 = b->next; + while(b->nodes) { + struct node *n = b->nodes; + b->nodes = n->next; + free(n); + } + free(b); + } + while(storage) { struct storage *st = storage; storage = storage->next; diff --git a/third-party/dht/dht.h b/third-party/dht/dht.h index 2364ac927..2f76e5678 100644 --- a/third-party/dht/dht.h +++ b/third-party/dht/dht.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2009, 2010 by Juliusz Chroboczek +Copyright (c) 2009-2011 by Juliusz Chroboczek Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -47,7 +47,7 @@ int dht_nodes(int af, void dht_dump_tables(FILE *f); int dht_get_nodes(struct sockaddr_in *sin, int *num, struct sockaddr_in6 *sin6, int *num6); -int dht_uninit(int dofree); +int dht_uninit(void); /* This must be provided by the user. */ void dht_hash(void *hash_return, int hash_size,