-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Cannot create a node with an initialized repo #1245
Comments
Hey @realharry I spent a little time looking at this problem and was able narrow the problem but I'm not sure of expected behavior here so I wanted to share what I've found. IPFS takes additional steps when initializing a new repo, adding a js-ipfs/src/core/components/init.js Lines 44 to 69 in d945fce
Because of this, IPFS is happy to use a repo previously created by itself but a fresh repo created without these config options fails. I'm not sure if this is all that it does but I was able to get a node started with this code: code spoiler
I'm not sure of the expected behavior here so I wanted others' thoughts. We could:
|
@realharry There is an issues with your code snippet, you're trying to initialize the repo with I agree that the error message is not informative tho - it should say that the repo already exists. Here is a code snippet that uses a repo object: const IPFS = require('ipfs');
const IPFSRepo = require('ipfs-repo');
const repo1 = new IPFSRepo('<path to repo>');
console.log('Creating IPFS node 1.');
let node1 = new IPFS({
repo: repo1,
init: false,
start: true,
EXPERIMENTAL: {}
});
node1.on('start', () => {
console.log('IPFS node 1 started.');
}); Here is a snippet that takes a path to the repo without explicitly creating a repo object: const IPFS = require('ipfs');
console.log('Creating IPFS node 1.');
let node1 = new IPFS({
repo: '<path to repo>',
init: false,
start: true,
EXPERIMENTAL: {}
});
node1.on('start', () => {
console.log('IPFS node 1 started.');
}); |
@dryajov's response is the correct way to reuse a repo as long as it was previously created by ipfs, which is probably all of the time. Is there any need to look further into what I had brought up or is that an unsupported use? |
@JonKrone there is no need to follow this steps as IPFS will perform them internally when initializing the repo. What we need to do is to handle this more intelligently in When IPFS boots, it calls |
Is there a way to provide clearer error messaging in this case? e.g. It would probably be helpful to note that a repo should generally be created with const node = new IPFS({
repo: repo,
init: true, // default
// init: false, // If you have already initialized the repo with `new IPFS()`.
// // The IPFS constructor initializes repos with extra options;
// // simply calling `init()` on an IPFSRepo instance is not enough.
// init: {
// bits: 1024 // size of the RSA key generated
// },
start: true, // default
... |
Actually, that error message could be even more actionable: |
Add some description to the "advanced options" documentation for the `IPFS` constructor detailing that `init: false` should really be used if a repo has already been initialized *by IPFS* and that simply calling `repoInstance.init()` doesn't init a repo with everything IPFS needs. This partially handles ipfs#1245.
Add some description to the "advanced options" documentation for the `IPFS` constructor detailing that `init: false` should really be used if a repo has already been initialized *by IPFS* and that simply calling `repoInstance.init()` doesn't init a repo with everything IPFS needs. This partially handles ipfs#1245. License: MIT Signed-off-by: Rob Brackett <work@robbrackett.com>
Is there is any updates on this issue? |
Starting a node with an already initialised and open repo works for me like so: const IPFS = require('ipfs')
const IPFSRepo = require('ipfs-repo')
const PeerId = require('peer-id')
const os = require('os')
const path = require('path')
async function main () {
const peerId = await PeerId.create({ bits: 2048 })
const repo = new IPFSRepo(path.join(os.tmpdir(), 'ipfs-' + Math.random()))
await repo.init({
// nb. you may need more config to make your node useful
// see: https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs/src/core/runtime/config-nodejs.js
// or https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs/src/core/runtime/config-browser.js
// depending on environment
/*
Addresses: {
...
}, ... etc
*/
Identity: {
PeerID: peerId.toB58String(),
PrivKey: peerId.privKey.bytes.toString('base64')
}
})
await repo.open()
const node = await IPFS.create({
repo
})
console.info('node started')
await node.stop()
console.info('node stopped')
}
main() This issue is very old and the codepaths that trigger the error reported no longer exist. If the above script does not work for you please open a new issue with more recent error stack traces, etc. |
Type: Bug
Severity: Medium
Description:
Attempting to create an IPFS node using an initialized Repo object throws "Callback was already called." error.
Not sure if I'm using the API correctly (practically, it's my first day of using js-ipfs), but if I try to pass the repo argument with the initialized Repo object in the IPFS constructor, I get the following exception from Async:
Steps to reproduce the error:
Here' a sample code snippet:
The text was updated successfully, but these errors were encountered: