Changeset 3248


Ignore:
Timestamp:
Oct 1, 2007, 5:32:34 AM (14 years ago)
Author:
charles
Message:

ensure TR_PEER_FROM_INCOMING peers get peer atoms. this should fix BentMyWookie?'s crash.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr.c

    r3247 r3248  
    865865
    866866static void
     867ensureAtomExists( Torrent * t, const struct in_addr * addr, uint16_t port, uint8_t flags, uint8_t from )
     868{
     869    if( !peerIsKnown( t, addr ) )
     870    {
     871        struct peer_atom * a = tr_new( struct peer_atom, 1 );
     872        a->addr = *addr;
     873        a->port = port;
     874        a->flags = flags;
     875        a->from = from;
     876        a->time = 0;
     877fprintf( stderr, "torrent [%s] getting a new atom: %s\n", t->tor->info.name, tr_peerIoAddrStr(&a->addr,a->port) );
     878        tr_ptrArrayInsertSorted( t->pool, a, comparePeerAtoms );
     879    }
     880}
     881
     882static void
    867883myHandshakeDoneCB( tr_handshake    * handshake,
    868884                   tr_peerIo       * io,
     
    921937    {
    922938        tr_peer * peer = getPeer( t, in_addr );
     939        uint16_t port;
     940        const struct in_addr * addr = tr_peerIoGetAddress( io,  &port );
     941        ensureAtomExists( t, addr, port, 0, TR_PEER_FROM_INCOMING );
    923942        if( peer->msgs != NULL ) { /* we already have this peer */
    924943            tr_peerIoFree( io );
     
    973992}
    974993
    975 static void
    976 maybeAddNewAtom( Torrent * t, const struct in_addr * addr, uint16_t port, uint8_t flags, uint8_t from )
    977 {
    978     if( !peerIsKnown( t, addr ) )
    979     {
    980         struct peer_atom * a = tr_new( struct peer_atom, 1 );
    981         a->addr = *addr;
    982         a->port = port;
    983         a->flags = flags;
    984         a->from = from;
    985         a->time = 0;
    986 fprintf( stderr, "torrent [%s] getting a new atom: %s\n", t->tor->info.name, tr_peerIoAddrStr(&a->addr,a->port) );
    987         tr_ptrArrayInsertSorted( t->pool, a, comparePeerAtoms );
    988     }
    989 }
    990 
    991994void
    992995tr_peerMgrAddPex( tr_peerMgr     * manager,
     
    10031006    t = getExistingTorrent( manager, torrentHash );
    10041007    for( end=pex+pexCount; pex!=end; ++pex )
    1005         maybeAddNewAtom( t, &pex->in_addr, pex->port, pex->flags, from );
     1008        ensureAtomExists( t, &pex->in_addr, pex->port, pex->flags, from );
    10061009    reconnectSoon( t );
    10071010
     
    10291032        memcpy( &addr, walk, 4 ); walk += 4;
    10301033        memcpy( &port, walk, 2 ); walk += 2;
    1031         maybeAddNewAtom( t, &addr, port, 0, from );
     1034        ensureAtomExists( t, &addr, port, 0, from );
    10321035    }
    10331036    reconnectSoon( t );
Note: See TracChangeset for help on using the changeset viewer.