Namecoin SPA

From Organic Design wiki
Revision as of 01:14, 26 August 2012 by Nad (talk | contribs) (intros)

I'm making a Single Page Application which exists entirely inside the Namecoin network's name:value storage system. Values can only be a maximum size of one kilobyte, so the boot-strapping has to be very modular. In fact it turns out that the current version has a bug that prevents values from being updated if the current value is greater than 520 bytes! There's discussion about raising the limit at some point to around 9KB, but incurring steepwe transaction costs for updates greater than 1KB.

od_init is the first node which declares two functions, the first called "n" takes a namecoin domain name and returns the content of its value field, or "404" if no such name was found. The second function called "d" extends the first function be taking a namecoin domain name and treating its value as the content of a function which it declares. After the two functions are declared, it then calls "d" with "od_http" as the parameter to declare the contents of that domain as a function, and then calls that function.

{{{1}}}


od_http is a small server loop which listens for HTTP requests on port 2012, it declares functions from two other domains, "od_recv" and "od_send" which are called within the loop. The od_recv function is called when the server loop detects that input needs to be processed, the result will always be a domain name which is then passed through the "n" function to get its value, and this value is sent back to the client as an HTTP response message by od_send.

{{{1}}}


od_recv reads in the GET request text and extracts just the valid domain part of it if any. If no domain is requested, then an HTML page is constructed from three other domains, "od_html" (an HTML DOCTYPE definition and opening element), "od_head" (meta tags, CSS and useful JS frameworks) abd "od_js" which is the next stage of the applications execution.

{{{1}}}
od_send
{{{1}}}


od_html
<xml><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"></xml>


od_head
{{{1}}}


od_js
{{{1}}}

If no hash fragment is specified, then a default node is used which contains JavaScript that gets executed (this only happens for this known default node, not for any arbitrary nodes). This JavaScript is the basic Single Page Application, or "viewer application" that knows how to render the DNS relationships between the nodes recirsively, so that further nodes can build up more complex applicational functionality.

See also