blob: 2d16590baabb9e735a04a8f624a34a1aed4a62fc [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 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
Jeff Thompsonadba5a92013-07-19 18:14:59 -070019submit any bugs or issues to the NDN-JS issue tracker:
20http://redmine.named-data.net/projects/ndn-js/issues
Jeff Burke004039b2012-12-08 11:31:37 -080021
Jeff Thompson0bfa3f92013-07-19 18:12:12 -070022The primary goal of NDN-JS is to provide a pure Javascript implementation of the NDN API
Jeff Burke169445b2012-12-08 12:15:54 -080023that enables developers to create browser-based applications using Named Data Networking.
24The approach requires no native code or signed Java applets, and thus can be delivered
25over the current web to modern browsers with no hassle for the end user.
Jeff Burke004039b2012-12-08 11:31:37 -080026
27Additional goals for the project:
Jeff Burke169445b2012-12-08 12:15:54 -080028- Websockets transport (rather than TCP or UDP, which are not directly supported in
29Javascript).
Jeff Burke858c07a2012-12-08 11:35:25 -080030- Relatively lightweight and compact, to enable efficient use on the web.
31- Wire format compatible with PARC's CCNx implementation of NDN.
Jeff Burke004039b2012-12-08 11:31:37 -080032
Jeff Burke169445b2012-12-08 12:15:54 -080033The library currently requires a remote NDN daemon, and has been tested with ccnd, from
34the's CCNx package: http://ccnx.org/
Jeff Burke004039b2012-12-08 11:31:37 -080035
36Currently, 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 Burke169445b2012-12-08 12:15:54 -080045By default, both parts of the library connect automatically to a set of proxies and hubs
46that are part of the NDN research project's testbed. http://named-data.net/testbed.html
47There are currently no restrictions on non-commercial, research-oriented data exchange on
48this testbed. (Contact jburke@remap.ucla.edu for more details.) The developer can also
49specify a local or remote ccnd as well, as an argument to the NDN constructor.
Jeff Burke004039b2012-12-08 11:31:37 -080050
51
52
53JAVASCRIPT API
54--------------
55
Alexander Afanasyev426174a2013-03-13 16:45:47 -070056See files in js/ and examples in tests/, examples/
Jeff Burke004039b2012-12-08 11:31:37 -080057
Jeff Thompson0bfa3f92013-07-19 18:12:12 -070058NDN-JS currently supports expressing Interests (and receiving data) and publishing Data
Jeff Burke169445b2012-12-08 12:15:54 -080059(that answers Interests). This includes encoding and decoding data packets as well as
60signing and verifying them using RSA keys.
Jeff Burke004039b2012-12-08 11:31:37 -080061
Jeff Burke33546102012-12-08 11:55:36 -080062** NDN connectivity **
Jeff Burke169445b2012-12-08 12:15:54 -080063The only way (for now) to get connectivity to other NDN nodes is via ccnd. For the
64Javascript API, a Websockets proxy that can communicate the target ccnd is currently
65required. Code for such a proxy (using Node.js) is in the wsproxy directory. It
66currently listens on port 9696 and passes messages (using either TCP or UDP) to ccnd on
67the same host.
Jeff Burke858c07a2012-12-08 11:35:25 -080068
Jeff Burke33546102012-12-08 11:55:36 -080069** Including the scripts in a web page **
Jeff Thompson0bfa3f92013-07-19 18:12:12 -070070To 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 -080071
Alexander Afanasyev88a314f2013-03-14 12:52:17 -070072ndn-js.js is a combined library (and ndn-js.min.js is a compressed version of the combined library),
73designed for efficient distribution. Bother can be either build in ./build/ndn-js.min.js using
74the following commands:
Jeff Burke33546102012-12-08 11:55:36 -080075
Alexander Afanasyev88a314f2013-03-14 12:52:17 -070076 ./waf configure
77 ./waf
Jeff Burke33546102012-12-08 11:55:36 -080078
Alexander Afanasyev88a314f2013-03-14 12:52:17 -070079Or 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
88You 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 Burke004039b2012-12-08 11:31:37 -080092A simple example of the current API to express an Interest and receive data:
93
Jeff Burke858c07a2012-12-08 11:35:25 -080094var ndn = new NDN(); // connect to a default hub/proxy
Jeff Thompsonb68ceab2012-11-25 18:25:56 -080095
96var AsyncGetClosure = function AsyncGetClosure() {
97 // Inherit from Closure.
98 Closure.call(this);
99};
100AsyncGetClosure.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 Thompson9e6dff02012-11-04 09:20:47 -0800107
Jeff Burke169445b2012-12-08 12:15:54 -0800108ndn.expressInterest(new Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt"), new
109AsyncGetClosure());
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800110
Jeff Burke018707d2012-12-08 12:23:39 -0800111** 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 Afanasyev426174a2013-03-13 16:45:47 -0700118For now, see tests/test-publish-async.html
Jeff Burke018707d2012-12-08 12:23:39 -0800119
120
121
Jeff Burke004039b2012-12-08 11:31:37 -0800122FIREFOX ADD-ON FOR THE NDN PROTOCOL
123-----------------------------------
124
Alexander Afanasyev426174a2013-03-13 16:45:47 -0700125See files in ndnProtocol/
Jeff Burke004039b2012-12-08 11:31:37 -0800126
Jeff Thompson0bfa3f92013-07-19 18:12:12 -0700127NDN-JS includes a Firefox extension for the ndn protocol built using the Javascript
Jeff Thompsonedaccfb2013-03-17 20:49:35 -0700128library. It currently obtains NDN connectivity through the NDN testbed, but you can
129click Set on the NDN Toolbar to change the connected hub.
Jeff Burke004039b2012-12-08 11:31:37 -0800130
131To install, either download
Alexander Afanasyev426174a2013-03-13 16:45:47 -0700132https://github.com/named-data/ndn-js/raw/downloads/ndnProtocol.xpi
133
134or use ndnProtocol.xpi from `downloads` branch. In Firefox, open
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800135Tools > Add-ons. In the "gear" or "wrench" menu, click Install Add-on From File and open
Jeff Thompsonedaccfb2013-03-17 20:49:35 -0700136ndnProtocol.xpi. (In Firefox for Android, type file: in the address bar and click the
137downloaded ndnProtocol.xpi.) Restart Firefox.
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800138
Jeff Thompson8c563fe2013-06-04 14:35:58 -0700139Firefox uses the protocol extension to load any URI starting with ndn. See this test page for examples:
Jeff Thompson71b6de42013-06-04 14:40:32 -0700140ndn:/ndn/ucla.edu/apps/ndn-js-test/NDNProtocolExamples.html?ndn.ChildSelector=1
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800141
Jeff Burke169445b2012-12-08 12:15:54 -0800142When the page is loaded, Firefox updates the address bar with the full matched name from
143the retrieved content object including the version, but without the implicit digest or
144segment number (see below).
Jeff Burke33546102012-12-08 11:55:36 -0800145
Jeff Burke004039b2012-12-08 11:31:37 -0800146* Interest selectors in the ndn protocol:
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800147
Jeff Burke169445b2012-12-08 12:15:54 -0800148You can add interest selectors. For example, this uses 1 to select the "rightmost" child
Jeff Thompson8c563fe2013-06-04 14:35:58 -0700149(latest version):
Jeff Thompson71b6de42013-06-04 14:40:32 -0700150ndn:/ndn/ucla.edu/apps/ndn-js-test/hello.txt?ndn.ChildSelector=1&key=value#ref
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800151
Jeff Thompson8c563fe2013-06-04 14:35:58 -0700152The browser loads the latest version and changes the address to:
Jeff Thompson71b6de42013-06-04 14:40:32 -0700153ndn:/ndn/ucla.edu/apps/ndn-js-test/hello.txt?ndn.ChildSelector=1&key=value#ref
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800154
Jeff Thompsonbd829262012-11-30 22:28:37 -0800155The child selector was used and removed. Note that the other non-ndn query values and
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800156ref "?key=value#ref" are still present, in case they are needed by the web application.
157
158The following selector keys are supported:
Jeff Thompsonbd829262012-11-30 22:28:37 -0800159ndn.MinSuffixComponent= non-negative int
160ndn.MaxSuffixComponents= non-negative int
161ndn.ChildSelector= non-negative int
162ndn.AnswerOriginKind= non-negative int
163ndn.Scope= non-negative int
Jeff Thompson42806a12012-12-29 18:19:39 -0800164ndn.InterestLifetime= non-negative int (milliseconds)
Jeff Thompsonbd829262012-11-30 22:28:37 -0800165ndn.PublisherPublicKeyDigest= % escaped value
166ndn.Nonce= % escaped value
Jeff Thompson6ac75d22013-02-04 22:41:34 -0800167ndn.Exclude= comma-separated list of % escaped values or * for ANY
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800168
Jeff Thompsonbd829262012-11-30 22:28:37 -0800169* Multiple segments in the ndn protocol
Jeff Thompsonb68ceab2012-11-25 18:25:56 -0800170
Jeff Burke169445b2012-12-08 12:15:54 -0800171A URI for content with multiple segments is handled as follows. If the URI has a segment
172number, just retrieve that segment and return the content to the browser.
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800173
Jeff Burke169445b2012-12-08 12:15:54 -0800174Otherwise look at the name in the returned ContentObject. If the returned name has no
175segment number, just return the content to the browser. If the name has a segment number
Jeff Thompson42682dc2013-02-07 07:53:30 -0800176which isn't 0, store it and express an interest for segment 0. Also express an interest for
177the highest segment to try to determine the FinalBlockID early. Fetch multiple segments in order and
178return each content to the browser (in order) as the arrive until we get the segment for FinalBlockID.
Jeff Thompson9e6dff02012-11-04 09:20:47 -0800179