okTurtles / dnschain

A blockchain-based DNS + HTTP server that fixes HTTPS security, and more!
https://okturtles.com
Other
1.73k stars 170 forks source link

Add `key` resource to icann.coffee & verify it works #131

Closed taoeffect closed 9 years ago

taoeffect commented 9 years ago

Pretty much the title, but also:

  1. In blockchain.coffee under resultTemplate:, change the header key blockchain: to datastore:. At some point we might even rename the entire file and class from "blockchain" to "datasource" since we're already mixing non-blockchain stuff.
  2. Verify that this request works:
$ curl "localhost:8088/v1/icann/key/okturtles.com"
{"version":"0.0.1","header":{"datasource":"icann"},"value":{"edns_options":[],"answer":[{"name":"okturtles.com","type":1,"class":1,"ttl":299,"address":"192.184.93.146"}],"authority":[],"additional":[]}}

I'm concerned it will break because I think I got the regex wrong:

+ (?:\/([^\/\.]+))? # optional property (or action on resource)

The reason I excluded the . was because we didn't want to capture what could be the start of the response format. So a request like the above will currently think that .com is the format. Doh!

I think the regex should be something like this instead:

/// ^
    \/(\w+)           # the datastore name
    \/(\w+)           # the corresponding resource
    (?:\/([^\/]+))?   # optional property (or action on resource)
    (?:\/([^\/]+))?   # optional action on property
    (?:\.(json|xml))? # optional response format
$ ///

Might not be exactly correct... it'll need to tested it thoroughly. It needs to handle both of these requests correctly (they should return the same result):

localhost:8088/v1/icann/key/okturtles.com
localhost:8088/v1/icann/key/okturtles.com.json

If the modified regex above doesn't work, then maybe play with negative lookahead (something like (?:\/([^\/]+(?!\.json|\.xml)))?).

wemeetagain commented 9 years ago

see a90f935

taoeffect commented 9 years ago

Fixed in 2a3ebaf.