Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
feat: new aegir
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias authored Oct 20, 2017
1 parent f120f84 commit 3d3cdf1
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 50 deletions.
22 changes: 22 additions & 0 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const multiaddr = require('multiaddr')
const pull = require('pull-stream')

const WS = require('./src')

let listener

module.exports = {
hooks: {
browser: {
pre (callback) {
const ws = new WS()
const ma = multiaddr('/ip4/127.0.0.1/tcp/9090/ws')
listener = ws.createListener((conn) => pull(conn, conn))
listener.listen(ma, callback)
},
post (callback) {
listener.close(callback)
}
}
}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package-lock.json
yarn.lock

# Logs
logs
*.log
Expand Down Expand Up @@ -36,3 +39,4 @@ node_modules
*.swp

dist

4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ language: node_js

matrix:
include:
- node_js: 4
env: CXX=g++-4.8
- node_js: 6
env:
- SAUCE=true
- CXX=g++-4.8
- node_js: "stable"
env:
env:
- CXX=g++-4.8

# Make sure we have new NPM.
Expand Down
8 changes: 5 additions & 3 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ machine:
dependencies:
pre:
- google-chrome --version
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
- sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
- curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
- sudo dpkg -i google-chrome.deb || true
- sudo apt-get update
- sudo apt-get --only-upgrade install google-chrome-stable
- sudo apt-get install -f
- sudo apt-get install --only-upgrade lsb-base
- sudo dpkg -i google-chrome.deb
- google-chrome --version
24 changes: 0 additions & 24 deletions gulpfile.js

This file was deleted.

25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
"description": "JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport spec",
"main": "src/index.js",
"scripts": {
"lint": "aegir-lint",
"test": "gulp test",
"test:node": "gulp test:node",
"test:browser": "gulp test:browser",
"build": "gulp build",
"release": "gulp release",
"release-minor": "gulp release --type minor",
"release-major": "gulp release --type major",
"coverage": "gulp coverage",
"coverage-publish": "aegir-coverage publish"
"lint": "aegir lint",
"test": "aegir test",
"test:node": "aegir test --target=node",
"test:browser": "aegir test --target=browser",
"build": "aegir build",
"release": "aegir release",
"release-minor": "aegir release --type minor",
"release-major": "aegir release --type major",
"coverage": "aegir coverage",
"coverage-publish": "aegir coverage --upload"
},
"browser": {
"pull-ws/server": false
Expand Down Expand Up @@ -42,15 +42,16 @@
"pull-ws": "^3.2.9"
},
"devDependencies": {
"aegir": "^11.0.2",
"aegir": "github:ipfs/aegir",
"chai": "^4.1.1",
"dirty-chai": "^2.0.1",
"gulp": "^3.9.1",
"interface-transport": "~0.3.5",
"multiaddr": "^3.0.1",
"pre-commit": "^1.2.2",
"pull-goodbye": "0.0.2",
"pull-stream": "^3.6.0"
"pull-stream": "^3.6.0",
"safe-buffer": "^5.1.1"
},
"contributors": [
"Chris Campbell <[email protected]>",
Expand Down
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ class WebSockets {
log('dialing %s', url)
const socket = connect(url, {
binary: true,
onConnect: (err) => callback(err)
onConnect: (err) => {
callback(err)
}
})

const conn = new Connection(socket)
conn.getObservedAddrs = (callback) => callback(null, [ma])
conn.close = (callback) => socket.close(callback)
conn.getObservedAddrs = (cb) => cb(null, [ma])
conn.close = (cb) => socket.close(cb)

return conn
}
Expand Down
13 changes: 8 additions & 5 deletions test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ describe('libp2p-websockets', () => {
beforeEach((done) => {
ws = new WS()
expect(ws).to.exist()
conn = ws.dial(ma, done)
conn = ws.dial(ma, (err, res) => {
expect(err).to.not.exist()
done()
})
})

it('echo', (done) => {
Expand All @@ -30,7 +33,7 @@ describe('libp2p-websockets', () => {
source: pull.values([message]),
sink: pull.collect((err, results) => {
expect(err).to.not.exist()
expect(results).to.be.eql([message])
expect(results).to.eql([message])
done()
})
})
Expand All @@ -40,13 +43,13 @@ describe('libp2p-websockets', () => {

describe('stress', () => {
it('one big write', (done) => {
const rawMessage = new Buffer(1000000).fill('a')
const rawMessage = Buffer.allocUnsafe(1000000).fill('a')

const s = goodbye({
source: pull.values([rawMessage]),
sink: pull.collect((err, results) => {
expect(err).to.not.exist()
expect(results).to.be.eql([rawMessage])
expect(results).to.eql([rawMessage])
done()
})
})
Expand All @@ -58,7 +61,7 @@ describe('libp2p-websockets', () => {
source: pull(
pull.infinite(),
pull.take(1000),
pull.map((val) => Buffer(val.toString()))
pull.map((val) => Buffer.from(val.toString()))
),
sink: pull.collect((err, result) => {
expect(err).to.not.exist()
Expand Down

0 comments on commit 3d3cdf1

Please sign in to comment.