blob: 7f052f172e9e1130ee02e30f4f96194997957e73 [file] [log] [blame]
Zhenkai Zhu8d935c82012-03-06 10:44:12 -08001/* -*- 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>
20 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
21 */
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080022
Chaoyi Bian11f294f2012-03-08 14:28:06 -080023#include "sync-logic.h"
Chaoyi Bian89ee2dc2012-03-09 14:06:01 -080024#include "sync-diff-leaf.h"
25#include "sync-full-leaf.h"
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070026#include "sync-log.h"
27
Chaoyi Bian89ee2dc2012-03-09 14:06:01 -080028#include <boost/make_shared.hpp>
29#include <boost/foreach.hpp>
Alexander Afanasyev387ac952012-03-11 23:49:27 -070030#include <boost/lexical_cast.hpp>
31#include <boost/date_time/posix_time/posix_time.hpp>
Zhenkai Zhua5d06d72012-03-09 15:16:24 -080032#include <vector>
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080033
34using namespace std;
35using namespace boost;
36
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -070037// INIT_LOGGER ("SyncLogic");
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070038
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080039namespace Sync
40{
41
Alexander Afanasyev750d1872012-03-12 15:33:56 -070042SyncLogic::SyncLogic (const std::string &syncPrefix,
43 LogicUpdateCallback onUpdate,
Zhenkai Zhuce66e212012-03-12 22:27:19 -070044 LogicRemoveCallback onRemove)
Alexander Afanasyevc1030192012-03-08 22:21:28 -080045 : m_syncPrefix (syncPrefix)
Alexander Afanasyev750d1872012-03-12 15:33:56 -070046 , m_onUpdate (onUpdate)
47 , m_onRemove (onRemove)
Alexander Afanasyev3f93c2b2012-03-13 00:02:31 -070048 , m_ccnxHandle(new CcnxWrapper())
Alexander Afanasyev45fba082012-03-12 18:05:24 -070049 , m_randomGenerator (static_cast<unsigned int> (std::time (0)))
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -070050 , m_rangeUniformRandom (m_randomGenerator, uniform_int<> (20,80))
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080051{
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -070052#ifdef _DEBUG
53#ifdef HAVE_LOG4CXX
54 // _LOG_FUNCTION (syncPrefix);
55 static int id = 0;
56 staticModuleLogger = log4cxx::Logger::getLogger ("SyncLogic." + lexical_cast<string> (id));
57 id ++;
58#endif
59#endif
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070060
Alexander Afanasyev1b449c42012-03-13 20:24:07 -070061 m_ccnxHandle->setInterestFilter (m_syncPrefix,
Alexander Afanasyev387ac952012-03-11 23:49:27 -070062 bind (&SyncLogic::respondSyncInterest, this, _1));
Alexander Afanasyevbf2b4362012-03-12 23:55:09 -070063
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070064 m_scheduler.schedule (posix_time::seconds (0),
65 bind (&SyncLogic::sendSyncInterest, this),
66 REEXPRESSING_INTEREST);
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080067}
68
Alexander Afanasyevc1030192012-03-08 22:21:28 -080069SyncLogic::~SyncLogic ()
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080070{
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -070071 // _LOG_FUNCTION (this);
Alexander Afanasyev1b449c42012-03-13 20:24:07 -070072 // cout << "SyncLogic::~SyncLogic ()" << endl;
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080073
Alexander Afanasyev1b449c42012-03-13 20:24:07 -070074 m_ccnxHandle.reset ();
75}
Alexander Afanasyev387ac952012-03-11 23:49:27 -070076
77void
78SyncLogic::respondSyncInterest (const string &interest)
79{
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070080 _LOG_TRACE ("<< I " << interest);
Alexander Afanasyev1b449c42012-03-13 20:24:07 -070081 //cout << "Respond Sync Interest" << endl;
Alexander Afanasyev387ac952012-03-11 23:49:27 -070082 string hash = interest.substr(interest.find_last_of("/") + 1);
Alexander Afanasyev1b449c42012-03-13 20:24:07 -070083 // cout << "Received Sync Interest: " << hash << endl;
84
Alexander Afanasyev387ac952012-03-11 23:49:27 -070085 DigestPtr digest = make_shared<Digest> ();
86 try
87 {
88 istringstream is (hash);
89 is >> *digest;
90 }
91 catch (Error::DigestCalculationError &e)
92 {
93 // log error. ignoring it for now, later we should log it
94 return;
95 }
96
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -070097 processSyncInterest (digest, interest, false);
Alexander Afanasyev387ac952012-03-11 23:49:27 -070098}
99
100void
101SyncLogic::processSyncInterest (DigestConstPtr digest, const std::string &interestName, bool timedProcessing/*=false*/)
102{
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700103 recursive_mutex::scoped_lock lock (m_stateMutex);
Alexander Afanasyev387ac952012-03-11 23:49:27 -0700104
Alexander Afanasyevdd0eba72012-03-13 13:57:10 -0700105 // Special case when state is not empty and we have received request with zero-root digest
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700106 if (digest->isZero () && !m_state.getDigest()->isZero ())
Alexander Afanasyevdd0eba72012-03-13 13:57:10 -0700107 {
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700108 _LOG_TRACE (">> D " << interestName << "/state" << " (zero)");
109
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700110 m_syncInterestTable.remove (interestName + "/state");
Alexander Afanasyevdd0eba72012-03-13 13:57:10 -0700111 m_ccnxHandle->publishData (interestName + "/state",
112 lexical_cast<string> (m_state),
113 m_syncResponseFreshness);
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700114 if (m_outstandingInterest == interestName)
115 {
116 m_scheduler.schedule (posix_time::seconds (0),
117 bind (&SyncLogic::sendSyncInterest, this),
118 REEXPRESSING_INTEREST);
119 }
Alexander Afanasyevdd0eba72012-03-13 13:57:10 -0700120 return;
121 }
Alexander Afanasyev763855a2012-03-13 14:17:37 -0700122
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700123 if (*m_state.getDigest() == *digest)
124 {
125 // cout << interestName << "\n";
126 if (digest->isZero ())
127 {
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700128 _LOG_TRACE ("processSyncInterest (): Digest is zero, adding /state to PIT");
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700129 m_syncInterestTable.insert (interestName + "/state");
130 }
131 else
132 {
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700133 _LOG_TRACE ("processSyncInterest (): Same state. Adding to PIT");
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700134 m_syncInterestTable.insert (interestName);
135 }
136 return;
137 }
Alexander Afanasyevdd0eba72012-03-13 13:57:10 -0700138
Alexander Afanasyev387ac952012-03-11 23:49:27 -0700139 DiffStateContainer::iterator stateInDiffLog = m_log.find (digest);
140
141 if (stateInDiffLog != m_log.end ())
142 {
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700143 _LOG_TRACE (">> D " << interestName);
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700144
145 m_syncInterestTable.remove (interestName);
Alexander Afanasyev387ac952012-03-11 23:49:27 -0700146 m_ccnxHandle->publishData (interestName,
147 lexical_cast<string> (*(*stateInDiffLog)->diff ()),
148 m_syncResponseFreshness);
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700149 if (m_outstandingInterest == interestName)
150 {
151 m_scheduler.schedule (posix_time::seconds (0),
152 bind (&SyncLogic::sendSyncInterest, this),
153 REEXPRESSING_INTEREST);
154 }
Alexander Afanasyev387ac952012-03-11 23:49:27 -0700155 return;
156 }
157
158 if (!timedProcessing)
159 {
Alexander Afanasyevbf2b4362012-03-12 23:55:09 -0700160 m_scheduler.schedule (posix_time::milliseconds (m_rangeUniformRandom ()) /*from 20 to 100ms*/,
161 bind (&SyncLogic::processSyncInterest, this, digest, interestName, true),
162 DELAYED_INTEREST_PROCESSING);
Alexander Afanasyev387ac952012-03-11 23:49:27 -0700163
Alexander Afanasyev387ac952012-03-11 23:49:27 -0700164 }
165 else
166 {
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700167 _LOG_TRACE (">> D " << interestName << "/state" << " (timed processing)");
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700168
169 m_syncInterestTable.remove (interestName + "/state");
Alexander Afanasyev387ac952012-03-11 23:49:27 -0700170 m_ccnxHandle->publishData (interestName + "/state",
171 lexical_cast<string> (m_state),
172 m_syncResponseFreshness);
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700173
174 if (m_outstandingInterest == interestName)
175 {
176 m_scheduler.schedule (posix_time::seconds (0),
177 bind (&SyncLogic::sendSyncInterest, this),
178 REEXPRESSING_INTEREST);
179 }
Alexander Afanasyev387ac952012-03-11 23:49:27 -0700180 }
Chaoyi Bian44fff0c2012-03-07 21:07:22 -0800181}
182
Alexander Afanasyevc1030192012-03-08 22:21:28 -0800183void
184SyncLogic::processSyncData (const string &name, const string &dataBuffer)
Chaoyi Bian44fff0c2012-03-07 21:07:22 -0800185{
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700186 _LOG_TRACE ("<< D " << name);
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700187 DiffStatePtr diffLog = make_shared<DiffState> ();
Alexander Afanasyeve4e2bf72012-03-12 12:44:54 -0700188
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700189 try
190 {
191 recursive_mutex::scoped_lock lock (m_stateMutex);
192
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700193 string last = name.substr(name.find_last_of("/") + 1);
194 istringstream ss (dataBuffer);
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700195
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700196 if (last == "state")
197 {
198 FullState full;
199 ss >> full;
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700200 BOOST_FOREACH (LeafConstPtr leaf, full.getLeaves()) // order doesn't matter
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700201 {
202 NameInfoConstPtr info = leaf->getInfo ();
203 SeqNo seq = leaf->getSeq ();
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700204
205 bool inserted = false;
206 bool updated = false;
207 SeqNo oldSeq;
208 tie (inserted, updated, oldSeq) = m_state.update (info, seq);
Chaoyi Bian89ee2dc2012-03-09 14:06:01 -0800209
Alexander Afanasyevd4adce52012-03-13 13:59:39 -0700210 if (inserted || updated)
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700211 {
212 diffLog->update (info, seq);
213 m_onUpdate (info->toString (), seq.getSeq(), oldSeq);
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700214 }
215 }
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700216 }
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700217 else
218 {
219 DiffState diff;
220 ss >> diff;
221 BOOST_FOREACH (LeafConstPtr leaf, diff.getLeaves().get<ordered>())
222 {
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700223 DiffLeafConstPtr diffLeaf = dynamic_pointer_cast<const DiffLeaf> (leaf);
224 BOOST_ASSERT (diffLeaf != 0);
225
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700226 NameInfoConstPtr info = diffLeaf->getInfo();
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700227 if (diffLeaf->getOperation() == UPDATE)
228 {
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700229 SeqNo seq = diffLeaf->getSeq();
Chaoyi Bian89ee2dc2012-03-09 14:06:01 -0800230
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700231 bool inserted = false;
232 bool updated = false;
233 SeqNo oldSeq;
234 tie (inserted, updated, oldSeq) = m_state.update (info, seq);
Chaoyi Bian89ee2dc2012-03-09 14:06:01 -0800235
Alexander Afanasyevd4adce52012-03-13 13:59:39 -0700236 if (inserted || updated)
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700237 {
238 diffLog->update (info, seq);
239 m_onUpdate (info->toString (), seq.getSeq(), oldSeq);
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700240 }
241 }
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700242 else if (diffLeaf->getOperation() == REMOVE)
243 {
244 if (m_state.remove (info))
245 {
246 diffLog->remove (info);
247 m_onRemove (info->toString ());
248 }
249 }
250 else
251 {
252 BOOST_ASSERT (false); // just in case
253 }
254 }
255 }
256
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700257 diffLog->setDigest(m_state.getDigest());
Alexander Afanasyeva36b7512012-03-12 16:03:03 -0700258 if (m_log.size () > 0)
259 {
260 m_log.get<sequenced> ().front ()->setNext (diffLog);
261 }
Alexander Afanasyevf0519d22012-03-13 14:00:44 -0700262 m_log.erase (m_state.getDigest());
263 /// @todo Optimization
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700264 m_log.insert (diffLog);
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700265 }
266 catch (Error::SyncXmlDecodingFailure &e)
267 {
Alexander Afanasyevd4cca472012-03-13 14:25:46 -0700268 diffLog.reset ();
269 // don't do anything
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700270 }
271
Alexander Afanasyevd4cca472012-03-13 14:25:46 -0700272 // if state has changed, then it is safe to express a new interest
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700273 if (diffLog->getLeaves ().size () > 0)
274 {
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700275 m_scheduler.schedule (posix_time::seconds (0),
276 bind (&SyncLogic::sendSyncInterest, this),
277 REEXPRESSING_INTEREST);
Alexander Afanasyevd4cca472012-03-13 14:25:46 -0700278 }
279 else
280 {
281 // should not reexpress the same interest. Need at least wait for data lifetime
282 // Otherwise we will get immediate reply from the local daemon and there will be 100% utilization
283 m_scheduler.cancel (REEXPRESSING_INTEREST);
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700284 // m_scheduler.schedule (posix_time::seconds (0),
285 m_scheduler.schedule (posix_time::seconds (m_syncResponseFreshness) + posix_time::milliseconds (1),
Alexander Afanasyevd4cca472012-03-13 14:25:46 -0700286 bind (&SyncLogic::sendSyncInterest, this),
287 REEXPRESSING_INTEREST);
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700288 }
Chaoyi Bian44fff0c2012-03-07 21:07:22 -0800289}
290
Alexander Afanasyevc1030192012-03-08 22:21:28 -0800291void
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700292SyncLogic::satisfyPendingSyncInterests (DiffStatePtr diffLog)
Chaoyi Bian44fff0c2012-03-07 21:07:22 -0800293{
Alexander Afanasyevc1030192012-03-08 22:21:28 -0800294 vector<string> pis = m_syncInterestTable.fetchAll ();
Alexander Afanasyevbf2b4362012-03-12 23:55:09 -0700295 if (pis.size () > 0)
296 {
Alexander Afanasyevf07ab352012-03-13 12:57:46 -0700297 stringstream ss;
Alexander Afanasyevbf2b4362012-03-12 23:55:09 -0700298 ss << *diffLog;
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700299 bool satisfiedOwnInterest = false;
300
Alexander Afanasyevf07ab352012-03-13 12:57:46 -0700301 for (vector<string>::iterator ii = pis.begin(); ii != pis.end(); ++ii)
302 {
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700303 _LOG_TRACE (">> D " << *ii);
Alexander Afanasyevf07ab352012-03-13 12:57:46 -0700304 m_ccnxHandle->publishData (*ii, ss.str(), m_syncResponseFreshness);
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700305
306 {
307 recursive_mutex::scoped_lock lock (m_stateMutex);
308 // _LOG_DEBUG (*ii << " == " << m_outstandingInterest << " = " << (*ii == m_outstandingInterest));
309 satisfiedOwnInterest = satisfiedOwnInterest || (*ii == m_outstandingInterest) || (*ii == (m_outstandingInterest + "/state"));
310 }
311 }
312
313 if (satisfiedOwnInterest)
314 {
315 _LOG_DEBUG ("Have satisfied our own interest. Scheduling interest reexpression");
316 // we need to reexpress interest only if we satisfied our own interest
317 m_scheduler.schedule (posix_time::milliseconds (0),
318 bind (&SyncLogic::sendSyncInterest, this),
319 REEXPRESSING_INTEREST);
Alexander Afanasyevf07ab352012-03-13 12:57:46 -0700320 }
321 }
Chaoyi Bian44fff0c2012-03-07 21:07:22 -0800322}
323
Alexander Afanasyevc1030192012-03-08 22:21:28 -0800324void
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700325SyncLogic::processPendingSyncInterests (DiffStatePtr diffLog)
326{
327 //cout << "Process Pending Interests" <<endl;
328 diffLog->setDigest (m_state.getDigest());
329 if (m_log.size () > 0)
330 {
331 m_log.get<sequenced> ().front ()->setNext (diffLog);
332 }
333 m_log.erase (m_state.getDigest()); // remove diff state with the same digest. next pointers are still valid
334 /// @todo Optimization
Alexander Afanasyev7df73332012-03-15 12:31:49 -0700335 m_log.get<sequenced> ().push_front (diffLog);
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700336 // _LOG_DEBUG (*diffLog->getDigest () << " " << m_log.size ());
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700337}
338
339void
Zhenkai Zhu0efa37b2012-03-12 13:54:12 -0700340SyncLogic::addLocalNames (const string &prefix, uint32_t session, uint32_t seq)
341{
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700342 DiffStatePtr diff;
343 {
344 //cout << "Add local names" <<endl;
345 recursive_mutex::scoped_lock lock (m_stateMutex);
346 NameInfoConstPtr info = StdNameInfo::FindOrCreate(prefix);
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700347
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700348 SeqNo seqN (session, seq);
349 m_state.update(info, seqN);
Zhenkai Zhu0efa37b2012-03-12 13:54:12 -0700350
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700351 _LOG_DEBUG ("addLocalNames (): new state " << *m_state.getDigest ());
352
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700353 diff = make_shared<DiffState>();
354 diff->update(info, seqN);
355 processPendingSyncInterests (diff);
356 }
357
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700358 // _LOG_DEBUG ("PIT size: " << m_syncInterestTable.size ());
359 satisfyPendingSyncInterests (diff);
Zhenkai Zhu0efa37b2012-03-12 13:54:12 -0700360}
361
362void
Alexander Afanasyevd91497c2012-03-12 15:39:30 -0700363SyncLogic::remove(const string &prefix)
364{
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700365 DiffStatePtr diff;
366 {
367 recursive_mutex::scoped_lock lock (m_stateMutex);
368 NameInfoConstPtr info = StdNameInfo::FindOrCreate(prefix);
369 m_state.remove(info);
Zhenkai Zhu0efa37b2012-03-12 13:54:12 -0700370
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700371 diff = make_shared<DiffState>();
372 diff->remove(info);
Zhenkai Zhu0efa37b2012-03-12 13:54:12 -0700373
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700374 processPendingSyncInterests (diff);
375 }
376
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700377 satisfyPendingSyncInterests (diff);
Zhenkai Zhu0efa37b2012-03-12 13:54:12 -0700378}
379
380void
Alexander Afanasyevc1030192012-03-08 22:21:28 -0800381SyncLogic::sendSyncInterest ()
Chaoyi Bian44fff0c2012-03-07 21:07:22 -0800382{
Alexander Afanasyev172d2b72012-03-08 23:43:39 -0800383 ostringstream os;
Chaoyi Bian89ee2dc2012-03-09 14:06:01 -0800384
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700385 {
386 // cout << "Sending Sync Interest" << endl;
387 recursive_mutex::scoped_lock lock (m_stateMutex);
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700388
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700389 os << m_syncPrefix << "/" << *m_state.getDigest();
390
391 _LOG_TRACE (">> I " << os.str ());
392
393 m_outstandingInterest = os.str ();
394 }
395
Alexander Afanasyev172d2b72012-03-08 23:43:39 -0800396 m_ccnxHandle->sendInterest (os.str (),
397 bind (&SyncLogic::processSyncData, this, _1, _2));
Alexander Afanasyevbf2b4362012-03-12 23:55:09 -0700398
399 m_scheduler.cancel (REEXPRESSING_INTEREST);
400 m_scheduler.schedule (posix_time::seconds (4),
401 bind (&SyncLogic::sendSyncInterest, this),
402 REEXPRESSING_INTEREST);
Chaoyi Bian44fff0c2012-03-07 21:07:22 -0800403}
404
Alexander Afanasyevc1030192012-03-08 22:21:28 -0800405}