Changeset 4884148
- Timestamp:
- Dec 17, 2011 2:02:01 PM (9 years ago)
- Branches:
- master
- Children:
- 18b8ddc
- Parents:
- bf45e31
- Location:
- router/java/src/net/i2p/router
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
router/java/src/net/i2p/router/peermanager/ProfileManagerImpl.java
rbf45e31 r4884148 22 22 import net.i2p.util.Log; 23 23 24 /** 25 * Methods to update profiles. 26 * Unless otherwise noted, methods are blocking on the reorganize lock. 27 */ 24 28 public class ProfileManagerImpl implements ProfileManager { 25 29 private final Log _log; … … 34 38 * Note that it took msToSend to send a message of size bytesSent to the peer over the transport. 35 39 * This should only be called if the transport considered the send successful. 36 * 40 * Non-blocking. Will not update the profile if we can't get the lock. 37 41 */ 38 42 public void messageSent(Hash peer, String transport, long msToSend, long bytesSent) { 39 PeerProfile data = getProfile (peer);43 PeerProfile data = getProfileNonblocking(peer); 40 44 if (data == null) return; 41 45 data.setLastSendSuccessful(_context.clock().now()); … … 44 48 45 49 /** 46 * Note that the router failed to send a message to the peer over the transport specified 47 * 50 * Note that the router failed to send a message to the peer over the transport specified. 51 * Non-blocking. Will not update the profile if we can't get the lock. 48 52 */ 49 53 public void messageFailed(Hash peer, String transport) { 50 PeerProfile data = getProfile (peer);54 PeerProfile data = getProfileNonblocking(peer); 51 55 if (data == null) return; 52 56 data.setLastSendFailed(_context.clock().now()); … … 54 58 55 59 /** 56 * Note that the router failed to send a message to the peer over any transport 57 * 60 * Note that the router failed to send a message to the peer over any transport. 61 * Non-blocking. Will not update the profile if we can't get the lock. 58 62 */ 59 63 public void messageFailed(Hash peer) { 60 PeerProfile data = getProfile (peer);64 PeerProfile data = getProfileNonblocking(peer); 61 65 if (data == null) return; 62 66 data.setLastSendFailed(_context.clock().now()); … … 71 75 _log.info("Comm error occurred for peer " + peer.toBase64(), new Exception("Comm error")); 72 76 PeerProfile data = getProfile(peer); 73 if (data == null) return;77 //if (data == null) return; 74 78 data.setLastSendFailed(_context.clock().now()); 75 79 } … … 81 85 public void tunnelJoined(Hash peer, long responseTimeMs) { 82 86 PeerProfile data = getProfile(peer); 83 if (data == null) return;87 //if (data == null) return; 84 88 data.getTunnelCreateResponseTime().addData(responseTimeMs, responseTimeMs); 85 89 data.setLastHeardFrom(_context.clock().now()); … … 96 100 public void tunnelRejected(Hash peer, long responseTimeMs, int severity) { 97 101 PeerProfile data = getProfile(peer); 98 if (data == null) return;102 //if (data == null) return; 99 103 data.setLastHeardFrom(_context.clock().now()); 100 104 data.getTunnelHistory().incrementRejected(severity); … … 109 113 public void tunnelTimedOut(Hash peer) { 110 114 PeerProfile data = getProfile(peer); 111 if (data == null) return;115 //if (data == null) return; 112 116 data.getTunnelHistory().incrementRejected(TunnelHistory.TUNNEL_REJECT_BANDWIDTH); 113 117 } … … 120 124 public void tunnelTestSucceeded(Hash peer, long responseTimeMs) { 121 125 PeerProfile data = getProfile(peer); 122 if (data == null) return;126 //if (data == null) return; 123 127 data.updateTunnelTestTimeAverage(responseTimeMs); 124 128 data.getTunnelTestResponseTime().addData(responseTimeMs, responseTimeMs); … … 129 133 return; 130 134 PeerProfile data = getProfile(peer); 131 if (data != null)135 //if (data != null) 132 136 data.dataPushed(size); // ignore rtt, as we are averaging over a minute 133 137 } 138 134 139 public void tunnelDataPushed1m(Hash peer, int size) { 135 140 if (_context.routerHash().equals(peer)) 136 141 return; 137 142 PeerProfile data = getProfile(peer); 138 if (data != null)143 //if (data != null) 139 144 data.dataPushed1m(size); 140 145 } … … 145 150 return; 146 151 PeerProfile data = getProfile(peer); 147 if (data != null)152 //if (data != null) 148 153 data.tunnelDataTransferred(size); 149 154 } … … 163 168 public void tunnelFailed(Hash peer, int pct) { 164 169 PeerProfile data = getProfile(peer); 165 if (data == null) return;170 //if (data == null) return; 166 171 data.setLastHeardFrom(_context.clock().now()); 167 172 data.getTunnelHistory().incrementFailed(pct); … … 175 180 public void dbLookupSuccessful(Hash peer, long responseTimeMs) { 176 181 PeerProfile data = getProfile(peer); 177 if (data == null) return;182 //if (data == null) return; 178 183 data.setLastHeardFrom(_context.clock().now()); 179 184 if (!data.getIsExpandedDB()) … … 192 197 public void dbLookupFailed(Hash peer) { 193 198 PeerProfile data = getProfile(peer); 194 if (data == null) return;199 //if (data == null) return; 195 200 if (!data.getIsExpandedDB()) 196 201 data.expandDBProfile(); … … 209 214 public void dbLookupReply(Hash peer, int newPeers, int oldPeers, int invalid, int duplicate, long responseTimeMs) { 210 215 PeerProfile data = getProfile(peer); 211 if (data == null) return;216 //if (data == null) return; 212 217 data.setLastHeardFrom(_context.clock().now()); 213 218 if (!data.getIsExpandedDB()) … … 225 230 public void dbLookupReceived(Hash peer) { 226 231 PeerProfile data = getProfile(peer); 227 if (data == null) return;232 //if (data == null) return; 228 233 data.setLastHeardFrom(_context.clock().now()); 229 234 if (!data.getIsExpandedDB()) … … 239 244 public void dbStoreReceived(Hash peer, boolean wasNewKey) { 240 245 PeerProfile data = getProfile(peer); 241 if (data == null) return;246 //if (data == null) return; 242 247 data.setLastHeardFrom(_context.clock().now()); 243 248 if (!data.getIsExpandedDB()) … … 258 263 public void dbStoreSent(Hash peer, long responseTimeMs) { 259 264 PeerProfile data = getProfile(peer); 260 if (data == null) return;265 //if (data == null) return; 261 266 long now = _context.clock().now(); 262 267 data.setLastHeardFrom(now); … … 276 281 public void dbStoreSuccessful(Hash peer) { 277 282 PeerProfile data = getProfile(peer); 278 if (data == null) return;283 //if (data == null) return; 279 284 long now = _context.clock().now(); 280 285 data.setLastHeardFrom(now); … … 294 299 public void dbStoreFailed(Hash peer) { 295 300 PeerProfile data = getProfile(peer); 296 if (data == null) return;301 //if (data == null) return; 297 302 if (!data.getIsExpandedDB()) 298 303 data.expandDBProfile(); … … 309 314 public void heardAbout(Hash peer) { 310 315 PeerProfile data = getProfile(peer); 311 if (data == null) return;316 //if (data == null) return; 312 317 data.setLastHeardAbout(_context.clock().now()); 313 318 } … … 319 324 public void heardAbout(Hash peer, long when) { 320 325 PeerProfile data = getProfile(peer); 321 if (data == null) return;326 //if (data == null) return; 322 327 if (when > data.getLastHeardAbout()) 323 328 data.setLastHeardAbout(when); … … 328 333 * transport. Messages received without any "from" information aren't recorded 329 334 * through this metric. If msToReceive is negative, there was no timing information 330 * available 331 * 335 * available. 336 * Non-blocking. Will not update the profile if we can't get the lock. 332 337 */ 333 338 public void messageReceived(Hash peer, String style, long msToReceive, int bytesRead) { 334 PeerProfile data = getProfile (peer);339 PeerProfile data = getProfileNonblocking(peer); 335 340 if (data == null) return; 336 341 data.setLastHeardFrom(_context.clock().now()); … … 338 343 } 339 344 345 /** 346 * Blocking. 347 * Creates a new profile if it didn't exist. 348 * @return non-null 349 */ 340 350 private PeerProfile getProfile(Hash peer) { 341 351 PeerProfile prof = _context.profileOrganizer().getProfile(peer); … … 348 358 } 349 359 350 351 /** provide a simple summary of a number of peers, suitable for publication in the netDb */ 360 /** 361 * Non-blocking. 362 * @return null if the profile doesn't exist, or the fetch would have blocked 363 * @since 0.8.12 364 */ 365 private PeerProfile getProfileNonblocking(Hash peer) { 366 return _context.profileOrganizer().getProfileNonblocking(peer); 367 } 368 369 /** 370 * provide a simple summary of a number of peers, suitable for publication in the netDb 371 * @deprecated unused 372 */ 352 373 public Properties summarizePeers(int numPeers) { 374 /**** 353 375 Set peers = new HashSet(numPeers); 354 376 // lets get the fastest ones we've got (this fails over to include just plain reliable, 355 377 // or even notFailing peers if there aren't enough fast ones) 356 378 _context.profileOrganizer().selectFastPeers(numPeers, null, peers); 379 ****/ 357 380 Properties props = new Properties(); 381 /**** 358 382 for (Iterator iter = peers.iterator(); iter.hasNext(); ) { 359 383 Hash peer = (Hash)iter.next(); … … 385 409 props.setProperty("profile." + peer.toBase64().replace('=', '_'), buf.toString()); 386 410 } 411 ****/ 387 412 return props; 388 413 } 389 414 415 /**** 390 416 private final static DecimalFormat _fmt = new DecimalFormat("##0.00", new DecimalFormatSymbols(Locale.UK)); 391 417 private final static String num(double val) { 392 418 synchronized (_fmt) { return _fmt.format(val); } 393 419 } 420 ****/ 394 421 } -
router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java
rbf45e31 r4884148 53 53 /** H(routerIdnetity), containing elements in _notFailingPeers */ 54 54 private final List<Hash> _notFailingPeersList; 55 /** H(routerIdentity) to PeerProfile for all peers that ARE failing horribly (but that we haven't dropped reference to yet) */55 /** TO BE REMOVED H(routerIdentity) to PeerProfile for all peers that ARE failing horribly (but that we haven't dropped reference to yet) */ 56 56 private final Map<Hash, PeerProfile> _failingPeers; 57 57 /** who are we? */ … … 121 121 } 122 122 123 /** 124 * Get the lock if we can. Non-blocking. 125 * @return true if the lock was acquired 126 * @since 0.8.12 127 */ 128 private boolean tryReadLock() { 129 return _reorganizeLock.readLock().tryLock(); 130 } 131 123 132 private void releaseReadLock() { 124 133 _reorganizeLock.readLock().unlock(); … … 148 157 149 158 /** 150 * Retrieve the profile for the given peer, if one exists (else null) 151 * 159 * Retrieve the profile for the given peer, if one exists (else null). 160 * Blocking if a reorganize is happening. 152 161 */ 153 162 public PeerProfile getProfile(Hash peer) { … … 156 165 return locked_getProfile(peer); 157 166 } finally { releaseReadLock(); } 167 } 168 169 /** 170 * Retrieve the profile for the given peer, if one exists (else null). 171 * Non-blocking. Returns null if a reorganize is happening. 172 * @since 0.8.12 173 */ 174 public PeerProfile getProfileNonblocking(Hash peer) { 175 if (tryReadLock()) { 176 try { 177 return locked_getProfile(peer); 178 } finally { releaseReadLock(); } 179 } 180 return null; 158 181 } 159 182 … … 244 267 public boolean isHighCapacity(Hash peer) { return isX(_highCapacityPeers, peer); } 245 268 public boolean isWellIntegrated(Hash peer) { return isX(_wellIntegratedPeers, peer); } 246 public boolean isFailing(Hash peer) { return isX(_failingPeers, peer); } 269 270 /** 271 * Deprecated for now, always false 272 */ 273 public boolean isFailing(Hash peer) { 274 // Always false so skip the lock 275 //return isX(_failingPeers, peer); 276 return false; 277 } 247 278 248 279 /** @since 0.8.8 */ -
router/java/src/net/i2p/router/transport/udp/IntroductionManager.java
rbf45e31 r4884148 127 127 continue; 128 128 } 129 if ( _context.profileOrganizer().isFailing(cur.getRemotePeer()) ||129 if ( /* _context.profileOrganizer().isFailing(cur.getRemotePeer()) || */ 130 130 _context.shitlist().isShitlisted(cur.getRemotePeer()) || 131 131 _transport.wasUnreachable(cur.getRemotePeer())) {
Note: See TracChangeset
for help on using the changeset viewer.