blob: f5c1be035b5eda1455d65d259aa18f2fdadc25f6 [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 Burke169445b2012-12-08 12:15:54 -08005NDN.JS is the first native version of the NDN protocol written in JavaScript. It is wire
6format compatible with PARC's CCNx.
Meki Cherkaouif2e96ed2012-04-22 16:21:27 -07007
Jeff Burke004039b2012-12-08 11:31:37 -08008The project by the UCLA NDN team - for more information on NDN, see
9 http://named-data.net/
10 http://ndn.ucla.edu/
11
Jeff Burke169445b2012-12-08 12:15:54 -080012NDN.JS is open source under a license described in the file COPYING. While the license
13does not require it, we really would appreciate it if others would share their
14contributions to the library if they are willing to do so under the same license.
Meki Cherkaouif2e96ed2012-04-22 16:21:27 -070015
Jeff Burke004039b2012-12-08 11:31:37 -080016---
17
Jeff Burke169445b2012-12-08 12:15:54 -080018This is a young project, with minimal documentation that we are slowly enhancing. Please
19email Jeff Burke (jburke@remap.ucla.edu) with any questions.
Jeff Burke004039b2012-12-08 11:31:37 -080020
Jeff Burke169445b2012-12-08 12:15:54 -080021The primary goal of NDN.JS is to provide a pure Javascript implementation of the NDN API
22that enables developers to create browser-based applications using Named Data Networking.
23The approach requires no native code or signed Java applets, and thus can be delivered
24over the current web to modern browsers with no hassle for the end user.
Jeff Burke004039b2012-12-08 11:31:37 -080025
26Additional goals for the project:
Jeff Burke169445b2012-12-08 12:15:54 -080027- Websockets transport (rather than TCP or UDP, which are not directly supported in
28Javascript).
Jeff Burke858c07a2012-12-08 11:35:25 -080029- Relatively lightweight and compact, to enable efficient use on the web.
30- Wire format compatible with PARC's CCNx implementation of NDN.
Jeff Burke004039b2012-12-08 11:31:37 -080031
Jeff Burke169445b2012-12-08 12:15:54 -080032The library currently requires a remote NDN daemon, and has been tested with ccnd, from
33the's CCNx package: http://ccnx.org/
Jeff Burke004039b2012-12-08 11:31:37 -080034
35Currently, the library has two APIs for developers:
36
37 1. The Javascript API for asynchronous Interest/Data exchange.
38 This uses WebSockets for transport and currently requires a
39 proxy for communication with a remote ccnd daemon.
40
41 2. A Firefox plug-in, which implements an "ndn:/" url scheme
42 following CCNx repository conventions for file retrieval.
43
Jeff Burke169445b2012-12-08 12:15:54 -080044By default, both parts of the library connect automatically to a set of proxies and hubs
45that are part of the NDN research project's testbed. http://named-data.net/testbed.html
46There are currently no restrictions on non-commercial, research-oriented data exchange on
47this testbed. (Contact jburke@remap.ucla.edu for more details.) The developer can also
48specify a local or remote ccnd as well, as an argument to the NDN constructor.
Jeff Burke004039b2012-12-08 11:31:37 -080049
50
51
52JAVASCRIPT API
53--------------
54
Jeff Burke33546102012-12-08 11:55:36 -080055See files in js/ and examples in js/testing, js/examples
Jeff Burke004039b2012-12-08 11:31:37 -080056
Jeff Burke169445b2012-12-08 12:15:54 -080057NDN.JS currently supports expressing Interests (and receiving data) and publishing Data
58(that answers Interests). This includes encoding and decoding data packets as well as
59signing and verifying them using RSA keys.
Jeff Burke004039b2012-12-08 11:31:37 -080060
Jeff Burke33546102012-12-08 11:55:36 -080061** NDN connectivity **
Jeff Burke169445b2012-12-08 12:15:54 -080062The only way (for now) to get connectivity to other NDN nodes is via ccnd. For the
63Javascript API, a Websockets proxy that can communicate the target ccnd is currently
64required. Code for such a proxy (using Node.js) is in the wsproxy directory. It
65currently listens on port 9696 and passes messages (using either TCP or UDP) to ccnd on
66the same host.
Jeff Burke858c07a2012-12-08 11:35:25 -080067
Jeff Burke33546102012-12-08 11:55:36 -080068** Including the scripts in a web page **
69To use NDN.JS in a web page, one of two scripts must be included using a <script> tag:
70
Jeff Burke169445b2012-12-08 12:15:54 -0800711. ndn-js.js, a combined, compressed library designed for efficient distribution. It can
72be built using js/tools/build/make-js.sh This is used in examples/ndn-ping.html
Jeff Burke33546102012-12-08 11:55:36 -080073
Jeff Burke169445b2012-12-08 12:15:54 -0800742. Helper.js, which loads each component script independently. This is used in most of
75the tests in testing/
Jeff Burke33546102012-12-08 11:55:36 -080076
Jeff Burke018707d2012-12-08 12:23:39 -080077** Example to retrieve content **
Jeff Burke004039b2012-12-08 11:31:37 -080078A simple example of the current API to express an Interest and receive data:
79
Jeff Burke858c07a2012-12-08 11:35:25 -080080var ndn = new NDN(); // connect to a default hub/proxy
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080081ndn.transport.connectWebSocket(ndn);
82
83var AsyncGetClosure = function AsyncGetClosure() {
84 // Inherit from Closure.
85 Closure.call(this);
86};
87AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) {
88 if (kind == Closure.UPCALL_CONTENT) {
89 console.log("Received " + upcallInfo.contentObject.name.to_uri());
90 console.log(upcallInfo.contentObject.content);
91 }
92 return Closure.RESULT_OK;
93};
Jeff Thompson9e6dff02012-11-04 09:20:47 -080094
Jeff Burke169445b2012-12-08 12:15:54 -080095ndn.expressInterest(new Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt"), new
96AsyncGetClosure());
Jeff Thompson9e6dff02012-11-04 09:20:47 -080097
Jeff Burke018707d2012-12-08 12:23:39 -080098** Example to publish content **
99
100// Note that publishing content requires knowledge of a
101// routable prefix for your upstream ccnd. We are working
102// on a way to either obtain that prefix or use the /local
103// convention.
104
105For now, see testing/test-publish-async.html
106
107
108
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800109
Jeff Burke004039b2012-12-08 11:31:37 -0800110FIREFOX ADD-ON FOR THE NDN PROTOCOL
111-----------------------------------
112
113See files in js/ndnProtocol
114
Jeff Burke169445b2012-12-08 12:15:54 -0800115NDN.JS includes a Firefox extension for the ndn protocol built using the Javascript
116library. It currently obtains NDN connectivity through the NDN testbed. (This is
117hard-coded.)
Jeff Burke004039b2012-12-08 11:31:37 -0800118
119To install, either download
Jeff Thompsonbd829262012-11-30 22:28:37 -0800120https://github.com/remap/ndn-js/blob/master/js/ndnProtocol.xpi
121or use js/ndnProtocol.xpi in the distribution. In Firefox, open
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800122Tools > Add-ons. In the "gear" or "wrench" menu, click Install Add-on From File and open
Jeff Thompsonbd829262012-11-30 22:28:37 -0800123ndnProtocol.xpi. Restart Firefox.
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800124
Jeff Thompsonbd829262012-11-30 22:28:37 -0800125Firefox uses the protocol extension to load any URI starting with ndn, for example
126ndn:/ndn/ucla.edu/apps/lwndn-test/trig-table
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800127
Jeff Burke169445b2012-12-08 12:15:54 -0800128When the page is loaded, Firefox updates the address bar with the full matched name from
129the retrieved content object including the version, but without the implicit digest or
130segment number (see below).
Jeff Burke33546102012-12-08 11:55:36 -0800131
132
133
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800134
Jeff Burke004039b2012-12-08 11:31:37 -0800135* Interest selectors in the ndn protocol:
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800136
Jeff Burke169445b2012-12-08 12:15:54 -0800137You can add interest selectors. For example, this uses 1 to select the "rightmost" child
138(latest version).
Jeff Thompsonbd829262012-11-30 22:28:37 -0800139ndn:/ndn/ucla.edu/apps/ndn-js-test/hello.txt?ndn.ChildSelector=1&key=value#ref
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800140
141The browser loads the latest version and changes the address to:
Jeff Thompsonbd829262012-11-30 22:28:37 -0800142ndn:/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 -0800143
Jeff Thompsonbd829262012-11-30 22:28:37 -0800144The child selector was used and removed. Note that the other non-ndn query values and
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800145ref "?key=value#ref" are still present, in case they are needed by the web application.
146
147The following selector keys are supported:
Jeff Thompsonbd829262012-11-30 22:28:37 -0800148ndn.MinSuffixComponent= non-negative int
149ndn.MaxSuffixComponents= non-negative int
150ndn.ChildSelector= non-negative int
151ndn.AnswerOriginKind= non-negative int
152ndn.Scope= non-negative int
Jeff Thompson42806a12012-12-29 18:19:39 -0800153ndn.InterestLifetime= non-negative int (milliseconds)
Jeff Thompsonbd829262012-11-30 22:28:37 -0800154ndn.PublisherPublicKeyDigest= % escaped value
155ndn.Nonce= % escaped value
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800156
Jeff Thompsonbd829262012-11-30 22:28:37 -0800157TODO: implement ndn.Exclude.
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800158
Jeff Thompsonbd829262012-11-30 22:28:37 -0800159* Multiple segments in the ndn protocol
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800160
Jeff Burke169445b2012-12-08 12:15:54 -0800161A URI for content with multiple segments is handled as follows. If the URI has a segment
162number, just retrieve that segment and return the content to the browser.
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800163
Jeff Burke169445b2012-12-08 12:15:54 -0800164Otherwise look at the name in the returned ContentObject. If the returned name has no
165segment number, just return the content to the browser. If the name has a segment number
166which isn't 0, store it and express an interest for segment 0. Read segments in order and
167return each content to the browser as we go until we get the segment for FinalBlockID.
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800168