Jeff Thompson | e2c4820 | 2012-12-01 09:05:58 -0800 | [diff] [blame] | 1 | NDN.JS is the first native version of the NDN protocol (also referred to as CCN) written in JavaScript. |
Meki Cherkaoui | f2e96ed | 2012-04-22 16:21:27 -0700 | [diff] [blame] | 2 | |
Jeff Thompson | e2c4820 | 2012-12-01 09:05:58 -0800 | [diff] [blame] | 3 | The 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 Cherkaoui | f2e96ed | 2012-04-22 16:21:27 -0700 | [diff] [blame] | 4 | |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 5 | The 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 Cherkaoui | f2e96ed | 2012-04-22 16:21:27 -0700 | [diff] [blame] | 6 | |
| 7 | This is currently done in the following way: |
| 8 | |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 9 | var ndn = new NDN(); |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 10 | ndn.transport.connectWebSocket(ndn); |
| 11 | |
| 12 | var AsyncGetClosure = function AsyncGetClosure() { |
| 13 | // Inherit from Closure. |
| 14 | Closure.call(this); |
| 15 | }; |
| 16 | AsyncGetClosure.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 Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 23 | |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 24 | ndn.expressInterest(new Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt"), new AsyncGetClosure()); |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 25 | |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 26 | *** Firefox extension for the ndn protocol |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 27 | |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 28 | NDN.JS also includes a Firefox extension for the ndn protocol. To install, either download |
| 29 | https://github.com/remap/ndn-js/blob/master/js/ndnProtocol.xpi |
| 30 | or use js/ndnProtocol.xpi in the distribution. In Firefox, open |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 31 | Tools > Add-ons. In the "gear" or "wrench" menu, click Install Add-on From File and open |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 32 | ndnProtocol.xpi. Restart Firefox. |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 33 | |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 34 | Firefox uses the protocol extension to load any URI starting with ndn, for example |
| 35 | ndn:/ndn/ucla.edu/apps/lwndn-test/trig-table |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 36 | |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 37 | When the page is loaded, Firefox updates the address bar with the full matched name from the |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 38 | retrieved content object including the version, but without the implicit digest or segment number |
| 39 | (see below). |
| 40 | |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 41 | * Interest selectors in the ndn protocol |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 42 | |
| 43 | You can add interest selectors. For example, this uses 1 to select the "rightmost" child (latest version). |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 44 | ndn:/ndn/ucla.edu/apps/ndn-js-test/hello.txt?ndn.ChildSelector=1&key=value#ref |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 45 | |
| 46 | The browser loads the latest version and changes the address to: |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 47 | ndn:/ndn/ucla.edu/apps/ndn-js-test/hello.txt/%FD%05%0B%16z%22%D1?key=value#ref |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 48 | |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 49 | The child selector was used and removed. Note that the other non-ndn query values and |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 50 | ref "?key=value#ref" are still present, in case they are needed by the web application. |
| 51 | |
| 52 | The following selector keys are supported: |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 53 | ndn.MinSuffixComponent= non-negative int |
| 54 | ndn.MaxSuffixComponents= non-negative int |
| 55 | ndn.ChildSelector= non-negative int |
| 56 | ndn.AnswerOriginKind= non-negative int |
| 57 | ndn.Scope= non-negative int |
| 58 | ndn.InterestLifetime= non-negative int |
| 59 | ndn.PublisherPublicKeyDigest= % escaped value |
| 60 | ndn.Nonce= % escaped value |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 61 | |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 62 | TODO: implement ndn.Exclude. |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 63 | |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 64 | * Multiple segments in the ndn protocol |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 65 | |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 66 | A URI for content with multiple segments is handled as follows. |
| 67 | If the URI has a segment number, just retrieve that segment and return the content to the browser. |
| 68 | |
| 69 | Otherwise look at the name in the returned ContentObject. If the returned name has no segment number, |
| 70 | just return the content to the browser. If the name has a segment number which isn't 0, store it |
| 71 | and express an interest for segment 0. Read segments in order and return each content to the browser |
| 72 | as we go until we get the segment for FinalBlockID. |
| 73 | |