Compare commits

...

7 Commits

10 changed files with 9 additions and 350 deletions

View File

@ -134,16 +134,6 @@ public abstract class DatabaseEntry extends DataStructureImpl {
type == KEY_TYPE_META_LS2;
}
/**
* Convenience method, is the type any variant of router info?
*
* @return true for any type of RouterInfo, false for LeaseSet, false for others
* @since x.x.x
*/
public boolean isRouterInfo() {
return (getType() == KEY_TYPE_ROUTERINFO);
}
/**
* Returns the raw payload data, excluding the signature, to be signed by sign().
*

View File

@ -140,7 +140,7 @@ public class MultiRouter {
HashSet<RouterInfo> riSet = new HashSet<RouterInfo>();
for(Router r : _routers) {
riSet.addAll(r.getContext().netDbSegmentor().getRouters());
riSet.addAll(r.getContext().netDb().getRouters());
}
for(Router r : _routers) {
for(RouterInfo ri : riSet){

View File

@ -196,12 +196,6 @@ class LookupDestJob extends JobImpl {
}
}
private String toBase32(){
if (_fromLocalDest != null)
return _fromLocalDest.toBase32();
return null;
}
private class DoneJob extends JobImpl {
public DoneJob(RouterContext enclosingContext) {
super(enclosingContext);

View File

@ -90,11 +90,6 @@ public class DummyNetworkDatabaseFacade extends SegmentedNetworkDatabaseFacade {
public Set<Hash> getAllRouters() { return new HashSet<Hash>(_routers.keySet()); }
public Set<Hash> findNearestRouters(Hash key, int maxNumRouters, Set<Hash> peersToIgnore) { return getAllRouters(); }
@Override
public LeaseSet lookupLeaseSetHashIsClient(Hash key) {
throw new UnsupportedOperationException("Unimplemented method 'lookupLeaseSetHashIsClient'");
}
@Override
public FloodfillNetworkDatabaseFacade mainNetDB() {
return _fndb;
@ -104,9 +99,4 @@ public class DummyNetworkDatabaseFacade extends SegmentedNetworkDatabaseFacade {
public FloodfillNetworkDatabaseFacade clientNetDB(Hash id) {
return _fndb;
}
@Override
public Set<FloodfillNetworkDatabaseFacade> getSubNetDBs(){
throw new UnsupportedOperationException("Unimplemented method 'getSubNetDBs'");
}
}

View File

@ -290,11 +290,6 @@ public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacad
return true;
}
public int minFloodfillPeers() {
int mfp = _context.getProperty(MINIMUM_SUBDB_PEERS, 0);
return mfp;
}
/**
* Send to a subset of all floodfill peers.
* We do this to implement Kademlia within the floodfills, i.e.

View File

@ -56,7 +56,7 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
/**
* Construct a new FloodfillNetworkDatabaseSegmentor with the given
* RouterContext, containing a default, main netDb and a multihome netDb
* RouterContext, containing a default, main netDb
* and which is prepared to add client netDbs.
*
* @since 0.9.60
@ -87,8 +87,7 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
}
/**
* If we are floodfill, turn it off and tell everybody for the _mainDbid and the
* _multihomeDbid
* If we are floodfill, turn it off and tell everybody for the _mainDbid
*
* @since 0.9.60
*
@ -100,7 +99,7 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
}
/**
* Start up the floodfill for the _mainDbid and the _multihomeDbid
* Start up the _mainDbid
*
* @since 0.9.60
*
@ -111,130 +110,6 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
_mainDbid.startup();
}
/**
* list of the RouterInfo objects for all known peers;
*
* @since 0.9.60
* @return non-null
*/
public List<RouterInfo> getKnownRouterData() {
List<RouterInfo> rv = new ArrayList<RouterInfo>();
for (FloodfillNetworkDatabaseFacade subdb : getSubNetDBs()) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("getKnownRouterData Called from FNDS,"+subdb._dbid+", will be combined with all other subDbs");
rv.addAll(subdb.getKnownRouterData());
}
return rv;
}
/**
* list of the Hashes of currently known floodfill peers;
* Returned list will not include our own hash.
* List is not sorted and not shuffled.
*
* @since 0.9.60
* @return non-null
*/
public List<Hash> getFloodfillPeers() {
if (_log.shouldLog(Log.DEBUG))
_log.debug("getFloodfillPeers collecting all floodfill peers across all subDbs");
List<Hash> peers = new ArrayList<Hash>();
for (FloodfillNetworkDatabaseFacade subdb : getSubNetDBs()) {
peers.addAll(subdb.getFloodfillPeers());
}
return peers;
}
/**
* Lookup using the client's tunnels when the client LS key is know
* but the client dbid is not.
*
* @param key The LS key for client.
* @return may be null
* @since 0.9.60
*/
@Override
public LeaseSet lookupLeaseSetHashIsClient(Hash key) {
return lookupLeaseSetLocally(key, null);
}
/**
* Lookup using the client's tunnels when the client LS key is known.
* if a DBID is not provided, the clients will all be checked, and the
* first value will be used.
*
* @return may be null
* @since 0.9.60
*/
//@Override
protected LeaseSet lookupLeaseSetLocally(Hash key, Hash dbid) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("lookupLeaseSetLocally on all subDbs: " + key.toBase32());
if (dbid == null) {
LeaseSet rv = null;
for (FloodfillNetworkDatabaseFacade subdb : getClientSubNetDBs()) {
rv = subdb.lookupLeaseSetLocally(key);
if (rv != null) {
return rv;
}
}
}
return this.getSubNetDB(dbid).lookupLeaseSetLocally(key);
}
/**
* Check if all of the known subDbs are initialized
*
* @since 0.9.60
* @return true if the mainNetdb and all known client netDbs are initialized
*/
public boolean isInitialized() {
if (_mainDbid == null)
return false;
boolean rv = _mainDbid.isInitialized();
if (!rv)
return rv;
for (FloodfillNetworkDatabaseFacade subdb : getClientSubNetDBs()) {
rv = subdb.isInitialized();
if (!rv) {
break;
}
}
return rv;
}
/**
* list of the RouterInfo objects for all known peers known to clients(in subDbs) only
*
* @since 0.9.60
* @return non-null
*/
public Set<RouterInfo> getRoutersKnownToClients() {
Set<RouterInfo> rv = new HashSet<>();
for (FloodfillNetworkDatabaseFacade subdb : getClientSubNetDBs()) {
Set<RouterInfo> rv2 = subdb.getRouters();
if (rv2 != null)
rv.addAll(rv2);
}
return rv;
}
/**
* list of the LeaseSet objects for all known peers known to clients(in subDbs) only
*
* @since 0.9.60
* @return non-null
*/
public Set<LeaseSet> getLeasesKnownToClients() {
Set<LeaseSet> rv = new HashSet<>();
for (FloodfillNetworkDatabaseFacade fndf : getClientSubNetDBs()) {
Set<LeaseSet> rv2 = fndf.getLeases();
if (rv2 != null)
rv.addAll(rv2);
}
return rv;
}
/**
* get the main netDb, which is the one we will use if we are a floodfill
*
@ -248,7 +123,7 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
/**
* get the client netDb for the given id
* Will return the "exploratory(default client)" netDb if
* Will return the "main" netDb if
* the dbid is null.
*
* @since 0.9.60
@ -265,78 +140,4 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
}
return mainNetDB();
}
/**
* look up the dbid of the client or clients with the given signing
* public key
*
* @since 0.9.60
* @return non-null
*/
@Override
public List<Hash> lookupClientBySigningPublicKey(SigningPublicKey spk) {
List<Hash> rv = new ArrayList<>();
for (Hash subdb : _context.clientManager().getPrimaryHashes()) {
FloodfillNetworkDatabaseFacade fndf = _context.clientManager().getClientFloodfillNetworkDatabaseFacade(subdb);
if (fndf == null)
continue;
// if (subdb.startsWith("clients_"))
// TODO: see if we can access only one subDb at a time when we need
// to look up a client by SPK. We mostly need this for managing blinded
// and encrypted keys in the Keyring Config UI page. See also
// ConfigKeyringHelper
BlindData bd = fndf.getBlindData(spk);
if (bd != null) {
rv.add(subdb);
}
}
return rv;
}
/**
* get all the subDbs and return them in a Set. This includes the main netDb
* and the possible-multihomes netDb
*
* @since 0.9.60
* @return non-null
*/
@Override
public Set<FloodfillNetworkDatabaseFacade> getSubNetDBs() {
if (!_mainDbid.isInitialized())
return Collections.emptySet();
Set<FloodfillNetworkDatabaseFacade> rv = new HashSet<>();
rv.add(_mainDbid);
rv.addAll(_context.clientManager().getClientFloodfillNetworkDatabaseFacades());
return rv;
}
/**
* get all the subDbs and return them in a Set. This only includes subDbs associated
* with specific clients, unless subDbs are disabled in which case it only contains the
* main netDB
*
* @since 0.9.60
* @return non-null
*/
private Set<FloodfillNetworkDatabaseFacade> getClientSubNetDBs() {
if (!_mainDbid.isInitialized())
return Collections.emptySet();
Set<FloodfillNetworkDatabaseFacade> rv = new HashSet<>();
rv.addAll(_context.clientManager().getClientFloodfillNetworkDatabaseFacades());
return rv;
}
/**
* list of the BlindData objects for all known clients
*
* @since 0.9.60
* @return non-null
*/
@Override
public List<BlindData> getLocalClientsBlindData() {
List<BlindData> rv = new ArrayList<>();
for (FloodfillNetworkDatabaseFacade subdb : getClientSubNetDBs()) {
}
return rv;
}
}

