Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013, Regents of the University of California |
| 4 | * Yingdi Yu |
| 5 | * |
| 6 | * BSD license, See the LICENSE file for more information |
| 7 | * |
| 8 | * Author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 9 | */ |
| 10 | |
| 11 | #include "invitation.h" |
| 12 | |
| 13 | #include <ndn-cpp-dev/security/identity-certificate.hpp> |
| 14 | #include <ndn-cpp-dev/security/signature-sha256-with-rsa.hpp> |
| 15 | |
| 16 | #include "logging.h" |
| 17 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 18 | using namespace ndn; |
| 19 | |
| 20 | INIT_LOGGER("Invitation"); |
| 21 | |
| 22 | |
| 23 | namespace chronos{ |
| 24 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 25 | const size_t Invitation::NAME_SIZE_MIN = 7; |
| 26 | const ssize_t Invitation::SIGNATURE = -1; |
| 27 | const ssize_t Invitation::KEY_LOCATOR = -2; |
| 28 | const ssize_t Invitation::TIMESTAMP = -3; |
| 29 | const ssize_t Invitation::INVITER_CERT = -4; |
| 30 | const ssize_t Invitation::INVITER_PREFIX = -5; |
| 31 | const ssize_t Invitation::CHATROOM = -6; |
| 32 | const ssize_t Invitation::CHRONOCHAT_INVITATION = -7; |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 33 | |
| 34 | |
| 35 | Invitation::Invitation(const Name& interestName) |
| 36 | { |
| 37 | size_t nameSize = interestName.size(); |
| 38 | |
| 39 | if(nameSize < NAME_SIZE_MIN) |
| 40 | throw Error("Wrong Invitation Name: Wrong length"); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 41 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 42 | if(interestName.get(CHRONOCHAT_INVITATION).toEscapedString() != "CHRONOCHAT-INVITATION") |
| 43 | throw Error("Wrong Invitation Name: Wrong application tags"); |
| 44 | |
| 45 | m_interestName = interestName.getPrefix(KEY_LOCATOR); |
| 46 | m_timestamp = interestName.get(TIMESTAMP).toNumber(); |
| 47 | m_inviterCertificate.wireDecode(interestName.get(INVITER_CERT).blockFromValue()); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 48 | m_inviterRoutingPrefix.wireDecode(interestName.get(INVITER_PREFIX).blockFromValue()); |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 49 | m_chatroom = interestName.get(CHATROOM).toEscapedString(); |
| 50 | m_inviteeNameSpace = interestName.getPrefix(CHRONOCHAT_INVITATION); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 51 | } |
| 52 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 53 | Invitation::Invitation(const Name& inviteeNameSpace, |
Yingdi Yu | 17032f8 | 2014-03-25 15:48:23 -0700 | [diff] [blame^] | 54 | const std::string& chatroom, |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 55 | const Name& inviterRoutingPrefix, |
| 56 | const IdentityCertificate& inviterCertificate) |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 57 | : m_inviteeNameSpace(inviteeNameSpace) |
| 58 | , m_chatroom(chatroom) |
| 59 | , m_inviterRoutingPrefix(inviterRoutingPrefix) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 60 | , m_inviterCertificate(inviterCertificate) |
Yingdi Yu | a787672 | 2014-03-25 14:46:55 -0700 | [diff] [blame] | 61 | , m_timestamp(time::toUnixTimestamp(time::system_clock::now()).count()) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 62 | { |
| 63 | m_interestName = m_inviteeNameSpace; |
| 64 | m_interestName.append("CHRONOCHAT-INVITATION") |
| 65 | .append(m_chatroom) |
| 66 | .append(m_inviterRoutingPrefix.wireEncode()) |
| 67 | .append(m_inviterCertificate.wireEncode()) |
| 68 | .append(name::Component::fromNumber(m_timestamp)); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | Invitation::Invitation(const Invitation& invitation) |
| 72 | : m_interestName(invitation.m_interestName) |
| 73 | , m_inviteeNameSpace(invitation.m_inviteeNameSpace) |
| 74 | , m_chatroom(invitation.m_chatroom) |
| 75 | , m_inviterRoutingPrefix(invitation.m_inviterRoutingPrefix) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 76 | , m_inviterCertificate(invitation.m_inviterCertificate) |
| 77 | , m_timestamp(invitation.m_timestamp) |
| 78 | { |
| 79 | } |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 80 | |
| 81 | }//chronos |