Wikipedia over DNS

I had written some code to take wikipedia articles and summarise them. I wanted to offer this for use in various places, now the obvious way to offer it is just a web service (via REST, XMLRPC, etc), but that's boring and I had a cunning plan. Why not offer it over DNS - it is basically a huge associative array and DNS is designed for this stuff.

So I wrote a little nameserver which returns the results as TXT records. There are some obvious limitations for example responses are limited to around 430 bytes (it only does UDP and no EDNS). It has advantages too, it gets cached at your nameserver and it also has slightly lower latency than HTTP (because there's no need to setup a TCP session).

Here's an example:

$ host -t txt foo.wp.dg.cx
foo.wp.dg.cx descriptive text "Foo may refer to: Foo, bar, and baz: metasyntactic variables, \"Fool\", as a nonstandard spelling to indicate a nonstandard pronunciation, Foo Fighters, a post-grunge group formed by Dave Grohl, Foo fighters, a World War II term for various UFOs or mysterio\" \"us aerial phenomena seen in the skies over Europe and the Pacific theatre, Foo, also a known surname or last name of a... http://a.vu/w:Foo"

Using it from Perl is fairly easy too, with a little help from Net::DNS:

use Net::DNS;
my $res = Net::DNS::Resolver->new;

sub wikipedia {
  my($name) = @_;
  my $q = $res->query("$name.wp.dg.cx", "TXT");
  if($q) {
    for my $rr($q->answer) {
      next unless $rr->type eq "TXT";
      return join "", $rr->char_str_list;
    }
  }
}

print wikipedia($ARGV[0]);

Unicode should be supported, all DNS queries are expected to be in UTF-8 (this assumes your resolver is happy with 8 bit characters, some aren't---I might support IDN one day). See the example below (the perl is just there to unescape the escaping dig does). The result is returned in UTF-8, which everything can handle. For example:

$ dig +short txt '新疆.wp.dg.cx' | perl -pe's/\\(\d{1,3})/chr $1/eg'
"Xinjiang (Uyghur: , Shinjang\; \; Postal map spelling: Sinkiang) is an autonomous region (Xinjiang Uyghur Autonomous Region) of the People's Republic of China. It is a large, sparsely populated area (spanning over 1.6 million sq. km) which takes up about on" "e sixth of the country's territory. Xinjiang borders the Tibet Autonomous Region to the south and Qinghai and Gansu... http://a.vu/w:Xinjiang"

I did a talk on this at London Perl Workshop 2008, the slides are here.