Meki Cherkaoui | f2e96ed | 2012-04-22 16:21:27 -0700 | [diff] [blame] | 1 | |
Jeff Thompson | 0bfa3f9 | 2013-07-19 18:12:12 -0700 | [diff] [blame] | 2 | NDN-JS: A javascript client library for Named Data Networking |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 3 | -------------------------------------------------------------- |
Meki Cherkaoui | f2e96ed | 2012-04-22 16:21:27 -0700 | [diff] [blame] | 4 | |
Jeff Thompson | 0bfa3f9 | 2013-07-19 18:12:12 -0700 | [diff] [blame] | 5 | NDN-JS is the first native version of the NDN protocol written in JavaScript. It is wire |
Jeff Burke | 169445b | 2012-12-08 12:15:54 -0800 | [diff] [blame] | 6 | format compatible with PARC's CCNx. |
Meki Cherkaoui | f2e96ed | 2012-04-22 16:21:27 -0700 | [diff] [blame] | 7 | |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 8 | The project by the UCLA NDN team - for more information on NDN, see |
| 9 | http://named-data.net/ |
| 10 | http://ndn.ucla.edu/ |
| 11 | |
Jeff Thompson | 0bfa3f9 | 2013-07-19 18:12:12 -0700 | [diff] [blame] | 12 | NDN-JS is open source under a license described in the file COPYING. While the license |
Jeff Burke | 169445b | 2012-12-08 12:15:54 -0800 | [diff] [blame] | 13 | does not require it, we really would appreciate it if others would share their |
| 14 | 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] | 15 | |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 16 | --- |
| 17 | |
Jeff Burke | 169445b | 2012-12-08 12:15:54 -0800 | [diff] [blame] | 18 | This is a young project, with minimal documentation that we are slowly enhancing. Please |
Jeff Thompson | adba5a9 | 2013-07-19 18:14:59 -0700 | [diff] [blame^] | 19 | submit any bugs or issues to the NDN-JS issue tracker: |
| 20 | http://redmine.named-data.net/projects/ndn-js/issues |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 21 | |
Jeff Thompson | 0bfa3f9 | 2013-07-19 18:12:12 -0700 | [diff] [blame] | 22 | The primary goal of NDN-JS is to provide a pure Javascript implementation of the NDN API |
Jeff Burke | 169445b | 2012-12-08 12:15:54 -0800 | [diff] [blame] | 23 | that enables developers to create browser-based applications using Named Data Networking. |
| 24 | The approach requires no native code or signed Java applets, and thus can be delivered |
| 25 | over the current web to modern browsers with no hassle for the end user. |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 26 | |
| 27 | Additional goals for the project: |
Jeff Burke | 169445b | 2012-12-08 12:15:54 -0800 | [diff] [blame] | 28 | - Websockets transport (rather than TCP or UDP, which are not directly supported in |
| 29 | Javascript). |
Jeff Burke | 858c07a | 2012-12-08 11:35:25 -0800 | [diff] [blame] | 30 | - Relatively lightweight and compact, to enable efficient use on the web. |
| 31 | - Wire format compatible with PARC's CCNx implementation of NDN. |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 32 | |
Jeff Burke | 169445b | 2012-12-08 12:15:54 -0800 | [diff] [blame] | 33 | The library currently requires a remote NDN daemon, and has been tested with ccnd, from |
| 34 | the's CCNx package: http://ccnx.org/ |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 35 | |
| 36 | Currently, the library has two APIs for developers: |
| 37 | |
| 38 | 1. The Javascript API for asynchronous Interest/Data exchange. |
| 39 | This uses WebSockets for transport and currently requires a |
| 40 | proxy for communication with a remote ccnd daemon. |
| 41 | |
| 42 | 2. A Firefox plug-in, which implements an "ndn:/" url scheme |
| 43 | following CCNx repository conventions for file retrieval. |
| 44 | |
Jeff Burke | 169445b | 2012-12-08 12:15:54 -0800 | [diff] [blame] | 45 | By default, both parts of the library connect automatically to a set of proxies and hubs |
| 46 | that are part of the NDN research project's testbed. http://named-data.net/testbed.html |
| 47 | There are currently no restrictions on non-commercial, research-oriented data exchange on |
| 48 | this testbed. (Contact jburke@remap.ucla.edu for more details.) The developer can also |
| 49 | specify a local or remote ccnd as well, as an argument to the NDN constructor. |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 50 | |
| 51 | |
| 52 | |
| 53 | JAVASCRIPT API |
| 54 | -------------- |
| 55 | |
Alexander Afanasyev | 426174a | 2013-03-13 16:45:47 -0700 | [diff] [blame] | 56 | See files in js/ and examples in tests/, examples/ |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 57 | |
Jeff Thompson | 0bfa3f9 | 2013-07-19 18:12:12 -0700 | [diff] [blame] | 58 | NDN-JS currently supports expressing Interests (and receiving data) and publishing Data |
Jeff Burke | 169445b | 2012-12-08 12:15:54 -0800 | [diff] [blame] | 59 | (that answers Interests). This includes encoding and decoding data packets as well as |
| 60 | signing and verifying them using RSA keys. |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 61 | |
Jeff Burke | 3354610 | 2012-12-08 11:55:36 -0800 | [diff] [blame] | 62 | ** NDN connectivity ** |
Jeff Burke | 169445b | 2012-12-08 12:15:54 -0800 | [diff] [blame] | 63 | The only way (for now) to get connectivity to other NDN nodes is via ccnd. For the |
| 64 | Javascript API, a Websockets proxy that can communicate the target ccnd is currently |
| 65 | required. Code for such a proxy (using Node.js) is in the wsproxy directory. It |
| 66 | currently listens on port 9696 and passes messages (using either TCP or UDP) to ccnd on |
| 67 | the same host. |
Jeff Burke | 858c07a | 2012-12-08 11:35:25 -0800 | [diff] [blame] | 68 | |
Jeff Burke | 3354610 | 2012-12-08 11:55:36 -0800 | [diff] [blame] | 69 | ** Including the scripts in a web page ** |
Jeff Thompson | 0bfa3f9 | 2013-07-19 18:12:12 -0700 | [diff] [blame] | 70 | To use NDN-JS in a web page, one of two scripts must be included using a script tag: |
Jeff Burke | 3354610 | 2012-12-08 11:55:36 -0800 | [diff] [blame] | 71 | |
Alexander Afanasyev | 88a314f | 2013-03-14 12:52:17 -0700 | [diff] [blame] | 72 | ndn-js.js is a combined library (and ndn-js.min.js is a compressed version of the combined library), |
| 73 | designed for efficient distribution. Bother can be either build in ./build/ndn-js.min.js using |
| 74 | the following commands: |
Jeff Burke | 3354610 | 2012-12-08 11:55:36 -0800 | [diff] [blame] | 75 | |
Alexander Afanasyev | 88a314f | 2013-03-14 12:52:17 -0700 | [diff] [blame] | 76 | ./waf configure |
| 77 | ./waf |
Jeff Burke | 3354610 | 2012-12-08 11:55:36 -0800 | [diff] [blame] | 78 | |
Alexander Afanasyev | 88a314f | 2013-03-14 12:52:17 -0700 | [diff] [blame] | 79 | Or downloaded from the `downloads` branch (https://github.com/named-data/ndn-js/tree/downloads): |
| 80 | |
| 81 | - http://raw.github.com/named-data/ndn-js/downloads/ndn-js.js |
| 82 | - http://raw.github.com/named-data/ndn-js/downloads/ndn-js.min.js |
| 83 | |
| 84 | ** Examples ** |
| 85 | |
| 86 | *** ndn-ping |
| 87 | |
| 88 | You can check out `examples/ndn-ping.html` to see an example how to implement ndn-ping in NDN.js |
| 89 | |
| 90 | *** Example to retrieve content *** |
| 91 | |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 92 | A simple example of the current API to express an Interest and receive data: |
| 93 | |
Jeff Burke | 858c07a | 2012-12-08 11:35:25 -0800 | [diff] [blame] | 94 | var ndn = new NDN(); // connect to a default hub/proxy |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 95 | |
| 96 | var AsyncGetClosure = function AsyncGetClosure() { |
| 97 | // Inherit from Closure. |
| 98 | Closure.call(this); |
| 99 | }; |
| 100 | AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) { |
| 101 | if (kind == Closure.UPCALL_CONTENT) { |
| 102 | console.log("Received " + upcallInfo.contentObject.name.to_uri()); |
| 103 | console.log(upcallInfo.contentObject.content); |
| 104 | } |
| 105 | return Closure.RESULT_OK; |
| 106 | }; |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 107 | |
Jeff Burke | 169445b | 2012-12-08 12:15:54 -0800 | [diff] [blame] | 108 | ndn.expressInterest(new Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt"), new |
| 109 | AsyncGetClosure()); |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 110 | |
Jeff Burke | 018707d | 2012-12-08 12:23:39 -0800 | [diff] [blame] | 111 | ** Example to publish content ** |
| 112 | |
| 113 | // Note that publishing content requires knowledge of a |
| 114 | // routable prefix for your upstream ccnd. We are working |
| 115 | // on a way to either obtain that prefix or use the /local |
| 116 | // convention. |
| 117 | |
Alexander Afanasyev | 426174a | 2013-03-13 16:45:47 -0700 | [diff] [blame] | 118 | For now, see tests/test-publish-async.html |
Jeff Burke | 018707d | 2012-12-08 12:23:39 -0800 | [diff] [blame] | 119 | |
| 120 | |
| 121 | |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 122 | FIREFOX ADD-ON FOR THE NDN PROTOCOL |
| 123 | ----------------------------------- |
| 124 | |
Alexander Afanasyev | 426174a | 2013-03-13 16:45:47 -0700 | [diff] [blame] | 125 | See files in ndnProtocol/ |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 126 | |
Jeff Thompson | 0bfa3f9 | 2013-07-19 18:12:12 -0700 | [diff] [blame] | 127 | NDN-JS includes a Firefox extension for the ndn protocol built using the Javascript |
Jeff Thompson | edaccfb | 2013-03-17 20:49:35 -0700 | [diff] [blame] | 128 | library. It currently obtains NDN connectivity through the NDN testbed, but you can |
| 129 | click Set on the NDN Toolbar to change the connected hub. |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 130 | |
| 131 | To install, either download |
Alexander Afanasyev | 426174a | 2013-03-13 16:45:47 -0700 | [diff] [blame] | 132 | https://github.com/named-data/ndn-js/raw/downloads/ndnProtocol.xpi |
| 133 | |
| 134 | or use ndnProtocol.xpi from `downloads` branch. In Firefox, open |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 135 | Tools > Add-ons. In the "gear" or "wrench" menu, click Install Add-on From File and open |
Jeff Thompson | edaccfb | 2013-03-17 20:49:35 -0700 | [diff] [blame] | 136 | ndnProtocol.xpi. (In Firefox for Android, type file: in the address bar and click the |
| 137 | downloaded ndnProtocol.xpi.) Restart Firefox. |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 138 | |
Jeff Thompson | 8c563fe | 2013-06-04 14:35:58 -0700 | [diff] [blame] | 139 | Firefox uses the protocol extension to load any URI starting with ndn. See this test page for examples: |
Jeff Thompson | 71b6de4 | 2013-06-04 14:40:32 -0700 | [diff] [blame] | 140 | ndn:/ndn/ucla.edu/apps/ndn-js-test/NDNProtocolExamples.html?ndn.ChildSelector=1 |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 141 | |
Jeff Burke | 169445b | 2012-12-08 12:15:54 -0800 | [diff] [blame] | 142 | When the page is loaded, Firefox updates the address bar with the full matched name from |
| 143 | the retrieved content object including the version, but without the implicit digest or |
| 144 | segment number (see below). |
Jeff Burke | 3354610 | 2012-12-08 11:55:36 -0800 | [diff] [blame] | 145 | |
Jeff Burke | 004039b | 2012-12-08 11:31:37 -0800 | [diff] [blame] | 146 | * Interest selectors in the ndn protocol: |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 147 | |
Jeff Burke | 169445b | 2012-12-08 12:15:54 -0800 | [diff] [blame] | 148 | You can add interest selectors. For example, this uses 1 to select the "rightmost" child |
Jeff Thompson | 8c563fe | 2013-06-04 14:35:58 -0700 | [diff] [blame] | 149 | (latest version): |
Jeff Thompson | 71b6de4 | 2013-06-04 14:40:32 -0700 | [diff] [blame] | 150 | 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] | 151 | |
Jeff Thompson | 8c563fe | 2013-06-04 14:35:58 -0700 | [diff] [blame] | 152 | The browser loads the latest version and changes the address to: |
Jeff Thompson | 71b6de4 | 2013-06-04 14:40:32 -0700 | [diff] [blame] | 153 | 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] | 154 | |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 155 | 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] | 156 | ref "?key=value#ref" are still present, in case they are needed by the web application. |
| 157 | |
| 158 | The following selector keys are supported: |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 159 | ndn.MinSuffixComponent= non-negative int |
| 160 | ndn.MaxSuffixComponents= non-negative int |
| 161 | ndn.ChildSelector= non-negative int |
| 162 | ndn.AnswerOriginKind= non-negative int |
| 163 | ndn.Scope= non-negative int |
Jeff Thompson | 42806a1 | 2012-12-29 18:19:39 -0800 | [diff] [blame] | 164 | ndn.InterestLifetime= non-negative int (milliseconds) |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 165 | ndn.PublisherPublicKeyDigest= % escaped value |
| 166 | ndn.Nonce= % escaped value |
Jeff Thompson | 6ac75d2 | 2013-02-04 22:41:34 -0800 | [diff] [blame] | 167 | ndn.Exclude= comma-separated list of % escaped values or * for ANY |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 168 | |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 169 | * Multiple segments in the ndn protocol |
Jeff Thompson | b68ceab | 2012-11-25 18:25:56 -0800 | [diff] [blame] | 170 | |
Jeff Burke | 169445b | 2012-12-08 12:15:54 -0800 | [diff] [blame] | 171 | A URI for content with multiple segments is handled as follows. If the URI has a segment |
| 172 | number, just retrieve that segment and return the content to the browser. |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 173 | |
Jeff Burke | 169445b | 2012-12-08 12:15:54 -0800 | [diff] [blame] | 174 | Otherwise look at the name in the returned ContentObject. If the returned name has no |
| 175 | segment number, just return the content to the browser. If the name has a segment number |
Jeff Thompson | 42682dc | 2013-02-07 07:53:30 -0800 | [diff] [blame] | 176 | which isn't 0, store it and express an interest for segment 0. Also express an interest for |
| 177 | the highest segment to try to determine the FinalBlockID early. Fetch multiple segments in order and |
| 178 | return each content to the browser (in order) as the arrive until we get the segment for FinalBlockID. |
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 179 | |