Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

swarm, tests and readme badgers #1

Merged
merged 1 commit into from
Feb 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# js-libp2p-ipfs
libp2p build (module) used in js-ipfs
js-libp2p-ipfs
==============

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
![Build Status](https://travis-ci.org/ipfs/js-libp2p-ipfs.svg?style=flat-square)](https://travis-ci.org/ipfs/js-libp2p-ipfs)
![](https://img.shields.io/badge/coverage-%3F-yellow.svg?style=flat-square)
[![Dependency Status](https://david-dm.org/ipfs/js-libp2p-ipfs.svg?style=flat-square)](https://david-dm.org/ipfs/js-libp2p-ipfs)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)

> libp2p build (module) used in js-ipfs
37 changes: 37 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "libp2p-ipfs",
"version": "0.0.0",
"description": "The libp2p build (module) used by js-ipfs on Node.js",
"main": "src/index.js",
"scripts": {
"test": "mocha tests/test-*.js",
"lint": "standard"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ipfs/js-libp2p-ipfs.git"
},
"keywords": [
"IPFS"
],
"author": "David Dias <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/ipfs/js-libp2p-ipfs/issues"
},
"homepage": "https://github.com/ipfs/js-libp2p-ipfs#readme",
"devDependencies": {
"chai": "^3.5.0",
"mocha": "^2.4.5",
"pre-commit": "^1.1.2",
"standard": "^6.0.7"
},
"dependencies": {
"libp2p-spdy": "^0.1.0",
"libp2p-swarm": "^0.5.5",
"libp2p-tcp": "^0.1.2",
"multiaddr": "^1.1.1",
"peer-id": "^0.5.0",
"peer-info": "^0.4.0"
}
}
32 changes: 32 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const Swarm = require('libp2p-swarm')
const tcp = require('libp2p-tcp')
// const utp = require('libp2p-utp')
var Spdy = require('libp2p-spdy')

exports = module.exports = libp2p

function libp2p (options) {
// options.peer - my Peer Info
// options.multiaddrs = { tcp: <multiaddr> , utp: <multiaddr>}
//
const swarm = new Swarm(options.peer)
swarm.addStreamMuxer('spdy', Spdy, {})

return {
listen: (callback) => {
// add the transports
// spdy and stuff
swarm.addTransport('tcp',
tcp,
{ multiaddr: options.multiaddrs.tcp },
{},
{ port: options.multiaddrs.tcp.toString().split('/')[4] },
() => {
callback()
})
},
records: '',
routing: '',
swarm: swarm
}
}
60 changes: 60 additions & 0 deletions tests/test-libp2p-ipfs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* globals describe, it */

const expect = require('chai').expect
const libp2p = require('../src')
const Id = require('peer-id')
const Peer = require('peer-info')
const multiaddr = require('multiaddr')

describe('libp2p-ipfs', () => {
const idA = Id.create()
const idB = Id.create()
const peerA = new Peer(idA, [])
const peerB = new Peer(idB, [])

var nodeA
var nodeB

it('prepare node A', (done) => {
const options = {
peer: peerA,
multiaddrs: {
tcp: multiaddr('/ip4/127.0.0.1/tcp/8010')
}
}

nodeA = libp2p(options)
nodeA.listen((err) => {
expect(err).to.not.exist
done()
})
})
it('prepare node B', (done) => {
const options = {
peer: peerB,
multiaddrs: {
tcp: multiaddr('/ip4/127.0.0.1/tcp/8020')
}
}

nodeB = libp2p(options)
nodeB.listen((err) => {
expect(err).to.not.exist
done()
})
})

it('B handle /echo/1.0.0', (done) => {
nodeB.swarm.handleProtocol('/echo/1.0.0', (conn) => {
conn.pipe(conn)
})
done()
})

it('A dial B to speak /echo/1.0.0', (done) => {
nodeA.swarm.dial(peerB, {}, '/echo/1.0.0', (err, conn) => {
expect(err).to.not.exist
done()
})
})
})