Changeset 8452


Ignore:
Timestamp:
May 20, 2009, 3:56:58 PM (12 years ago)
Author:
charles
Message:

(trunk libT) tweak tr-dht a little

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/tr-dht.c

    r8445 r8452  
    2121*/
    2222
     23/* ansi */
    2324#include <errno.h>
    2425#include <stdio.h>
    25 #include <stdlib.h>
    26 #include <string.h>
    27 #include <unistd.h>
    28 #include <fcntl.h>
     26
     27/* posix */
     28#include <netinet/in.h> /* sockaddr_in */
     29#include <signal.h> /* sig_atomic_t */
    2930#include <sys/time.h>
    30 #include <sys/signal.h>
    31 #include <arpa/inet.h>
    3231#include <sys/types.h>
    33 #include <sys/socket.h>
    34 #include <netdb.h>
    35 
     32#include <sys/socket.h> /* socket(), bind() */
     33#include <unistd.h> /* close() */
     34
     35/* third party */
    3636#include <event.h>
    37 
    3837#include <dht/dht.h>
    3938
     39/* libT */
    4040#include "transmission.h"
     41#include "bencode.h"
    4142#include "crypto.h"
    42 #include "peer-mgr.h"
    43 #include "platform.h"
     43#include "net.h"
     44#include "peer-mgr.h" /* tr_peerMgrCompactToPex() */
     45#include "platform.h" /* tr_threadNew() */
    4446#include "session.h"
    45 #include "torrent.h"
    46 #include "trevent.h"
     47#include "torrent.h" /* tr_torrentFindFromHash() */
    4748#include "tr-dht.h"
     49#include "trevent.h" /* tr_runInEventThread() */
    4850#include "utils.h"
    4951#include "version.h"
     
    203205        char compact[300 * 6];
    204206        char *dat_file;
    205         int n, i, j;
    206         n = dht_get_nodes(sins, 300);
    207         j = 0;
    208         for(i = 0; i < n; i++) {
    209             memcpy(compact + j, &sins[i].sin_addr, 4);
    210             memcpy(compact + j + 4, &sins[i].sin_port, 2);
     207        int i;
     208        int n = dht_get_nodes(sins, 300);
     209        int j = 0;
     210        for( i=0; i<n; ++i ) {
     211            memcpy( compact + j, &sins[i].sin_addr, 4 );
     212            memcpy( compact + j + 4, &sins[i].sin_port, 2 );
    211213            j += 6;
    212214        }
    213         tr_bencInitDict(&benc, 2);
    214         tr_bencDictAddRaw(&benc, "id", myid, 20);
    215         tr_bencDictAddRaw(&benc, "nodes", compact, j);
     215        tr_bencInitDict( &benc, 2 );
     216        tr_bencDictAddRaw( &benc, "id", myid, 20 );
     217        tr_bencDictAddRaw( &benc, "nodes", compact, j );
    216218        dat_file = tr_buildPath( ss->configDir, "dht.dat", NULL );
    217219        tr_bencSaveFile( dat_file, &benc );
     
    226228
    227229tr_bool
    228 tr_dhtEnabled(tr_session *ss)
    229 {
    230     return ss && ss == session;
     230tr_dhtEnabled( const tr_session * ss )
     231{
     232    return ss && ( ss == session );
    231233}
    232234
     
    238240
    239241static void
    240 getstatus(void *closure)
     242getstatus( void * closure )
    241243{
    242244    struct getstatus_closure * ret = closure;
     
    258260
    259261int
    260 tr_dhtStatus(tr_session *ss, int *nodes_return )
     262tr_dhtStatus( tr_session * ss, int * nodes_return )
    261263{
    262264    struct getstatus_closure ret = { -1, - 1 };
     
    276278
    277279tr_port
    278 tr_dhtPort(tr_session *ss)
     280tr_dhtPort( const tr_session *ss )
    279281{
    280282    return tr_dhtEnabled( ss ) ? dht_port : 0;
  • trunk/libtransmission/tr-dht.h

    r8435 r8452  
    2727#define TR_DHT_GOOD 4
    2828
    29 int tr_dhtInit(tr_session *ss);
    30 void tr_dhtUninit(tr_session *ss);
    31 tr_bool tr_dhtEnabled(tr_session *ss);
    32 int tr_dhtStatus(tr_session *ss, int * setme_nodeCount );
    33 tr_port tr_dhtPort(tr_session *ss);
    34 int tr_dhtAddNode(tr_session *ss, tr_address *address, tr_port port, tr_bool bootstrap);
    35 int tr_dhtAnnounce(tr_torrent *tor, tr_bool announce);
     29int  tr_dhtInit( tr_session * );
     30void tr_dhtUninit( tr_session * );
     31tr_bool tr_dhtEnabled( const tr_session * );
     32tr_port tr_dhtPort ( const tr_session * );
     33int tr_dhtStatus( tr_session *, int * setme_nodeCount );
     34int tr_dhtAddNode( tr_session *, tr_address *, tr_port, tr_bool bootstrap );
     35int tr_dhtAnnounce( tr_torrent *, tr_bool announce );
Note: See TracChangeset for help on using the changeset viewer.