blob: e10248cd8f4b60492d3def91e5059bfdb6b77ab6 [file] [log] [blame] [view]
Meki Cherkaouif2e96ed2012-04-22 16:21:27 -07001
Jeff Thompson0bfa3f92013-07-19 18:12:12 -07002NDN-JS: A javascript client library for Named Data Networking
Jeff Burke004039b2012-12-08 11:31:37 -08003--------------------------------------------------------------
Meki Cherkaouif2e96ed2012-04-22 16:21:27 -07004
Jeff Thompson0bfa3f92013-07-19 18:12:12 -07005NDN-JS is the first native version of the NDN protocol written in JavaScript. It is wire
Jeff Burke169445b2012-12-08 12:15:54 -08006format 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 Thompson0bfa3f92013-07-19 18:12:12 -070012NDN-JS is open source under a license described in the file COPYING. While the license
Jeff Burke169445b2012-12-08 12:15:54 -080013does 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 Thompsona6599bf2013-08-06 17:05:41 -070016See the file INSTALL for build and install instructions.
17
Jeff Burke004039b2012-12-08 11:31:37 -080018---
19
Jeff Burke169445b2012-12-08 12:15:54 -080020This is a young project, with minimal documentation that we are slowly enhancing. Please
Jeff Thompsonadba5a92013-07-19 18:14:59 -070021submit any bugs or issues to the NDN-JS issue tracker:
22http://redmine.named-data.net/projects/ndn-js/issues
Jeff Burke004039b2012-12-08 11:31:37 -080023
Jeff Thompson0bfa3f92013-07-19 18:12:12 -070024The primary goal of NDN-JS is to provide a pure Javascript implementation of the NDN API
Jeff Burke169445b2012-12-08 12:15:54 -080025that enables developers to create browser-based applications using Named Data Networking.
26The approach requires no native code or signed Java applets, and thus can be delivered
27over the current web to modern browsers with no hassle for the end user.
Jeff Burke004039b2012-12-08 11:31:37 -080028
29Additional goals for the project:
Jeff Burke169445b2012-12-08 12:15:54 -080030- Websockets transport (rather than TCP or UDP, which are not directly supported in
31Javascript).
Jeff Burke858c07a2012-12-08 11:35:25 -080032- Relatively lightweight and compact, to enable efficient use on the web.
33- Wire format compatible with PARC's CCNx implementation of NDN.
Jeff Burke004039b2012-12-08 11:31:37 -080034
Jeff Burke169445b2012-12-08 12:15:54 -080035The library currently requires a remote NDN daemon, and has been tested with ccnd, from
36the's CCNx package: http://ccnx.org/
Jeff Burke004039b2012-12-08 11:31:37 -080037
38Currently, the library has two APIs for developers:
39
40 1. The Javascript API for asynchronous Interest/Data exchange.
41 This uses WebSockets for transport and currently requires a
42 proxy for communication with a remote ccnd daemon.
43
44 2. A Firefox plug-in, which implements an "ndn:/" url scheme
45 following CCNx repository conventions for file retrieval.
46
Jeff Burke169445b2012-12-08 12:15:54 -080047By default, both parts of the library connect automatically to a set of proxies and hubs
48that are part of the NDN research project's testbed. http://named-data.net/testbed.html
49There are currently no restrictions on non-commercial, research-oriented data exchange on
50this testbed. (Contact jburke@remap.ucla.edu for more details.) The developer can also
51specify a local or remote ccnd as well, as an argument to the NDN constructor.
Jeff Burke004039b2012-12-08 11:31:37 -080052
53
54
55JAVASCRIPT API
56--------------
57
Alexander Afanasyev426174a2013-03-13 16:45:47 -070058See files in js/ and examples in tests/, examples/
Jeff Burke004039b2012-12-08 11:31:37 -080059
Jeff Thompson0bfa3f92013-07-19 18:12:12 -070060NDN-JS currently supports expressing Interests (and receiving data) and publishing Data
Jeff Burke169445b2012-12-08 12:15:54 -080061(that answers Interests). This includes encoding and decoding data packets as well as
62signing and verifying them using RSA keys.
Jeff Burke004039b2012-12-08 11:31:37 -080063
Jeff Burke33546102012-12-08 11:55:36 -080064** NDN connectivity **
Jeff Burke169445b2012-12-08 12:15:54 -080065The only way (for now) to get connectivity to other NDN nodes is via ccnd. For the
66Javascript API, a Websockets proxy that can communicate the target ccnd is currently
67required. Code for such a proxy (using Node.js) is in the wsproxy directory. It
68currently listens on port 9696 and passes messages (using either TCP or UDP) to ccnd on
69the same host.
Jeff Burke858c07a2012-12-08 11:35:25 -080070
Jeff Burke33546102012-12-08 11:55:36 -080071** Including the scripts in a web page **
Jeff Thompson0bfa3f92013-07-19 18:12:12 -070072To use NDN-JS in a web page, one of two scripts must be included using a script tag:
Jeff Burke33546102012-12-08 11:55:36 -080073
Alexander Afanasyev88a314f2013-03-14 12:52:17 -070074ndn-js.js is a combined library (and ndn-js.min.js is a compressed version of the combined library),
75designed for efficient distribution. Bother can be either build in ./build/ndn-js.min.js using
76the following commands:
Jeff Burke33546102012-12-08 11:55:36 -080077
Alexander Afanasyev88a314f2013-03-14 12:52:17 -070078 ./waf configure
79 ./waf
Jeff Burke33546102012-12-08 11:55:36 -080080
Alexander Afanasyev88a314f2013-03-14 12:52:17 -070081Or downloaded from the `downloads` branch (https://github.com/named-data/ndn-js/tree/downloads):
82
83- http://raw.github.com/named-data/ndn-js/downloads/ndn-js.js
84- http://raw.github.com/named-data/ndn-js/downloads/ndn-js.min.js
85
86** Examples **
87
88*** ndn-ping
89
90You can check out `examples/ndn-ping.html` to see an example how to implement ndn-ping in NDN.js
91
92*** Example to retrieve content ***
93
Jeff Burke004039b2012-12-08 11:31:37 -080094A simple example of the current API to express an Interest and receive data:
95
Jeff Burke858c07a2012-12-08 11:35:25 -080096var ndn = new NDN(); // connect to a default hub/proxy
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080097
98var AsyncGetClosure = function AsyncGetClosure() {
99 // Inherit from Closure.
100 Closure.call(this);
101};
102AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) {
103 if (kind == Closure.UPCALL_CONTENT) {
104 console.log("Received " + upcallInfo.contentObject.name.to_uri());
105 console.log(upcallInfo.contentObject.content);
106 }
107 return Closure.RESULT_OK;
108};
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800109
Jeff Burke169445b2012-12-08 12:15:54 -0800110ndn.expressInterest(new Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt"), new
111AsyncGetClosure());
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800112
Jeff Burke018707d2012-12-08 12:23:39 -0800113** Example to publish content **
114
115// Note that publishing content requires knowledge of a
116// routable prefix for your upstream ccnd. We are working
117// on a way to either obtain that prefix or use the /local
118// convention.
119
Alexander Afanasyev426174a2013-03-13 16:45:47 -0700120For now, see tests/test-publish-async.html
Jeff Burke018707d2012-12-08 12:23:39 -0800121
122
123
Jeff Burke004039b2012-12-08 11:31:37 -0800124FIREFOX ADD-ON FOR THE NDN PROTOCOL
125-----------------------------------
126
Alexander Afanasyev426174a2013-03-13 16:45:47 -0700127See files in ndnProtocol/
Jeff Burke004039b2012-12-08 11:31:37 -0800128
Jeff Thompson0bfa3f92013-07-19 18:12:12 -0700129NDN-JS includes a Firefox extension for the ndn protocol built using the Javascript
Jeff Thompsonedaccfb2013-03-17 20:49:35 -0700130library. It currently obtains NDN connectivity through the NDN testbed, but you can
131click Set on the NDN Toolbar to change the connected hub.
Jeff Burke004039b2012-12-08 11:31:37 -0800132
133To install, either download
Alexander Afanasyev426174a2013-03-13 16:45:47 -0700134https://github.com/named-data/ndn-js/raw/downloads/ndnProtocol.xpi
135
136or use ndnProtocol.xpi from `downloads` branch. In Firefox, open
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800137Tools > Add-ons. In the "gear" or "wrench" menu, click Install Add-on From File and open
Jeff Thompsonedaccfb2013-03-17 20:49:35 -0700138ndnProtocol.xpi. (In Firefox for Android, type file: in the address bar and click the
139downloaded ndnProtocol.xpi.) Restart Firefox.
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800140
Jeff Thompson8c563fe2013-06-04 14:35:58 -0700141Firefox uses the protocol extension to load any URI starting with ndn. See this test page for examples:
Jeff Thompson71b6de42013-06-04 14:40:32 -0700142ndn:/ndn/ucla.edu/apps/ndn-js-test/NDNProtocolExamples.html?ndn.ChildSelector=1
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800143
Jeff Burke169445b2012-12-08 12:15:54 -0800144When the page is loaded, Firefox updates the address bar with the full matched name from
145the retrieved content object including the version, but without the implicit digest or
146segment number (see below).
Jeff Burke33546102012-12-08 11:55:36 -0800147
Jeff Burke004039b2012-12-08 11:31:37 -0800148* Interest selectors in the ndn protocol:
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800149
Jeff Burke169445b2012-12-08 12:15:54 -0800150You can add interest selectors. For example, this uses 1 to select the "rightmost" child
Jeff Thompson8c563fe2013-06-04 14:35:58 -0700151(latest version):
Jeff Thompson71b6de42013-06-04 14:40:32 -0700152ndn:/ndn/ucla.edu/apps/ndn-js-test/hello.txt?ndn.ChildSelector=1&key=value#ref
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800153
Jeff Thompson8c563fe2013-06-04 14:35:58 -0700154The browser loads the latest version and changes the address to:
Jeff Thompson71b6de42013-06-04 14:40:32 -0700155ndn:/ndn/ucla.edu/apps/ndn-js-test/hello.txt?ndn.ChildSelector=1&key=value#ref
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800156
Jeff Thompsonbd829262012-11-30 22:28:37 -0800157The child selector was used and removed. Note that the other non-ndn query values and
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800158ref "?key=value#ref" are still present, in case they are needed by the web application.
159
160The following selector keys are supported:
Jeff Thompsonbd829262012-11-30 22:28:37 -0800161ndn.MinSuffixComponent= non-negative int
162ndn.MaxSuffixComponents= non-negative int
163ndn.ChildSelector= non-negative int
164ndn.AnswerOriginKind= non-negative int
165ndn.Scope= non-negative int
Jeff Thompson42806a12012-12-29 18:19:39 -0800166ndn.InterestLifetime= non-negative int (milliseconds)
Jeff Thompsonbd829262012-11-30 22:28:37 -0800167ndn.PublisherPublicKeyDigest= % escaped value
168ndn.Nonce= % escaped value
Jeff Thompson6ac75d22013-02-04 22:41:34 -0800169ndn.Exclude= comma-separated list of % escaped values or * for ANY
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800170
Jeff Thompsonbd829262012-11-30 22:28:37 -0800171* Multiple segments in the ndn protocol
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800172
Jeff Burke169445b2012-12-08 12:15:54 -0800173A URI for content with multiple segments is handled as follows. If the URI has a segment
174number, just retrieve that segment and return the content to the browser.
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800175
Jeff Burke169445b2012-12-08 12:15:54 -0800176Otherwise look at the name in the returned ContentObject. If the returned name has no
177segment number, just return the content to the browser. If the name has a segment number
Jeff Thompson42682dc2013-02-07 07:53:30 -0800178which isn't 0, store it and express an interest for segment 0. Also express an interest for
179the highest segment to try to determine the FinalBlockID early. Fetch multiple segments in order and
180return each content to the browser (in order) as the arrive until we get the segment for FinalBlockID.
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800181