Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -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 | |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 11 | #ifndef CHRONOS_CONTACT_ITEM_H |
| 12 | #define CHRONOS_CONTACT_ITEM_H |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 13 | |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 14 | #include "endorse-certificate.h" |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 15 | #include <ndn-cpp-dev/util/regex.hpp> |
| 16 | #include <vector> |
| 17 | |
| 18 | |
| 19 | namespace chronos{ |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 20 | |
| 21 | class ContactItem |
| 22 | { |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 23 | public: |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 24 | typedef std::map<ndn::Name, ndn::shared_ptr<ndn::Regex> >::const_iterator const_iterator; |
| 25 | typedef std::map<ndn::Name, ndn::shared_ptr<ndn::Regex> >::iterator iterator; |
| 26 | |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 27 | ContactItem(const EndorseCertificate& selfEndorseCertificate, |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 28 | bool isIntroducer = false, |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 29 | const std::string& alias = ""); |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 30 | |
| 31 | ContactItem(const ContactItem& contactItem); |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 32 | |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 33 | virtual |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 34 | ~ContactItem() {} |
| 35 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 36 | const EndorseCertificate& |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 37 | getSelfEndorseCertificate() const |
| 38 | { return m_selfEndorseCertificate; } |
| 39 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 40 | const ndn::Name& |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 41 | getNameSpace() const |
| 42 | { return m_namespace; } |
| 43 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 44 | const std::string& |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 45 | getAlias() const |
| 46 | { return m_alias; } |
| 47 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 48 | const std::string& |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 49 | getName() const |
| 50 | { return m_name; } |
| 51 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 52 | const std::string& |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 53 | getInstitution() const |
| 54 | { return m_institution; } |
| 55 | |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 56 | const ndn::Name& |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 57 | getPublicKeyName() const |
| 58 | { return m_selfEndorseCertificate.getPublicKeyName(); } |
| 59 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 60 | bool |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 61 | isIntroducer() const |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 62 | { return m_isIntroducer; } |
| 63 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 64 | void |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 65 | setIsIntroducer(bool isIntroducer) |
| 66 | { m_isIntroducer = isIntroducer; } |
| 67 | |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 68 | void |
| 69 | addTrustScope(const ndn::Name& nameSpace) |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 70 | { m_trustScope[nameSpace] = ndn::Regex::fromName(nameSpace); } |
| 71 | |
| 72 | void |
| 73 | deleteTrustScope(const ndn::Name& nameSpace) |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 74 | { |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 75 | std::map<ndn::Name, ndn::shared_ptr<ndn::Regex> >::iterator it = m_trustScope.find(nameSpace); |
| 76 | if(it != m_trustScope.end()) |
| 77 | m_trustScope.erase(it); |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | bool |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 81 | canBeTrustedFor(const ndn::Name& name) |
| 82 | { |
| 83 | std::map<ndn::Name, ndn::shared_ptr<ndn::Regex> >::iterator it = m_trustScope.begin(); |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 84 | |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 85 | for(; it != m_trustScope.end(); it++) |
| 86 | if(it->second->match(name)) |
| 87 | return true; |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | const_iterator |
| 92 | trustScopeBegin() const |
| 93 | { return m_trustScope.begin(); } |
| 94 | |
| 95 | const_iterator |
| 96 | trustScopeEnd() const |
| 97 | { return m_trustScope.end(); } |
| 98 | |
| 99 | iterator |
| 100 | trustScopeBegin() |
| 101 | { return m_trustScope.begin(); } |
| 102 | |
| 103 | iterator |
| 104 | trustScopeEnd() |
| 105 | { return m_trustScope.end(); } |
| 106 | |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 107 | |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 108 | protected: |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 109 | EndorseCertificate m_selfEndorseCertificate; |
| 110 | |
| 111 | ndn::Name m_namespace; |
| 112 | std::string m_alias; |
| 113 | |
| 114 | std::string m_name; |
| 115 | std::string m_institution; |
Yingdi Yu | a50c325 | 2013-11-03 15:05:26 -0800 | [diff] [blame] | 116 | |
| 117 | bool m_isIntroducer; |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 118 | |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 119 | std::map<ndn::Name, ndn::shared_ptr<ndn::Regex> > m_trustScope; |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 120 | }; |
| 121 | |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 122 | }//chronos |
| 123 | |
Yingdi Yu | 53b8a9c | 2013-10-14 09:36:31 -0700 | [diff] [blame] | 124 | #endif |