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: Add /p2p-stardust #35

Merged
merged 1 commit into from
Feb 7, 2019
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"chai": "^4.2.0"
},
"dependencies": {
"multiaddr": "^6.0.3"
"multiaddr": "^6.0.4"
},
"contributors": [
"Alan Shaw <alan@tableflip.io>",
Expand Down
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ const Reliable = or(
UTP
)

// Unlike ws-star, stardust can run over any transport thus removing the requirement for websockets (but don't even think about running a stardust server over webrtc-star ;) )
const Stardust = or(
and(Reliable, base('p2p-stardust'), base('ipfs')),
mkg20001 marked this conversation as resolved.
Show resolved Hide resolved
and(Reliable, base('p2p-stardust'))
)

let _IPFS = or(
and(Reliable, base('ipfs')),
WebRTCStar,
Expand Down Expand Up @@ -122,6 +128,7 @@ exports.WebSocketStar = WebSocketStar
exports.WebRTCStar = WebRTCStar
exports.WebRTCDirect = WebRTCDirect
exports.Reliable = Reliable
exports.Stardust = Stardust
exports.Circuit = Circuit
exports.IPFS = IPFS

Expand Down
27 changes: 25 additions & 2 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ describe('multiaddr validation', function () {
'/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star/ipfs/Qma3uqwymdqwXtC4uvmqqwwMhTDHD7xp9FzM75tQB5qRM3'
]

const goodStardust = [
'/ip4/1.2.3.4/tcp/3456/ws/p2p-stardust',
'/ip6/::/tcp/0/ws/p2p-stardust',
'/dnsaddr/localhost/ws/p2p-stardust/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/ip4/1.2.3.4/tcp/3456/ws/p2p-stardust/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
'/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-stardust/ipfs/Qma3uqwymdqwXtC4uvmqqwwMhTDHD7xp9FzM75tQB5qRM3'
]

const badWS = [
'/ip4/0.0.0.0/tcp/12345/udp/2222/ws',
'/ip6/::/ip4/0.0.0.0/udp/1234/ws',
Expand Down Expand Up @@ -158,7 +166,12 @@ describe('multiaddr validation', function () {
const tests = Array.from(arguments).slice(1)
tests.forEach(function (test) {
test.forEach(function (testcase) {
expect(p.matches(testcase)).to.be.eql(true)
try {
expect(p.matches(testcase)).to.be.eql(true)
} catch (err) {
err.stack = '[testcase=' + JSON.stringify(testcase) + ', shouldMatch=true] ' + err.stack
throw err
}
})
})
}
Expand All @@ -167,7 +180,12 @@ describe('multiaddr validation', function () {
const tests = Array.from(arguments).slice(1)
tests.forEach(function (test) {
test.forEach(function (testcase) {
expect(p.matches(testcase)).to.be.eql(false)
try {
expect(p.matches(testcase)).to.be.eql(false)
} catch (err) {
err.stack = '[testcase=' + JSON.stringify(testcase) + ', shouldMatch=false] ' + err.stack
throw err
}
})
})
}
Expand Down Expand Up @@ -231,6 +249,11 @@ describe('multiaddr validation', function () {
assertMismatches(mafmt.WebSocketStar, goodIP, goodUDP, badWS)
})

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

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