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 | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 4 | * This class represents Forwarding Entries |
| 5 | */ |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 6 | |
| 7 | var ForwardingEntry = function ForwardingEntry( |
| 8 | //ActionType |
| 9 | _action, |
Jeff Thompson | f3bd359 | 2012-09-29 23:25:30 -0700 | [diff] [blame] | 10 | //Name |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 11 | _prefixName, |
| 12 | //PublisherPublicKeyDigest |
| 13 | _ccndId, |
| 14 | //Integer |
| 15 | _faceID, |
| 16 | //Integer |
| 17 | _flags, |
| 18 | //Integer |
| 19 | _lifetime){ |
| 20 | |
| 21 | |
| 22 | |
| 23 | //String |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 24 | this.action = _action; |
Jeff Thompson | f3bd359 | 2012-09-29 23:25:30 -0700 | [diff] [blame] | 25 | //Name\ |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 26 | this.prefixName = _prefixName; |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 27 | //PublisherPublicKeyDigest |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 28 | this.ccndID = _ccndId; |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 29 | //Integer |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 30 | this.faceID = _faceID; |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 31 | //Integer |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 32 | this.flags = _flags; |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 33 | //Integer |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 34 | this.lifetime = _lifetime; // in seconds |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 35 | |
| 36 | }; |
| 37 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 38 | ForwardingEntry.prototype.from_ccnb =function( |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 39 | //XMLDecoder |
| 40 | decoder) |
| 41 | //throws ContentDecodingException |
| 42 | { |
| 43 | decoder.readStartElement(this.getElementLabel()); |
| 44 | if (decoder.peekStartElement(CCNProtocolDTags.Action)) { |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 45 | this.action = decoder.readUTF8Element(CCNProtocolDTags.Action); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 46 | } |
| 47 | if (decoder.peekStartElement(CCNProtocolDTags.Name)) { |
Jeff Thompson | f3bd359 | 2012-09-29 23:25:30 -0700 | [diff] [blame] | 48 | this.prefixName = new Name(); |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 49 | this.prefixName.from_ccnb(decoder) ; |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 50 | } |
| 51 | if (decoder.peekStartElement(CCNProtocolDTags.PublisherPublicKeyDigest)) { |
| 52 | this.CcndId = new PublisherPublicKeyDigest(); |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 53 | this.CcndId.from_ccnb(decoder); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 54 | } |
| 55 | if (decoder.peekStartElement(CCNProtocolDTags.FaceID)) { |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 56 | this.faceID = decoder.readIntegerElement(CCNProtocolDTags.FaceID); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 57 | } |
| 58 | if (decoder.peekStartElement(CCNProtocolDTags.ForwardingFlags)) { |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 59 | this.flags = decoder.readIntegerElement(CCNProtocolDTags.ForwardingFlags); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 60 | } |
| 61 | if (decoder.peekStartElement(CCNProtocolDTags.FreshnessSeconds)) { |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 62 | this.lifetime = decoder.readIntegerElement(CCNProtocolDTags.FreshnessSeconds); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 63 | } |
| 64 | decoder.readEndElement(); |
| 65 | }; |
| 66 | |
| 67 | /** |
| 68 | * Used by NetworkObject to encode the object to a network stream. |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 69 | */ |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 70 | ForwardingEntry.prototype.to_ccnb =function( |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 71 | //XMLEncoder |
| 72 | encoder) |
| 73 | { |
| 74 | |
| 75 | |
| 76 | //if (!validate()) { |
| 77 | //throw new ContentEncodingException("Cannot encode " + this.getClass().getName() + ": field values missing."); |
| 78 | //} |
| 79 | encoder.writeStartElement(this.getElementLabel()); |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 80 | if (null != this.action && this.action.length != 0) |
| 81 | encoder.writeElement(CCNProtocolDTags.Action, this.action); |
| 82 | if (null != this.prefixName) { |
| 83 | this.prefixName.to_ccnb(encoder); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 84 | } |
| 85 | if (null != this.CcndId) { |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 86 | this.CcndId.to_ccnb(encoder); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 87 | } |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 88 | if (null != this.faceID) { |
| 89 | encoder.writeElement(CCNProtocolDTags.FaceID, this.faceID); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 90 | } |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 91 | if (null != this.flags) { |
| 92 | encoder.writeElement(CCNProtocolDTags.ForwardingFlags, this.flags); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 93 | } |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 94 | if (null != this.lifetime) { |
| 95 | encoder.writeElement(CCNProtocolDTags.FreshnessSeconds, this.lifetime); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 96 | } |
| 97 | encoder.writeEndElement(); |
| 98 | }; |
| 99 | |
| 100 | ForwardingEntry.prototype.getElementLabel = function() { return CCNProtocolDTags.ForwardingEntry; } |