-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtypes.ts
270 lines (239 loc) · 4.85 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import { ClassValues, QClassValues, QTypeValues, TypeValues } from './enums';
interface IDnsHeader {
/**
* A 16 bit identifier
*
* @type {number}
*/
id: number;
/**
* A one bit field that specifies whether this message is a
* query (0), or a response (1)
*
* @type {number}
*/
qr: number;
/**
* A 4 bit field that specifies the kind of query in this message.
* - `0`: a standard query (QUERY)
* - `1`: an inverse query (IQUERY)
* - `2`: a server status request (STATUS)
* - `3-15`: reserved for future use
*
* @type {number}
*/
opcode: number;
/**
* Authoritative Answer - one bit.
*
* @type {number}
*/
aa: number;
/**
* TrunCation - one bit.
*
* @type {number}
*/
tc: number;
/**
* Recursion Desired - one bit.
*
* @type {number}
*/
rd: number;
/**
* Recursion Available - one bit.
*
* @type {number}
*/
ra: number;
/**
* Reserved for future use.
* Must be zero in all queries and responses.
* 3 bits
*
* @type {number}
*/
z: number;
/**
* Response code - 4 bit field
* - `0`: No error condition
* - `1`: Format error
* - `2`: Server failure
* - `3`: Name Error
* - `4`: Not Implemented
* - `5`: Refused
* - `6-15`: Reserved for future use
*
* @type {number}
*/
rCode: number;
/**
* Number of entries in the question section.
* An unsigned 16 bit integer.
*
* @type {number}
*/
qdCount: number;
/**
* Number of resource records in the answer section.
* An unsigned 16 bit integer.
*
* @type {number}
*/
anCount: number;
/**
* Number of name server resource records in the authority records section.
* An unsigned 16 bit integer.
*
* @type {number}
*/
nsCount: number;
/**
* Number of resource records in the additional records section.
* An unsigned 16 bit integer.
*
* @type {number}
*/
arCount: number;
}
interface IQuestion {
/**
* Domain name represented as a sequence of labels.
* Each label consists of a length octet followed by that number of octets.
* The domain name terminates with a zero length octet.
* May have and odd number of octets. No padding is used.
*
* @type {string}
*/
name: string;
/**
* A two octet code - specifies the type of query.
*
* @type {number}
*/
type: TypeValues | QTypeValues;
/**
* A two octet code - specifies the class of the query.
*
* @type {number}
*/
class: ClassValues | QClassValues;
}
interface IResourceRecord {
/**
* Domain name.
*
* @type {string}
*/
name: string;
/**
* Type of Resource Record.
* 16 bit integer.
*
* @type {TypeValues}
*/
type: TypeValues;
/**
* Class of the data present in this RR.
* 16 bit integer.
*
* @type {ClassValues}
*/
class: ClassValues;
/**
* Time interval (in seconds) that the RR may be cached,
* before it should be discarded.
* A 32 bit unsigned integer.
*
* @type {number}
*/
ttl: number;
/**
* Length in octets of the data field.
* An unsigned 16 bit integer.
*
* @type {number}
*/
dataLength: number;
/**
* Variable length string of octets that describes the record.
*
* @type {string}
*/
data: string;
}
/**
* Refer to https://datatracker.ietf.org/doc/html/rfc1035#section-4
*/
interface IDnsMessage {
header: IDnsHeader;
questions: IQuestion[];
answers: IResourceRecord[];
authority: IResourceRecord[];
additional: IResourceRecord[];
toByteString(): string;
}
/**
* A message parser interface that takes a Buffer as an argument.
*/
interface IDnsMessageParser {
/**
* Parse the Buffer into a valid IDnsMessage
*
* @returns {IDnsMessage}
*/
parse(): IDnsMessage;
}
/**
* This interface is used to find DNS records for the given domain.
* The server is defined using host and port.
*/
interface IDnsQuery {
/**
* The domain for which the DNS query is being made.
*
* @type {string}
*/
domain: string;
/**
* The host of the server.
*
* @type {string}
*/
host: string;
/**
* The port of the server.
*
* @type {number}
*/
port: number;
/**
* If true, then logs the Data packets in hex format.
*
* @type {boolean}
*/
debug: boolean;
/**
* Send the DNS query message to the server.
* You can override the header by passing the required field in the params.
*
* @param {?Partial<IDnsHeader>} [header]
* @returns {Promise<IDnsMessage>}
*/
sendMessage(header?: Partial<IDnsHeader>): Promise<IDnsMessage>;
}
interface ICommandWaitingForReply {
resolve(reply?: IDnsMessage | PromiseLike<IDnsMessage>): void;
reject(reply?: unknown): void;
request: IDnsMessage;
}
export {
IDnsHeader,
IDnsMessage,
IDnsMessageParser,
IQuestion,
IDnsQuery,
ICommandWaitingForReply,
IResourceRecord
};