Wentao Shang | bd63e46 | 2012-12-03 16:19:33 -0800 | [diff] [blame] | 1 | /** |
Jeff Thompson | 146d7de | 2012-11-17 16:15:28 -0800 | [diff] [blame] | 2 | * @author: Meki Cheraoui |
Jeff Thompson | 745026e | 2012-10-13 12:49:20 -0700 | [diff] [blame] | 3 | * See COPYING for copyright and distribution information. |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 4 | * This class represents Interest Objects |
| 5 | */ |
| 6 | |
Jeff Thompson | 42806a1 | 2012-12-29 18:19:39 -0800 | [diff] [blame] | 7 | // _interestLifetime is in milliseconds. |
Jeff Thompson | ea3a690 | 2013-02-17 21:56:34 -0800 | [diff] [blame] | 8 | var Interest = function Interest |
| 9 | (_name, _faceInstance, _minSuffixComponents, _maxSuffixComponents, _publisherPublicKeyDigest, _exclude, |
| 10 | _childSelector, _answerOriginKind, _scope, _interestLifetime, _nonce) { |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 11 | |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 12 | this.name = _name; |
| 13 | this.faceInstance = _faceInstance; |
| 14 | this.maxSuffixComponents = _maxSuffixComponents; |
| 15 | this.minSuffixComponents = _minSuffixComponents; |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 16 | |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 17 | this.publisherPublicKeyDigest = _publisherPublicKeyDigest; |
| 18 | this.exclude = _exclude; |
| 19 | this.childSelector = _childSelector; |
| 20 | this.answerOriginKind = _answerOriginKind; |
| 21 | this.scope = _scope; |
Jeff Thompson | 42806a1 | 2012-12-29 18:19:39 -0800 | [diff] [blame] | 22 | this.interestLifetime = _interestLifetime; // milli seconds |
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 23 | this.nonce = _nonce; |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 24 | }; |
| 25 | |
Jeff Thompson | 821183d | 2012-11-24 18:46:21 -0800 | [diff] [blame] | 26 | Interest.RECURSIVE_POSTFIX = "*"; |
| 27 | |
| 28 | Interest.CHILD_SELECTOR_LEFT = 0; |
| 29 | Interest.CHILD_SELECTOR_RIGHT = 1; |
| 30 | Interest.ANSWER_CONTENT_STORE = 1; |
| 31 | Interest.ANSWER_GENERATED = 2; |
| 32 | Interest.ANSWER_STALE = 4; // Stale answer OK |
| 33 | Interest.MARK_STALE = 16; // Must have scope 0. Michael calls this a "hack" |
| 34 | |
| 35 | Interest.DEFAULT_ANSWER_ORIGIN_KIND = Interest.ANSWER_CONTENT_STORE | Interest.ANSWER_GENERATED; |
| 36 | |
| 37 | |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 38 | Interest.prototype.from_ccnb = function(/*XMLDecoder*/ decoder) { |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 39 | |
| 40 | decoder.readStartElement(CCNProtocolDTags.Interest); |
| 41 | |
Jeff Thompson | f3bd359 | 2012-09-29 23:25:30 -0700 | [diff] [blame] | 42 | this.name = new Name(); |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 43 | this.name.from_ccnb(decoder); |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 44 | |
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 45 | if (decoder.peekStartElement(CCNProtocolDTags.MinSuffixComponents)) |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 46 | this.minSuffixComponents = decoder.readIntegerElement(CCNProtocolDTags.MinSuffixComponents); |
Jeff Thompson | 12414d6 | 2013-07-26 17:01:29 -0700 | [diff] [blame^] | 47 | else |
| 48 | this.minSuffixComponents = null; |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 49 | |
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 50 | if (decoder.peekStartElement(CCNProtocolDTags.MaxSuffixComponents)) |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 51 | this.maxSuffixComponents = decoder.readIntegerElement(CCNProtocolDTags.MaxSuffixComponents); |
Jeff Thompson | 12414d6 | 2013-07-26 17:01:29 -0700 | [diff] [blame^] | 52 | else |
| 53 | this.maxSuffixComponents = null; |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 54 | |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 55 | if (decoder.peekStartElement(CCNProtocolDTags.PublisherPublicKeyDigest)) { |
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 56 | this.publisherPublicKeyDigest = new PublisherPublicKeyDigest(); |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 57 | this.publisherPublicKeyDigest.from_ccnb(decoder); |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 58 | } |
Jeff Thompson | 12414d6 | 2013-07-26 17:01:29 -0700 | [diff] [blame^] | 59 | else |
| 60 | this.publisherPublicKeyDigest = null; |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 61 | |
| 62 | if (decoder.peekStartElement(CCNProtocolDTags.Exclude)) { |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 63 | this.exclude = new Exclude(); |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 64 | this.exclude.from_ccnb(decoder); |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 65 | } |
Jeff Thompson | 12414d6 | 2013-07-26 17:01:29 -0700 | [diff] [blame^] | 66 | else |
| 67 | this.exclude = null; |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 68 | |
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 69 | if (decoder.peekStartElement(CCNProtocolDTags.ChildSelector)) |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 70 | this.childSelector = decoder.readIntegerElement(CCNProtocolDTags.ChildSelector); |
Jeff Thompson | 12414d6 | 2013-07-26 17:01:29 -0700 | [diff] [blame^] | 71 | else |
| 72 | this.childSelector = null; |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 73 | |
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 74 | if (decoder.peekStartElement(CCNProtocolDTags.AnswerOriginKind)) |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 75 | this.answerOriginKind = decoder.readIntegerElement(CCNProtocolDTags.AnswerOriginKind); |
Jeff Thompson | 12414d6 | 2013-07-26 17:01:29 -0700 | [diff] [blame^] | 76 | else |
| 77 | this.answerOriginKind = null; |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 78 | |
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 79 | if (decoder.peekStartElement(CCNProtocolDTags.Scope)) |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 80 | this.scope = decoder.readIntegerElement(CCNProtocolDTags.Scope); |
Jeff Thompson | 12414d6 | 2013-07-26 17:01:29 -0700 | [diff] [blame^] | 81 | else |
| 82 | this.scope = null; |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 83 | |
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 84 | if (decoder.peekStartElement(CCNProtocolDTags.InterestLifetime)) |
Jeff Thompson | 42806a1 | 2012-12-29 18:19:39 -0800 | [diff] [blame] | 85 | this.interestLifetime = 1000.0 * DataUtils.bigEndianToUnsignedInt |
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 86 | (decoder.readBinaryElement(CCNProtocolDTags.InterestLifetime)) / 4096; |
Jeff Thompson | 12414d6 | 2013-07-26 17:01:29 -0700 | [diff] [blame^] | 87 | else |
| 88 | this.interestLifetime = null; |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 89 | |
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 90 | if (decoder.peekStartElement(CCNProtocolDTags.Nonce)) |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 91 | this.nonce = decoder.readBinaryElement(CCNProtocolDTags.Nonce); |
Jeff Thompson | 12414d6 | 2013-07-26 17:01:29 -0700 | [diff] [blame^] | 92 | else |
| 93 | this.nonce = null; |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 94 | |
| 95 | decoder.readEndElement(); |
| 96 | }; |
| 97 | |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 98 | Interest.prototype.to_ccnb = function(/*XMLEncoder*/ encoder){ |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 99 | //Could check if name is present |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 100 | |
| 101 | encoder.writeStartElement(CCNProtocolDTags.Interest); |
| 102 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 103 | this.name.to_ccnb(encoder); |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 104 | |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 105 | if (null != this.minSuffixComponents) |
| 106 | encoder.writeElement(CCNProtocolDTags.MinSuffixComponents, this.minSuffixComponents); |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 107 | |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 108 | if (null != this.maxSuffixComponents) |
| 109 | encoder.writeElement(CCNProtocolDTags.MaxSuffixComponents, this.maxSuffixComponents); |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 110 | |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 111 | if (null != this.publisherPublicKeyDigest) |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 112 | this.publisherPublicKeyDigest.to_ccnb(encoder); |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 113 | |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 114 | if (null != this.exclude) |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 115 | this.exclude.to_ccnb(encoder); |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 116 | |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 117 | if (null != this.childSelector) |
| 118 | encoder.writeElement(CCNProtocolDTags.ChildSelector, this.childSelector); |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 119 | |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 120 | if (this.DEFAULT_ANSWER_ORIGIN_KIND != this.answerOriginKind && this.answerOriginKind!=null) |
| 121 | encoder.writeElement(CCNProtocolDTags.AnswerOriginKind, this.answerOriginKind); |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 122 | |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 123 | if (null != this.scope) |
| 124 | encoder.writeElement(CCNProtocolDTags.Scope, this.scope); |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 125 | |
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 126 | if (null != this.interestLifetime) |
| 127 | encoder.writeElement(CCNProtocolDTags.InterestLifetime, |
Jeff Thompson | 42806a1 | 2012-12-29 18:19:39 -0800 | [diff] [blame] | 128 | DataUtils.nonNegativeIntToBigEndian((this.interestLifetime / 1000.0) * 4096)); |
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 129 | |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 130 | if (null != this.nonce) |
| 131 | encoder.writeElement(CCNProtocolDTags.Nonce, this.nonce); |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 132 | |
| 133 | encoder.writeEndElement(); |
| 134 | |
| 135 | }; |
| 136 | |
Jeff Thompson | 202728a | 2013-02-10 22:20:08 -0800 | [diff] [blame] | 137 | /* |
| 138 | * Return true if this.name.match(name) and the name conforms to the interest selectors. |
| 139 | */ |
Jeff Thompson | 3f4be55 | 2013-01-05 22:36:40 -0800 | [diff] [blame] | 140 | Interest.prototype.matches_name = function(/*Name*/ name) { |
Jeff Thompson | 202728a | 2013-02-10 22:20:08 -0800 | [diff] [blame] | 141 | if (!this.name.match(name)) |
| 142 | return false; |
| 143 | |
| 144 | if (this.minSuffixComponents != null && |
| 145 | // Add 1 for the implicit digest. |
| 146 | !(name.components.length + 1 - this.name.components.length >= this.minSuffixComponents)) |
| 147 | return false; |
| 148 | if (this.maxSuffixComponents != null && |
| 149 | // Add 1 for the implicit digest. |
| 150 | !(name.components.length + 1 - this.name.components.length <= this.maxSuffixComponents)) |
| 151 | return false; |
| 152 | if (this.exclude != null && name.components.length > this.name.components.length && |
| 153 | this.exclude.matches(name.components[this.name.components.length])) |
| 154 | return false; |
| 155 | |
| 156 | return true; |
Jeff Thompson | ea3a690 | 2013-02-17 21:56:34 -0800 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | /* |
| 160 | * Return a new Interest with the same fields as this Interest. |
| 161 | * Note: This does NOT make a deep clone of the name, exclue or other objects. |
| 162 | */ |
| 163 | Interest.prototype.clone = function() { |
| 164 | return new Interest |
| 165 | (this.name, this.faceInstance, this.minSuffixComponents, this.maxSuffixComponents, |
| 166 | this.publisherPublicKeyDigest, this.exclude, this.childSelector, this.answerOriginKind, |
| 167 | this.scope, this.interestLifetime, this.nonce); |
| 168 | }; |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 169 | |
Jeff Thompson | 08d41b7 | 2013-02-03 23:09:29 -0800 | [diff] [blame] | 170 | /* |
| 171 | * Handle the interest Exclude element. |
| 172 | * _values is an array where each element is either Uint8Array component or Exclude.ANY. |
Jeff Thompson | b9ce458 | 2012-09-30 17:52:51 -0700 | [diff] [blame] | 173 | */ |
Jeff Thompson | 08d41b7 | 2013-02-03 23:09:29 -0800 | [diff] [blame] | 174 | var Exclude = function Exclude(_values) { |
| 175 | this.values = (_values || []); |
Jeff Thompson | b9ce458 | 2012-09-30 17:52:51 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Jeff Thompson | 08d41b7 | 2013-02-03 23:09:29 -0800 | [diff] [blame] | 178 | Exclude.ANY = "*"; |
| 179 | |
Jeff Thompson | b9ce458 | 2012-09-30 17:52:51 -0700 | [diff] [blame] | 180 | Exclude.prototype.from_ccnb = function(/*XMLDecoder*/ decoder) { |
Jeff Thompson | 08d41b7 | 2013-02-03 23:09:29 -0800 | [diff] [blame] | 181 | decoder.readStartElement(CCNProtocolDTags.Exclude); |
Jeff Thompson | b9ce458 | 2012-09-30 17:52:51 -0700 | [diff] [blame] | 182 | |
Jeff Thompson | 08d41b7 | 2013-02-03 23:09:29 -0800 | [diff] [blame] | 183 | while (true) { |
| 184 | if (decoder.peekStartElement(CCNProtocolDTags.Component)) |
| 185 | this.values.push(decoder.readBinaryElement(CCNProtocolDTags.Component)); |
| 186 | else if (decoder.peekStartElement(CCNProtocolDTags.Any)) { |
| 187 | decoder.readStartElement(CCNProtocolDTags.Any); |
| 188 | decoder.readEndElement(); |
| 189 | this.values.push(Exclude.ANY); |
| 190 | } |
| 191 | else if (decoder.peekStartElement(CCNProtocolDTags.Bloom)) { |
| 192 | // Skip the Bloom and treat it as Any. |
| 193 | decoder.readBinaryElement(CCNProtocolDTags.Bloom); |
| 194 | this.values.push(Exclude.ANY); |
| 195 | } |
| 196 | else |
| 197 | break; |
| 198 | } |
| 199 | |
| 200 | decoder.readEndElement(); |
| 201 | }; |
| 202 | |
| 203 | Exclude.prototype.to_ccnb = function(/*XMLEncoder*/ encoder) { |
| 204 | if (this.values == null || this.values.length == 0) |
| 205 | return; |
| 206 | |
| 207 | encoder.writeStartElement(CCNProtocolDTags.Exclude); |
| 208 | |
| 209 | // TODO: Do we want to order the components (except for ANY)? |
| 210 | for (var i = 0; i < this.values.length; ++i) { |
| 211 | if (this.values[i] == Exclude.ANY) { |
| 212 | encoder.writeStartElement(CCNProtocolDTags.Any); |
| 213 | encoder.writeEndElement(); |
| 214 | } |
| 215 | else |
| 216 | encoder.writeElement(CCNProtocolDTags.Component, this.values[i]); |
| 217 | } |
| 218 | |
| 219 | encoder.writeEndElement(); |
| 220 | }; |
| 221 | |
Jeff Thompson | 202728a | 2013-02-10 22:20:08 -0800 | [diff] [blame] | 222 | /* |
| 223 | * Return a string with elements separated by "," and Exclude.ANY shown as "*". |
| 224 | */ |
Jeff Thompson | 08d41b7 | 2013-02-03 23:09:29 -0800 | [diff] [blame] | 225 | Exclude.prototype.to_uri = function() { |
| 226 | if (this.values == null || this.values.length == 0) |
| 227 | return ""; |
| 228 | |
| 229 | var result = ""; |
| 230 | for (var i = 0; i < this.values.length; ++i) { |
| 231 | if (i > 0) |
| 232 | result += ","; |
Jeff Thompson | fced4c2 | 2013-01-27 16:34:13 -0800 | [diff] [blame] | 233 | |
Jeff Thompson | 08d41b7 | 2013-02-03 23:09:29 -0800 | [diff] [blame] | 234 | if (this.values[i] == Exclude.ANY) |
| 235 | result += "*"; |
| 236 | else |
| 237 | result += Name.toEscapedString(this.values[i]); |
| 238 | } |
| 239 | return result; |
Jeff Thompson | b9ce458 | 2012-09-30 17:52:51 -0700 | [diff] [blame] | 240 | }; |
Jeff Thompson | 202728a | 2013-02-10 22:20:08 -0800 | [diff] [blame] | 241 | |
| 242 | /* |
| 243 | * Return true if the component matches any of the exclude criteria. |
| 244 | */ |
| 245 | Exclude.prototype.matches = function(/*Uint8Array*/ component) { |
| 246 | for (var i = 0; i < this.values.length; ++i) { |
| 247 | if (this.values[i] == Exclude.ANY) { |
| 248 | var lowerBound = null; |
| 249 | if (i > 0) |
| 250 | lowerBound = this.values[i - 1]; |
| 251 | |
| 252 | // Find the upper bound, possibly skipping over multiple ANY in a row. |
| 253 | var iUpperBound; |
| 254 | var upperBound = null; |
| 255 | for (iUpperBound = i + 1; iUpperBound < this.values.length; ++iUpperBound) { |
| 256 | if (this.values[iUpperBound] != Exclude.ANY) { |
| 257 | upperBound = this.values[iUpperBound]; |
| 258 | break; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | // If lowerBound != null, we already checked component equals lowerBound on the last pass. |
| 263 | // If upperBound != null, we will check component equals upperBound on the next pass. |
| 264 | if (upperBound != null) { |
| 265 | if (lowerBound != null) { |
| 266 | if (Exclude.compareComponents(component, lowerBound) > 0 && |
| 267 | Exclude.compareComponents(component, upperBound) < 0) |
| 268 | return true; |
| 269 | } |
| 270 | else { |
| 271 | if (Exclude.compareComponents(component, upperBound) < 0) |
| 272 | return true; |
| 273 | } |
| 274 | |
| 275 | // Make i equal iUpperBound on the next pass. |
| 276 | i = iUpperBound - 1; |
| 277 | } |
| 278 | else { |
| 279 | if (lowerBound != null) { |
| 280 | if (Exclude.compareComponents(component, lowerBound) > 0) |
| 281 | return true; |
| 282 | } |
| 283 | else |
| 284 | // this.values has only ANY. |
| 285 | return true; |
| 286 | } |
| 287 | } |
| 288 | else { |
| 289 | if (DataUtils.arraysEqual(component, this.values[i])) |
| 290 | return true; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | return false; |
| 295 | }; |
| 296 | |
| 297 | /* |
| 298 | * Return -1 if component1 is less than component2, 1 if greater or 0 if equal. |
| 299 | * A component is less if it is shorter, otherwise if equal length do a byte comparison. |
| 300 | */ |
| 301 | Exclude.compareComponents = function(/*Uint8Array*/ component1, /*Uint8Array*/ component2) { |
| 302 | if (component1.length < component2.length) |
| 303 | return -1; |
| 304 | if (component1.length > component2.length) |
| 305 | return 1; |
| 306 | |
| 307 | for (var i = 0; i < component1.length; ++i) { |
| 308 | if (component1[i] < component2[i]) |
| 309 | return -1; |
| 310 | if (component1[i] > component2[i]) |
| 311 | return 1; |
| 312 | } |
| 313 | |
| 314 | return 0; |
| 315 | }; |