forked from I2P_Developers/i2p.i2p
Router: add protected isMainDb() function to KNDF and use it when we want to make sure we're the main db
This commit is contained in:
@@ -91,7 +91,7 @@ public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacad
|
||||
// for ISJ
|
||||
_context.statManager().createRateStat("netDb.RILookupDirect", "Was an iterative RI lookup sent directly?", "NetworkDatabase", rate);
|
||||
// No need to start the FloodfillMonitorJob for client subDb.
|
||||
if (super.isClientDb())
|
||||
if (!super.isMainDb())
|
||||
_ffMonitor = null;
|
||||
else
|
||||
_ffMonitor = new FloodfillMonitorJob(_context, this);
|
||||
@@ -103,7 +103,7 @@ public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacad
|
||||
super.startup();
|
||||
if (_ffMonitor != null)
|
||||
_context.jobQueue().addJob(_ffMonitor);
|
||||
if (super.isClientDb())
|
||||
if (!super.isMainDb())
|
||||
isFF = false;
|
||||
else
|
||||
isFF = _context.getBooleanProperty(FloodfillMonitorJob.PROP_FLOODFILL_PARTICIPANT);
|
||||
@@ -126,7 +126,7 @@ public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacad
|
||||
@Override
|
||||
protected void createHandlers() {
|
||||
// Only initialize the handlers for the flooodfill netDb.
|
||||
if (!isClientDb()) {
|
||||
if (super.isMainDb()) {
|
||||
if (_log.shouldInfo())
|
||||
_log.info("[dbid: " + super._dbid + "] Initializing the message handlers");
|
||||
_context.inNetMessagePool().registerHandlerJobBuilder(DatabaseLookupMessage.MESSAGE_TYPE, new FloodfillDatabaseLookupMessageHandler(_context, this));
|
||||
|
||||
@@ -180,7 +180,7 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
|
||||
_peerSelector = createPeerSelector();
|
||||
_publishingLeaseSets = new HashMap<Hash, RepublishLeaseSetJob>(8);
|
||||
_activeRequests = new HashMap<Hash, SearchJob>(8);
|
||||
if (isClientDb())
|
||||
if (!isMainDb())
|
||||
_reseedChecker = null;
|
||||
else
|
||||
_reseedChecker = new ReseedChecker(context);
|
||||
@@ -218,7 +218,7 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
|
||||
/** @since 0.9 */
|
||||
@Override
|
||||
public ReseedChecker reseedChecker() {
|
||||
if (isClientDb())
|
||||
if (!isMainDb())
|
||||
return null;
|
||||
return _reseedChecker;
|
||||
}
|
||||
@@ -322,6 +322,21 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the database is the main netDb. This is the one we're normally using
|
||||
* if you're acting as a floodfill.
|
||||
*
|
||||
* @return true if _dbid == FNDS.MAIN_DBID
|
||||
* @since 0.9.60
|
||||
*/
|
||||
protected boolean isMainDb() {
|
||||
// This is a null check in disguise, don't use equals() here.
|
||||
// FNDS.MAIN_DBID is always null.
|
||||
if (_dbid == FloodfillNetworkDatabaseSegmentor.MAIN_DBID)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the current database is a multihome database.
|
||||
@@ -346,7 +361,7 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
|
||||
BUCKET_SIZE, KAD_B, new RejectTrimmer<Hash>());
|
||||
_dbDir = getDbDir();
|
||||
try {
|
||||
if (!isClientDb()) {
|
||||
if (isMainDb()) {
|
||||
_ds = new PersistentDataStore(_context, _dbDir, this);
|
||||
} else {
|
||||
_ds = new TransientDataStore(_context);
|
||||
@@ -382,7 +397,7 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
|
||||
}
|
||||
|
||||
if (!QUIET) {
|
||||
if (!isClientDb() && !isMultihomeDb()) {
|
||||
if (isMainDb()) {
|
||||
// fill the search queue with random keys in buckets that are too small
|
||||
// Disabled since KBucketImpl.generateRandomKey() is b0rked,
|
||||
// and anyway, we want to search for a completely random key,
|
||||
@@ -404,7 +419,7 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
|
||||
_log.warn("Operating in quiet mode - not exploring or pushing data proactively, simply reactively");
|
||||
_log.warn("This should NOT be used in production");
|
||||
}
|
||||
if (!isClientDb() && !isMultihomeDb()) {
|
||||
if (isMainDb()) {
|
||||
// periodically update and resign the router's 'published date', which basically
|
||||
// serves as a version
|
||||
Job plrij = new PublishLocalRouterInfoJob(_context);
|
||||
@@ -1460,7 +1475,7 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
|
||||
// are any updates
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Dropping a lease: " + dbEntry);
|
||||
if (!isClientDb()) {
|
||||
if (isMainDb()) {
|
||||
_ds.remove(dbEntry, false);
|
||||
} else {
|
||||
// if this happens it's because we're a TransientDataStore instead,
|
||||
|
||||
Reference in New Issue
Block a user