blob: dd34c0d002059e3e0ad1297852b1c104a4c23d35 [file] [log] [blame]
Jeff Thompson745026e2012-10-13 12:49:20 -07001/*
Jeff Thompson5b265a72012-11-12 01:13:08 -08002 * @author: Meki Cherkaoui, Jeff Thompson, Wentao Shang
Jeff Thompson745026e2012-10-13 12:49:20 -07003 * See COPYING for copyright and distribution information.
4 * This class represents the top-level object for communicating with an NDN host.
5 */
Meki Cherkaoui8f173612012-06-06 01:05:40 -07006
Jeff Thompson5b265a72012-11-12 01:13:08 -08007var LOG = 3;
8
Jeff Thompsone06b31e2012-09-30 17:19:19 -07009/**
Jeff Thompson5b265a72012-11-12 01:13:08 -080010 * settings is an associative array with the following defaults:
11 * {
12 * host: 'localhost',
13 * port: 9696,
14 * getTransport: function() { return new WebSocketTransport(); }
15 * }
Jeff Thompsone06b31e2012-09-30 17:19:19 -070016 */
Jeff Thompson5b265a72012-11-12 01:13:08 -080017var NDN = function NDN(settings) {
18 settings = (settings || {});
19 this.host = (settings.host || "localhost");
20 this.port = (settings.port || 9696);
21 var getTransport = (settings.getTransport || function() { return new WebSocketTransport(); });
22 this.transport = getTransport();
Meki Cherkaoui8f173612012-06-06 01:05:40 -070023};
24
Jeff Thompson5b265a72012-11-12 01:13:08 -080025
26/* Java Socket Bridge and XPCOM transport */
27
Jeff Thompsone06b31e2012-09-30 17:19:19 -070028NDN.prototype.createRoute = function(host,port){
Meki Cherkaoui8f173612012-06-06 01:05:40 -070029 this.host=host;
30 this.port=port;
31}
32
Jeff Thompson34419762012-10-15 22:24:12 -070033/** Encode name as an Interest. If template is not null, use its attributes.
34 * Send the interest to host:port, read the entire response and call
35 * closure.upcall(Closure.UPCALL_CONTENT (or Closure.UPCALL_CONTENT_UNVERIFIED),
Jeff Thompson97f27432012-10-16 00:28:03 -070036 * new UpcallInfo(this, interest, 0, contentObject)).
Jeff Thompson34419762012-10-15 22:24:12 -070037 */
38NDN.prototype.expressInterest = function(
39 // Name
40 name,
41 // Closure
42 closure,
43 // Interest
44 template) {
45 if (this.host == null || this.port == null) {
46 dump('ERROR host OR port NOT SET\n');
47 return;
48 }
49
Jeff Thompson5b265a72012-11-12 01:13:08 -080050 var interest = new Interest(name);
Jeff Thompson34419762012-10-15 22:24:12 -070051 if (template != null) {
Jeff Thompson4404ab52012-10-21 10:29:48 -070052 interest.minSuffixComponents = template.minSuffixComponents;
53 interest.maxSuffixComponents = template.maxSuffixComponents;
54 interest.publisherPublicKeyDigest = template.publisherPublicKeyDigest;
55 interest.exclude = template.exclude;
56 interest.childSelector = template.childSelector;
57 interest.answerOriginKind = template.answerOriginKind;
58 interest.scope = template.scope;
59 interest.interestLifetime = template.interestLifetime;
Jeff Thompson34419762012-10-15 22:24:12 -070060 }
61 else
Jeff Thompson741108b2012-10-15 23:07:09 -070062 interest.interestLifetime = 4200;
Jeff Thompson97f27432012-10-16 00:28:03 -070063
Jeff Thompson5b265a72012-11-12 01:13:08 -080064 this.transport.expressInterest(this, interest, closure);
Jeff Thompson34419762012-10-15 22:24:12 -070065};
66
Jeff Thompson5b265a72012-11-12 01:13:08 -080067
68NDN.prototype.registerPrefix = function(name, closure, flag) {
69 return this.transport.registerPrefix(this, name, closure, flag);
70}