forked from I2P_Developers/i2p.i2p
Transport:
- Implement mayDisconnect() for outbound connections also - Run UDP idle disconnect loop faster if floodfill or near connection limit NetDB: - Call mayDisconnect() after direct netdb store - Fix check to publish RI faster, broken in .24, we were publishing at every check, causing increased load on floodfills
This commit is contained in:
@@ -86,7 +86,8 @@ public class PublishLocalRouterInfoJob extends JobImpl {
|
||||
// 3 times out of 4, we don't republish if everything is the same...
|
||||
// If something changed, including the cost, then publish,
|
||||
// otherwise don't.
|
||||
boolean different = !oldRI.getCapabilities().equals(ri.getCapabilities());
|
||||
String newcaps = getContext().router().getCapabilities();
|
||||
boolean different = !oldRI.getCapabilities().equals(newcaps);
|
||||
if (!different) {
|
||||
Comparator<RouterAddress> comp = new AddrComparator();
|
||||
Collections.sort(oldAddrs, comp);
|
||||
@@ -107,7 +108,7 @@ public class PublishLocalRouterInfoJob extends JobImpl {
|
||||
}
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Republishing early because addresses or costs or caps have changed -" +
|
||||
" oldCaps: " + oldRI.getCapabilities() + " newCaps: " + ri.getCapabilities() +
|
||||
" oldCaps: " + oldRI.getCapabilities() + " newCaps: " + newcaps +
|
||||
" old:\n" +
|
||||
oldAddrs + "\nnew:\n" + newAddrs);
|
||||
}
|
||||
|
@@ -562,9 +562,12 @@ class StoreJob extends JobImpl {
|
||||
private final TunnelInfo _sendThrough;
|
||||
private final int _msgSize;
|
||||
|
||||
/** direct */
|
||||
public SendSuccessJob(RouterContext enclosingContext, RouterInfo peer) {
|
||||
this(enclosingContext, peer, null, 0);
|
||||
}
|
||||
|
||||
/** through tunnel */
|
||||
public SendSuccessJob(RouterContext enclosingContext, RouterInfo peer, TunnelInfo sendThrough, int size) {
|
||||
super(enclosingContext);
|
||||
_peer = peer;
|
||||
@@ -597,6 +600,10 @@ class StoreJob extends JobImpl {
|
||||
getContext().profileManager().tunnelDataPushed(_sendThrough.getPeer(i), howLong, _msgSize);
|
||||
_sendThrough.incrementVerifiedBytesTransferred(_msgSize);
|
||||
}
|
||||
if (_sendThrough == null) {
|
||||
// advise comm system, to reduce lifetime of direct connections to floodfills
|
||||
getContext().commSystem().mayDisconnect(_peer.getHash());
|
||||
}
|
||||
|
||||
if (_state.getCompleteCount() >= getRedundancy()) {
|
||||
succeed();
|
||||
|
@@ -273,9 +273,12 @@ class EventPumper implements Runnable {
|
||||
}
|
||||
|
||||
final long expire;
|
||||
if (!haveCap && con.getMayDisconnect() &&
|
||||
if ((!haveCap || !con.isInbound()) &&
|
||||
con.getMayDisconnect() &&
|
||||
con.getMessagesReceived() <= 2 && con.getMessagesSent() <= 1) {
|
||||
expire = MAY_DISCON_TIMEOUT;
|
||||
if (_log.shouldInfo())
|
||||
_log.info("Possible early disconnect for " + con);
|
||||
} else {
|
||||
expire = _expireIdleWriteTime;
|
||||
}
|
||||
|
@@ -495,7 +495,7 @@ public class NTCPTransport extends TransportImpl {
|
||||
@Override
|
||||
public void mayDisconnect(final Hash peer) {
|
||||
final NTCPConnection con = _conByIdent.get(peer);
|
||||
if (con != null && con.isEstablished() && con.isInbound() &&
|
||||
if (con != null && con.isEstablished() &&
|
||||
con.getMessagesReceived() <= 2 && con.getMessagesSent() <= 1) {
|
||||
con.setMayDisconnect();
|
||||
}
|
||||
|
@@ -773,7 +773,10 @@ class PeerState {
|
||||
return _remoteIP.length == 16;
|
||||
}
|
||||
|
||||
/** the last time we used them as an introducer, or 0 */
|
||||
public long getIntroducerTime() { return _lastIntroducerTime; }
|
||||
|
||||
/** set the last time we used them as an introducer to now */
|
||||
public void setIntroducerTime() { _lastIntroducerTime = _context.clock().now(); }
|
||||
|
||||
/**
|
||||
|
@@ -2504,8 +2504,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
@Override
|
||||
public void mayDisconnect(final Hash peer) {
|
||||
final PeerState ps = _peersByIdent.get(peer);
|
||||
if (ps != null && ps.isInbound() &&
|
||||
if (ps != null &&
|
||||
ps.getWeRelayToThemAs() <= 0 &&
|
||||
(ps.getTheyRelayToUsAs() <= 0 || ps.getIntroducerTime() < _context.clock().now() - 2*60*60*1000) &&
|
||||
ps.getMessagesReceived() <= 2 && ps.getMessagesSent() <= 2) {
|
||||
ps.setMayDisconnect();
|
||||
}
|
||||
@@ -2935,7 +2936,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
boolean shouldPingFirewall = _reachabilityStatus != Status.OK;
|
||||
int currentListenPort = getListenPort(false);
|
||||
boolean pingOneOnly = shouldPingFirewall && getExternalPort(false) == currentListenPort;
|
||||
boolean shortLoop = shouldPingFirewall;
|
||||
boolean shortLoop = shouldPingFirewall || !haveCap || _context.netDb().floodfillEnabled();
|
||||
_lastLoopShort = shortLoop;
|
||||
_expireBuffer.clear();
|
||||
_runCount++;
|
||||
@@ -2946,8 +2947,11 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
// if we offered to introduce them, or we used them as introducer in last 2 hours
|
||||
if (peer.getWeRelayToThemAs() > 0 || peer.getIntroducerTime() > pingCutoff) {
|
||||
inactivityCutoff = longInactivityCutoff;
|
||||
} else if (!haveCap && peer.getMayDisconnect() &&
|
||||
} else if ((!haveCap || !peer.isInbound()) &&
|
||||
peer.getMayDisconnect() &&
|
||||
peer.getMessagesReceived() <= 2 && peer.getMessagesSent() <= 2) {
|
||||
if (_log.shouldInfo())
|
||||
_log.info("Possible early disconnect for: " + peer);
|
||||
inactivityCutoff = mayDisconCutoff;
|
||||
} else {
|
||||
inactivityCutoff = shortInactivityCutoff;
|
||||
|
Reference in New Issue
Block a user