blob: 5a392a1cdc8f826b4cd97439c41b78d2912aab88 [file] [log] [blame]
Yingdi Yu42f66462013-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 Yued8cfc42013-11-01 17:37:51 -070012
13#include <ndn.cxx/security/certificate/identity-certificate.h>
Yingdi Yu42f66462013-10-31 17:38:22 -070014#include "exception.h"
15#include "logging.h"
16
17using namespace std;
18using namespace ndn;
19
20INIT_LOGGER("ChronosInvitation");
21
Yingdi Yu42372442013-11-06 18:43:31 -080022ChronosInvitation::ChronosInvitation(const ndn::Name& originalInterestName)
23 : m_interestName(originalInterestName)
Yingdi Yu42f66462013-10-31 17:38:22 -070024{
Yingdi Yu42372442013-11-06 18:43:31 -080025 Name interestName = originalInterestName.getPrefix(originalInterestName.size()-1);
Yingdi Yu42f66462013-10-31 17:38:22 -070026 if(interestName.get(0).toUri() != string("ndn")
27 || interestName.get(1).toUri() != string("broadcast")
28 || interestName.get(2).toUri() != string("chronos")
29 || interestName.get(3).toUri() != string("invitation"))
30 throw LnException("Wrong ChronosInvitation Name");
31
32 int i = 4;
33 int size = interestName.size();
34
35 string chatroomStr("chatroom");
36 int inviteeBegin = 4;
37 for(; i < size; i++)
38 if(interestName.get(i).toUri() == chatroomStr)
39 break;
40
41 if(i >= size)
42 throw LnException("Wrong ChronosInvitation Name, No chatroom tag");
43 m_inviteeNameSpace = interestName.getSubName(inviteeBegin, i - inviteeBegin);
44
45 _LOG_DEBUG(m_inviteeNameSpace.toUri());
46
47 string inviterPrefixStr("inviter-prefix");
48 int chatroomBegin = (++i);
49 for(; i < size; i++)
50 if(interestName.get(i).toUri() == inviterPrefixStr)
51 break;
52
53 if(i > size)
54 throw LnException("Wrong ChronosInvitation Name, No inviter-prefix tag");
55 m_chatroom = interestName.getSubName(chatroomBegin, i - chatroomBegin);
56
57 _LOG_DEBUG(m_chatroom.toUri());
58
59 string inviterStr("inviter");
60 int inviterPrefixBegin = (++i);
61 for(; i < size; i++)
62 if(interestName.get(i).toUri() == inviterStr)
63 break;
64
65 if(i > size)
66 throw LnException("Wrong ChronosInvitation Name, No inviter tag");
67 m_inviterPrefix = interestName.getSubName(inviterPrefixBegin, i - inviterPrefixBegin);
68
69 _LOG_DEBUG(m_inviterPrefix.toUri());
70
71 int inviterCertBegin = (++i);
72 m_inviterCertificateName = interestName.getSubName(inviterCertBegin, size - 1 - inviterCertBegin);
73
74 _LOG_DEBUG(m_inviterCertificateName.toUri());
75
76 string signature = interestName.get(-1).toBlob();
77 m_signatureBits.insert(m_signatureBits.end(), signature.begin(), signature.end());
Yingdi Yued8cfc42013-11-01 17:37:51 -070078
79 Name keyName = security::IdentityCertificate::certificateNameToPublicKeyName(m_inviterCertificateName, true);
80 m_inviterNameSpace = keyName.getPrefix(keyName.size()-1);
Yingdi Yu42f66462013-10-31 17:38:22 -070081
82 string signedName = interestName.getSubName(0, size - 1).toUri();
83 m_signedBlob.insert(m_signedBlob.end(), signedName.begin(), signedName.end());
84}
85
86ChronosInvitation::ChronosInvitation(const ChronosInvitation& invitation)
87 : m_interestName(invitation.m_interestName)
88 , m_inviteeNameSpace(invitation.m_inviteeNameSpace)
89 , m_chatroom(invitation.m_chatroom)
90 , m_inviterPrefix(invitation.m_inviterPrefix)
91 , m_inviterCertificateName(invitation.m_inviterCertificateName)
92 , m_signatureBits(invitation.m_signatureBits)
93 , m_inviterNameSpace(invitation.m_inviterNameSpace)
94 , m_signedBlob(invitation.m_signedBlob)
95{}