Adding ErrorCode enum
This commit is contained in:
parent
eb4ae29f7e
commit
57c638316e
3
lib/request.d.ts
vendored
3
lib/request.d.ts
vendored
@ -1,5 +1,5 @@
|
|||||||
/// <reference types="node" />
|
/// <reference types="node" />
|
||||||
import { Message, MessageHeader, MessageQuestion, MessageRecourceRecord } from "./types";
|
import { Message, MessageHeader, MessageQuestion, MessageRecourceRecord, ErrorCodes } from "./types";
|
||||||
export declare enum QueryTypes {
|
export declare enum QueryTypes {
|
||||||
/**
|
/**
|
||||||
* IPv4 address
|
* IPv4 address
|
||||||
@ -101,6 +101,7 @@ export declare class Request implements Message {
|
|||||||
additionals: RecourceRecord[];
|
additionals: RecourceRecord[];
|
||||||
_packet: Buffer;
|
_packet: Buffer;
|
||||||
constructor(packet: Buffer, sendCallback: (packet: Buffer) => any);
|
constructor(packet: Buffer, sendCallback: (packet: Buffer) => any);
|
||||||
|
error(error: ErrorCodes): void;
|
||||||
send(): void;
|
send(): void;
|
||||||
serialize(truncate?: boolean, rcode?: 0 | 1 | 2 | 3 | 4 | 5): Buffer;
|
serialize(truncate?: boolean, rcode?: 0 | 1 | 2 | 3 | 4 | 5): Buffer;
|
||||||
private serializeHeader();
|
private serializeHeader();
|
||||||
|
@ -160,6 +160,9 @@ class Request {
|
|||||||
get questions() {
|
get questions() {
|
||||||
return this._questions.map(e => e);
|
return this._questions.map(e => e);
|
||||||
}
|
}
|
||||||
|
error(error) {
|
||||||
|
this._header.RCODE = error;
|
||||||
|
}
|
||||||
send() {
|
send() {
|
||||||
this.sendCallback(this.serialize());
|
this.sendCallback(this.serialize());
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
10
lib/types.d.ts
vendored
10
lib/types.d.ts
vendored
@ -1,4 +1,12 @@
|
|||||||
/// <reference types="node" />
|
/// <reference types="node" />
|
||||||
|
export declare enum ErrorCodes {
|
||||||
|
NoError = 0,
|
||||||
|
FormatError = 1,
|
||||||
|
ServerFailure = 2,
|
||||||
|
NameError = 3,
|
||||||
|
NotImplemented = 4,
|
||||||
|
Refused = 5,
|
||||||
|
}
|
||||||
export interface MessageHeader {
|
export interface MessageHeader {
|
||||||
/**
|
/**
|
||||||
* A 16 bit identifier assigned by the program that
|
* A 16 bit identifier assigned by the program that
|
||||||
@ -61,7 +69,7 @@ export interface MessageHeader {
|
|||||||
* 5 Refused - Nameserver refuses request
|
* 5 Refused - Nameserver refuses request
|
||||||
* 6-15 Reserved for future usage
|
* 6-15 Reserved for future usage
|
||||||
*/
|
*/
|
||||||
RCODE: 0 | 1 | 2 | 3 | 4 | 5;
|
RCODE: ErrorCodes;
|
||||||
/**
|
/**
|
||||||
* Number of entries in question section
|
* Number of entries in question section
|
||||||
* uint16
|
* uint16
|
||||||
|
17
lib/types.js
17
lib/types.js
@ -1,3 +1,20 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
// 0 No error condition
|
||||||
|
// * 1 Format error - unable to interpret query
|
||||||
|
// * 2 Server failure - internal problem
|
||||||
|
// * 3 Name error - Only for authorative name server, domain name of query does not exist
|
||||||
|
// * 4 Not implemented - Request not supported
|
||||||
|
// * 5 Refused - Nameserver refuses request
|
||||||
|
// * 6 - 15 Reserved for future usage
|
||||||
|
// *
|
||||||
|
var ErrorCodes;
|
||||||
|
(function (ErrorCodes) {
|
||||||
|
ErrorCodes[ErrorCodes["NoError"] = 0] = "NoError";
|
||||||
|
ErrorCodes[ErrorCodes["FormatError"] = 1] = "FormatError";
|
||||||
|
ErrorCodes[ErrorCodes["ServerFailure"] = 2] = "ServerFailure";
|
||||||
|
ErrorCodes[ErrorCodes["NameError"] = 3] = "NameError";
|
||||||
|
ErrorCodes[ErrorCodes["NotImplemented"] = 4] = "NotImplemented";
|
||||||
|
ErrorCodes[ErrorCodes["Refused"] = 5] = "Refused";
|
||||||
|
})(ErrorCodes = exports.ErrorCodes || (exports.ErrorCodes = {}));
|
||||||
//# sourceMappingURL=types.js.map
|
//# sourceMappingURL=types.js.map
|
@ -1 +1 @@
|
|||||||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;AACA,uBAAuB;AACvB,kDAAkD;AAClD,8CAA8C;AAC9C,kGAAkG;AAClG,0DAA0D;AAC1D,0DAA0D;AAC1D,wCAAwC;AACxC,WAAW;AACX,IAAY,UAOX;AAPD,WAAY,UAAU;IACnB,iDAAW,CAAA;IACX,yDAAW,CAAA;IACX,6DAAa,CAAA;IACb,qDAAS,CAAA;IACT,+DAAc,CAAA;IACd,iDAAO,CAAA;AACV,CAAC,EAPW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAOrB"}
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nodename-core",
|
"name": "nodename-core",
|
||||||
"version": "0.1.3",
|
"version": "0.1.4",
|
||||||
"main": "lib/listener.js",
|
"main": "lib/listener.js",
|
||||||
"types": "lib/listener.d.ts",
|
"types": "lib/listener.d.ts",
|
||||||
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Parser } from "binary-parser"
|
import { Parser } from "binary-parser"
|
||||||
import { Message, MessageHeader, MessageQuestion, MessageRecourceRecord } from "./types"
|
import { Message, MessageHeader, MessageQuestion, MessageRecourceRecord, ErrorCodes } from "./types"
|
||||||
|
|
||||||
const MAX_LABEL_SIZE = 63;
|
const MAX_LABEL_SIZE = 63;
|
||||||
|
|
||||||
@ -193,6 +193,10 @@ export class Request implements Message {
|
|||||||
this._questions = parseQuestions(this._header.QDCOUNT, bodyData);
|
this._questions = parseQuestions(this._header.QDCOUNT, bodyData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error(error: ErrorCodes) {
|
||||||
|
this._header.RCODE = error;
|
||||||
|
}
|
||||||
|
|
||||||
send() {
|
send() {
|
||||||
this.sendCallback(this.serialize());
|
this.sendCallback(this.serialize());
|
||||||
}
|
}
|
||||||
|
20
src/types.ts
20
src/types.ts
@ -1,3 +1,21 @@
|
|||||||
|
|
||||||
|
// 0 No error condition
|
||||||
|
// * 1 Format error - unable to interpret query
|
||||||
|
// * 2 Server failure - internal problem
|
||||||
|
// * 3 Name error - Only for authorative name server, domain name of query does not exist
|
||||||
|
// * 4 Not implemented - Request not supported
|
||||||
|
// * 5 Refused - Nameserver refuses request
|
||||||
|
// * 6 - 15 Reserved for future usage
|
||||||
|
// *
|
||||||
|
export enum ErrorCodes {
|
||||||
|
NoError = 0,
|
||||||
|
FormatError,
|
||||||
|
ServerFailure,
|
||||||
|
NameError,
|
||||||
|
NotImplemented,
|
||||||
|
Refused
|
||||||
|
}
|
||||||
|
|
||||||
export interface MessageHeader {
|
export interface MessageHeader {
|
||||||
/**
|
/**
|
||||||
* A 16 bit identifier assigned by the program that
|
* A 16 bit identifier assigned by the program that
|
||||||
@ -69,7 +87,7 @@ export interface MessageHeader {
|
|||||||
* 5 Refused - Nameserver refuses request
|
* 5 Refused - Nameserver refuses request
|
||||||
* 6-15 Reserved for future usage
|
* 6-15 Reserved for future usage
|
||||||
*/
|
*/
|
||||||
RCODE: 0 | 1 | 2 | 3 | 4 | 5;
|
RCODE: ErrorCodes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of entries in question section
|
* Number of entries in question section
|
||||||
|
Loading…
Reference in New Issue
Block a user