Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -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: Mengjin Yan <jane.yan0129@gmail.com> |
| 9 | * Author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 10 | */ |
| 11 | #ifndef CHRONOCHAT_CHATROOM_INFO_HPP |
| 12 | #define CHRONOCHAT_CHATROOM_INFO_HPP |
| 13 | |
| 14 | #include "common.hpp" |
| 15 | #include "chatroom-tlv.hpp" |
| 16 | #include <ndn-cxx/face.hpp> |
| 17 | #include <ndn-cxx/security/key-chain.hpp> |
| 18 | #include <ndn-cxx/name-component.hpp> |
| 19 | #include <ndn-cxx/util/time.hpp> |
| 20 | #include <ndn-cxx/util/concepts.hpp> |
| 21 | #include <ndn-cxx/encoding/block.hpp> |
| 22 | #include <ndn-cxx/encoding/encoding-buffer.hpp> |
| 23 | #include <ndn-cxx/exclude.hpp> |
| 24 | #include <boost/concept_check.hpp> |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 25 | #include <list> |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 26 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 27 | namespace chronochat { |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 28 | |
| 29 | /** \brief store a chatroom's information with encode and decode method. |
| 30 | \sa docs/design.rst |
| 31 | */ |
| 32 | |
| 33 | class ChatroomInfo |
| 34 | { |
| 35 | |
| 36 | public: |
| 37 | |
| 38 | class Error : public std::runtime_error |
| 39 | { |
| 40 | public: |
| 41 | explicit |
| 42 | Error(const std::string& what) |
| 43 | : std::runtime_error(what) |
| 44 | { |
| 45 | } |
| 46 | }; |
| 47 | |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 48 | enum TrustModel { |
| 49 | TRUST_MODEL_HIERARCHICAL = 2, |
| 50 | TRUST_MODEL_WEBOFTRUST = 1, |
| 51 | TRUST_MODEL_NONE = 0 |
| 52 | }; |
| 53 | |
| 54 | public: |
| 55 | |
| 56 | ChatroomInfo(); |
| 57 | |
| 58 | explicit |
| 59 | ChatroomInfo(const Block& chatroomWire); |
| 60 | |
| 61 | const Block& |
| 62 | wireEncode() const; |
| 63 | |
| 64 | void |
| 65 | wireDecode(const Block& chatroomWire); |
| 66 | |
| 67 | const Name::Component& |
| 68 | getName() const; |
| 69 | |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 70 | const TrustModel |
| 71 | getTrustModel() const; |
| 72 | |
| 73 | const Name& |
| 74 | getSyncPrefix() const; |
| 75 | |
| 76 | const Name& |
| 77 | getManagerPrefix() const; |
| 78 | |
| 79 | const std::list<Name>& |
| 80 | getParticipants() const; |
| 81 | |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 82 | void |
| 83 | setName(const Name::Component& name); |
| 84 | |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 85 | void |
| 86 | setTrustModel(const TrustModel trustModel); |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 87 | |
| 88 | void |
| 89 | addParticipant(const Name& participant); |
| 90 | |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 91 | void |
| 92 | removeParticipant(const Name& participant); |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 93 | |
| 94 | void |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 95 | setSyncPrefix(const Name& prefix); |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 96 | |
| 97 | void |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 98 | setManager(const Name& manager); |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 99 | |
| 100 | private: |
| 101 | template<bool T> |
| 102 | size_t |
| 103 | wireEncode(ndn::EncodingImpl<T>& block) const; |
| 104 | |
| 105 | private: |
| 106 | mutable Block m_wire; |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 107 | Name::Component m_chatroomName; |
| 108 | std::list<Name> m_participants; |
| 109 | Name m_manager; |
| 110 | Name m_syncPrefix; |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 111 | TrustModel m_trustModel; |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 112 | |
| 113 | }; |
| 114 | |
| 115 | inline const Name::Component& |
| 116 | ChatroomInfo::getName() const |
| 117 | { |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 118 | return m_chatroomName; |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | inline const ChatroomInfo::TrustModel |
| 122 | ChatroomInfo::getTrustModel() const |
| 123 | { |
| 124 | return m_trustModel; |
| 125 | } |
| 126 | |
Qiuhan Ding | 5d98cc5 | 2014-10-30 15:17:53 -0700 | [diff] [blame] | 127 | |
| 128 | inline const Name& |
| 129 | ChatroomInfo::getManagerPrefix() const |
| 130 | { |
| 131 | return m_manager; |
| 132 | } |
| 133 | |
| 134 | inline const Name& |
| 135 | ChatroomInfo::getSyncPrefix() const |
| 136 | { |
| 137 | return m_syncPrefix; |
| 138 | } |
| 139 | |
| 140 | inline const std::list<Name>& |
| 141 | ChatroomInfo::getParticipants() const |
| 142 | { |
| 143 | return m_participants; |
| 144 | } |
| 145 | |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 146 | BOOST_CONCEPT_ASSERT((ndn::WireEncodable<ChatroomInfo>)); |
| 147 | BOOST_CONCEPT_ASSERT((ndn::WireDecodable<ChatroomInfo>)); |
| 148 | |
| 149 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 150 | } // namespace chronochat |
Mengjin Yan | aec7074 | 2014-08-25 10:37:45 -0700 | [diff] [blame] | 151 | |
Yingdi Yu | eb692ac | 2015-02-10 18:46:18 -0800 | [diff] [blame] | 152 | #endif // CHRONOCHAT_CHATROOM_INFO_HPP |