blob: 152704fff137e544f9204bdee2d7b2e8559b19fa [file] [log] [blame]
Meki Cherkaoui97e7a592012-04-14 02:50:06 -07001
2var Interest = function Interest(_Name,_MinSuffixComponents,_MaxSuffixComponents,_PublisherPublicKeyDigest, _Exclude, _ChildSelector,_AnswerOriginKind,_Scope,_InterestLifetime,_Nonce){
3
4
5 this.Name = _Name;
6 this.MaxSuffixComponents = _MaxSuffixComponents;
7 this.MinSuffixComponents = _MinSuffixComponents;
8
9 this.PublisherKeyDigest = _PublisherPublicKeyDigest;
10 this.Exclude = _Exclude;
11 this.ChildSelector = _ChildSelector;
12 this.AnswerOriginKind = _AnswerOriginKind;
13 this.Scope = _Scope;
14 this.InterestLifetime = null; // For now we don't have the ability to set an interest lifetime
15 this.Nonce = _Nonce;
16
17 /*Not sure if the rest is needed*/
18 this.Publisher = _Publisher;
19
20 this.UserTime=_UserTime;
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 = ANSWER_CONTENT_STORE | ANSWER_GENERATED;
32
33
34};
35
36Interest.prototype.decode = function(/*XMLDecoder*/ decoder) {
37
38 decoder.readStartElement(CCNProtocolDTags.Interest);
39
40 this.Name = new ContentName();
41 this.Name.decode(decoder);
42
43 if (decoder.peekStartElement(CCNProtocolDTags.MinSuffixComponents)) {
44 this.MinSuffixComponents = decoder.readIntegerElement(CCNProtocolDTags.MinSuffixComponents);
45 }
46
47 if (decoder.peekStartElement(CCNProtocolDTags.MaxSuffixComponents)) {
48 this.MaxSuffixComponents = decoder.readIntegerElement(CCNProtocolDTags.MaxSuffixComponents);
49 }
50
51 //TODO something about that guy
52 /*if (PublisherID.peek(decoder)) {
53 this.Publisher = new PublisherID();
54 this.Publisher.decode(decoder);
55 }*/
56
57 if (decoder.peekStartElement(CCNProtocolDTags.Exclude)) {
58 this.Exclude = new Exclude();
59 this.Exclude.decode(decoder);
60 }
61
62 if (decoder.peekStartElement(CCNProtocolDTags.ChildSelector)) {
63 this.ChildSelector = decoder.readIntegerElement(CCNProtocolDTags.ChildSelector);
64 }
65
66 if (decoder.peekStartElement(CCNProtocolDTags.AnswerOriginKind)) {
67 // call setter to handle defaulting
68 this.AnswerOriginKind = decoder.readIntegerElement(CCNProtocolDTags.AnswerOriginKind);
69 }
70
71 if (decoder.peekStartElement(CCNProtocolDTags.Scope)) {
72 this.Scope = decoder.readIntegerElement(CCNProtocolDTags.Scope);
73 }
74
75 if (decoder.peekStartElement(CCNProtocolDTags.InterestLifetime)) {
76 this.InterestLifetime = decoder.readBinaryElement(CCNProtocolDTags.InterestLifetime);
77 }
78
79 if (decoder.peekStartElement(CCNProtocolDTags.Nonce)) {
80 this.Nonce = decoder.readBinaryElement(CCNProtocolDTags.Nonce);
81 }
82
83 decoder.readEndElement();
84};
85
86
87Interest.prototype.encode = function(/*XMLEncoder*/ encoder){
88 if (!validate()) {
89 throw new ContentEncodingException("Cannot encode " + this.getClass().getName() + ": field values missing.");
90 }
91
92 encoder.writeStartElement(CCNProtocolDTags.Interest);
93
94 this.Name.encode(encoder);
95
96 if (null != this.MinSuffixComponents)
97 encoder.writeElement(CCNProtocolDTags.MinSuffixComponents, this.MinSuffixComponents);
98
99 if (null != this.MaxSuffixComponents)
100 encoder.writeElement(CCNProtocolDTags.MaxSuffixComponents, this.MaxSuffixComponents);
101
102 //TODO
103
104 /*if (null != this.PublisherID)
105 publisherID().encode(encoder);*/
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 if (this.DEFAULT_ANSWER_ORIGIN_KIND != this.AnswerOriginKind)
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