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 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 11 | #include "invitation.hpp" |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 12 | |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 13 | #include <ndn-cxx/security/signature-sha256-with-rsa.hpp> |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 14 | |
| 15 | #include "logging.h" |
| 16 | |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 17 | namespace chronos{ |
| 18 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 19 | using std::string; |
| 20 | |
| 21 | using ndn::IdentityCertificate; |
| 22 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 23 | const size_t Invitation::NAME_SIZE_MIN = 7; |
| 24 | const ssize_t Invitation::SIGNATURE = -1; |
| 25 | const ssize_t Invitation::KEY_LOCATOR = -2; |
| 26 | const ssize_t Invitation::TIMESTAMP = -3; |
| 27 | const ssize_t Invitation::INVITER_CERT = -4; |
| 28 | const ssize_t Invitation::INVITER_PREFIX = -5; |
| 29 | const ssize_t Invitation::CHATROOM = -6; |
| 30 | const ssize_t Invitation::CHRONOCHAT_INVITATION = -7; |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 31 | |
| 32 | |
| 33 | Invitation::Invitation(const Name& interestName) |
| 34 | { |
| 35 | size_t nameSize = interestName.size(); |
| 36 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 37 | if (nameSize < NAME_SIZE_MIN) |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 38 | throw Error("Wrong Invitation Name: Wrong length"); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 39 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 40 | if (interestName.get(CHRONOCHAT_INVITATION).toUri() != "CHRONOCHAT-INVITATION") |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 41 | throw Error("Wrong Invitation Name: Wrong application tags"); |
| 42 | |
| 43 | m_interestName = interestName.getPrefix(KEY_LOCATOR); |
| 44 | m_timestamp = interestName.get(TIMESTAMP).toNumber(); |
| 45 | m_inviterCertificate.wireDecode(interestName.get(INVITER_CERT).blockFromValue()); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 46 | m_inviterRoutingPrefix.wireDecode(interestName.get(INVITER_PREFIX).blockFromValue()); |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 47 | m_chatroom = interestName.get(CHATROOM).toUri(); |
Yingdi Yu | fa0b6a0 | 2014-04-30 14:26:42 -0700 | [diff] [blame] | 48 | m_inviteeNameSpace = interestName.getPrefix(CHRONOCHAT_INVITATION); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 51 | Invitation::Invitation(const Name& inviteeNameSpace, |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 52 | const string& chatroom, |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 53 | const Name& inviterRoutingPrefix, |
| 54 | const IdentityCertificate& inviterCertificate) |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 55 | : m_inviteeNameSpace(inviteeNameSpace) |
| 56 | , m_chatroom(chatroom) |
| 57 | , m_inviterRoutingPrefix(inviterRoutingPrefix) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 58 | , m_inviterCertificate(inviterCertificate) |
Yingdi Yu | a787672 | 2014-03-25 14:46:55 -0700 | [diff] [blame] | 59 | , m_timestamp(time::toUnixTimestamp(time::system_clock::now()).count()) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 60 | { |
| 61 | m_interestName = m_inviteeNameSpace; |
| 62 | m_interestName.append("CHRONOCHAT-INVITATION") |
| 63 | .append(m_chatroom) |
| 64 | .append(m_inviterRoutingPrefix.wireEncode()) |
| 65 | .append(m_inviterCertificate.wireEncode()) |
| 66 | .append(name::Component::fromNumber(m_timestamp)); |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | Invitation::Invitation(const Invitation& invitation) |
| 70 | : m_interestName(invitation.m_interestName) |
| 71 | , m_inviteeNameSpace(invitation.m_inviteeNameSpace) |
| 72 | , m_chatroom(invitation.m_chatroom) |
| 73 | , m_inviterRoutingPrefix(invitation.m_inviterRoutingPrefix) |
Yingdi Yu | 348f5ea | 2014-03-01 14:47:25 -0800 | [diff] [blame] | 74 | , m_inviterCertificate(invitation.m_inviterCertificate) |
| 75 | , m_timestamp(invitation.m_timestamp) |
| 76 | { |
| 77 | } |
Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [diff] [blame] | 78 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 79 | } // namespace chronos |