blob: cc5ba406c74c900d13cb760ad96bc3810b802b83 [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
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 Yufa4ce792014-02-06 18:09:22 -080018using namespace ndn;
19
20INIT_LOGGER("Invitation");
21
22
23namespace chronos{
24
Yingdi Yu348f5ea2014-03-01 14:47:25 -080025const size_t Invitation::NAME_SIZE_MIN = 7;
26const ssize_t Invitation::SIGNATURE = -1;
27const ssize_t Invitation::KEY_LOCATOR = -2;
28const ssize_t Invitation::TIMESTAMP = -3;
29const ssize_t Invitation::INVITER_CERT = -4;
30const ssize_t Invitation::INVITER_PREFIX = -5;
31const ssize_t Invitation::CHATROOM = -6;
32const ssize_t Invitation::CHRONOCHAT_INVITATION = -7;
Yingdi Yufa4ce792014-02-06 18:09:22 -080033
34
35Invitation::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 Yufa4ce792014-02-06 18:09:22 -080041
Yingdi Yu348f5ea2014-03-01 14:47:25 -080042 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 Yufa4ce792014-02-06 18:09:22 -080048 m_inviterRoutingPrefix.wireDecode(interestName.get(INVITER_PREFIX).blockFromValue());
Yingdi Yu348f5ea2014-03-01 14:47:25 -080049 m_chatroom = interestName.get(CHATROOM).toEscapedString();
50 m_inviteeNameSpace = interestName.getPrefix(CHRONOCHAT_INVITATION);
Yingdi Yufa4ce792014-02-06 18:09:22 -080051}
52
Yingdi Yu348f5ea2014-03-01 14:47:25 -080053Invitation::Invitation(const Name& inviteeNameSpace,
Yingdi Yu17032f82014-03-25 15:48:23 -070054 const std::string& chatroom,
Yingdi Yu348f5ea2014-03-01 14:47:25 -080055 const Name& inviterRoutingPrefix,
56 const IdentityCertificate& inviterCertificate)
Yingdi Yufa4ce792014-02-06 18:09:22 -080057 : m_inviteeNameSpace(inviteeNameSpace)
58 , m_chatroom(chatroom)
59 , m_inviterRoutingPrefix(inviterRoutingPrefix)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080060 , m_inviterCertificate(inviterCertificate)
Yingdi Yua7876722014-03-25 14:46:55 -070061 , m_timestamp(time::toUnixTimestamp(time::system_clock::now()).count())
Yingdi Yu348f5ea2014-03-01 14:47:25 -080062{
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 Yufa4ce792014-02-06 18:09:22 -080069}
70
71Invitation::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 Yu348f5ea2014-03-01 14:47:25 -080076 , m_inviterCertificate(invitation.m_inviterCertificate)
77 , m_timestamp(invitation.m_timestamp)
78{
79}
Yingdi Yufa4ce792014-02-06 18:09:22 -080080
81}//chronos