2005-08-31 jrandom

* Don't publish leaseSets to the netDb if they will never be looked for -
      namely, if they are for destinations that only establish outbound
      streams.  I2PTunnel's 'client' and 'httpclient' proxies have been
      modified to tell the router that it doesn't need to publish their
      leaseSet (by setting the I2CP config option 'i2cp.dontPublishLeaseSet'
      to 'true').
    * Don't publish the top 10 peer rankings of each router in the netdb, as
      it isn't being watched right now.
This commit is contained in:
jrandom
2005-09-01 00:20:16 +00:00
committed by zzz
parent 9bd87ab511
commit b43114f61b
15 changed files with 67 additions and 11 deletions

View File

@ -101,6 +101,10 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
this.l = l;
this.handlerName = handlerName + _clientId;
// no need to load the netDb with leaseSets for destinations that will never
// be looked up
tunnel.getClientOptions().setProperty("i2cp.dontPublishLeaseSet", "true");
while (sockMgr == null) {
synchronized (sockLock) {
if (ownDest) {

View File

@ -25,6 +25,7 @@ import net.i2p.data.i2cp.SessionConfig;
* @author jrandom
*/
public abstract class ClientManagerFacade implements Service {
public static final String PROP_CLIENT_ONLY = "i2cp.dontPublishLeaseSet";
/**
* Request that a particular client authorize the Leases contained in the
@ -71,6 +72,10 @@ public abstract class ClientManagerFacade implements Service {
public abstract void messageReceived(ClientMessage msg);
public boolean verifyClientLiveliness() { return true; }
/**
* Does the client specified want their leaseSet published?
*/
public boolean shouldPublishLeaseSet(Hash destinationHash) { return true; }
/**

View File

@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
*
*/
public class RouterVersion {
public final static String ID = "$Revision: 1.220 $ $Date: 2005/08/27 17:15:38 $";
public final static String ID = "$Revision: 1.221 $ $Date: 2005/08/29 20:59:13 $";
public final static String VERSION = "0.6.0.3";
public final static long BUILD = 4;
public final static long BUILD = 5;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION);
System.out.println("Router ID: " + RouterVersion.ID);

View File

@ -25,6 +25,7 @@ import net.i2p.data.TunnelId;
import net.i2p.data.i2cp.MessageId;
import net.i2p.data.i2cp.SessionConfig;
import net.i2p.router.ClientMessage;
import net.i2p.router.ClientManagerFacade;
import net.i2p.router.Job;
import net.i2p.router.JobImpl;
import net.i2p.router.RouterContext;
@ -269,6 +270,16 @@ public class ClientManager {
return false;
}
public boolean shouldPublishLeaseSet(Hash destHash) {
if (destHash == null) return true;
ClientConnectionRunner runner = getRunner(destHash);
if (runner == null) return true;
String dontPublish = runner.getConfig().getOptions().getProperty(ClientManagerFacade.PROP_CLIENT_ONLY);
if ( (dontPublish != null) && ("true".equals(dontPublish)) )
return false;
return true;
}
public Set listClients() {
Set rv = new HashSet();
synchronized (_runners) {

View File

@ -164,6 +164,8 @@ public class ClientManagerFacadeImpl extends ClientManagerFacade {
return false;
}
}
public boolean shouldPublishLeaseSet(Hash destinationHash) { return _manager.shouldPublishLeaseSet(destinationHash); }
public void messageDeliveryStatusUpdate(Destination fromDest, MessageId id, boolean delivered) {
if (_manager != null)

View File

@ -75,9 +75,11 @@ public class HandleDatabaseLookupMessageJob extends JobImpl {
LeaseSet ls = getContext().netDb().lookupLeaseSetLocally(_message.getSearchKey());
if (ls != null) {
boolean publish = getContext().clientManager().shouldPublishLeaseSet(_message.getSearchKey());
// only answer a request for a LeaseSet if it has been published
// to us, or, if its local, if we would have published to ourselves
if (answerAllQueries() || ls.getReceivedAsPublished()) {
if (publish && (answerAllQueries() || ls.getReceivedAsPublished())) {
getContext().statManager().addRateData("netDb.lookupsMatchedReceivedPublished", 1, 0);
sendData(_message.getSearchKey(), ls, fromKey, _message.getReplyTunnel());
} else {
@ -85,7 +87,7 @@ public class HandleDatabaseLookupMessageJob extends JobImpl {
CLOSENESS_THRESHOLD,
_message.getDontIncludePeers());
if (getContext().clientManager().isLocal(ls.getDestination())) {
if (weAreClosest(routerInfoSet)) {
if (publish && weAreClosest(routerInfoSet)) {
getContext().statManager().addRateData("netDb.lookupsMatchedLocalClosest", 1, 0);
sendData(_message.getSearchKey(), ls, fromKey, _message.getReplyTunnel());
} else {

View File

@ -54,6 +54,8 @@ class DataPublisherJob extends JobImpl {
_log.warn("Not publishing a lease that isn't current - " + key,
new Exception("Publish expired lease?"));
}
if (!getContext().clientManager().shouldPublishLeaseSet(key))
continue;
}
_facade.sendStore(key, data, null, null, STORE_TIMEOUT, null);
//StoreJob store = new StoreJob(getContext(), _facade, key, data, null, null, STORE_TIMEOUT);

View File

@ -135,6 +135,8 @@ class DataRepublishingSelectorJob extends JobImpl {
} else {
LeaseSet ls = _facade.lookupLeaseSetLocally(key);
if (ls != null) {
if (!getContext().clientManager().shouldPublishLeaseSet(ls.getDestination().calculateHash()))
return -3;
if (ls.isCurrent(Router.CLOCK_FUDGE_FACTOR)) {
// last time it was sent was before the last send period
return KBucketSet.NUM_BUCKETS - bucket;

View File

@ -20,4 +20,6 @@ public interface DataStore {
public DataStructure remove(Hash key);
public Set getKeys();
public void restart();
public int countLeaseSets();
}

View File

@ -382,10 +382,8 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
}
public int getKnownLeaseSets() {
if (_kb == null) return 0;
CountLeaseSets count = new CountLeaseSets();
_kb.getAll(count);
return count.size();
if (_ds == null) return 0;
return _ds.countLeaseSets();
}
private class CountLeaseSets implements SelectionCollector {
@ -476,6 +474,9 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
_log.error("wtf, locally published leaseSet is not valid?", iae);
return;
}
if (!_context.clientManager().shouldPublishLeaseSet(h))
return;
synchronized (_explicitSendKeys) {
_explicitSendKeys.add(h);
}

View File

@ -59,6 +59,22 @@ class PersistentDataStore extends TransientDataStore {
_context.jobQueue().addJob(new WriteJob(key, data));
}
public int countLeaseSets() {
File dbDir = null;
try {
dbDir = getDbDir();
} catch (IOException ioe) {
return 0;
}
if (dbDir == null)
return 0;
File leaseSetFiles[] = dbDir.listFiles(LeaseSetFilter.getInstance());
if (leaseSetFiles == null)
return 0;
else
return leaseSetFiles.length;
}
private void accept(LeaseSet ls) {
super.put(ls.getDestination().calculateHash(), ls);
}

View File

@ -37,6 +37,9 @@ public class RepublishLeaseSetJob extends JobImpl {
}
public String getName() { return "Republish a local leaseSet"; }
public void runJob() {
if (!getContext().clientManager().shouldPublishLeaseSet(_dest))
return;
try {
if (getContext().clientManager().isLocal(_dest)) {
LeaseSet ls = _facade.lookupLeaseSetLocally(_dest);

View File

@ -59,6 +59,9 @@ class TransientDataStore implements DataStore {
return _data.containsKey(key);
}
}
public int countLeaseSets() { return 0; }
/** nothing published more than 5 minutes in the future */
private final static long MAX_FUTURE_PUBLISH_DATE = 5*60*1000;

View File

@ -30,7 +30,7 @@ public class PeerTestJob extends JobImpl {
private Log _log;
private PeerManager _manager;
private boolean _keepTesting;
private static final long DEFAULT_PEER_TEST_DELAY = 60*1000;
private static final long DEFAULT_PEER_TEST_DELAY = 5*60*1000;
private static final int TEST_PRIORITY = 100;
/** Creates a new instance of PeerTestJob */
@ -48,7 +48,7 @@ public class PeerTestJob extends JobImpl {
/** how long to give each peer before marking them as unresponsive? */
private int getTestTimeout() { return 30*1000; }
/** number of peers to test each round */
private int getTestConcurrency() { return 2; }
private int getTestConcurrency() { return 1; }
public void startTesting(PeerManager manager) {
_manager = manager;

View File

@ -743,8 +743,11 @@ public class ProfileOrganizer {
// the CLI shouldn't depend upon the netDb
if (netDb == null) return true;
if (_context.router() == null) return true;
if ( (_context.shitlist() != null) && (_context.shitlist().isShitlisted(peer)) )
if ( (_context.shitlist() != null) && (_context.shitlist().isShitlisted(peer)) ) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Peer " + peer.toBase64() + " is shitlisted, dont select it");
return false; // never select a shitlisted peer
}
if (null != netDb.lookupRouterInfoLocally(peer)) {
if (_log.shouldLog(Log.INFO))