Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * @author: ucla-cs |
| 3 | * This class represents Forwarding Entries |
| 4 | */ |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 5 | |
| 6 | var ForwardingEntry = function ForwardingEntry( |
| 7 | //ActionType |
| 8 | _action, |
Jeff Thompson | f3bd359 | 2012-09-29 23:25:30 -0700 | [diff] [blame] | 9 | //Name |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 10 | _prefixName, |
| 11 | //PublisherPublicKeyDigest |
| 12 | _ccndId, |
| 13 | //Integer |
| 14 | _faceID, |
| 15 | //Integer |
| 16 | _flags, |
| 17 | //Integer |
| 18 | _lifetime){ |
| 19 | |
| 20 | |
| 21 | |
| 22 | //String |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 23 | this.action = _action; |
Jeff Thompson | f3bd359 | 2012-09-29 23:25:30 -0700 | [diff] [blame] | 24 | //Name\ |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 25 | this.prefixName = _prefixName; |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 26 | //PublisherPublicKeyDigest |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 27 | this.ccndID = _ccndId; |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 28 | //Integer |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 29 | this.faceID = _faceID; |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 30 | //Integer |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 31 | this.flags = _flags; |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 32 | //Integer |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 33 | this.lifetime = _lifetime; // in seconds |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 34 | |
| 35 | }; |
| 36 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 37 | ForwardingEntry.prototype.from_ccnb =function( |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 38 | //XMLDecoder |
| 39 | decoder) |
| 40 | //throws ContentDecodingException |
| 41 | { |
| 42 | decoder.readStartElement(this.getElementLabel()); |
| 43 | if (decoder.peekStartElement(CCNProtocolDTags.Action)) { |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 44 | this.action = decoder.readUTF8Element(CCNProtocolDTags.Action); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 45 | } |
| 46 | if (decoder.peekStartElement(CCNProtocolDTags.Name)) { |
Jeff Thompson | f3bd359 | 2012-09-29 23:25:30 -0700 | [diff] [blame] | 47 | this.prefixName = new Name(); |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 48 | this.prefixName.from_ccnb(decoder) ; |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 49 | } |
| 50 | if (decoder.peekStartElement(CCNProtocolDTags.PublisherPublicKeyDigest)) { |
| 51 | this.CcndId = new PublisherPublicKeyDigest(); |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 52 | this.CcndId.from_ccnb(decoder); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 53 | } |
| 54 | if (decoder.peekStartElement(CCNProtocolDTags.FaceID)) { |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 55 | this.faceID = decoder.readIntegerElement(CCNProtocolDTags.FaceID); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 56 | } |
| 57 | if (decoder.peekStartElement(CCNProtocolDTags.ForwardingFlags)) { |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 58 | this.flags = decoder.readIntegerElement(CCNProtocolDTags.ForwardingFlags); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 59 | } |
| 60 | if (decoder.peekStartElement(CCNProtocolDTags.FreshnessSeconds)) { |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 61 | this.lifetime = decoder.readIntegerElement(CCNProtocolDTags.FreshnessSeconds); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 62 | } |
| 63 | decoder.readEndElement(); |
| 64 | }; |
| 65 | |
| 66 | /** |
| 67 | * Used by NetworkObject to encode the object to a network stream. |
| 68 | * @see org.ccnx.ccn.impl.encoding.XMLEncodable |
| 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; } |