add validator for webrtc-star-check

This commit is contained in:
David Dias 2016-05-21 19:57:26 +01:00
parent bb32f0068d
commit eefa364ed6
3 changed files with 12 additions and 2 deletions

View File

@ -39,7 +39,7 @@
"pre-commit": "^1.1.2"
},
"dependencies": {
"multiaddr": "^2.0.0"
"multiaddr": "^2.0.2"
},
"contributors": [
"David Dias <daviddias.p@gmail.com>",

View File

@ -7,6 +7,7 @@ var TCP = and(IP, base('tcp'))
var UDP = and(IP, base('udp'))
var UTP = and(UDP, base('utp'))
var WebSockets = and(TCP, base('ws'))
var WebRTCStar = and(base('libp2p-webrtc-star'), WebSockets)
var Reliable = or(TCP, UTP)
var IPFS = and(Reliable, base('ipfs'))
@ -15,6 +16,7 @@ exports.TCP = TCP
exports.UDP = UDP
exports.UTP = UTP
exports.WebSockets = WebSockets
exports.WebRTCStar = WebRTCStar
exports.Reliable = Reliable
exports.IPFS = IPFS

View File

@ -51,6 +51,11 @@ describe('multiaddr validation', function () {
'/ip6/::/tcp/0/ws'
]
var goodWebRTCStar = [
'/libp2p-webrtc-star/ip4/1.2.3.4/tcp/3456/ws',
'/libp2p-webrtc-star/ip6/::/tcp/0/ws'
]
var badWS = [
'/ip4/0.0.0.0/tcp/12345/udp/2222/ws',
'/ip6/::/ip4/0.0.0.0/udp/1234/ws'
@ -91,5 +96,8 @@ describe('multiaddr validation', function () {
assertMatches(mafmt.WebSockets, goodWS)
assertMismatches(mafmt.WebSockets, goodIP, goodUDP, badWS)
assertMatches(mafmt.WebRTCStar, goodWebRTCStar)
assertMismatches(mafmt.WebRTCStar, goodIP, goodUDP, badWS)
})
})