Changeset 9434


Ignore:
Timestamp:
Oct 29, 2009, 4:10:03 PM (12 years ago)
Author:
charles
Message:

(trunk libT) #2508 atom->port never updated

Location:
trunk/libtransmission
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-common.h

    r8903 r9434  
    4949    TR_PEER_CLIENT_GOT_ALLOWED_FAST,
    5050    TR_PEER_CLIENT_GOT_SUGGEST,
     51    TR_PEER_CLIENT_GOT_PORT,
    5152    TR_PEER_PEER_GOT_DATA,
    5253    TR_PEER_PEER_PROGRESS,
     
    6869    tr_bool          wasPieceData; /* for GOT_DATA */
    6970    tr_bool          uploadOnly;   /* for UPLOAD_ONLY */
     71    tr_port          port;         /* for GOT_PORT */
    7072}
    7173tr_peer_event;
  • trunk/libtransmission/peer-mgr.c

    r9416 r9434  
    131131}
    132132
     133static const char*
     134tr_atomAddrStr( const struct peer_atom * atom )
     135{
     136    return tr_peerIoAddrStr( &atom->addr, atom->port );
     137}
     138
    133139struct tr_blockIterator
    134140{
     
    261267**/
    262268
     269const tr_address *
     270tr_peerAddress( const tr_peer * peer )
     271{
     272    return &peer->atom->addr;
     273}
     274
    263275static Torrent*
    264276getExistingTorrent( tr_peerMgr *    manager,
     
    271283
    272284static int
    273 peerCompare( const void * va, const void * vb )
    274 {
    275     const tr_peer * a = va;
    276     const tr_peer * b = vb;
    277 
    278     return tr_compareAddresses( &a->addr, &b->addr );
     285peerCompare( const void * a, const void * b )
     286{
     287    return tr_compareAddresses( tr_peerAddress( a ), tr_peerAddress( b ) );
    279288}
    280289
    281290static int
    282 peerCompareToAddr( const void * va, const void * vb )
    283 {
    284     const tr_peer * a = va;
    285 
    286     return tr_compareAddresses( &a->addr, vb );
     291peerCompareToAddr( const void * a, const void * vb )
     292{
     293    return tr_compareAddresses( tr_peerAddress( a ), vb );
    287294}
    288295
     
    320327
    321328static tr_peer*
    322 peerConstructor( const tr_address * addr )
    323 {
    324     tr_peer * p;
    325     p = tr_new0( tr_peer, 1 );
    326     p->addr = *addr;
    327     return p;
     329peerConstructor( struct peer_atom * atom )
     330{
     331    tr_peer * peer = tr_new0( tr_peer, 1 );
     332    peer->atom = atom;
     333    return peer;
    328334}
    329335
    330336static tr_peer*
    331 getPeer( Torrent          * torrent,
    332          const tr_address * addr )
     337getPeer( Torrent * torrent, struct peer_atom * atom )
    333338{
    334339    tr_peer * peer;
     
    336341    assert( torrentIsLocked( torrent ) );
    337342
    338     peer = getExistingPeer( torrent, addr );
     343    peer = getExistingPeer( torrent, &atom->addr );
    339344
    340345    if( peer == NULL )
    341346    {
    342         peer = peerConstructor( addr );
     347        peer = peerConstructor( atom );
    343348        tr_ptrArrayInsertSorted( &torrent->peers, peer, peerCompare );
    344349    }
     
    929934{
    930935    tordbg( t, "increasing peer %s strike count to %d",
    931             tr_peerIoAddrStr( &peer->addr,
    932                               peer->port ), peer->strikes + 1 );
     936            tr_atomAddrStr( peer->atom ), peer->strikes + 1 );
    933937
    934938    if( ++peer->strikes >= MAX_BAD_PIECES_PER_PEER )
     
    937941        atom->myflags |= MYFLAG_BANNED;
    938942        peer->doPurge = 1;
    939         tordbg( t, "banning peer %s", tr_peerIoAddrStr( &atom->addr, atom->port ) );
     943        tordbg( t, "banning peer %s", tr_atomAddrStr( atom ) );
    940944    }
    941945}
     
    10641068        }
    10651069
     1070        case TR_PEER_CLIENT_GOT_PORT:
     1071            if( peer )
     1072                peer->atom->port = e->port;
     1073            break;
     1074
    10661075        case TR_PEER_CLIENT_GOT_SUGGEST:
    10671076            if( peer )
     
    11091118                struct peer_atom * atom = peer->atom;
    11101119                if( e->progress >= 1.0 ) {
    1111                     tordbg( t, "marking peer %s as a seed", tr_peerIoAddrStr( &atom->addr, atom->port ) );
     1120                    tordbg( t, "marking peer %s as a seed",
     1121                            tr_atomAddrStr( atom ) );
    11121122                    atom->flags |= ADDED_F_SEED_FLAG;
    11131123                }
     
    11761186                peer->doPurge = 1;
    11771187                tordbg( t, "setting %s doPurge flag because we got an ERANGE, EMSGSIZE, or ENOTCONN error",
    1178                         tr_peerIoAddrStr( &peer->addr, peer->port ) );
     1188                        tr_atomAddrStr( peer->atom ) );
    11791189            }
    11801190            else
     
    12091219        a->flags = flags;
    12101220        a->from = from;
    1211         tordbg( t, "got a new atom: %s", tr_peerIoAddrStr( &a->addr, a->port ) );
     1221        tordbg( t, "got a new atom: %s", tr_atomAddrStr( a ) );
    12121222        tr_ptrArrayInsertSorted( &t->pool, a, comparePeerAtoms );
    12131223    }
     
    12861296        {
    12871297            tordbg( t, "banned peer %s tried to reconnect",
    1288                     tr_peerIoAddrStr( &atom->addr, atom->port ) );
     1298                    tr_atomAddrStr( atom ) );
    12891299        }
    12901300        else if( tr_peerIoIsIncoming( io )
     
    13021312            else
    13031313            {
    1304                 peer = getPeer( t, addr );
     1314                peer = getPeer( t, atom );
    13051315                tr_free( peer->client );
    13061316
     
    13131323                }
    13141324
    1315                 peer->port = port;
    1316                 peer->atom = atom;
    13171325                peer->io = tr_handshakeStealIO( handshake ); /* this steals its refcount too, which is
    13181326                                                                balanced by our unref in peerDestructor()  */
     
    14941502            {
    14951503                tordbg( t, "peer %s contributed to corrupt piece (%d); now has %d strikes",
    1496                         tr_peerIoAddrStr( &peer->addr, peer->port ),
     1504                        tr_atomAddrStr( peer->atom ),
    14971505                        pieceIndex, (int)peer->strikes + 1 );
    14981506                addStrike( t, peer );
     
    18921900        tr_peer_stat *           stat = ret + i;
    18931901
    1894         tr_ntop( &peer->addr, stat->addr, sizeof( stat->addr ) );
     1902        tr_ntop( &atom->addr, stat->addr, sizeof( stat->addr ) );
    18951903        tr_strlcpy( stat->client, ( peer->client ? peer->client : "" ),
    18961904                   sizeof( stat->client ) );
    1897         stat->port               = ntohs( peer->port );
     1905        stat->port               = ntohs( peer->atom->port );
    18981906        stat->from               = atom->from;
    18991907        stat->progress           = peer->progress;
     
    21192127    {
    21202128        tordbg( t, "purging peer %s because its doPurge flag is set",
    2121                 tr_peerIoAddrStr( &atom->addr, atom->port ) );
     2129                tr_atomAddrStr( atom ) );
    21222130        return TR_MUST_CLOSE;
    21232131    }
     
    21422150        {
    21432151            tordbg( t, "purging peer %s because we're both seeds",
    2144                     tr_peerIoAddrStr( &atom->addr, atom->port ) );
     2152                    tr_atomAddrStr( atom ) );
    21452153            return TR_MUST_CLOSE;
    21462154        }
     
    21632171        if( idleTime > limit ) {
    21642172            tordbg( t, "purging peer %s because it's been %d secs since we shared anything",
    2165                        tr_peerIoAddrStr( &atom->addr, atom->port ), idleTime );
     2173                       tr_atomAddrStr( atom ), idleTime );
    21662174            return TR_CAN_CLOSE;
    21672175        }
     
    22962304        {
    22972305            tordbg( t, "RECONNECT peer %d (%s) is in its grace period of %d seconds..",
    2298                     i, tr_peerIoAddrStr( &atom->addr, atom->port ), interval );
     2306                    i, tr_atomAddrStr( atom ), interval );
    22992307            continue;
    23002308        }
     
    24072415
    24082416            tordbg( t, "Starting an OUTGOING connection with %s",
    2409                    tr_peerIoAddrStr( &atom->addr, atom->port ) );
     2417                   tr_atomAddrStr( atom ) );
    24102418
    24112419            io = tr_peerIoNewOutgoing( mgr->session, mgr->session->bandwidth, &atom->addr, atom->port, t->tor->info.hash );
     
    24142422            {
    24152423                tordbg( t, "peerIo not created; marking peer %s as unreachable",
    2416                         tr_peerIoAddrStr( &atom->addr, atom->port ) );
     2424                        tr_atomAddrStr( atom ) );
    24172425                atom->myflags |= MYFLAG_UNREACHABLE;
    24182426            }
  • trunk/libtransmission/peer-mgr.h

    r9383 r9434  
    8888
    8989    uint8_t                  encryption_preference;
    90     tr_port                  port;
    9190    tr_port                  dht_port;
    92     tr_address               addr;
    9391    struct tr_peerIo       * io;
    9492    struct peer_atom       * atom;
     
    110108tr_peer;
    111109
     110const tr_address * tr_peerAddress( const tr_peer * );
    112111
    113112int tr_pexCompare( const void * a, const void * b );
  • trunk/libtransmission/peer-msgs.c

    r9383 r9434  
    413413**/
    414414
    415 static const tr_peer_event blankEvent = { 0, 0, 0, 0, 0.0f, 0, 0, 0 };
     415static const tr_peer_event blankEvent = { 0, 0, 0, 0, 0.0f, 0, 0, 0, 0 };
    416416
    417417static void
     
    489489    e.eventType = TR_PEER_CLIENT_GOT_SUGGEST;
    490490    e.pieceIndex = pieceIndex;
     491    publish( msgs, &e );
     492}
     493
     494static void
     495fireClientGotPort( tr_peermsgs * msgs, tr_port port )
     496{
     497    tr_peer_event e = blankEvent;
     498    e.eventType = TR_PEER_CLIENT_GOT_PORT;
     499    e.port = port;
    491500    publish( msgs, &e );
    492501}
     
    10601069    /* get peer's listening port */
    10611070    if( tr_bencDictFindInt( &val, "p", &i ) ) {
    1062         msgs->peer->port = htons( (uint16_t)i );
    1063         dbgmsg( msgs, "msgs->port is now %hu", msgs->peer->port );
     1071        fireClientGotPort( msgs, (tr_port)i );
     1072        dbgmsg( msgs, "peer's port is now %d", (int)i );
    10641073    }
    10651074
     
    14561465            tr_peerIoReadUint16( msgs->peer->io, inbuf, &msgs->peer->dht_port );
    14571466            if( msgs->peer->dht_port > 0 )
    1458                 tr_dhtAddNode( getSession(msgs), &msgs->peer->addr, msgs->peer->dht_port, 0 );
     1467                tr_dhtAddNode( getSession(msgs),
     1468                               tr_peerAddress( msgs->peer ),
     1469                               msgs->peer->dht_port, 0 );
    14591470            break;
    14601471
  • trunk/libtransmission/tr-dht.c

    r9417 r9434  
    5353#ifdef WITHOUT_DHT
    5454
    55   /* These are the stubs for when we're building without DHT support */
     55  /**
     56  *** These are the stubs for when we're building without DHT support
     57  **/
     58
    5659  int tr_dhtInit( tr_session * session UNUSED,
    5760                  tr_address * address UNUSED ) { return TR_DHT_STOPPED; }
     61
    5862  void tr_dhtUninit( tr_session * session UNUSED ) { }
     63
    5964  tr_bool tr_dhtEnabled( const tr_session * session UNUSED ) { return FALSE; }
     65
    6066  tr_port tr_dhtPort ( const tr_session * sesssion UNUSED ) { return 0; }
     67
    6168  int tr_dhtStatus( tr_session * session     UNUSED,
    6269                    int        * setmeCount  UNUSED ) { return TR_DHT_STOPPED; }
    63   int tr_dhtAddNode( tr_session * session    UNUSED,
    64                      tr_address * addr       UNUSED,
    65                      tr_port      port       UNUSED,
    66                      tr_bool      bootstrap  UNUSED ) { return 0; }
     70
     71  int tr_dhtAddNode( tr_session       * session    UNUSED,
     72                     const tr_address * addr       UNUSED,
     73                     tr_port            port       UNUSED,
     74                     tr_bool            bootstrap  UNUSED ) { return 0; }
     75
    6776  int tr_dhtAnnounce( tr_torrent * session UNUSED,
    6877                      tr_bool announce UNUSED ) { return -1; }
     
    320329
    321330int
    322 tr_dhtAddNode(tr_session *ss, tr_address *address, tr_port port,
    323               tr_bool bootstrap)
     331tr_dhtAddNode( tr_session       * ss,
     332               const tr_address * address,
     333               tr_port            port,
     334               tr_bool            bootstrap )
    324335{
    325336    struct sockaddr_in sin;
  • trunk/libtransmission/tr-dht.h

    r9383 r9434  
    3333int tr_dhtStatus( tr_session *, int * setme_nodeCount );
    3434const char *tr_dhtPrintableStatus(int status);
    35 int tr_dhtAddNode( tr_session *, tr_address *, tr_port, tr_bool bootstrap );
     35int tr_dhtAddNode( tr_session *, const tr_address *, tr_port, tr_bool bootstrap );
    3636int tr_dhtAnnounce( tr_torrent *, tr_bool announce );
  • trunk/libtransmission/webseed.c

    r8685 r9434  
    5252***/
    5353
    54 static const tr_peer_event blankEvent = { 0, 0, 0, 0, 0.0f, 0, 0, 0 };
     54static const tr_peer_event blankEvent = { 0, 0, 0, 0, 0.0f, 0, 0, 0, 0 };
    5555
    5656static void
Note: See TracChangeset for help on using the changeset viewer.