Compare commits

...

5 Commits

8 changed files with 120 additions and 39 deletions

View File

@ -752,12 +752,12 @@ class NetDbRenderer {
// remote lookup
LookupWaiter lw = new LookupWaiter();
// use-case for the exploratory netDb here?
_context.exploratoryNetDb().lookupLeaseSetRemotely(hash, lw, lw, 8*1000, null);
_context.mainNetDb().lookupLeaseSetRemotely(hash, lw, lw, 8*1000, null);
// just wait right here in the middle of the rendering, sure
synchronized(lw) {
try { lw.wait(9*1000); } catch (InterruptedException ie) {}
}
ls = _context.exploratoryNetDb().lookupLeaseSetLocally(hash);
ls = _context.mainNetDb().lookupLeaseSetLocally(hash);
}
if (ls != null) {
BigInteger dist = HashDistance.getDistance(_context.routerHash(), ls.getRoutingKey());

View File

@ -375,7 +375,6 @@ public class RouterContext extends I2PAppContext {
public SegmentedNetworkDatabaseFacade netDbSegmentor() { return _netDb; }
public FloodfillNetworkDatabaseFacade netDb() { return _netDb.mainNetDB(); }
public FloodfillNetworkDatabaseFacade mainNetDb() { return _netDb.mainNetDB(); }
public FloodfillNetworkDatabaseFacade exploratoryNetDb() { return _netDb.exploratoryNetDB(); }
public FloodfillNetworkDatabaseFacade clientNetDb(String id) { return _netDb.clientNetDB(id); }
public FloodfillNetworkDatabaseFacade clientNetDb(Hash id) { return _netDb.clientNetDB(id); }
/**

View File

@ -219,11 +219,11 @@ class ClientConnectionRunner {
for (SessionParams sp : _sessions.values()) {
LeaseSet ls = sp.currentLeaseSet;
if (ls != null)
_context.netDbSegmentor().getSubNetDB(dbid).unpublish(ls);
_context.clientNetDb(dbid).unpublish(ls);
// unpublish encrypted LS also
ls = sp.currentEncryptedLeaseSet;
if (ls != null)
_context.netDbSegmentor().getSubNetDB(dbid).unpublish(ls);
_context.clientNetDb(dbid).unpublish(ls);
if (!sp.isPrimary)
_context.tunnelManager().removeAlias(sp.dest);
}
@ -460,11 +460,11 @@ class ClientConnectionRunner {
_manager.unregisterSession(id, sp.dest);
LeaseSet ls = sp.currentLeaseSet;
if (ls != null)
_context.netDbSegmentor().getSubNetDB(dbid).unpublish(ls);
_context.clientNetDb(dbid).unpublish(ls);
// unpublish encrypted LS also
ls = sp.currentEncryptedLeaseSet;
if (ls != null)
_context.netDbSegmentor().getSubNetDB(dbid).unpublish(ls);
_context.clientNetDb(dbid).unpublish(ls);
isPrimary = sp.isPrimary;
if (isPrimary)
_context.tunnelManager().removeTunnels(sp.dest);
@ -485,11 +485,11 @@ class ClientConnectionRunner {
_manager.unregisterSession(sp.sessionId, sp.dest);
LeaseSet ls = sp.currentLeaseSet;
if (ls != null)
_context.netDbSegmentor().getSubNetDB(dbid).unpublish(ls);
_context.clientNetDb(dbid).unpublish(ls);
// unpublish encrypted LS also
ls = sp.currentEncryptedLeaseSet;
if (ls != null)
_context.netDbSegmentor().getSubNetDB(dbid).unpublish(ls);
_context.clientNetDb(dbid).unpublish(ls);
_context.tunnelManager().removeAlias(sp.dest);
synchronized(this) {
if (sp.rerequestTimer != null)

View File

@ -717,7 +717,7 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
EncryptedLeaseSet encls = (EncryptedLeaseSet) ls;
if (_log.shouldDebug())
_log.debug("Storing decrypted: " + encls.getDecryptedLeaseSet());
_context.netDbSegmentor().getSubNetDB(dest.getHash()).store(dest.getHash(), encls.getDecryptedLeaseSet());
_context.clientNetDb(dest.getHash()).store(dest.getHash(), encls.getDecryptedLeaseSet());
}
} catch (IllegalArgumentException iae) {
if (_log.shouldLog(Log.ERROR))

View File

@ -123,11 +123,6 @@ public class DummyNetworkDatabaseFacade extends SegmentedNetworkDatabaseFacade {
return _fndb;
}
@Override
public FloodfillNetworkDatabaseFacade exploratoryNetDB() {
return _fndb;
}
@Override
public String getDbidByHash(Hash clientKey) {
throw new UnsupportedOperationException("Unimplemented method 'lookupLeaseSetHashIsClient'");

View File

@ -94,7 +94,7 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
* @return the FloodfillNetworkDatabaseFacade object corresponding to the ID
*/
@Override
public FloodfillNetworkDatabaseFacade getSubNetDB(Hash id) {
protected FloodfillNetworkDatabaseFacade getSubNetDB(Hash id) {
if (id == null)
return getSubNetDB(MAIN_DBID);
return getSubNetDB(id.toBase32());
@ -114,7 +114,7 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
if (id.equals(MULTIHOME_DBID))
return multiHomeNetDB();
if (id.equals(EXPLORATORY_DBID))
return exploratoryNetDB();
return clientNetDB();
if (id.endsWith(".i2p")) {
if (!id.startsWith("clients_"))
@ -139,6 +139,8 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
*
*/
public synchronized void shutdown() {
_mainDbid.shutdown();
_multihomeDbid.shutdown();
// shut down every entry in _subDBs
for (FloodfillNetworkDatabaseFacade subdb : getSubNetDBs()) {
if (_log.shouldLog(Log.DEBUG))
@ -335,7 +337,9 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
}
/**
* get the client netDb for the given id
* get the client netDb for the given id.
* Will return the "exploratory(default client)" netDb if
* the dbid is null.
*
* @since 0.9.60
*
@ -343,12 +347,14 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
@Override
public FloodfillNetworkDatabaseFacade clientNetDB(String id) {
if (id == null || id.isEmpty())
return exploratoryNetDB();
return clientNetDB();
return this.getSubNetDB(id);
}
/**
* get the client netDb for the given id
* Will return the "exploratory(default client)" netDb if
* the dbid is null.
*
* @since 0.9.60
*
@ -357,27 +363,16 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
public FloodfillNetworkDatabaseFacade clientNetDB(Hash id) {
if (id != null)
return getSubNetDB(id.toBase32());
return exploratoryNetDB();
return clientNetDB();
}
/**
* get the default client netDb
* get the default client(exploratory) netDb
*
* @since 0.9.60
*
*/
public FloodfillNetworkDatabaseFacade clientNetDB() {
return exploratoryNetDB();
}
/**
* get the default client netDb
*
* @since 0.9.60
*
*/
@Override
public FloodfillNetworkDatabaseFacade exploratoryNetDB() {
return _exploratoryDbid;
}
@ -441,7 +436,7 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
Set<FloodfillNetworkDatabaseFacade> rv = new HashSet<>();
rv.add(mainNetDB());
rv.add(multiHomeNetDB());
rv.add(exploratoryNetDB());
rv.add(clientNetDB());
rv.addAll(_subDBs.values());
return rv;
}

View File

@ -60,25 +60,103 @@ public abstract class SegmentedNetworkDatabaseFacade {
// super(context, null);
}
/**
* Get a sub-netDb using a string identifier
*
* @since 0.9.60
*/
protected abstract FloodfillNetworkDatabaseFacade getSubNetDB(String dbid);
public abstract FloodfillNetworkDatabaseFacade getSubNetDB(Hash dbid);
/**
* Get a sub-netDb using a Hash identifier
*
* @since 0.9.60
*/
protected abstract FloodfillNetworkDatabaseFacade getSubNetDB(Hash dbid);
/**
* Get the main netDb, the one which is used if we're a floodfill
*
* @since 0.9.60
*/
public abstract FloodfillNetworkDatabaseFacade mainNetDB();
/**
* Get the multihome netDb, the one which is used if we're a floodfill AND we
* have a multihome address sent to us
*
* @since 0.9.60
*/
public abstract FloodfillNetworkDatabaseFacade multiHomeNetDB();
/**
* Get a client netDb for a given client string identifier. Will never
* return the mainNetDB.
*
* @since 0.9.60
*/
public abstract FloodfillNetworkDatabaseFacade clientNetDB(String dbid);
/**
* Get a client netDb for a given client Hash identifier. Will never
* return the mainNetDB.
*
* @since 0.9.60
*/
public abstract FloodfillNetworkDatabaseFacade clientNetDB(Hash dbid);
public abstract FloodfillNetworkDatabaseFacade exploratoryNetDB();
/**
* Shut down the network database and all subDbs.
*
* @since 0.9.60
*/
public abstract void shutdown();
/**
* Lookup the leaseSet for a given key in only client dbs.
*
* @since 0.9.60
*/
public abstract LeaseSet lookupLeaseSetHashIsClient(Hash key);
/**
* Lookup the leaseSet for a given key locally across all dbs if dbid is
* null, or locally for the given dbid if it is not null. Use carefully,
* this function crosses db boundaries and is intended only for local use.
*
* @since 0.9.60
*/
protected abstract LeaseSet lookupLeaseSetLocally(Hash key, String dbid);
/**
* Lookup the dbid for a given hash.
*
* @since 0.9.60
*/
public abstract String getDbidByHash(Hash clientKey);
/**
* Get a set of all sub-netDbs.
*
* @since 0.9.60
*/
public abstract Set<FloodfillNetworkDatabaseFacade> getSubNetDBs();
/**
* Get a set of all client dbid strings
*
* @since 0.9.60
*/
public abstract List<String> getClients();
/**
* Make sure the SNDF is initialized
*/
public boolean isInitialized() {
return mainNetDB().isInitialized();
}
/**
* Get a set of all routers
*
* @since 0.9.60
*/
public Set<RouterInfo> getRouters() {
return mainNetDB().getRouters();
}
/**
* Get a set of all routers known to clients, which should always be zero.
*
* @since 0.9.60
*/
public Set<RouterInfo> getRoutersKnownToClients() {
Set<RouterInfo> ris = new HashSet<>();
Set<FloodfillNetworkDatabaseFacade> fndfs = getSubNetDBs();
@ -87,6 +165,12 @@ public abstract class SegmentedNetworkDatabaseFacade {
}
return ris;
}
/**
* Get a set of all leases known to all clients.
*
* @since 0.9.60
*/
public Set<LeaseSet> getLeasesKnownToClients() {
Set<LeaseSet> lss = new HashSet<>();
Set<FloodfillNetworkDatabaseFacade> fndfs = getSubNetDBs();
@ -95,19 +179,27 @@ public abstract class SegmentedNetworkDatabaseFacade {
}
return lss;
}
/** @since 0.9.60 */
/**
* Check if the mainNetDB needs to reseed
*
* @since 0.9.60
* */
public ReseedChecker reseedChecker() {
return mainNetDB().reseedChecker();
};
/**
* For console ConfigKeyringHelper
*
* @return true if removed
* @since 0.9.60
*/
public List<String> lookupClientBySigningPublicKey(SigningPublicKey spk) {
return Collections.emptyList();
}
/**
* For console ConfigKeyringHelper
*
* @since 0.9.60
*/
public List<BlindData> getLocalClientsBlindData() {
return Collections.emptyList();
}

View File

@ -271,7 +271,7 @@ class InboundMessageDistributor implements GarlicMessageReceiver.CloveReceiver {
if (dsm.getEntry().isLeaseSet()) {
if (_log.shouldLog(Log.INFO))
_log.info("[client: " + _clientNickname + "] Saving LS DSM from client tunnel.");
FloodfillDatabaseStoreMessageHandler _FDSMH = new FloodfillDatabaseStoreMessageHandler(_context, _context.netDbSegmentor().getSubNetDB(_client));
FloodfillDatabaseStoreMessageHandler _FDSMH = new FloodfillDatabaseStoreMessageHandler(_context, _context.clientNetDb(_client));
Job j = _FDSMH.createJob(msg, null, null);
j.runJob();
if (sz > 0) {
@ -403,7 +403,7 @@ class InboundMessageDistributor implements GarlicMessageReceiver.CloveReceiver {
// ToDo: This should actually have a try and catch.
if (_log.shouldLog(Log.INFO))
_log.info("Store the LS in the correct dbid subDb: " + _client.toBase32());
FloodfillDatabaseStoreMessageHandler _FDSMH = new FloodfillDatabaseStoreMessageHandler(_context, _context.netDbSegmentor().getSubNetDB(_client));
FloodfillDatabaseStoreMessageHandler _FDSMH = new FloodfillDatabaseStoreMessageHandler(_context, _context.clientNetDb(_client));
Job j = _FDSMH.createJob(data, null, null);
j.runJob();
if (sz > 0) {