Skip to content

Commit

Permalink
feat: fix p2p addrs
Browse files Browse the repository at this point in the history
* chore: update gitignore

* chore: update CI

* chore: update deps

* feat: update protocols table

* test: update tests to new names of p2p- multiaddrs
  • Loading branch information
daviddias authored Sep 3, 2017
1 parent b86970f commit 28d8ce5
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 64 deletions.
18 changes: 14 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
**/node_modules/
**/*.log
test/repo-tests*
**/bundle.js

# Logs
logs
*.log

coverage

# Runtime data
pids
*.pid
Expand All @@ -19,14 +26,17 @@ coverage
# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
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
docs
test/test-data/go-ipfs-repo/LOCK
test/test-data/go-ipfs-repo/LOG
test/test-data/go-ipfs-repo/LOG.old

.vscode/
# while testing npm5
package-lock.json
15 changes: 5 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@ language: node_js

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

# Make sure we have new NPM.
before_install:
- npm install -g npm@4
- node_js: 8
env: CXX=g++-4.8
# - node_js: stable
# env: CXX=g++-4.8

script:
- npm run lint
- npm test
- npm run test
- npm run coverage
- make test

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@
},
"homepage": "https://github.com/multiformats/js-multiaddr",
"dependencies": {
"bs58": "^4.0.0",
"bs58": "^4.0.1",
"ip": "^1.1.5",
"lodash.filter": "^4.6.0",
"lodash.map": "^4.6.0",
"varint": "^5.0.0",
"xtend": "^4.0.1"
},
"devDependencies": {
"aegir": "^11.0.1",
"aegir": "^11.0.2",
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"dirty-chai": "^1.2.2",
"chai": "^4.1.2",
"dirty-chai": "^2.0.1",
"pre-commit": "^1.2.2"
},
"contributors": [
Expand All @@ -62,4 +62,4 @@
"greenkeeper[bot] <greenkeeper[bot]@users.noreply.github.com>",
"npm-to-cdn-bot (by Forbes Lindesay) <npmcdn-to-unpkg-bot@users.noreply.github.com>"
]
}
}
5 changes: 3 additions & 2 deletions src/protocols-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ Protocols.table = [
[443, 0, 'https'],
[477, 0, 'ws'],
[478, 0, 'wss'],
[275, 0, 'libp2p-webrtc-star'],
[276, 0, 'libp2p-webrtc-direct'],
[479, 0, 'p2p-websockets-star'],
[275, 0, 'p2p-webrtc-star'],
[276, 0, 'p2p-webrtc-direct'],
[290, 0, 'p2p-circuit']
]

Expand Down
86 changes: 43 additions & 43 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('requiring varint', () => {
describe('manipulation', () => {
it('basic', () => {
const udpAddrStr = '/ip4/127.0.0.1/udp/1234'
const udpAddrBuf = new Buffer('047f0000011104d2', 'hex')
const udpAddrBuf = Buffer.from('047f0000011104d2', 'hex')
const udpAddr = multiaddr(udpAddrStr)

expect(udpAddr.toString()).to.equal(udpAddrStr)
Expand Down Expand Up @@ -299,15 +299,22 @@ describe('variants', () => {
expect(addr.toString()).to.equal(str)
})

it('webrtc-star', () => {
const str = '/libp2p-webrtc-star/ip4/127.0.0.1/tcp/9090/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
it('p2p-webrtc-star', () => {
const str = '/ip4/127.0.0.1/tcp/9090/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC'
const addr = multiaddr(str)
expect(addr).to.have.property('buffer')
expect(addr.toString()).to.equal(str)
})

it('webrtc-direct', () => {
const str = '/libp2p-webrtc-direct/ip4/127.0.0.1/tcp/9090/http'
it('p2p-webrtc-direct', () => {
const str = '/ip4/127.0.0.1/tcp/9090/http/p2p-webrtc-direct'
const addr = multiaddr(str)
expect(addr).to.have.property('buffer')
expect(addr.toString()).to.equal(str)
})

it('p2p-websockets-star', () => {
const str = '/ip4/127.0.0.1/tcp/9090/ws/p2p-websockets-star'
const addr = multiaddr(str)
expect(addr).to.have.property('buffer')
expect(addr.toString()).to.equal(str)
Expand All @@ -317,42 +324,37 @@ describe('variants', () => {
describe('helpers', () => {
describe('.toOptions', () => {
it('returns a well formed options object', () => {
expect(
multiaddr('/ip4/0.0.0.0/tcp/1234').toOptions()
).to.be.eql({
family: 'ipv4',
host: '0.0.0.0',
transport: 'tcp',
port: '1234'
})
expect(multiaddr('/ip4/0.0.0.0/tcp/1234').toOptions())
.to.eql({
family: 'ipv4',
host: '0.0.0.0',
transport: 'tcp',
port: '1234'
})
})
})

describe('.inspect', () => {
it('renders the buffer as hex', () => {
expect(
multiaddr('/ip4/0.0.0.0/tcp/1234').inspect()
).to.be.eql(
'<Multiaddr 04000000000604d2 - /ip4/0.0.0.0/tcp/1234>'
)
expect(multiaddr('/ip4/0.0.0.0/tcp/1234').inspect())
.to.eql('<Multiaddr 04000000000604d2 - /ip4/0.0.0.0/tcp/1234>')
})
})

describe('.protos', () => {
it('returns a list of all protocols in the address', () => {
expect(
multiaddr('/ip4/0.0.0.0/utp').protos()
).to.eql([{
code: 4,
name: 'ip4',
size: 32,
resolvable: false
}, {
code: 302,
name: 'utp',
size: 0,
resolvable: false
}])
expect(multiaddr('/ip4/0.0.0.0/utp').protos())
.to.eql([{
code: 4,
name: 'ip4',
size: 32,
resolvable: false
}, {
code: 302,
name: 'utp',
size: 0,
resolvable: false
}])
})

it('works with ipfs', () => {
Expand All @@ -379,23 +381,21 @@ describe('helpers', () => {

describe('.tuples', () => {
it('returns the tuples', () => {
expect(
multiaddr('/ip4/0.0.0.0/utp').tuples()
).to.be.eql([
[4, new Buffer([0, 0, 0, 0])],
[302]
])
expect(multiaddr('/ip4/0.0.0.0/utp').tuples())
.to.eql([
[4, Buffer.from([0, 0, 0, 0])],
[302]
])
})
})

describe('.stringTuples', () => {
it('returns the string partss', () => {
expect(
multiaddr('/ip4/0.0.0.0/utp').stringTuples()
).to.be.eql([
[4, '0.0.0.0'],
[302]
])
expect(multiaddr('/ip4/0.0.0.0/utp').stringTuples())
.to.eql([
[4, '0.0.0.0'],
[302]
])
})
})

Expand Down

0 comments on commit 28d8ce5

Please sign in to comment.