corestore init

This commit is contained in:
Raven Scott
2026-05-28 01:41:48 -04:00
parent b7b3a1c111
commit 7c49928a5c
+14 -4
View File
@@ -201,6 +201,19 @@ async function main() {
if (cleanStorage) {
await runPluginStorageReset('--clean startup');
}
// Initialize the main Corestore before plugins so storage is guaranteed to exist
// even if a plugin fails during startup.
let store = null;
try {
store = new Corestore(storageDir);
await store.ready();
logInfo('Main', `Corestore initialized with storage: ${storageDir}`);
} catch (err) {
logError('Main', `Failed to initialize corestore at ${storageDir}: ${err.message}`);
process.exit(1);
}
setupCache();
ca.installRootCA();
@@ -287,10 +300,7 @@ async function main() {
const topic = crypto.createHash('sha256').update(process.env.TOPIC_SEED || 'p2ns-dns').digest();
state.topic = topic; // Store topic in state for keep-alive and cleanup
logDebug('Main', `Generated topic: ${topic.toString('hex')}`);
// Initialize corestore and hyperswarm
let store = new Corestore(storageDir);
await store.ready();
logInfo('Main', `Corestore initialized with storage: ${storageDir}`);
// Corestore is initialized before plugin loading
// Use the persistent keypair that was loaded earlier (already in state.keypair)
// Configure Hyperswarm for better local network peer discovery
const swarmOptions = {