blob: 8ca4b061d67fb7ac6ea1bf42352f682a0d093ae1 [file] [log] [blame]
Yingdi Yufa4ce792014-02-06 18:09:22 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
Varun Patila24bd3e2020-11-24 10:08:33 +05303 * Copyright (c) 2020, Regents of the University of California
Yingdi Yufa4ce792014-02-06 18:09:22 -08004 * 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 Yueb692ac2015-02-10 18:46:18 -080013namespace chronochat {
Yingdi Yufa4ce792014-02-06 18:09:22 -080014
Yingdi Yu0b0a7362014-08-05 16:31:30 -070015using std::string;
Varun Patil3d850902020-11-23 12:19:14 +053016using ndn::security::Certificate;
Yingdi Yu0b0a7362014-08-05 16:31:30 -070017
Yingdi Yu348f5ea2014-03-01 14:47:25 -080018const size_t Invitation::NAME_SIZE_MIN = 7;
19const ssize_t Invitation::SIGNATURE = -1;
20const ssize_t Invitation::KEY_LOCATOR = -2;
21const ssize_t Invitation::TIMESTAMP = -3;
22const ssize_t Invitation::INVITER_CERT = -4;
23const ssize_t Invitation::INVITER_PREFIX = -5;
24const ssize_t Invitation::CHATROOM = -6;
25const ssize_t Invitation::CHRONOCHAT_INVITATION = -7;
Yingdi Yufa4ce792014-02-06 18:09:22 -080026
27
28Invitation::Invitation(const Name& interestName)
29{
30 size_t nameSize = interestName.size();
31
Yingdi Yu0b0a7362014-08-05 16:31:30 -070032 if (nameSize < NAME_SIZE_MIN)
Varun Patila24bd3e2020-11-24 10:08:33 +053033 NDN_THROW(Error("Wrong Invitation Name: Wrong length"));
Yingdi Yufa4ce792014-02-06 18:09:22 -080034
Yingdi Yu0b0a7362014-08-05 16:31:30 -070035 if (interestName.get(CHRONOCHAT_INVITATION).toUri() != "CHRONOCHAT-INVITATION")
Varun Patila24bd3e2020-11-24 10:08:33 +053036 NDN_THROW(Error("Wrong Invitation Name: Wrong application tags"));
Yingdi Yu348f5ea2014-03-01 14:47:25 -080037
38 m_interestName = interestName.getPrefix(KEY_LOCATOR);
39 m_timestamp = interestName.get(TIMESTAMP).toNumber();
40 m_inviterCertificate.wireDecode(interestName.get(INVITER_CERT).blockFromValue());
Yingdi Yufa4ce792014-02-06 18:09:22 -080041 m_inviterRoutingPrefix.wireDecode(interestName.get(INVITER_PREFIX).blockFromValue());
Yingdi Yu0b0a7362014-08-05 16:31:30 -070042 m_chatroom = interestName.get(CHATROOM).toUri();
Yingdi Yufa0b6a02014-04-30 14:26:42 -070043 m_inviteeNameSpace = interestName.getPrefix(CHRONOCHAT_INVITATION);
Yingdi Yufa4ce792014-02-06 18:09:22 -080044}
45
Yingdi Yu348f5ea2014-03-01 14:47:25 -080046Invitation::Invitation(const Name& inviteeNameSpace,
Yingdi Yu0b0a7362014-08-05 16:31:30 -070047 const string& chatroom,
Yingdi Yu348f5ea2014-03-01 14:47:25 -080048 const Name& inviterRoutingPrefix,
Varun Patil3d850902020-11-23 12:19:14 +053049 const Certificate& inviterCertificate)
Yingdi Yufa4ce792014-02-06 18:09:22 -080050 : m_inviteeNameSpace(inviteeNameSpace)
51 , m_chatroom(chatroom)
52 , m_inviterRoutingPrefix(inviterRoutingPrefix)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080053 , m_inviterCertificate(inviterCertificate)
Yingdi Yua7876722014-03-25 14:46:55 -070054 , m_timestamp(time::toUnixTimestamp(time::system_clock::now()).count())
Yingdi Yu348f5ea2014-03-01 14:47:25 -080055{
56 m_interestName = m_inviteeNameSpace;
57 m_interestName.append("CHRONOCHAT-INVITATION")
58 .append(m_chatroom)
59 .append(m_inviterRoutingPrefix.wireEncode())
60 .append(m_inviterCertificate.wireEncode())
61 .append(name::Component::fromNumber(m_timestamp));
Yingdi Yufa4ce792014-02-06 18:09:22 -080062}
63
64Invitation::Invitation(const Invitation& invitation)
65 : m_interestName(invitation.m_interestName)
66 , m_inviteeNameSpace(invitation.m_inviteeNameSpace)
67 , m_chatroom(invitation.m_chatroom)
68 , m_inviterRoutingPrefix(invitation.m_inviterRoutingPrefix)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080069 , m_inviterCertificate(invitation.m_inviterCertificate)
70 , m_timestamp(invitation.m_timestamp)
71{
72}
Yingdi Yufa4ce792014-02-06 18:09:22 -080073
Yingdi Yueb692ac2015-02-10 18:46:18 -080074} // namespace chronochat