Changeset 14083
- Timestamp:
- May 27, 2013, 9:04:48 PM (9 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-mgr.c
r14076 r14083 487 487 488 488 static void 489 resetTorrentStats (tr_torrent * tor) 490 { 491 int i; 492 493 tor->peerCount = 0; 494 tor->activePeerCount[TR_UP] = 0; 495 tor->activePeerCount[TR_DOWN] = 0; 496 tor->activeWebseedCount = 0; 497 for (i=0; i<TR_PEER_FROM__MAX; i++) 498 tor->peerFromCount[i] = 0; 499 } 500 501 static void 489 502 swarmFree (void * vs) 490 503 { … … 501 514 tr_ptrArrayDestruct (&s->outgoingHandshakes, NULL); 502 515 tr_ptrArrayDestruct (&s->peers, NULL); 516 resetTorrentStats (s->tor); 503 517 504 518 replicationFree (s); … … 520 534 tr_ptrArrayDestruct (&s->webseeds, (PtrArrayForeachFunc)tr_peerFree); 521 535 s->webseeds = TR_PTR_ARRAY_INIT; 536 s->tor->activeWebseedCount = 0; 522 537 523 538 /* repopulate it */ … … 594 609 managerUnlock (manager); 595 610 tr_free (manager); 596 }597 598 static int599 clientIsDownloadingFrom (const tr_torrent * tor, const tr_peerMsgs * p)600 {601 if (!tr_torrentHasMetadata (tor))602 return true;603 604 return tr_peerMsgsIsClientInterested (p) && !tr_peerMsgsIsClientChoked (p);605 }606 607 static int608 clientIsUploadingTo (const tr_peerMsgs * p)609 {610 return tr_peerMsgsIsPeerInterested (p) && !tr_peerMsgsIsPeerChoked (p);611 611 } 612 612 … … 869 869 countActiveWebseeds (tr_swarm * s) 870 870 { 871 int i; 872 int activeCount = 0; 873 const int n = tr_ptrArraySize (&s->webseeds); 874 const uint64_t now = tr_time_msec (); 875 876 for (i=0; i<n; ++i) 877 if (tr_peerIsTransferringPieces (tr_ptrArrayNth(&s->webseeds,i), now, TR_DOWN, NULL)) 878 ++activeCount; 871 int activeCount; 872 873 if (s->tor->isRunning && !tr_torrentIsSeed (s->tor)) 874 { 875 int i; 876 const int n = tr_ptrArraySize (&s->webseeds); 877 const uint64_t now = tr_time_msec (); 878 879 for (i=0; i<n; ++i) 880 if (tr_peerIsTransferringPieces (tr_ptrArrayNth(&s->webseeds,i), now, TR_DOWN, NULL)) 881 ++activeCount; 882 } 883 else 884 { 885 activeCount = 0; 886 } 879 887 880 888 return activeCount; … … 1932 1940 1933 1941 tr_ptrArrayInsertSorted (&swarm->peers, peer, peerCompare); 1942 ++tor->peerCount; 1943 ++tor->peerFromCount[atom->fromFirst]; 1944 1945 assert (tor->peerCount == tr_ptrArraySize (&swarm->peers)); 1946 assert (tor->peerFromCount[atom->fromFirst] <= tor->peerCount); 1934 1947 } 1935 1948 … … 2420 2433 } 2421 2434 2435 static void removeAllPeers (tr_swarm *); 2436 2422 2437 static void 2423 2438 stopSwarm (tr_swarm * swarm) 2424 2439 { 2425 tr_peer * peer;2426 2427 2440 swarm->isRunning = false; 2428 2441 … … 2430 2443 invalidatePieceSorting (swarm); 2431 2444 2432 /* disconnect the peers. */ 2433 while ((peer = tr_ptrArrayPop (&swarm->peers))) 2434 tr_peerFree (peer); 2445 removeAllPeers (swarm); 2435 2446 2436 2447 /* disconnect the handshakes. handshakeAbort calls handshakeDoneCB (), … … 2522 2533 for (i=0; i<peerCount; ++i) 2523 2534 tr_peerUpdateProgress (tor, peers[i]); 2535 2536 /* update the bittorrent peers' willingnes... */ 2537 for (i=0; i<peerCount; ++i) 2538 { 2539 tr_peerMsgsUpdateActive (tr_peerMsgsCast(peers[i]), TR_UP); 2540 tr_peerMsgsUpdateActive (tr_peerMsgsCast(peers[i]), TR_DOWN); 2541 } 2524 2542 } 2525 2543 … … 2616 2634 assert (desiredAvailable <= tor->info.totalSize); 2617 2635 return desiredAvailable; 2618 }2619 2620 void2621 tr_peerMgrTorrentStats (tr_torrent * tor,2622 int * setmePeersConnected,2623 int * setmeWebseedsSendingToUs,2624 int * setmePeersSendingToUs,2625 int * setmePeersGettingFromUs,2626 int * setmePeersFrom)2627 {2628 int i;2629 int n;2630 tr_swarm * s;2631 2632 assert (tr_isTorrent (tor));2633 2634 *setmePeersConnected = 0;2635 *setmePeersGettingFromUs = 0;2636 *setmePeersSendingToUs = 0;2637 *setmeWebseedsSendingToUs = 0;2638 2639 s = tor->swarm;2640 n = tr_ptrArraySize (&s->peers);2641 2642 for (i=0; i<TR_PEER_FROM__MAX; ++i)2643 setmePeersFrom[i] = 0;2644 2645 for (i=0; i<n; ++i)2646 {2647 tr_peer * peer = tr_ptrArrayNth (&s->peers, i);2648 tr_peerMsgs * msgs = PEER_MSGS (peer);2649 const struct peer_atom * atom = peer->atom;2650 2651 assert (msgs != NULL);2652 2653 ++*setmePeersConnected;2654 2655 ++setmePeersFrom[atom->fromFirst];2656 2657 if (clientIsDownloadingFrom (tor, msgs))2658 ++*setmePeersSendingToUs;2659 2660 if (clientIsUploadingTo (msgs))2661 ++*setmePeersGettingFromUs;2662 }2663 2664 *setmeWebseedsSendingToUs = countActiveWebseeds (s);2665 2636 } 2666 2637 … … 2736 2707 stat->clientIsInterested = tr_peerMsgsIsClientInterested (msgs); 2737 2708 stat->isIncoming = tr_peerMsgsIsIncomingConnection (msgs); 2738 stat->isDownloadingFrom = clientIsDownloadingFrom (tor, msgs);2739 stat->isUploadingTo = clientIsUploadingTo (msgs);2709 stat->isDownloadingFrom = tr_peerMsgsIsActive (msgs, TR_PEER_TO_CLIENT); 2710 stat->isUploadingTo = tr_peerMsgsIsActive (msgs, TR_CLIENT_TO_PEER); 2740 2711 stat->isSeed = peerIsSeed (peer); 2741 2712 … … 3182 3153 while ((tor = tr_torrentNext (mgr->session, tor))) 3183 3154 { 3184 if (tor->isRunning )3155 if (tor->isRunning && tor->peerCount) 3185 3156 { 3186 3157 tr_swarm * s = tor->swarm; 3187 if (!tr_ptrArrayEmpty (&s->peers)) 3188 { 3189 rechokeUploads (s, now); 3190 rechokeDownloads (s); 3191 } 3158 rechokeUploads (s, now); 3159 rechokeDownloads (s); 3192 3160 } 3193 3161 } … … 3322 3290 3323 3291 removed = tr_ptrArrayRemoveSorted (&s->peers, peer, peerCompare); 3292 --s->tor->peerCount; 3293 --s->tor->peerFromCount[atom->fromFirst]; 3324 3294 3325 3295 if (replicationExists (s)) … … 3327 3297 3328 3298 assert (removed == peer); 3299 assert (s->tor->peerCount == tr_ptrArraySize (&s->peers)); 3300 assert (s->tor->peerFromCount[atom->fromFirst] >= 0); 3301 3329 3302 tr_peerFree (removed); 3330 3303 } … … 3363 3336 while (!tr_ptrArrayEmpty (&s->peers)) 3364 3337 removePeer (s, tr_ptrArrayNth (&s->peers, 0)); 3338 3339 assert (!s->tor->peerCount); 3365 3340 } 3366 3341 … … 3646 3621 if (tor->isStopping) 3647 3622 tr_torrentStop (tor); 3623 3624 /* update the torrent's stats */ 3625 tor->activeWebseedCount = countActiveWebseeds (tor->swarm); 3648 3626 } 3649 3627 -
trunk/libtransmission/peer-mgr.h
r13954 r14083 171 171 void tr_peerMgrOnBlocklistChanged (tr_peerMgr * manager); 172 172 173 void tr_peerMgrTorrentStats (tr_torrent * tor,174 int * setmePeersConnected,175 int * setmeWebseedsSendingToUs,176 int * setmePeersSendingToUs,177 int * setmePeersGettingFromUs,178 int * setmePeersFrom); /* TR_PEER_FROM__MAX */179 180 173 struct tr_peer_stat * tr_peerMgrPeerStats (const tr_torrent * tor, 181 174 int * setmeCount); -
trunk/libtransmission/peer-msgs.c
r14076 r14083 199 199 int prefetchCount; 200 200 201 int is_active[2]; 202 201 203 /* how long the outMessages batch should be allowed to grow before 202 204 * it's flushed -- some messages (like requests >:) should be sent … … 268 270 *** 269 271 **/ 272 273 static void 274 myDebug (const char * file, int line, 275 const struct tr_peerMsgs * msgs, 276 const char * fmt, ...) TR_GNUC_PRINTF(4, 5); 270 277 271 278 static void … … 679 686 #endif 680 687 688 /*** 689 **** ACTIVE 690 ***/ 691 692 bool 693 tr_peerMsgsIsActive (const tr_peerMsgs * msgs, tr_direction direction) 694 { 695 assert (tr_isPeerMsgs (msgs)); 696 assert (tr_isDirection (direction)); 697 698 return msgs->is_active[direction]; 699 } 700 701 static void 702 tr_peerMsgsSetActive (tr_peerMsgs * msgs, 703 tr_direction direction, 704 bool is_active) 705 { 706 if (msgs->is_active[direction] != is_active) 707 { 708 int n = msgs->torrent->activePeerCount[direction]; 709 710 msgs->is_active[direction] = is_active; 711 712 if (is_active) 713 ++n; 714 else 715 --n; 716 assert (0 <= n); 717 assert (n <= msgs->torrent->peerCount); 718 719 msgs->torrent->activePeerCount[direction] = n; 720 } 721 } 722 723 void 724 tr_peerMsgsUpdateActive (tr_peerMsgs * msgs, tr_direction direction) 725 { 726 bool active; 727 728 assert (tr_isPeerMsgs (msgs)); 729 assert (tr_isDirection (direction)); 730 731 if (direction == TR_CLIENT_TO_PEER) 732 { 733 active = tr_peerMsgsIsPeerInterested (msgs) 734 && !tr_peerMsgsIsPeerChoked (msgs); 735 } 736 else /* TR_PEER_TO_CLIENT */ 737 { 738 if (!tr_torrentHasMetadata (msgs->torrent)) 739 active = true; 740 else 741 active = tr_peerMsgsIsClientInterested (msgs) 742 && !tr_peerMsgsIsClientChoked (msgs); 743 } 744 745 tr_peerMsgsSetActive (msgs, direction, active); 746 } 747 681 748 /** 682 749 *** INTEREST … … 712 779 713 780 if (msgs->client_is_interested != b) 714 sendInterest (msgs, b); 781 { 782 sendInterest (msgs, b); 783 784 tr_peerMsgsUpdateActive (msgs, TR_PEER_TO_CLIENT); 785 } 715 786 } 716 787 … … 1417 1488 if (!fext) 1418 1489 fireGotChoke (msgs); 1490 tr_peerMsgsUpdateActive (msgs, TR_PEER_TO_CLIENT); 1419 1491 break; 1420 1492 … … 1422 1494 dbgmsg (msgs, "got Unchoke"); 1423 1495 msgs->client_is_choked = false; 1496 tr_peerMsgsUpdateActive (msgs, TR_PEER_TO_CLIENT); 1424 1497 updateDesiredRequestCount (msgs); 1425 1498 break; … … 1428 1501 dbgmsg (msgs, "got Interested"); 1429 1502 msgs->peer_is_interested = true; 1503 tr_peerMsgsUpdateActive (msgs, TR_CLIENT_TO_PEER); 1430 1504 break; 1431 1505 … … 1433 1507 dbgmsg (msgs, "got Not Interested"); 1434 1508 msgs->peer_is_interested = false; 1509 tr_peerMsgsUpdateActive (msgs, TR_CLIENT_TO_PEER); 1435 1510 break; 1436 1511 … … 2394 2469 assert (msgs != NULL); 2395 2470 2471 tr_peerMsgsSetActive (msgs, TR_UP, false); 2472 tr_peerMsgsSetActive (msgs, TR_DOWN, false); 2473 2396 2474 if (msgs->pexTimer != NULL) 2397 2475 event_free (msgs->pexTimer); … … 2418 2496 { 2419 2497 .destruct = peermsgs_destruct, 2420 .is_transferring_pieces = peermsgs_is_transferring_pieces 2498 .is_transferring_pieces = peermsgs_is_transferring_pieces, 2421 2499 }; 2422 2500 … … 2527 2605 m->client_is_interested = false; 2528 2606 m->peer_is_interested = false; 2607 m->is_active[TR_UP] = false; 2608 m->is_active[TR_DOWN] = false; 2529 2609 m->callback = callback; 2530 2610 m->callbackData = callbackData; -
trunk/libtransmission/peer-msgs.h
r14076 r14083 53 53 bool tr_peerMsgsIsClientInterested (const tr_peerMsgs * msgs); 54 54 55 bool tr_peerMsgsIsActive (const tr_peerMsgs * msgs, 56 tr_direction direction); 57 58 void tr_peerMsgsUpdateActive (tr_peerMsgs * msgs, 59 tr_direction direction); 60 55 61 time_t tr_peerMsgsGetConnectionAge (const tr_peerMsgs * msgs); 56 62 -
trunk/libtransmission/torrent.c
r14079 r14083 1256 1256 unsigned int pieceUploadSpeed_Bps; 1257 1257 unsigned int pieceDownloadSpeed_Bps; 1258 int i; 1258 1259 1259 1260 assert (tr_isTorrent (tor)); … … 1271 1272 s->manualAnnounceTime = tr_announcerNextManualAnnounce (tor); 1272 1273 1273 tr_peerMgrTorrentStats (tor,1274 &s->peersConnected,1275 &s->webseedsSendingToUs,1276 &s->peersSendingToUs,1277 &s->peersGettingFromUs,1278 s->peersFrom);1274 s->peersConnected = tor->peerCount; 1275 s->peersSendingToUs = tor->activePeerCount[TR_DOWN]; 1276 s->peersGettingFromUs = tor->activePeerCount[TR_UP]; 1277 s->webseedsSendingToUs = tor->activeWebseedCount; 1278 for (i=0; i<TR_PEER_FROM__MAX; i++) 1279 s->peersFrom[i] = tor->peerFromCount[i]; 1279 1280 1280 1281 s->rawUploadSpeed_KBps = toSpeedKBps (tr_bandwidthGetRawSpeed_Bps (&tor->bandwidth, now, TR_UP)); -
trunk/libtransmission/torrent.h
r13933 r14083 226 226 int secondsDownloading; 227 227 int secondsSeeding; 228 229 int peerCount; 230 int peerFromCount[TR_PEER_FROM__MAX]; 231 int activePeerCount[2]; 232 int activeWebseedCount; 228 233 229 234 int queuePosition;
Note: See TracChangeset
for help on using the changeset viewer.