From 9d1ea6eb6b2417d96d14da7d0018446955737526 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 20 May 2009 15:56:58 +0000 Subject: [PATCH] (trunk libT) tweak tr-dht a little --- libtransmission/tr-dht.c | 56 +++++++++++++++++++++------------------- libtransmission/tr-dht.h | 14 +++++----- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/libtransmission/tr-dht.c b/libtransmission/tr-dht.c index d3417dba2..0c26e940b 100644 --- a/libtransmission/tr-dht.c +++ b/libtransmission/tr-dht.c @@ -20,31 +20,33 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/* ansi */ #include #include -#include -#include -#include -#include + +/* posix */ +#include /* sockaddr_in */ +#include /* sig_atomic_t */ #include -#include -#include #include -#include -#include +#include /* socket(), bind() */ +#include /* close() */ +/* third party */ #include - #include +/* libT */ #include "transmission.h" +#include "bencode.h" #include "crypto.h" -#include "peer-mgr.h" -#include "platform.h" +#include "net.h" +#include "peer-mgr.h" /* tr_peerMgrCompactToPex() */ +#include "platform.h" /* tr_threadNew() */ #include "session.h" -#include "torrent.h" -#include "trevent.h" +#include "torrent.h" /* tr_torrentFindFromHash() */ #include "tr-dht.h" +#include "trevent.h" /* tr_runInEventThread() */ #include "utils.h" #include "version.h" @@ -202,17 +204,17 @@ tr_dhtUninit(tr_session *ss) struct sockaddr_in sins[300]; char compact[300 * 6]; char *dat_file; - int n, i, j; - n = dht_get_nodes(sins, 300); - j = 0; - for(i = 0; i < n; i++) { - memcpy(compact + j, &sins[i].sin_addr, 4); - memcpy(compact + j + 4, &sins[i].sin_port, 2); + int i; + int n = dht_get_nodes(sins, 300); + int j = 0; + for( i=0; iconfigDir, "dht.dat", NULL ); tr_bencSaveFile( dat_file, &benc ); tr_free( dat_file ); @@ -225,9 +227,9 @@ tr_dhtUninit(tr_session *ss) } tr_bool -tr_dhtEnabled(tr_session *ss) +tr_dhtEnabled( const tr_session * ss ) { - return ss && ss == session; + return ss && ( ss == session ); } struct getstatus_closure @@ -237,7 +239,7 @@ struct getstatus_closure }; static void -getstatus(void *closure) +getstatus( void * closure ) { struct getstatus_closure * ret = closure; int good, dubious, incoming; @@ -257,7 +259,7 @@ getstatus(void *closure) } int -tr_dhtStatus(tr_session *ss, int *nodes_return ) +tr_dhtStatus( tr_session * ss, int * nodes_return ) { struct getstatus_closure ret = { -1, - 1 }; @@ -275,7 +277,7 @@ tr_dhtStatus(tr_session *ss, int *nodes_return ) } tr_port -tr_dhtPort(tr_session *ss) +tr_dhtPort( const tr_session *ss ) { return tr_dhtEnabled( ss ) ? dht_port : 0; } diff --git a/libtransmission/tr-dht.h b/libtransmission/tr-dht.h index 6da5dc4d1..d8538c276 100644 --- a/libtransmission/tr-dht.h +++ b/libtransmission/tr-dht.h @@ -26,10 +26,10 @@ THE SOFTWARE. #define TR_DHT_FIREWALLED 3 #define TR_DHT_GOOD 4 -int tr_dhtInit(tr_session *ss); -void tr_dhtUninit(tr_session *ss); -tr_bool tr_dhtEnabled(tr_session *ss); -int tr_dhtStatus(tr_session *ss, int * setme_nodeCount ); -tr_port tr_dhtPort(tr_session *ss); -int tr_dhtAddNode(tr_session *ss, tr_address *address, tr_port port, tr_bool bootstrap); -int tr_dhtAnnounce(tr_torrent *tor, tr_bool announce); +int tr_dhtInit( tr_session * ); +void tr_dhtUninit( tr_session * ); +tr_bool tr_dhtEnabled( const tr_session * ); +tr_port tr_dhtPort ( const tr_session * ); +int tr_dhtStatus( tr_session *, int * setme_nodeCount ); +int tr_dhtAddNode( tr_session *, tr_address *, tr_port, tr_bool bootstrap ); +int tr_dhtAnnounce( tr_torrent *, tr_bool announce );