Commit aa8bdc9d1c7570e788c3416709fa6ef788024cec
Merge remote-tracking branch 'origin/master' into update
cel committed on 11/1/2016, 5:24:41 PMParent: c93111a7768b13d7bed3ff7994833c1b1279a1ae
Parent: 0553b24bb466e1e4ead0148e234950014b19335f
Files changed
README.md | changed |
index.js | changed |
lib/publish.js | changed |
lib/server.js | changed |
package.json | changed |
README.md | |||
---|---|---|---|
@@ -1,5 +1,5 @@ | |||
1 | -# ssb-dns | ||
1 … | +# dnssb | ||
2 | 2 … | ||
3 | 3 … | It's fairly easy to [serve dns](https://github.com/iriscouch/dnsd) from a nodejs process. | |
4 | 4 … | ||
5 | 5 … | [scuttlebot](http://ssbc.github.io/scuttlebot/) makes it easy to work with a peer-to-peer log store. | |
@@ -18,16 +18,16 @@ | |||
18 | 18 … | ||
19 | 19 … | Or via git: | |
20 | 20 … | ||
21 | 21 … | ``` | |
22 | -git clone https://github.com/ansuz/ssb-dns; | ||
23 | -cd ssb-dns; | ||
22 … | +git clone https://github.com/ansuz/dnssb; | ||
23 … | +cd dnssb; | ||
24 | 24 … | npm i -g; | |
25 | 25 … | ``` | |
26 | 26 … | ||
27 | 27 … | ## Usage | |
28 | 28 … | ||
29 | -`ssb-dns` assumes that you have a scuttlebot instance running. | ||
29 … | +`dnssb` assumes that you have a scuttlebot instance running. | ||
30 | 30 … | You can find out more about scuttlebot [here](https://ssbc.github.io/scuttlebot/). | |
31 | 31 … | ||
32 | 32 … | ## Publish a record | |
33 | 33 … | ||
@@ -37,12 +37,12 @@ | |||
37 | 37 … | ||
38 | 38 … | In the future this might be genralized to squat even more TLDs, or to simply be unopinionated about them. | |
39 | 39 … | ||
40 | 40 … | ``` | |
41 | -ssb-dns publish [{prev record key}...] {domain name} {record type} {value} [optionally add a dns class] | ||
41 … | +dnssb publish [{prev record key}...] {domain name} {record type} {value} [optionally add a dns class] | ||
42 | 42 … | ``` | |
43 | 43 … | ||
44 | -To replace some existing ssb-dns records, pass their ssb message id(s) as | ||
44 … | +To replace some existing dnssb records, pass their ssb message id(s) as | ||
45 | 45 … | the first arguments to the publish command. To append a record to the set of | |
46 | 46 … | existing records, omit the message ids. | |
47 | 47 … | ||
48 | 48 … | To replace all existing records for a name+type+class, use `update`: | |
@@ -50,14 +50,26 @@ | |||
50 | 50 … | ``` | |
51 | 51 … | ssb-dns update {domain name} {record type} {value} [optionally add a dns class] | |
52 | 52 … | ``` | |
53 | 53 … | ||
54 … | +## Display all records | ||
55 … | + | ||
56 … | +> I want to use this | ||
57 … | + | ||
58 … | +You'll only be able to resolve records that your node knows about. | ||
59 … | + | ||
60 … | +You can print a list of valid records with: | ||
61 … | + | ||
62 … | +``` | ||
63 … | +dnssb dump | ||
64 … | +``` | ||
65 … | + | ||
54 | 66 … | ## Fetch a record | |
55 | 67 … | ||
56 | 68 … | First launch the server in one terminal: | |
57 | 69 … | ||
58 | 70 … | ``` | |
59 | -ssb-dns server {port: 53053} {host: 127.0.0.1} | ||
71 … | +dnssb server {port: 53053} {host: 127.0.0.1} | ||
60 | 72 … | ``` | |
61 | 73 … | ||
62 | 74 … | Then query it for a record: | |
63 | 75 … | ||
@@ -68,29 +80,46 @@ | |||
68 | 80 … | ## FAQ | |
69 | 81 … | ||
70 | 82 … | > Can I use this without running [scuttlebot](http://github.com/ssbc/scuttlebot)? | |
71 | 83 … | ||
72 | -You could get a friend to host ssb-dns for you if you _really_ trust them. | ||
84 … | +You could get a friend to host dnssb for you if you _really_ trust them and don't care if they see all your dns requests. | ||
73 | 85 … | Once running, you should be able to use the dns server as you would any other dns provider. | |
74 | 86 … | ||
75 | 87 … | > Is it Enterprise-Ready? | |
76 | 88 … | ||
77 | -Hell no. It barely works | ||
89 … | +That depends on your the needs of your Enterprise, but I would lean towards _no_. | ||
78 | 90 … | ||
79 | 91 … | > Does it protect against name-squatting? | |
80 | 92 … | ||
81 | -Not even a little bit. | ||
93 … | +The records available to dnssb are sourced from your ssb social network, so the quality of your results will depend on who you choose to follow (and who they choose to follow). | ||
82 | 94 … | ||
95 … | +> How can I deal with malicious behaviour? | ||
96 … | + | ||
97 … | +Records must be published by someone in your social network, and all such records are cryptographically signed using their private key. | ||
98 … | + | ||
99 … | +If you notice malicious behaviour, it can always be traced back to the person who published it, through your social graph, if need be. | ||
100 … | +Naming things is a social problem, and the best way to resolve conflicts is probably to discuss it. | ||
101 … | + | ||
102 … | +Additionally, in the future there will be better support for reporting and blocking abusive behaviour. | ||
103 … | + | ||
83 | 104 … | > Does it resolve conflicts if they occur? | |
84 | 105 … | ||
85 | 106 … | Not yet. | |
86 | 107 … | ||
87 | 108 … | > What is it good for? | |
88 | 109 … | ||
89 | -1. If there is a DNS outage you can still resolve any you or your friends have published to ssb | ||
90 | -2. If you don't have access to the internet at all, this will continue to work (for some definition of work) | ||
110 … | +1. If there is a DNS outage you can still resolve any records you or your friends have published to ssb. | ||
111 … | +2. As with everything committed to ssb, records are stored locally (and indefinitely) in a set of hash chains (one for each user). As such, if you don't have access to the internet at all, this will continue to work | ||
91 | 112 … | 3. You can use this as a kind of distributed hosts file | |
92 | 113 … | ||
93 | 114 … | > How optimized is this? | |
94 | 115 … | ||
95 | 116 … | Not much, but it should get better over time if people are interested in using it. | |
96 | 117 … | ||
118 … | +> Is there a web interface? | ||
119 … | + | ||
120 … | +Not yet, but I'd like there to be! | ||
121 … | + | ||
122 … | +> Does it handle wildcard entries? | ||
123 … | + | ||
124 … | +Not yet, but I'd like it to! | ||
125 … | + |
index.js | ||
---|---|---|
@@ -60,9 +60,8 @@ | ||
60 | 60 … | while (argv[1] && SsbRef.isMsgId(argv[1])) { |
61 | 61 … | branches.push(argv.splice(1)); |
62 | 62 … | } |
63 | 63 … | |
64 | - console.log(argv.length); | |
65 | 64 … | if (argv.length < 4) { |
66 | 65 … | console.log("Try:"); |
67 | 66 … | console.error(publishHelp); |
68 | 67 … | return; |
lib/publish.js | ||
---|---|---|
@@ -22,32 +22,32 @@ | ||
22 | 22 … | var endsInSSB = Publish.endsInSSB = function (s) { |
23 | 23 … | return /\.ssb$/i.test(s); |
24 | 24 … | }; |
25 | 25 … | |
26 | -var isValidRecord = Publish.isValidRecord = function (record) { | |
27 | - // TODO return what's wrong with the input instead of a boolean | |
26 … | +var validateRecord = Publish.validateRecord = function (record) { | |
27 … | + if (!endsInSSB(record.name)) { return "[Record NameError] records must end in .ssb"; } | |
28 … | + if (!isValidType(record.type)) { return "[Record TypeError] " + record.type + " is not a valid dns type"; } | |
29 … | + if (!isValidClass(record.class)) { return "[Record ClassError] class must be one of [" + CLASSES.join(', ') + "]"; } | |
28 | 30 … | |
29 | - return endsInSSB(record.name) && // it ends in .ssb | |
30 | - record.value && // there is a value // TODO validate that it is correct for the type | |
31 | - isValidType(record.type) && // it is a valid type | |
32 | - isValidClass(record.class); // there is a class // TODO make sure it's valid | |
31 … | + // TODO rename 'value' to 'data' ??? | |
32 … | + // TODO perform stricter validation on value | |
33 … | + if (!(record.value && typeof(record.value) === 'string')) { return "[Record DataError] expected a value to publish"; } | |
33 | 34 … | }; |
34 | 35 … | |
35 | 36 … | var makeRecord = Publish.makeRecord = function (name, type, value, _class) { |
36 | 37 … | return { |
37 | 38 … | name: typeof(name) === 'string' && name.toLowerCase(), // domain names must be lowercase |
38 | 39 … | type: type, |
39 | - value: value, | |
40 … | + value: value, // TODO change to 'data' ??? | |
40 | 41 … | class: _class || 'IN', |
41 | 42 … | }; |
42 | 43 … | }; |
43 | 44 … | |
44 | 45 … | Publish.record = function (branches, name, type, value, _class, cb) { |
45 | 46 … | var record = makeRecord(name, type, value, _class); |
46 | 47 … | |
47 | - if (!isValidRecord(record)) { | |
48 | - return void cb(new Error("invalid input")); | |
49 | - } | |
48 … | + var complaint = validateRecord(record); | |
49 … | + if (complaint) { return void cb(new Error(complaint)); } | |
50 | 50 … | |
51 | 51 … | if (!branches.every(SsbRef.isMsgId)) { |
52 | 52 … | return void cb(new Error("invalid branches")); |
53 | 53 … | } |
@@ -64,16 +64,10 @@ | ||
64 | 64 … | |
65 | 65 … | // publish a message |
66 | 66 … | sbot.publish(val, function (err, msg) { |
67 | 67 … | if (err) { return void cb(err); } |
68 | - | |
69 | - | |
70 | 68 … | sbot.close(); |
71 | 69 … | return void cb(err, msg); |
72 | - | |
73 | - console.log(msg); | |
74 | - | |
75 | - console.log(JSON.stringify(record, null, 4)); | |
76 | 70 … | }) |
77 | 71 … | }); |
78 | 72 … | }; |
79 | 73 … |
lib/server.js | ||
---|---|---|
@@ -53,11 +53,11 @@ | ||
53 | 53 … | res.end(); |
54 | 54 … | })); |
55 | 55 … | }; |
56 | 56 … | |
57 | -var createServer = function (sbot, port, host, cb, opt) { | |
57 … | +var createServer = Server.create = function (sbot, port, host, cb, opt) { | |
58 | 58 … | var Dnsd = require("dnsd"); |
59 | - Dnsd.createServer(function(req, res) { | |
59 … | + return Dnsd.createServer(function(req, res) { | |
60 | 60 … | answer(sbot, req, res, opt); |
61 | 61 … | }).listen(port, host, cb); |
62 | 62 … | }; |
63 | 63 … | |
@@ -67,8 +67,16 @@ | ||
67 | 67 … | if (err) { |
68 | 68 … | console.error(err); |
69 | 69 … | return void process.exit(1); |
70 | 70 … | } |
71 | - createServer(sbot, port, host, cb, opt); | |
71 … | + var server = createServer(sbot, port, host, cb, opt); | |
72 … | + | |
73 … | + var close = function () { | |
74 … | + console.error("Server connection lost. Shutting down"); | |
75 … | + sbot.close(); | |
76 … | + server.close(); | |
77 … | + }; | |
78 … | + | |
79 … | + sbot.on('closed', close); | |
72 | 80 … | }); |
73 | 81 … | }; |
74 | 82 … |
package.json | ||
---|---|---|
@@ -1,10 +1,13 @@ | ||
1 | 1 … | { |
2 | 2 … | "name": "ssb-dns", |
3 | - "version": "1.0.20", | |
3 … | + "version": "1.0.22", | |
4 | 4 … | "description": "resolve dns via ssb", |
5 | 5 … | "main": "index.js", |
6 | - "bin": "index.js", | |
6 … | + "bin": { | |
7 … | + "dnssb": "index.js", | |
8 … | + "ssb-dns": "index.js" | |
9 … | + }, | |
7 | 10 … | "scripts": { |
8 | 11 … | "test": "echo \"Error: no test specified\" && exit 1" |
9 | 12 … | }, |
10 | 13 … | "dependencies": { |
Built with git-ssb-web