Source:
private boolean route(final Type type, final long uid, byte htl, final Listener listener) { final Message message = DMT.createProbeRequest(htl, uid, type); PeerNode[] peers; int degree; PeerNode candidate; for (; htl > 0; htl = probabilisticDecrement(htl)) { peers = node.getConnectedPeers(); degree = peers.length; if (degree == 0) { if (logMINOR) Logger.minor(Probe.class, "Aborting received probe request because there are no connections."); listener.onError(Error.DISCONNECTED, null); return true; } candidate = peers[node.random.nextInt(degree)]; if (candidate.isConnected()) { double acceptProbability; int candidateDegree = candidate.getDegree(); if (candidateDegree == 0) acceptProbability = 1.0; else acceptProbability = (double)degree / candidateDegree; if (logDEBUG) Logger.debug(Probe.class, "acceptProbability is " + acceptProbability); if (node.random.nextDouble() < acceptProbability) { if (logDEBUG) Logger.debug(Probe.class, "Accepted candidate."); final MessageFilter filter = createResponseFilter(type, candidate, uid, htl); message.set(DMT.HTL, htl); try { node.getUSM().addAsyncFilter(filter, new ResultListener(listener), this); if (logDEBUG) Logger.debug(Probe.class, "Sending."); candidate.sendAsync(message, null, this); return true; } catch (NotConnectedException e) { if (logMINOR) Logger.minor(Probe.class, "Peer became disconnected between check and send attempt.", e); } catch (DisconnectedException e) { if (logMINOR) Logger.minor(Probe.class, "Peer became disconnected while attempting to add filter.", e); } } } } return false; }

Target:
private boolean route(final Type type, final long uid, byte htl, final Listener listener) { final Message message = DMT.createProbeRequest(htl, uid, type); PeerNode[] peers; int degree; PeerNode candidate; for (int sendAttempts = 0; sendAttempts < MAX_SEND_ATTEMPTS; sendAttempts++) { peers = node.getConnectedPeers(); degree = peers.length; if (degree == 0 ) { if (logMINOR) { Logger.minor(Probe.class, "Aborting probe request: no connections."); } listener.onError(Error.DISCONNECTED, null); return true; } candidate = peers[node.random.nextInt(degree)]; if (candidate.isConnected()) { float acceptProbability; int candidateDegree = candidate.getDegree(); if (candidateDegree == 0) acceptProbability = 1.0f; else acceptProbability = (float)degree / candidateDegree; if (logDEBUG) Logger.debug(Probe.class, "acceptProbability is " + acceptProbability); if (node.random.nextFloat() < acceptProbability) { if (logDEBUG) Logger.debug(Probe.class, "Accepted candidate."); final MessageFilter filter = createResponseFilter(type, candidate, uid, htl); message.set(DMT.HTL, htl); try { node.getUSM().addAsyncFilter(filter, new ResultListener(listener), this); if (logDEBUG) Logger.debug(Probe.class, "Sending."); candidate.sendAsync(message, null, this); return true; } catch (NotConnectedException e) { if (logMINOR) Logger.minor(Probe.class, "Peer became disconnected between check and send attempt.", e); } catch (DisconnectedException e) { if (logMINOR) Logger.minor(Probe.class, "Peer became disconnected while attempting to add filter.", e); } } else { htl = probabilisticDecrement(htl); if (htl == 0) return false; } } else { if (logMINOR) Logger.minor(Probe.class, "Peer in connectedPeers was not connected.", new Exception()); } } if (logWARNING) { Logger.warning(Probe.class, "Aborting probe request: send attempt limit reached."); } listener.onError(Error.CANNOT_FORWARD, null); return true; }