propagate from branch 'i2p.i2p' (head 6fddab77462a92759305edee8fe5a944d6865375)

to branch 'i2p.i2p.zzz.test' (head 45a25185236e38606e761060427ee8fa60144a8c)
This commit is contained in:
zzz
2009-06-17 12:40:33 +00:00
27 changed files with 350 additions and 196 deletions

View File

@ -36,6 +36,7 @@ public abstract class CommSystemFacade implements Service {
public int countActiveSendPeers() { return 0; }
public boolean haveInboundCapacity() { return true; }
public boolean haveOutboundCapacity() { return true; }
public boolean haveHighOutboundCapacity() { return true; }
public List getMostRecentErrorMessages() { return Collections.EMPTY_LIST; }
/**

View File

@ -101,7 +101,7 @@ class RouterThrottleImpl implements RouterThrottle {
// reject here if lag too high???
RateStat rs = _context.statManager().getRate("transport.sendProcessingTime");
Rate r = null;
Rate r = rs.getRate(60*1000);
//Reject tunnels if the time to process messages and send them is too large. Too much time implies congestion.
if(r != null) {

View File

@ -18,9 +18,9 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 12;
public final static long BUILD = 2;
/** for example "-test" */
public final static String EXTRA = "-rc";
public final static String EXTRA = "";
public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;
public static void main(String args[]) {
System.out.println("I2P Router version: " + FULL_VERSION);

View File

@ -116,7 +116,14 @@ class PeerManager {
case PeerSelectionCriteria.PURPOSE_TEST:
// for now, the peers we test will be the reliable ones
//_organizer.selectWellIntegratedPeers(criteria.getMinimumRequired(), exclude, curVals);
_organizer.selectNotFailingPeers(criteria.getMinimumRequired(), exclude, peers);
// The PeerTestJob does only run every 5 minutes, but
// this was helping drive us to connection limits, let's leave the exploration
// to the ExploratoryPeerSelector, which will restrict to connected peers
// when we get close to the limit. So let's stick with connected peers here.
// Todo: what's the point of the PeerTestJob anyway?
//_organizer.selectNotFailingPeers(criteria.getMinimumRequired(), exclude, peers);
_organizer.selectActiveNotFailingPeers(criteria.getMinimumRequired(), exclude, peers);
break;
case PeerSelectionCriteria.PURPOSE_TUNNEL:
// pull all of the fast ones, regardless of how many we

View File

@ -316,8 +316,8 @@ public class ProfileOrganizer {
} finally { releaseReadLock(); }
if (matches.size() < howMany) {
if (_log.shouldLog(Log.INFO))
_log.info("selectHighCap("+howMany+"), not enough fast (" + matches.size() + ") going on to notFailing");
selectNotFailingPeers(howMany, exclude, matches, mask);
_log.info("selectHighCap("+howMany+"), not enough highcap (" + matches.size() + ") going on to ANFP2");
selectActiveNotFailingPeers2(howMany, exclude, matches, mask);
} else {
if (_log.shouldLog(Log.INFO))
_log.info("selectHighCap("+howMany+"), found enough highCap (" + matches.size() + ")");
@ -375,6 +375,7 @@ public class ProfileOrganizer {
selectAllNotFailingPeers(howMany, exclude, matches, onlyNotFailing, mask);
return;
}
/**
* Return a set of Hashes for peers that are both not failing and we're actively
* talking with.
@ -403,6 +404,39 @@ public class ProfileOrganizer {
}
}
/**
* Return a set of Hashes for peers that are both not failing and we're actively
* talking with.
*
* We use commSystem().isEstablished(), not profile.getIsActive(), as the
* NTCP idle time is now shorter than the 5 minute getIsActive() threshold,
* and we're using this to try and limit connections.
*
* This DOES cascade further to non-connected peers.
*/
private void selectActiveNotFailingPeers2(int howMany, Set exclude, Set matches, int mask) {
if (matches.size() < howMany) {
Map<Hash, PeerProfile> activePeers = new HashMap();
getReadLock();
try {
for (Iterator<Map.Entry<Hash, PeerProfile>> iter = _notFailingPeers.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry<Hash, PeerProfile> e = iter.next();
if (_context.commSystem().isEstablished(e.getKey()))
activePeers.put(e.getKey(), e.getValue());
}
locked_selectPeers(activePeers, howMany, exclude, matches, mask);
} finally { releaseReadLock(); }
}
if (matches.size() < howMany) {
if (_log.shouldLog(Log.INFO))
_log.info("selectANFP2("+howMany+"), not enough ANFP (" + matches.size() + ") going on to notFailing");
selectNotFailingPeers(howMany, exclude, matches, mask);
} else {
if (_log.shouldLog(Log.INFO))
_log.info("selectANFP2("+howMany+"), found enough ANFP (" + matches.size() + ")");
}
}
/**
* Return a set of Hashes for peers that are not failing.
*
@ -520,8 +554,8 @@ public class ProfileOrganizer {
}
}
}
if (_log.shouldLog(Log.INFO))
_log.info("Unreachable: " + l);
if (_log.shouldLog(Log.DEBUG))
_log.debug("Unreachable: " + l);
return l;
}

View File

@ -73,6 +73,8 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
public boolean haveInboundCapacity() { return (_manager == null ? false : _manager.haveInboundCapacity()); }
@Override
public boolean haveOutboundCapacity() { return (_manager == null ? false : _manager.haveOutboundCapacity()); }
@Override
public boolean haveHighOutboundCapacity() { return (_manager == null ? false : _manager.haveHighOutboundCapacity()); }
/**
* Framed average clock skew of connected peers in seconds, or null if we cannot answer.

View File

@ -47,6 +47,7 @@ public interface Transport {
public int countActivePeers();
public int countActiveSendPeers();
public boolean haveCapacity();
public boolean haveHighCapacity();
public Vector getClockSkews();
public List getMostRecentErrorMessages();

View File

@ -215,6 +215,20 @@ public class TransportManager implements TransportEventListener {
return false;
}
/**
* Are all transports well below their outbound connection limit
* Use for throttling in the router.
*/
public boolean haveHighOutboundCapacity() {
if (_transports.size() <= 0)
return false;
for (int i = 0; i < _transports.size(); i++) {
if (!((Transport)_transports.get(i)).haveHighCapacity())
return false;
}
return true;
}
/**
* Is at least one transport below its inbound connection limit + some margin
* Use for throttling in the router.

View File

@ -47,9 +47,11 @@ import org.freenetproject.ForwardPortStatus;
*
* some code has been borrowed from Limewire : @see com.limegroup.gnutella.UPnPManager
*
* @see http://www.upnp.org/
* @see http://en.wikipedia.org/wiki/Universal_Plug_and_Play
*
* @see "http://www.upnp.org/"
* @see "http://en.wikipedia.org/wiki/Universal_Plug_and_Play"
*/
/*
* TODO: Support multiple IGDs ?
* TODO: Advertise the node like the MDNS plugin does
* TODO: Implement EventListener and react on ip-change

View File

@ -42,7 +42,8 @@ public class NTCPSendFinisher {
}
public void stop() {
_executor.shutdownNow();
if (_executor != null)
_executor.shutdownNow();
}
public void add(OutNetMessage msg) {

View File

@ -326,6 +326,10 @@ public class NTCPTransport extends TransportImpl {
return countActivePeers() < getMaxConnections() * 4 / 5;
}
public boolean haveHighCapacity() {
return countActivePeers() < getMaxConnections() / 2;
}
/** queue up afterSend call, which can take some time w/ jobs, etc */
void sendComplete(OutNetMessage msg) { _finisher.add(msg); }

View File

@ -386,8 +386,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
* Todo:
* - Much better tracking of troublemakers
* - Disable if we have good local address or UPnP
*
* @param ip publicly routable IPv4 only
*
* @param from Hash of inbound destination
* @param ourIP publicly routable IPv4 only
* @param ourPort >= 1024
*/
void externalAddressReceived(Hash from, byte ourIP[], int ourPort) {
@ -1381,6 +1382,12 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
}
}
public boolean haveHighCapacity() {
synchronized (_peersByIdent) {
return _peersByIdent.size() < getMaxConnections() / 2;
}
}
/**
* Return our peer clock skews on this transport.
* Vector composed of Long, each element representing a peer skew in seconds.

View File

@ -47,7 +47,7 @@ class ExploratoryPeerSelector extends TunnelPeerSelector {
//
if (exploreHighCap)
ctx.profileOrganizer().selectHighCapacityPeers(length, exclude, matches);
else if (ctx.commSystem().haveOutboundCapacity())
else if (ctx.commSystem().haveHighOutboundCapacity())
ctx.profileOrganizer().selectNotFailingPeers(length, exclude, matches, false);
else // use only connected peers so we don't make more connections
ctx.profileOrganizer().selectActiveNotFailingPeers(length, exclude, matches);

View File

@ -815,7 +815,7 @@ public interface XmlPullParser {
* <a href="http://www.w3.org/TR/REC-xml-names/#ns-using">Namespaces in XML</a>
* specification to "http://www.w3.org/XML/1998/namespace".
*
* @param zero based index of attribute
* @param index zero based index of attribute
* @return attribute namespace,
* empty string ("") is returned if namesapces processing is not enabled or
* namespaces processing is enabled but attribute has no namespace (it has no prefix).
@ -828,7 +828,7 @@ public interface XmlPullParser {
* Throws an IndexOutOfBoundsException if the index is out of range
* or current event type is not START_TAG.
*
* @param zero based index of attribute
* @param index zero based index of attribute
* @return attribute name (null is never returned)
*/
String getAttributeName (int index);
@ -840,7 +840,7 @@ public interface XmlPullParser {
* Throws an IndexOutOfBoundsException if the index is out of range
* or current event type is not START_TAG.
*
* @param zero based index of attribute
* @param index zero based index of attribute
* @return attribute prefix or null if namespaces processing is not enabled.
*/
String getAttributePrefix(int index);
@ -849,7 +849,7 @@ public interface XmlPullParser {
* Returns the type of the specified attribute
* If parser is non-validating it MUST return CDATA.
*
* @param zero based index of attribute
* @param index zero based index of attribute
* @return attribute type (null is never returned)
*/
String getAttributeType(int index);
@ -859,7 +859,7 @@ public interface XmlPullParser {
* If parser is non-validating it MUST always return false.
* This information is part of XML infoset:
*
* @param zero based index of attribute
* @param index zero based index of attribute
* @return false if attribute was in input
*/
boolean isAttributeDefault(int index);
@ -876,7 +876,7 @@ public interface XmlPullParser {
*
* @see #defineEntityReplacementText
*
* @param zero based index of attribute
* @param index zero based index of attribute
* @return value of attribute (null is never returned)
*/
String getAttributeValue(int index);