blob: cc5ba406c74c900d13cb760ad96bc3810b802b83 [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2013, Regents of the University of California
* Yingdi Yu
*
* BSD license, See the LICENSE file for more information
*
* Author: Yingdi Yu <yingdi@cs.ucla.edu>
*/
#include "invitation.h"
#include <ndn-cpp-dev/security/identity-certificate.hpp>
#include <ndn-cpp-dev/security/signature-sha256-with-rsa.hpp>
#include "logging.h"
using namespace ndn;
INIT_LOGGER("Invitation");
namespace chronos{
const size_t Invitation::NAME_SIZE_MIN = 7;
const ssize_t Invitation::SIGNATURE = -1;
const ssize_t Invitation::KEY_LOCATOR = -2;
const ssize_t Invitation::TIMESTAMP = -3;
const ssize_t Invitation::INVITER_CERT = -4;
const ssize_t Invitation::INVITER_PREFIX = -5;
const ssize_t Invitation::CHATROOM = -6;
const ssize_t Invitation::CHRONOCHAT_INVITATION = -7;
Invitation::Invitation(const Name& interestName)
{
size_t nameSize = interestName.size();
if(nameSize < NAME_SIZE_MIN)
throw Error("Wrong Invitation Name: Wrong length");
if(interestName.get(CHRONOCHAT_INVITATION).toEscapedString() != "CHRONOCHAT-INVITATION")
throw Error("Wrong Invitation Name: Wrong application tags");
m_interestName = interestName.getPrefix(KEY_LOCATOR);
m_timestamp = interestName.get(TIMESTAMP).toNumber();
m_inviterCertificate.wireDecode(interestName.get(INVITER_CERT).blockFromValue());
m_inviterRoutingPrefix.wireDecode(interestName.get(INVITER_PREFIX).blockFromValue());
m_chatroom = interestName.get(CHATROOM).toEscapedString();
m_inviteeNameSpace = interestName.getPrefix(CHRONOCHAT_INVITATION);
}
Invitation::Invitation(const Name& inviteeNameSpace,
const std::string& chatroom,
const Name& inviterRoutingPrefix,
const IdentityCertificate& inviterCertificate)
: m_inviteeNameSpace(inviteeNameSpace)
, m_chatroom(chatroom)
, m_inviterRoutingPrefix(inviterRoutingPrefix)
, m_inviterCertificate(inviterCertificate)
, m_timestamp(time::toUnixTimestamp(time::system_clock::now()).count())
{
m_interestName = m_inviteeNameSpace;
m_interestName.append("CHRONOCHAT-INVITATION")
.append(m_chatroom)
.append(m_inviterRoutingPrefix.wireEncode())
.append(m_inviterCertificate.wireEncode())
.append(name::Component::fromNumber(m_timestamp));
}
Invitation::Invitation(const Invitation& invitation)
: m_interestName(invitation.m_interestName)
, m_inviteeNameSpace(invitation.m_inviteeNameSpace)
, m_chatroom(invitation.m_chatroom)
, m_inviterRoutingPrefix(invitation.m_inviterRoutingPrefix)
, m_inviterCertificate(invitation.m_inviterCertificate)
, m_timestamp(invitation.m_timestamp)
{
}
}//chronos