Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/p2p addrs situation #18

Merged
merged 4 commits into from
Sep 3, 2017
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
43 changes: 38 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
node_modules
**/node_modules/
**/*.log
test/repo-tests*
**/bundle.js

# Logs
logs
*.log

dist
coverage

*.log
# 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

.vscode
.history
# while testing npm5
package-lock.json
28 changes: 18 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
sudo: false
language: node_js
node_js:
- 4
- 5

# Make sure we have new NPM.
before_install:
- npm install -g npm
matrix:
include:
- node_js: 6
env: CXX=g++-4.8
- 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

addons:
firefox: 'latest'
- make test

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

after_success:
- npm run coverage-publish

addons:
firefox: 'latest'
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
},
"homepage": "https://github.com/whyrusleeping/js-mafmt#readme",
"devDependencies": {
"aegir": "^11.0.1",
"chai": "^3.5.0",
"aegir": "^11.0.2",
"chai": "^4.1.2",
"pre-commit": "^1.2.2"
},
"dependencies": {
"multiaddr": "^2.2.3"
"multiaddr": "^3.0.0"
},
"contributors": [
"David Dias <daviddias.p@gmail.com>",
Expand All @@ -47,4 +47,4 @@
"dignifiedquire <dignifiedquire@gmail.com>",
"dmitriy ryajov <dryajov@dmitriys-MBP.HomeNET>"
]
}
}
26 changes: 19 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ const HTTP = or(
)

const WebRTCStar = or(
and(base('libp2p-webrtc-star'), WebSockets, base('ipfs')),
and(base('libp2p-webrtc-star'), WebSocketsSecure, base('ipfs'))
and(WebSockets, base('p2p-webrtc-star'), base('ipfs')),
and(WebSocketsSecure, base('p2p-webrtc-star'), base('ipfs'))
)

const WebRTCDirect = and(base('libp2p-webrtc-direct'), HTTP)
const WebSocketsStar = or(
and(WebSockets, base('p2p-websockets-star')),
and(WebSockets, base('p2p-websockets-star'), base('ipfs')),
and(WebSocketsSecure, base('p2p-websockets-star'), base('ipfs'))
)

const WebRTCDirect = and(HTTP, base('p2p-webrtc-direct'))

const Reliable = or(
WebSockets,
Expand Down Expand Up @@ -96,6 +102,7 @@ exports.UTP = UTP
exports.HTTP = HTTP
exports.WebSockets = WebSockets
exports.WebSocketsSecure = WebSocketsSecure
exports.WebSocketsStar = WebSocketsStar
exports.WebRTCStar = WebRTCStar
exports.WebRTCDirect = WebRTCDirect
exports.Reliable = Reliable
Expand Down Expand Up @@ -124,8 +131,11 @@ function and () {
if (a.length < args.length) {
return null
}
args.some(function (arg) {
a = typeof arg === 'function' ? arg().partialMatch(a) : arg.partialMatch(a)
args.some((arg) => {
a = typeof arg === 'function'
? arg().partialMatch(a)
: arg.partialMatch(a)

if (a === null) {
return true
}
Expand Down Expand Up @@ -157,8 +167,10 @@ function or () {

function partialMatch (a) {
let out = null
args.some(function (arg) {
const res = typeof arg === 'function' ? arg().partialMatch(a) : arg.partialMatch(a)
args.some((arg) => {
const res = typeof arg === 'function'
? arg().partialMatch(a)
: arg.partialMatch(a)
if (res) {
out = res
return true
Expand Down
35 changes: 22 additions & 13 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,26 @@ describe('multiaddr validation', function () {
]

const goodWebRTCStar = [
'/libp2p-webrtc-star/ip4/1.2.3.4/tcp/3456/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/libp2p-webrtc-star/dns/ipfs.io/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/libp2p-webrtc-star/dns/ipfs.io/wss/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/libp2p-webrtc-star/ip6/::/tcp/0/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo5'
'/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/dns/ipfs.io/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/dns/ipfs.io/wss/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/ip6/::/tcp/0/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo5'
]

const goodWebRTCDirect = [
// '/libp2p-webrtc-direct/dns/ipfs.io',
'/libp2p-webrtc-direct/ip4/1.2.3.4/tcp/3456/http',
'/libp2p-webrtc-direct/ip6/::/tcp/0/http'
'/ip4/1.2.3.4/tcp/3456/http/p2p-webrtc-direct',
'/ip6/::/tcp/0/http/p2p-webrtc-direct'
]

const goodWebSocketsStar = [
'/ip4/1.2.3.4/tcp/3456/ws/p2p-websockets-star',
'/ip6/::/tcp/0/ws/p2p-websockets-star'
]

const badWS = [
'/ip4/0.0.0.0/tcp/12345/udp/2222/ws',
'/ip6/::/ip4/0.0.0.0/udp/1234/ws',
'/libp2p-webrtc-star/ip4/127.0.0.1/tcp/24642/ws'
'/ip4/127.0.0.1/tcp/24642/ws/p2p-webrtc-star'
]

const badWSS = [
Expand All @@ -100,7 +104,7 @@ describe('multiaddr validation', function () {
'/p2p-circuit',
'/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
'/p2p-circuit/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
'/p2p-circuit/libp2p-webrtc-star/ip4/1.2.3.4/tcp/3456/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/p2p-circuit/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/p2p-circuit/ip4/1.2.3.4/tcp/3456/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/p2p-circuit/ip4/127.0.0.1/tcp/4002/ipfs/QmddWMcQX6orJGHpETYMyPgXrCXCtYANMFVDCvhKoDwLqA',
'/p2p-circuit/ipfs/QmddWMcQX6orJGHpETYMyPgXrCXCtYANMFVDCvhKoDwLqA',
Expand All @@ -113,12 +117,12 @@ describe('multiaddr validation', function () {
'/ip4/0.0.7.6/udp/1234',
'/ip6/::/udp/0/utp',
'/dns/ipfs.io/ws',
'/libp2p-webrtc-direct/ip4/1.2.3.4/tcp/3456/http'
'/ip4/1.2.3.4/tcp/3456/http/p2p-webrtc-star'
]

const goodIPFS = [
'/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
'/libp2p-webrtc-star/ip4/1.2.3.4/tcp/3456/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/ip4/1.2.3.4/tcp/3456/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit',
'/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj'
Expand Down Expand Up @@ -182,12 +186,17 @@ describe('multiaddr validation', function () {
assertMismatches(mafmt.WebSocketsSecure, goodIP, badWSS, goodUDP, badWS)
})

it('WebRTC-star validation', function () {
it('WebSocketsStar validation', function () {
assertMatches(mafmt.WebSocketsStar, goodWebSocketsStar)
assertMismatches(mafmt.WebSocketsStar, goodIP, goodUDP, badWS)
})

it('WebRTCStar validation', function () {
assertMatches(mafmt.WebRTCStar, goodWebRTCStar)
assertMismatches(mafmt.WebRTCStar, goodIP, goodUDP, badWS)
})

it('WebRTC-direct validation', function () {
it('WebRTCDirect validation', function () {
assertMatches(mafmt.WebRTCDirect, goodWebRTCDirect)
assertMismatches(mafmt.WebRTCDirect, goodIP, goodUDP, badWS)
})
Expand Down