Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 19 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 20 | */ |
| 21 | |
| 22 | #include "ccnx-content-object-header.h" |
| 23 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 24 | #include "ns3/log.h" |
Alexander Afanasyev | f9f4eb0 | 2011-12-16 01:51:14 -0800 | [diff] [blame] | 25 | #include "../helper/ccnx-encoding-helper.h" |
| 26 | #include "../helper/ccnx-decoding-helper.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 27 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 28 | #include "../helper/ccnb-parser/ccnb-parser-common.h" |
| 29 | #include "../helper/ccnb-parser/visitors/ccnb-parser-void-depth-first-visitor.h" |
| 30 | #include "../helper/ccnb-parser/visitors/ccnb-parser-name-components-visitor.h" |
| 31 | #include "../helper/ccnb-parser/visitors/ccnb-parser-non-negative-integer-visitor.h" |
| 32 | #include "../helper/ccnb-parser/visitors/ccnb-parser-timestamp-visitor.h" |
| 33 | #include "../helper/ccnb-parser/visitors/ccnb-parser-string-visitor.h" |
| 34 | #include "../helper/ccnb-parser/visitors/ccnb-parser-uint32t-blob-visitor.h" |
| 35 | #include "../helper/ccnb-parser/visitors/ccnb-parser-content-type-visitor.h" |
| 36 | |
| 37 | #include "../helper/ccnb-parser/syntax-tree/ccnb-parser-block.h" |
| 38 | #include "../helper/ccnb-parser/syntax-tree/ccnb-parser-dtag.h" |
| 39 | |
| 40 | #include <boost/foreach.hpp> |
| 41 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 42 | NS_LOG_COMPONENT_DEFINE ("CcnxContentObjectHeader"); |
| 43 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 44 | using namespace ns3::CcnbParser; |
| 45 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 46 | namespace ns3 |
| 47 | { |
| 48 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 49 | const std::string CcnxContentObjectHeader::Signature::DefaultDigestAlgorithm = "2.16.840.1.101.3.4.2.1"; |
| 50 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 51 | NS_OBJECT_ENSURE_REGISTERED (CcnxContentObjectHeader); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 52 | NS_OBJECT_ENSURE_REGISTERED (CcnxContentObjectTail); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 53 | |
| 54 | TypeId |
| 55 | CcnxContentObjectHeader::GetTypeId (void) |
| 56 | { |
| 57 | static TypeId tid = TypeId ("ns3::CcnxContentObjectHeader") |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 58 | .SetGroupName ("Ccnx") |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 59 | .SetParent<Header> () |
| 60 | .AddConstructor<CcnxContentObjectHeader> () |
| 61 | ; |
| 62 | return tid; |
| 63 | } |
| 64 | |
| 65 | CcnxContentObjectHeader::CcnxContentObjectHeader () |
| 66 | { |
| 67 | } |
| 68 | |
| 69 | void |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 70 | CcnxContentObjectHeader::SetName (const Ptr<CcnxNameComponents> &name) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 71 | { |
| 72 | m_name = name; |
| 73 | } |
| 74 | |
Ilya Moiseenko | 2bd1bc3 | 2011-08-23 16:01:35 -0700 | [diff] [blame] | 75 | const CcnxNameComponents& |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 76 | CcnxContentObjectHeader::GetName () const |
| 77 | { |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 78 | if (m_name==0) throw CcnxContentObjectHeaderException(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 79 | return *m_name; |
| 80 | } |
| 81 | |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame^] | 82 | Ptr<const CcnxNameComponents> |
| 83 | CcnxContentObjectHeader::GetNamePtr () const |
| 84 | { |
| 85 | return m_name; |
| 86 | } |
| 87 | |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 88 | #define CCNB CcnxEncodingHelper // just to simplify writing |
Alexander Afanasyev | 9568f95 | 2012-04-05 16:09:14 -0700 | [diff] [blame] | 89 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 90 | void |
| 91 | CcnxContentObjectHeader::Serialize (Buffer::Iterator start) const |
| 92 | { |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 93 | size_t written = 0; |
| 94 | written += CCNB::AppendBlockHeader (start, CCN_DTAG_ContentObject, CcnbParser::CCN_DTAG); // <ContentObject> |
| 95 | |
| 96 | // fake signature |
| 97 | written += CCNB::AppendBlockHeader (start, CCN_DTAG_Signature, CcnbParser::CCN_DTAG); // <Signature> |
| 98 | // Signature ::= √DigestAlgorithm? |
| 99 | // Witness? |
| 100 | // √SignatureBits |
| 101 | if (GetSignature ().GetDigestAlgorithm () != Signature::DefaultDigestAlgorithm) |
| 102 | { |
| 103 | written += CCNB::AppendString (start, CCN_DTAG_DigestAlgorithm, GetSignature ().GetDigestAlgorithm ()); |
| 104 | } |
| 105 | written += CCNB::AppendTaggedBlob (start, CCN_DTAG_SignatureBits, GetSignature ().GetSignatureBits ()); // <SignatureBits /> |
| 106 | written += CCNB::AppendCloser (start); // </Signature> |
| 107 | |
| 108 | written += CCNB::AppendBlockHeader (start, CCN_DTAG_Name, CCN_DTAG); // <Name> |
| 109 | written += CCNB::AppendNameComponents (start, GetName()); // <Component>...</Component>... |
| 110 | written += CCNB::AppendCloser (start); // </Name> |
| 111 | |
| 112 | // fake signature |
| 113 | written += CCNB::AppendBlockHeader (start, CCN_DTAG_SignedInfo, CCN_DTAG); // <SignedInfo> |
| 114 | // SignedInfo ::= √PublisherPublicKeyDigest |
| 115 | // √Timestamp |
| 116 | // √Type? |
| 117 | // √FreshnessSeconds? |
| 118 | // FinalBlockID? |
| 119 | // KeyLocator? |
| 120 | written += CCNB::AppendTaggedBlob (start, CCN_DTAG_PublisherPublicKeyDigest, // <PublisherPublicKeyDigest>... |
| 121 | GetSignedInfo ().GetPublisherPublicKeyDigest ()); |
| 122 | |
| 123 | written += CCNB::AppendBlockHeader (start, CCN_DTAG_Timestamp, CCN_DTAG); // <Timestamp>... |
| 124 | written += CCNB::AppendTimestampBlob (start, GetSignedInfo ().GetTimestamp ()); |
| 125 | written += CCNB::AppendCloser (start); |
| 126 | |
| 127 | if (GetSignedInfo ().GetContentType () != DATA) |
| 128 | { |
| 129 | uint8_t type[3]; |
| 130 | type[0] = (GetSignedInfo ().GetContentType () >> 16) & 0xFF; |
| 131 | type[1] = (GetSignedInfo ().GetContentType () >> 8 ) & 0xFF; |
| 132 | type[2] = (GetSignedInfo ().GetContentType () ) & 0xFF; |
| 133 | |
| 134 | written += CCNB::AppendTaggedBlob (start, CCN_DTAG_Type, type, 3); |
| 135 | } |
Alexander Afanasyev | faf9581 | 2012-06-05 21:28:11 -0700 | [diff] [blame] | 136 | if (GetSignedInfo ().GetFreshness () > Seconds(0)) |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 137 | { |
| 138 | written += CCNB::AppendBlockHeader (start, CCN_DTAG_FreshnessSeconds, CCN_DTAG); |
| 139 | written += CCNB::AppendNumber (start, GetSignedInfo ().GetFreshness ().ToInteger (Time::S)); |
| 140 | written += CCNB::AppendCloser (start); |
| 141 | } |
Alexander Afanasyev | faf9581 | 2012-06-05 21:28:11 -0700 | [diff] [blame] | 142 | if (GetSignedInfo ().GetKeyLocator () != 0) |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 143 | { |
| 144 | written += CCNB::AppendBlockHeader (start, CCN_DTAG_KeyLocator, CCN_DTAG); // <KeyLocator> |
| 145 | { |
| 146 | written += CCNB::AppendBlockHeader (start, CCN_DTAG_KeyName, CCN_DTAG); // <KeyName> |
| 147 | { |
| 148 | written += CCNB::AppendBlockHeader (start, CCN_DTAG_Name, CCN_DTAG); // <Name> |
| 149 | written += CCNB::AppendNameComponents (start, GetName()); // <Component>...</Component>... |
| 150 | written += CCNB::AppendCloser (start); // </Name> |
| 151 | } |
| 152 | written += CCNB::AppendCloser (start); // </KeyName> |
| 153 | } |
| 154 | written += CCNB::AppendCloser (start); // </KeyLocator> |
| 155 | } |
| 156 | |
| 157 | written += CCNB::AppendCloser (start); // </SignedInfo> |
| 158 | |
| 159 | written += CCNB::AppendBlockHeader (start, CCN_DTAG_Content, CCN_DTAG); // <Content> |
| 160 | |
| 161 | // there are no closing tags !!! |
| 162 | // The closing tag is handled by CcnxContentObjectTail |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | uint32_t |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 166 | CcnxContentObjectHeader::GetSerializedSize () const |
| 167 | { |
| 168 | size_t written = 0; |
| 169 | written += CCNB::EstimateBlockHeader (CCN_DTAG_ContentObject); // <ContentObject> |
| 170 | |
| 171 | // fake signature |
| 172 | written += CCNB::EstimateBlockHeader (CCN_DTAG_Signature); // <Signature> |
| 173 | // Signature ::= DigestAlgorithm? |
| 174 | // Witness? |
| 175 | // SignatureBits |
| 176 | if (GetSignature ().GetDigestAlgorithm () != Signature::DefaultDigestAlgorithm) |
| 177 | { |
| 178 | written += CCNB::EstimateString (CCN_DTAG_DigestAlgorithm, GetSignature ().GetDigestAlgorithm ()); |
| 179 | } |
| 180 | written += CCNB::EstimateTaggedBlob (CCN_DTAG_SignatureBits, |
| 181 | sizeof (GetSignature ().GetSignatureBits ())); // <SignatureBits /> |
| 182 | written += 1; // </Signature> |
| 183 | |
| 184 | written += CCNB::EstimateBlockHeader (CCN_DTAG_Name); // <Name> |
| 185 | written += CCNB::EstimateNameComponents (GetName()); // <Component>...</Component>... |
| 186 | written += 1; // </Name> |
| 187 | |
| 188 | // fake signature |
| 189 | written += CCNB::EstimateBlockHeader (CCN_DTAG_SignedInfo); // <SignedInfo> |
| 190 | // SignedInfo ::= √PublisherPublicKeyDigest |
| 191 | // √Timestamp |
| 192 | // √Type? |
| 193 | // √FreshnessSeconds? |
| 194 | // FinalBlockID? |
| 195 | // KeyLocator? |
| 196 | |
| 197 | written += CCNB::EstimateTaggedBlob (CCN_DTAG_PublisherPublicKeyDigest, // <PublisherPublicKeyDigest>... |
| 198 | sizeof (GetSignedInfo ().GetPublisherPublicKeyDigest ())); |
| 199 | |
| 200 | written += CCNB::EstimateBlockHeader (CCN_DTAG_Timestamp); // <Timestamp>... |
| 201 | written += CCNB::EstimateTimestampBlob (GetSignedInfo ().GetTimestamp ()); |
| 202 | written += 1; |
| 203 | |
| 204 | if (GetSignedInfo ().GetContentType () != DATA) |
| 205 | { |
| 206 | written += CCNB::EstimateTaggedBlob (CCN_DTAG_Type, 3); |
| 207 | } |
Alexander Afanasyev | faf9581 | 2012-06-05 21:28:11 -0700 | [diff] [blame] | 208 | if (GetSignedInfo ().GetFreshness () > Seconds(0)) |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 209 | { |
| 210 | written += CCNB::EstimateBlockHeader (CCN_DTAG_FreshnessSeconds); |
| 211 | written += CCNB::EstimateNumber (GetSignedInfo ().GetFreshness ().ToInteger (Time::S)); |
| 212 | written += 1; |
| 213 | } |
| 214 | |
Alexander Afanasyev | faf9581 | 2012-06-05 21:28:11 -0700 | [diff] [blame] | 215 | if (GetSignedInfo ().GetKeyLocator () != 0) |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 216 | { |
| 217 | written += CCNB::EstimateBlockHeader (CCN_DTAG_KeyLocator); // <KeyLocator> |
| 218 | { |
| 219 | written += CCNB::EstimateBlockHeader (CCN_DTAG_KeyName); // <KeyName> |
| 220 | { |
| 221 | written += CCNB::EstimateBlockHeader (CCN_DTAG_Name); // <Name> |
| 222 | written += CCNB::EstimateNameComponents (GetName()); // <Component>...</Component>... |
| 223 | written += 1; // </Name> |
| 224 | } |
| 225 | written += 1; // </KeyName> |
| 226 | } |
| 227 | written += 1; // </KeyLocator> |
| 228 | } |
| 229 | |
| 230 | written += 1; // </SignedInfo> |
| 231 | |
| 232 | written += CCNB::EstimateBlockHeader (CCN_DTAG_Content); // <Content> |
| 233 | |
| 234 | // there are no closing tags !!! |
| 235 | // The closing tag is handled by CcnxContentObjectTail |
| 236 | return written; |
| 237 | } |
| 238 | #undef CCNB |
| 239 | |
| 240 | class ContentObjectVisitor : public VoidDepthFirstVisitor |
| 241 | { |
| 242 | public: |
| 243 | virtual void visit (Dtag &n, boost::any param/*should be CcnxContentObjectHeader* */) |
| 244 | { |
| 245 | // uint32_t n.m_dtag; |
| 246 | // std::list<Ptr<Block> > n.m_nestedBlocks; |
| 247 | static NameComponentsVisitor nameComponentsVisitor; |
| 248 | static NonNegativeIntegerVisitor nonNegativeIntegerVisitor; |
| 249 | static TimestampVisitor timestampVisitor; |
| 250 | static StringVisitor stringVisitor; |
| 251 | static Uint32tBlobVisitor uint32tBlobVisitor; |
| 252 | static ContentTypeVisitor contentTypeVisitor; |
| 253 | |
| 254 | CcnxContentObjectHeader &contentObject = *(boost::any_cast<CcnxContentObjectHeader*> (param)); |
| 255 | |
| 256 | switch (n.m_dtag) |
| 257 | { |
| 258 | case CCN_DTAG_ContentObject: |
| 259 | // process nested blocks |
| 260 | BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags) |
| 261 | { |
| 262 | block->accept (*this, param); |
| 263 | } |
| 264 | break; |
| 265 | case CCN_DTAG_Name: |
| 266 | { |
| 267 | // process name components |
| 268 | Ptr<CcnxNameComponents> name = Create<CcnxNameComponents> (); |
| 269 | |
| 270 | BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags) |
| 271 | { |
| 272 | block->accept (nameComponentsVisitor, &(*name)); |
| 273 | } |
| 274 | contentObject.SetName (name); |
| 275 | break; |
| 276 | } |
| 277 | |
| 278 | case CCN_DTAG_Signature: |
| 279 | // process nested blocks |
| 280 | BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags) |
| 281 | { |
| 282 | block->accept (*this, param); |
| 283 | } |
| 284 | break; |
| 285 | |
| 286 | case CCN_DTAG_DigestAlgorithm: |
| 287 | NS_LOG_DEBUG ("DigestAlgorithm"); |
| 288 | if (n.m_nestedTags.size ()!=1) // should be exactly one UDATA inside this tag |
| 289 | throw CcnbDecodingException (); |
| 290 | |
| 291 | contentObject.GetSignature ().SetDigestAlgorithm |
| 292 | (boost::any_cast<std::string> ((*n.m_nestedTags.begin())->accept |
| 293 | (stringVisitor))); |
| 294 | break; |
| 295 | |
| 296 | case CCN_DTAG_SignatureBits: |
| 297 | NS_LOG_DEBUG ("SignatureBits"); |
| 298 | if (n.m_nestedTags.size ()!=1) // should be only one nested tag |
| 299 | throw CcnbDecodingException (); |
| 300 | |
| 301 | contentObject.GetSignature ().SetSignatureBits |
| 302 | (boost::any_cast<uint32_t> ((*n.m_nestedTags.begin())->accept |
| 303 | (uint32tBlobVisitor))); |
| 304 | break; |
| 305 | |
| 306 | case CCN_DTAG_SignedInfo: |
| 307 | // process nested blocks |
| 308 | BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags) |
| 309 | { |
| 310 | block->accept (*this, param); |
| 311 | } |
| 312 | break; |
| 313 | |
| 314 | case CCN_DTAG_PublisherPublicKeyDigest: |
| 315 | NS_LOG_DEBUG ("PublisherPublicKeyDigest"); |
| 316 | if (n.m_nestedTags.size ()!=1) // should be only one nested tag |
| 317 | throw CcnbDecodingException (); |
| 318 | |
| 319 | contentObject.GetSignedInfo ().SetPublisherPublicKeyDigest |
| 320 | (boost::any_cast<uint32_t> ((*n.m_nestedTags.begin())->accept |
| 321 | (uint32tBlobVisitor))); |
| 322 | break; |
| 323 | |
| 324 | case CCN_DTAG_Timestamp: |
| 325 | NS_LOG_DEBUG ("Timestamp"); |
| 326 | if (n.m_nestedTags.size()!=1) // should be exactly one nested tag |
| 327 | throw CcnbDecodingException (); |
| 328 | |
| 329 | contentObject.GetSignedInfo ().SetTimestamp |
| 330 | (boost::any_cast<Time> ((*n.m_nestedTags.begin())->accept |
| 331 | (timestampVisitor))); |
| 332 | break; |
| 333 | |
| 334 | case CCN_DTAG_Type: |
| 335 | NS_LOG_DEBUG ("Type"); |
| 336 | if (n.m_nestedTags.size ()!=1) // should be only one nested tag |
| 337 | throw CcnbDecodingException (); |
| 338 | |
| 339 | contentObject.GetSignedInfo ().SetContentType |
| 340 | (static_cast<CcnxContentObjectHeader::ContentType> |
| 341 | (boost::any_cast<uint32_t> ((*n.m_nestedTags.begin())->accept |
| 342 | (contentTypeVisitor)))); |
| 343 | break; |
| 344 | |
| 345 | case CCN_DTAG_FreshnessSeconds: |
| 346 | NS_LOG_DEBUG ("FreshnessSeconds"); |
| 347 | |
| 348 | if (n.m_nestedTags.size()!=1) // should be exactly one nested tag |
| 349 | throw CcnbDecodingException (); |
| 350 | |
| 351 | contentObject.GetSignedInfo ().SetFreshness |
| 352 | (Seconds |
| 353 | (boost::any_cast<uint32_t> ((*n.m_nestedTags.begin())->accept |
| 354 | (nonNegativeIntegerVisitor)))); |
| 355 | break; |
| 356 | |
| 357 | case CCN_DTAG_KeyLocator: |
| 358 | // process nested blocks |
| 359 | BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags) |
| 360 | { |
| 361 | block->accept (*this, param); |
| 362 | } |
| 363 | break; |
| 364 | |
| 365 | case CCN_DTAG_KeyName: |
| 366 | { |
| 367 | if (n.m_nestedTags.size ()!=1) // should be exactly one nested tag |
| 368 | throw CcnbDecodingException (); |
| 369 | |
| 370 | Ptr<BaseTag> nameTag = DynamicCast<BaseTag>(n.m_nestedTags.front ()); |
| 371 | if (nameTag == 0) |
| 372 | throw CcnbDecodingException (); |
| 373 | |
| 374 | // process name components |
| 375 | Ptr<CcnxNameComponents> name = Create<CcnxNameComponents> (); |
| 376 | |
| 377 | BOOST_FOREACH (Ptr<Block> block, nameTag->m_nestedTags) |
| 378 | { |
| 379 | block->accept (nameComponentsVisitor, &(*name)); |
| 380 | } |
| 381 | contentObject.GetSignedInfo ().SetKeyLocator (name); |
| 382 | break; |
| 383 | } |
| 384 | |
| 385 | case CCN_DTAG_Content: // !!! HACK |
| 386 | // This hack was necessary for memory optimizations (i.e., content is virtual payload) |
| 387 | NS_ASSERT_MSG (n.m_nestedTags.size() == 0, "Parser should have stopped just after processing <Content> tag"); |
| 388 | break; |
| 389 | |
| 390 | default: // ignore all other stuff |
| 391 | break; |
| 392 | } |
| 393 | } |
| 394 | }; |
| 395 | |
| 396 | uint32_t |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 397 | CcnxContentObjectHeader::Deserialize (Buffer::Iterator start) |
| 398 | { |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 399 | static ContentObjectVisitor contentObjectVisitor; |
| 400 | |
| 401 | Buffer::Iterator i = start; |
| 402 | Ptr<CcnbParser::Block> root = CcnbParser::Block::ParseBlock (i); |
| 403 | root->accept (contentObjectVisitor, this); |
| 404 | |
| 405 | return i.GetDistanceFrom (start); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | TypeId |
| 409 | CcnxContentObjectHeader::GetInstanceTypeId (void) const |
| 410 | { |
| 411 | return GetTypeId (); |
| 412 | } |
| 413 | |
| 414 | void |
| 415 | CcnxContentObjectHeader::Print (std::ostream &os) const |
| 416 | { |
Alexander Afanasyev | 7f3e49e | 2012-04-30 00:17:07 -0700 | [diff] [blame] | 417 | os << "D: " << GetName (); |
| 418 | // os << "<ContentObject><Name>" << GetName () << "</Name><Content>"; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 421 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 422 | |
| 423 | CcnxContentObjectTail::CcnxContentObjectTail () |
| 424 | { |
| 425 | } |
| 426 | |
| 427 | TypeId |
| 428 | CcnxContentObjectTail::GetTypeId (void) |
| 429 | { |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 430 | static TypeId tid = TypeId ("ns3::CcnxContentObjectTail") |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 431 | .SetParent<Trailer> () |
| 432 | .AddConstructor<CcnxContentObjectTail> () |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 433 | ; |
| 434 | return tid; |
| 435 | } |
| 436 | |
| 437 | TypeId |
| 438 | CcnxContentObjectTail::GetInstanceTypeId (void) const |
| 439 | { |
| 440 | return GetTypeId (); |
| 441 | } |
| 442 | |
| 443 | void |
| 444 | CcnxContentObjectTail::Print (std::ostream &os) const |
| 445 | { |
| 446 | os << "</Content></ContentObject>"; |
| 447 | } |
| 448 | |
| 449 | uint32_t |
| 450 | CcnxContentObjectTail::GetSerializedSize (void) const |
| 451 | { |
| 452 | return 2; |
| 453 | } |
| 454 | |
| 455 | void |
| 456 | CcnxContentObjectTail::Serialize (Buffer::Iterator start) const |
| 457 | { |
| 458 | Buffer::Iterator i = start; |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 459 | i.Prev (2); // Trailer interface requires us to go backwards |
| 460 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 461 | i.WriteU8 (0x00); // </Content> |
| 462 | i.WriteU8 (0x00); // </ContentObject> |
| 463 | } |
| 464 | |
| 465 | uint32_t |
| 466 | CcnxContentObjectTail::Deserialize (Buffer::Iterator start) |
| 467 | { |
| 468 | Buffer::Iterator i = start; |
Alexander Afanasyev | e91ab75 | 2011-08-31 19:13:40 -0700 | [diff] [blame] | 469 | i.Prev (2); // Trailer interface requires us to go backwards |
| 470 | |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 471 | uint8_t closing_tag_content = i.ReadU8 (); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 472 | NS_ASSERT_MSG (closing_tag_content==0, "Should be a closing tag </Content> (0x00)"); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 473 | |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 474 | uint8_t closing_tag_content_object = i.ReadU8 (); |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame] | 475 | NS_ASSERT_MSG (closing_tag_content_object==0, "Should be a closing tag </ContentObject> (0x00)"); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 476 | |
| 477 | return 2; |
| 478 | } |
Alexander Afanasyev | 8c5046a | 2012-06-05 16:22:14 -0700 | [diff] [blame] | 479 | |
| 480 | /////////////////////////////////////////////////////////////////////// |
| 481 | /////////////////////////////////////////////////////////////////////// |
| 482 | /////////////////////////////////////////////////////////////////////// |
| 483 | |
| 484 | CcnxContentObjectHeader::SignedInfo::SignedInfo () |
| 485 | : m_publisherPublicKeyDigest (0) |
| 486 | // , m_timestamp |
| 487 | , m_type (DATA) |
| 488 | // , m_freshness |
| 489 | // , FinalBlockID |
| 490 | // , KeyLocator |
| 491 | { |
| 492 | } |
| 493 | |
| 494 | void |
| 495 | CcnxContentObjectHeader::SignedInfo::SetPublisherPublicKeyDigest (uint32_t digest) |
| 496 | { |
| 497 | m_publisherPublicKeyDigest = digest; |
| 498 | } |
| 499 | |
| 500 | uint32_t |
| 501 | CcnxContentObjectHeader::SignedInfo::GetPublisherPublicKeyDigest () const |
| 502 | { |
| 503 | return m_publisherPublicKeyDigest; |
| 504 | } |
| 505 | |
| 506 | void |
| 507 | CcnxContentObjectHeader::SignedInfo::SetTimestamp (const Time ×tamp) |
| 508 | { |
| 509 | m_timestamp = timestamp; |
| 510 | } |
| 511 | |
| 512 | Time |
| 513 | CcnxContentObjectHeader::SignedInfo::GetTimestamp () const |
| 514 | { |
| 515 | return m_timestamp; |
| 516 | } |
| 517 | |
| 518 | void |
| 519 | CcnxContentObjectHeader::SignedInfo::SetContentType (CcnxContentObjectHeader::ContentType type) |
| 520 | { |
| 521 | m_type = type; |
| 522 | } |
| 523 | |
| 524 | CcnxContentObjectHeader::ContentType |
| 525 | CcnxContentObjectHeader::SignedInfo::GetContentType () const |
| 526 | { |
| 527 | return m_type; |
| 528 | } |
| 529 | |
| 530 | void |
| 531 | CcnxContentObjectHeader::SignedInfo::SetFreshness (const Time &freshness) |
| 532 | { |
| 533 | m_freshness = freshness; |
| 534 | } |
| 535 | |
| 536 | Time |
| 537 | CcnxContentObjectHeader::SignedInfo::GetFreshness () const |
| 538 | { |
| 539 | return m_freshness; |
| 540 | } |
| 541 | |
| 542 | void |
| 543 | CcnxContentObjectHeader::SignedInfo::SetKeyLocator (Ptr<const CcnxNameComponents> keyLocator) |
| 544 | { |
| 545 | m_keyLocator = keyLocator; |
| 546 | } |
| 547 | |
| 548 | Ptr<const CcnxNameComponents> |
| 549 | CcnxContentObjectHeader::SignedInfo::GetKeyLocator () const |
| 550 | { |
| 551 | return m_keyLocator; |
| 552 | } |
| 553 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 554 | } // namespace ns3 |