blob: 1adb58e6cc7a23aca5a5877a92d48be149eb3940 [file] [log] [blame]
Jeff Thompsone2c48202012-12-01 09:05:58 -08001NDN.JS is the first native version of the NDN protocol (also referred to as CCN) written in JavaScript.
Meki Cherkaouif2e96ed2012-04-22 16:21:27 -07002
Jeff Thompsone2c48202012-12-01 09:05:58 -08003The goal of this project is to improve the current implementation of the NDN API that allows users to create applications running on top of the NDN network. The goal is to have a lightweight version of the protocol, which can run on browsers. The main intent is to enable browser-based applications to use NDN directly without requiring a binary build of the CCNx code. In particular, the goal is to have an AJAX-style dynamic data access. The goal is also to have a lighter version of the protocol, which would be better suited for embedded systems. Furthermore, the goal is that NDN.JS communicates with CCNx nodes (routers).
Meki Cherkaouif2e96ed2012-04-22 16:21:27 -07004
Jeff Thompsonbd829262012-11-30 22:28:37 -08005The current status of NDN.JS allows for JavaScript applications running on browsers to send interest packets and retrieve data packets. This includes encoding and decoding data packets.
Meki Cherkaouif2e96ed2012-04-22 16:21:27 -07006
7This is currently done in the following way:
8
Jeff Thompson9e6dff02012-11-04 09:20:47 -08009var ndn = new NDN();
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080010ndn.transport.connectWebSocket(ndn);
11
12var AsyncGetClosure = function AsyncGetClosure() {
13 // Inherit from Closure.
14 Closure.call(this);
15};
16AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) {
17 if (kind == Closure.UPCALL_CONTENT) {
18 console.log("Received " + upcallInfo.contentObject.name.to_uri());
19 console.log(upcallInfo.contentObject.content);
20 }
21 return Closure.RESULT_OK;
22};
Jeff Thompson9e6dff02012-11-04 09:20:47 -080023
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080024ndn.expressInterest(new Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt"), new AsyncGetClosure());
Jeff Thompson9e6dff02012-11-04 09:20:47 -080025
Jeff Thompsonbd829262012-11-30 22:28:37 -080026*** Firefox extension for the ndn protocol
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080027
Jeff Thompsonbd829262012-11-30 22:28:37 -080028NDN.JS also includes a Firefox extension for the ndn protocol. To install, either download
29https://github.com/remap/ndn-js/blob/master/js/ndnProtocol.xpi
30or use js/ndnProtocol.xpi in the distribution. In Firefox, open
Jeff Thompson9e6dff02012-11-04 09:20:47 -080031Tools > Add-ons. In the "gear" or "wrench" menu, click Install Add-on From File and open
Jeff Thompsonbd829262012-11-30 22:28:37 -080032ndnProtocol.xpi. Restart Firefox.
Jeff Thompson9e6dff02012-11-04 09:20:47 -080033
Jeff Thompsonbd829262012-11-30 22:28:37 -080034Firefox uses the protocol extension to load any URI starting with ndn, for example
35ndn:/ndn/ucla.edu/apps/lwndn-test/trig-table
Jeff Thompson9e6dff02012-11-04 09:20:47 -080036
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080037When the page is loaded, Firefox updates the address bar with the full matched name from the
Jeff Thompson9e6dff02012-11-04 09:20:47 -080038retrieved content object including the version, but without the implicit digest or segment number
39(see below).
40
Jeff Thompsonbd829262012-11-30 22:28:37 -080041* Interest selectors in the ndn protocol
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080042
43You can add interest selectors. For example, this uses 1 to select the "rightmost" child (latest version).
Jeff Thompsonbd829262012-11-30 22:28:37 -080044ndn:/ndn/ucla.edu/apps/ndn-js-test/hello.txt?ndn.ChildSelector=1&key=value#ref
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080045
46The browser loads the latest version and changes the address to:
Jeff Thompsonbd829262012-11-30 22:28:37 -080047ndn:/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 -080048
Jeff Thompsonbd829262012-11-30 22:28:37 -080049The child selector was used and removed. Note that the other non-ndn query values and
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080050ref "?key=value#ref" are still present, in case they are needed by the web application.
51
52The following selector keys are supported:
Jeff Thompsonbd829262012-11-30 22:28:37 -080053ndn.MinSuffixComponent= non-negative int
54ndn.MaxSuffixComponents= non-negative int
55ndn.ChildSelector= non-negative int
56ndn.AnswerOriginKind= non-negative int
57ndn.Scope= non-negative int
58ndn.InterestLifetime= non-negative int
59ndn.PublisherPublicKeyDigest= % escaped value
60ndn.Nonce= % escaped value
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080061
Jeff Thompsonbd829262012-11-30 22:28:37 -080062TODO: implement ndn.Exclude.
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080063
Jeff Thompsonbd829262012-11-30 22:28:37 -080064* Multiple segments in the ndn protocol
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080065
Jeff Thompson9e6dff02012-11-04 09:20:47 -080066A URI for content with multiple segments is handled as follows.
67If the URI has a segment number, just retrieve that segment and return the content to the browser.
68
69Otherwise look at the name in the returned ContentObject. If the returned name has no segment number,
70just return the content to the browser. If the name has a segment number which isn't 0, store it
71and express an interest for segment 0. Read segments in order and return each content to the browser
72as we go until we get the segment for FinalBlockID.
73