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
Showing
15 changed files
with
203 additions
and
5 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
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
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
Empty file.
Empty file.
Empty file.
20 changes: 20 additions & 0 deletions
20
test/http-api/interface-ipfs-core-over-ipfs-api/test-object.js
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,20 @@ | ||
/* eslint-env mocha */ | ||
|
||
'use strict' | ||
|
||
const test = require('interface-ipfs-core') | ||
const FactoryClient = require('./../../utils/factory-http') | ||
|
||
let fc | ||
|
||
const common = { | ||
setup: function (callback) { | ||
fc = new FactoryClient() | ||
callback(null, fc) | ||
}, | ||
teardown: function (callback) { | ||
fc.dismantle(callback) | ||
} | ||
} | ||
|
||
test.object(common) |
Empty file.
File renamed without changes.
File renamed without changes.
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,68 @@ | ||
{ | ||
"Identity": { | ||
"PeerID": "", | ||
"PrivKey": "" | ||
}, | ||
"Datastore": { | ||
"Type": "", | ||
"Path": "", | ||
"StorageMax": "", | ||
"StorageGCWatermark": 0, | ||
"GCPeriod": "", | ||
"Params": null, | ||
"NoSync": false | ||
}, | ||
"Addresses": { | ||
"Swarm": [ | ||
"/ip4/127.0.0.1/tcp/0" | ||
], | ||
"API": "/ip4/127.0.0.1/tcp/0", | ||
"Gateway": "/ip4/127.0.0.1/tcp/0" | ||
}, | ||
"Mounts": { | ||
"IPFS": "/ipfs", | ||
"IPNS": "/ipns", | ||
"FuseAllowOther": false | ||
}, | ||
"Version": { | ||
"Current": "jsipfs-dev", | ||
"Check": "error", | ||
"CheckDate": "0001-01-01T00:00:00Z", | ||
"CheckPeriod": "172800000000000", | ||
"AutoUpdate": "minor" | ||
}, | ||
"Discovery": { | ||
"MDNS": { | ||
"Enabled": true, | ||
"Interval": 10 | ||
} | ||
}, | ||
"Ipns": { | ||
"RepublishPeriod": "", | ||
"RecordLifetime": "", | ||
"ResolveCacheSize": 128 | ||
}, | ||
"Bootstrap": [], | ||
"Tour": { | ||
"Last": "" | ||
}, | ||
"Gateway": { | ||
"HTTPHeaders": null, | ||
"RootRedirect": "", | ||
"Writable": false | ||
}, | ||
"SupernodeRouting": { | ||
"Servers": [] | ||
}, | ||
"API": { | ||
"HTTPHeaders": null | ||
}, | ||
"Swarm": { | ||
"AddrFilters": null | ||
}, | ||
"Log": { | ||
"MaxSizeMB": 250, | ||
"MaxBackups": 1, | ||
"MaxAgeDays": 0 | ||
} | ||
} |
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,99 @@ | ||
'use strict' | ||
|
||
const PeerId = require('peer-id') | ||
const IPFSRepo = require('ipfs-repo') | ||
const IPFSAPI = require('ipfs-api') | ||
const IPFS = require('../../../src/core') | ||
const cleanRepo = require('../clean') | ||
const HTTPAPI = require('../../../src/http-api') | ||
const series = require('run-series') | ||
const defaultConfig = require('./default-config.json') | ||
|
||
module.exports = Factory | ||
|
||
function Factory () { | ||
if (!(this instanceof Factory)) { | ||
return new Factory() | ||
} | ||
|
||
const nodes = [] | ||
|
||
/* yields a new started node */ | ||
this.spawnNode = (repoPath, config, callback) => { | ||
if (typeof repoPath === 'function') { | ||
callback = repoPath | ||
repoPath = undefined | ||
} | ||
if (typeof config === 'function') { | ||
callback = config | ||
config = undefined | ||
} | ||
|
||
if (!repoPath) { | ||
repoPath = '/tmp/.ipfs-' + Math.random() | ||
.toString() | ||
.substring(2, 8) | ||
} | ||
|
||
if (!config) { | ||
config = JSON.parse(JSON.stringify(defaultConfig)) | ||
const pId = PeerId.create({ bits: 32 }).toJSON() | ||
config.Identity.PeerID = pId.id | ||
config.Identity.PrivKey = pId.privKey | ||
} | ||
|
||
// set up the repo | ||
const repo = new IPFSRepo(repoPath, { | ||
stores: require('fs-blob-store') | ||
}) | ||
repo.teardown = (done) => { | ||
cleanRepo(repoPath) | ||
done() | ||
} | ||
|
||
// create the IPFS node | ||
const ipfs = new IPFS(repo) | ||
ipfs.init({ emptyRepo: true }, (err) => { | ||
if (err) { | ||
return callback(err) | ||
} | ||
repo.config.set(config, launchNode) | ||
}) | ||
|
||
function launchNode () { | ||
// create the IPFS node through the HTTP-API | ||
const node = new HTTPAPI(repo) | ||
nodes.push({ | ||
httpApi: node, | ||
repo: repo | ||
}) | ||
|
||
node.start((err) => { | ||
if (err) { | ||
return callback(err) | ||
} | ||
console.log(node.apiMultiaddr) | ||
const ctl = IPFSAPI(node.apiMultiaddr) | ||
callback(null, ctl) | ||
}) | ||
} | ||
} | ||
|
||
this.dismantle = function (callback) { | ||
series(nodes.map((node) => { | ||
return node.httpApi.stop | ||
}), clean) | ||
|
||
function clean (err) { | ||
if (err) { | ||
return callback(err) | ||
} | ||
series( | ||
nodes.map((node) => { | ||
return node.repo.teardown | ||
}), | ||
callback | ||
) | ||
} | ||
} | ||
} |