Changeset 2946
- Timestamp:
- Aug 30, 2007, 4:23:19 AM (15 years ago)
- Location:
- branches/encryption/libtransmission
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/encryption/libtransmission/handshake.c
r2944 r2946 169 169 { 170 170 setState( handshake, state ); 171 tr_peerConnectionSetIOMode( handshake->connection, EV_READ );171 tr_peerConnectionSetIOMode( handshake->connection, EV_READ, EV_WRITE ); 172 172 } 173 173 … … 196 196 setState( handshake, SENDING_YA ); 197 197 tr_peerConnectionWriteBuf( handshake->connection, outbuf ); 198 tr_peerConnectionSetIOMode( handshake->connection, EV_WRITE, EV_READ ); 198 199 199 200 /* cleanup */ … … 228 229 setState( handshake, SENDING_PLAINTEXT_HANDSHAKE ); 229 230 tr_peerConnectionWrite( handshake->connection, buf, HANDSHAKE_SIZE ); 231 tr_peerConnectionSetIOMode( handshake->connection, EV_WRITE, EV_READ ); 230 232 } 231 233 … … 250 252 char * buf; 251 253 int len; 252 int i;253 254 const char * v = TR_NAME " " USERAGENT_PREFIX; 254 255 const int port = tr_getPublicPort( handshake->handle ); 255 256 struct evbuffer * outbuf = evbuffer_new( ); 256 257 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 */ 273 260 274 261 tr_bencInit( &val, TYPE_DICT ); … … 284 271 fprintf( stderr, "sending ltep handshake...\n" ); 285 272 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; 292 276 tr_peerConnectionWriteUint32( handshake->connection, outbuf, msglen ); 293 tr_peerConnectionWriteBytes ( handshake->connection, outbuf, &msgid, 1 );294 tr_peerConnectionWrite Uint32( 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, <ep_msgid, 1 ); 279 tr_peerConnectionWriteBytes ( handshake->connection, outbuf, buf, len ); 296 280 297 281 handshake->state = SENDING_LTEP_HANDHAKE; 298 282 tr_peerConnectionWriteBuf( handshake->connection, outbuf ); 283 tr_peerConnectionSetIOMode( handshake->connection, EV_WRITE, EV_READ ); 299 284 300 285 /* cleanup */ … … 335 320 setState( handshake, SENDING_YB ); 336 321 tr_peerConnectionWrite( handshake->connection, outbuf, walk-outbuf ); 322 tr_peerConnectionSetIOMode( handshake->connection, EV_WRITE, EV_READ ); 337 323 338 324 return READ_DONE; … … 561 547 setState( handshake, SENDING_CRYPTO_PROVIDE ); 562 548 tr_peerConnectionWriteBuf( handshake->connection, outbuf ); 549 tr_peerConnectionSetIOMode( handshake->connection, EV_WRITE, EV_READ ); 563 550 564 551 /* cleanup */ … … 573 560 const int key_len = VC_LENGTH; 574 561 uint8_t tmp[VC_LENGTH]; 575 576 static int drained = 0;577 562 578 563 /* note: this works w/o having to `unwind' the buffer if … … 593 578 594 579 evbuffer_drain( inbuf, 1 ); 595 fprintf( stderr, "drained %d\n", ++drained );596 580 } 597 581 -
branches/encryption/libtransmission/peer-connection.c
r2944 r2946 75 75 const int ret = (*c->canRead)( e, c->userData ); 76 76 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; 77 80 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;80 81 } 81 82 } … … 181 182 182 183 void 183 tr_peerConnectionSetIOMode( tr_peerConnection * c, short mode )184 { 185 tr_setBufferEventMode( c->handle, c->bufev, mode );184 tr_peerConnectionSetIOMode( tr_peerConnection * c, short enable, short disable ) 185 { 186 tr_setBufferEventMode( c->handle, c->bufev, enable, disable ); 186 187 } 187 188 … … 192 193 canReadWrapper( c->bufev, c ); 193 194 else 194 tr_peerConnectionSetIOMode( c, EV_READ );195 tr_peerConnectionSetIOMode( c, EV_READ, EV_WRITE ); 195 196 } 196 197 … … 338 339 { 339 340 case PEER_ENCRYPTION_PLAINTEXT: 341 fprintf( stderr, "writing %d plaintext bytes to outbuf...\n", byteCount ); 340 342 evbuffer_add( outbuf, bytes, byteCount ); 341 343 break; 342 344 343 345 case PEER_ENCRYPTION_RC4: 346 fprintf( stderr, "encrypting and writing %d bytes to outbuf...\n", byteCount ); 344 347 tmp = tr_new( uint8_t, byteCount ); 345 348 tr_cryptoEncrypt( conn->crypto, byteCount, bytes, tmp ); … … 382 385 { 383 386 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 ); 385 388 evbuffer_remove( inbuf, bytes, byteCount ); 386 389 break; 387 390 388 391 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 ); 390 393 evbuffer_remove( inbuf, bytes, byteCount ); 391 394 tr_cryptoDecrypt( conn->crypto, byteCount, bytes, bytes ); -
branches/encryption/libtransmission/peer-connection.h
r2944 r2946 97 97 98 98 void tr_peerConnectionSetIOMode ( tr_peerConnection * connection, 99 short mode ); 99 short enable_mode, 100 short disable_mode ); 100 101 101 102 void tr_peerConnectionReadOrWait( tr_peerConnection * connection ); -
branches/encryption/libtransmission/trevent.c
r2939 r2946 94 94 case 'd': /* event_del */ 95 95 read( fd, &event, sizeof(struct event*) ); 96 tr_dbg( "read del event from pipe: event is %p", event );97 96 event_del( event ); 98 97 tr_free( event ); … … 102 101 read( fd, &event, sizeof(struct event*) ); 103 102 read( fd, &interval, sizeof(struct timeval) ); 104 tr_dbg( "read event from pipe: event.ev_arg is %p", event->ev_arg );105 103 event_add( event, &interval ); 106 104 break; … … 111 109 read( fd, &type, sizeof(enum evhttp_cmd_type) ); 112 110 read( fd, &uri, sizeof(char*) ); 113 tr_dbg( "read http req from pipe: req.cb_arg is %p", req->cb_arg );114 111 evhttp_make_request( evcon, req, type, uri ); 115 112 tr_free( uri ); … … 118 115 case 'm': /* set bufferevent mode */ 119 116 read( fd, &bufev, sizeof(struct evhttp_request*) ); 117 mode = 0; 120 118 read( fd, &mode, sizeof(short) ); 121 119 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 ); 123 123 break; 124 124 … … 127 127 read( fd, &buf, sizeof(char*) ); 128 128 read( fd, &buflen, sizeof(size_t) ); 129 bufferevent_enable( bufev, EV_WRITE );130 bufferevent_disable( bufev, EV_READ );131 129 bufferevent_write( bufev, buf, buflen ); 132 130 tr_free( buf ); … … 284 282 tr_setBufferEventMode( struct tr_handle * handle, 285 283 struct bufferevent * bufev, 286 short mode ) 284 short mode_enable, 285 short mode_disable ) 287 286 { 288 287 const char ch = 'm'; … … 293 292 write( fd, &ch, 1 ); 294 293 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 51 51 void tr_setBufferEventMode( struct tr_handle * tr_handle, 52 52 struct bufferevent * bufferEvent, 53 short mode ); 53 short mode_enable, 54 short mode_disable ); 54 55 55 56 #endif
Note: See TracChangeset
for help on using the changeset viewer.