akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 19 | * Chaoyi Bian <bcy@pku.edu.cn> |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 20 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #ifndef SYNC_STATE_H |
| 24 | #define SYNC_STATE_H |
| 25 | |
| 26 | #include "sync-state-leaf-container.h" |
| 27 | #include <boost/exception/all.hpp> |
akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 28 | #include "sync-state.pb.h" |
| 29 | |
| 30 | /** |
| 31 | * \defgroup sync SYNC protocol |
| 32 | * |
| 33 | * Implementation of SYNC protocol |
| 34 | */ |
| 35 | namespace Sync { |
| 36 | |
| 37 | /** |
| 38 | * \ingroup sync |
| 39 | * @brief this prefix will be used for the dummy node which increases its sequence number whenever |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 40 | * a remove operation happens; this is to prevent the reversion of root digest when we prune |
akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 41 | * a branch, i.e. help the root digest to be forward only |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 42 | * No corresponding data msg would be published and no attempt would be made to retrieve the |
akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 43 | * data msg |
| 44 | */ |
| 45 | const std::string forwarderPrefix = "/d0n0t18ak/t0ps8cr8t"; |
| 46 | |
| 47 | class State; |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 48 | typedef shared_ptr<State> StatePtr; |
| 49 | typedef shared_ptr<State> StateConstPtr; |
akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * \ingroup sync |
| 53 | * @brief Container for state leaves and definition of the abstract interface to work with State objects |
| 54 | */ |
| 55 | class State |
| 56 | { |
| 57 | public: |
| 58 | virtual ~State () { }; |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 59 | |
akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 60 | /** |
| 61 | * @brief Add or update leaf to the state tree |
| 62 | * |
| 63 | * @param info name of the leaf |
| 64 | * @param seq sequence number of the leaf |
| 65 | */ |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 66 | virtual tuple<bool/*inserted*/, bool/*updated*/, SeqNo/*oldSeqNo*/> |
akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 67 | update (NameInfoConstPtr info, const SeqNo &seq) = 0; |
| 68 | |
| 69 | /** |
| 70 | * @brief Remove leaf from the state tree |
| 71 | * @param info name of the leaf |
| 72 | */ |
| 73 | virtual bool |
| 74 | remove (NameInfoConstPtr info) = 0; |
| 75 | |
| 76 | /** |
| 77 | * @brief Get state leaves |
| 78 | */ |
| 79 | const LeafContainer & |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 80 | getLeaves () const |
akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 81 | { return m_leaves; } |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 82 | |
akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 83 | protected: |
| 84 | LeafContainer m_leaves; |
| 85 | }; |
| 86 | |
| 87 | |
| 88 | /** |
| 89 | * @brief Formats a protobuf SyncStateMsg msg |
| 90 | * @param oss output SyncStateMsg msg |
| 91 | * @param state state |
| 92 | * @returns output SyncStateMsg msg |
| 93 | */ |
| 94 | SyncStateMsg & |
| 95 | operator << (SyncStateMsg &ossm, const State &state); |
| 96 | |
| 97 | |
| 98 | /** |
| 99 | * @brief Parse a protobuf SyncStateMsg msg |
| 100 | * @param iss input SyncStateMsg msg |
| 101 | * @param state state |
| 102 | * @returns SyncStateMsg msg |
| 103 | */ |
| 104 | SyncStateMsg & |
| 105 | operator >> (SyncStateMsg &issm, State &state); |
| 106 | |
| 107 | namespace Error { |
| 108 | /** |
| 109 | * @brief Will be thrown when data cannot be properly decoded to SyncStateMsg |
| 110 | */ |
| 111 | struct SyncStateMsgDecodingFailure : virtual boost::exception, virtual std::exception { }; |
| 112 | } |
| 113 | |
| 114 | } // Sync |
| 115 | |
| 116 | #endif // SYNC_STATE_H |