Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 1 | /* -*- 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 Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 12 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 13 | #include <ndn-cpp/security/certificate/identity-certificate.hpp> |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 14 | #include "exception.h" |
| 15 | #include "logging.h" |
| 16 | |
| 17 | using namespace std; |
| 18 | using namespace ndn; |
| 19 | |
| 20 | INIT_LOGGER("ChronosInvitation"); |
| 21 | |
Yingdi Yu | 4694828 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 22 | ChronosInvitation::ChronosInvitation(const ndn::Name& originalInterestName) |
| 23 | : m_interestName(originalInterestName) |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 24 | { |
Yingdi Yu | 6eabbd7 | 2013-12-27 08:44:12 +0800 | [diff] [blame^] | 25 | Name interestName = originalInterestName; |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 26 | if(interestName.get(0).toEscapedString() != string("ndn") |
| 27 | || interestName.get(1).toEscapedString() != string("broadcast") |
| 28 | || interestName.get(2).toEscapedString() != string("chronos") |
| 29 | || interestName.get(3).toEscapedString() != string("invitation")) |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 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++) |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 38 | if(interestName.get(i).toEscapedString() == chatroomStr) |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 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 | |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 45 | string inviterPrefixStr("inviter-prefix"); |
| 46 | int chatroomBegin = (++i); |
| 47 | for(; i < size; i++) |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 48 | if(interestName.get(i).toEscapedString() == inviterPrefixStr) |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 49 | break; |
| 50 | |
| 51 | if(i > size) |
| 52 | throw LnException("Wrong ChronosInvitation Name, No inviter-prefix tag"); |
| 53 | m_chatroom = interestName.getSubName(chatroomBegin, i - chatroomBegin); |
| 54 | |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 55 | string inviterStr("inviter"); |
| 56 | int inviterPrefixBegin = (++i); |
| 57 | for(; i < size; i++) |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 58 | if(interestName.get(i).toEscapedString() == inviterStr) |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 59 | break; |
| 60 | |
| 61 | if(i > size) |
| 62 | throw LnException("Wrong ChronosInvitation Name, No inviter tag"); |
| 63 | m_inviterPrefix = interestName.getSubName(inviterPrefixBegin, i - inviterPrefixBegin); |
| 64 | |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 65 | int inviterCertBegin = (++i); |
| 66 | m_inviterCertificateName = interestName.getSubName(inviterCertBegin, size - 1 - inviterCertBegin); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 67 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 68 | m_signatureBits = interestName.get(-1).getValue(); |
Yingdi Yu | 9b34b1f | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 69 | |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 70 | Name keyName = IdentityCertificate::certificateNameToPublicKeyName(m_inviterCertificateName); |
| 71 | m_inviterNameSpace = keyName.getPrefix(-1); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 72 | |
| 73 | string signedName = interestName.getSubName(0, size - 1).toUri(); |
Yingdi Yu | 76dd800 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 74 | m_signedBlob = Blob((const uint8_t*)signedName.c_str(), signedName.size()); |
Yingdi Yu | 7989eb2 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | ChronosInvitation::ChronosInvitation(const ChronosInvitation& invitation) |
| 78 | : m_interestName(invitation.m_interestName) |
| 79 | , m_inviteeNameSpace(invitation.m_inviteeNameSpace) |
| 80 | , m_chatroom(invitation.m_chatroom) |
| 81 | , m_inviterPrefix(invitation.m_inviterPrefix) |
| 82 | , m_inviterCertificateName(invitation.m_inviterCertificateName) |
| 83 | , m_signatureBits(invitation.m_signatureBits) |
| 84 | , m_inviterNameSpace(invitation.m_inviterNameSpace) |
| 85 | , m_signedBlob(invitation.m_signedBlob) |
| 86 | {} |