blob: 9495cec1154784191f10f71d7b0fccb235dde2e4 [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
26const size_t Invitation::NAME_SIZE_MIN = 9;
27const size_t Invitation::INVITEE_START = 4;
28const ssize_t Invitation::SIGNATURE = -1;
29const ssize_t Invitation::KEY_LOCATOR = -2;
30const ssize_t Invitation::TIMESTAMP = -3;
31const ssize_t Invitation::INVITER_PREFIX = -4;
32const ssize_t Invitation::CHATROOM = -5;
33const Name Invitation::INVITATION_PREFIX("/ndn/broadcast/chronos/chat-invitation");
34
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");
42
43 if(!INVITATION_PREFIX.isPrefixOf(interestName))
44 throw Error("Wrong Invitation Name: Wrong invitation prefix");
45
46 m_interestName = interestName.getPrefix(-3);
47 m_inviterRoutingPrefix.wireDecode(interestName.get(INVITER_PREFIX).blockFromValue());
48 m_chatroom.wireDecode(interestName.get(CHATROOM).blockFromValue());
49 m_inviteeNameSpace = interestName.getSubName(INVITEE_START, nameSize - NAME_SIZE_MIN);
50}
51
52Invitation::Invitation(const Name &inviteeNameSpace,
53 const Name &chatroom,
54 const Name &inviterRoutingPrefix)
55 : m_inviteeNameSpace(inviteeNameSpace)
56 , m_chatroom(chatroom)
57 , m_inviterRoutingPrefix(inviterRoutingPrefix)
58{
59 m_interestName = INVITATION_PREFIX;
60 m_interestName.append(inviteeNameSpace).append(chatroom.wireEncode()).append(inviterRoutingPrefix.wireEncode());
61}
62
63Invitation::Invitation(const Invitation& invitation)
64 : m_interestName(invitation.m_interestName)
65 , m_inviteeNameSpace(invitation.m_inviteeNameSpace)
66 , m_chatroom(invitation.m_chatroom)
67 , m_inviterRoutingPrefix(invitation.m_inviterRoutingPrefix)
68{}
69
70}//chronos