blob: 851010ba4fed8e356ab09977ac2b1fbca07776e5 [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
18using namespace std;
19using namespace ndn;
20
21INIT_LOGGER("Invitation");
22
23
24namespace chronos{
25
Yingdi Yu348f5ea2014-03-01 14:47:25 -080026const size_t Invitation::NAME_SIZE_MIN = 7;
27const ssize_t Invitation::SIGNATURE = -1;
28const ssize_t Invitation::KEY_LOCATOR = -2;
29const ssize_t Invitation::TIMESTAMP = -3;
30const ssize_t Invitation::INVITER_CERT = -4;
31const ssize_t Invitation::INVITER_PREFIX = -5;
32const ssize_t Invitation::CHATROOM = -6;
33const ssize_t Invitation::CHRONOCHAT_INVITATION = -7;
Yingdi Yufa4ce792014-02-06 18:09:22 -080034
35
36Invitation::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 Yufa4ce792014-02-06 18:09:22 -080042
Yingdi Yu348f5ea2014-03-01 14:47:25 -080043 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 Yufa4ce792014-02-06 18:09:22 -080049 m_inviterRoutingPrefix.wireDecode(interestName.get(INVITER_PREFIX).blockFromValue());
Yingdi Yu348f5ea2014-03-01 14:47:25 -080050 m_chatroom = interestName.get(CHATROOM).toEscapedString();
51 m_inviteeNameSpace = interestName.getPrefix(CHRONOCHAT_INVITATION);
Yingdi Yufa4ce792014-02-06 18:09:22 -080052}
53
Yingdi Yu348f5ea2014-03-01 14:47:25 -080054Invitation::Invitation(const Name& inviteeNameSpace,
55 const string& chatroom,
56 const Name& inviterRoutingPrefix,
57 const IdentityCertificate& inviterCertificate)
Yingdi Yufa4ce792014-02-06 18:09:22 -080058 : m_inviteeNameSpace(inviteeNameSpace)
59 , m_chatroom(chatroom)
60 , m_inviterRoutingPrefix(inviterRoutingPrefix)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080061 , m_inviterCertificate(inviterCertificate)
Yingdi Yua7876722014-03-25 14:46:55 -070062 , m_timestamp(time::toUnixTimestamp(time::system_clock::now()).count())
Yingdi Yu348f5ea2014-03-01 14:47:25 -080063{
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 Yufa4ce792014-02-06 18:09:22 -080070}
71
72Invitation::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 Yu348f5ea2014-03-01 14:47:25 -080077 , m_inviterCertificate(invitation.m_inviterCertificate)
78 , m_timestamp(invitation.m_timestamp)
79{
80}
Yingdi Yufa4ce792014-02-06 18:09:22 -080081
82}//chronos