Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
823819c982 | ||
|
abaed056e5 | ||
e2393d965a |
@ -5,7 +5,7 @@ digd.js
|
|||||||
| [dig.js](https://git.coolaj86.com/coolaj86/dig.js)
|
| [dig.js](https://git.coolaj86.com/coolaj86/dig.js)
|
||||||
| [mdig.js](https://git.coolaj86.com/coolaj86/mdig.js)
|
| [mdig.js](https://git.coolaj86.com/coolaj86/mdig.js)
|
||||||
| **digd.js**
|
| **digd.js**
|
||||||
| A [Root project](https://rootprojects.org).
|
| Sponsored by [Daplie](https://daplie.com).
|
||||||
|
|
||||||
A lightweight DNS / mDNS daemon (server) in node.js.
|
A lightweight DNS / mDNS daemon (server) in node.js.
|
||||||
|
|
||||||
@ -39,7 +39,8 @@ npm install -g 'git+https://git.coolaj86.com/coolaj86/digd.js.git#v1.2.0'
|
|||||||
|
|
||||||
### without git
|
### without git
|
||||||
|
|
||||||
Don't have git? You can use npm's centralized repository:
|
Don't have git? Well, you can also bow down to the gods of the centralized, monopolized, concentrated, *dictator*net
|
||||||
|
(as we like to call it here at Daplie Labs), if that's how you roll:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install -g digd.js
|
npm install -g digd.js
|
||||||
|
2
dist/etc/systemd/system/digd.js.service
vendored
2
dist/etc/systemd/system/digd.js.service
vendored
@ -8,7 +8,7 @@ Wants=network-online.target systemd-networkd-wait-online.service
|
|||||||
# Restart on crash (bad signal), but not on 'clean' failure (error exit code)
|
# Restart on crash (bad signal), but not on 'clean' failure (error exit code)
|
||||||
# Allow up to 3 restarts within 10 seconds
|
# Allow up to 3 restarts within 10 seconds
|
||||||
# (it's unlikely that a user or properly-running script will do this)
|
# (it's unlikely that a user or properly-running script will do this)
|
||||||
Restart=always
|
Restart=on-abnormal
|
||||||
StartLimitInterval=10
|
StartLimitInterval=10
|
||||||
StartLimitBurst=3
|
StartLimitBurst=3
|
||||||
|
|
||||||
|
@ -27,9 +27,10 @@ module.exports.create = function (cli, dnsd) {
|
|||||||
|
|
||||||
// TODO pad two bytes for lengths
|
// TODO pad two bytes for lengths
|
||||||
dnsd.onMessage(nb, function (err, newAb, dbgmsg) {
|
dnsd.onMessage(nb, function (err, newAb, dbgmsg) {
|
||||||
var lenbuf = Buffer.from([ newAb.length >> 8, newAb.length & 255 ]);
|
|
||||||
// TODO XXX generate legit error packet
|
// TODO XXX generate legit error packet
|
||||||
if (err) { console.error("Error", err); c.end(); return; }
|
if (err) { console.error("Error", err); c.end(); return; }
|
||||||
|
|
||||||
|
var lenbuf = Buffer.from([ newAb.length >> 8, newAb.length & 255 ]);
|
||||||
console.log('TCP ' + dbgmsg);
|
console.log('TCP ' + dbgmsg);
|
||||||
|
|
||||||
c.write(lenbuf);
|
c.write(lenbuf);
|
||||||
@ -53,10 +54,11 @@ module.exports.create = function (cli, dnsd) {
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
console.error("TCP Server Error:");
|
console.error("TCP Server Error:");
|
||||||
console.error(err);
|
console.error(err.stack);
|
||||||
tcpServer.close(function () {
|
tcpServer.close(function () {
|
||||||
setTimeout(runTcp, 1000);
|
setTimeout(runTcp, 1000);
|
||||||
});
|
});
|
||||||
|
//throw new Error(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
tcpServer.listen(cli.port, function () {
|
tcpServer.listen(cli.port, function () {
|
||||||
|
16
lib/udpd.js
16
lib/udpd.js
@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports.create = function (cli, dnsd) {
|
module.exports.create = function (cli, dnsd) {
|
||||||
|
function runUdp() {
|
||||||
var server = require('dgram').createSocket({
|
var server = require('dgram').createSocket({
|
||||||
type: cli.udp6 ? 'udp6' : 'udp4'
|
type: cli.udp6 ? 'udp6' : 'udp4'
|
||||||
, reuseAddr: true
|
, reuseAddr: true
|
||||||
@ -19,8 +20,12 @@ module.exports.create = function (cli, dnsd) {
|
|||||||
process.exit(123);
|
process.exit(123);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.error("error:", err.stack);
|
console.error("UDP Server Error:");
|
||||||
server.close();
|
console.error(err.stack);
|
||||||
|
server.close(function () {
|
||||||
|
setTimeout(runUdp, 1000);
|
||||||
|
});
|
||||||
|
//throw new Error(err);
|
||||||
};
|
};
|
||||||
|
|
||||||
handlers.onMessage = function (nb, rinfo) {
|
handlers.onMessage = function (nb, rinfo) {
|
||||||
@ -29,9 +34,9 @@ module.exports.create = function (cli, dnsd) {
|
|||||||
|
|
||||||
dnsd.onMessage(nb, function (err, newAb, dbgmsg) {
|
dnsd.onMessage(nb, function (err, newAb, dbgmsg) {
|
||||||
// TODO send legit error message
|
// TODO send legit error message
|
||||||
if (err) { server.send(Buffer.from([0x00])); return; }
|
if (err) { server.send(Buffer.from([0x00]), rinfo.port, rinfo.address); return; }
|
||||||
server.send(newAb, rinfo.port, rinfo.address, function () {
|
server.send(newAb, rinfo.port, rinfo.address, function () {
|
||||||
console.log(dbgmsg, rinfo.port, rinfo.address);
|
console.log('[dnsd.onMessage] ' + dbgmsg, rinfo.port, rinfo.address);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -55,4 +60,7 @@ module.exports.create = function (cli, dnsd) {
|
|||||||
server.on('listening', handlers.onListening);
|
server.on('listening', handlers.onListening);
|
||||||
|
|
||||||
return server;
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
return runUdp();
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "digd.js",
|
"name": "digd.js",
|
||||||
"version": "1.2.1",
|
"version": "1.2.2",
|
||||||
"description": "A lightweight DNS / mDNS daemon (server) for creating and capturing DNS and mDNS query and response packets to disk as binary and/or JSON. Options are similar to the Unix dig command.",
|
"description": "A lightweight DNS / mDNS daemon (server) for creating and capturing DNS and mDNS query and response packets to disk as binary and/or JSON. Options are similar to the Unix dig command.",
|
||||||
"main": "bin/digd.js",
|
"main": "bin/digd.js",
|
||||||
"homepage": "https://git.coolaj86.com/coolaj86/digd.js",
|
"homepage": "https://git.coolaj86.com/coolaj86/digd.js",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user