Ticket #6121: integrate_webseeds_with_max_peers.patch

File integrate_webseeds_with_max_peers.patch, 3.0 KB (added by x190, 6 years ago)
  • libtransmission/peer-mgr.c

    old new  
    18921892static int
    18931893getMaxPeerCount (const tr_torrent * tor)
    18941894{
    1895   return tor->maxConnectedPeers;
     1895  int max_peers = tor->maxConnectedPeers - countActiveWebseeds (tor->swarm)*4;
     1896 
     1897  if (max_peers < 0)
     1898    max_peers = 0;
     1899   
     1900  return max_peers;
    18961901}
    18971902
    18981903static int
     
    34633468enforceTorrentPeerLimit (tr_swarm * s, uint64_t now)
    34643469{
    34653470  int n = tr_ptrArraySize (&s->peers);
    3466   const int max = tr_torrentGetPeerLimit (s->tor);
     3471  /* webseeds normally generate 4 connections each */
     3472  int max = (tr_torrentGetPeerLimit (s->tor) - countActiveWebseeds (s)*4);
     3473 
     3474  if (max < 0)
     3475    max = 0;
     3476   
    34673477  if (n > max)
    34683478    {
    34693479      void * base = tr_ptrArrayBase (&s->peers);
     
    34793489enforceSessionPeerLimit (tr_session * session, uint64_t now)
    34803490{
    34813491  int n = 0;
     3492  int ws = 0;
    34823493  tr_torrent * tor = NULL;
    3483   const int max = tr_sessionGetPeerLimit (session);
    3484 
     3494  int max = tr_sessionGetPeerLimit (session);
    34853495  /* count the total number of peers */
    34863496  while ((tor = tr_torrentNext (session, tor)))
    3487     n += tr_ptrArraySize (&tor->swarm->peers);
     3497    {
     3498      n += tr_ptrArraySize (&tor->swarm->peers);
     3499      ws += countActiveWebseeds (tor->swarm)*4;
     3500    }
     3501   
     3502  max -= ws;
     3503  if (max < 0)
     3504    max = 0;
    34883505
    34893506  /* if there are too many, prune out the worst */
    34903507  if (n > max)
     
    39333950static struct peer_candidate*
    39343951getPeerCandidates (tr_session * session, int * candidateCount, int max)
    39353952{
    3936   int atomCount;
    3937   int peerCount;
    3938   tr_torrent * tor;
     3953  int atomCount = 0;
     3954  int peerCount = 0;
     3955  int webseedCount = 0;
     3956  tr_torrent * tor = NULL;
    39393957  struct peer_candidate * candidates;
    39403958  struct peer_candidate * walk;
    39413959  const time_t now = tr_time ();
    39423960  const uint64_t now_msec = tr_time_msec ();
    3943   /* leave 5% of connection slots for incoming connections -- ticket #2609 */
    3944   const int maxCandidates = tr_sessionGetPeerLimit (session) * 0.95;
    3945 
    3946   /* count how many peers and atoms we've got */
    3947   tor= NULL;
    3948   atomCount = 0;
    3949   peerCount = 0;
     3961  /* count how many peers, atoms, and webseeds we've got */
    39503962  while ((tor = tr_torrentNext (session, tor)))
    39513963    {
    39523964      atomCount += tr_ptrArraySize (&tor->swarm->pool);
    39533965      peerCount += tr_ptrArraySize (&tor->swarm->peers);
     3966      webseedCount += countActiveWebseeds (tor->swarm)*4;
    39543967    }
    3955 
     3968  /* leave 5% of connection slots for incoming connections -- ticket #2609 */
     3969  const int maxCandidates = (tr_sessionGetPeerLimit (session) * 0.95 - webseedCount);
    39563970  /* don't start any new handshakes if we're full up */
    39573971  if (maxCandidates <= peerCount)
    39583972    {
     
    39743988        continue;
    39753989
    39763990      /* if we've already got enough peers in this torrent... */
    3977       if (tr_torrentGetPeerLimit (tor) <= tr_ptrArraySize (&tor->swarm->peers))
     3991      if ((tr_torrentGetPeerLimit (tor) - countActiveWebseeds (tor->swarm)*4) <= tr_ptrArraySize (&tor->swarm->peers))
    39783992        continue;
    39793993
    39803994      /* if we've already got enough speed in this torrent... */