View File

@ -81,7 +81,6 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
protected final int _networkID;
private final BlindCache _blindCache;
protected final Hash _dbid;
private Hash _localKey;
private final Job _elj, _erj;
/**
@ -934,13 +933,6 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
return _lastRIPublishTime;
}
public boolean matchClientKey(Hash key) {
if ((_localKey != null) && (_localKey.equals(key)))
return true;
else
return false;
}
/**
* Persist the local router's info (as updated) into netDb/my.info, since
* ./router.info isn't always updated. This also allows external applications

View File

@ -85,13 +85,12 @@ class SearchUpdateReplyFoundJob extends JobImpl implements ReplyJob {
DatabaseStoreMessage msg = (DatabaseStoreMessage)message;
DatabaseEntry entry = msg.getEntry();
try {
if (entry.isRouterInfo()) {
RouterInfo ri = (RouterInfo) entry;
_facade.store(ri.getHash(), ri);
}
if (entry.isLeaseSet()) {
LeaseSet ls = (LeaseSet) entry;
_facade.store(ls.getHash(), ls);
} else {
RouterInfo ri = (RouterInfo) entry;
_facade.store(ri.getHash(), ri);
}
} catch (UnsupportedCryptoException iae) {
// don't blame the peer

View File

@ -58,7 +58,6 @@ import net.i2p.util.Log;
*/
public abstract class SegmentedNetworkDatabaseFacade {
public SegmentedNetworkDatabaseFacade(RouterContext context) {
// super(context, null);
}
/**
@ -95,105 +94,4 @@ public abstract class SegmentedNetworkDatabaseFacade {
* @since 0.9.60
*/
public abstract void startup();
/**
* Lookup the leaseSet for a given key in only client dbs.
*
* @return may be null
* @since 0.9.60
*/
public abstract LeaseSet lookupLeaseSetHashIsClient(Hash key);
/**
* Get a set of all sub-netDbs.
*
* @return all the sub netDbs including the main
* @since 0.9.60
*/
public abstract Set<FloodfillNetworkDatabaseFacade> getSubNetDBs();
/**
* Make sure the SNDF is initialized. This is overridden in
* FloodfillNetworkDatabaseSegmentor so that it will be false until
* *all* required subDbs are initialized.
*
* @return true if the netDbs are initialized
* @since 0.9.60
*/
public boolean isInitialized() {
return mainNetDB().isInitialized();
}
/**
* list all of the RouterInfo objects known to all of the subDbs including
* the main subDb.
*
* @return all of the RouterInfo objects known to all of the netDbs. non-null
* @since 0.9.60
*/
public Set<RouterInfo> getRouters() {
Set<RouterInfo> rv = new HashSet<>();
for (FloodfillNetworkDatabaseFacade subdb : getSubNetDBs()) {
rv.addAll(subdb.getRouters());
}
return rv;
}
/**
* list of the RouterInfo objects for all known peers in all client
* subDbs which is mostly pointless because they should normally reject
* them anyway.
*
* @return non-null all the routerInfos in all of the client netDbs *only*
* @since 0.9.60
*/
public Set<RouterInfo> getRoutersKnownToClients() {
Set<RouterInfo> ris = new HashSet<>();
Set<FloodfillNetworkDatabaseFacade> fndfs = getSubNetDBs();
for (FloodfillNetworkDatabaseFacade fndf : fndfs) {
ris.addAll(fndf.getRouters());
}
return ris;
}
/**
* Get a set of all leases known to all clients. These will be
* leaseSets for destinations that the clients communicate with
* and the leaseSet of the client itself.
*
* @return non-null. all the leaseSets known to all of the client netDbs
* @since 0.9.60
*/
public Set<LeaseSet> getLeasesKnownToClients() {
Set<LeaseSet> lss = new HashSet<>();
Set<FloodfillNetworkDatabaseFacade> fndfs = getSubNetDBs();
for (FloodfillNetworkDatabaseFacade fndf : fndfs) {
lss.addAll(fndf.getLeases());
}
return lss;
}
/**
* Check if the mainNetDB needs to reseed
*
* @return non-null.
* @since 0.9.60
* */
public ReseedChecker reseedChecker() {
return mainNetDB().reseedChecker();
};
/**
* For console ConfigKeyringHelper
*
* @return non-null
* @since 0.9.60
*/
public List<Hash> lookupClientBySigningPublicKey(SigningPublicKey spk) {
return Collections.emptyList();
}
/**
* For console ConfigKeyringHelper
*
* @return non-null
* @since 0.9.60
*/
public List<BlindData> getLocalClientsBlindData() {
return Collections.emptyList();
}
}

View File

@ -77,7 +77,7 @@ class OutboundTunnelEndpoint {
int msgtype = msg.getType();
if (msgtype == DatabaseStoreMessage.MESSAGE_TYPE) {
DatabaseStoreMessage dsm = (DatabaseStoreMessage)msg;
if (dsm.getEntry().isRouterInfo()) {
if (!dsm.getEntry().isLeaseSet()) {
_ridsm++;
_context.statManager().addRateData("tunnel.outboundTunnelEndpointFwdRIDSM", 1);
if (_log.shouldLog(Log.WARN))