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