Changeset 2946


Ignore:
Timestamp:
Aug 30, 2007, 4:23:19 AM (15 years ago)
Author:
charles
Message:

this is another code dump that prints a lot of debug messages to the console and then crashes. outbound connections: handshake->ltep->pex->packets is coming along. lots of functionality in trunk not plugged back in yet.

Location:
branches/encryption/libtransmission
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/encryption/libtransmission/handshake.c

    r2944 r2946  
    169169{
    170170    setState( handshake, state );
    171     tr_peerConnectionSetIOMode( handshake->connection, EV_READ );
     171    tr_peerConnectionSetIOMode( handshake->connection, EV_READ, EV_WRITE );
    172172}
    173173
     
    196196    setState( handshake, SENDING_YA );
    197197    tr_peerConnectionWriteBuf( handshake->connection, outbuf );
     198    tr_peerConnectionSetIOMode( handshake->connection, EV_WRITE, EV_READ );
    198199
    199200    /* cleanup */
     
    228229    setState( handshake, SENDING_PLAINTEXT_HANDSHAKE );
    229230    tr_peerConnectionWrite( handshake->connection, buf, HANDSHAKE_SIZE );
     231    tr_peerConnectionSetIOMode( handshake->connection, EV_WRITE, EV_READ );
    230232}
    231233
     
    250252    char * buf;
    251253    int len;
    252     int i;
    253254    const char * v = TR_NAME " " USERAGENT_PREFIX;
    254255    const int port = tr_getPublicPort( handshake->handle );
    255256    struct evbuffer * outbuf = evbuffer_new( );
    256257    uint32_t msglen;
    257     uint32_t msgextid;
    258     uint8_t msgid;
    259 
    260    
    261 void tr_peerConnectionWriteUint32 ( tr_peerConnection   * conn,
    262                                     struct evbuffer     * outbuf,
    263                                     uint32_t              writeme );
    264 void tr_peerConnectionWriteBytes   ( tr_peerConnection  * conn,
    265                                      struct evbuffer    * outbuf,
    266                                      const void         * bytes,
    267                                      int                  byteCount );
    268 
    269 void tr_peerConnectionWriteUint16 ( tr_peerConnection   * conn,
    270                                     struct evbuffer     * outbuf,
    271                                     uint16_t              writeme );
    272 
     258    const uint8_t tr_msgid = 20; /* ltep extension id */
     259    const uint8_t ltep_msgid = 0; /* handshake id */
    273260
    274261    tr_bencInit( &val, TYPE_DICT );
     
    284271    fprintf( stderr, "sending ltep handshake...\n" );
    285272    buf = tr_bencSaveMalloc( &val,  &len );
    286 for( i=0; i<len; ++i) fprintf( stderr, "%c", buf[i] );
    287 fprintf( stderr, "\n" );
    288 
    289     msglen = 1 + sizeof(uint32_t) + len;
    290     msgid = 20; /* LTEP extension command number */
    291     msgextid = 0; /* LTEP handshake number */
     273    tr_bencPrint( &val );
     274
     275    msglen = sizeof(tr_msgid) + sizeof(ltep_msgid) + len;
    292276    tr_peerConnectionWriteUint32( handshake->connection, outbuf, msglen );
    293     tr_peerConnectionWriteBytes( handshake->connection, outbuf, &msgid, 1 );
    294     tr_peerConnectionWriteUint32( handshake->connection, outbuf, msgextid );
    295     tr_peerConnectionWriteBytes( handshake->connection, outbuf, buf, len );
     277    tr_peerConnectionWriteBytes ( handshake->connection, outbuf, &tr_msgid, 1 );
     278    tr_peerConnectionWriteBytes ( handshake->connection, outbuf, &ltep_msgid, 1 );
     279    tr_peerConnectionWriteBytes ( handshake->connection, outbuf, buf, len );
    296280   
    297281    handshake->state = SENDING_LTEP_HANDHAKE;
    298282    tr_peerConnectionWriteBuf( handshake->connection, outbuf );
     283    tr_peerConnectionSetIOMode( handshake->connection, EV_WRITE, EV_READ );
    299284 
    300285    /* cleanup */
     
    335320    setState( handshake, SENDING_YB );
    336321    tr_peerConnectionWrite( handshake->connection, outbuf, walk-outbuf );
     322    tr_peerConnectionSetIOMode( handshake->connection, EV_WRITE, EV_READ );
    337323
    338324    return READ_DONE;
     
    561547    setState( handshake, SENDING_CRYPTO_PROVIDE );
    562548    tr_peerConnectionWriteBuf( handshake->connection, outbuf );
     549    tr_peerConnectionSetIOMode( handshake->connection, EV_WRITE, EV_READ );
    563550
    564551    /* cleanup */
     
    573560    const int key_len = VC_LENGTH;
    574561    uint8_t tmp[VC_LENGTH];
    575 
    576 static int drained = 0;
    577562
    578563    /* note: this works w/o having to `unwind' the buffer if
     
    593578
    594579        evbuffer_drain( inbuf, 1 );
    595         fprintf( stderr, "drained %d\n", ++drained );
    596580    }
    597581
  • branches/encryption/libtransmission/peer-connection.c

    r2944 r2946  
    7575        const int ret = (*c->canRead)( e, c->userData );
    7676        switch( ret ) {
     77            case READ_AGAIN: if( EVBUFFER_LENGTH( e->input ) ) continue; /* note fall-through */
     78            case READ_MORE: fprintf( stderr, "waiting for bytes from peer...\n" );
     79                            tr_peerConnectionSetIOMode( c, EV_READ, 0 ); return; break;
    7780            case READ_DONE: return; fprintf( stderr, "READ_DONE\n"); break;
    78             case READ_AGAIN: fprintf( stderr, "READ_AGAIN: going again w/o reading more data\n"); continue; break;
    79             case READ_MORE: fprintf( stderr, "READ_MORE: waiting for more...\n" ); tr_peerConnectionSetIOMode( c, EV_READ ); return; break;
    8081        }
    8182    }
     
    181182
    182183void
    183 tr_peerConnectionSetIOMode( tr_peerConnection * c, short mode )
    184 {
    185     tr_setBufferEventMode( c->handle, c->bufev, mode );
     184tr_peerConnectionSetIOMode( tr_peerConnection * c, short enable, short disable )
     185{
     186    tr_setBufferEventMode( c->handle, c->bufev, enable, disable );
    186187}
    187188
     
    192193        canReadWrapper( c->bufev, c );
    193194    else
    194         tr_peerConnectionSetIOMode( c, EV_READ );
     195        tr_peerConnectionSetIOMode( c, EV_READ, EV_WRITE );
    195196}
    196197
     
    338339    {
    339340        case PEER_ENCRYPTION_PLAINTEXT:
     341            fprintf( stderr, "writing %d plaintext bytes to outbuf...\n", byteCount );
    340342            evbuffer_add( outbuf, bytes, byteCount );
    341343            break;
    342344
    343345        case PEER_ENCRYPTION_RC4:
     346            fprintf( stderr, "encrypting and writing %d bytes to outbuf...\n", byteCount );
    344347            tmp = tr_new( uint8_t, byteCount );
    345348            tr_cryptoEncrypt( conn->crypto, byteCount, bytes, tmp );
     
    382385    {
    383386        case PEER_ENCRYPTION_PLAINTEXT:
    384             fprintf( stderr, "reading %d plaintext bytes from peer...\n", byteCount );
     387            fprintf( stderr, "reading %d plaintext bytes from inbuf...\n", byteCount );
    385388            evbuffer_remove(  inbuf, bytes, byteCount );
    386389            break;
    387390
    388391        case PEER_ENCRYPTION_RC4:
    389             fprintf( stderr, "reading and decrypting %d bytes from peer...\n", byteCount );
     392            fprintf( stderr, "reading and decrypting %d bytes from inbuf...\n", byteCount );
    390393            evbuffer_remove(  inbuf, bytes, byteCount );
    391394            tr_cryptoDecrypt( conn->crypto, byteCount, bytes, bytes );
  • branches/encryption/libtransmission/peer-connection.h

    r2944 r2946  
    9797
    9898void  tr_peerConnectionSetIOMode ( tr_peerConnection   * connection,
    99                                    short                 mode );
     99                                   short                 enable_mode,
     100                                   short                 disable_mode );
    100101
    101102void  tr_peerConnectionReadOrWait( tr_peerConnection * connection );
  • branches/encryption/libtransmission/trevent.c

    r2939 r2946  
    9494        case 'd': /* event_del */
    9595            read( fd, &event, sizeof(struct event*) );
    96             tr_dbg( "read del event from pipe: event is %p", event );
    9796            event_del( event );
    9897            tr_free( event );
     
    102101            read( fd, &event, sizeof(struct event*) );
    103102            read( fd, &interval, sizeof(struct timeval) );
    104             tr_dbg( "read event from pipe: event.ev_arg is %p", event->ev_arg );
    105103            event_add( event, &interval );
    106104            break;
     
    111109            read( fd, &type, sizeof(enum evhttp_cmd_type) );
    112110            read( fd, &uri, sizeof(char*) );
    113             tr_dbg( "read http req from pipe: req.cb_arg is %p", req->cb_arg );
    114111            evhttp_make_request( evcon, req, type, uri );
    115112            tr_free( uri );
     
    118115        case 'm': /* set bufferevent mode */
    119116            read( fd, &bufev, sizeof(struct evhttp_request*) );
     117            mode = 0;
    120118            read( fd, &mode, sizeof(short) );
    121119            bufferevent_enable( bufev, mode );
    122             bufferevent_disable( bufev, mode==EV_READ ? EV_WRITE : EV_READ );
     120            mode = 0;
     121            read( fd, &mode, sizeof(short) );
     122            bufferevent_disable( bufev, mode );
    123123            break;
    124124
     
    127127            read( fd, &buf, sizeof(char*) );
    128128            read( fd, &buflen, sizeof(size_t) );
    129             bufferevent_enable( bufev, EV_WRITE );
    130             bufferevent_disable( bufev, EV_READ );
    131129            bufferevent_write( bufev, buf, buflen );
    132130            tr_free( buf );
     
    284282tr_setBufferEventMode( struct tr_handle   * handle,
    285283                       struct bufferevent * bufev,
    286                        short                mode )
     284                       short                mode_enable,
     285                       short                mode_disable )
    287286{
    288287    const char ch = 'm';
     
    293292    write( fd, &ch, 1 );
    294293    write( fd, &bufev, sizeof(struct bufferevent*) );
    295     write( fd, &mode, sizeof(short) );
    296     tr_lockUnlock( lock );
    297 }
    298 
     294    write( fd, &mode_enable, sizeof(short) );
     295    write( fd, &mode_disable, sizeof(short) );
     296    tr_lockUnlock( lock );
     297}
  • branches/encryption/libtransmission/trevent.h

    r2936 r2946  
    5151void tr_setBufferEventMode( struct tr_handle   * tr_handle,
    5252                            struct bufferevent * bufferEvent,
    53                             short                mode );
     53                            short                mode_enable,
     54                            short                mode_disable );
    5455
    5556#endif
Note: See TracChangeset for help on using the changeset viewer.