forked from I2P_Developers/i2p.i2p
Compare commits
5 Commits
i2p.i2p-2.
...
i2p.i2p-2.
Author | SHA1 | Date | |
---|---|---|---|
c25d547848 | |||
d16ab61b46 | |||
569e2e89a0 | |||
492356d11b | |||
4c8a441e06 |
@ -374,7 +374,6 @@ public class RouterContext extends I2PAppContext {
|
||||
*/
|
||||
public SegmentedNetworkDatabaseFacade netDbSegmentor() { return _netDb; }
|
||||
public FloodfillNetworkDatabaseFacade netDb() { return _netDb.mainNetDB(); }
|
||||
public FloodfillNetworkDatabaseFacade multihomeNetDb() { return _netDb.multiHomeNetDB(); }
|
||||
public FloodfillNetworkDatabaseFacade clientNetDb(Hash id) { return _netDb.clientNetDB(id); }
|
||||
/**
|
||||
* The actual driver of the router, where all jobs are enqueued and processed.
|
||||
|
@ -100,11 +100,6 @@ public class DummyNetworkDatabaseFacade extends SegmentedNetworkDatabaseFacade {
|
||||
return _fndb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FloodfillNetworkDatabaseFacade multiHomeNetDB() {
|
||||
return _fndb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FloodfillNetworkDatabaseFacade clientNetDB(Hash id) {
|
||||
return _fndb;
|
||||
|
@ -147,34 +147,14 @@ public class HandleDatabaseLookupMessageJob extends JobImpl {
|
||||
// Only send it out if it is in our estimated keyspace.
|
||||
// For this, we do NOT use their dontInclude list as it can't be trusted
|
||||
// (i.e. it could mess up the closeness calculation)
|
||||
LeaseSet possibleMultihomed = null;
|
||||
if (getContext().netDbSegmentor().useSubDbs()) {
|
||||
possibleMultihomed = getContext().multihomeNetDb().lookupLeaseSetLocally(searchKey);
|
||||
}
|
||||
Set<Hash> closestHashes = getContext().netDb().findNearestRouters(searchKey,
|
||||
CLOSENESS_THRESHOLD, null);
|
||||
if (weAreClosest(closestHashes)) {
|
||||
// It's in our keyspace, so give it to them
|
||||
// there is a slight chance that there is also a multihomed router in our cache at the
|
||||
// same time we are closest to our locally published leaseSet. That means there is a slight
|
||||
// chance an attacker can send a least as a store which goes into the multihome cache, then
|
||||
// fetch back a locally-created, locally-published leaseset. BUT, if we always publish a
|
||||
// multihomed leaseset even if we are closest to the local, we never send it out if a potential
|
||||
// multihome is found in the cache.
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("We have local LS " + searchKey + ", answering query, in our keyspace");
|
||||
getContext().statManager().addRateData("netDb.lookupsMatchedLocalClosest", 1);
|
||||
sendData(searchKey, ls, fromKey, toTunnel);
|
||||
} else if (getContext().netDbSegmentor().useSubDbs() && possibleMultihomed != null) {
|
||||
// If it's in the possibleMultihomed cache, then it was definitely stored to us meaning it is effectively
|
||||
// always recievedAsPublished. No need to decide whether or not to answer the request like above, just
|
||||
// answer it so it doesn't look different from other stores.
|
||||
if (possibleMultihomed.getReceivedAsPublished()) {
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("We have local LS, possibly from a multihomed router " + searchKey + ", and somebody requested it back from us. Answering query, as if in our keyspace, to avoid attack.");
|
||||
getContext().statManager().addRateData("netDb.lookupsMatchedLocalMultihome", 1);
|
||||
sendData(searchKey, possibleMultihomed, fromKey, toTunnel);
|
||||
}
|
||||
} else {
|
||||
// Lie, pretend we don't have it
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
@ -184,30 +164,17 @@ public class HandleDatabaseLookupMessageJob extends JobImpl {
|
||||
sendClosest(searchKey, routerHashSet, fromKey, toTunnel);
|
||||
}
|
||||
} else {
|
||||
LeaseSet possibleMultihomed = null;
|
||||
if (getContext().netDbSegmentor().useSubDbs()) {
|
||||
possibleMultihomed = getContext().multihomeNetDb().lookupLeaseSetLocally(searchKey);
|
||||
}
|
||||
if ((getContext().netDbSegmentor().useSubDbs()) && possibleMultihomed != null) {
|
||||
if (possibleMultihomed.getReceivedAsPublished()) {
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("We have local LS " + searchKey + " in our multihomes cache meaning it was stored to us. Answering query with the stored LS.");
|
||||
getContext().statManager().addRateData("netDb.lookupsMatchedLocalMultihome", 1);
|
||||
sendData(searchKey, possibleMultihomed, fromKey, toTunnel);
|
||||
}
|
||||
} else {
|
||||
// It was not published to us (we looked it up, for example)
|
||||
// or it's local and we aren't floodfill,
|
||||
// or it's local and we don't publish it.
|
||||
// Lie, pretend we don't have it
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("We have LS " + searchKey +
|
||||
", NOT answering query - local? " + isLocal + " shouldPublish? " + shouldPublishLocal +
|
||||
" RAP? " + ls.getReceivedAsPublished() + " RAR? " + ls.getReceivedAsReply());
|
||||
getContext().statManager().addRateData("netDb.lookupsMatchedRemoteNotClosest", 1);
|
||||
Set<Hash> routerHashSet = getNearestRouters(lookupType);
|
||||
sendClosest(searchKey, routerHashSet, fromKey, toTunnel);
|
||||
}
|
||||
// It was not published to us (we looked it up, for example)
|
||||
// or it's local and we aren't floodfill,
|
||||
// or it's local and we don't publish it.
|
||||
// Lie, pretend we don't have it
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("We have LS " + searchKey +
|
||||
", NOT answering query - local? " + isLocal + " shouldPublish? " + shouldPublishLocal +
|
||||
" RAP? " + ls.getReceivedAsPublished() + " RAR? " + ls.getReceivedAsReply());
|
||||
getContext().statManager().addRateData("netDb.lookupsMatchedRemoteNotClosest", 1);
|
||||
Set<Hash> routerHashSet = getNearestRouters(lookupType);
|
||||
sendClosest(searchKey, routerHashSet, fromKey, toTunnel);
|
||||
}
|
||||
} else if (type == DatabaseEntry.KEY_TYPE_ROUTERINFO &&
|
||||
lookupType != DatabaseLookupMessage.Type.LS) {
|
||||
|
@ -477,8 +477,6 @@ public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacad
|
||||
|
||||
@Override
|
||||
public boolean floodfillEnabled() {
|
||||
if (isMultihomeDb())
|
||||
return _context.netDb().floodfillEnabled();
|
||||
return _floodfillEnabled;
|
||||
}
|
||||
|
||||
|
@ -23,17 +23,15 @@ import net.i2p.util.Log;
|
||||
* are identified by the hash of the primary session belonging to the client who "owns"
|
||||
* a particular sub-netDb.
|
||||
*
|
||||
* There are 3 "Special" netDbs which have non-hash names:
|
||||
* There is one "Special" netDb which has a non-hash name. This is used for the operation of
|
||||
* router itself and not clients, in particular when acting as a floodfill:
|
||||
*
|
||||
* - Main NetDB: This is the netDb we use if or when we become a floodfill, and for
|
||||
* direct interaction with other routers on the network, such as when we are communicating
|
||||
* with a floodfill.
|
||||
* - Multihome NetDB: This is used to stash leaseSets for our own sites when they are
|
||||
* sent to us by a floodfill, so that we can reply when they are requested back from us
|
||||
* regardless of our closeness to them in the routing table.
|
||||
* - Exploratory NetDB: This is used when we want to stash a DatabaseEntry for a key
|
||||
* during exploration but don't want it to go into the Main NetDB until we do something
|
||||
* else with it.
|
||||
*
|
||||
* It is possible that it may be advantageous some day to have other netDb's for specific use
|
||||
* cases, but that is not the purpose of this class at this time.
|
||||
*
|
||||
* And there are an unlimited number of "Client" netDbs. These sub-netDbs are
|
||||
* intended to contain only the information required to operate them, and as such
|
||||
@ -54,9 +52,7 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
|
||||
private RouterContext _context;
|
||||
private static final String PROP_NETDB_ISOLATION = "router.netdb.isolation";
|
||||
public static final Hash MAIN_DBID = null;
|
||||
public static final Hash MULTIHOME_DBID = Hash.FAKE_HASH;
|
||||
private final FloodfillNetworkDatabaseFacade _mainDbid;
|
||||
private final FloodfillNetworkDatabaseFacade _multihomeDbid;
|
||||
|
||||
/**
|
||||
* Construct a new FloodfillNetworkDatabaseSegmentor with the given
|
||||
@ -71,7 +67,6 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
|
||||
if (_context == null)
|
||||
_context = context;
|
||||
_mainDbid = new FloodfillNetworkDatabaseFacade(_context, MAIN_DBID);
|
||||
_multihomeDbid = new FloodfillNetworkDatabaseFacade(_context, MULTIHOME_DBID);
|
||||
}
|
||||
|
||||
public boolean useSubDbs() {
|
||||
@ -103,8 +98,6 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("shutdown called from FNDS, shutting down main and multihome db");
|
||||
_mainDbid.shutdown();
|
||||
if (useSubDbs())
|
||||
_multihomeDbid.shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -117,8 +110,6 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("startup called from FNDS, starting up main and multihome db");
|
||||
_mainDbid.startup();
|
||||
if (useSubDbs())
|
||||
_multihomeDbid.startup();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -256,17 +247,6 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
|
||||
return _mainDbid;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the multiHome netDb, which is especially for handling multihomes
|
||||
*
|
||||
* @since 0.9.60
|
||||
* @return may be null
|
||||
*/
|
||||
@Override
|
||||
public FloodfillNetworkDatabaseFacade multiHomeNetDB() {
|
||||
return _multihomeDbid;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the client netDb for the given id
|
||||
* Will return the "exploratory(default client)" netDb if
|
||||
@ -333,7 +313,6 @@ public class FloodfillNetworkDatabaseSegmentor extends SegmentedNetworkDatabaseF
|
||||
return rv;
|
||||
}
|
||||
rv.add(_mainDbid);
|
||||
rv.add(multiHomeNetDB());
|
||||
rv.addAll(_context.clientManager().getClientFloodfillNetworkDatabaseFacades());
|
||||
return rv;
|
||||
}
|
||||
|
@ -151,9 +151,9 @@ class HandleFloodfillDatabaseStoreMessageJob extends JobImpl {
|
||||
// If we're using subdbs, store the leaseSet in the multihome DB.
|
||||
// otherwise, throw rather than return, so that we send the ack below (prevent easy attack)
|
||||
dontBlamePeer = true;
|
||||
if (getContext().netDbSegmentor().useSubDbs())
|
||||
getContext().multihomeNetDb().store(key, ls);
|
||||
else
|
||||
//if (getContext().netDbSegmentor().useSubDbs())
|
||||
//getContext().multihomeNetDb().store(key, ls);
|
||||
//else
|
||||
throw new IllegalArgumentException("(dbid: " + _facade._dbid
|
||||
+ ") Peer attempted to store local leaseSet: "
|
||||
+ key.toBase32());
|
||||
|
@ -338,8 +338,6 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
|
||||
// FNDS.MAIN_DBID is always null. and if _dbid is also null it is not a client Db
|
||||
if (_dbid == FloodfillNetworkDatabaseSegmentor.MAIN_DBID)
|
||||
return false;
|
||||
if (_dbid.equals(FloodfillNetworkDatabaseSegmentor.MULTIHOME_DBID))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -358,23 +356,6 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the current database is a multihome database.
|
||||
*
|
||||
* @return true if the current database is a multihome database, false otherwise.
|
||||
* @since 0.9.60
|
||||
*/
|
||||
public boolean isMultihomeDb() {
|
||||
// This is a null check in disguise, don't use .equals() here.
|
||||
// FNDS.MAIN_DBID is always null, and if _dbid is null it is not the multihome Db
|
||||
if (_dbid == FloodfillNetworkDatabaseSegmentor.MAIN_DBID)
|
||||
return false;
|
||||
if (_dbid.equals(FloodfillNetworkDatabaseSegmentor.MULTIHOME_DBID))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public synchronized void startup() {
|
||||
_log.info("Starting up the kademlia network database");
|
||||
RouterInfo ri = _context.router().getRouterInfo();
|
||||
|
@ -85,14 +85,6 @@ public abstract class SegmentedNetworkDatabaseFacade {
|
||||
* @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
|
||||
*
|
||||
* @return may be null if the multihome netDb is not initialized
|
||||
* @since 0.9.60
|
||||
*/
|
||||
public abstract FloodfillNetworkDatabaseFacade multiHomeNetDB();
|
||||
/**
|
||||
* Get a client netDb for a given client Hash identifier. Will never
|
||||
* return the mainNetDB.
|
||||
|
Reference in New Issue
Block a user