Changeset 3780
- Timestamp:
- Nov 10, 2007, 2:59:14 PM (15 years ago)
- Location:
- branches/0.9x
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/0.9x/README
r3531 r3780 19 19 Building a Transmission release from the command line: 20 20 21 $ tar xvf z transmission-0.90.tar.gz22 $ cd transmission-0.9 021 $ tar xvfj transmission-0.93.tar.bz2 22 $ cd transmission-0.92 23 23 $ ./configure -q && make -s 24 24 $ su (if necessary for the next line) -
branches/0.9x/libtransmission/inout.c
r3673 r3780 202 202 203 203 int 204 tr_ioWrite( tr_torrent * tor,205 int pieceIndex,206 int begin,207 int len,208 uint8_t* buf )209 { 210 return readOrWritePiece( tor, TR_IO_WRITE, pieceIndex, begin, buf, len );204 tr_ioWrite( tr_torrent * tor, 205 int pieceIndex, 206 int begin, 207 int len, 208 const uint8_t * buf ) 209 { 210 return readOrWritePiece( tor, TR_IO_WRITE, pieceIndex, begin, (void*)buf, len ); 211 211 } 212 212 -
branches/0.9x/libtransmission/inout.h
r3649 r3780 39 39 **********************************************************************/ 40 40 int tr_ioRead ( struct tr_torrent*, int index, int begin, int len, uint8_t * ); 41 int tr_ioWrite ( struct tr_torrent *, int index, int begin, int len, uint8_t * );41 int tr_ioWrite ( struct tr_torrent *, int index, int begin, int len, const uint8_t * ); 42 42 43 43 /* hashes the specified piece and updates the completion accordingly. */ -
branches/0.9x/libtransmission/peer-mgr.c
r3662 r3780 73 73 /* set this too high and there will be a lot of churn. 74 74 * set it too low and you'll get peers too slowly */ 75 MAX_RECONNECTIONS_PER_PULSE = 10,75 MAX_RECONNECTIONS_PER_PULSE = 5, 76 76 77 77 /* corresponds to ut_pex's added.f flags */ … … 937 937 tr_peerIoFree( io ); 938 938 } 939 else if( tr_ptrArraySize( t->peers ) >= MAX_CONNECTED_PEERS_PER_TORRENT ) 940 { 941 tr_peerIoFree( io ); 942 } 939 943 else 940 944 { … … 1695 1699 1696 1700 /* add some new ones */ 1697 nAdd = MAX_CONNECTED_PEERS_PER_TORRENT - peerCount; 1701 nAdd = !peerCount ? MAX_CONNECTED_PEERS_PER_TORRENT 1702 : MAX_RECONNECTIONS_PER_PULSE; 1698 1703 for( i=0; i<nAdd && i<nCandidates && i<MAX_RECONNECTIONS_PER_PULSE; ++i ) 1699 1704 { -
branches/0.9x/libtransmission/peer-msgs.c
r3705 r3780 21 21 #include <netinet/in.h> /* struct in_addr */ 22 22 23 #include <sys/types.h> /* event.h needs this */24 23 #include <event.h> 25 24 … … 40 39 *** 41 40 **/ 42 43 #define MAX_ALLOWED_SET_COUNT 10 /* number of pieces generated for allow-fast,44 threshold for fast-allowing others */45 41 46 42 enum … … 69 65 MAX_REQUEST_BYTE_COUNT = (16 * 1024), /* drop requests who want too much */ 70 66 71 KEEPALIVE_INTERVAL_SECS = 90, /* idle seconds before we send a keepalive */ 67 /* idle seconds before we send a keepalive */ 68 KEEPALIVE_INTERVAL_SECS = 90, 69 72 70 PEX_INTERVAL = (60 * 1000), /* msec between calls to sendPex() */ 73 71 PEER_PULSE_INTERVAL = (100), /* msec between calls to pulse() */ 74 72 RATE_PULSE_INTERVAL = (333), /* msec between calls to ratePulse() */ 73 74 /* number of pieces generated for allow-fast, 75 threshold for fast-allowing others */ 76 MAX_ALLOWED_SET_COUNT = 10 75 77 }; 76 78 … … 78 80 { 79 81 AWAITING_BT_LENGTH, 80 AWAITING_BT_MESSAGE, 81 READING_BT_PIECE 82 AWAITING_BT_MESSAGE 82 83 }; 83 84 … … 93 94 compareRequest( const void * va, const void * vb ) 94 95 { 95 struct peer_request * a = (struct peer_request*) va; 96 struct peer_request * b = (struct peer_request*) vb; 97 if( a->index != b->index ) return a->index - b->index; 98 if( a->offset != b->offset ) return a->offset - b->offset; 99 if( a->length != b->length ) return a->length - b->length; 96 int i; 97 const struct peer_request * a = va; 98 const struct peer_request * b = vb; 99 if(( i = tr_compareUint32( a->index, b->index ))) return i; 100 if(( i = tr_compareUint32( a->offset, b->offset ))) return i; 101 if(( i = tr_compareUint32( a->length, b->length ))) return i; 100 102 return 0; 101 103 } … … 113 115 struct evbuffer * outBlock; /* buffer of all the current piece message */ 114 116 struct evbuffer * outMessages; /* buffer of all the non-piece messages */ 115 struct evbuffer * inBlock; /* the block we're currently receiving */116 117 tr_list * peerAskedFor; 117 118 tr_list * peerAskedForFast; … … 122 123 tr_timer * pulseTimer; 123 124 tr_timer * pexTimer; 124 125 struct peer_request blockToUs; /* the block currntly being sent to us */126 125 127 126 time_t lastReqAddedAt; … … 284 283 285 284 static void 286 fireGotBlock( tr_peermsgs * msgs, uint32_t pieceIndex, uint32_t offset, uint32_t length)285 fireGotBlock( tr_peermsgs * msgs, const struct peer_request * req ) 287 286 { 288 287 tr_peermsgs_event e = blankEvent; 289 288 e.eventType = TR_PEERMSG_CLIENT_BLOCK; 290 e.pieceIndex = pieceIndex;291 e.offset = offset;292 e.length = length;289 e.pieceIndex = req->index; 290 e.offset = req->offset; 291 e.length = req->length; 293 292 publish( msgs, &e ); 294 293 } … … 434 433 #endif 435 434 static void 436 sendFastHave( tr_peermsgs * msgs, 437 int all) 438 { 439 dbgmsg( msgs, "w00t telling them we %s pieces", (all ? "HAVE_ALL" : "HAVE_NONE" ) ); 435 sendFastHave( tr_peermsgs * msgs, int all ) 436 { 437 dbgmsg( msgs, "w00t telling them we have %s pieces", (all ? "ALL" : "NONE" ) ); 440 438 tr_peerIoWriteUint32( msgs->io, msgs->outMessages, sizeof(uint8_t) ); 441 tr_peerIoWriteUint8( msgs->io, msgs->outMessages, ( all ? BT_HAVE_ALL : BT_HAVE_NONE ) );442 439 tr_peerIoWriteUint8( msgs->io, msgs->outMessages, ( all ? BT_HAVE_ALL 440 : BT_HAVE_NONE ) ); 443 441 updateInterest( msgs ); 444 442 } … … 493 491 494 492 static int 495 reqIsValid( const tr_peermsgs * msgs, uint32_t index, uint32_t offset, uint32_t length ) 493 reqIsValid( const tr_peermsgs * msgs, 494 uint32_t index, 495 uint32_t offset, 496 uint32_t length ) 496 497 { 497 498 const tr_torrent * tor = msgs->torrent; … … 530 531 while( ( count < max ) && ( msgs->clientWillAskFor != NULL ) ) 531 532 { 532 struct peer_request * r eq= tr_list_pop_front( &msgs->clientWillAskFor );533 protocolSendRequest( msgs, r eq);534 r eq->time_requested = msgs->lastReqAddedAt = time( NULL );535 tr_list_append( &msgs->clientAskedFor, r eq);533 struct peer_request * r = tr_list_pop_front( &msgs->clientWillAskFor ); 534 protocolSendRequest( msgs, r ); 535 r->time_requested = msgs->lastReqAddedAt = time( NULL ); 536 tr_list_append( &msgs->clientAskedFor, r ); 536 537 ++count; 537 538 ++sent; … … 698 699 tr_bencInitInt( tr_bencDictAdd( &val, "p" ), port ); 699 700 tr_bencInitStr( tr_bencDictAdd( &val, "v" ), v, 0, 1 ); 700 buf = tr_bencSaveMalloc( &val, 701 buf = tr_bencSaveMalloc( &val, &len ); 701 702 702 703 tr_peerIoWriteUint32( msgs->io, outbuf, 2*sizeof(uint8_t) + len ); … … 891 892 sendFastReject( msgs, req->index, req->offset, req->length ); 892 893 } 893 else if( peerIsChoked && !peerIsFast ) /* maybe he doesn'tknow he's choked? */894 else if( peerIsChoked && !peerIsFast ) /* doesn't he know he's choked? */ 894 895 { 895 896 tr_peerMsgsSetChoke( msgs, 1 ); … … 951 952 } 952 953 954 static void 955 clientGotBlock( tr_peermsgs * msgs, const uint8_t * block, const struct peer_request * req ); 953 956 954 957 static int … … 958 961 uint32_t ui32; 959 962 uint32_t msglen = msgs->incomingMessageLength; 963 const size_t startBufLen = EVBUFFER_LENGTH( inbuf ); 960 964 961 965 if( EVBUFFER_LENGTH(inbuf) < msglen ) … … 963 967 964 968 tr_peerIoReadUint8( msgs->io, inbuf, &id ); 965 dbgmsg( msgs, "got BT id %d, len %d ", (int)id, (int)msglen);969 dbgmsg( msgs, "got BT id %d, len %d, buffer size is %d", (int)id, (int)msglen, (int)EVBUFFER_LENGTH(inbuf) ); 966 970 967 971 if( !messageLengthIsCorrect( msgs, id, msglen ) ) 968 972 { 973 dbgmsg( msgs, "bad packet - BT message #%d with a length of %d", (int)id, (int)msglen ); 969 974 fireGotError( msgs ); 970 975 return READ_DONE; … … 975 980 switch( id ) 976 981 { 977 case BT_CHOKE: 978 dbgmsg( msgs, "got Choke" ); 979 msgs->info->clientIsChoked = 1; 980 cancelAllRequestsToPeer( msgs ); 981 cancelAllRequestsToClientExceptFast( msgs ); 982 break; 983 984 case BT_UNCHOKE: 985 dbgmsg( msgs, "got Unchoke" ); 986 msgs->info->clientIsChoked = 0; 987 fireNeedReq( msgs ); 988 break; 989 990 case BT_INTERESTED: 991 dbgmsg( msgs, "got Interested" ); 992 msgs->info->peerIsInterested = 1; 993 tr_peerMsgsSetChoke( msgs, 0 ); 994 break; 995 996 case BT_NOT_INTERESTED: 997 dbgmsg( msgs, "got Not Interested" ); 998 msgs->info->peerIsInterested = 0; 999 break; 1000 1001 case BT_HAVE: 1002 tr_peerIoReadUint32( msgs->io, inbuf, &ui32 ); 1003 dbgmsg( msgs, "got Have: %u", ui32 ); 1004 tr_bitfieldAdd( msgs->info->have, ui32 ); 1005 updatePeerProgress( msgs ); 1006 tr_rcTransferred( msgs->torrent->swarmspeed, msgs->torrent->info.pieceSize ); 1007 break; 1008 1009 case BT_BITFIELD: { 1010 const int clientIsSeed = tr_torrentIsSeed( msgs->torrent ); 1011 dbgmsg( msgs, "got a bitfield" ); 1012 tr_peerIoReadBytes( msgs->io, inbuf, msgs->info->have->bits, msglen ); 1013 updatePeerProgress( msgs ); 1014 tr_peerMsgsSetChoke( msgs, !clientIsSeed || (msgs->info->progress<1.0) ); 1015 fireNeedReq( msgs ); 1016 break; 1017 } 1018 1019 case BT_REQUEST: { 1020 struct peer_request req; 1021 tr_peerIoReadUint32( msgs->io, inbuf, &req.index ); 1022 tr_peerIoReadUint32( msgs->io, inbuf, &req.offset ); 1023 tr_peerIoReadUint32( msgs->io, inbuf, &req.length ); 1024 dbgmsg( msgs, "got Request: %u:%u->%u", req.index, req.offset, req.length ); 1025 peerMadeRequest( msgs, &req ); 1026 break; 1027 } 1028 1029 case BT_CANCEL: { 1030 struct peer_request req; 1031 tr_peerIoReadUint32( msgs->io, inbuf, &req.index ); 1032 tr_peerIoReadUint32( msgs->io, inbuf, &req.offset ); 1033 tr_peerIoReadUint32( msgs->io, inbuf, &req.length ); 1034 dbgmsg( msgs, "got a Cancel %u:%u->%u", req.index, req.offset, req.length ); 1035 tr_free( tr_list_remove( &msgs->peerAskedForFast, &req, compareRequest ) ); 1036 tr_free( tr_list_remove( &msgs->peerAskedFor, &req, compareRequest ) ); 1037 break; 1038 } 1039 1040 case BT_PIECE: { 1041 dbgmsg( msgs, "got a Piece!" ); 1042 assert( msgs->blockToUs.length == 0 ); 1043 tr_peerIoReadUint32( msgs->io, inbuf, &msgs->blockToUs.index ); 1044 tr_peerIoReadUint32( msgs->io, inbuf, &msgs->blockToUs.offset ); 1045 msgs->blockToUs.length = msglen - 8; 1046 assert( EVBUFFER_LENGTH(msgs->inBlock) == 0 ); 1047 msgs->state = msgs->blockToUs.length ? READING_BT_PIECE : AWAITING_BT_LENGTH; 1048 return READ_AGAIN; 1049 break; 1050 } 1051 1052 case BT_PORT: { 1053 dbgmsg( msgs, "Got a BT_PORT" ); 1054 tr_peerIoReadUint16( msgs->io, inbuf, &msgs->info->port ); 1055 break; 1056 } 1057 1058 case BT_SUGGEST: { 1059 /* FIXME(tiennou) */ 1060 uint32_t index; 1061 tr_peerIoReadUint32( msgs->io, inbuf, &index ); 1062 break; 1063 } 1064 1065 case BT_HAVE_ALL: 1066 dbgmsg( msgs, "Got a BT_HAVE_ALL" ); 982 case BT_CHOKE: 983 dbgmsg( msgs, "got Choke" ); 984 msgs->info->clientIsChoked = 1; 985 cancelAllRequestsToPeer( msgs ); 986 cancelAllRequestsToClientExceptFast( msgs ); 987 break; 988 989 case BT_UNCHOKE: 990 dbgmsg( msgs, "got Unchoke" ); 991 msgs->info->clientIsChoked = 0; 992 fireNeedReq( msgs ); 993 break; 994 995 case BT_INTERESTED: 996 dbgmsg( msgs, "got Interested" ); 997 msgs->info->peerIsInterested = 1; 998 tr_peerMsgsSetChoke( msgs, 0 ); 999 break; 1000 1001 case BT_NOT_INTERESTED: 1002 dbgmsg( msgs, "got Not Interested" ); 1003 msgs->info->peerIsInterested = 0; 1004 break; 1005 1006 case BT_HAVE: 1007 tr_peerIoReadUint32( msgs->io, inbuf, &ui32 ); 1008 dbgmsg( msgs, "got Have: %u", ui32 ); 1009 tr_bitfieldAdd( msgs->info->have, ui32 ); 1010 updatePeerProgress( msgs ); 1011 tr_rcTransferred( msgs->torrent->swarmspeed, msgs->torrent->info.pieceSize ); 1012 break; 1013 1014 case BT_BITFIELD: { 1015 const int clientIsSeed = tr_torrentIsSeed( msgs->torrent ); 1016 dbgmsg( msgs, "got a bitfield" ); 1017 tr_peerIoReadBytes( msgs->io, inbuf, msgs->info->have->bits, msglen ); 1018 updatePeerProgress( msgs ); 1019 tr_peerMsgsSetChoke( msgs, !clientIsSeed || (msgs->info->progress<1.0) ); 1020 fireNeedReq( msgs ); 1021 break; 1022 } 1023 1024 case BT_REQUEST: { 1025 struct peer_request req; 1026 tr_peerIoReadUint32( msgs->io, inbuf, &req.index ); 1027 tr_peerIoReadUint32( msgs->io, inbuf, &req.offset ); 1028 tr_peerIoReadUint32( msgs->io, inbuf, &req.length ); 1029 dbgmsg( msgs, "got Request: %u:%u->%u", req.index, req.offset, req.length ); 1030 peerMadeRequest( msgs, &req ); 1031 break; 1032 } 1033 1034 case BT_CANCEL: { 1035 struct peer_request req; 1036 tr_peerIoReadUint32( msgs->io, inbuf, &req.index ); 1037 tr_peerIoReadUint32( msgs->io, inbuf, &req.offset ); 1038 tr_peerIoReadUint32( msgs->io, inbuf, &req.length ); 1039 dbgmsg( msgs, "got a Cancel %u:%u->%u", req.index, req.offset, req.length ); 1040 tr_free( tr_list_remove( &msgs->peerAskedForFast, &req, compareRequest ) ); 1041 tr_free( tr_list_remove( &msgs->peerAskedFor, &req, compareRequest ) ); 1042 break; 1043 } 1044 1045 case BT_PIECE: { 1046 uint8_t * block; 1047 struct peer_request req; 1048 tr_peerIoReadUint32( msgs->io, inbuf, &req.index ); 1049 tr_peerIoReadUint32( msgs->io, inbuf, &req.offset ); 1050 req.length = msglen - 8; 1051 block = tr_new( uint8_t, req.length ); 1052 tr_peerIoReadBytes( msgs->io, inbuf, block, req.length ); 1053 dbgmsg( msgs, "got a Block %u:%u->%u", req.index, req.offset, req.length ); 1054 clientGotBlock( msgs, block, &req ); 1055 tr_free( block ); 1056 break; 1057 } 1058 1059 case BT_PORT: 1060 dbgmsg( msgs, "Got a BT_PORT" ); 1061 tr_peerIoReadUint16( msgs->io, inbuf, &msgs->info->port ); 1062 break; 1063 1064 #if 0 1065 case BT_SUGGEST: { 1066 /* FIXME(tiennou) */ 1067 uint32_t index; 1068 tr_peerIoReadUint32( msgs->io, inbuf, &index ); 1069 break; 1070 } 1071 1072 case BT_HAVE_ALL: 1073 dbgmsg( msgs, "Got a BT_HAVE_ALL" ); 1067 1074 tr_bitfieldAddRange( msgs->info->have, 0, msgs->torrent->info.pieceCount ); 1068 updatePeerProgress( msgs ); 1069 break; 1070 1071 case BT_HAVE_NONE: 1072 dbgmsg( msgs, "Got a BT_HAVE_NONE" ); 1073 tr_bitfieldClear( msgs->info->have ); 1074 updatePeerProgress( msgs ); 1075 break; 1076 1077 case BT_REJECT: { 1078 struct peer_request req; 1079 dbgmsg( msgs, "Got a BT_REJECT" ); 1080 tr_peerIoReadUint32( msgs->io, inbuf, &req.index ); 1081 tr_peerIoReadUint32( msgs->io, inbuf, &req.offset ); 1082 tr_peerIoReadUint32( msgs->io, inbuf, &req.length ); 1083 tr_free( tr_list_remove( &msgs->clientAskedFor, &req, compareRequest ) ); 1084 break; 1085 } 1086 1087 case BT_ALLOWED_FAST: { 1088 dbgmsg( msgs, "Got a BT_ALLOWED_FAST" ); 1089 tr_peerIoReadUint32( msgs->io, inbuf, &ui32 ); 1090 tr_bitfieldAdd( msgs->clientAllowedPieces, ui32 ); 1091 break; 1092 } 1093 1094 case BT_LTEP: 1095 dbgmsg( msgs, "Got a BT_LTEP" ); 1096 parseLtep( msgs, msglen, inbuf ); 1097 break; 1098 1099 default: 1100 dbgmsg( msgs, "peer sent us an UNKNOWN: %d", (int)id ); 1101 tr_peerIoDrain( msgs->io, inbuf, msglen ); 1102 break; 1103 } 1075 updatePeerProgress( msgs ); 1076 break; 1077 1078 case BT_HAVE_NONE: 1079 dbgmsg( msgs, "Got a BT_HAVE_NONE" ); 1080 tr_bitfieldClear( msgs->info->have ); 1081 updatePeerProgress( msgs ); 1082 break; 1083 1084 case BT_REJECT: { 1085 struct peer_request req; 1086 dbgmsg( msgs, "Got a BT_REJECT" ); 1087 tr_peerIoReadUint32( msgs->io, inbuf, &req.index ); 1088 tr_peerIoReadUint32( msgs->io, inbuf, &req.offset ); 1089 tr_peerIoReadUint32( msgs->io, inbuf, &req.length ); 1090 tr_free( tr_list_remove( &msgs->clientAskedFor, &req, compareRequest ) ); 1091 break; 1092 } 1093 1094 case BT_ALLOWED_FAST: { 1095 dbgmsg( msgs, "Got a BT_ALLOWED_FAST" ); 1096 tr_peerIoReadUint32( msgs->io, inbuf, &ui32 ); 1097 tr_bitfieldAdd( msgs->clientAllowedPieces, ui32 ); 1098 break; 1099 } 1100 #endif 1101 1102 case BT_LTEP: 1103 dbgmsg( msgs, "Got a BT_LTEP" ); 1104 parseLtep( msgs, msglen, inbuf ); 1105 break; 1106 1107 default: 1108 dbgmsg( msgs, "peer sent us an UNKNOWN: %d", (int)id ); 1109 tr_peerIoDrain( msgs->io, inbuf, msglen ); 1110 break; 1111 } 1112 1113 1114 dbgmsg( msgs, "startBufLen was %d, msglen was %d, current inbuf len is %d", (int)startBufLen, (int)(msglen+1), (int)EVBUFFER_LENGTH(inbuf) ); 1104 1115 1105 1116 msgs->incomingMessageLength = -1; … … 1170 1181 1171 1182 static void 1172 gotUnwantedBlock( tr_peermsgs * msgs, 1173 uint32_t index UNUSED, 1174 uint32_t offset UNUSED, 1175 uint32_t length ) 1176 { 1177 reassignBytesToCorrupt( msgs, length ); 1178 } 1179 1180 static void 1181 addUsToBlamefield( tr_peermsgs * msgs, uint32_t index ) 1183 clientGotUnwantedBlock( tr_peermsgs * msgs, const struct peer_request * req ) 1184 { 1185 reassignBytesToCorrupt( msgs, req->length ); 1186 } 1187 1188 static void 1189 addPeerToBlamefield( tr_peermsgs * msgs, uint32_t index ) 1182 1190 { 1183 1191 if( !msgs->info->blame ) … … 1187 1195 1188 1196 static void 1189 gotBlock( tr_peermsgs * msgs, 1190 struct evbuffer * inbuf, 1191 uint32_t index, 1192 uint32_t offset, 1193 uint32_t length ) 1194 { 1197 clientGotBlock( tr_peermsgs * msgs, const uint8_t * data, const struct peer_request * req ) 1198 { 1199 int i; 1195 1200 tr_torrent * tor = msgs->torrent; 1196 const int block = _tr_block( tor, index, offset ); 1197 struct peer_request key, *req; 1201 const int block = _tr_block( tor, req->index, req->offset ); 1202 struct peer_request *myreq; 1203 1204 assert( msgs != NULL ); 1205 assert( req != NULL ); 1206 assert( req->length > 0 ); 1207 assert( req->length == (uint32_t)tr_torBlockCountBytes( msgs->torrent, block ) ); 1208 1209 /* save the block */ 1210 dbgmsg( msgs, "got block %u:%u->%u", req->index, req->offset, req->length ); 1198 1211 1199 1212 /** … … 1201 1214 **/ 1202 1215 1203 key.index = index; 1204 key.offset = offset; 1205 key.length = length; 1206 req = (struct peer_request*) tr_list_remove( &msgs->clientAskedFor, &key, 1207 compareRequest ); 1208 if( req == NULL ) { 1209 gotUnwantedBlock( msgs, index, offset, length ); 1216 myreq = tr_list_remove( &msgs->clientAskedFor, req, compareRequest ); 1217 if( myreq == NULL ) { 1218 clientGotUnwantedBlock( msgs, req ); 1210 1219 dbgmsg( msgs, "we didn't ask for this message..." ); 1211 1220 return; 1212 1221 } 1222 1213 1223 dbgmsg( msgs, "got block %u:%u->%u (turnaround time %d secs)", 1214 req->index, req->offset, req->length, 1215 (int)(time(NULL) - req->time_requested) ); 1216 tr_free( req ); 1224 myreq->index, myreq->offset, myreq->length, 1225 (int)(time(NULL) - myreq->time_requested) ); 1217 1226 dbgmsg( msgs, "peer has %d more blocks we've asked for", 1218 1227 tr_list_size(msgs->clientAskedFor)); … … 1223 1232 1224 1233 if( tr_cpBlockIsComplete( tor->completion, block ) ) { 1225 dbgmsg( msgs, "have this block already..." ); 1226 tr_dbg( "have this block already..." ); 1227 gotUnwantedBlock( msgs, index, offset, length ); 1234 dbgmsg( msgs, "we have this block already..." ); 1235 clientGotUnwantedBlock( msgs, req ); 1228 1236 return; 1229 1237 } 1230 1238 1231 if( (int)length != tr_torBlockCountBytes( tor, block ) ) { 1232 dbgmsg( msgs, "block is the wrong length..." ); 1233 tr_dbg( "block is the wrong length..." ); 1234 gotUnwantedBlock( msgs, index, offset, length ); 1239 /** 1240 *** Save the block 1241 **/ 1242 1243 msgs->info->peerSentPieceDataAt = time( NULL ); 1244 clientGotBytes( msgs, req->length ); 1245 i = tr_ioWrite( tor, req->index, req->offset, req->length, data ); 1246 if( i ) 1235 1247 return; 1236 }1237 1238 /**1239 *** Write the block1240 **/1241 1242 if( tr_ioWrite( tor, index, offset, length, EVBUFFER_DATA( inbuf )))1243 return;1244 1245 #warning this sanity check is here to help track down the excess corrupt data bug, but is expensive and should be removed before the next release1246 {1247 uint8_t * tmp = tr_new( uint8_t, length );1248 const int val = tr_ioRead( tor, index, offset, length, tmp );1249 assert( !val );1250 assert( !memcmp( tmp, EVBUFFER_DATA(inbuf), length ) );1251 tr_free( tmp );1252 }1253 1248 1254 1249 tr_cpBlockAdd( tor->completion, block ); 1255 1250 1256 add UsToBlamefield( msgs,index );1257 1258 fireGotBlock( msgs, index, offset, length);1251 addPeerToBlamefield( msgs, req->index ); 1252 1253 fireGotBlock( msgs, req ); 1259 1254 1260 1255 /** … … 1262 1257 **/ 1263 1258 1264 if( tr_cpPieceIsComplete( tor->completion, index ) )1265 { 1266 if( tr_ioHash( tor, index ) )1259 if( tr_cpPieceIsComplete( tor->completion, req->index ) ) 1260 { 1261 if( tr_ioHash( tor, req->index ) ) 1267 1262 { 1268 gotBadPiece( msgs, index );1263 gotBadPiece( msgs, req->index ); 1269 1264 return; 1270 1265 } 1271 1266 1272 fireClientHave( msgs, index ); 1273 } 1274 } 1275 1276 1277 static ReadState 1278 readBtPiece( tr_peermsgs * msgs, struct evbuffer * inbuf ) 1279 { 1280 uint32_t inlen; 1281 uint8_t * tmp; 1282 1283 assert( msgs != NULL ); 1284 assert( msgs->blockToUs.length > 0 ); 1285 assert( inbuf != NULL ); 1286 assert( EVBUFFER_LENGTH( inbuf ) > 0 ); 1287 1288 /* read from the inbuf into our block buffer */ 1289 inlen = MIN( EVBUFFER_LENGTH(inbuf), msgs->blockToUs.length ); 1290 tmp = tr_new( uint8_t, inlen ); 1291 tr_peerIoReadBytes( msgs->io, inbuf, tmp, inlen ); 1292 evbuffer_add( msgs->inBlock, tmp, inlen ); 1293 1294 /* update our tables accordingly */ 1295 assert( inlen >= msgs->blockToUs.length ); 1296 msgs->blockToUs.length -= inlen; 1297 msgs->info->peerSentPieceDataAt = time( NULL ); 1298 clientGotBytes( msgs, inlen ); 1299 1300 /* if this was the entire block, save it */ 1301 if( !msgs->blockToUs.length ) 1302 { 1303 dbgmsg( msgs, "got block %u:%u", msgs->blockToUs.index, msgs->blockToUs.offset ); 1304 assert( (int)EVBUFFER_LENGTH( msgs->inBlock ) == tr_torBlockCountBytes( msgs->torrent, _tr_block(msgs->torrent,msgs->blockToUs.index, msgs->blockToUs.offset) ) ); 1305 gotBlock( msgs, msgs->inBlock, 1306 msgs->blockToUs.index, 1307 msgs->blockToUs.offset, 1308 EVBUFFER_LENGTH( msgs->inBlock ) ); 1309 evbuffer_drain( msgs->inBlock, ~0 ); 1310 msgs->state = AWAITING_BT_LENGTH; 1311 } 1312 1313 /* cleanup */ 1314 tr_free( tmp ); 1315 return READ_AGAIN; 1267 fireClientHave( msgs, req->index ); 1268 } 1316 1269 } 1317 1270 … … 1333 1286 case AWAITING_BT_LENGTH: ret = readBtLength ( msgs, inbuf ); break; 1334 1287 case AWAITING_BT_MESSAGE: ret = readBtMessage ( msgs, inbuf ); break; 1335 case READING_BT_PIECE: ret = readBtPiece ( msgs, inbuf ); break;1336 1288 default: assert( 0 ); 1337 1289 } … … 1371 1323 1372 1324 if( tor->uploadLimitMode == TR_SPEEDLIMIT_GLOBAL ) 1373 return tor->handle->useUploadLimit ? tr_rcBytesLeft( tor->handle->upload ) : maxval; 1325 return tor->handle->useUploadLimit 1326 ? tr_rcBytesLeft( tor->handle->upload ) : maxval; 1374 1327 1375 1328 if( tor->uploadLimitMode == TR_SPEEDLIMIT_SINGLE ) … … 1385 1338 msgs->info->rateToClient = tr_rcRate( msgs->info->rcToClient ); 1386 1339 msgs->info->rateToPeer = tr_rcRate( msgs->info->rcToPeer ); 1387 msgs->maxActiveRequests = MIN( 8 + (int)(msgs->info->rateToClient/ 10), 100 );1388 msgs->minActiveRequests = msgs->maxActiveRequests / 2;1340 msgs->maxActiveRequests = MIN( 8 + (int)(msgs->info->rateToClient/5), 100 ); 1341 msgs->minActiveRequests = msgs->maxActiveRequests / 3; 1389 1342 return TRUE; 1390 1343 } … … 1677 1630 m->outMessages = evbuffer_new( ); 1678 1631 m->outBlock = evbuffer_new( ); 1679 m->inBlock = evbuffer_new( );1680 1632 m->peerAllowedPieces = NULL; 1681 1633 m->clientAllowedPieces = NULL; … … 1697 1649 } 1698 1650 1699 tr_peerIoSetTimeoutSecs( m->io, 150 ); /* error if we don't read or write for 2.5 minutes*/1651 tr_peerIoSetTimeoutSecs( m->io, 150 ); /* timeout after N seconds of inactivity */ 1700 1652 tr_peerIoSetIOFuncs( m->io, canRead, didWrite, gotError, m ); 1701 1653 tr_peerIoSetIOMode( m->io, EV_READ|EV_WRITE, 0 ); … … 1742 1694 evbuffer_free( msgs->outMessages ); 1743 1695 evbuffer_free( msgs->outBlock ); 1744 evbuffer_free( msgs->inBlock );1745 1696 tr_free( msgs->pex ); 1746 1697 msgs->pexCount = 0; -
branches/0.9x/libtransmission/trevent.c
r3457 r3780 229 229 eh->lock = tr_lockNew( ); 230 230 eh->h = handle; 231 eh->pulseInterval = timevalMsec( 50);231 eh->pulseInterval = timevalMsec( 25 ); 232 232 eh->thread = tr_threadNew( libeventThreadFunc, eh, "libeventThreadFunc" ); 233 233 }
Note: See TracChangeset
for help on using the changeset viewer.