blob: 9af3c4dc86a694d7d84b89ac12c6f3c2847ec33d [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 Yufa0b6a02014-04-30 14:26:42 -070013#include <ndn-cxx/security/signature-sha256-with-rsa.hpp>
Yingdi Yufa4ce792014-02-06 18:09:22 -080014
Yingdi Yueb692ac2015-02-10 18:46:18 -080015namespace chronochat {
Yingdi Yufa4ce792014-02-06 18:09:22 -080016
Yingdi Yu0b0a7362014-08-05 16:31:30 -070017using std::string;
18
Varun Patil3d850902020-11-23 12:19:14 +053019using ndn::security::Certificate;
Yingdi Yu0b0a7362014-08-05 16:31:30 -070020
Yingdi Yu348f5ea2014-03-01 14:47:25 -080021const size_t Invitation::NAME_SIZE_MIN = 7;
22const ssize_t Invitation::SIGNATURE = -1;
23const ssize_t Invitation::KEY_LOCATOR = -2;
24const ssize_t Invitation::TIMESTAMP = -3;
25const ssize_t Invitation::INVITER_CERT = -4;
26const ssize_t Invitation::INVITER_PREFIX = -5;
27const ssize_t Invitation::CHATROOM = -6;
28const ssize_t Invitation::CHRONOCHAT_INVITATION = -7;
Yingdi Yufa4ce792014-02-06 18:09:22 -080029
30
31Invitation::Invitation(const Name& interestName)
32{
33 size_t nameSize = interestName.size();
34
Yingdi Yu0b0a7362014-08-05 16:31:30 -070035 if (nameSize < NAME_SIZE_MIN)
Varun Patila24bd3e2020-11-24 10:08:33 +053036 NDN_THROW(Error("Wrong Invitation Name: Wrong length"));
Yingdi Yufa4ce792014-02-06 18:09:22 -080037
Yingdi Yu0b0a7362014-08-05 16:31:30 -070038 if (interestName.get(CHRONOCHAT_INVITATION).toUri() != "CHRONOCHAT-INVITATION")
Varun Patila24bd3e2020-11-24 10:08:33 +053039 NDN_THROW(Error("Wrong Invitation Name: Wrong application tags"));
Yingdi Yu348f5ea2014-03-01 14:47:25 -080040
41 m_interestName = interestName.getPrefix(KEY_LOCATOR);
42 m_timestamp = interestName.get(TIMESTAMP).toNumber();
43 m_inviterCertificate.wireDecode(interestName.get(INVITER_CERT).blockFromValue());
Yingdi Yufa4ce792014-02-06 18:09:22 -080044 m_inviterRoutingPrefix.wireDecode(interestName.get(INVITER_PREFIX).blockFromValue());
Yingdi Yu0b0a7362014-08-05 16:31:30 -070045 m_chatroom = interestName.get(CHATROOM).toUri();
Yingdi Yufa0b6a02014-04-30 14:26:42 -070046 m_inviteeNameSpace = interestName.getPrefix(CHRONOCHAT_INVITATION);
Yingdi Yufa4ce792014-02-06 18:09:22 -080047}
48
Yingdi Yu348f5ea2014-03-01 14:47:25 -080049Invitation::Invitation(const Name& inviteeNameSpace,
Yingdi Yu0b0a7362014-08-05 16:31:30 -070050 const string& chatroom,
Yingdi Yu348f5ea2014-03-01 14:47:25 -080051 const Name& inviterRoutingPrefix,
Varun Patil3d850902020-11-23 12:19:14 +053052 const Certificate& inviterCertificate)
Yingdi Yufa4ce792014-02-06 18:09:22 -080053 : m_inviteeNameSpace(inviteeNameSpace)
54 , m_chatroom(chatroom)
55 , m_inviterRoutingPrefix(inviterRoutingPrefix)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080056 , m_inviterCertificate(inviterCertificate)
Yingdi Yua7876722014-03-25 14:46:55 -070057 , m_timestamp(time::toUnixTimestamp(time::system_clock::now()).count())
Yingdi Yu348f5ea2014-03-01 14:47:25 -080058{
59 m_interestName = m_inviteeNameSpace;
60 m_interestName.append("CHRONOCHAT-INVITATION")
61 .append(m_chatroom)
62 .append(m_inviterRoutingPrefix.wireEncode())
63 .append(m_inviterCertificate.wireEncode())
64 .append(name::Component::fromNumber(m_timestamp));
Yingdi Yufa4ce792014-02-06 18:09:22 -080065}
66
67Invitation::Invitation(const Invitation& invitation)
68 : m_interestName(invitation.m_interestName)
69 , m_inviteeNameSpace(invitation.m_inviteeNameSpace)
70 , m_chatroom(invitation.m_chatroom)
71 , m_inviterRoutingPrefix(invitation.m_inviterRoutingPrefix)
Yingdi Yu348f5ea2014-03-01 14:47:25 -080072 , m_inviterCertificate(invitation.m_inviterCertificate)
73 , m_timestamp(invitation.m_timestamp)
74{
75}
Yingdi Yufa4ce792014-02-06 18:09:22 -080076
Yingdi Yueb692ac2015-02-10 18:46:18 -080077} // namespace chronochat