blob: b2b1623a2ac370f4c56695217a212af08bfd55e2 [file] [log] [blame] [view]
Meki Cherkaouif2e96ed2012-04-22 16:21:27 -07001
Jeff Burke004039b2012-12-08 11:31:37 -08002NDN.JS: A javascript client library for Named Data Networking
3--------------------------------------------------------------
Meki Cherkaouif2e96ed2012-04-22 16:21:27 -07004
Jeff Burke169445b2012-12-08 12:15:54 -08005NDN.JS is the first native version of the NDN protocol written in JavaScript. It is wire
6format 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 Burke169445b2012-12-08 12:15:54 -080012NDN.JS is open source under a license described in the file COPYING. While the license
13does 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 Burke004039b2012-12-08 11:31:37 -080016---
17
Jeff Burke169445b2012-12-08 12:15:54 -080018This is a young project, with minimal documentation that we are slowly enhancing. Please
19email Jeff Burke (jburke@remap.ucla.edu) with any questions.
Jeff Burke004039b2012-12-08 11:31:37 -080020
Jeff Burke169445b2012-12-08 12:15:54 -080021The primary goal of NDN.JS is to provide a pure Javascript implementation of the NDN API
22that enables developers to create browser-based applications using Named Data Networking.
23The approach requires no native code or signed Java applets, and thus can be delivered
24over the current web to modern browsers with no hassle for the end user.
Jeff Burke004039b2012-12-08 11:31:37 -080025
26Additional goals for the project:
Jeff Burke169445b2012-12-08 12:15:54 -080027- Websockets transport (rather than TCP or UDP, which are not directly supported in
28Javascript).
Jeff Burke858c07a2012-12-08 11:35:25 -080029- Relatively lightweight and compact, to enable efficient use on the web.
30- Wire format compatible with PARC's CCNx implementation of NDN.
Jeff Burke004039b2012-12-08 11:31:37 -080031
Jeff Burke169445b2012-12-08 12:15:54 -080032The library currently requires a remote NDN daemon, and has been tested with ccnd, from
33the's CCNx package: http://ccnx.org/
Jeff Burke004039b2012-12-08 11:31:37 -080034
35Currently, the library has two APIs for developers:
36
37 1. The Javascript API for asynchronous Interest/Data exchange.
38 This uses WebSockets for transport and currently requires a
39 proxy for communication with a remote ccnd daemon.
40
41 2. A Firefox plug-in, which implements an "ndn:/" url scheme
42 following CCNx repository conventions for file retrieval.
43
Jeff Burke169445b2012-12-08 12:15:54 -080044By default, both parts of the library connect automatically to a set of proxies and hubs
45that are part of the NDN research project's testbed. http://named-data.net/testbed.html
46There are currently no restrictions on non-commercial, research-oriented data exchange on
47this testbed. (Contact jburke@remap.ucla.edu for more details.) The developer can also
48specify a local or remote ccnd as well, as an argument to the NDN constructor.
Jeff Burke004039b2012-12-08 11:31:37 -080049
50
51
52JAVASCRIPT API
53--------------
54
Alexander Afanasyev426174a2013-03-13 16:45:47 -070055See files in js/ and examples in tests/, examples/
Jeff Burke004039b2012-12-08 11:31:37 -080056
Jeff Burke169445b2012-12-08 12:15:54 -080057NDN.JS currently supports expressing Interests (and receiving data) and publishing Data
58(that answers Interests). This includes encoding and decoding data packets as well as
59signing and verifying them using RSA keys.
Jeff Burke004039b2012-12-08 11:31:37 -080060
Jeff Burke33546102012-12-08 11:55:36 -080061** NDN connectivity **
Jeff Burke169445b2012-12-08 12:15:54 -080062The only way (for now) to get connectivity to other NDN nodes is via ccnd. For the
63Javascript API, a Websockets proxy that can communicate the target ccnd is currently
64required. Code for such a proxy (using Node.js) is in the wsproxy directory. It
65currently listens on port 9696 and passes messages (using either TCP or UDP) to ccnd on
66the same host.
Jeff Burke858c07a2012-12-08 11:35:25 -080067
Jeff Burke33546102012-12-08 11:55:36 -080068** Including the scripts in a web page **
Jeff Thompson18874622013-03-16 16:40:33 -070069To 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 -080070
Alexander Afanasyev88a314f2013-03-14 12:52:17 -070071ndn-js.js is a combined library (and ndn-js.min.js is a compressed version of the combined library),
72designed for efficient distribution. Bother can be either build in ./build/ndn-js.min.js using
73the following commands:
Jeff Burke33546102012-12-08 11:55:36 -080074
Alexander Afanasyev88a314f2013-03-14 12:52:17 -070075 ./waf configure
76 ./waf
Jeff Burke33546102012-12-08 11:55:36 -080077
Alexander Afanasyev88a314f2013-03-14 12:52:17 -070078Or downloaded from the `downloads` branch (https://github.com/named-data/ndn-js/tree/downloads):
79
80- http://raw.github.com/named-data/ndn-js/downloads/ndn-js.js
81- http://raw.github.com/named-data/ndn-js/downloads/ndn-js.min.js
82
83** Examples **
84
85*** ndn-ping
86
87You can check out `examples/ndn-ping.html` to see an example how to implement ndn-ping in NDN.js
88
89*** Example to retrieve content ***
90
Jeff Burke004039b2012-12-08 11:31:37 -080091A simple example of the current API to express an Interest and receive data:
92
Jeff Burke858c07a2012-12-08 11:35:25 -080093var ndn = new NDN(); // connect to a default hub/proxy
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080094
95var AsyncGetClosure = function AsyncGetClosure() {
96 // Inherit from Closure.
97 Closure.call(this);
98};
99AsyncGetClosure.prototype.upcall = function(kind, upcallInfo) {
100 if (kind == Closure.UPCALL_CONTENT) {
101 console.log("Received " + upcallInfo.contentObject.name.to_uri());
102 console.log(upcallInfo.contentObject.content);
103 }
104 return Closure.RESULT_OK;
105};
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800106
Jeff Burke169445b2012-12-08 12:15:54 -0800107ndn.expressInterest(new Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt"), new
108AsyncGetClosure());
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800109
Jeff Burke018707d2012-12-08 12:23:39 -0800110** Example to publish content **
111
112// Note that publishing content requires knowledge of a
113// routable prefix for your upstream ccnd. We are working
114// on a way to either obtain that prefix or use the /local
115// convention.
116
Alexander Afanasyev426174a2013-03-13 16:45:47 -0700117For now, see tests/test-publish-async.html
Jeff Burke018707d2012-12-08 12:23:39 -0800118
119
120
Jeff Burke004039b2012-12-08 11:31:37 -0800121FIREFOX ADD-ON FOR THE NDN PROTOCOL
122-----------------------------------
123
Alexander Afanasyev426174a2013-03-13 16:45:47 -0700124See files in ndnProtocol/
Jeff Burke004039b2012-12-08 11:31:37 -0800125
Jeff Burke169445b2012-12-08 12:15:54 -0800126NDN.JS includes a Firefox extension for the ndn protocol built using the Javascript
Jeff Thompsonedaccfb2013-03-17 20:49:35 -0700127library. It currently obtains NDN connectivity through the NDN testbed, but you can
128click Set on the NDN Toolbar to change the connected hub.
Jeff Burke004039b2012-12-08 11:31:37 -0800129
130To install, either download
Alexander Afanasyev426174a2013-03-13 16:45:47 -0700131https://github.com/named-data/ndn-js/raw/downloads/ndnProtocol.xpi
132
133or use ndnProtocol.xpi from `downloads` branch. In Firefox, open
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800134Tools > Add-ons. In the "gear" or "wrench" menu, click Install Add-on From File and open
Jeff Thompsonedaccfb2013-03-17 20:49:35 -0700135ndnProtocol.xpi. (In Firefox for Android, type file: in the address bar and click the
136downloaded ndnProtocol.xpi.) Restart Firefox.
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800137
Jeff Thompson8c563fe2013-06-04 14:35:58 -0700138Firefox uses the protocol extension to load any URI starting with ndn. See this test page for examples:
Jeff Thompson0044ecb2013-06-04 14:33:21 -0700139[ndn:/ndn/ucla.edu/apps/ndn-js-test/NDNProtocolExamples.html?ndn.ChildSelector=1](ndn:/ndn/ucla.edu/apps/ndn-js-test/NDNProtocolExamples.html?ndn.ChildSelector=1)
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800140
Jeff Burke169445b2012-12-08 12:15:54 -0800141When the page is loaded, Firefox updates the address bar with the full matched name from
142the retrieved content object including the version, but without the implicit digest or
143segment number (see below).
Jeff Burke33546102012-12-08 11:55:36 -0800144
Jeff Burke004039b2012-12-08 11:31:37 -0800145* Interest selectors in the ndn protocol:
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800146
Jeff Burke169445b2012-12-08 12:15:54 -0800147You can add interest selectors. For example, this uses 1 to select the "rightmost" child
Jeff Thompson8c563fe2013-06-04 14:35:58 -0700148(latest version):
Jeff Thompson0044ecb2013-06-04 14:33:21 -0700149[ndn:/ndn/ucla.edu/apps/ndn-js-test/hello.txt?ndn.ChildSelector=1&key=value#ref](ndn:/ndn/ucla.edu/apps/ndn-js-test/hello.txt?ndn.ChildSelector=1&key=value#ref)
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800150
Jeff Thompson8c563fe2013-06-04 14:35:58 -0700151The browser loads the latest version and changes the address to:
Jeff Thompson0044ecb2013-06-04 14:33:21 -0700152[ndn:/ndn/ucla.edu/apps/ndn-js-test/hello.txt?ndn.ChildSelector=1&key=value#ref](ndn:/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 -0800153
Jeff Thompsonbd829262012-11-30 22:28:37 -0800154The child selector was used and removed. Note that the other non-ndn query values and
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800155ref "?key=value#ref" are still present, in case they are needed by the web application.
156
157The following selector keys are supported:
Jeff Thompsonbd829262012-11-30 22:28:37 -0800158ndn.MinSuffixComponent= non-negative int
159ndn.MaxSuffixComponents= non-negative int
160ndn.ChildSelector= non-negative int
161ndn.AnswerOriginKind= non-negative int
162ndn.Scope= non-negative int
Jeff Thompson42806a12012-12-29 18:19:39 -0800163ndn.InterestLifetime= non-negative int (milliseconds)
Jeff Thompsonbd829262012-11-30 22:28:37 -0800164ndn.PublisherPublicKeyDigest= % escaped value
165ndn.Nonce= % escaped value
Jeff Thompson6ac75d22013-02-04 22:41:34 -0800166ndn.Exclude= comma-separated list of % escaped values or * for ANY
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800167
Jeff Thompsonbd829262012-11-30 22:28:37 -0800168* Multiple segments in the ndn protocol
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800169
Jeff Burke169445b2012-12-08 12:15:54 -0800170A URI for content with multiple segments is handled as follows. If the URI has a segment
171number, just retrieve that segment and return the content to the browser.
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800172
Jeff Burke169445b2012-12-08 12:15:54 -0800173Otherwise look at the name in the returned ContentObject. If the returned name has no
174segment number, just return the content to the browser. If the name has a segment number
Jeff Thompson42682dc2013-02-07 07:53:30 -0800175which isn't 0, store it and express an interest for segment 0. Also express an interest for
176the highest segment to try to determine the FinalBlockID early. Fetch multiple segments in order and
177return each content to the browser (in order) as the arrive until we get the segment for FinalBlockID.
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800178