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

Commit

Permalink
feat: use new API and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Mar 27, 2017
1 parent 84e4005 commit 39c2f7b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 57 deletions.
31 changes: 3 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
This libp2p build has support for:

- WebSockets and WebRTC
- SPDY stream multiplexing
- SPDY and mplex stream multiplexing
- secio encrypted channels
- Identify STUN protocol

Expand All @@ -29,17 +29,6 @@ This libp2p build has support for:
- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [start](#start)
- [stop](#stop)
- [dialById](#dialbyid)
- [dialByMultiaddr](#dialbymultiaddr)
- [dialByPeerInfo](#dialbypeerinfo)
- [hangUpById](#hangupbyid)
- [hangUpByMultiaddr](#hangupbymultiaddr)
- [hangUpByPeerInfo](#hangupbypeerinfo)
- [handle](#handle)
- [unhandle](#unhandle)
- [discovery](#discovery)
- [Contribute](#contribute)
- [License](#license)

Expand All @@ -52,26 +41,12 @@ npm install --save libp2p-ipfs-browser
## Usage

```js
const libp2p-ipfs-browser = require('libp2p-ipfs-browser')

libp2p-ipfs-browser.start()
const Node = require('libp2p-ipfs-browser')
```

## API

### start
### stop
### dialById
### dialByMultiaddr
### dialByPeerInfo
### hangUpById
### hangUpByMultiaddr
### hangUpByPeerInfo
### handle
### unhandle
### discovery

This will create a new instance of an `events` `EventEmitter`.
API docs can be found at https://github.com/libp2p/js-libp2p#usage

## Contribute

Expand Down
4 changes: 1 addition & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ gulp.task('libnode:start', (done) => {

node = new Node(peer)
node.start(() => {
node.handle('/echo/1.0.0', (protocol, conn) => {
pull(conn, conn)
})
node.handle('/echo/1.0.0', (protocol, conn) => pull(conn, conn))
ready()
})
}
Expand Down
8 changes: 4 additions & 4 deletions test/webrtc-star-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('libp2p-ipfs-browser (webrtc only)', () => {
})

it('dial from the second node to the first node', (done) => {
node1.dialByPeerInfo(peer2, '/echo/1.0.0', (err, conn) => {
node1.dial(peer2, '/echo/1.0.0', (err, conn) => {
expect(err).to.not.exist()
setTimeout(check, 500)

Expand All @@ -89,7 +89,7 @@ describe('libp2p-ipfs-browser (webrtc only)', () => {
})

it('node1 hangUp node2', (done) => {
node1.hangUpByPeerInfo(peer2, (err) => {
node1.hangUp(peer2, (err) => {
expect(err).to.not.exist()
setTimeout(check, 500)

Expand Down Expand Up @@ -121,8 +121,8 @@ describe('libp2p-ipfs-browser (webrtc only)', () => {
const mh3 = multiaddr('/libp2p-webrtc-star/ip4/127.0.0.1/tcp/15555/ws/ipfs/' + id3.toB58String())
peer3.multiaddr.add(mh3)

node1.discovery.on('peer', (peerInfo) => node1.dialByPeerInfo(peerInfo, check))
node2.discovery.on('peer', (peerInfo) => node2.dialByPeerInfo(peerInfo, check))
node1.on('peer', (peerInfo) => node1.dial(peerInfo, check))
node2.on('peer', (peerInfo) => node2.dial(peerInfo, check))

const node3 = new Node(peer3, null, { webRTCStar: true })
node3.start(check)
Expand Down
37 changes: 15 additions & 22 deletions test/websockets-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ describe('libp2p-ipfs-browser (websockets only)', () => {

// General connectivity tests

it('libp2p.dialByMultiaddr nodeA to nodeB', (done) => {
nodeA.dialByMultiaddr(peerB.multiaddrs[0], (err) => {
it('libp2p.dial using Multiaddr nodeA to nodeB', (done) => {
nodeA.dial(peerB.multiaddrs[0], (err) => {
expect(err).to.not.exist()
// Some time for Identify to finish
setTimeout(check, 500)
Expand All @@ -75,12 +75,11 @@ describe('libp2p-ipfs-browser (websockets only)', () => {
expect(Object.keys(peers)).to.have.length(1)
done()
}
// TODO confirm that we got the pubkey through identify
})
})

it('libp2p.dialByMultiaddr on Protocol nodeA to nodeB', (done) => {
nodeA.dialByMultiaddr(peerB.multiaddrs[0], '/echo/1.0.0', (err, conn) => {
it('libp2p.dial using Multiaddr on Protocol nodeA to nodeB', (done) => {
nodeA.dial(peerB.multiaddrs[0], '/echo/1.0.0', (err, conn) => {
expect(err).to.not.exist()
const peers = nodeA.peerBook.getAll()
expect(err).to.not.exist()
Expand All @@ -98,8 +97,8 @@ describe('libp2p-ipfs-browser (websockets only)', () => {
})
})

it('libp2p.hangupByMultiaddr nodeA to nodeB', (done) => {
nodeA.hangUpByMultiaddr(peerB.multiaddrs[0], (err) => {
it('libp2p.hangUp using Multiaddr nodeA to nodeB', (done) => {
nodeA.hangUp(peerB.multiaddrs[0], (err) => {
expect(err).to.not.exist()
setTimeout(check, 500)

Expand All @@ -113,8 +112,8 @@ describe('libp2p-ipfs-browser (websockets only)', () => {
})
})

it('libp2p.dialByPeerInfo nodeA to nodeB', (done) => {
nodeA.dialByPeerInfo(peerB, (err) => {
it('libp2p.dial using PeerInfo nodeA to nodeB', (done) => {
nodeA.dial(peerB, (err) => {
expect(err).to.not.exist()
// Some time for Identify to finish
setTimeout(check, 500)
Expand All @@ -129,8 +128,8 @@ describe('libp2p-ipfs-browser (websockets only)', () => {
})
})

it('libp2p.dialByPeerInfo on Protocol nodeA to nodeB', (done) => {
nodeA.dialByPeerInfo(peerB, '/echo/1.0.0', (err, conn) => {
it('libp2p.dial using PeerInfo on Protocol nodeA to nodeB', (done) => {
nodeA.dial(peerB, '/echo/1.0.0', (err, conn) => {
expect(err).to.not.exist()
const peers = nodeA.peerBook.getAll()
expect(err).to.not.exist()
Expand All @@ -141,15 +140,15 @@ describe('libp2p-ipfs-browser (websockets only)', () => {
conn,
pull.collect((err, data) => {
expect(err).to.not.exist()
expect(data).to.be.eql([Buffer('hey')])
expect(data).to.eql([Buffer('hey')])
done()
})
)
})
})

it('libp2p.hangupByPeerInfo nodeA to nodeB', (done) => {
nodeA.hangUpByPeerInfo(peerB, (err) => {
it('libp2p.hangUp using PeerInfo nodeA to nodeB', (done) => {
nodeA.hangUp(peerB, (err) => {
expect(err).to.not.exist()
setTimeout(check, 500)

Expand All @@ -163,15 +162,9 @@ describe('libp2p-ipfs-browser (websockets only)', () => {
})
})

// NOTE, these dialById only works if a previous dial was made
// until we have PeerRouting
it.skip('libp2p.dialById nodeA to nodeB', (done) => {})
it.skip('libp2p.dialById on Protocol nodeA to nodeB', (done) => {})
it.skip('libp2p.hangupById nodeA to nodeB', (done) => {})

describe('stress', () => {
it('one big write', (done) => {
nodeA.dialByPeerInfo(peerB, '/echo/1.0.0', (err, conn) => {
nodeA.dial(peerB, '/echo/1.0.0', (err, conn) => {
expect(err).to.not.exist()
const rawMessage = new Buffer(100000)
rawMessage.fill('a')
Expand All @@ -190,7 +183,7 @@ describe('libp2p-ipfs-browser (websockets only)', () => {
})

it('many writes', (done) => {
nodeA.dialByPeerInfo(peerB, '/echo/1.0.0', (err, conn) => {
nodeA.dial(peerB, '/echo/1.0.0', (err, conn) => {
expect(err).to.not.exist()

const s = serializer(goodbye({
Expand Down

0 comments on commit 39c2f7b

Please sign in to comment.