Difference between revisions of "Namecoin SPA"
m (→See also) |
(nodes need to be <500 bytes not 1KB :-() |
||
| Line 1: | Line 1: | ||
| − | 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. | + | 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 [https://github.com/namecoin/namecoin/issues/3 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 | |
| − | {{code|<perl>use IO::Socket; | + | {{code|<perl>sub n { |
| + | my $c=shift; | ||
| + | $_=`namecoind name_show d/$c`; | ||
| + | $_=/"value"\s*:\s*"(.*?[^\\])"/s?$1:"404"; | ||
| + | s/\\"/"/g;s/\\n/\n/g; | ||
| + | } | ||
| + | sub d { | ||
| + | my $s=shift; | ||
| + | my $c=n($s); | ||
| + | eval "sub $s {$c}"; | ||
| + | } | ||
| + | d('od_http');</perl>}} | ||
| + | |||
| + | |||
| + | ;od_http | ||
| + | {{code|<perl>d('od_recv'); | ||
| + | d('od_send'); | ||
| + | use IO::Socket; | ||
sub Wait {wait;} | sub Wait {wait;} | ||
$SIG{CHLD}=\&Wait; | $SIG{CHLD}=\&Wait; | ||
| Line 9: | Line 26: | ||
next if $pid = fork; | next if $pid = fork; | ||
die "fork - $!\n" unless defined $pid; | die "fork - $!\n" unless defined $pid; | ||
| − | + | od_send(n(od_recv())); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
exit(fork); | exit(fork); | ||
} | } | ||
| Line 25: | Line 32: | ||
| − | + | ;od_recv | |
| + | {{code|<perl>$i = '';while(<$c>){last if/^\r\n$/;$i.=$_;} | ||
| + | $_=$i=~/^GET \/([a-z0-9]+)/?$1:n("od_html").n("od_head") | ||
| + | ."<body><script>".n("od_js")."</script></body></html>";</perl>}} | ||
| + | |||
| + | |||
| + | ;od_send | ||
| + | {{code|<perl>$l=length $_; | ||
| + | select $c; | ||
| + | $|=1; | ||
| + | print $c "HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=UTF-8\nConnection: Keep-Alive\n" | ||
| + | ."Keep-Alive: timeout=15, max=100\nContent-Length: $l\n\n$_\r\n\r\n"; | ||
| + | close($c);</perl>}} | ||
| + | |||
| + | |||
| + | ;od_html | ||
{{code|<xml><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | {{code|<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"> | + | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"></xml>}} |
| − | + | ||
| − | + | ||
| − | + | ;od_head | |
| − | + | {{code|<xml><head> | |
| − | + | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
| − | + | <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> | |
| − | + | <script type="text/javascript" src="http://code.jquery.com/ui/jquery-ui-git.js"></script> | |
| − | + | <link rel="stylesheet" href="http://code.jquery.com/ui/jquery-ui-git.css" media="screen" /> | |
| − | + | </head></xml>}} | |
| − | + | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| + | ;od_js | ||
| + | {{code|<js>function hash() { | ||
| + | var h=window.location.hash.substr(1); | ||
| + | if(h){ | ||
| + | $.ajax({ | ||
| + | type: "GET", | ||
| + | url: "/"+h, | ||
| + | success: function(d) { alert(d) } | ||
| + | }); | ||
| + | } else alert("no hash"); | ||
| + | } | ||
| + | $(window).bind("hashchange", hash); | ||
| + | hash();</js>}} | ||
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. | 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. | ||
Revision as of 00:58, 26 August 2012
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
- od_http
- od_recv
- od_send
- od_html
- od_head
- od_js
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.



