blob: 6a709fefc91706651a2f598be579bdf40a4d8e47 [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,
13 _FreshnessSeconds,){
14
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,
25
26
27 //Action ::= ("newface" | "destroyface" | "queryface")
28 //PublisherPublicKeyDigest ::= SHA-256 digest
29 //FaceID ::= nonNegativeInteger
30 //IPProto ::= nonNegativeInteger [IANA protocol number, 6=TCP, 17=UDP]
31 //Host ::= textual representation of numeric IPv4 or IPv6 address
32 //Port ::= nonNegativeInteger [1..65535]
33 //MulticastInterface ::= textual representation of numeric IPv4 or IPv6 address
34 //MulticastTTL ::= nonNegativeInteger [1..255]
35 //FreshnessSeconds ::= nonNegativeInteger
36
37};
38
39/**
40 * Used by NetworkObject to decode the object from a network stream.
41 * @see org.ccnx.ccn.impl.encoding.XMLEncodable
42 */
43FaceInstance.prototype.decode(//XMLDecoder
44 decoder) {
45
46 decoder.readStartElement(this.getElementLabel());
47
48 if (decoder.peekStartElement(CCNProtocolDTags.Action)) {
49
50 this.Action = decoder.readUTF8Element(CCNProtocolDTags.Action);
51
52 }
53 if (decoder.peekStartElement(CCNProtocolDTags.PublisherPublicKeyDigest)) {
54
55 this.PublisherPublicKeyDigest = new PublisherPublicKeyDigest();
56 this.PublisherPublicKeyDigest.decode(decoder);
57
58 }
59 if (decoder.peekStartElement(CCNProtocolDTags.FaceID)) {
60
61 this.FaceID = decoder.readIntegerElement(CCNProtocolDTags.FaceID);
62
63 }
64 if (decoder.peekStartElement(CCNProtocolDTags.IPProto)) {
65
66 //int
67 var pI = decoder.readIntegerElement(CCNProtocolDTags.IPProto);
68
69 this.IPProto = null;
70
71 if (NetworkProtocol.TCP.value().intValue() == pI) {
72
73 this.IPProto = NetworkProtocol.TCP;
74
75 } else if (NetworkProtocol.UDP.value().intValue() == pI) {
76
77 this.IPProto = NetworkProtocol.UDP;
78
79 } else {
80
81 throw new Exception("FaceInstance.decoder. Invalid " +
82 CCNProtocolDTags.tagToString(CCNProtocolDTags.IPProto) + " field: " + pI);
83
84 }
85 }
86
87 if (decoder.peekStartElement(CCNProtocolDTags.Host)) {
88
89 this.Host = decoder.readUTF8Element(CCNProtocolDTags.Host);
90
91 }
92
93 if (decoder.peekStartElement(CCNProtocolDTags.Port)) {
94 this.Port = decoder.readIntegerElement(CCNProtocolDTags.Port);
95 }
96
97 if (decoder.peekStartElement(CCNProtocolDTags.MulticastInterface)) {
98 this.MulticastInterface = decoder.readUTF8Element(CCNProtocolDTags.MulticastInterface);
99 }
100
101 if (decoder.peekStartElement(CCNProtocolDTags.MulticastTTL)) {
102 this.MulticastTTL = decoder.readIntegerElement(CCNProtocolDTags.MulticastTTL);
103 }
104
105 if (decoder.peekStartElement(CCNProtocolDTags.FreshnessSeconds)) {
106 this.FreshnessSeconds = decoder.readIntegerElement(CCNProtocolDTags.FreshnessSeconds);
107 }
108
109 decoder.readEndElement();
110}
111
112/**
113 * Used by NetworkObject to encode the object to a network stream.
114 * @see org.ccnx.ccn.impl.encoding.XMLEncodable
115 */
116public void encode(XMLEncoder encoder) throws ContentEncodingException {
117 if (!validate()) {
118 throw new ContentEncodingException("Cannot encode " + this.getClass().getName() + ": field values missing.");
119 }
120 encoder.writeStartElement(getElementLabel());
121 if (null != _action && _action.length() != 0)
122 encoder.writeElement(CCNProtocolDTags.Action, _action);
123 if (null != _ccndID) {
124 _ccndID.encode(encoder);
125 }
126 if (null != _faceID) {
127 encoder.writeElement(CCNProtocolDTags.FaceID, _faceID);
128 }
129 if (null != _ipProto) {
130 encoder.writeElement(CCNProtocolDTags.IPProto, _ipProto.value());
131 }
132 if (null != _host && _host.length() != 0) {
133 encoder.writeElement(CCNProtocolDTags.Host, _host);
134 }
135 if (null != _port) {
136 encoder.writeElement(CCNProtocolDTags.Port, _port);
137 }
138 if (null != _multicastInterface && _multicastInterface.length() != 0) {
139 encoder.writeElement(CCNProtocolDTags.MulticastInterface, _multicastInterface);
140 }
141 if (null != _multicastTTL) {
142 encoder.writeElement(CCNProtocolDTags.MulticastTTL, _multicastTTL);
143 }
144 if (null != _lifetime) {
145 encoder.writeElement(CCNProtocolDTags.FreshnessSeconds, _lifetime);
146 }
147 encoder.writeEndElement();
148}
149
150
151FaceInstance.prototype.getElementLabel= function(){return CCNProtocolDTags.FaceInstance;};
152