SSU: More consolidation of clock().now() calls

This commit is contained in:
zzz
2019-01-12 13:45:38 +00:00
parent f5ca17c844
commit 10f2d838c9
3 changed files with 12 additions and 4 deletions

View File

@@ -286,9 +286,10 @@ class OutboundMessageFragments {
// if there is nothing left to send.
// Otherwise, return the volley to be sent.
// Otherwise, wait()
long now = _context.clock().now();
while (_iterator.hasNext()) {
peer = _iterator.next();
int remaining = peer.finishMessages();
int remaining = peer.finishMessages(now);
if (remaining <= 0) {
// race with add()
_iterator.remove();

View File

@@ -116,6 +116,13 @@ class OutboundMessageState implements CDPQEntry {
return _expiration < _context.clock().now();
}
/**
* @since 0.9.38
*/
public boolean isExpired(long now) {
return _expiration < now;
}
public synchronized boolean isComplete() {
return _fragmentAcks == 0;
}

View File

@@ -1560,7 +1560,7 @@ public class PeerState {
*
* @return number of active outbound messages remaining
*/
public int finishMessages() {
public int finishMessages(long now) {
// short circuit, unsynchronized
if (_outboundMessages.isEmpty())
return _outboundQueue.size();
@@ -1582,7 +1582,7 @@ public class PeerState {
_retransmitter = null;
if (succeeded == null) succeeded = new ArrayList<OutboundMessageState>(4);
succeeded.add(state);
} else if (state.isExpired()) {
} else if (state.isExpired(now)) {
iter.remove();
if (_retransmitter == state)
_retransmitter = null;
@@ -1789,7 +1789,7 @@ public class PeerState {
long now = _context.clock().now();
if (state.getNextSendTime() <= now) {
OutboundMessageState retrans = _retransmitter;
if ( (retrans != null) && ( (retrans.isExpired() || retrans.isComplete()) ) ) {
if ( (retrans != null) && ( (retrans.isExpired(now) || retrans.isComplete()) ) ) {
_retransmitter = null;
retrans = null;
}