Tue, 12 Aug 2014 18:32:40 +0200
Import initial revisions of new project mDNSGw.
.hgignore | file | annotate | diff | comparison | revisions | |
.npmignore | file | annotate | diff | comparison | revisions | |
doc/authors.txt | file | annotate | diff | comparison | revisions | |
doc/changelog.txt | file | annotate | diff | comparison | revisions | |
doc/license.txt | file | annotate | diff | comparison | revisions | |
doc/readme.txt | file | annotate | diff | comparison | revisions | |
doc/todo.txt | file | annotate | diff | comparison | revisions | |
package.json | file | annotate | diff | comparison | revisions | |
src/app.js | file | annotate | diff | comparison | revisions | |
src/fork.js | file | annotate | diff | comparison | revisions |
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/.hgignore Tue Aug 12 18:32:40 2014 +0200 1.3 @@ -0,0 +1,22 @@ 1.4 +syntax: glob 1.5 +*.orig 1.6 +*.rej 1.7 +*.swp 1.8 +*.o 1.9 +*~ 1.10 + 1.11 +# custom paths 1.12 +old 1.13 +proto 1.14 + 1.15 +# files too big to track 1.16 +graphics/ubudesktop.xcf 1.17 + 1.18 +syntax: regexp 1.19 +.*\#.*\#$ 1.20 + 1.21 +# ignore all but text or sav (saved not forgotton) extensions 1.22 +doc/(?!.*\.sav$|.*\.txt$|.*\.f?odt$).+ 1.23 + 1.24 +# ignore all but most important design files 1.25 +design/(?!.*\.graffle$).+
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/doc/authors.txt Tue Aug 12 18:32:40 2014 +0200 2.3 @@ -0,0 +1,4 @@ 2.4 +Design, Implementation 2.5 +Michael Schloh von Bennewitz 2.6 +http://michael.schloh.com/ 2.7 +michael@schloh.com
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/doc/changelog.txt Tue Aug 12 18:32:40 2014 +0200 3.3 @@ -0,0 +1,11 @@ 3.4 +Change log in reverse cron order 3.5 + 3.6 +00000000 Release version 1.0.0 3.7 + 3.8 +20140812 Release version 0.7.0 3.9 + Implement main program logic 3.10 + Develop build framework 3.11 + 3.12 +20140811 Release prototype 0.6.0 3.13 + 3.14 +20140810 Project creation
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/doc/license.txt Tue Aug 12 18:32:40 2014 +0200 4.3 @@ -0,0 +1,11 @@ 4.4 +Permission to use, copy, modify, and/or distribute this software for any 4.5 +purpose with or without fee is hereby granted, provided that the above 4.6 +copyright notice and this permission notice appear in all copies. 4.7 + 4.8 +THE SOFTWARE IS PROVIDED “AS IS” AND ISC DISCLAIMS ALL WARRANTIES 4.9 +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 4.10 +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY 4.11 +SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 4.12 +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 4.13 +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 4.14 +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/doc/readme.txt Tue Aug 12 18:32:40 2014 +0200 5.3 @@ -0,0 +1,41 @@ 5.4 + ____ _ _ ____ ____ 5.5 + _ __ ___ | _ \| \ | / ___| / ___|_ __ 5.6 + | '_ ` _ \| | | | \| \___ \| | _\ \ /\ / / 5.7 + | | | | | | |_| | |\ |___) | |_| |\ V V / 5.8 + |_| |_| |_|____/|_| \_|____/ \____| \_/\_/ 5.9 + 5.10 + mDNSGw - Zero Configuration DNS Gateway for Mesh Networks 5.11 + Version 0.7.0 (14-Aug-2014) 5.12 + 5.13 + ABSTRACT 5.14 + 5.15 + Mesh networks consisting of independent subnets and nodes benefit 5.16 + from a enhanced degree of zero configuration operation. A robust 5.17 + network serves the interests of consumers of such applications as 5.18 + found in the Internet of Things for example, where independent nodes 5.19 + communicate with one another over a self maintaining autonomous 5.20 + Internet platform. 5.21 + 5.22 + COPYRIGHT AND LICENSE 5.23 + 5.24 + Copyright (c) 2014 Michael Schloh von Bennewitz <michael@schloh.com> 5.25 + 5.26 + Permission to use, copy, modify, and/or distribute this software for 5.27 + any purpose with or without fee is hereby granted, provided that the 5.28 + above copyright notice and this permission notice appear in all copies. 5.29 + 5.30 + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 5.31 + WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 5.32 + WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 5.33 + AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 5.34 + DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 5.35 + PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 5.36 + ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 5.37 + THIS SOFTWARE. 5.38 + 5.39 + HOME AND DOCUMENTATION 5.40 + 5.41 + Documentation and releases are located at 5.42 + 5.43 + o http://dev.europalab.com/mdnsgw/ 5.44 + o ftp://ftp.europalab.com//pub/sfw/mdnsgw/
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/doc/todo.txt Tue Aug 12 18:32:40 2014 +0200 6.3 @@ -0,0 +1,19 @@ 6.4 +Unmet requirements 6.5 + 6.6 +Milestone release 1.2.0 (secondary enhancements) 6.7 + Hardcore ::1 for all AAAA requests. 6.8 + 6.9 +Milestone release 1.1.0 (primary enhancements) 6.10 + Reloop when a service goes down. 6.11 + Remove hostnames not in use. 6.12 + 6.13 +Milestone release 1.0.0 (testing complete) 6.14 + Test multiple addresses in redis. 6.15 + Include redis quit() and mdns stop(). 6.16 + 6.17 +Milestone release 0.9.0 (code complete) 6.18 + Remove servinames redis logic. 6.19 + Use forever or similar to daemonize. 6.20 + 6.21 +Unscheduled items 6.22 + None.
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/package.json Tue Aug 12 18:32:40 2014 +0200 7.3 @@ -0,0 +1,54 @@ 7.4 +{ 7.5 + "name": "mdnsgate", 7.6 + "version": "0.7.0", 7.7 + "description": "MDNS gateway for DNS clients", 7.8 + "main": "src/fork.js", 7.9 + "directories": {"doc": "doc", "src": "src"}, 7.10 + "bin": {"mdnsgw": "bin/fork.js"}, 7.11 + "man": { 7.12 + "name": "mdnsgw", 7.13 + "version": "0.7.0", 7.14 + "description": "A zeroconf DNS gateway", 7.15 + "main": "fork.js", 7.16 + "man": "man/mdnsgw.8" 7.17 + }, 7.18 + "scripts": { 7.19 + "test": "echo \"Error: no test specified\" && exit 1" 7.20 + }, 7.21 + "keywords": [ 7.22 + "dns", 7.23 + "mdns", 7.24 + "gateway", 7.25 + "server" 7.26 + ], 7.27 + "dependencies": { 7.28 + "redis": "*", 7.29 + "mdns": "*", 7.30 + "native-dns": "*", 7.31 + "forever-monitor": "*" 7.32 + }, 7.33 + "devDependencies": {}, 7.34 + "bundleDependencies": [], 7.35 + "engines": { 7.36 + "node": ">= 0.6.0", 7.37 + "npm": ">= 1.0.0" 7.38 + }, 7.39 + "author": { 7.40 + "name": "Michael Schloh von Bennewitz", 7.41 + "email": "michael@schloh.com", 7.42 + "url": "http://michael.schloh.com/" 7.43 + }, 7.44 + "maintainers": [{ 7.45 + "name": "Arthur Fonzarelli", 7.46 + "email": "arthur@thefonz.it", 7.47 + "web": "http://www.thefonz.it/" 7.48 + }], 7.49 + "homepage": "http://dev.europalab.com/mdnsgw/", 7.50 + "bugs": {"email": "mdnsgw@europalab.com"}, 7.51 + "repository": { 7.52 + "type": "mercurial", 7.53 + "url": "https://scm.europalab.com/mdnsgw/" 7.54 + }, 7.55 + "license": "ISC", 7.56 + "private": true 7.57 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/src/app.js Tue Aug 12 18:32:40 2014 +0200 8.3 @@ -0,0 +1,166 @@ 8.4 +#! /usr/bin/env nodejs 8.5 +// 8.6 +// mDNSGw - Zero Configuration DNS Gateway for Mesh Networks 8.7 +// Copyright © 2014 Michael Schloh von Bennewitz <michael@schloh.com> 8.8 +// 8.9 +// Permission to use, copy, modify, and/or distribute this software for 8.10 +// any purpose with or without fee is hereby granted, provided that the 8.11 +// above copyright notice and this permission notice appear in all copies. 8.12 +// 8.13 +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 8.14 +// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 8.15 +// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 8.16 +// AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 8.17 +// DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 8.18 +// PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 8.19 +// ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 8.20 +// THIS SOFTWARE. 8.21 +// 8.22 +// This file is part of mDNSGw, a Zero configuration DNS gateway 8.23 +// which can be found at http://dev.europalab.com/mdnsgw/ 8.24 +// 8.25 +// app.js: ECMA JavaScript implementation 8.26 +// 8.27 + 8.28 +/*********************************************************** 8.29 +| ____ _ _ ____ ____ | 8.30 +| _ __ ___ | _ \| \ | / ___| / ___|_ __ | 8.31 +| | '_ ` _ \| | | | \| \___ \| | _\ \ /\ / / | 8.32 +| | | | | | | |_| | |\ |___) | |_| |\ V V / | 8.33 +| |_| |_| |_|____/|_| \_|____/ \____| \_/\_/ | 8.34 +| | 8.35 +| Requirements: Redis server with standard configuration | 8.36 +| NodeJS and NPM modules (see package.json) | 8.37 +| | 8.38 +| Execute: To start this application, launch it with the | 8.39 +| script named fork.js: $ ./fork.js | 8.40 +| | 8.41 +| Support: http://list.europalab.com/mailman/mdnsgs/ | 8.42 +| | 8.43 +***********************************************************/ 8.44 + 8.45 +// import module dependencies 8.46 +var mdnsinst = require('mdns'); 8.47 +var redisdat = require('redis'); 8.48 +var nameinst = require('native-dns'); 8.49 + 8.50 + 8.51 +// instantiate a new redis client 8.52 +// http://www.rediscookbook.org/ 8.53 +var rediscli = redisdat.createClient(); 8.54 +rediscli.on('error', function (error) { 8.55 + console.log('Error ' + error); 8.56 +}); 8.57 + 8.58 +// clear mDNS service keys 8.59 +rediscli.del('hostnames'); 8.60 +// this is not working unfortunately for the loop 8.61 +rediscli.keys('*', function (error, replies) { 8.62 + replies.forEach(function (reply, ident) { 8.63 + rediscli.del(reply, function (error, value) { 8.64 + if (error) throw(error); 8.65 + }); 8.66 + }); 8.67 +}); 8.68 + 8.69 +// scan all advertised mDNS service types 8.70 +var browsall = mdnsinst.browseThemAll(); 8.71 +browsall.on('serviceUp', function(service) { 8.72 + // iterate through hosts and watch accordingly 8.73 + if (service.type.name.match(/^[a-zA-Z0-9\-]+$/)) { // mdns module hack 8.74 + if (service.type.protocol == 'tcp') { 8.75 + var browserv = mdnsinst.createBrowser(mdnsinst.tcp(service.type.name)); 8.76 + } 8.77 + else if (service.type.protocol == 'udp') { 8.78 + var browserv = mdnsinst.createBrowser(mdnsinst.udp(service.type.name)); 8.79 + } 8.80 + else if (service.type.protocol == 'sctp') { 8.81 + var browserv = mdnsinst.createBrowser(mdnsinst.sctp(service.type.name)); 8.82 + } 8.83 + else throw(error); 8.84 + 8.85 + // common logic for all transports (TCP, UDP, SCTP, etcetera) 8.86 + browserv.on('serviceUp', function(service) { 8.87 + //console.log('service up: ', service); 8.88 + //{interfaceIndex: 2, type: {name: 'ssh', protocol: 'tcp', subtypes: [], fullyQualified: true}, replyDomain: 'local.', flags: 2, name: 'hostname-mich', networkInterface: 'eth0', fullname: 'hostname-mich._ssh._tcp.local.', host: 'hostname-mich.local.', port: 22, addresses: ['192.168.1.50']} 8.89 + 8.90 + // insert one or more IP addresses for each hostname.local. 8.91 + rediscli.hset('hostnames', service.host.replace(/\.$/, ''), service.addresses); 8.92 + }); 8.93 + browserv.on('serviceDown', function(service) { 8.94 + //console.log('service down: ', service); 8.95 + //FIXME: still need to selectively remove hosts 8.96 + }); 8.97 + browserv.start(); 8.98 + } 8.99 +}); 8.100 +browsall.start(); 8.101 + 8.102 +// instantiate a new DNS server 8.103 +var nameserv = nameinst.createServer(); 8.104 + 8.105 +nameserv.on('request', function (request, response) { 8.106 + //console.log(request) 8.107 + 8.108 + // ensure that requested hostname is present 8.109 + rediscli.hget('hostnames', request.question[0].name, function (error, value) { 8.110 + // handle unexpected errors 8.111 + if (error) throw(error); 8.112 + 8.113 + if (value) { // the db succeeded in finding a match 8.114 + // populate the DNS response with the chosen hostname 8.115 + rediscli.hkeys('hostnames', function (error, replies) { 8.116 + replies.forEach(function (host, index) { 8.117 + if (request.question[0].name == host) { 8.118 + rediscli.hget('hostnames', host, function (error, value) { 8.119 + // handle unexpected errors 8.120 + if (error) throw(error); 8.121 + 8.122 + // FIXME: still must handle multihomed hosts 8.123 + //// a host might have more than one address 8.124 + //value.forEach(function (addr, iter) 8.125 + // set the nameserver address 8.126 + response.answer.push(nameinst.A({ 8.127 + name: host, 8.128 + address: value, 8.129 + ttl: 600, 8.130 + })); 8.131 + response.send(); 8.132 + }); 8.133 + } 8.134 + }); 8.135 + }); 8.136 + } 8.137 + else { 8.138 + response.answer.push(nameinst.A({ 8.139 + name: request.question[0].name, 8.140 + address: '127.0.0.1', 8.141 + ttl: 600, 8.142 + })); 8.143 + response.send(); 8.144 + } 8.145 + }); 8.146 +}); 8.147 + 8.148 +// DNS error handler logic 8.149 +nameserv.on('error', function (err, buff, req, res) { 8.150 + console.log('DNS problem: ', err.stack); 8.151 +}); 8.152 + 8.153 +nameserv.serve(15353); 8.154 + 8.155 +//// debug print all key and value database entries 8.156 +//rediscli.hgetall('hostnames', function (error, object) {console.dir(object);}); 8.157 + 8.158 +//// display stored mDNS service data entries 8.159 +//rediscli.hkeys('hostnames', function (error, replies) { 8.160 +// console.log(replies.length + ' replies:'); 8.161 +// replies.forEach(function (reply, ident) { 8.162 +// console.log(' ' + ident + ': ' + reply); 8.163 +// }); 8.164 +//}); 8.165 + 8.166 +//// block executes on program termination 8.167 +//rediscli.quit(); // cleanup db connection 8.168 +//browserv.stop(); // zombie scope too bad 8.169 +//browsall.stop();
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/src/fork.js Tue Aug 12 18:32:40 2014 +0200 9.3 @@ -0,0 +1,62 @@ 9.4 +#! /usr/bin/env nodejs 9.5 +// 9.6 +// mDNSGw - Zero Configuration DNS Gateway for Mesh Networks 9.7 +// Copyright © 2014 Michael Schloh von Bennewitz <michael@schloh.com> 9.8 +// 9.9 +// Permission to use, copy, modify, and/or distribute this software for 9.10 +// any purpose with or without fee is hereby granted, provided that the 9.11 +// above copyright notice and this permission notice appear in all copies. 9.12 +// 9.13 +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 9.14 +// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 9.15 +// WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 9.16 +// AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 9.17 +// DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 9.18 +// PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 9.19 +// ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 9.20 +// THIS SOFTWARE. 9.21 +// 9.22 +// This file is part of mDNSGw, a Zero configuration DNS gateway 9.23 +// which can be found at http://dev.europalab.com/mdnsgw/ 9.24 +// 9.25 +// fork.js: ECMA JavaScript implementation 9.26 +// 9.27 + 9.28 +/*********************************************************** 9.29 +| ____ _ _ ____ ____ | 9.30 +| _ __ ___ | _ \| \ | / ___| / ___|_ __ | 9.31 +| | '_ ` _ \| | | | \| \___ \| | _\ \ /\ / / | 9.32 +| | | | | | | |_| | |\ |___) | |_| |\ V V / | 9.33 +| |_| |_| |_|____/|_| \_|____/ \____| \_/\_/ | 9.34 +| | 9.35 +| Requirements: Redis server with standard configuration | 9.36 +| NodeJS and NPM modules (see package.json) | 9.37 +| | 9.38 +| Execute: To start this application, launch it with the | 9.39 +| script named fork.js: $ ./fork.js | 9.40 +| | 9.41 +| Support: http://list.europalab.com/mailman/mdnsgs/ | 9.42 +| | 9.43 +***********************************************************/ 9.44 + 9.45 +// import module dependencies 9.46 +var forkserv = require('forever-monitor'); 9.47 + 9.48 + 9.49 +// configure a child process to daemonize 9.50 +var childproc = new (forkserv.Monitor)('app.js', { 9.51 + max: 4, 9.52 + silent: true, 9.53 + pidFile: 'mdnsgw.pid', 9.54 + logFile: 'mdnsgw.log', 9.55 + outFile: 'mdnsgw.out', 9.56 + errFile: 'mdnsgw.err', 9.57 + options: [] 9.58 +}); 9.59 + 9.60 +childproc.on('exit', function () { 9.61 + console.log('app.js has exited after 4 restarts'); 9.62 +}); 9.63 + 9.64 +// fork a child 9.65 +childproc.start();