a presentation by robin upton (2009-03-12) latest version at attribution – noncommercial -...
TRANSCRIPT
A presentation by Robin Upton (2009-03-12)latest version at www.altruists.org/ff4
Attribution – NonCommercial - ShareAlike
www.altruists.org
FF404: Decentralised F2F Programming in 4 Minutes
Decentralised Programming
v1.0
http://www.altruists.org/ff4
(1) Decentralised Programming
. WWW as Distributed Programming
C C C C C C C
Sdistributed.net = Distributed, Centralised
Calculations are performed by many CPUs, but directed by a single authority.
Friend2Friend.net = Distributed, Decentralised
Each computers in F2F network has unique local data & instructions. None has special privilege.
F
F F
F FF
F
Distributed programs may still be centrally controlled.
http://www.distributed.net
Sites:
code data code data code data code data
WWW as Distributed Programming
Clients Send Data
Websites have unique instructions and data stores...
Clients send data to one site at a time
Clients:
Clients Send Data
. Servers Return Data
Users input data through browsers and pass it to websites:
decentralization
Servers Return Data
Code ≠ Data
Websites receive data, carry out instructions, return data to clients
Code ≠ Data
'Code' = XML = 'Data'
function f2fError($text, $nodename='error'){ // Example of usual source code
$err= new DOMDocument();$errnode=$err->createElementNS(nsF2F, $nodename, $text);$err->appendChild($errnode);return $err;
}to be processed by trusted code.
Untrusted data is dynamically input...
Most programming languages cannot treat data as code.
'Code' = XML = 'Data'
(2) How to Program F2F
In F2F, programs, instructions and data share a common format: XML
F2F data streams can embed instructions, allowing for rich interaction.
i.e. Sites can dynamically script other sites.
F2F service, coded in
XML<input> arbitrary XML ...
<output> arbitrary XML ...
(2) How to Program F2F
. Hello World Service
F2F servers are XML virtual machines. Input, output & internal
workings are XML.
Although required, the namespace is omitted for brevity from this point on.
<servicereq>
All instructions to F2F servers take the form:
<f2f:servicereq function=“some URI”/>
<fatal-error> <message> <process>
<thread> etc.
XML Stylesheet Language Transformations v1.0
... is a 1999 W3C recommendation!
... is a programming language expressed in XML.
... transforms one XML document into another.
... ‘side-effect free’, so cannot write files/send messages/ etc.
http://www.w3.org/TR/xslt
Hello-World Service
. Processing Service Requests
We start by requesting the service:
<servicereq function=“http://friend2friend.net/modules/demo/hello-world”/>
So this is implemented by the XSL template at hello.xslt
<service rdf:about=“http://friend2friend.net/modules/demo/hello-world” src= “hello.xslt”/>
The F2F server finds the matching service definition:
Unique identifier
Location on disk
Passing Arguments
The XSL transforms it to an Output Document:
The <servicereq> itself isthe script’s Input Document:
<?xml version="1.0"?>
<!-- -->
<!-- HELLO-WORLD: --!>
<!-- Prints "Hello World",
whatever arguments it receives. ->
<!-- -->
<stylesheet version="1.0"
xmlns="http://www.w3.org/1999/XSL/Transform
" xmlns:f2f="http://friend2friend.net/">
<template match="/f2f:servicereq[@function=
'http://friend2friend.net/modules/demo/hello-
world']">Hello World!</template>
</stylesheet>
Processing Service Requests
<servicereq function=“http://friend2 friend.net/modules/demo/hello-world”>
Hello World!
Passing Arguments
Nested Servicereqs
Many languages pass a comma separated list of input parameters to a function:
function browse($uri, $width, $height){ ...instructions here, in which $uri , $width and $height are
replaced at run time by the values of the arguments given...}
browse(“http://friend2friend.net”, 130, 500)
<servicereq function=”http://f2f.name/browse”> <uri>http://friend2friend.net</uri> <width>130</width> <height>500<height> </servicereq>
<?xml version="1.0"?>
<!-- BROWSE -->
<!-- Transform here,
which operates
on the whole
XML document
--!>
F2F passes an XML document:
Nested Servicereqs
. Processing Directives
browse(“http://friend2friend.net”, getwidth(), getheight())
By default, F2F starts with the deepest <servicereq>:
Evaluation is usually from inside out:
<servicereq function=”http://f2f.name/browse”> <uri>http://friend2friend.net</uri> <width><servicereq function=”http://f2f.name/get-width”/></width> <height><servicereq function=”http://f2f.name/get-height”/><height> </servicereq>
130 500
<height>500</height><width>130</width>
<?xml version="1.0"?>
<!-- GET-WIDTH -->
<!-- Transform here,
which gets the
width.
--!>
<?xml version="1.0"?>
<!-- GET-HEIGHT -->
<!-- Transform here,
which gets the
height.
--!>
<?xml version="1.0"?>
<!-- BROWSE -->
<!-- Transform here,
which operates
on the whole
XML document
--!>
Tree-shaped Pipelines
Nested <servicereq> items results in pipelining
XML:
Nested Servicereqs = Pipelined XML
The interior <servicereq> outputs XML...
...which is fed into the exterior
<servicereq>
<servicereq function=”ex.2”><servicereq function=”ex.1”>
<input>...</input></servicereq>
</servicereq>
XSLex.1
XSLex.2
XML pipelining is taking the input from one transform and feeding it into another:
Core Services
The <servicereq> model allows trees of transforms.
Tree-shaped Pipelines
XSL
2B
XSL
3
<servicereq function=”3”><input3a/><servicereq function=”2A”>
<input2a1/><servicereq function=”1A”>
<input1a/></servicereq><input2a2/><servicereq function=”1B”>
<input1b/></servicereq>
</servicereq><input3b/><servicereq function=”2B”>
<input2b></servicereq><input3c/>
</servicereq>
3b
3a
XSL
2A
3c
2b
XSL
1A
XSL
1B
1a
2a2
2a1
1b
Saving Instructions
About 80 hardcoded (non-XSLT) services extend the possibilities. e.g:
Core Services
Send/Receive <message> http://friend2friend.net/services/send
http://friend2friend.net/services/receive
Read/Write XML datahttp://friend2friend.net/services/xml-write
http://friend2friend.net/services/xml-read When will Bush get convict
Read/Write the F2F Server http://friend2friend.net/services/access-get
http://friend2friend.net/services/access-set
Read/Write Files to diskhttp://friend2friend.net/services/fs-read
http://friend2friend.net/services/fs-write
www.friend2friend.net
F2F scripts use XSLT, extended with about 100 extra core functions.
Nested <f2f:servicereq> items pipeline XML data & instructions.
http://www.altruists.org/ff5
F2F servers are general purpose XML virtual machines.
F2F servers are designed to form decentralised networks.
<servicereq function=”ex.2”> <servicereq function=”ex.1”> <input>...</input> </servicereq></servicereq>