Yingdi Yu | 42f6646 | 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 | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 12 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 13 | #include <ndn-cpp/security/certificate/identity-certificate.hpp> |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 14 | #include "logging.h" |
| 15 | |
| 16 | using namespace std; |
| 17 | using namespace ndn; |
| 18 | |
| 19 | INIT_LOGGER("ChronosInvitation"); |
| 20 | |
Yingdi Yu | 4237244 | 2013-11-06 18:43:31 -0800 | [diff] [blame] | 21 | ChronosInvitation::ChronosInvitation(const ndn::Name& originalInterestName) |
| 22 | : m_interestName(originalInterestName) |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 23 | { |
Yingdi Yu | accbda9 | 2013-12-27 08:44:12 +0800 | [diff] [blame] | 24 | Name interestName = originalInterestName; |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 25 | 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 Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame^] | 29 | throw Error("Wrong ChronosInvitation Name"); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 30 | |
| 31 | int i = 4; |
| 32 | int size = interestName.size(); |
| 33 | |
| 34 | string chatroomStr("chatroom"); |
| 35 | int inviteeBegin = 4; |
| 36 | for(; i < size; i++) |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 37 | if(interestName.get(i).toEscapedString() == chatroomStr) |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 38 | break; |
| 39 | |
| 40 | if(i >= size) |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame^] | 41 | throw Error("Wrong ChronosInvitation Name, No chatroom tag"); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 42 | m_inviteeNameSpace = interestName.getSubName(inviteeBegin, i - inviteeBegin); |
| 43 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 44 | string inviterPrefixStr("inviter-prefix"); |
| 45 | int chatroomBegin = (++i); |
| 46 | for(; i < size; i++) |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 47 | if(interestName.get(i).toEscapedString() == inviterPrefixStr) |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 48 | break; |
| 49 | |
| 50 | if(i > size) |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame^] | 51 | throw Error("Wrong ChronosInvitation Name, No inviter-prefix tag"); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 52 | m_chatroom = interestName.getSubName(chatroomBegin, i - chatroomBegin); |
| 53 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 54 | string inviterStr("inviter"); |
| 55 | int inviterPrefixBegin = (++i); |
| 56 | for(; i < size; i++) |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 57 | if(interestName.get(i).toEscapedString() == inviterStr) |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 58 | break; |
| 59 | |
| 60 | if(i > size) |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame^] | 61 | throw Error("Wrong ChronosInvitation Name, No inviter tag"); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 62 | m_inviterPrefix = interestName.getSubName(inviterPrefixBegin, i - inviterPrefixBegin); |
| 63 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 64 | int inviterCertBegin = (++i); |
| 65 | m_inviterCertificateName = interestName.getSubName(inviterCertBegin, size - 1 - inviterCertBegin); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 66 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 67 | m_signatureBits = interestName.get(-1).getValue(); |
Yingdi Yu | ed8cfc4 | 2013-11-01 17:37:51 -0700 | [diff] [blame] | 68 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 69 | Name keyName = IdentityCertificate::certificateNameToPublicKeyName(m_inviterCertificateName); |
| 70 | m_inviterNameSpace = keyName.getPrefix(-1); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 71 | |
| 72 | string signedName = interestName.getSubName(0, size - 1).toUri(); |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame^] | 73 | m_signedBlob = Buffer(signedName.c_str(), signedName.size()); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | ChronosInvitation::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 | {} |