Skip to content

Commit

Permalink
Merge branch 'i2p.i2p.2.4.0-unused' into 'master'
Browse files Browse the repository at this point in the history
Remove unused functions from FNDS, SNDF, KNDF

Closes #466, #440, #463, and #462

See merge request i2p-hackers/i2p.i2p!141
  • Loading branch information
eyedeekay committed Nov 1, 2023
2 parents a320b25 + a460ae2 commit 291e630
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 350 deletions.
10 changes: 0 additions & 10 deletions core/java/src/net/i2p/data/DatabaseEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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().
*
Expand Down
2 changes: 1 addition & 1 deletion router/java/src/net/i2p/router/MultiRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private static void internalReseed() {

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){
Expand Down
6 changes: 0 additions & 6 deletions router/java/src/net/i2p/router/client/LookupDestJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ public void fail(Hash dbEntry) {
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;
Expand All @@ -104,9 +99,4 @@ public FloodfillNetworkDatabaseFacade mainNetDB() {
public FloodfillNetworkDatabaseFacade clientNetDB(Hash id) {
return _fndb;
}

@Override
public Set<FloodfillNetworkDatabaseFacade> getSubNetDBs(){
throw new UnsupportedOperationException("Unimplemented method 'getSubNetDBs'");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*
Expand All @@ -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
*
Expand All @@ -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<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
*
Expand All @@ -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
Expand All @@ -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<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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 291e630

Please sign in to comment.