Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | var protocol = exports; |
michael@0 | 2 | |
michael@0 | 3 | // |
michael@0 | 4 | // ### function parseSynHead (type, flags, data) |
michael@0 | 5 | // #### @type {Number} Frame type |
michael@0 | 6 | // #### @flags {Number} Frame flags |
michael@0 | 7 | // #### @data {Buffer} input data |
michael@0 | 8 | // Returns parsed syn_* frame's head |
michael@0 | 9 | // |
michael@0 | 10 | protocol.parseSynHead = function parseSynHead(type, flags, data) { |
michael@0 | 11 | var stream = type === 0x01; |
michael@0 | 12 | |
michael@0 | 13 | return { |
michael@0 | 14 | type: stream ? 'SYN_STREAM' : 'SYN_REPLY', |
michael@0 | 15 | id: data.readUInt32BE(0, true) & 0x7fffffff, |
michael@0 | 16 | version: 2, |
michael@0 | 17 | associated: stream ? data.readUInt32BE(4, true) & 0x7fffffff : 0, |
michael@0 | 18 | priority: stream ? data[8] >> 6 : 0, |
michael@0 | 19 | fin: (flags & 0x01) === 0x01, |
michael@0 | 20 | unidir: (flags & 0x02) === 0x02, |
michael@0 | 21 | _offset: stream ? 10 : 6 |
michael@0 | 22 | }; |
michael@0 | 23 | }; |
michael@0 | 24 | |
michael@0 | 25 | // |
michael@0 | 26 | // ### function parseHeaders (pairs) |
michael@0 | 27 | // #### @pairs {Buffer} header pairs |
michael@0 | 28 | // Returns hashmap of parsed headers |
michael@0 | 29 | // |
michael@0 | 30 | protocol.parseHeaders = function parseHeaders(pairs) { |
michael@0 | 31 | var count = pairs.readUInt16BE(0, true), |
michael@0 | 32 | headers = {}; |
michael@0 | 33 | |
michael@0 | 34 | pairs = pairs.slice(2); |
michael@0 | 35 | |
michael@0 | 36 | function readString() { |
michael@0 | 37 | var len = pairs.readUInt16BE(0, true), |
michael@0 | 38 | value = pairs.slice(2, 2 + len); |
michael@0 | 39 | |
michael@0 | 40 | pairs = pairs.slice(2 + len); |
michael@0 | 41 | |
michael@0 | 42 | return value.toString(); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | while(count > 0) { |
michael@0 | 46 | headers[readString()] = readString(); |
michael@0 | 47 | count--; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | return headers; |
michael@0 | 51 | }; |
michael@0 | 52 | |
michael@0 | 53 | // |
michael@0 | 54 | // ### function parsesRst frame |
michael@0 | 55 | protocol.parseRst = function parseRst(data) { |
michael@0 | 56 | return { |
michael@0 | 57 | type: 'RST_STREAM', |
michael@0 | 58 | id: data.readUInt32BE(0, true) & 0x7fffffff, |
michael@0 | 59 | status: data.readUInt32BE(4, true) |
michael@0 | 60 | }; |
michael@0 | 61 | }; |
michael@0 | 62 | |
michael@0 | 63 | protocol.parseGoaway = function parseGoaway(data) { |
michael@0 | 64 | return { |
michael@0 | 65 | type: 'GOAWAY', |
michael@0 | 66 | lastId: data.readUInt32BE(0, true) & 0x7fffffff |
michael@0 | 67 | }; |
michael@0 | 68 | }; |