blob: 97b3855528da399fec7cf83c17dc198b1590ba72 [file] [log] [blame]
Yingdi Yufa4ce792014-02-06 18:09:22 -08001/* -*- 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 Yu0b0a7362014-08-05 16:31:30 -070011#include "invitation.hpp"
Yingdi Yufa4ce792014-02-06 18:09:22 -080012
Yingdi Yufa0b6a02014-04-30 14:26:42 -070013#include <ndn-cxx/security/signature-sha256-with-rsa.hpp>
Yingdi Yufa4ce792014-02-06 18:09:22 -080014
15#include "logging.h"
16
Yingdi Yufa4ce792014-02-06 18:09:22 -080017namespace chronos{
18
Yingdi Yu0b0a7362014-08-05 16:31:30 -070019using std::string;
20
21using ndn::IdentityCertificate;
22
Yingdi Yu348f5ea2014-03-01 14:47:25 -080023const size_t Invitation::NAME_SIZE_MIN = 7;
24const ssize_t Invitation::SIGNATURE = -1;
25const ssize_t Invitation::KEY_LOCATOR = -2;
26const ssize_t Invitation::TIMESTAMP = -3;
27const ssize_t Invitation::INVITER_CERT = -4;
28const ssize_t Invitation::INVITER_PREFIX = -5;
29const ssize_t Invitation::CHATROOM = -6;
30const ssize_t Invitation::CHRONOCHAT_INVITATION = -7;
Yingdi Yufa4ce792014-02-06 18:09:22 -080031
32
33Invitation::Invitation(const Name& interestName)
34{
35 size_t nameSize = interestName.size();
36
Yingdi Yu0b0a7362014-08-05 16:31:30 -070037 if (nameSize < NAME_SIZE_MIN)
Yingdi Yufa0b6a02014-04-30 14:26:42 -070038 throw Error("Wrong Invitation Name: Wrong length");
Yingdi Yufa4ce792014-02-06 18:09:22 -080039
Yingdi Yu0b0a7362014-08-05 16:31:30 -070040 if (interestName.get(CHRONOCHAT_INVITATION).toUri() != "CHRONOCHAT-INVITATION")
Yingdi Yu348f5ea2014-03-01 14:47:25 -080041 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 Yufa4ce792014-02-06 18:09:22 -080046 m_inviterRoutingPrefix.wireDecode(interestName.get(INVITER_PREFIX).blockFromValue());
Yingdi Yu0b0a7362014-08-05 16:31:30 -070047 m_chatroom = interestName.get(CHATROOM).toUri();
Yingdi Yufa0b6a02014-04-30 14:26:42 -070048 m_inviteeNameSpace = interestName.getPrefix(CHRONOCHAT_INVITATION);
Yingdi Yufa4ce792014-02-06 18:09:22 -080049}
50
Yingdi Yu348f5ea2014-03-01 14:47:25 -080051Invitation::Invitation(const Name& inviteeNameSpace,
Yingdi Yu0b0a7362014-08-05 16:31:30 -070052 const string& chatroom,
Yingdi Yu348f5ea2014-03-01 14:47:25 -080053 const Name& inviterRoutingPrefix,
54 const IdentityCertificate& inviterCertificate)
Yingdi Yufa4ce792014-02-06 18:09:22 -080055 : m_inviteeNameSpace(inviteeNameSpace)
56 , m_chatroom(chatroom)
57 , m_inviterRoutingPrefix(inviterRoutingPrefix)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080058 , m_inviterCertificate(inviterCertificate)
Yingdi Yua7876722014-03-25 14:46:55 -070059 , m_timestamp(time::toUnixTimestamp(time::system_clock::now()).count())
Yingdi Yu348f5ea2014-03-01 14:47:25 -080060{
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 Yufa4ce792014-02-06 18:09:22 -080067}
68
69Invitation::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 Yu348f5ea2014-03-01 14:47:25 -080074 , m_inviterCertificate(invitation.m_inviterCertificate)
75 , m_timestamp(invitation.m_timestamp)
76{
77}
Yingdi Yufa4ce792014-02-06 18:09:22 -080078
Yingdi Yu0b0a7362014-08-05 16:31:30 -070079} // namespace chronos