Zhenkai Zhu | 8d935c8 | 2012-03-06 10:44:12 -0800 | [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> |
Chaoyi Bian | 3e1eb16 | 2012-04-03 16:59:32 -0700 | [diff] [blame] | 19 | * Chaoyi Bian <bcy@pku.edu.cn> |
Zhenkai Zhu | 8d935c8 | 2012-03-06 10:44:12 -0800 | [diff] [blame] | 20 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 21 | * Yingdi Yu <yingdi@cs.ucla.edu> |
Zhenkai Zhu | 8d935c8 | 2012-03-06 10:44:12 -0800 | [diff] [blame] | 22 | */ |
Chaoyi Bian | 44fff0c | 2012-03-07 21:07:22 -0800 | [diff] [blame] | 23 | |
Chaoyi Bian | 11f294f | 2012-03-08 14:28:06 -0800 | [diff] [blame] | 24 | #include "sync-logic.h" |
Chaoyi Bian | 89ee2dc | 2012-03-09 14:06:01 -0800 | [diff] [blame] | 25 | #include "sync-diff-leaf.h" |
| 26 | #include "sync-full-leaf.h" |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 27 | #include "sync-logging.h" |
Zhenkai Zhu | 3cfdcb9 | 2012-06-06 15:20:10 -0700 | [diff] [blame] | 28 | #include "sync-state.h" |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 29 | |
Chaoyi Bian | 89ee2dc | 2012-03-09 14:06:01 -0800 | [diff] [blame] | 30 | #include <boost/foreach.hpp> |
Alexander Afanasyev | 387ac95 | 2012-03-11 23:49:27 -0700 | [diff] [blame] | 31 | #include <boost/lexical_cast.hpp> |
Zhenkai Zhu | a5d06d7 | 2012-03-09 15:16:24 -0800 | [diff] [blame] | 32 | #include <vector> |
Chaoyi Bian | 44fff0c | 2012-03-07 21:07:22 -0800 | [diff] [blame] | 33 | |
| 34 | using namespace std; |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 35 | using namespace ndn; |
Chaoyi Bian | 44fff0c | 2012-03-07 21:07:22 -0800 | [diff] [blame] | 36 | |
Chaoyi Bian | f007f92 | 2012-04-09 20:05:37 -0700 | [diff] [blame] | 37 | INIT_LOGGER ("SyncLogic"); |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 38 | |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 39 | |
| 40 | #ifdef _DEBUG |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 41 | #define _LOG_DEBUG_ID(v) _LOG_DEBUG(m_instanceId << " " << v) |
Alexander Afanasyev | 983b0e9 | 2012-04-26 12:44:18 -0700 | [diff] [blame] | 42 | #else |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 43 | #define _LOG_DEBUG_ID(v) _LOG_DEBUG(v) |
Alexander Afanasyev | 983b0e9 | 2012-04-26 12:44:18 -0700 | [diff] [blame] | 44 | #endif |
| 45 | |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 46 | #define GET_RANDOM(var) var () |
| 47 | |
Alexander Afanasyev | 983b0e9 | 2012-04-26 12:44:18 -0700 | [diff] [blame] | 48 | #define TIME_SECONDS_WITH_JITTER(sec) \ |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 49 | (time::seconds(sec) + time::milliseconds(GET_RANDOM (m_reexpressionJitter))) |
Alexander Afanasyev | 983b0e9 | 2012-04-26 12:44:18 -0700 | [diff] [blame] | 50 | |
Alexander Afanasyev | 4261226 | 2012-05-05 10:58:37 -0700 | [diff] [blame] | 51 | #define TIME_MILLISECONDS_WITH_JITTER(ms) \ |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 52 | (time::seconds(ms) + time::milliseconds(GET_RANDOM (m_reexpressionJitter))) |
Alexander Afanasyev | 983b0e9 | 2012-04-26 12:44:18 -0700 | [diff] [blame] | 53 | |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 54 | namespace Sync { |
Alexander Afanasyev | 983b0e9 | 2012-04-26 12:44:18 -0700 | [diff] [blame] | 55 | |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 56 | using ndn::shared_ptr; |
Chaoyi Bian | 44fff0c | 2012-03-07 21:07:22 -0800 | [diff] [blame] | 57 | |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 58 | int SyncLogic::m_instanceCounter = 0; |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 59 | |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 60 | SyncLogic::SyncLogic (const Name& syncPrefix, |
| 61 | shared_ptr<Validator> validator, |
| 62 | shared_ptr<Face> face, |
| 63 | LogicUpdateCallback onUpdate, |
| 64 | LogicRemoveCallback onRemove) |
| 65 | : m_state (new FullState) |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 66 | , m_syncInterestTable (*face->ioService(), time::seconds(m_syncInterestReexpress)) |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 67 | , m_syncPrefix (syncPrefix) |
| 68 | , m_onUpdate (onUpdate) |
| 69 | , m_onRemove (onRemove) |
| 70 | , m_perBranch (false) |
| 71 | , m_validator(validator) |
| 72 | , m_keyChain(new KeyChain()) |
| 73 | , m_face(face) |
| 74 | , m_scheduler(*face->ioService()) |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 75 | , m_randomGenerator (static_cast<unsigned int> (std::time (0))) |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 76 | , m_rangeUniformRandom (m_randomGenerator, boost::uniform_int<> (200,1000)) |
| 77 | , m_reexpressionJitter (m_randomGenerator, boost::uniform_int<> (100,500)) |
| 78 | , m_recoveryRetransmissionInterval (m_defaultRecoveryRetransmitInterval) |
| 79 | { |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 80 | m_syncRegisteredPrefixId = m_face->setInterestFilter (m_syncPrefix, |
| 81 | bind(&SyncLogic::onSyncInterest, this, _1, _2), |
Yingdi Yu | 51c8025 | 2014-02-10 19:32:05 -0800 | [diff] [blame^] | 82 | bind(&SyncLogic::onSyncRegisterFailed, this, _1, _2)); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 83 | |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 84 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 85 | m_reexpressingInterestId = m_scheduler.scheduleEvent (time::seconds (0), // no need to add jitter |
| 86 | bind (&SyncLogic::sendSyncInterest, this)); |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 87 | |
| 88 | m_instanceId = string("Instance " + boost::lexical_cast<string>(m_instanceCounter++) + " "); |
Chaoyi Bian | 44fff0c | 2012-03-07 21:07:22 -0800 | [diff] [blame] | 89 | } |
| 90 | |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 91 | SyncLogic::SyncLogic (const Name& syncPrefix, |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 92 | shared_ptr<Validator> validator, |
Yingdi Yu | 6e235db | 2013-12-27 08:40:53 +0800 | [diff] [blame] | 93 | shared_ptr<Face> face, |
Zhenkai Zhu | b9f1959 | 2012-10-16 14:27:38 -0700 | [diff] [blame] | 94 | LogicPerBranchCallback onUpdateBranch) |
| 95 | : m_state (new FullState) |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 96 | , m_syncInterestTable (*face->ioService(), time::seconds (m_syncInterestReexpress)) |
Zhenkai Zhu | b9f1959 | 2012-10-16 14:27:38 -0700 | [diff] [blame] | 97 | , m_syncPrefix (syncPrefix) |
| 98 | , m_onUpdateBranch (onUpdateBranch) |
| 99 | , m_perBranch(true) |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 100 | , m_validator(validator) |
Yingdi Yu | 0cb0f2b | 2014-01-09 13:51:16 -0800 | [diff] [blame] | 101 | , m_keyChain(new KeyChain()) |
Yingdi Yu | 6e235db | 2013-12-27 08:40:53 +0800 | [diff] [blame] | 102 | , m_face(face) |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 103 | , m_scheduler(*face->ioService()) |
Zhenkai Zhu | b9f1959 | 2012-10-16 14:27:38 -0700 | [diff] [blame] | 104 | , m_randomGenerator (static_cast<unsigned int> (std::time (0))) |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 105 | , m_rangeUniformRandom (m_randomGenerator, boost::uniform_int<> (200,1000)) |
| 106 | , m_reexpressionJitter (m_randomGenerator, boost::uniform_int<> (100,500)) |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 107 | , m_recoveryRetransmissionInterval (m_defaultRecoveryRetransmitInterval) |
Zhenkai Zhu | b9f1959 | 2012-10-16 14:27:38 -0700 | [diff] [blame] | 108 | { |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 109 | m_syncRegisteredPrefixId = m_face->setInterestFilter (m_syncPrefix, |
| 110 | bind(&SyncLogic::onSyncInterest, this, _1, _2), |
Yingdi Yu | 51c8025 | 2014-02-10 19:32:05 -0800 | [diff] [blame^] | 111 | bind(&SyncLogic::onSyncRegisterFailed, this, _1, _2)); |
Zhenkai Zhu | b9f1959 | 2012-10-16 14:27:38 -0700 | [diff] [blame] | 112 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 113 | m_reexpressingInterestId = m_scheduler.scheduleEvent (time::seconds (0), // no need to add jitter |
| 114 | bind (&SyncLogic::sendSyncInterest, this)); |
Zhenkai Zhu | b9f1959 | 2012-10-16 14:27:38 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 117 | SyncLogic::~SyncLogic () |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 118 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 119 | m_face->unsetInterestFilter(m_syncRegisteredPrefixId); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 120 | m_scheduler.cancelEvent (m_reexpressingInterestId); |
| 121 | m_scheduler.cancelEvent (m_delayedInterestProcessingId); |
Zhenkai Zhu | eb1d865 | 2012-12-23 15:25:39 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 124 | /** |
| 125 | * Two types of intersts |
| 126 | * |
| 127 | * Normal name: .../<hash> |
| 128 | * Recovery name: .../recovery/<hash> |
| 129 | */ |
| 130 | boost::tuple<DigestConstPtr, std::string> |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 131 | SyncLogic::convertNameToDigestAndType (const Name &name) |
Alexander Afanasyev | 387ac95 | 2012-03-11 23:49:27 -0700 | [diff] [blame] | 132 | { |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 133 | BOOST_ASSERT (m_syncPrefix.isPrefixOf(name)); |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 134 | |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 135 | int nameLengthDiff = name.size() - m_syncPrefix.size(); |
| 136 | BOOST_ASSERT (nameLengthDiff > 0); |
| 137 | BOOST_ASSERT (nameLengthDiff < 3); |
| 138 | |
| 139 | string hash = name.get(-1).toEscapedString(); |
| 140 | string interestType; |
| 141 | |
| 142 | if(nameLengthDiff == 1) |
| 143 | interestType = "normal"; |
| 144 | else |
| 145 | interestType = name.get(-2).toEscapedString(); |
Alexander Afanasyev | 387ac95 | 2012-03-11 23:49:27 -0700 | [diff] [blame] | 146 | |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 147 | _LOG_DEBUG_ID (hash << ", " << interestType); |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 148 | |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame] | 149 | DigestPtr digest = boost::make_shared<Digest> (); |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 150 | istringstream is (hash); |
| 151 | is >> *digest; |
| 152 | |
| 153 | return make_tuple (digest, interestType); |
Alexander Afanasyev | 387ac95 | 2012-03-11 23:49:27 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | void |
Yingdi Yu | 51c8025 | 2014-02-10 19:32:05 -0800 | [diff] [blame^] | 157 | SyncLogic::onSyncInterest (const Name& prefix, const ndn::Interest& interest) |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 158 | { |
Yingdi Yu | 51c8025 | 2014-02-10 19:32:05 -0800 | [diff] [blame^] | 159 | Name name = interest.getName(); |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 160 | |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 161 | _LOG_DEBUG_ID("respondSyncInterest: " << name); |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 162 | |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 163 | try |
| 164 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 165 | _LOG_DEBUG_ID ("<< I " << name); |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 166 | |
| 167 | DigestConstPtr digest; |
| 168 | string type; |
| 169 | tie (digest, type) = convertNameToDigestAndType (name); |
| 170 | |
| 171 | if (type == "normal") // kind of ineffective... |
| 172 | { |
| 173 | processSyncInterest (name, digest); |
| 174 | } |
| 175 | else if (type == "recovery") |
| 176 | { |
| 177 | processSyncRecoveryInterest (name, digest); |
| 178 | } |
| 179 | } |
| 180 | catch (Error::DigestCalculationError &e) |
| 181 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 182 | _LOG_DEBUG_ID ("Something fishy happened..."); |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 183 | // log error. ignoring it for now, later we should log it |
| 184 | return ; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | void |
Yingdi Yu | 51c8025 | 2014-02-10 19:32:05 -0800 | [diff] [blame^] | 189 | SyncLogic::onSyncRegisterFailed(const Name& prefix, const string& msg) |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 190 | { |
Yingdi Yu | 51c8025 | 2014-02-10 19:32:05 -0800 | [diff] [blame^] | 191 | _LOG_DEBUG_ID("Sync prefix registration failed! " << msg); |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | void |
Yingdi Yu | 51c8025 | 2014-02-10 19:32:05 -0800 | [diff] [blame^] | 195 | SyncLogic::onSyncData(const ndn::Interest& interest, Data& data) |
| 196 | { |
| 197 | OnDataValidated onValidated = bind(&SyncLogic::onSyncDataValidated, this, _1); |
| 198 | OnDataValidationFailed onValidationFailed = bind(&SyncLogic::onSyncDataValidationFailed, this, _1); |
| 199 | m_validator->validate(data, onValidated, onValidationFailed); |
| 200 | } |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 201 | |
| 202 | void |
Yingdi Yu | 51c8025 | 2014-02-10 19:32:05 -0800 | [diff] [blame^] | 203 | SyncLogic::onSyncTimeout(const ndn::Interest& interest) |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 204 | { |
| 205 | // It is OK. Others will handle the time out situation. |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | void |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 209 | SyncLogic::onSyncDataValidationFailed(const shared_ptr<const Data>& data) |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 210 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 211 | _LOG_DEBUG_ID("Sync data cannot be verified!"); |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | void |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 215 | SyncLogic::onSyncDataValidated(const shared_ptr<const Data>& data) |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 216 | { |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 217 | Name name = data->getName(); |
Yingdi Yu | 0cb0f2b | 2014-01-09 13:51:16 -0800 | [diff] [blame] | 218 | const char* wireData = (const char*)data->getContent().value(); |
| 219 | size_t len = data->getContent().value_size(); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 220 | |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 221 | try |
| 222 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 223 | _LOG_DEBUG_ID ("<< D " << name); |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 224 | |
| 225 | DigestConstPtr digest; |
| 226 | string type; |
| 227 | tie (digest, type) = convertNameToDigestAndType (name); |
| 228 | |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 229 | if (type == "normal") |
| 230 | { |
Zhenkai Zhu | 97e36bd | 2012-06-06 13:55:03 -0700 | [diff] [blame] | 231 | processSyncData (name, digest, wireData, len); |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 232 | } |
| 233 | else |
| 234 | { |
Alexander Afanasyev | a76010b | 2012-05-24 21:31:49 -0700 | [diff] [blame] | 235 | // timer is always restarted when we schedule recovery |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 236 | m_scheduler.cancelEvent (m_reexpressingRecoveryInterestId); |
Zhenkai Zhu | 97e36bd | 2012-06-06 13:55:03 -0700 | [diff] [blame] | 237 | processSyncData (name, digest, wireData, len); |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 238 | } |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 239 | } |
| 240 | catch (Error::DigestCalculationError &e) |
| 241 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 242 | _LOG_DEBUG_ID ("Something fishy happened..."); |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 243 | // log error. ignoring it for now, later we should log it |
| 244 | return; |
| 245 | } |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 248 | void |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 249 | SyncLogic::processSyncInterest (const Name &name, DigestConstPtr digest, bool timedProcessing/*=false*/) |
Alexander Afanasyev | 387ac95 | 2012-03-11 23:49:27 -0700 | [diff] [blame] | 250 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 251 | _LOG_DEBUG_ID("processSyncInterest"); |
Zhenkai Zhu | 2d3e270 | 2012-10-15 14:18:05 -0700 | [diff] [blame] | 252 | DigestConstPtr rootDigest; |
| 253 | { |
Zhenkai Zhu | 2d3e270 | 2012-10-15 14:18:05 -0700 | [diff] [blame] | 254 | rootDigest = m_state->getDigest(); |
| 255 | } |
Alexander Afanasyev | 387ac95 | 2012-03-11 23:49:27 -0700 | [diff] [blame] | 256 | |
Alexander Afanasyev | dd0eba7 | 2012-03-13 13:57:10 -0700 | [diff] [blame] | 257 | // Special case when state is not empty and we have received request with zero-root digest |
Zhenkai Zhu | 2d3e270 | 2012-10-15 14:18:05 -0700 | [diff] [blame] | 258 | if (digest->isZero () && !rootDigest->isZero ()) |
Alexander Afanasyev | dd0eba7 | 2012-03-13 13:57:10 -0700 | [diff] [blame] | 259 | { |
Zhenkai Zhu | 2d3e270 | 2012-10-15 14:18:05 -0700 | [diff] [blame] | 260 | |
| 261 | SyncStateMsg ssm; |
| 262 | { |
Zhenkai Zhu | 2d3e270 | 2012-10-15 14:18:05 -0700 | [diff] [blame] | 263 | ssm << (*m_state); |
| 264 | } |
| 265 | sendSyncData (name, digest, ssm); |
Alexander Afanasyev | dd0eba7 | 2012-03-13 13:57:10 -0700 | [diff] [blame] | 266 | return; |
| 267 | } |
Alexander Afanasyev | 763855a | 2012-03-13 14:17:37 -0700 | [diff] [blame] | 268 | |
Zhenkai Zhu | 2d3e270 | 2012-10-15 14:18:05 -0700 | [diff] [blame] | 269 | if (*rootDigest == *digest) |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 270 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 271 | _LOG_DEBUG_ID ("processSyncInterest (): Same state. Adding to PIT"); |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 272 | m_syncInterestTable.insert (digest, name.toUri(), false); |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 273 | return; |
| 274 | } |
Alexander Afanasyev | dd0eba7 | 2012-03-13 13:57:10 -0700 | [diff] [blame] | 275 | |
Alexander Afanasyev | 387ac95 | 2012-03-11 23:49:27 -0700 | [diff] [blame] | 276 | DiffStateContainer::iterator stateInDiffLog = m_log.find (digest); |
| 277 | |
| 278 | if (stateInDiffLog != m_log.end ()) |
| 279 | { |
Alexander Afanasyev | 235c6d7 | 2012-03-15 22:28:43 -0700 | [diff] [blame] | 280 | DiffStateConstPtr stateDiff = (*stateInDiffLog)->diff (); |
Alexander Afanasyev | 235c6d7 | 2012-03-15 22:28:43 -0700 | [diff] [blame] | 281 | |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 282 | sendSyncData (name, digest, stateDiff); |
Alexander Afanasyev | 387ac95 | 2012-03-11 23:49:27 -0700 | [diff] [blame] | 283 | return; |
| 284 | } |
| 285 | |
| 286 | if (!timedProcessing) |
| 287 | { |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 288 | bool exists = m_syncInterestTable.insert (digest, name.toUri(), true); |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 289 | if (exists) // somebody else replied, so restart random-game timer |
Alexander Afanasyev | 3a22913 | 2012-04-25 15:07:26 -0700 | [diff] [blame] | 290 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 291 | _LOG_DEBUG_ID ("Unknown digest, but somebody may have already replied, so restart our timer"); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 292 | m_scheduler.cancelEvent (m_delayedInterestProcessingId); |
Alexander Afanasyev | 3a22913 | 2012-04-25 15:07:26 -0700 | [diff] [blame] | 293 | } |
Alexander Afanasyev | 03793b4 | 2012-05-01 13:03:07 -0700 | [diff] [blame] | 294 | |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 295 | uint32_t waitDelay = GET_RANDOM (m_rangeUniformRandom); |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 296 | _LOG_DEBUG_ID ("Digest is not in the log. Schedule processing after small delay: " << time::milliseconds (waitDelay)); |
Alexander Afanasyev | 983b0e9 | 2012-04-26 12:44:18 -0700 | [diff] [blame] | 297 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 298 | m_delayedInterestProcessingId = m_scheduler.scheduleEvent (time::milliseconds (waitDelay), |
| 299 | bind (&SyncLogic::processSyncInterest, this, name, digest, true)); |
Alexander Afanasyev | 387ac95 | 2012-03-11 23:49:27 -0700 | [diff] [blame] | 300 | } |
| 301 | else |
| 302 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 303 | _LOG_DEBUG_ID (" (timed processing)"); |
Alexander Afanasyev | a76010b | 2012-05-24 21:31:49 -0700 | [diff] [blame] | 304 | |
| 305 | m_recoveryRetransmissionInterval = m_defaultRecoveryRetransmitInterval; |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 306 | sendSyncRecoveryInterests (digest); |
Alexander Afanasyev | 387ac95 | 2012-03-11 23:49:27 -0700 | [diff] [blame] | 307 | } |
Chaoyi Bian | 44fff0c | 2012-03-07 21:07:22 -0800 | [diff] [blame] | 308 | } |
| 309 | |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 310 | void |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 311 | SyncLogic::processSyncData (const Name &name, DigestConstPtr digest, const char *wireData, size_t len) |
Chaoyi Bian | 44fff0c | 2012-03-07 21:07:22 -0800 | [diff] [blame] | 312 | { |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame] | 313 | DiffStatePtr diffLog = boost::make_shared<DiffState> (); |
Alexander Afanasyev | 2b6fbfb | 2012-05-24 10:57:14 -0700 | [diff] [blame] | 314 | bool ownInterestSatisfied = false; |
Alexander Afanasyev | e4e2bf7 | 2012-03-12 12:44:54 -0700 | [diff] [blame] | 315 | |
Alexander Afanasyev | 750d187 | 2012-03-12 15:33:56 -0700 | [diff] [blame] | 316 | try |
| 317 | { |
Alexander Afanasyev | 750d187 | 2012-03-12 15:33:56 -0700 | [diff] [blame] | 318 | |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 319 | m_syncInterestTable.remove (name.toUri()); // Remove satisfied interest from PIT |
Alexander Afanasyev | 750d187 | 2012-03-12 15:33:56 -0700 | [diff] [blame] | 320 | |
Alexander Afanasyev | 2b6fbfb | 2012-05-24 10:57:14 -0700 | [diff] [blame] | 321 | ownInterestSatisfied = (name == m_outstandingInterestName); |
| 322 | |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 323 | DiffState diff; |
Zhenkai Zhu | 97e36bd | 2012-06-06 13:55:03 -0700 | [diff] [blame] | 324 | SyncStateMsg msg; |
Zhenkai Zhu | 3cfdcb9 | 2012-06-06 15:20:10 -0700 | [diff] [blame] | 325 | if (!msg.ParseFromArray(wireData, len) || !msg.IsInitialized()) |
Zhenkai Zhu | 97e36bd | 2012-06-06 13:55:03 -0700 | [diff] [blame] | 326 | { |
| 327 | //Throw |
Zhenkai Zhu | 3cfdcb9 | 2012-06-06 15:20:10 -0700 | [diff] [blame] | 328 | BOOST_THROW_EXCEPTION (Error::SyncStateMsgDecodingFailure () ); |
Zhenkai Zhu | 97e36bd | 2012-06-06 13:55:03 -0700 | [diff] [blame] | 329 | } |
| 330 | msg >> diff; |
| 331 | |
Zhenkai Zhu | 1cb2929 | 2012-05-31 22:54:34 -0700 | [diff] [blame] | 332 | vector<MissingDataInfo> v; |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 333 | BOOST_FOREACH (LeafConstPtr leaf, diff.getLeaves().get<ordered>()) |
Alexander Afanasyev | 04fd8a8 | 2012-03-12 15:40:48 -0700 | [diff] [blame] | 334 | { |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 335 | DiffLeafConstPtr diffLeaf = boost::dynamic_pointer_cast<const DiffLeaf> (leaf); |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 336 | BOOST_ASSERT (diffLeaf != 0); |
| 337 | |
| 338 | NameInfoConstPtr info = diffLeaf->getInfo(); |
Zhenkai Zhu | ba3c1d1 | 2012-10-03 23:26:35 -0700 | [diff] [blame] | 339 | if (diffLeaf->getOperation() == UPDATE) |
Alexander Afanasyev | 04fd8a8 | 2012-03-12 15:40:48 -0700 | [diff] [blame] | 340 | { |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 341 | SeqNo seq = diffLeaf->getSeq(); |
Alexander Afanasyev | 750d187 | 2012-03-12 15:33:56 -0700 | [diff] [blame] | 342 | |
| 343 | bool inserted = false; |
| 344 | bool updated = false; |
| 345 | SeqNo oldSeq; |
Zhenkai Zhu | 2d3e270 | 2012-10-15 14:18:05 -0700 | [diff] [blame] | 346 | { |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 347 | boost::tie (inserted, updated, oldSeq) = m_state->update (info, seq); |
Zhenkai Zhu | 2d3e270 | 2012-10-15 14:18:05 -0700 | [diff] [blame] | 348 | } |
Chaoyi Bian | 89ee2dc | 2012-03-09 14:06:01 -0800 | [diff] [blame] | 349 | |
Alexander Afanasyev | d4adce5 | 2012-03-13 13:59:39 -0700 | [diff] [blame] | 350 | if (inserted || updated) |
Alexander Afanasyev | 750d187 | 2012-03-12 15:33:56 -0700 | [diff] [blame] | 351 | { |
| 352 | diffLog->update (info, seq); |
Zhenkai Zhu | 68f04d5 | 2012-06-05 14:07:41 -0700 | [diff] [blame] | 353 | if (!oldSeq.isValid()) |
| 354 | { |
| 355 | oldSeq = SeqNo(seq.getSession(), 0); |
| 356 | } |
| 357 | else |
| 358 | { |
| 359 | ++oldSeq; |
| 360 | } |
Zhenkai Zhu | ba3c1d1 | 2012-10-03 23:26:35 -0700 | [diff] [blame] | 361 | // there is no need for application to process update on forwarder node |
| 362 | if (info->toString() != forwarderPrefix) |
| 363 | { |
| 364 | MissingDataInfo mdi = {info->toString(), oldSeq, seq}; |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 365 | { |
| 366 | ostringstream interestName; |
| 367 | interestName << mdi.prefix << "/" << mdi.high.getSession() << "/" << mdi.high.getSeq(); |
| 368 | _LOG_DEBUG_ID("+++++++++++++++ " + interestName.str()); |
| 369 | } |
Zhenkai Zhu | b9f1959 | 2012-10-16 14:27:38 -0700 | [diff] [blame] | 370 | if (m_perBranch) |
| 371 | { |
| 372 | ostringstream interestName; |
| 373 | interestName << mdi.prefix << "/" << mdi.high.getSession() << "/" << mdi.high.getSeq(); |
| 374 | m_onUpdateBranch(interestName.str()); |
| 375 | } |
| 376 | else |
| 377 | { |
| 378 | v.push_back(mdi); |
| 379 | } |
Zhenkai Zhu | ba3c1d1 | 2012-10-03 23:26:35 -0700 | [diff] [blame] | 380 | } |
Alexander Afanasyev | 04fd8a8 | 2012-03-12 15:40:48 -0700 | [diff] [blame] | 381 | } |
| 382 | } |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 383 | else if (diffLeaf->getOperation() == REMOVE) |
Alexander Afanasyev | 04fd8a8 | 2012-03-12 15:40:48 -0700 | [diff] [blame] | 384 | { |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 385 | if (m_state->remove (info)) |
Alexander Afanasyev | 750d187 | 2012-03-12 15:33:56 -0700 | [diff] [blame] | 386 | { |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 387 | diffLog->remove (info); |
Zhenkai Zhu | b9f1959 | 2012-10-16 14:27:38 -0700 | [diff] [blame] | 388 | if (!m_perBranch) |
| 389 | { |
| 390 | m_onRemove (info->toString ()); |
| 391 | } |
Alexander Afanasyev | 04fd8a8 | 2012-03-12 15:40:48 -0700 | [diff] [blame] | 392 | } |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 393 | } |
| 394 | else |
| 395 | { |
Alexander Afanasyev | 750d187 | 2012-03-12 15:33:56 -0700 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | |
Zhenkai Zhu | 1cb2929 | 2012-05-31 22:54:34 -0700 | [diff] [blame] | 399 | if (!v.empty()) |
| 400 | { |
Zhenkai Zhu | b9f1959 | 2012-10-16 14:27:38 -0700 | [diff] [blame] | 401 | if (!m_perBranch) |
| 402 | { |
| 403 | m_onUpdate(v); |
| 404 | } |
Zhenkai Zhu | 1cb2929 | 2012-05-31 22:54:34 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Alexander Afanasyev | 235c6d7 | 2012-03-15 22:28:43 -0700 | [diff] [blame] | 407 | insertToDiffLog (diffLog); |
Alexander Afanasyev | 750d187 | 2012-03-12 15:33:56 -0700 | [diff] [blame] | 408 | } |
Zhenkai Zhu | 97e36bd | 2012-06-06 13:55:03 -0700 | [diff] [blame] | 409 | catch (Error::SyncStateMsgDecodingFailure &e) |
Alexander Afanasyev | 750d187 | 2012-03-12 15:33:56 -0700 | [diff] [blame] | 410 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 411 | _LOG_DEBUG_ID ("Something really fishy happened during state decoding " << |
Alexander Afanasyev | 282a10b | 2012-05-09 12:56:38 -0700 | [diff] [blame] | 412 | diagnostic_information (e)); |
Alexander Afanasyev | d4cca47 | 2012-03-13 14:25:46 -0700 | [diff] [blame] | 413 | diffLog.reset (); |
| 414 | // don't do anything |
Alexander Afanasyev | 750d187 | 2012-03-12 15:33:56 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Alexander Afanasyev | 2b6fbfb | 2012-05-24 10:57:14 -0700 | [diff] [blame] | 417 | if ((diffLog != 0 && diffLog->getLeaves ().size () > 0) || |
| 418 | ownInterestSatisfied) |
Alexander Afanasyev | 750d187 | 2012-03-12 15:33:56 -0700 | [diff] [blame] | 419 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 420 | _LOG_DEBUG_ID(" +++++++++++++++ state changed!!!"); |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 421 | // Do it only if everything went fine and state changed |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 422 | |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 423 | // this is kind of wrong |
| 424 | // satisfyPendingSyncInterests (diffLog); // if there are interests in PIT, there is a point to satisfy them using new state |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 425 | |
Alexander Afanasyev | 282a10b | 2012-05-09 12:56:38 -0700 | [diff] [blame] | 426 | // if state has changed, then it is safe to express a new interest |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 427 | time::Duration after = time::milliseconds(GET_RANDOM (m_reexpressionJitter)); |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 428 | // cout << "------------ reexpress interest after: " << after << endl; |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 429 | EventId eventId = m_scheduler.scheduleEvent (after, |
| 430 | bind (&SyncLogic::sendSyncInterest, this)); |
| 431 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 432 | m_scheduler.cancelEvent (m_reexpressingInterestId); |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 433 | m_reexpressingInterestId = eventId; |
Alexander Afanasyev | 04fd8a8 | 2012-03-12 15:40:48 -0700 | [diff] [blame] | 434 | } |
Chaoyi Bian | 44fff0c | 2012-03-07 21:07:22 -0800 | [diff] [blame] | 435 | } |
| 436 | |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 437 | void |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 438 | SyncLogic::processSyncRecoveryInterest (const Name &name, DigestConstPtr digest) |
Chaoyi Bian | 44fff0c | 2012-03-07 21:07:22 -0800 | [diff] [blame] | 439 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 440 | _LOG_DEBUG_ID("processSyncRecoveryInterest"); |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 441 | DiffStateContainer::iterator stateInDiffLog = m_log.find (digest); |
| 442 | |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 443 | if (stateInDiffLog == m_log.end ()) |
Alexander Afanasyev | bf2b436 | 2012-03-12 23:55:09 -0700 | [diff] [blame] | 444 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 445 | _LOG_DEBUG_ID ("Could not find " << *digest << " in digest log"); |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 446 | return; |
| 447 | } |
Alexander Afanasyev | 860e6fe | 2012-03-15 17:30:31 -0700 | [diff] [blame] | 448 | |
Zhenkai Zhu | 2d3e270 | 2012-10-15 14:18:05 -0700 | [diff] [blame] | 449 | SyncStateMsg ssm; |
| 450 | { |
Zhenkai Zhu | 2d3e270 | 2012-10-15 14:18:05 -0700 | [diff] [blame] | 451 | ssm << (*m_state); |
| 452 | } |
| 453 | sendSyncData (name, digest, ssm); |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 454 | } |
Alexander Afanasyev | 860e6fe | 2012-03-15 17:30:31 -0700 | [diff] [blame] | 455 | |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 456 | void |
| 457 | SyncLogic::satisfyPendingSyncInterests (DiffStateConstPtr diffLog) |
| 458 | { |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame] | 459 | DiffStatePtr fullStateLog = boost::make_shared<DiffState> (); |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 460 | { |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 461 | BOOST_FOREACH (LeafConstPtr leaf, m_state->getLeaves ()/*.get<timed> ()*/) |
| 462 | { |
| 463 | fullStateLog->update (leaf->getInfo (), leaf->getSeq ()); |
| 464 | /// @todo Impose limit on how many state info should be send out |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | try |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 469 | { |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 470 | uint32_t counter = 0; |
| 471 | while (m_syncInterestTable.size () > 0) |
Alexander Afanasyev | 860e6fe | 2012-03-15 17:30:31 -0700 | [diff] [blame] | 472 | { |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 473 | Sync::Interest interest = m_syncInterestTable.pop (); |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 474 | |
| 475 | if (!interest.m_unknown) |
| 476 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 477 | _LOG_DEBUG_ID (">> D " << interest.m_name); |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 478 | sendSyncData (interest.m_name, interest.m_digest, diffLog); |
| 479 | } |
| 480 | else |
| 481 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 482 | _LOG_DEBUG_ID (">> D (unknown)" << interest.m_name); |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 483 | sendSyncData (interest.m_name, interest.m_digest, fullStateLog); |
| 484 | } |
| 485 | counter ++; |
Alexander Afanasyev | f07ab35 | 2012-03-13 12:57:46 -0700 | [diff] [blame] | 486 | } |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 487 | _LOG_DEBUG_ID ("Satisfied " << counter << " pending interests"); |
Alexander Afanasyev | f07ab35 | 2012-03-13 12:57:46 -0700 | [diff] [blame] | 488 | } |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 489 | catch (Error::InterestTableIsEmpty &e) |
| 490 | { |
| 491 | // ok. not really an error |
Chaoyi Bian | 44fff0c | 2012-03-07 21:07:22 -0800 | [diff] [blame] | 492 | } |
Chaoyi Bian | 44fff0c | 2012-03-07 21:07:22 -0800 | [diff] [blame] | 493 | } |
| 494 | |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 495 | void |
Alexander Afanasyev | 235c6d7 | 2012-03-15 22:28:43 -0700 | [diff] [blame] | 496 | SyncLogic::insertToDiffLog (DiffStatePtr diffLog) |
Alexander Afanasyev | 1b449c4 | 2012-03-13 20:24:07 -0700 | [diff] [blame] | 497 | { |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 498 | diffLog->setDigest (m_state->getDigest()); |
Alexander Afanasyev | 1b449c4 | 2012-03-13 20:24:07 -0700 | [diff] [blame] | 499 | if (m_log.size () > 0) |
| 500 | { |
| 501 | m_log.get<sequenced> ().front ()->setNext (diffLog); |
| 502 | } |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 503 | m_log.erase (m_state->getDigest()); // remove diff state with the same digest. next pointers are still valid |
Alexander Afanasyev | 1b449c4 | 2012-03-13 20:24:07 -0700 | [diff] [blame] | 504 | /// @todo Optimization |
Alexander Afanasyev | 7df7333 | 2012-03-15 12:31:49 -0700 | [diff] [blame] | 505 | m_log.get<sequenced> ().push_front (diffLog); |
Alexander Afanasyev | 1b449c4 | 2012-03-13 20:24:07 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | void |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 509 | SyncLogic::addLocalNames (const Name &prefix, uint64_t session, uint64_t seq) |
Zhenkai Zhu | 0efa37b | 2012-03-12 13:54:12 -0700 | [diff] [blame] | 510 | { |
Alexander Afanasyev | 1b449c4 | 2012-03-13 20:24:07 -0700 | [diff] [blame] | 511 | DiffStatePtr diff; |
| 512 | { |
| 513 | //cout << "Add local names" <<endl; |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 514 | NameInfoConstPtr info = StdNameInfo::FindOrCreate(prefix.toUri()); |
Alexander Afanasyev | 860e6fe | 2012-03-15 17:30:31 -0700 | [diff] [blame] | 515 | |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 516 | _LOG_DEBUG_ID ("addLocalNames (): old state " << *m_state->getDigest ()); |
Zhenkai Zhu | 0efa37b | 2012-03-12 13:54:12 -0700 | [diff] [blame] | 517 | |
Zhenkai Zhu | 0efa37b | 2012-03-12 13:54:12 -0700 | [diff] [blame] | 518 | SeqNo seqN (session, seq); |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 519 | m_state->update(info, seqN); |
Zhenkai Zhu | 0efa37b | 2012-03-12 13:54:12 -0700 | [diff] [blame] | 520 | |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 521 | _LOG_DEBUG_ID ("addLocalNames (): new state " << *m_state->getDigest ()); |
Alexander Afanasyev | 860e6fe | 2012-03-15 17:30:31 -0700 | [diff] [blame] | 522 | |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame] | 523 | diff = boost::make_shared<DiffState>(); |
Alexander Afanasyev | 1b449c4 | 2012-03-13 20:24:07 -0700 | [diff] [blame] | 524 | diff->update(info, seqN); |
Alexander Afanasyev | 235c6d7 | 2012-03-15 22:28:43 -0700 | [diff] [blame] | 525 | insertToDiffLog (diff); |
Alexander Afanasyev | 1b449c4 | 2012-03-13 20:24:07 -0700 | [diff] [blame] | 526 | } |
| 527 | |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 528 | // _LOG_DEBUG_ID ("PIT size: " << m_syncInterestTable.size ()); |
Alexander Afanasyev | 860e6fe | 2012-03-15 17:30:31 -0700 | [diff] [blame] | 529 | satisfyPendingSyncInterests (diff); |
Zhenkai Zhu | 0efa37b | 2012-03-12 13:54:12 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | void |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 533 | SyncLogic::remove(const Name &prefix) |
Alexander Afanasyev | d91497c | 2012-03-12 15:39:30 -0700 | [diff] [blame] | 534 | { |
Alexander Afanasyev | 1b449c4 | 2012-03-13 20:24:07 -0700 | [diff] [blame] | 535 | DiffStatePtr diff; |
| 536 | { |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 537 | NameInfoConstPtr info = StdNameInfo::FindOrCreate(prefix.toUri()); |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 538 | m_state->remove(info); |
Zhenkai Zhu | 0efa37b | 2012-03-12 13:54:12 -0700 | [diff] [blame] | 539 | |
Zhenkai Zhu | a2e0b08 | 2012-09-26 10:34:15 -0700 | [diff] [blame] | 540 | // increment the sequence number for the forwarder node |
| 541 | NameInfoConstPtr forwarderInfo = StdNameInfo::FindOrCreate(forwarderPrefix); |
Zhenkai Zhu | a2e0b08 | 2012-09-26 10:34:15 -0700 | [diff] [blame] | 542 | |
Alexander Afanasyev | 7e1986f | 2012-10-04 10:21:10 -0700 | [diff] [blame] | 543 | LeafContainer::iterator item = m_state->getLeaves ().find (forwarderInfo); |
| 544 | SeqNo seqNo (0); |
| 545 | if (item != m_state->getLeaves ().end ()) |
| 546 | { |
| 547 | seqNo = (*item)->getSeq (); |
| 548 | ++seqNo; |
| 549 | } |
| 550 | m_state->update (forwarderInfo, seqNo); |
Zhenkai Zhu | a2e0b08 | 2012-09-26 10:34:15 -0700 | [diff] [blame] | 551 | |
Alexander Afanasyev | d95c231 | 2013-11-07 13:45:34 -0800 | [diff] [blame] | 552 | diff = boost::make_shared<DiffState>(); |
Alexander Afanasyev | 1b449c4 | 2012-03-13 20:24:07 -0700 | [diff] [blame] | 553 | diff->remove(info); |
Alexander Afanasyev | 7e1986f | 2012-10-04 10:21:10 -0700 | [diff] [blame] | 554 | diff->update(forwarderInfo, seqNo); |
Zhenkai Zhu | 0efa37b | 2012-03-12 13:54:12 -0700 | [diff] [blame] | 555 | |
Alexander Afanasyev | 235c6d7 | 2012-03-15 22:28:43 -0700 | [diff] [blame] | 556 | insertToDiffLog (diff); |
Alexander Afanasyev | 1b449c4 | 2012-03-13 20:24:07 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Alexander Afanasyev | 860e6fe | 2012-03-15 17:30:31 -0700 | [diff] [blame] | 559 | satisfyPendingSyncInterests (diff); |
Zhenkai Zhu | 0efa37b | 2012-03-12 13:54:12 -0700 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | void |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 563 | SyncLogic::sendSyncInterest () |
Chaoyi Bian | 44fff0c | 2012-03-07 21:07:22 -0800 | [diff] [blame] | 564 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 565 | _LOG_DEBUG_ID("sendSyncInterest"); |
Chaoyi Bian | 89ee2dc | 2012-03-09 14:06:01 -0800 | [diff] [blame] | 566 | |
Alexander Afanasyev | 860e6fe | 2012-03-15 17:30:31 -0700 | [diff] [blame] | 567 | { |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 568 | m_outstandingInterestName = m_syncPrefix; |
| 569 | ostringstream os; |
| 570 | os << *m_state->getDigest(); |
| 571 | m_outstandingInterestName.append(os.str()); |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 572 | _LOG_DEBUG_ID (">> I " << m_outstandingInterestName); |
Alexander Afanasyev | 860e6fe | 2012-03-15 17:30:31 -0700 | [diff] [blame] | 573 | } |
Alexander Afanasyev | bf2b436 | 2012-03-12 23:55:09 -0700 | [diff] [blame] | 574 | |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 575 | _LOG_DEBUG_ID("sendSyncInterest: " << m_outstandingInterestName); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 576 | |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 577 | EventId eventId = m_scheduler.scheduleEvent (time::seconds(m_syncInterestReexpress) + time::milliseconds(GET_RANDOM (m_reexpressionJitter)), |
| 578 | bind (&SyncLogic::sendSyncInterest, this)); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 579 | m_scheduler.cancelEvent (m_reexpressingInterestId); |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 580 | m_reexpressingInterestId = eventId; |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 581 | |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 582 | ndn::Interest interest(m_outstandingInterestName); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 583 | interest.setMustBeFresh(true); |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 584 | |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 585 | m_face->expressInterest(interest, |
Yingdi Yu | 51c8025 | 2014-02-10 19:32:05 -0800 | [diff] [blame^] | 586 | bind(&SyncLogic::onSyncData, this, _1, _2), |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 587 | bind(&SyncLogic::onSyncTimeout, this, _1)); |
Chaoyi Bian | 44fff0c | 2012-03-07 21:07:22 -0800 | [diff] [blame] | 588 | } |
| 589 | |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 590 | void |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 591 | SyncLogic::sendSyncRecoveryInterests (DigestConstPtr digest) |
| 592 | { |
| 593 | ostringstream os; |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 594 | os << *digest; |
| 595 | |
| 596 | Name interestName = m_syncPrefix; |
| 597 | interestName.append("recovery").append(os.str()); |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 598 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 599 | time::Duration nextRetransmission = time::milliseconds (m_recoveryRetransmissionInterval + GET_RANDOM (m_reexpressionJitter)); |
| 600 | |
Alexander Afanasyev | a76010b | 2012-05-24 21:31:49 -0700 | [diff] [blame] | 601 | m_recoveryRetransmissionInterval <<= 1; |
| 602 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 603 | m_scheduler.cancelEvent (m_reexpressingRecoveryInterestId); |
Alexander Afanasyev | a76010b | 2012-05-24 21:31:49 -0700 | [diff] [blame] | 604 | if (m_recoveryRetransmissionInterval < 100*1000) // <100 seconds |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 605 | m_reexpressingRecoveryInterestId = m_scheduler.scheduleEvent (nextRetransmission, |
| 606 | bind (&SyncLogic::sendSyncRecoveryInterests, this, digest)); |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 607 | |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 608 | ndn::Interest interest(interestName); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 609 | interest.setMustBeFresh(true); |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 610 | |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 611 | m_face->expressInterest(interest, |
Yingdi Yu | 51c8025 | 2014-02-10 19:32:05 -0800 | [diff] [blame^] | 612 | bind(&SyncLogic::onSyncData, this, _1, _2), |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 613 | bind(&SyncLogic::onSyncTimeout, this, _1)); |
Alexander Afanasyev | 46eb526 | 2012-05-10 16:30:35 -0700 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | |
| 617 | void |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 618 | SyncLogic::sendSyncData (const Name &name, DigestConstPtr digest, StateConstPtr state) |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 619 | { |
Zhenkai Zhu | 2d3e270 | 2012-10-15 14:18:05 -0700 | [diff] [blame] | 620 | SyncStateMsg msg; |
| 621 | msg << (*state); |
| 622 | sendSyncData(name, digest, msg); |
| 623 | } |
| 624 | |
| 625 | // pass in state msg instead of state, so that there is no need to lock the state until |
| 626 | // this function returns |
| 627 | void |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 628 | SyncLogic::sendSyncData (const Name &name, DigestConstPtr digest, SyncStateMsg &ssm) |
Zhenkai Zhu | 2d3e270 | 2012-10-15 14:18:05 -0700 | [diff] [blame] | 629 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 630 | _LOG_DEBUG_ID (">> D " << name); |
Zhenkai Zhu | 3cfdcb9 | 2012-06-06 15:20:10 -0700 | [diff] [blame] | 631 | int size = ssm.ByteSize(); |
| 632 | char *wireData = new char[size]; |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 633 | ssm.SerializeToArray(wireData, size); |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 634 | |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 635 | Data syncData(name); |
| 636 | syncData.setContent(reinterpret_cast<const uint8_t*>(wireData), size); |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 637 | syncData.setFreshnessPeriod(m_syncResponseFreshness); |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 638 | |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 639 | m_keyChain->sign(syncData); |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 640 | |
Yingdi Yu | 6d638f0 | 2014-01-24 11:01:21 -0800 | [diff] [blame] | 641 | m_face->put(syncData); |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame] | 642 | |
Chaoyi Bian | 6665d5a | 2012-06-07 14:16:44 -0700 | [diff] [blame] | 643 | delete []wireData; |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 644 | |
Alexander Afanasyev | 282a10b | 2012-05-09 12:56:38 -0700 | [diff] [blame] | 645 | // checking if our own interest got satisfied |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 646 | bool satisfiedOwnInterest = false; |
| 647 | { |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 648 | satisfiedOwnInterest = (m_outstandingInterestName == name); |
| 649 | } |
| 650 | |
| 651 | if (satisfiedOwnInterest) |
| 652 | { |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 653 | _LOG_DEBUG_ID ("Satisfied our own Interest. Re-expressing (hopefully with a new digest)"); |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 654 | |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 655 | time::Duration after = time::milliseconds(GET_RANDOM (m_reexpressionJitter)); |
Alexander Afanasyev | 531803b | 2014-02-05 15:57:35 -0800 | [diff] [blame] | 656 | // cout << "------------ reexpress interest after: " << after << endl; |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 657 | EventId eventId = m_scheduler.scheduleEvent (after, |
| 658 | bind (&SyncLogic::sendSyncInterest, this)); |
Yingdi Yu | 280bb96 | 2014-01-30 09:52:43 -0800 | [diff] [blame] | 659 | m_scheduler.cancelEvent (m_reexpressingInterestId); |
Yingdi Yu | 7ad4e4f | 2014-02-03 18:27:36 -0800 | [diff] [blame] | 660 | m_reexpressingInterestId = eventId; |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 661 | } |
| 662 | } |
| 663 | |
Zhenkai Zhu | e566093 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 664 | string |
| 665 | SyncLogic::getRootDigest() |
| 666 | { |
| 667 | ostringstream os; |
Zhenkai Zhu | e566093 | 2012-06-04 15:25:20 -0700 | [diff] [blame] | 668 | os << *m_state->getDigest(); |
| 669 | return os.str(); |
| 670 | } |
| 671 | |
Alexander Afanasyev | 8023738 | 2012-10-04 10:20:47 -0700 | [diff] [blame] | 672 | size_t |
| 673 | SyncLogic::getNumberOfBranches () const |
| 674 | { |
Alexander Afanasyev | 8023738 | 2012-10-04 10:20:47 -0700 | [diff] [blame] | 675 | return m_state->getLeaves ().size (); |
| 676 | } |
| 677 | |
Alexander Afanasyev | 5548c04 | 2012-10-04 19:10:09 -0700 | [diff] [blame] | 678 | void |
| 679 | SyncLogic::printState () const |
| 680 | { |
Alexander Afanasyev | 5548c04 | 2012-10-04 19:10:09 -0700 | [diff] [blame] | 681 | BOOST_FOREACH (const boost::shared_ptr<Sync::Leaf> leaf, m_state->getLeaves ()) |
| 682 | { |
| 683 | std::cout << *leaf << std::endl; |
| 684 | } |
| 685 | } |
| 686 | |
Zhenkai Zhu | d5aec4b | 2012-10-09 12:01:19 -0700 | [diff] [blame] | 687 | std::map<std::string, bool> |
| 688 | SyncLogic::getBranchPrefixes() const |
| 689 | { |
Zhenkai Zhu | d5aec4b | 2012-10-09 12:01:19 -0700 | [diff] [blame] | 690 | std::map<std::string, bool> m; |
| 691 | |
| 692 | BOOST_FOREACH (const boost::shared_ptr<Sync::Leaf> leaf, m_state->getLeaves ()) |
| 693 | { |
| 694 | std::string prefix = leaf->getInfo()->toString(); |
| 695 | // do not return forwarder prefix |
| 696 | if (prefix != forwarderPrefix) |
| 697 | { |
| 698 | m.insert(pair<std::string, bool>(prefix, false)); |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | return m; |
| 703 | } |
Alexander Afanasyev | f3c03a9 | 2012-05-09 12:00:37 -0700 | [diff] [blame] | 704 | |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 705 | } |