diff --git a/lib/make/network.js b/lib/make/network.js index 5f8ecdc..cdf779d 100644 --- a/lib/make/network.js +++ b/lib/make/network.js @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ make.network = { - sdp: function () { + sdp () { // session description protocol template return [ 'v=0', @@ -38,16 +38,82 @@ make.network = { 'a=candidate:0 2 UDP 2113601790 192.168.129.33 62658 typ host' ].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'] }, - randomIPv4: function () { + randomIPv4 () { 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]) }, - randomIPv6: function () { + randomIPv6 () { let parts = [] for (let i = 0; i < 8; i++) { @@ -66,15 +132,15 @@ make.network = { '*', '#', 'A', 'B', 'C', 'D', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' - ], make.numbers.range()).join('') + ], make.number.range()).join('') }, - goodHostnames: function () { + goodHostnames () { return [ '0.0.0.0', '127.0.0.1:8080' ] }, - badHostnames: function () { + badHostnames () { return [ 'google.org:8080', '::1', @@ -89,25 +155,52 @@ make.network = { '2001:db8::1:1:1:1:1' ] }, - hostname: function () { - return random.pick([this.randomIPv4, this.randomIPv6, this.goodHostnames, this.badHostnames]) + hostname () { + return random.pick([ + this.randomIPv4, + this.randomIPv6, + this.goodHostnames, + this.badHostnames + ]) }, - port: function () { + port () { return random.pick([80, 443, 21, 23, 9310]) }, - hash: function () { - return random.pick(['', '#', '#main-content', function () { return '#' + make.text.any() }]) + hash () { + return random.pick([ + '', + '#', + '#main-content', + () => '#' + make.text.any() + ]) }, - path: function () { - return random.pick(['', '/', '/index.html', function () { return '/' + make.text.any() }]) + path () { + return random.pick([ + '', + '/', + '/index.html', + () => '/' + make.text.any() + ]) }, - protocol: function () { - return random.pick(['http:', 'https:', 'ftp:', 'telnet:', 'chrome:', 'resource:']) + protocol () { + return random.pick([ + 'http', + 'https', + 'ftp', + 'telnet', + 'chrome', + 'resource' + ]) + ':' }, - search: function () { - return random.pick(['', '?', '?foo=bar', function () { return '?' + make.text.any() }]) + search () { + return random.pick([ + '', + '?', + '?foo=bar', + () => '?' + make.text.any() + ]) }, - randomBitmask: function (list) { + randomBitmask (list) { if (list.length <= 1) { return list.join('') }