blob: cf9c330eca733405ea4d724ec8bd5a9b1f6b4ca7 [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
42See files in js/ and examples in js/testing/
43
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 Burke858c07a2012-12-08 11:35:25 -080046To use the library with a remote ccnd, a Websockets proxy 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.
47
Jeff Burke004039b2012-12-08 11:31:37 -080048A simple example of the current API to express an Interest and receive data:
49
Jeff Burke858c07a2012-12-08 11:35:25 -080050var ndn = new NDN(); // connect to a default hub/proxy
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080051ndn.transport.connectWebSocket(ndn);
52
53var AsyncGetClosure = function AsyncGetClosure() {
54 // Inherit from Closure.
55 Closure.call(this);
56};
57AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) {
58 if (kind == Closure.UPCALL_CONTENT) {
59 console.log("Received " + upcallInfo.contentObject.name.to_uri());
60 console.log(upcallInfo.contentObject.content);
61 }
62 return Closure.RESULT_OK;
63};
Jeff Thompson9e6dff02012-11-04 09:20:47 -080064
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080065ndn.expressInterest(new Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt"), new AsyncGetClosure());
Jeff Thompson9e6dff02012-11-04 09:20:47 -080066
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080067
Jeff Burke004039b2012-12-08 11:31:37 -080068FIREFOX ADD-ON FOR THE NDN PROTOCOL
69-----------------------------------
70
71See files in js/ndnProtocol
72
73NDN.JS includes a Firefox extension for the ndn protocol.
74
75To install, either download
Jeff Thompsonbd829262012-11-30 22:28:37 -080076https://github.com/remap/ndn-js/blob/master/js/ndnProtocol.xpi
77or use js/ndnProtocol.xpi in the distribution. In Firefox, open
Jeff Thompson9e6dff02012-11-04 09:20:47 -080078Tools > Add-ons. In the "gear" or "wrench" menu, click Install Add-on From File and open
Jeff Thompsonbd829262012-11-30 22:28:37 -080079ndnProtocol.xpi. Restart Firefox.
Jeff Thompson9e6dff02012-11-04 09:20:47 -080080
Jeff Thompsonbd829262012-11-30 22:28:37 -080081Firefox uses the protocol extension to load any URI starting with ndn, for example
82ndn:/ndn/ucla.edu/apps/lwndn-test/trig-table
Jeff Thompson9e6dff02012-11-04 09:20:47 -080083
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080084When the page is loaded, Firefox updates the address bar with the full matched name from the
Jeff Thompson9e6dff02012-11-04 09:20:47 -080085retrieved content object including the version, but without the implicit digest or segment number
86(see below).
87
Jeff Burke004039b2012-12-08 11:31:37 -080088* Interest selectors in the ndn protocol:
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080089
90You can add interest selectors. For example, this uses 1 to select the "rightmost" child (latest version).
Jeff Thompsonbd829262012-11-30 22:28:37 -080091ndn:/ndn/ucla.edu/apps/ndn-js-test/hello.txt?ndn.ChildSelector=1&key=value#ref
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080092
93The browser loads the latest version and changes the address to:
Jeff Thompsonbd829262012-11-30 22:28:37 -080094ndn:/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 -080095
Jeff Thompsonbd829262012-11-30 22:28:37 -080096The child selector was used and removed. Note that the other non-ndn query values and
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080097ref "?key=value#ref" are still present, in case they are needed by the web application.
98
99The following selector keys are supported:
Jeff Thompsonbd829262012-11-30 22:28:37 -0800100ndn.MinSuffixComponent= non-negative int
101ndn.MaxSuffixComponents= non-negative int
102ndn.ChildSelector= non-negative int
103ndn.AnswerOriginKind= non-negative int
104ndn.Scope= non-negative int
105ndn.InterestLifetime= non-negative int
106ndn.PublisherPublicKeyDigest= % escaped value
107ndn.Nonce= % escaped value
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800108
Jeff Thompsonbd829262012-11-30 22:28:37 -0800109TODO: implement ndn.Exclude.
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800110
Jeff Thompsonbd829262012-11-30 22:28:37 -0800111* Multiple segments in the ndn protocol
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800112
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800113A URI for content with multiple segments is handled as follows.
114If the URI has a segment number, just retrieve that segment and return the content to the browser.
115
116Otherwise look at the name in the returned ContentObject. If the returned name has no segment number,
117just return the content to the browser. If the name has a segment number which isn't 0, store it
118and express an interest for segment 0. Read segments in order and return each content to the browser
119as we go until we get the segment for FinalBlockID.
120