Add IceCandidate, SdpMid, Turn BNF structures from Framboise

This commit is contained in:
Christoph Diehl 2017-11-28 21:40:13 +03:00
parent 88d3051fc3
commit 6df44b5f63

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
make.network = { make.network = {
sdp: function () { sdp () {
// session description protocol template // session description protocol template
return [ return [
'v=0', 'v=0',
@ -38,16 +38,82 @@ make.network = {
'a=candidate:0 2 UDP 2113601790 192.168.129.33 62658 typ host' 'a=candidate:0 2 UDP 2113601790 192.168.129.33 62658 typ host'
].join('\n') ].join('\n')
}, },
PeerConnectionProtocols: function () { IceCandidate () {
// https://tools.ietf.org/html/rfc5245#section-15
// candidate=
return utils.block.block([
random.pick([0, 1, make.number.any]),
' ',
random.pick([0, 1, make.number.any]),
' ',
random.pick(['UDP', 'TCP', 'SCTP']),
random.pick(['', '/' + random.pick(['DTLS', 'DTLS-SRTP'])]),
' ',
random.pick([make.number.any]),
' ',
random.pick([make.network.goodHostnames]),
' ',
random.pick([56187, make.number.any]),
' ',
'type',
' ',
random.pick([
'host',
utils.block.block([
random.pick(['srflx','prflx', 'relay']),
' ',
random.pick(['raddr']),
' ',
random.pick([make.network.goodHostnames]),
' ',
random.pick(['rport']),
random.use([utils.block.block([' ', make.number.any])])
])
])
])
},
SdpMid() {
// m=
return utils.block.block([
random.pick(['application', 'video', 'audio']),
' ',
make.number.any,
' ',
random.pick(['RTP/AVP', 'RTP/SAVPF', 'RTP/SAVP', 'SCTP/DTLS']),
' ',
make.number.any
])
},
Turn() {
// https://tools.ietf.org/html/rfc7065#section-3.1
return utils.block.block([
// scheme
random.pick(make.network.PeerConnectionProtocols),
':',
// turn-host
random.pick([
make.text.any,
make.network.hostname
]),
// turn-port
random.use([utils.block.block([':', make.number.any])]),
random.use([utils.block.block(['/', make.text.any])]),
'?',
random.pick(['transport']),
'=',
random.pick(['udp', 'tcp', make.text.any])
])
},
PeerConnectionProtocols () {
return ['turn', 'turns', 'stun', 'stuns'] return ['turn', 'turns', 'stun', 'stuns']
}, },
randomIPv4: function () { randomIPv4 () {
return random.pick([random.number(255), make.number.any]) + '.' + return random.pick([random.number(255), make.number.any]) + '.' +
random.pick([random.number(255), make.number.any]) + '.' + random.pick([random.number(255), make.number.any]) + '.' +
random.pick([random.number(255), make.number.any]) + '.' + random.pick([random.number(255), make.number.any]) + '.' +
random.pick([random.number(255), make.number.any]) random.pick([random.number(255), make.number.any])
}, },
randomIPv6: function () { randomIPv6 () {
let parts = [] let parts = []
for (let i = 0; i < 8; i++) { for (let i = 0; i < 8; i++) {
@ -66,15 +132,15 @@ make.network = {
'*', '#', '*', '#',
'A', 'B', 'C', 'D', 'A', 'B', 'C', 'D',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9' '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
], make.numbers.range()).join('') ], make.number.range()).join('')
}, },
goodHostnames: function () { goodHostnames () {
return [ return [
'0.0.0.0', '0.0.0.0',
'127.0.0.1:8080' '127.0.0.1:8080'
] ]
}, },
badHostnames: function () { badHostnames () {
return [ return [
'google.org:8080', 'google.org:8080',
'::1', '::1',
@ -89,25 +155,52 @@ make.network = {
'2001:db8::1:1:1:1:1' '2001:db8::1:1:1:1:1'
] ]
}, },
hostname: function () { hostname () {
return random.pick([this.randomIPv4, this.randomIPv6, this.goodHostnames, this.badHostnames]) return random.pick([
this.randomIPv4,
this.randomIPv6,
this.goodHostnames,
this.badHostnames
])
}, },
port: function () { port () {
return random.pick([80, 443, 21, 23, 9310]) return random.pick([80, 443, 21, 23, 9310])
}, },
hash: function () { hash () {
return random.pick(['', '#', '#main-content', function () { return '#' + make.text.any() }]) return random.pick([
'',
'#',
'#main-content',
() => '#' + make.text.any()
])
}, },
path: function () { path () {
return random.pick(['', '/', '/index.html', function () { return '/' + make.text.any() }]) return random.pick([
'',
'/',
'/index.html',
() => '/' + make.text.any()
])
}, },
protocol: function () { protocol () {
return random.pick(['http:', 'https:', 'ftp:', 'telnet:', 'chrome:', 'resource:']) return random.pick([
'http',
'https',
'ftp',
'telnet',
'chrome',
'resource'
]) + ':'
}, },
search: function () { search () {
return random.pick(['', '?', '?foo=bar', function () { return '?' + make.text.any() }]) return random.pick([
'',
'?',
'?foo=bar',
() => '?' + make.text.any()
])
}, },
randomBitmask: function (list) { randomBitmask (list) {
if (list.length <= 1) { if (list.length <= 1) {
return list.join('') return list.join('')
} }