blob: bb4b7da196cfcc4c1479b3e517aeb057a1cad0da [file] [log] [blame]
Meki Cherkaouif2e96ed2012-04-22 16:21:27 -07001
Jeff Burke004039b2012-12-08 11:31:37 -08002NDN.JS: A javascript client library for Named Data Networking
3--------------------------------------------------------------
Meki Cherkaouif2e96ed2012-04-22 16:21:27 -07004
Jeff Burke004039b2012-12-08 11:31:37 -08005NDN.JS is the first native version of the NDN protocol written in JavaScript. It is wire format compatible with PARC's CCNx.
Meki Cherkaouif2e96ed2012-04-22 16:21:27 -07006
Jeff Burke004039b2012-12-08 11:31:37 -08007The project by the UCLA NDN team - for more information on NDN, see
8 http://named-data.net/
9 http://ndn.ucla.edu/
10
11NDN.JS is open source under a license described in the file COPYING. While the license does not require it, we really would appreciate it if others would share their contributions to the library if they are willing to do so under the same license.
Meki Cherkaouif2e96ed2012-04-22 16:21:27 -070012
Jeff Burke004039b2012-12-08 11:31:37 -080013---
14
15This is a young project, with minimal documentation that we are slowly enhancing. Please email Jeff Burke (jburke@remap.ucla.edu) with any questions.
16
17The primary goal of NDN.JS is to provide a pure Javascript implementation of the NDN API that enables developers to create browser-based applications using Named Data Networking. The approach requires no native code or signed Java applets, and thus can be delivered over the current web to modern browsers with no hassle for the end user.
18
19Additional goals for the project:
Jeff Burke858c07a2012-12-08 11:35:25 -080020- Websockets transport (rather than TCP or UDP, which are not directly supported in Javascript).
21- Relatively lightweight and compact, to enable efficient use on the web.
22- Wire format compatible with PARC's CCNx implementation of NDN.
Jeff Burke004039b2012-12-08 11:31:37 -080023
24The library currently requires a remote NDN daemon, and has been tested with ccnd, from the's CCNx package: http://ccnx.org/
25
26Currently, the library has two APIs for developers:
27
28 1. The Javascript API for asynchronous Interest/Data exchange.
29 This uses WebSockets for transport and currently requires a
30 proxy for communication with a remote ccnd daemon.
31
32 2. A Firefox plug-in, which implements an "ndn:/" url scheme
33 following CCNx repository conventions for file retrieval.
34
35By default, both parts of the library connect automatically to a set of proxies and hubs that are part of the NDN research project's testbed. http://named-data.net/testbed.html There are currently no restrictions on non-commercial, research-oriented data exchange on this testbed. (Contact jburke@remap.ucla.edu for more details.) The developer can also specify a local or remote ccnd as well, as an argument to the NDN constructor.
36
37
38
39JAVASCRIPT API
40--------------
41
Jeff Burke33546102012-12-08 11:55:36 -080042See files in js/ and examples in js/testing, js/examples
Jeff Burke004039b2012-12-08 11:31:37 -080043
44NDN.JS currently supports expressing Interests (and receiving data) and publishing Data (that answers Interests). This includes encoding and decoding data packets as well as signing and verifying them using RSA keys.
45
Jeff Burke33546102012-12-08 11:55:36 -080046** NDN connectivity **
47The only way (for now) to get connectivity to other NDN nodes is via ccnd. For the Javascript API, a Websockets proxy that can communicate the target ccnd is currently required. Code for such a proxy (using Node.js) is in the wsproxy directory. It currently listens on port 9696 and passes messages (using either TCP or UDP) to ccnd on the same host.
Jeff Burke858c07a2012-12-08 11:35:25 -080048
Jeff Burke33546102012-12-08 11:55:36 -080049** Including the scripts in a web page **
50To use NDN.JS in a web page, one of two scripts must be included using a <script> tag:
51
521. ndn-js.js, a combined, compressed library designed for efficient distribution. It can be built using js/tools/build/make-js.sh This is used in examples/ndn-ping.html
53
542. Helper.js, which loads each component script independently. This is used in most of the tests in testing/
55
56** Example **
Jeff Burke004039b2012-12-08 11:31:37 -080057A simple example of the current API to express an Interest and receive data:
58
Jeff Burke858c07a2012-12-08 11:35:25 -080059var ndn = new NDN(); // connect to a default hub/proxy
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080060ndn.transport.connectWebSocket(ndn);
61
62var AsyncGetClosure = function AsyncGetClosure() {
63 // Inherit from Closure.
64 Closure.call(this);
65};
66AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) {
67 if (kind == Closure.UPCALL_CONTENT) {
68 console.log("Received " + upcallInfo.contentObject.name.to_uri());
69 console.log(upcallInfo.contentObject.content);
70 }
71 return Closure.RESULT_OK;
72};
Jeff Thompson9e6dff02012-11-04 09:20:47 -080073
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080074ndn.expressInterest(new Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt"), new AsyncGetClosure());
Jeff Thompson9e6dff02012-11-04 09:20:47 -080075
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080076
Jeff Burke004039b2012-12-08 11:31:37 -080077FIREFOX ADD-ON FOR THE NDN PROTOCOL
78-----------------------------------
79
80See files in js/ndnProtocol
81
Jeff Burke33546102012-12-08 11:55:36 -080082NDN.JS includes a Firefox extension for the ndn protocol built using the Javascript library. It currently obtains NDN connectivity through the NDN testbed. (This is hard-coded.)
Jeff Burke004039b2012-12-08 11:31:37 -080083
84To install, either download
Jeff Thompsonbd829262012-11-30 22:28:37 -080085https://github.com/remap/ndn-js/blob/master/js/ndnProtocol.xpi
86or use js/ndnProtocol.xpi in the distribution. In Firefox, open
Jeff Thompson9e6dff02012-11-04 09:20:47 -080087Tools > Add-ons. In the "gear" or "wrench" menu, click Install Add-on From File and open
Jeff Thompsonbd829262012-11-30 22:28:37 -080088ndnProtocol.xpi. Restart Firefox.
Jeff Thompson9e6dff02012-11-04 09:20:47 -080089
Jeff Thompsonbd829262012-11-30 22:28:37 -080090Firefox uses the protocol extension to load any URI starting with ndn, for example
91ndn:/ndn/ucla.edu/apps/lwndn-test/trig-table
Jeff Thompson9e6dff02012-11-04 09:20:47 -080092
Jeff Burke33546102012-12-08 11:55:36 -080093When the page is loaded, Firefox updates the address bar with the full matched name from the retrieved content object including the version, but without the implicit digest or segment number (see below).
94
95
96
Jeff Thompson9e6dff02012-11-04 09:20:47 -080097
Jeff Burke004039b2012-12-08 11:31:37 -080098* Interest selectors in the ndn protocol:
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080099
100You can add interest selectors. For example, this uses 1 to select the "rightmost" child (latest version).
Jeff Thompsonbd829262012-11-30 22:28:37 -0800101ndn:/ndn/ucla.edu/apps/ndn-js-test/hello.txt?ndn.ChildSelector=1&key=value#ref
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800102
103The browser loads the latest version and changes the address to:
Jeff Thompsonbd829262012-11-30 22:28:37 -0800104ndn:/ndn/ucla.edu/apps/ndn-js-test/hello.txt/%FD%05%0B%16z%22%D1?key=value#ref
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800105
Jeff Thompsonbd829262012-11-30 22:28:37 -0800106The child selector was used and removed. Note that the other non-ndn query values and
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800107ref "?key=value#ref" are still present, in case they are needed by the web application.
108
109The following selector keys are supported:
Jeff Thompsonbd829262012-11-30 22:28:37 -0800110ndn.MinSuffixComponent= non-negative int
111ndn.MaxSuffixComponents= non-negative int
112ndn.ChildSelector= non-negative int
113ndn.AnswerOriginKind= non-negative int
114ndn.Scope= non-negative int
115ndn.InterestLifetime= non-negative int
116ndn.PublisherPublicKeyDigest= % escaped value
117ndn.Nonce= % escaped value
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800118
Jeff Thompsonbd829262012-11-30 22:28:37 -0800119TODO: implement ndn.Exclude.
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800120
Jeff Thompsonbd829262012-11-30 22:28:37 -0800121* Multiple segments in the ndn protocol
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800122
Jeff Burke33546102012-12-08 11:55:36 -0800123A URI for content with multiple segments is handled as follows. If the URI has a segment number, just retrieve that segment and return the content to the browser.
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800124
Jeff Burke33546102012-12-08 11:55:36 -0800125Otherwise look at the name in the returned ContentObject. If the returned name has no segment number, just return the content to the browser. If the name has a segment number which isn't 0, store it and express an interest for segment 0. Read segments in order and return each content to the browser as we go until we get the segment for FinalBlockID.
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800126