This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d01c82f
commit fca76b0
Showing
8 changed files
with
337 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"Addresses": { | ||
"Swarm": [ | ||
"/ip4/0.0.0.0/tcp/4001", | ||
"/ip6/::/tcp/4001" | ||
], | ||
"API": "/ip4/127.0.0.1/tcp/5001", | ||
"Gateway": "/ip4/127.0.0.1/tcp/8080" | ||
}, | ||
"Discovery": { | ||
"MDNS": { | ||
"Enabled": true, | ||
"Interval": 10 | ||
} | ||
}, | ||
"Mounts": { | ||
"IPFS": "/ipfs", | ||
"IPNS": "/ipns" | ||
}, | ||
"Ipns": { | ||
"ResolveCacheSize": 128 | ||
}, | ||
"Gateway": { | ||
"RootRedirect": "", | ||
"Writable": false | ||
}, | ||
"Bootstrap": [ | ||
"/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", | ||
"/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z", | ||
"/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM", | ||
"/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm", | ||
"/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu", | ||
"/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64", | ||
"/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd", | ||
"/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3", | ||
"/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const peerId = require('peer-id') | ||
const IpfsBlocks = require('ipfs-blocks').BlockService | ||
const IpfsDagService = require('ipfs-merkle-dag').DAGService | ||
const path = require('path') | ||
|
||
module.exports = (repo, opts, callback) => { | ||
opts = opts || {} | ||
opts.force = opts.force || false | ||
opts.emptyRepo = opts.emptyRepo || false | ||
opts.bits = opts.bits || 2048 | ||
|
||
// Pre-set config values. | ||
var config = require('../../default-config.json') | ||
|
||
// Verify repo does not yet exist (or that 'force' is provided). | ||
repo.exists((err, res) => { | ||
if (err) { return callback(err) } | ||
if (res === true && !opts.force) { | ||
return callback(new Error('repo already exists and \'force\' is not set')) | ||
} | ||
|
||
generateAndSetKeypair() | ||
}) | ||
|
||
// Generate peer identity keypair + transform to desired format + add to config. | ||
function generateAndSetKeypair () { | ||
var keys = peerId.create({ | ||
bits: opts.bits | ||
}) | ||
config.Identity = { | ||
PeerID: keys.toB58String(), | ||
PrivKey: keys.privKey.toString('base64') | ||
} | ||
|
||
writeVersion() | ||
} | ||
|
||
function writeVersion () { | ||
const version = '3' | ||
repo.version.set(version, (err) => { | ||
if (err) { return callback(err) } | ||
|
||
writeConfig() | ||
}) | ||
} | ||
|
||
// Write the config to the repo. | ||
function writeConfig () { | ||
repo.config.set(config, (err) => { | ||
if (err) { return callback(err) } | ||
|
||
addDefaultAssets() | ||
}) | ||
} | ||
|
||
// Add the default assets to the repo. | ||
function addDefaultAssets () { | ||
// Skip this step on the browser, or if emptyRepo was supplied. | ||
const isNode = !global.window | ||
if (!isNode || opts.emptyRepo) { | ||
return doneImport(null) | ||
} | ||
|
||
const importer = require('ipfs-data-importing') | ||
const blocks = new IpfsBlocks(repo) | ||
const dag = new IpfsDagService(blocks) | ||
|
||
const initDocsPath = path.join(__dirname, '../../init-doc') | ||
|
||
importer.import(initDocsPath, dag, { | ||
recursive: true | ||
}, doneImport) | ||
|
||
function doneImport (err, stat) { | ||
if (err) { return callback(err) } | ||
|
||
// All finished! | ||
callback(null, true) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* eslint-env mocha */ | ||
|
||
const expect = require('chai').expect | ||
const IPFS = require('../../src/core') | ||
const IPFSRepo = require('ipfs-repo') | ||
|
||
function createTestRepo () { | ||
const repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8) + '/' | ||
|
||
var store | ||
var teardown | ||
|
||
const isNode = !global.window | ||
if (isNode) { | ||
store = require('fs-blob-store') | ||
teardown = (done) => { | ||
const rimraf = require('rimraf') | ||
rimraf(repoPath, (err) => { | ||
expect(err).to.not.exist | ||
done() | ||
}) | ||
} | ||
} else { | ||
const idb = window.indexedDB || | ||
window.mozIndexedDB || | ||
window.webkitIndexedDB || | ||
window.msIndexedDB | ||
store = require('idb-plus-blob-store') | ||
teardown = (done) => { | ||
idb.deleteDatabase(repoPath) | ||
idb.deleteDatabase(repoPath + '/blocks') | ||
done() | ||
} | ||
} | ||
|
||
const options = { | ||
bits: 64, | ||
stores: { | ||
keys: store, | ||
config: store, | ||
datastore: store, | ||
logs: store, | ||
locks: store, | ||
version: store | ||
} | ||
} | ||
|
||
var repo = new IPFSRepo(repoPath, options) | ||
|
||
repo.teardown = teardown | ||
|
||
return repo | ||
} | ||
|
||
describe('node: init', function () { | ||
this.timeout(10000) | ||
|
||
it('init docs written', (done) => { | ||
var repo = createTestRepo() | ||
const ipfs = new IPFS(repo) | ||
ipfs.init({ bits: 64 }, (err) => { | ||
expect(err).to.not.exist | ||
|
||
// Check for default assets | ||
var multihash = new Buffer('12205e7c3ce237f936c76faf625e90f7751a9f5eeb048f59873303c215e9cce87599', 'hex') | ||
ipfs.object.get(multihash, {}, (err, node) => { | ||
expect(err).to.not.exist | ||
expect(node.links).to.exist | ||
|
||
repo.teardown(done) | ||
}) | ||
}) | ||
}) | ||
|
||
it('empty repo', (done) => { | ||
var repo = createTestRepo() | ||
const ipfs = new IPFS(repo) | ||
ipfs.init({ bits: 64, emptyRepo: true }, (err) => { | ||
expect(err).to.not.exist | ||
|
||
// Check for default assets | ||
var multihash = new Buffer('12205e7c3ce237f936c76faf625e90f7751a9f5eeb048f59873303c215e9cce87599', 'hex') | ||
ipfs.object.get(multihash, {}, (err, node) => { | ||
expect(err).to.exist | ||
repo.teardown(done) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* eslint-env mocha */ | ||
|
||
const expect = require('chai').expect | ||
const IPFS = require('../../src/core') | ||
const IPFSRepo = require('ipfs-repo') | ||
|
||
function createTestRepo () { | ||
const repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8) + '/' | ||
|
||
var store | ||
var teardown | ||
|
||
const isNode = !global.window | ||
if (isNode) { | ||
store = require('fs-blob-store') | ||
teardown = (done) => { | ||
const rimraf = require('rimraf') | ||
rimraf(repoPath, (err) => { | ||
expect(err).to.not.exist | ||
done() | ||
}) | ||
} | ||
} else { | ||
const idb = window.indexedDB || | ||
window.mozIndexedDB || | ||
window.webkitIndexedDB || | ||
window.msIndexedDB | ||
store = require('idb-plus-blob-store') | ||
teardown = (done) => { | ||
idb.deleteDatabase(repoPath) | ||
idb.deleteDatabase(repoPath + '/blocks') | ||
done() | ||
} | ||
} | ||
|
||
const options = { | ||
bits: 64, | ||
stores: { | ||
keys: store, | ||
config: store, | ||
datastore: store, | ||
logs: store, | ||
locks: store, | ||
version: store | ||
} | ||
} | ||
|
||
var repo = new IPFSRepo(repoPath, options) | ||
|
||
repo.teardown = teardown | ||
|
||
return repo | ||
} | ||
|
||
describe('init', function () { | ||
this.timeout(10000) | ||
|
||
it('basic', (done) => { | ||
var repo = createTestRepo() | ||
const ipfs = new IPFS(repo) | ||
ipfs.init({ emptyRepo: true }, (err) => { | ||
expect(err).to.not.exist | ||
|
||
repo.exists((err, res) => { | ||
expect(err).to.not.exist | ||
expect(res).to.equal(true) | ||
|
||
repo.config.get((err, config) => { | ||
expect(err).to.not.exist | ||
expect(config.Identity).to.exist | ||
|
||
repo.teardown(done) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
it('set # of bits in key', (done) => { | ||
var repo1 = createTestRepo() | ||
var repo2 = createTestRepo() | ||
const ipfsShort = new IPFS(repo1) | ||
const ipfsLong = new IPFS(repo2) | ||
ipfsShort.init({ bits: 128, emptyRepo: true }, (err) => { | ||
expect(err).to.not.exist | ||
|
||
ipfsLong.init({ bits: 256, emptyRepo: true }, (err) => { | ||
expect(err).to.not.exist | ||
|
||
repo1.config.get((err, config1) => { | ||
expect(err).to.not.exist | ||
|
||
repo2.config.get((err, config2) => { | ||
expect(err).to.not.exist | ||
expect(config1.Identity.PrivKey.length).is.below(config2.Identity.PrivKey.length) | ||
|
||
repo1.teardown(() => { | ||
repo2.teardown(done) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
it('force init (overwrite)', (done) => { | ||
var repo = createTestRepo() | ||
const ipfs1 = new IPFS(repo) | ||
const ipfs2 = new IPFS(repo) | ||
ipfs1.init({ bits: 128, emptyRepo: true }, (err) => { | ||
expect(err).to.not.exist | ||
|
||
ipfs2.init({ bits: 128, force: false }, (err) => { | ||
expect(err).to.exist | ||
|
||
ipfs2.init({ force: true }, (err) => { | ||
expect(err).to.not.exist | ||
|
||
repo.teardown(done) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |