Meki Cherkaoui | 09c1557 | 2012-04-28 14:42:18 -0700 | [diff] [blame] | 1 | |
| 2 | |
| 3 | |
| 4 | var FaceInstance = function FaceInstance( |
| 5 | _Action, |
| 6 | _PublisherPublicKeyDigest, |
| 7 | _FaceID, |
| 8 | _IPProto, |
| 9 | _Host, |
| 10 | _Port, |
| 11 | _MulticastInterface, |
| 12 | _MulticastTTL, |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 13 | _FreshnessSeconds){ |
Meki Cherkaoui | 09c1557 | 2012-04-28 14:42:18 -0700 | [diff] [blame] | 14 | |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 15 | |
| 16 | this.Action = _Action; |
| 17 | this.PublisherPublicKeyDigest = _PublisherPublicKeyDigest; |
| 18 | this.FaceID = _FaceID; |
| 19 | this.IPProto = _IPProto; |
| 20 | this.Host = _Host; |
| 21 | this.Port = _Port; |
| 22 | this.MulticastInterface =_MulticastInterface; |
| 23 | this.MulticastTTL =_MulticastTTL; |
| 24 | this.FreshnessSeconds = _FreshnessSeconds; |
Meki Cherkaoui | 09c1557 | 2012-04-28 14:42:18 -0700 | [diff] [blame] | 25 | |
| 26 | //Action ::= ("newface" | "destroyface" | "queryface") |
| 27 | //PublisherPublicKeyDigest ::= SHA-256 digest |
| 28 | //FaceID ::= nonNegativeInteger |
| 29 | //IPProto ::= nonNegativeInteger [IANA protocol number, 6=TCP, 17=UDP] |
| 30 | //Host ::= textual representation of numeric IPv4 or IPv6 address |
| 31 | //Port ::= nonNegativeInteger [1..65535] |
| 32 | //MulticastInterface ::= textual representation of numeric IPv4 or IPv6 address |
| 33 | //MulticastTTL ::= nonNegativeInteger [1..255] |
| 34 | //FreshnessSeconds ::= nonNegativeInteger |
| 35 | |
| 36 | }; |
| 37 | |
| 38 | /** |
| 39 | * Used by NetworkObject to decode the object from a network stream. |
| 40 | * @see org.ccnx.ccn.impl.encoding.XMLEncodable |
| 41 | */ |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 42 | FaceInstance.prototype.decode = function(//XMLDecoder |
Meki Cherkaoui | 09c1557 | 2012-04-28 14:42:18 -0700 | [diff] [blame] | 43 | decoder) { |
| 44 | |
| 45 | decoder.readStartElement(this.getElementLabel()); |
| 46 | |
| 47 | if (decoder.peekStartElement(CCNProtocolDTags.Action)) { |
| 48 | |
| 49 | this.Action = decoder.readUTF8Element(CCNProtocolDTags.Action); |
| 50 | |
| 51 | } |
| 52 | if (decoder.peekStartElement(CCNProtocolDTags.PublisherPublicKeyDigest)) { |
| 53 | |
| 54 | this.PublisherPublicKeyDigest = new PublisherPublicKeyDigest(); |
| 55 | this.PublisherPublicKeyDigest.decode(decoder); |
| 56 | |
| 57 | } |
| 58 | if (decoder.peekStartElement(CCNProtocolDTags.FaceID)) { |
| 59 | |
| 60 | this.FaceID = decoder.readIntegerElement(CCNProtocolDTags.FaceID); |
| 61 | |
| 62 | } |
| 63 | if (decoder.peekStartElement(CCNProtocolDTags.IPProto)) { |
| 64 | |
| 65 | //int |
| 66 | var pI = decoder.readIntegerElement(CCNProtocolDTags.IPProto); |
| 67 | |
| 68 | this.IPProto = null; |
| 69 | |
| 70 | if (NetworkProtocol.TCP.value().intValue() == pI) { |
| 71 | |
| 72 | this.IPProto = NetworkProtocol.TCP; |
| 73 | |
| 74 | } else if (NetworkProtocol.UDP.value().intValue() == pI) { |
| 75 | |
| 76 | this.IPProto = NetworkProtocol.UDP; |
| 77 | |
| 78 | } else { |
| 79 | |
| 80 | throw new Exception("FaceInstance.decoder. Invalid " + |
| 81 | CCNProtocolDTags.tagToString(CCNProtocolDTags.IPProto) + " field: " + pI); |
| 82 | |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | if (decoder.peekStartElement(CCNProtocolDTags.Host)) { |
| 87 | |
| 88 | this.Host = decoder.readUTF8Element(CCNProtocolDTags.Host); |
| 89 | |
| 90 | } |
| 91 | |
| 92 | if (decoder.peekStartElement(CCNProtocolDTags.Port)) { |
| 93 | this.Port = decoder.readIntegerElement(CCNProtocolDTags.Port); |
| 94 | } |
| 95 | |
| 96 | if (decoder.peekStartElement(CCNProtocolDTags.MulticastInterface)) { |
| 97 | this.MulticastInterface = decoder.readUTF8Element(CCNProtocolDTags.MulticastInterface); |
| 98 | } |
| 99 | |
| 100 | if (decoder.peekStartElement(CCNProtocolDTags.MulticastTTL)) { |
| 101 | this.MulticastTTL = decoder.readIntegerElement(CCNProtocolDTags.MulticastTTL); |
| 102 | } |
| 103 | |
| 104 | if (decoder.peekStartElement(CCNProtocolDTags.FreshnessSeconds)) { |
| 105 | this.FreshnessSeconds = decoder.readIntegerElement(CCNProtocolDTags.FreshnessSeconds); |
| 106 | } |
| 107 | |
| 108 | decoder.readEndElement(); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Used by NetworkObject to encode the object to a network stream. |
| 113 | * @see org.ccnx.ccn.impl.encoding.XMLEncodable |
| 114 | */ |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 115 | FaceInstance.prototype.encode = function(//XMLEncoder |
| 116 | encoder){ |
| 117 | |
| 118 | //if (!this.validate()) { |
| 119 | //throw new Exception("Cannot encode : field values missing."); |
| 120 | //throw new Exception("") |
| 121 | //} |
| 122 | encoder.writeStartElement(this.getElementLabel()); |
| 123 | if (null != this.Action && this.Action.length != 0) |
| 124 | encoder.writeElement(CCNProtocolDTags.Action, this.Action); |
| 125 | if (null != this.PublisherPublicKeyDigest) { |
| 126 | this.PublisherPublicKeyDigest.encode(encoder); |
Meki Cherkaoui | 09c1557 | 2012-04-28 14:42:18 -0700 | [diff] [blame] | 127 | } |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 128 | if (null != this.FaceID) { |
| 129 | encoder.writeElement(CCNProtocolDTags.FaceID, this.FaceID); |
Meki Cherkaoui | 09c1557 | 2012-04-28 14:42:18 -0700 | [diff] [blame] | 130 | } |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 131 | if (null != this.IPProto) { |
| 132 | //encoder.writeElement(CCNProtocolDTags.IPProto, this.IpProto.value()); |
| 133 | encoder.writeElement(CCNProtocolDTags.IPProto, this.IPProto); |
Meki Cherkaoui | 09c1557 | 2012-04-28 14:42:18 -0700 | [diff] [blame] | 134 | } |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 135 | if (null != this.Host && this.Host.length != 0) { |
| 136 | encoder.writeElement(CCNProtocolDTags.Host, this.Host); |
Meki Cherkaoui | 09c1557 | 2012-04-28 14:42:18 -0700 | [diff] [blame] | 137 | } |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 138 | if (null != this.Port) { |
| 139 | encoder.writeElement(CCNProtocolDTags.Port, this.Port); |
Meki Cherkaoui | 09c1557 | 2012-04-28 14:42:18 -0700 | [diff] [blame] | 140 | } |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 141 | if (null != this.MulticastInterface && this.MulticastInterface.length != 0) { |
| 142 | encoder.writeElement(CCNProtocolDTags.MulticastInterface, this.MulticastInterface); |
Meki Cherkaoui | 09c1557 | 2012-04-28 14:42:18 -0700 | [diff] [blame] | 143 | } |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 144 | if (null != this.MulticastTTL) { |
| 145 | encoder.writeElement(CCNProtocolDTags.MulticastTTL, this.MulticastTTL); |
Meki Cherkaoui | 09c1557 | 2012-04-28 14:42:18 -0700 | [diff] [blame] | 146 | } |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 147 | if (null != this.FreshnessSeconds) { |
| 148 | encoder.writeElement(CCNProtocolDTags.FreshnessSeconds, this.FreshnessSeconds); |
Meki Cherkaoui | 09c1557 | 2012-04-28 14:42:18 -0700 | [diff] [blame] | 149 | } |
| 150 | encoder.writeEndElement(); |
| 151 | } |
| 152 | |
| 153 | |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 154 | |
| 155 | |
Meki Cherkaoui | 09c1557 | 2012-04-28 14:42:18 -0700 | [diff] [blame] | 156 | FaceInstance.prototype.getElementLabel= function(){return CCNProtocolDTags.FaceInstance;}; |
| 157 | |