Yingdi Yu | fa4ce79 | 2014-02-06 18:09:22 -0800 | [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 "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 | |
| 18 | using namespace std; |
| 19 | using namespace ndn; |
| 20 | |
| 21 | INIT_LOGGER("Invitation"); |
| 22 | |
| 23 | |
| 24 | namespace chronos{ |
| 25 | |
| 26 | const size_t Invitation::NAME_SIZE_MIN = 9; |
| 27 | const size_t Invitation::INVITEE_START = 4; |
| 28 | const ssize_t Invitation::SIGNATURE = -1; |
| 29 | const ssize_t Invitation::KEY_LOCATOR = -2; |
| 30 | const ssize_t Invitation::TIMESTAMP = -3; |
| 31 | const ssize_t Invitation::INVITER_PREFIX = -4; |
| 32 | const ssize_t Invitation::CHATROOM = -5; |
| 33 | const Name Invitation::INVITATION_PREFIX("/ndn/broadcast/chronos/chat-invitation"); |
| 34 | |
| 35 | |
| 36 | Invitation::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 | |
| 52 | Invitation::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 | |
| 63 | Invitation::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 |