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