don't modify original object, chimney

This commit is contained in:
AJ ONeal 2017-02-17 18:57:25 -07:00
parent 39de466876
commit 113187e68a
1 changed files with 9 additions and 16 deletions

View File

@ -23,10 +23,10 @@ var dnspack = exports.DNS_PACKER = {
dv.setUint16(0, id, false);
dv.setUint16(2, header, false);
dv.setUint16(4, packet.question.length, false);
dv.setUint16(6, packet.answer.length, false);
dv.setUint16(8, packet.authority.length, false);
dv.setUint16(6, (packet.answer||[]).length, false);
dv.setUint16(8, (packet.authority||[]).length, false);
// EDNS is added as an additional with TYPE 41 (OPT, 0x29)
dv.setUint16(10, packet.additional.length + (packet.payload ? 1 : 0), false);
dv.setUint16(10, (packet.additional||[]).length + (packet.payload ? 1 : 0), false);
function lint(r) {
if (!r.name) {
@ -37,24 +37,20 @@ var dnspack = exports.DNS_PACKER = {
if (!r.className) {
throw new Error("no className");
}
r.class = classes[r.className];
}
if (!r.type) {
if (!r.typeName) {
throw new Error("no typeName");
}
r.type = types[r.typeName];
if (!r.type) {
if (!types[r.typeName]) {
console.warn("ignoring invalid type '" + r.type + "' for '" + r.name + "', ignoring");
}
}
}
function packLabelSequence(sequence, terminates) {
console.log('sequence:', sequence);
if (labelsMap[sequence]) {
console.log('cached sequence:', sequence);
// minimal compression pointer 0xc0 (192)
dv.setUint8(total, 0xc0, false);
total += 1;
@ -88,9 +84,9 @@ var dnspack = exports.DNS_PACKER = {
packLabelSequence(q.name, true);
dv.setUint16(total, q.type, false);
dv.setUint16(total, q.type || types[q.typeName], false);
total += 2;
dv.setUint16(total, q.class, false);
dv.setUint16(total, q.class || classes[q.className], false);
total += 2;
}
@ -118,13 +114,10 @@ var dnspack = exports.DNS_PACKER = {
}
}
//console.log(packet);
// fixed size, other than labels
packet.question.forEach(packQuestion);
packet.answer.forEach(packAnswer);
packet.authority.forEach(packAnswer);
packet.additional.forEach(packAnswer);
(packet.answer||[]).forEach(packAnswer);
(packet.authority||[]).forEach(packAnswer);
(packet.additional||[]).forEach(packAnswer);
// TODO handle compression pointers
// TODO handle edns