Guest User

Untitled

a guest
Jul 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.57 KB | None | 0 0
  1. --- transmission-1.76_orig/libtransmission/peer-mgr.c 2009-10-25 02:47:21.000000000 +0100
  2. +++ transmission-1.76/libtransmission/peer-mgr.c 2009-11-22 02:45:51.393980440 +0100
  3. @@ -2276,10 +2276,6 @@
  4. if( atom->myflags & MYFLAG_UNREACHABLE )
  5. continue;
  6.  
  7. - /* we don't need two connections to the same peer... */
  8. - if( peerIsInUse( t, &atom->addr ) )
  9. - continue;
  10. -
  11. /* no need to connect if we're both seeds... */
  12. if( seed && ( ( atom->flags & ADDED_F_SEED_FLAG ) ||
  13. ( atom->uploadOnly == UPLOAD_ONLY_YES ) ) )
  14. @@ -2298,10 +2294,15 @@
  15. if( tr_sessionIsAddressBlocked( t->manager->session, &atom->addr ) )
  16. continue;
  17.  
  18. + /* we don't need two connections to the same peer... */
  19. + if( peerIsInUse( t, &atom->addr ) )
  20. + continue;
  21. +
  22. ret[retCount++] = atom;
  23. }
  24.  
  25. - qsort( ret, retCount, sizeof( struct peer_atom* ), compareCandidates );
  26. + if( retCount != 0 )
  27. + qsort( ret, retCount, sizeof( struct peer_atom* ), compareCandidates );
  28. *setmeSize = retCount;
  29. return ret;
  30. }
  31. @@ -2333,9 +2334,8 @@
  32. {
  33. static time_t prevTime = 0;
  34. static int newConnectionsThisSecond = 0;
  35. - time_t now;
  36. + time_t now = time( NULL );
  37.  
  38. - now = time( NULL );
  39. if( prevTime != now )
  40. {
  41. prevTime = now;
  42. @@ -2349,92 +2349,119 @@
  43. else
  44. {
  45. int i;
  46. - int canCloseCount;
  47. int mustCloseCount;
  48. - int candidateCount;
  49. int maxCandidates;
  50. - struct tr_peer ** canClose = getPeersToClose( t, TR_CAN_CLOSE, &canCloseCount );
  51. struct tr_peer ** mustClose = getPeersToClose( t, TR_MUST_CLOSE, &mustCloseCount );
  52. - struct peer_atom ** candidates = getPeerCandidates( t, &candidateCount );
  53. -
  54. - tordbg( t, "reconnect pulse for [%s]: "
  55. - "%d must-close connections, "
  56. - "%d can-close connections, "
  57. - "%d connection candidates, "
  58. - "%d atoms, "
  59. - "max per pulse is %d",
  60. - t->tor->info.name,
  61. - mustCloseCount,
  62. - canCloseCount,
  63. - candidateCount,
  64. - tr_ptrArraySize( &t->pool ),
  65. - MAX_RECONNECTIONS_PER_PULSE );
  66.  
  67. /* disconnect the really bad peers */
  68. for( i=0; i<mustCloseCount; ++i )
  69. closePeer( t, mustClose[i] );
  70.  
  71. /* decide how many peers can we try to add in this pass */
  72. - maxCandidates = candidateCount;
  73. - maxCandidates = MIN( maxCandidates, MAX_RECONNECTIONS_PER_PULSE );
  74. + maxCandidates = MAX_RECONNECTIONS_PER_PULSE;
  75. maxCandidates = MIN( maxCandidates, getMaxPeerCount( t->tor ) - getPeerCount( t ) );
  76. maxCandidates = MIN( maxCandidates, MAX_CONNECTIONS_PER_SECOND - newConnectionsThisSecond );
  77.  
  78. - /* maybe disconnect some lesser peers, if we have candidates to replace them with */
  79. - for( i=0; ( i<canCloseCount ) && ( i<maxCandidates ); ++i )
  80. - closePeer( t, canClose[i] );
  81. -
  82. - tordbg( t, "candidateCount is %d, MAX_RECONNECTIONS_PER_PULSE is %d,"
  83. - " getPeerCount(t) is %d, getMaxPeerCount(t) is %d, "
  84. - "newConnectionsThisSecond is %d, MAX_CONNECTIONS_PER_SECOND is %d",
  85. - candidateCount,
  86. - MAX_RECONNECTIONS_PER_PULSE,
  87. - getPeerCount( t ),
  88. - getMaxPeerCount( t->tor ),
  89. - newConnectionsThisSecond, MAX_CONNECTIONS_PER_SECOND );
  90. -
  91. - /* add some new ones */
  92. - for( i=0; i<maxCandidates; ++i )
  93. + if( maxCandidates == 0 )
  94. {
  95. - tr_peerMgr * mgr = t->manager;
  96. - struct peer_atom * atom = candidates[i];
  97. - tr_peerIo * io;
  98. -
  99. - tordbg( t, "Starting an OUTGOING connection with %s",
  100. - tr_peerIoAddrStr( &atom->addr, atom->port ) );
  101. -
  102. - io = tr_peerIoNewOutgoing( mgr->session, mgr->session->bandwidth, &atom->addr, atom->port, t->tor->info.hash );
  103. -
  104. - if( io == NULL )
  105. - {
  106. - tordbg( t, "peerIo not created; marking peer %s as unreachable",
  107. - tr_peerIoAddrStr( &atom->addr, atom->port ) );
  108. - atom->myflags |= MYFLAG_UNREACHABLE;
  109. - }
  110. - else
  111. - {
  112. - tr_handshake * handshake = tr_handshakeNew( io,
  113. - mgr->session->encryptionMode,
  114. - myHandshakeDoneCB,
  115. - mgr );
  116. -
  117. - assert( tr_peerIoGetTorrentHash( io ) );
  118. -
  119. - tr_peerIoUnref( io ); /* balanced by the implicit ref in tr_peerIoNewOutgoing() */
  120. -
  121. - ++newConnectionsThisSecond;
  122. -
  123. - tr_ptrArrayInsertSorted( &t->outgoingHandshakes, handshake,
  124. - handshakeCompare );
  125. - }
  126. -
  127. - atom->time = time( NULL );
  128. + tordbg( t, "reconnect pulse for [%s]: "
  129. + "%d must-close connections, "
  130. + "%d connection candidates _needed_, "
  131. + "%d atoms, "
  132. + "max per pulse is %d",
  133. + t->tor->info.name,
  134. + mustCloseCount,
  135. + maxCandidates,
  136. + tr_ptrArraySize( &t->pool ),
  137. + MAX_RECONNECTIONS_PER_PULSE );
  138. +
  139. + tordbg( t, "maxCandidates is %d, MAX_RECONNECTIONS_PER_PULSE is %d,"
  140. + " getPeerCount(t) is %d, getMaxPeerCount(t) is %d, "
  141. + "newConnectionsThisSecond is %d, MAX_CONNECTIONS_PER_SECOND is %d",
  142. + maxCandidates,
  143. + MAX_RECONNECTIONS_PER_PULSE,
  144. + getPeerCount( t ),
  145. + getMaxPeerCount( t->tor ),
  146. + newConnectionsThisSecond, MAX_CONNECTIONS_PER_SECOND );
  147. }
  148. -
  149. - /* cleanup */
  150. - tr_free( candidates );
  151. - tr_free( mustClose );
  152. - tr_free( canClose );
  153. + else
  154. + {
  155. + int canCloseCount;
  156. + int candidateCount;
  157. + struct tr_peer ** canClose = getPeersToClose( t, TR_CAN_CLOSE, &canCloseCount );
  158. + struct peer_atom ** candidates;
  159. +
  160. + candidates = getPeerCandidates( t, &candidateCount );
  161. + maxCandidates = MIN( maxCandidates, candidateCount );
  162. +
  163. + tordbg( t, "reconnect pulse for [%s]: "
  164. + "%d must-close connections, "
  165. + "%d can-close connections, "
  166. + "%d connection candidates, "
  167. + "%d atoms, "
  168. + "max per pulse is %d",
  169. + t->tor->info.name,
  170. + mustCloseCount,
  171. + canCloseCount,
  172. + candidateCount,
  173. + tr_ptrArraySize( &t->pool ),
  174. + MAX_RECONNECTIONS_PER_PULSE );
  175. +
  176. + /* maybe disconnect some lesser peers, if we have candidates to replace them with */
  177. + for( i=0; ( i<canCloseCount ) && ( i<maxCandidates ); ++i )
  178. + closePeer( t, canClose[i] );
  179. +
  180. + tordbg( t, "candidateCount is %d, MAX_RECONNECTIONS_PER_PULSE is %d,"
  181. + " getPeerCount(t) is %d, getMaxPeerCount(t) is %d, "
  182. + "newConnectionsThisSecond is %d, MAX_CONNECTIONS_PER_SECOND is %d",
  183. + candidateCount,
  184. + MAX_RECONNECTIONS_PER_PULSE,
  185. + getPeerCount( t ),
  186. + getMaxPeerCount( t->tor ),
  187. + newConnectionsThisSecond, MAX_CONNECTIONS_PER_SECOND );
  188. +
  189. + /* add some new ones */
  190. + for( i=0; i<maxCandidates; ++i )
  191. + {
  192. + tr_peerMgr * mgr = t->manager;
  193. + struct peer_atom * atom = candidates[i];
  194. + tr_peerIo * io;
  195. +
  196. + tordbg( t, "Starting an OUTGOING connection with %s",
  197. + tr_peerIoAddrStr( &atom->addr, atom->port ) );
  198. +
  199. + io = tr_peerIoNewOutgoing( mgr->session, mgr->session->bandwidth, &atom->addr, atom->port, t->tor->info.hash );
  200. +
  201. + if( io == NULL )
  202. + {
  203. + tordbg( t, "peerIo not created; marking peer %s as unreachable",
  204. + tr_peerIoAddrStr( &atom->addr, atom->port ) );
  205. + atom->myflags |= MYFLAG_UNREACHABLE;
  206. + }
  207. + else
  208. + {
  209. + tr_handshake * handshake = tr_handshakeNew( io,
  210. + mgr->session->encryptionMode,
  211. + myHandshakeDoneCB,
  212. + mgr );
  213. +
  214. + assert( tr_peerIoGetTorrentHash( io ) );
  215. +
  216. + tr_peerIoUnref( io ); /* balanced by the implicit ref in tr_peerIoNewOutgoing() */
  217. +
  218. + ++newConnectionsThisSecond;
  219. +
  220. + tr_ptrArrayInsertSorted( &t->outgoingHandshakes, handshake,
  221. + handshakeCompare );
  222. + }
  223. +
  224. + atom->time = time( NULL );
  225. + }
  226. + /* cleanup */
  227. + tr_free( candidates );
  228. + tr_free( canClose );
  229. + }
  230. + tr_free( mustClose );
  231. }
  232. }
Add Comment
Please, Sign In to add comment