blob: bd3ab8a340c49d7b998606aa89dc5a92c9c51659 [file] [log] [blame]
Yingdi Yu53b8a9c2013-10-14 09:36:31 -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
Yingdi Yua1a688f2014-02-06 18:09:22 -080011#ifndef CHRONOS_CONTACT_ITEM_H
12#define CHRONOS_CONTACT_ITEM_H
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070013
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070014#include "endorse-certificate.h"
Yingdi Yua1a688f2014-02-06 18:09:22 -080015#include <ndn-cpp-dev/util/regex.hpp>
16#include <vector>
17
18
19namespace chronos{
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070020
21class ContactItem
22{
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070023public:
Yingdi Yua1a688f2014-02-06 18:09:22 -080024 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 Yu53b8a9c2013-10-14 09:36:31 -070027 ContactItem(const EndorseCertificate& selfEndorseCertificate,
Yingdi Yu813d4e92013-11-03 16:22:05 -080028 bool isIntroducer = false,
Yingdi Yua1a688f2014-02-06 18:09:22 -080029 const std::string& alias = "");
Yingdi Yua50c3252013-11-03 15:05:26 -080030
31 ContactItem(const ContactItem& contactItem);
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070032
Yingdi Yua50c3252013-11-03 15:05:26 -080033 virtual
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070034 ~ContactItem() {}
35
Yingdi Yu64206112013-12-24 11:16:32 +080036 const EndorseCertificate&
Yingdi Yuede8eaf2013-10-14 14:07:03 -070037 getSelfEndorseCertificate() const
38 { return m_selfEndorseCertificate; }
39
Yingdi Yu64206112013-12-24 11:16:32 +080040 const ndn::Name&
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070041 getNameSpace() const
42 { return m_namespace; }
43
Yingdi Yu64206112013-12-24 11:16:32 +080044 const std::string&
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070045 getAlias() const
46 { return m_alias; }
47
Yingdi Yu64206112013-12-24 11:16:32 +080048 const std::string&
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070049 getName() const
50 { return m_name; }
51
Yingdi Yu64206112013-12-24 11:16:32 +080052 const std::string&
Yingdi Yu53b8a9c2013-10-14 09:36:31 -070053 getInstitution() const
54 { return m_institution; }
55
Yingdi Yua1a688f2014-02-06 18:09:22 -080056 const ndn::Name&
Yingdi Yuede8eaf2013-10-14 14:07:03 -070057 getPublicKeyName() const
58 { return m_selfEndorseCertificate.getPublicKeyName(); }
59
Yingdi Yu64206112013-12-24 11:16:32 +080060 bool
Yingdi Yu813d4e92013-11-03 16:22:05 -080061 isIntroducer() const
Yingdi Yua50c3252013-11-03 15:05:26 -080062 { return m_isIntroducer; }
63
Yingdi Yu64206112013-12-24 11:16:32 +080064 void
Yingdi Yu8dacdf22013-11-05 23:06:43 -080065 setIsIntroducer(bool isIntroducer)
66 { m_isIntroducer = isIntroducer; }
67
Yingdi Yu813d4e92013-11-03 16:22:05 -080068 void
69 addTrustScope(const ndn::Name& nameSpace)
Yingdi Yua1a688f2014-02-06 18:09:22 -080070 { m_trustScope[nameSpace] = ndn::Regex::fromName(nameSpace); }
71
72 void
73 deleteTrustScope(const ndn::Name& nameSpace)
Yingdi Yu813d4e92013-11-03 16:22:05 -080074 {
Yingdi Yua1a688f2014-02-06 18:09:22 -080075 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 Yu813d4e92013-11-03 16:22:05 -080078 }
79
80 bool
Yingdi Yua1a688f2014-02-06 18:09:22 -080081 canBeTrustedFor(const ndn::Name& name)
82 {
83 std::map<ndn::Name, ndn::shared_ptr<ndn::Regex> >::iterator it = m_trustScope.begin();
Yingdi Yu813d4e92013-11-03 16:22:05 -080084
Yingdi Yua1a688f2014-02-06 18:09:22 -080085 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 Yu813d4e92013-11-03 16:22:05 -0800107
Yingdi Yuede8eaf2013-10-14 14:07:03 -0700108protected:
Yingdi Yu53b8a9c2013-10-14 09:36:31 -0700109 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 Yua50c3252013-11-03 15:05:26 -0800116
117 bool m_isIntroducer;
Yingdi Yu813d4e92013-11-03 16:22:05 -0800118
Yingdi Yua1a688f2014-02-06 18:09:22 -0800119 std::map<ndn::Name, ndn::shared_ptr<ndn::Regex> > m_trustScope;
Yingdi Yu53b8a9c2013-10-14 09:36:31 -0700120};
121
Yingdi Yua1a688f2014-02-06 18:09:22 -0800122}//chronos
123
Yingdi Yu53b8a9c2013-10-14 09:36:31 -0700124#endif