-
Notifications
You must be signed in to change notification settings - Fork 9
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
f504198
commit 2944a12
Showing
23 changed files
with
277 additions
and
29 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,42 @@ | ||
**/node_modules/ | ||
**/*.log | ||
test/repo-tests* | ||
**/bundle.js | ||
docs | ||
# Logs | ||
logs | ||
*.log | ||
|
||
coverage | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
build | ||
|
||
# Dependency directory | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git | ||
node_modules | ||
|
||
lib | ||
dist | ||
test/test-data/go-ipfs-repo/LOCK | ||
test/test-data/go-ipfs-repo/LOG | ||
test/test-data/go-ipfs-repo/LOG.old | ||
|
||
# while testing npm5 | ||
package-lock.json |
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,2 @@ | ||
// Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories. | ||
javascript() |
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 |
---|---|---|
@@ -1,19 +1,44 @@ | ||
{ | ||
"name": "libp2p-interop", | ||
"name": "interop-libp2p", | ||
"version": "0.0.0", | ||
"description": "", | ||
"main": " ", | ||
"description": "Interoperability Tests for libp2p", | ||
"leadMaintainer": "Vasco Santos <santos.vasco10@gmail.com>", | ||
"main": "", | ||
"engines": { | ||
"node": ">=10.0.0", | ||
"npm": ">6.0.0" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"lint": "aegir lint", | ||
"test": "cross-env IPFS_REUSEPORT=false aegir test", | ||
"test:node": "cross-env IPFS_REUSEPORT=false aegir test -t node -f test/node.js", | ||
"test:browser": "cross-env IPFS_REUSEPORT=false aegir test -t browser --no-cors -f test/browser.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/libp2p/interop.git" | ||
}, | ||
"author": "David Dias <daviddias@ipfs.io>", | ||
"keywords": [ | ||
"libp2p" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/libp2p/interop/issues" | ||
}, | ||
"homepage": "https://github.com/libp2p/interop#readme" | ||
"homepage": "https://github.com/libp2p/interop#readme", | ||
"devDependencies": { | ||
"aegir": "^17.0.1", | ||
"chai": "^4.2.0", | ||
"chai-checkmark": "^1.0.1", | ||
"cross-env": "^5.2.0", | ||
"dirty-chai": "^2.0.1", | ||
"go-libp2p-dep": "libp2p/npm-go-libp2p-dep#feat/initial-implementation", | ||
"libp2p-daemon": "~0.1.0", | ||
"libp2p-daemon-client": "~0.0.2", | ||
"rimraf": "^2.6.3" | ||
}, | ||
"contributors": [], | ||
"dependencies": { | ||
"execa": "^1.0.0" | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,111 @@ | ||
'use strict' | ||
|
||
const assert = require('assert') | ||
const execa = require('execa') | ||
const rimraf = require('rimraf') | ||
|
||
const Client = require('libp2p-daemon-client') | ||
|
||
// go-libp2p defaults | ||
const goDaemon = { | ||
defaultSock: '/tmp/p2pd-go.sock', | ||
bin: './node_modules/go-libp2p-dep/go-libp2p/p2pd' | ||
} | ||
|
||
// js-libp2p defaults | ||
const jsDaemon = { | ||
defaultSock: '/tmp/p2pd-js.sock', | ||
bin: './node_modules/libp2p-daemon/src/cli/bin.js' | ||
} | ||
|
||
class Daemon { | ||
/** | ||
* @constructor | ||
* @param {String} type daemon implementation type ("go" or "js") | ||
* @param {String} sock unix socket path | ||
*/ | ||
constructor (type, sock) { | ||
assert(type === 'go' || type === 'js', 'invalid type received. Should be "go" or "js"') | ||
|
||
this._client = undefined | ||
this._type = type | ||
this._binPath = type === 'go' ? goDaemon.bin : jsDaemon.bin | ||
this._sock = sock | ||
|
||
if (!this._sock) { | ||
this._sock = type === 'go' ? goDaemon.defaultSock : jsDaemon.defaultSock | ||
} | ||
} | ||
|
||
/** | ||
* @async | ||
* Starts a daemon and a client associated with it. | ||
* @returns {void} | ||
*/ | ||
async start () { | ||
if (this._client) { | ||
throw new Error('Daemon has already started') | ||
} | ||
|
||
// start daemon | ||
await this._startDaemon() | ||
|
||
// start client | ||
this._client = new Client(this._sock) | ||
|
||
await this._client.attach() | ||
} | ||
|
||
/** | ||
* Starts the specifiec daemon and wait for its start. | ||
* @returns {Promise} | ||
*/ | ||
_startDaemon () { | ||
return new Promise((resolve, reject) => { | ||
const options = this._type === 'go' ? ['-sock', this._sock] : ['--sock', this._sock] | ||
const daemon = execa(this._binPath, options) | ||
|
||
daemon.stdout.once('data', () => { | ||
return resolve() | ||
}) | ||
daemon.stderr.once('data', (data) => { | ||
return reject(data.toString()) | ||
}) | ||
}) | ||
} | ||
|
||
/** | ||
* @async | ||
* Stops the daemon client and cleans the unix socket. | ||
* @returns {void} | ||
*/ | ||
async stop () { | ||
await this._client && this._client.close() | ||
await this._cleanUnixSocket() | ||
} | ||
|
||
/** | ||
* Cleans the unix socket. | ||
* @returns {Promise} | ||
*/ | ||
_cleanUnixSocket () { | ||
return new Promise((resolve, reject) => { | ||
rimraf(this._sock, (err) => { | ||
if (err) { | ||
return reject(err) | ||
} | ||
resolve() | ||
}) | ||
}) | ||
} | ||
|
||
/** | ||
* libp2p client instance | ||
* @type {Client} | ||
*/ | ||
get client () { | ||
return this._client | ||
} | ||
} | ||
|
||
exports = module.exports = Daemon |
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,61 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
chai.use(require('dirty-chai')) | ||
chai.use(require('chai-checkmark')) | ||
const expect = chai.expect | ||
|
||
const Daemon = require('../src/daemon') | ||
|
||
describe('connect', () => { | ||
let goDaemon | ||
let jsDaemon | ||
|
||
// Start Daemons | ||
beforeEach(async function () { | ||
goDaemon = new Daemon('go') | ||
jsDaemon = new Daemon('js') | ||
|
||
await goDaemon.start() | ||
await jsDaemon.start() | ||
}) | ||
|
||
// Stop daemons | ||
afterEach(async function () { | ||
await goDaemon.stop() | ||
await jsDaemon.stop() | ||
}) | ||
|
||
it('a js peer should be able to connect with a go peer', async function () { | ||
this.timeout(10 * 1000) | ||
|
||
const identifyGo = await goDaemon.client.identify() | ||
|
||
const knownPeersBeforeConnect = await jsDaemon.client.listPeers() | ||
expect(knownPeersBeforeConnect).to.have.lengthOf(0) | ||
|
||
// connect peers | ||
await jsDaemon.client.connect(identifyGo.peerId, identifyGo.addrs) | ||
|
||
const knownPeersAfterConnect = await jsDaemon.client.listPeers() | ||
expect(knownPeersAfterConnect).to.have.lengthOf(1) | ||
expect(knownPeersAfterConnect[0].toB58String()).to.equal(identifyGo.peerId.toB58String()) | ||
}) | ||
|
||
it.skip('a go peer should be able to connect with a js peer', async function () { | ||
this.timeout(10 * 1000) | ||
|
||
const identifyJs = await jsDaemon.client.identify() | ||
|
||
const knownPeersBeforeConnect = await goDaemon.client.listPeers() | ||
expect(knownPeersBeforeConnect).to.have.lengthOf(0) | ||
|
||
// connect peers | ||
await goDaemon.client.connect(identifyJs.peerId, identifyJs.addrs) | ||
|
||
const knownPeersAfterConnect = await goDaemon.client.listPeers() | ||
expect(knownPeersAfterConnect).to.have.lengthOf(1) | ||
expect(knownPeersAfterConnect[0].toB58String()).to.equal(identifyJs.peerId.toB58String()) | ||
}) | ||
}) |
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,4 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
require('./connect') |