blob: 03f792d5d567696a20f84e5a28679e807ab6f24e [file] [log] [blame]
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -07001 /*
2 * @author: ucla-cs
3 * This class represents Interest Objects
4 */
5
6var Interest = function Interest(_Name,_FaceInstance,_MinSuffixComponents,_MaxSuffixComponents,_PublisherPublicKeyDigest, _Exclude, _ChildSelector,_AnswerOriginKind,_Scope,_InterestLifetime,_Nonce){
7
8 this.Name = _Name;
9 this.FaceInstance = _FaceInstance;
10 this.MaxSuffixComponents = _MaxSuffixComponents;
11 this.MinSuffixComponents = _MinSuffixComponents;
12
13 this.PublisherKeyDigest = _PublisherPublicKeyDigest;
14 this.Exclude = _Exclude;
15 this.ChildSelector = _ChildSelector;
16 this.AnswerOriginKind = _AnswerOriginKind;
17 this.Scope = _Scope;
18 this.InterestLifetime = null; // For now we don't have the ability to set an interest lifetime
19 this.Nonce = _Nonce;
20
21
22 this.RECURSIVE_POSTFIX = "*";
23
24 this.CHILD_SELECTOR_LEFT = 0;
25 this.CHILD_SELECTOR_RIGHT = 1;
26 this.ANSWER_CONTENT_STORE = 1;
27 this.ANSWER_GENERATED = 2;
28 this.ANSWER_STALE = 4; // Stale answer OK
29 this.MARK_STALE = 16; // Must have Scope 0. Michael calls this a "hack"
30
31 this.DEFAULT_ANSWER_ORIGIN_KIND = this.ANSWER_CONTENT_STORE | this.ANSWER_GENERATED;
32
33};
34
35Interest.prototype.decode = function(/*XMLDecoder*/ decoder) {
36
37 decoder.readStartElement(CCNProtocolDTags.Interest);
38
39 this.Name = new ContentName();
40 this.Name.decode(decoder);
41
42 if (decoder.peekStartElement(CCNProtocolDTags.MinSuffixComponents)) {
43 this.MinSuffixComponents = decoder.readIntegerElement(CCNProtocolDTags.MinSuffixComponents);
44 }
45
46 if (decoder.peekStartElement(CCNProtocolDTags.MaxSuffixComponents)) {
47 this.MaxSuffixComponents = decoder.readIntegerElement(CCNProtocolDTags.MaxSuffixComponents);
48 }
49
50 //TODO decode PublisherID
51 /*if (PublisherID.peek(decoder)) {
52 this.Publisher = new PublisherID();
53 this.Publisher.decode(decoder);
54 }*/
55
56 if (decoder.peekStartElement(CCNProtocolDTags.Exclude)) {
57 this.Exclude = new Exclude();
58 this.Exclude.decode(decoder);
59 }
60
61 if (decoder.peekStartElement(CCNProtocolDTags.ChildSelector)) {
62 this.ChildSelector = decoder.readIntegerElement(CCNProtocolDTags.ChildSelector);
63 }
64
65 if (decoder.peekStartElement(CCNProtocolDTags.AnswerOriginKind)) {
66 // call setter to handle defaulting
67 this.AnswerOriginKind = decoder.readIntegerElement(CCNProtocolDTags.AnswerOriginKind);
68 }
69
70 if (decoder.peekStartElement(CCNProtocolDTags.Scope)) {
71 this.Scope = decoder.readIntegerElement(CCNProtocolDTags.Scope);
72 }
73
74 if (decoder.peekStartElement(CCNProtocolDTags.InterestLifetime)) {
75 this.InterestLifetime = decoder.readBinaryElement(CCNProtocolDTags.InterestLifetime);
76 }
77
78 if (decoder.peekStartElement(CCNProtocolDTags.Nonce)) {
79 this.Nonce = decoder.readBinaryElement(CCNProtocolDTags.Nonce);
80 }
81
82 decoder.readEndElement();
83};
84
85Interest.prototype.encode = function(/*XMLEncoder*/ encoder){
86 /*if (!validate()) {
87 throw new ContentEncodingException("Cannot encode " + this.getClass().getName() + ": field values missing.");
88 }*/
89
90 encoder.writeStartElement(CCNProtocolDTags.Interest);
91
92 this.Name.encode(encoder);
93
94 if (null != this.MinSuffixComponents)
95 encoder.writeElement(CCNProtocolDTags.MinSuffixComponents, this.MinSuffixComponents);
96
97 if (null != this.MaxSuffixComponents)
98 encoder.writeElement(CCNProtocolDTags.MaxSuffixComponents, this.MaxSuffixComponents);
99
100 //TODO Encode PublisherID
101
102 /*if (null != this.PublisherID)
103 publisherID().encode(encoder);*/
104
105 //TODO Encode Exclude
106
107 //if (null != this.Exclude)
108 //exclude().encode(encoder);
109
110 if (null != this.ChildSelector)
111 encoder.writeElement(CCNProtocolDTags.ChildSelector, this.ChildSelector);
112
113 //TODO Encode OriginKind
114 if (this.DEFAULT_ANSWER_ORIGIN_KIND != this.AnswerOriginKind && this.AnswerOriginKind!=null)
115 //encoder.writeElement(CCNProtocolDTags.AnswerOriginKind, this.AnswerOriginKind);
116
117 if (null != this.Scope)
118 encoder.writeElement(CCNProtocolDTags.Scope, this.Scope);
119
120 if (null != this.Nonce)
121 encoder.writeElement(CCNProtocolDTags.Nonce, this.Nonce);
122
123 encoder.writeEndElement();
124
125};
126