blob: 7912a2d2231b08f1c33967ee10d5841d39d125e9 [file] [log] [blame]
Yingdi Yu7989eb22013-10-31 17:38:22 -07001/* -*- 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 "chronos-invitation.h"
Yingdi Yu9b34b1f2013-11-01 17:37:51 -070012
Yingdi Yu76dd8002013-12-24 11:16:32 +080013#include <ndn-cpp/security/certificate/identity-certificate.hpp>
Yingdi Yu7989eb22013-10-31 17:38:22 -070014#include "logging.h"
15
16using namespace std;
17using namespace ndn;
18
19INIT_LOGGER("ChronosInvitation");
20
Yingdi Yu46948282013-11-06 18:43:31 -080021ChronosInvitation::ChronosInvitation(const ndn::Name& originalInterestName)
22 : m_interestName(originalInterestName)
Yingdi Yu7989eb22013-10-31 17:38:22 -070023{
Yingdi Yu6eabbd72013-12-27 08:44:12 +080024 Name interestName = originalInterestName;
Yingdi Yu76dd8002013-12-24 11:16:32 +080025 if(interestName.get(0).toEscapedString() != string("ndn")
26 || interestName.get(1).toEscapedString() != string("broadcast")
27 || interestName.get(2).toEscapedString() != string("chronos")
28 || interestName.get(3).toEscapedString() != string("invitation"))
Yingdi Yuf8f572d2014-01-13 11:19:47 -080029 throw Error("Wrong ChronosInvitation Name");
Yingdi Yu7989eb22013-10-31 17:38:22 -070030
31 int i = 4;
32 int size = interestName.size();
33
34 string chatroomStr("chatroom");
35 int inviteeBegin = 4;
36 for(; i < size; i++)
Yingdi Yu76dd8002013-12-24 11:16:32 +080037 if(interestName.get(i).toEscapedString() == chatroomStr)
Yingdi Yu7989eb22013-10-31 17:38:22 -070038 break;
39
40 if(i >= size)
Yingdi Yuf8f572d2014-01-13 11:19:47 -080041 throw Error("Wrong ChronosInvitation Name, No chatroom tag");
Yingdi Yu7989eb22013-10-31 17:38:22 -070042 m_inviteeNameSpace = interestName.getSubName(inviteeBegin, i - inviteeBegin);
43
Yingdi Yu7989eb22013-10-31 17:38:22 -070044 string inviterPrefixStr("inviter-prefix");
45 int chatroomBegin = (++i);
46 for(; i < size; i++)
Yingdi Yu76dd8002013-12-24 11:16:32 +080047 if(interestName.get(i).toEscapedString() == inviterPrefixStr)
Yingdi Yu7989eb22013-10-31 17:38:22 -070048 break;
49
50 if(i > size)
Yingdi Yuf8f572d2014-01-13 11:19:47 -080051 throw Error("Wrong ChronosInvitation Name, No inviter-prefix tag");
Yingdi Yu7989eb22013-10-31 17:38:22 -070052 m_chatroom = interestName.getSubName(chatroomBegin, i - chatroomBegin);
53
Yingdi Yu7989eb22013-10-31 17:38:22 -070054 string inviterStr("inviter");
55 int inviterPrefixBegin = (++i);
56 for(; i < size; i++)
Yingdi Yu76dd8002013-12-24 11:16:32 +080057 if(interestName.get(i).toEscapedString() == inviterStr)
Yingdi Yu7989eb22013-10-31 17:38:22 -070058 break;
59
60 if(i > size)
Yingdi Yuf8f572d2014-01-13 11:19:47 -080061 throw Error("Wrong ChronosInvitation Name, No inviter tag");
Yingdi Yu7989eb22013-10-31 17:38:22 -070062 m_inviterPrefix = interestName.getSubName(inviterPrefixBegin, i - inviterPrefixBegin);
63
Yingdi Yu7989eb22013-10-31 17:38:22 -070064 int inviterCertBegin = (++i);
65 m_inviterCertificateName = interestName.getSubName(inviterCertBegin, size - 1 - inviterCertBegin);
Yingdi Yu7989eb22013-10-31 17:38:22 -070066
Yingdi Yu76dd8002013-12-24 11:16:32 +080067 m_signatureBits = interestName.get(-1).getValue();
Yingdi Yu9b34b1f2013-11-01 17:37:51 -070068
Yingdi Yu76dd8002013-12-24 11:16:32 +080069 Name keyName = IdentityCertificate::certificateNameToPublicKeyName(m_inviterCertificateName);
70 m_inviterNameSpace = keyName.getPrefix(-1);
Yingdi Yu7989eb22013-10-31 17:38:22 -070071
72 string signedName = interestName.getSubName(0, size - 1).toUri();
Yingdi Yuf8f572d2014-01-13 11:19:47 -080073 m_signedBlob = Buffer(signedName.c_str(), signedName.size());
Yingdi Yu7989eb22013-10-31 17:38:22 -070074}
75
76ChronosInvitation::ChronosInvitation(const ChronosInvitation& invitation)
77 : m_interestName(invitation.m_interestName)
78 , m_inviteeNameSpace(invitation.m_inviteeNameSpace)
79 , m_chatroom(invitation.m_chatroom)
80 , m_inviterPrefix(invitation.m_inviterPrefix)
81 , m_inviterCertificateName(invitation.m_inviterCertificateName)
82 , m_signatureBits(invitation.m_signatureBits)
83 , m_inviterNameSpace(invitation.m_inviterNameSpace)
84 , m_signedBlob(invitation.m_signedBlob)
85{}