Meki Cherkaoui | f2e96ed | 2012-04-22 16:21:27 -0700 | [diff] [blame] | 1 | |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 2 | NDN.JS: A javascript client library for Named Data Networking |
| 3 | -------------------------------------------------------------- |
Meki Cherkaoui | f2e96ed | 2012-04-22 16:21:27 -0700 | [diff] [blame] | 4 | |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 5 | NDN.JS is the first native version of the NDN protocol written in JavaScript. It is wire format compatible with PARC's CCNx. |
Meki Cherkaoui | f2e96ed | 2012-04-22 16:21:27 -0700 | [diff] [blame] | 6 | |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 7 | The project by the UCLA NDN team - for more information on NDN, see |
| 8 | http://named-data.net/ |
| 9 | http://ndn.ucla.edu/ |
| 10 | |
| 11 | NDN.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 Cherkaoui | f2e96ed | 2012-04-22 16:21:27 -0700 | [diff] [blame] | 12 | |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 13 | --- |
| 14 | |
| 15 | This is a young project, with minimal documentation that we are slowly enhancing. Please email Jeff Burke (jburke@remap.ucla.edu) with any questions. |
| 16 | |
| 17 | The 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 | |
| 19 | Additional goals for the project: |
Jeff Burke | 858c07a | 2012-12-08 11:35:25 -0800 | [diff] [blame] | 20 | - 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 Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 23 | |
| 24 | The library currently requires a remote NDN daemon, and has been tested with ccnd, from the's CCNx package: http://ccnx.org/ |
| 25 | |
| 26 | Currently, 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 | |
| 35 | By 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 | |
| 39 | JAVASCRIPT API |
| 40 | -------------- |
| 41 | |
| 42 | See files in js/ and examples in js/testing/ |
| 43 | |
| 44 | NDN.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 Burke | 858c07a | 2012-12-08 11:35:25 -0800 | [diff] [blame] | 46 | To 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 Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 48 | A simple example of the current API to express an Interest and receive data: |
| 49 | |
Jeff Burke | 858c07a | 2012-12-08 11:35:25 -0800 | [diff] [blame] | 50 | var ndn = new NDN(); // connect to a default hub/proxy |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 51 | ndn.transport.connectWebSocket(ndn); |
| 52 | |
| 53 | var AsyncGetClosure = function AsyncGetClosure() { |
| 54 | // Inherit from Closure. |
| 55 | Closure.call(this); |
| 56 | }; |
| 57 | AsyncGetClosure.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 Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 64 | |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 65 | 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] | 66 | |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 67 | |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 68 | FIREFOX ADD-ON FOR THE NDN PROTOCOL |
| 69 | ----------------------------------- |
| 70 | |
| 71 | See files in js/ndnProtocol |
| 72 | |
| 73 | NDN.JS includes a Firefox extension for the ndn protocol. |
| 74 | |
| 75 | To install, either download |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 76 | https://github.com/remap/ndn-js/blob/master/js/ndnProtocol.xpi |
| 77 | or use js/ndnProtocol.xpi in the distribution. In Firefox, open |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 78 | 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] | 79 | ndnProtocol.xpi. Restart Firefox. |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 80 | |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 81 | Firefox uses the protocol extension to load any URI starting with ndn, for example |
| 82 | ndn:/ndn/ucla.edu/apps/lwndn-test/trig-table |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 83 | |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 84 | 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] | 85 | retrieved content object including the version, but without the implicit digest or segment number |
| 86 | (see below). |
| 87 | |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 88 | * Interest selectors in the ndn protocol: |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 89 | |
| 90 | 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] | 91 | 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] | 92 | |
| 93 | The browser loads the latest version and changes the address to: |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 94 | 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] | 95 | |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 96 | 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] | 97 | ref "?key=value#ref" are still present, in case they are needed by the web application. |
| 98 | |
| 99 | The following selector keys are supported: |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 100 | ndn.MinSuffixComponent= non-negative int |
| 101 | ndn.MaxSuffixComponents= non-negative int |
| 102 | ndn.ChildSelector= non-negative int |
| 103 | ndn.AnswerOriginKind= non-negative int |
| 104 | ndn.Scope= non-negative int |
| 105 | ndn.InterestLifetime= non-negative int |
| 106 | ndn.PublisherPublicKeyDigest= % escaped value |
| 107 | ndn.Nonce= % escaped value |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 108 | |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 109 | TODO: implement ndn.Exclude. |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 110 | |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 111 | * Multiple segments in the ndn protocol |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 112 | |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 113 | A URI for content with multiple segments is handled as follows. |
| 114 | If the URI has a segment number, just retrieve that segment and return the content to the browser. |
| 115 | |
| 116 | Otherwise look at the name in the returned ContentObject. If the returned name has no segment number, |
| 117 | just return the content to the browser. If the name has a segment number which isn't 0, store it |
| 118 | and express an interest for segment 0. Read segments in order and return each content to the browser |
| 119 | as we go until we get the segment for FinalBlockID. |
| 120 | |