mname-client
Advanced tools
Comparing version 0.5.1 to 0.6.0
@@ -81,2 +81,3 @@ /* | ||
mod_assert.number(options.timeout, 'options.timeout'); | ||
mod_assert.optionalFunc(options.filter, 'options.filter'); | ||
@@ -125,3 +126,4 @@ var resolvers = options.resolvers || this.dc_resolvers; | ||
type: options.type, | ||
timeout: options.timeout | ||
timeout: options.timeout, | ||
filter: options.filter | ||
}; | ||
@@ -166,2 +168,3 @@ reqs.push(self.lookupOnce(opts, function (err, msg) { | ||
mod_assert.optionalString(options.protocol, 'options.protocol'); | ||
mod_assert.optionalFunc(options.filter, 'options.filter'); | ||
@@ -176,2 +179,4 @@ var protocol = 'udp'; | ||
req.addEDNS({ maxUDPLength: 1420 }); | ||
if (options.filter) | ||
options.filter(req); | ||
@@ -178,0 +183,0 @@ var timer = setTimeout(function () { |
@@ -217,1 +217,31 @@ /* | ||
}; | ||
var FLAGS = { | ||
qr: true, aa: true, rd: true, ra: true, ad: true, cd: true, | ||
response: 'qr', authoritative: 'aa', recursionDesired: 'rd', | ||
recursionAvailable: 'ra', authenticated: 'ad', noChecking: 'cd', | ||
checkingDisabled: 'cd' | ||
}; | ||
function validateAndAliasFlag(flag) { | ||
if (typeof (FLAGS[flag]) === 'string') | ||
flag = FLAGS[flag]; | ||
if (FLAGS[flag] !== true) | ||
throw (new Error('Invalid DNS header flag "' + flag + '"')); | ||
return (flag); | ||
} | ||
DnsMessage.prototype.testFlag = function testFlag(flag) { | ||
flag = validateAndAliasFlag(flag); | ||
return (this.header.flags[flag] === true); | ||
}; | ||
DnsMessage.prototype.setFlag = function setFlag(flag) { | ||
flag = validateAndAliasFlag(flag); | ||
this.header.flags[flag] = true; | ||
}; | ||
DnsMessage.prototype.clearFlag = function clearFlag(flag) { | ||
flag = validateAndAliasFlag(flag); | ||
this.header.flags[flag] = false; | ||
}; |
{ | ||
"name": "mname-client", | ||
"description": "DNS client library for node.js", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"author": "Joyent, Inc", | ||
@@ -6,0 +6,0 @@ "scripts": { |
193
README.md
@@ -66,3 +66,3 @@ # node-named-client | ||
target: '216.58.192.14' } ]; | ||
/* | ||
@@ -87,3 +87,3 @@ * Need to call done() to indicate that this query is complete. | ||
sock.send(req); | ||
/* Call end once you've added all pipelined queries you want. */ | ||
@@ -107,3 +107,3 @@ sock.end(); | ||
sock.send(req, { address: '8.8.8.8', port: 53 }); | ||
/* Will cause the socket to close after the last outstanding query returns. */ | ||
@@ -116,1 +116,188 @@ sock.end(); | ||
``` | ||
## API | ||
### `new mod_mname_client.DnsClient([options])` | ||
Parameters: | ||
- `options` -- an optional Object, with keys: | ||
* `resolvers` -- an optional Array of String, IP addresses of nameservers | ||
to use | ||
* `concurrency` -- an optional Number, max number of requests to send at | ||
once, default 3 | ||
### `DnsClient#close()` | ||
Ends all sockets and waits for outstanding DNS requests to finish or time out | ||
before closing. | ||
### `DnsClient#lookup(options, cb)` | ||
Look up a name and return the first successful result as a DnsMessage. | ||
Parameters: | ||
- `options` -- Object, with keys: | ||
* `domain` -- String, domain to look up | ||
* `type` -- String, the query type (qtype), e.g. `"AAAA"` | ||
* `timeout` -- Number, milliseconds | ||
* `resolvers` -- optional Array of String, resolvers to use just for this | ||
request | ||
* `filter` -- optional Func `(msg)`, if provided will run on each DnsMessage | ||
before sending (useful to set flags or sign requests) | ||
- `cb` -- Func `(err, message)` with parameters: | ||
* `err` -- either `null` or an `Error` instance | ||
* `message` -- a DnsMessage (if `err` is `null`) | ||
### `new mod_mname_client.DnsMessage()` | ||
Construct a new, empty DNS message. The message is also an EventEmitter. | ||
### `DnsMessage->error(err)` | ||
Event emitted when the DNS message experiences an error because of a network | ||
or system failure. This is not emitted if the message receives a reply that is | ||
an error-type reply (e.g. `isError()` on the reply would return `true`). | ||
Parameters: | ||
- `err` -- an Error object | ||
### `DnsMessage->reply(msg)` | ||
Event emitted when a reply to the DNS message is received. | ||
Parameters: | ||
- `msg` -- a DnsMessage instance | ||
### `DnsMessage#isError()` | ||
Returns `true` if this message indicates an error (either by the rcode being | ||
something other than `NOERROR`, or the truncation flag being set). | ||
### `DnsMessage#toError([resolver])` | ||
Converts the DnsMessage into an `Error` object with a descriptive message about | ||
the error that occurred. The optional `resolver` parameter is included in the | ||
Error messages. | ||
If the DnsMessage does not represent any kind of error condition, this function | ||
returns `null`. The returned errors will be named either `TruncationError` or | ||
`DnsError`. | ||
Parameters: | ||
- `resolver` -- optional String, resolver IP or name to include in error | ||
message | ||
### `DnsMessage#getAnswers()` | ||
Returns the answer part of the DNS message as an Array of Record Objects, of | ||
the form: | ||
```json | ||
{ | ||
"name": "domain.foo.com", | ||
"type": "AAAA", | ||
"class": "IN", | ||
"ttl": 30, | ||
"address": "abcd::1" | ||
} | ||
``` | ||
The `name`, `type`, `class` and `ttl` properties are available on all types of | ||
record. Other fields such as `address` appear only on the relevant `type`. | ||
### `DnsMessage#getAuthority()` | ||
Returns the authority section of the DNS message as an Array of Record Objects | ||
(see `getAnswers()`). | ||
### `DnsMessage#getAdditionals()` | ||
Returns the additional section of the DNS message as an Array of Record Objects | ||
(see `getAnswers()`). | ||
### `DnsMessage#testFlag(flag)` | ||
Returns `true` if a given flag is set in the message header. Valid flag names: | ||
- `qr`, `response` | ||
- `aa`, `authoritative` | ||
- `rd`, `recursionDesired` | ||
- `ra`, `recursionAvailable` | ||
- `ad`, `authenticated` | ||
- `cd`, `noChecking` | ||
- `cd`, `checkingDisabled` | ||
Parameters: | ||
- `flag` -- a String | ||
### `DnsMessage#setFlag(flag)` | ||
### `DnsMessage#clearFlag(flag)` | ||
Sets or clears a given flag (see `testFlag()` for a list of values). | ||
Parameters: | ||
- `flag` -- a String | ||
### `DnsMessage#addQuestion(name, type, qclass)` | ||
Adds a question section to the DNS message. | ||
Parameters: | ||
- `name` -- a String, the domain name to be questioned | ||
- `type` -- a String, the record type desired (e.g. `'AAAA'`) | ||
- `qclass` -- a String, the query class (e.g. `'IN'`) | ||
### `DnsMessage#addEDNS(options)` | ||
Adds EDNS to the message. | ||
Parameters | ||
- `options` -- an Object, with keys: | ||
* `maxUDPLength` -- a Number, the maximum length of UDP frames | ||
### `new mod_mname_client.DnsTcpSocket(options)` | ||
Creates a new TCP-based DNS client socket. | ||
Parameters: | ||
- `options` -- an Object, with keys: | ||
* `address` -- a String, IP address of remote machine | ||
* `port` -- a Number, the port to connect to | ||
### `new mod_mname_client.DnsUdpSocket(options)` | ||
Creates a new UDP-based DNS client socket. | ||
Parameters: | ||
- `options` -- an Object, with keys: | ||
* `family` -- a String, either `'udp4'` or `'udp6'` | ||
### `DnsSocket->ready()` | ||
Event emitted by `DnsTcpSocket` or `DnsUdpSocket` when the socket is open and | ||
ready for use. | ||
### `DnsSocket->error(err)` | ||
Event emitted by `DnsTcpSocket` or `DnsUdpSocket` when a socket-level error is | ||
experienced. | ||
Parameters: | ||
- `err` -- an Error object | ||
### `DnsSocket#end()` | ||
Wait for any outstanding requests to complete, and then close the socket. | ||
### `DnsSocket#isReady()` | ||
Returns `true` if the socket has emitted the `->ready` event. | ||
### `DnsSocket#send(msg[, destination])` | ||
Sends a DnsMessage over the socket. | ||
Parameters: | ||
- `msg` -- a DnsMessage object | ||
- `destination` -- a String, optional for TCP sockets, required for UDP (must | ||
be remote address to send message to) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33980
846
300