Skip to content

Commit

Permalink
Clean up request() flow; decrement HTL consistently.
Browse files Browse the repository at this point in the history
Decrement HTL on failed send requests and replace while() with a for()
to make that behavior more consistent. Move return to avoid excess
continues.
  • Loading branch information
Thynix committed May 17, 2012
1 parent e788bc9 commit cc7dc83
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/freenet/node/MHProbe.java
Expand Up @@ -273,7 +273,7 @@ public void request(final Message message, final PeerNode source, final AsyncMes
* though it is decremented probabilistically.
*/
htl = probabilisticDecrement(htl);
while (htl > 0) {
for (; htl > 0; htl = probabilisticDecrement(htl)) {
PeerNode candidate;
//Can't return a probe request if not connected to anyone.
if (degree == 0) {
Expand All @@ -285,7 +285,6 @@ public void request(final Message message, final PeerNode source, final AsyncMes
} catch (IndexOutOfBoundsException e) {
if (logDEBUG) Logger.debug(MHProbe.class, "Peer count changed during candidate search.", e);
degree = degree();
htl = probabilisticDecrement(htl);
continue;
}
//acceptProbability is the MH correction.
Expand All @@ -310,17 +309,15 @@ public void request(final Message message, final PeerNode source, final AsyncMes
node.usm.addAsyncFilter(filter, callback, this);
if (logDEBUG) Logger.debug(MHProbe.class, "Sending.");
candidate.sendAsync(message, null, this);
return;
} catch (NotConnectedException e) {
if (logDEBUG) Logger.debug(MHProbe.class, "Peer became disconnected between check and send attempt.", e);
continue;
} catch (DisconnectedException e) {
//TODO: This is confusing - it's async yet it would throw an exception while waiting?
if (logDEBUG) Logger.debug(MHProbe.class, "Peer became disconnected while waiting for a response.", e);
//TODO: Is it reasonable to re-send in this case?
//continue;
callback.onDisconnect(candidate);
}
return;
}
}
}
Expand Down

0 comments on commit cc7dc83

Please sign in to comment.