A presentation by Robin Upton ( ) latest version at Attribution – NonCommercial - ShareAlike FF 4 : Decentralised Programming with F 2 F Decentralised Programming v
(1)Decentralised Programming. WWW as Distributed Programming C C C C C C C S distributed.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 F F F Distributed programs may still be centrally controlled.
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 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. All instructions to F2F servers take the form: etc.
Hello-World Service. Processing Service Requests We start by requesting the service: So this is implemented by the XSL template at 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 itself is the script’s Input Document: Hello World! Processing Service Requests 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(“ 130, 500) <!-- Transform here, which operates on the whole XML document --!> F2F passes an XML document:
Nested Servicereqs. Processing Directives browse(“ getwidth(), getheight()) By default, F2F starts with the deepest : Evaluation is usually from inside out: <!-- Transform here, which gets the width. --!> <!-- Transform here, which gets the height. --!> <!-- Transform here, which operates on the whole XML document --!>
Nested Servicereqs = Pipelined XML A may have extra attributes, called processing directives. Processing Directives XSL stylesheet Raw XML Output Post- processed XML Output Pre- processed Input: servicereq Raw Input: servicereq Pre-processing directives modify the input of the stylesheet. Mid-processing & Post-processing directives modify the output. For more details, see: FF6: Common Processing Directives
Tree-shaped Pipelines Nested items results in pipelining XML: Nested Servicereqs = Pipelined XML The interior outputs XML......which is fed into the exterior... XSL ex.1 XSL ex.2 XML pipelining is taking the input from one transform and feeding it into another:
Core Services The model allows trees of transforms. Tree-shaped Pipelines XSL 2B XSL 3 3b 3a XSL 2A 3c 2b XSL 1A XSL 1B 1a 2a22a1 1b
Saving Instructions About 80 hardcoded (non-XSLT) services extend the possibilities. e.g: Core Services Send/Receive Read/Write XML data Read/Write the F2F Server Read/Write Files to disk
Sending Instructions in the below will be interpreted -->...May contain instructions or data... //wherever.xml <servicereq Saving Instructions To write an XML file to disk: If the data above contained this would get interpreted first. //wherever.xml <servicereq To prevent descendants from being interpreted, add f2f:escaped=”!”:
Clientside Instructions <servicereq Sending Instructions Sending instructions to another server requires a different form of escaping: The f2f:sendescaped attribute is decreased by 1 whenever the data is sent, so: f2f:sendescaped =”1”- Run on friend's server f2f:sendescaped =”2”- Run on friend of a friend's server f2f:sendescaped =”3”- Run on friend of a friend of a friend's server...
Icon here XSLT Transform output here Will be transformed Summary Clientside Instructions Clients interpret, and elements......so XML can be used to script client interactivity.
Summary F2F scripts use XSLT, extended with about 80 extra core functions. Nested items pipeline XML data & instructions. A JS F2F client is available for Firefox. Recommended Follow-up: FF5: Service Request Processing Model F2F servers are general purpose XML virtual machines. F2F servers are designed to form decentralised networks....