blob: 48d9e5f32c5efe715c4b586fa0f52f9688f8ee75 [file] [log] [blame]
Meki Cherkaoui09c15572012-04-28 14:42:18 -07001
2
3
4var FaceInstance = function FaceInstance(
5 _Action,
6 _PublisherPublicKeyDigest,
7 _FaceID,
8 _IPProto,
9 _Host,
10 _Port,
11 _MulticastInterface,
12 _MulticastTTL,
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070013 _FreshnessSeconds){
Meki Cherkaoui09c15572012-04-28 14:42:18 -070014
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070015
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 Cherkaoui09c15572012-04-28 14:42:18 -070025
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 Cherkaouiabb973b2012-05-09 14:25:57 -070042FaceInstance.prototype.decode = function(//XMLDecoder
Meki Cherkaoui09c15572012-04-28 14:42:18 -070043 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 Cherkaouiabb973b2012-05-09 14:25:57 -0700115FaceInstance.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 Cherkaoui09c15572012-04-28 14:42:18 -0700127 }
Meki Cherkaouiabb973b2012-05-09 14:25:57 -0700128 if (null != this.FaceID) {
129 encoder.writeElement(CCNProtocolDTags.FaceID, this.FaceID);
Meki Cherkaoui09c15572012-04-28 14:42:18 -0700130 }
Meki Cherkaouiabb973b2012-05-09 14:25:57 -0700131 if (null != this.IPProto) {
132 //encoder.writeElement(CCNProtocolDTags.IPProto, this.IpProto.value());
133 encoder.writeElement(CCNProtocolDTags.IPProto, this.IPProto);
Meki Cherkaoui09c15572012-04-28 14:42:18 -0700134 }
Meki Cherkaouiabb973b2012-05-09 14:25:57 -0700135 if (null != this.Host && this.Host.length != 0) {
136 encoder.writeElement(CCNProtocolDTags.Host, this.Host);
Meki Cherkaoui09c15572012-04-28 14:42:18 -0700137 }
Meki Cherkaouiabb973b2012-05-09 14:25:57 -0700138 if (null != this.Port) {
139 encoder.writeElement(CCNProtocolDTags.Port, this.Port);
Meki Cherkaoui09c15572012-04-28 14:42:18 -0700140 }
Meki Cherkaouiabb973b2012-05-09 14:25:57 -0700141 if (null != this.MulticastInterface && this.MulticastInterface.length != 0) {
142 encoder.writeElement(CCNProtocolDTags.MulticastInterface, this.MulticastInterface);
Meki Cherkaoui09c15572012-04-28 14:42:18 -0700143 }
Meki Cherkaouiabb973b2012-05-09 14:25:57 -0700144 if (null != this.MulticastTTL) {
145 encoder.writeElement(CCNProtocolDTags.MulticastTTL, this.MulticastTTL);
Meki Cherkaoui09c15572012-04-28 14:42:18 -0700146 }
Meki Cherkaouiabb973b2012-05-09 14:25:57 -0700147 if (null != this.FreshnessSeconds) {
148 encoder.writeElement(CCNProtocolDTags.FreshnessSeconds, this.FreshnessSeconds);
Meki Cherkaoui09c15572012-04-28 14:42:18 -0700149 }
150 encoder.writeEndElement();
151}
152
153
Meki Cherkaouiabb973b2012-05-09 14:25:57 -0700154
155
Meki Cherkaoui09c15572012-04-28 14:42:18 -0700156FaceInstance.prototype.getElementLabel= function(){return CCNProtocolDTags.FaceInstance;};
157