SSU: now() call reduction

This commit is contained in:
zzz
2022-12-12 05:53:40 -05:00
parent 803265660e
commit 3472871e35
5 changed files with 46 additions and 23 deletions

View File

@@ -1271,7 +1271,7 @@ class EstablishmentManager {
_transport.addRemotePeerState(peer);
_transport.setIP(remote.calculateHash(), state.getSentIP());
_context.statManager().addRateData("udp.outboundEstablishTime", state.getLifetime());
_context.statManager().addRateData("udp.outboundEstablishTime", state.getLifetime(now));
DatabaseStoreMessage dbsm = null;
if (version == 1) {
// version 2 sends our RI in handshake
@@ -2295,9 +2295,9 @@ class EstablishmentManager {
//if (_log.shouldLog(Log.DEBUG))
// _log.debug("Removing completely confirmed inbound state");
break;
} else if (cur.getLifetime() > MAX_IB_ESTABLISH_TIME ||
} else if (cur.getLifetime(now) > MAX_IB_ESTABLISH_TIME ||
(istate == IB_STATE_RETRY_SENT && // limit time to get sess. req after retry
cur.getLifetime() >= 5 * InboundEstablishState.RETRANSMIT_DELAY)) {
cur.getLifetime(now) >= 5 * InboundEstablishState.RETRANSMIT_DELAY)) {
// took too long
iter.remove();
inboundState = cur;
@@ -2427,7 +2427,7 @@ class EstablishmentManager {
iter.remove();
outboundState = cur;
break;
} else if (cur.getLifetime() >= MAX_OB_ESTABLISH_TIME) {
} else if (cur.getLifetime(now) >= MAX_OB_ESTABLISH_TIME) {
// took too long
iter.remove();
outboundState = cur;
@@ -2466,7 +2466,7 @@ class EstablishmentManager {
//if (_log.shouldLog(Log.DEBUG))
// _log.debug("Processing for outbound: " + outboundState);
synchronized (outboundState) {
boolean expired = outboundState.getLifetime() >= MAX_OB_ESTABLISH_TIME;
boolean expired = outboundState.getLifetime(now) >= MAX_OB_ESTABLISH_TIME;
switch (outboundState.getState()) {
case OB_STATE_UNKNOWN: // fall thru
case OB_STATE_INTRODUCED:
@@ -3168,7 +3168,7 @@ class EstablishmentManager {
private void doFailsafe(long now) {
for (Iterator<OutboundEstablishState> iter = _liveIntroductions.values().iterator(); iter.hasNext(); ) {
OutboundEstablishState state = iter.next();
if (state.getLifetime() > 3*MAX_OB_ESTABLISH_TIME) {
if (state.getLifetime(now) > 3*MAX_OB_ESTABLISH_TIME) {
iter.remove();
if (_log.shouldLog(Log.WARN))
_log.warn("Failsafe remove LI " + state);
@@ -3176,7 +3176,7 @@ class EstablishmentManager {
}
for (Iterator<OutboundEstablishState> iter = _outboundByClaimedAddress.values().iterator(); iter.hasNext(); ) {
OutboundEstablishState state = iter.next();
if (state.getLifetime() > 3*MAX_OB_ESTABLISH_TIME) {
if (state.getLifetime(now) > 3*MAX_OB_ESTABLISH_TIME) {
iter.remove();
if (_log.shouldLog(Log.WARN))
_log.warn("Failsafe remove OBBCA " + state);
@@ -3184,7 +3184,7 @@ class EstablishmentManager {
}
for (Iterator<OutboundEstablishState> iter = _outboundByHash.values().iterator(); iter.hasNext(); ) {
OutboundEstablishState state = iter.next();
if (state.getLifetime() > 3*MAX_OB_ESTABLISH_TIME) {
if (state.getLifetime(now) > 3*MAX_OB_ESTABLISH_TIME) {
iter.remove();
if (_log.shouldLog(Log.WARN))
_log.warn("Failsafe remove OBBH " + state);

View File

@@ -332,8 +332,17 @@ class InboundEstablishState {
_currentState = InboundState.IB_STATE_CREATED_SENT;
}
/** how long have we been trying to establish this session? */
public long getLifetime() { return _context.clock().now() - _establishBegin; }
/**
* how long have we been trying to establish this session?
*/
public long getLifetime() { return getLifetime(_context.clock().now()); }
/**
* how long have we been trying to establish this session?
* @since 0.9.57
*/
public long getLifetime(long now) { return now - _establishBegin; }
public long getEstablishBeginTime() { return _establishBegin; }
/**

View File

@@ -727,9 +727,18 @@ class OutboundEstablishState {
_nextSend = now;
return true;
}
/** how long have we been trying to establish this session? */
public long getLifetime() { return _context.clock().now() - _establishBegin; }
/**
* how long have we been trying to establish this session?
*/
public long getLifetime() { return getLifetime(_context.clock().now()); }
/**
* how long have we been trying to establish this session?
* @since 0.9.57
*/
public long getLifetime(long now) { return now - _establishBegin; }
public long getEstablishBeginTime() { return _establishBegin; }
/**

View File

@@ -433,11 +433,13 @@ class OutboundMessageFragments {
(peer.isIPv6() ? PacketBuilder2.MIN_IPV6_DATA_PACKET_OVERHEAD : PacketBuilder2.MIN_DATA_PACKET_OVERHEAD);
peer.messageRetransmitted(queued, maxPktSz);
// _packetsRetransmitted += toSend; // lifetime for the transport
_context.statManager().addRateData("udp.peerPacketsRetransmitted", peer.getPacketsRetransmitted(), peer.getPacketsTransmitted());
_context.statManager().addRateData("udp.packetsRetransmitted", state.getLifetime(), peer.getPacketsTransmitted());
long lifetime = state.getLifetime();
int transmitted = peer.getPacketsTransmitted();
_context.statManager().addRateData("udp.peerPacketsRetransmitted", peer.getPacketsRetransmitted(), transmitted);
_context.statManager().addRateData("udp.packetsRetransmitted", lifetime, transmitted);
if (_log.shouldLog(Log.INFO))
_log.info("Retransmitting " + state + " to " + peer);
_context.statManager().addRateData("udp.sendVolleyTime", state.getLifetime(), queued);
_context.statManager().addRateData("udp.sendVolleyTime", lifetime, queued);
}
}

View File

@@ -448,16 +448,17 @@ class PacketHandler {
if (_log.shouldLog(Log.WARN))
_log.warn("Cannot validate rcvd pkt (path) wasCached? " + alreadyFailed + ": " + packet);
_context.statManager().addRateData("udp.droppedInvalidEstablish", packet.getLifetime());
long lifetime = packet.getLifetime();
_context.statManager().addRateData("udp.droppedInvalidEstablish", lifetime);
switch (peerType) {
case INBOUND_FALLBACK:
_context.statManager().addRateData("udp.droppedInvalidEstablish.inbound", packet.getLifetime(), packet.getTimeSinceReceived());
_context.statManager().addRateData("udp.droppedInvalidEstablish.inbound", lifetime, packet.getTimeSinceReceived());
break;
case OUTBOUND_FALLBACK:
_context.statManager().addRateData("udp.droppedInvalidEstablish.outbound", packet.getLifetime(), packet.getTimeSinceReceived());
_context.statManager().addRateData("udp.droppedInvalidEstablish.outbound", lifetime, packet.getTimeSinceReceived());
break;
case NEW_PEER:
_context.statManager().addRateData("udp.droppedInvalidEstablish.new", packet.getLifetime(), packet.getTimeSinceReceived());
_context.statManager().addRateData("udp.droppedInvalidEstablish.new", lifetime, packet.getTimeSinceReceived());
break;
}
return;
@@ -903,7 +904,7 @@ class PacketHandler {
header.getType() != SSU2Util.TOKEN_REQUEST_FLAG_BYTE ||
header.getVersion() != 2 ||
header.getNetID() != _networkID) {
// i2pd short session request? TODO
// i2pd short 87 byte session request thru 0.9.56
if (_log.shouldWarn())
_log.warn("Failed decrypt Session/Token Request after Retry: " + header +
" len " + packet.getPacket().getLength() + " on " + state);
@@ -928,9 +929,11 @@ class PacketHandler {
// Session Confirmed or retransmitted Session Request or Token Request
header = SSU2Header.trialDecryptShortHeader(packet, k1, k2);
if (header == null) {
// too short
// too short, perhaps SSU 1/2 confusion?
// Java 0.9.55 short destroy bug?
if (_log.shouldWarn())
_log.warn("Failed decrypt Session Confirmed on " + state);
_log.warn("Session Confirmed too short len: " +
+ packet.getPacket().getLength() + " on " + state);
return false;
}
if (header.getDestConnID() != state.getRcvConnID()) {