Skip to content

Commit

Permalink
Router: add protected isMainDb() function to KNDF and use it when we …
Browse files Browse the repository at this point in the history
…want to make sure we're the main db
  • Loading branch information
eyedeekay committed Oct 8, 2023
1 parent 6ada2f3 commit 4c7846b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public FloodfillNetworkDatabaseFacade(RouterContext context, Hash dbid) {
// 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);
Expand All @@ -103,7 +103,7 @@ public synchronized void startup() {
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);
Expand All @@ -126,7 +126,7 @@ public synchronized void startup() {
@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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public KademliaNetworkDatabaseFacade(RouterContext context, Hash dbid) {
_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);
Expand Down Expand Up @@ -218,7 +218,7 @@ public boolean isInitialized() {
/** @since 0.9 */
@Override
public ReseedChecker reseedChecker() {
if (isClientDb())
if (!isMainDb())
return null;
return _reseedChecker;
}
Expand Down Expand Up @@ -322,6 +322,21 @@ public boolean isClientDb() {
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.
Expand All @@ -346,7 +361,7 @@ public synchronized void startup() {
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);
Expand Down Expand Up @@ -382,7 +397,7 @@ public synchronized void startup() {
}

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,
Expand All @@ -404,7 +419,7 @@ public synchronized void startup() {
_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);
Expand Down Expand Up @@ -1460,7 +1475,7 @@ public void fail(Hash dbEntry) {
// 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,
Expand Down

0 comments on commit 4c7846b

Please sign in to comment.