Difference between revisions of "Namecoin SPA"

From Organic Design wiki
(intros)
m
Line 16: Line 16:
  
  
'''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''.
+
'''od_http''' is a small server loop which listens for HTTP requests on port 2012, it declares functions from two other domains, "od_send" and "od_recv" 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''.
{{code|<perl>d('od_recv');
+
{{code|<perl>d('od_send');
d('od_send');
+
d('od_recv');
 
use IO::Socket;
 
use IO::Socket;
 
sub Wait {wait;}
 
sub Wait {wait;}
Line 32: Line 32:
  
  
'''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.
+
'''od_send''' composes the passed content into an HTTP message and sends it to the client.
{{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 $_;
 
{{code|<perl>$l=length $_;
 
select $c;
 
select $c;
Line 46: Line 41:
  
  
;od_html
+
'''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.
 +
{{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_html''' is a standard DOCTYPE definition and opening HTML element for our applications page.
 
{{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"></xml>}}
 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"></xml>}}
  
  
;od_head
+
'''od_head''' is the HTML ''head'' element for our page including some useful Javascript frameworks and CSS.
 
{{code|<xml><head>
 
{{code|<xml><head>
 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Line 60: Line 60:
  
  
;od_js
+
'''od_js''' is the initial structure of our Single Page Application, defining the event-handler for changes in the hash-fragment, and retrieving newly requested domain values from the server via Ajax request. Like the Perl stage, this stage must first ensure that it has the ability to declare new functionality from other namecoin domain values.
 
{{code|<js>function hash() {
 
{{code|<js>function hash() {
 
   var h=window.location.hash.substr(1);
 
   var h=window.location.hash.substr(1);
Line 73: Line 73:
 
$(window).bind("hashchange", hash);
 
$(window).bind("hashchange", hash);
 
hash();</js>}}
 
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.
 
  
 
== See also ==
 
== See also ==
 
*[https://github.com/namecoin/namecoin/issues/3 Bug - cannot update a value if current value is greater than 520 bytes]
 
*[https://github.com/namecoin/namecoin/issues/3 Bug - cannot update a value if current value is greater than 520 bytes]

Revision as of 01:28, 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 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_send" and "od_recv" 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_send composes the passed content into an HTTP message and sends it to the client.

{{{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_html is a standard DOCTYPE definition and opening HTML element for our applications page.

<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 is the HTML head element for our page including some useful Javascript frameworks and CSS.

{{{1}}}


od_js is the initial structure of our Single Page Application, defining the event-handler for changes in the hash-fragment, and retrieving newly requested domain values from the server via Ajax request. Like the Perl stage, this stage must first ensure that it has the ability to declare new functionality from other namecoin domain values.

{{{1}}}

See also