From a460ae2ffc2b341147b86980e9fac218cbdd255f Mon Sep 17 00:00:00 2001 From: idk Date: Wed, 1 Nov 2023 20:32:57 +0000 Subject: [PATCH] Remove unused functions from FNDS, SNDF, KNDF --- core/java/src/net/i2p/data/DatabaseEntry.java | 10 - .../java/src/net/i2p/router/MultiRouter.java | 2 +- .../net/i2p/router/client/LookupDestJob.java | 6 - .../dummy/DummyNetworkDatabaseFacade.java | 10 - .../FloodfillNetworkDatabaseFacade.java | 5 - .../FloodfillNetworkDatabaseSegmentor.java | 207 +----------------- .../KademliaNetworkDatabaseFacade.java | 8 - .../kademlia/SearchUpdateReplyFoundJob.java | 7 +- .../SegmentedNetworkDatabaseFacade.java | 102 --------- .../router/tunnel/OutboundTunnelEndpoint.java | 2 +- 10 files changed, 9 insertions(+), 350 deletions(-) diff --git a/core/java/src/net/i2p/data/DatabaseEntry.java b/core/java/src/net/i2p/data/DatabaseEntry.java index 5f75a37b10..8a6b84e275 100644 --- a/core/java/src/net/i2p/data/DatabaseEntry.java +++ b/core/java/src/net/i2p/data/DatabaseEntry.java @@ -153,16 +153,6 @@ public static boolean isLeaseSet(int type) { 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(). * diff --git a/router/java/src/net/i2p/router/MultiRouter.java b/router/java/src/net/i2p/router/MultiRouter.java index 814163b481..18a802dc69 100644 --- a/router/java/src/net/i2p/router/MultiRouter.java +++ b/router/java/src/net/i2p/router/MultiRouter.java @@ -140,7 +140,7 @@ private static void internalReseed() { HashSet riSet = new HashSet(); for(Router r : _routers) { - riSet.addAll(r.getContext().netDbSegmentor().getRouters()); + riSet.addAll(r.getContext().netDb().getRouters()); } for(Router r : _routers) { for(RouterInfo ri : riSet){ diff --git a/router/java/src/net/i2p/router/client/LookupDestJob.java b/router/java/src/net/i2p/router/client/LookupDestJob.java index 09516f299d..2bb8c1de8c 100644 --- a/router/java/src/net/i2p/router/client/LookupDestJob.java +++ b/router/java/src/net/i2p/router/client/LookupDestJob.java @@ -196,12 +196,6 @@ else if (fail1) } } - private String toBase32(){ - if (_fromLocalDest != null) - return _fromLocalDest.toBase32(); - return null; - } - private class DoneJob extends JobImpl { public DoneJob(RouterContext enclosingContext) { super(enclosingContext); diff --git a/router/java/src/net/i2p/router/dummy/DummyNetworkDatabaseFacade.java b/router/java/src/net/i2p/router/dummy/DummyNetworkDatabaseFacade.java index 52b65b89a8..3eced438f9 100644 --- a/router/java/src/net/i2p/router/dummy/DummyNetworkDatabaseFacade.java +++ b/router/java/src/net/i2p/router/dummy/DummyNetworkDatabaseFacade.java @@ -90,11 +90,6 @@ public void fail(Hash dbEntry) { public Set getAllRouters() { return new HashSet(_routers.keySet()); } public Set findNearestRouters(Hash key, int maxNumRouters, Set 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 FloodfillNetworkDatabaseFacade mainNetDB() { public FloodfillNetworkDatabaseFacade clientNetDB(Hash id) { return _fndb; } - - @Override - public Set getSubNetDBs(){ - throw new UnsupportedOperationException("Unimplemented method 'getSubNetDBs'"); - } } diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java index 646f7985d4..cc1aefa3c7 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java @@ -290,11 +290,6 @@ public boolean floodConditional(DatabaseEntry ds) { 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. diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseSegmentor.java b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseSegmentor.java index 3d5c347868..c47043910e 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseSegmentor.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseSegmentor.java @@ -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 @@ protected FloodfillNetworkDatabaseFacade getSubNetDB(Hash id) { } /** - * 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 synchronized void shutdown() { } /** - * Start up the floodfill for the _mainDbid and the _multihomeDbid + * Start up the _mainDbid * * @since 0.9.60 * @@ -111,130 +110,6 @@ public synchronized void startup() { _mainDbid.startup(); } - /** - * list of the RouterInfo objects for all known peers; - * - * @since 0.9.60 - * @return non-null - */ - public List getKnownRouterData() { - List rv = new ArrayList(); - 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 getFloodfillPeers() { - if (_log.shouldLog(Log.DEBUG)) - _log.debug("getFloodfillPeers collecting all floodfill peers across all subDbs"); - List peers = new ArrayList(); - 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 getRoutersKnownToClients() { - Set rv = new HashSet<>(); - for (FloodfillNetworkDatabaseFacade subdb : getClientSubNetDBs()) { - Set 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 getLeasesKnownToClients() { - Set rv = new HashSet<>(); - for (FloodfillNetworkDatabaseFacade fndf : getClientSubNetDBs()) { - Set 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 FloodfillNetworkDatabaseFacade mainNetDB() { /** * 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 FloodfillNetworkDatabaseFacade clientNetDB(Hash id) { } 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 lookupClientBySigningPublicKey(SigningPublicKey spk) { - List 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 getSubNetDBs() { - if (!_mainDbid.isInitialized()) - return Collections.emptySet(); - Set 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 getClientSubNetDBs() { - if (!_mainDbid.isInitialized()) - return Collections.emptySet(); - Set 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 getLocalClientsBlindData() { - List rv = new ArrayList<>(); - for (FloodfillNetworkDatabaseFacade subdb : getClientSubNetDBs()) { - } - return rv; - } } diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java b/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java index d9e6cdc872..9a1f152911 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java @@ -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 long getLastRouterInfoPublishTime() { 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 diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/SearchUpdateReplyFoundJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/SearchUpdateReplyFoundJob.java index 3296cb63bc..b099e9f891 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/SearchUpdateReplyFoundJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/SearchUpdateReplyFoundJob.java @@ -85,13 +85,12 @@ public void runJob() { 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 diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/SegmentedNetworkDatabaseFacade.java b/router/java/src/net/i2p/router/networkdb/kademlia/SegmentedNetworkDatabaseFacade.java index b7a4b9735a..6a308f8fbb 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/SegmentedNetworkDatabaseFacade.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/SegmentedNetworkDatabaseFacade.java @@ -58,7 +58,6 @@ */ public abstract class SegmentedNetworkDatabaseFacade { public SegmentedNetworkDatabaseFacade(RouterContext context) { - // super(context, null); } /** @@ -95,105 +94,4 @@ public SegmentedNetworkDatabaseFacade(RouterContext context) { * @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 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 getRouters() { - Set 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 getRoutersKnownToClients() { - Set ris = new HashSet<>(); - Set 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 getLeasesKnownToClients() { - Set lss = new HashSet<>(); - Set 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 lookupClientBySigningPublicKey(SigningPublicKey spk) { - return Collections.emptyList(); - } - /** - * For console ConfigKeyringHelper - * - * @return non-null - * @since 0.9.60 - */ - public List getLocalClientsBlindData() { - return Collections.emptyList(); - } } diff --git a/router/java/src/net/i2p/router/tunnel/OutboundTunnelEndpoint.java b/router/java/src/net/i2p/router/tunnel/OutboundTunnelEndpoint.java index 2436c569f8..99feff9db6 100644 --- a/router/java/src/net/i2p/router/tunnel/OutboundTunnelEndpoint.java +++ b/router/java/src/net/i2p/router/tunnel/OutboundTunnelEndpoint.java @@ -77,7 +77,7 @@ public void receiveComplete(I2NPMessage msg, Hash toRouter, TunnelId toTunnel) { 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))