blob: 6d56764fe57b8339124d821b7f344497d5484027 [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>
Chaoyi Bian3e1eb162012-04-03 16:59:32 -070019 * Chaoyi Bian <bcy@pku.edu.cn>
Zhenkai Zhu8d935c82012-03-06 10:44:12 -080020 * 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
Chaoyi Bianf007f922012-04-09 20:05:37 -070037INIT_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 Afanasyev235c6d72012-03-15 22:28:43 -0700143 DiffStateConstPtr stateDiff = (*stateInDiffLog)->diff ();
144 // string state = lexical_cast<string> (*stateDiff);
145 // erase_all (state, "\n");
146 // _LOG_TRACE (">> D " << interestName << ", state: " << state);
147 // _LOG_DEBUG ("Log size: " << m_log.size ());
148
149 // BOOST_FOREACH (DiffStateConstPtr ds, m_log.get<sequenced> ())
150 // {
151 // string state = lexical_cast<string> (*ds);
152 // erase_all (state, "\n");
153 // _LOG_DEBUG (" " << state << ", " << *ds->getDigest ());
154 // }
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700155
156 m_syncInterestTable.remove (interestName);
Alexander Afanasyev387ac952012-03-11 23:49:27 -0700157 m_ccnxHandle->publishData (interestName,
Alexander Afanasyev235c6d72012-03-15 22:28:43 -0700158 lexical_cast<string> (*stateDiff),
Alexander Afanasyev387ac952012-03-11 23:49:27 -0700159 m_syncResponseFreshness);
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700160 if (m_outstandingInterest == interestName)
161 {
162 m_scheduler.schedule (posix_time::seconds (0),
163 bind (&SyncLogic::sendSyncInterest, this),
164 REEXPRESSING_INTEREST);
165 }
Alexander Afanasyev387ac952012-03-11 23:49:27 -0700166 return;
167 }
168
169 if (!timedProcessing)
170 {
Alexander Afanasyevbf2b4362012-03-12 23:55:09 -0700171 m_scheduler.schedule (posix_time::milliseconds (m_rangeUniformRandom ()) /*from 20 to 100ms*/,
172 bind (&SyncLogic::processSyncInterest, this, digest, interestName, true),
173 DELAYED_INTEREST_PROCESSING);
Alexander Afanasyev387ac952012-03-11 23:49:27 -0700174
Alexander Afanasyev387ac952012-03-11 23:49:27 -0700175 }
176 else
177 {
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700178 _LOG_TRACE (">> D " << interestName << "/state" << " (timed processing)");
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700179
180 m_syncInterestTable.remove (interestName + "/state");
Alexander Afanasyev387ac952012-03-11 23:49:27 -0700181 m_ccnxHandle->publishData (interestName + "/state",
182 lexical_cast<string> (m_state),
183 m_syncResponseFreshness);
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700184
185 if (m_outstandingInterest == interestName)
186 {
187 m_scheduler.schedule (posix_time::seconds (0),
188 bind (&SyncLogic::sendSyncInterest, this),
189 REEXPRESSING_INTEREST);
190 }
Alexander Afanasyev387ac952012-03-11 23:49:27 -0700191 }
Chaoyi Bian44fff0c2012-03-07 21:07:22 -0800192}
193
Alexander Afanasyevc1030192012-03-08 22:21:28 -0800194void
195SyncLogic::processSyncData (const string &name, const string &dataBuffer)
Chaoyi Bian44fff0c2012-03-07 21:07:22 -0800196{
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700197 _LOG_TRACE ("<< D " << name);
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700198 DiffStatePtr diffLog = make_shared<DiffState> ();
Alexander Afanasyeve4e2bf72012-03-12 12:44:54 -0700199
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700200 try
201 {
202 recursive_mutex::scoped_lock lock (m_stateMutex);
203
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700204 string last = name.substr(name.find_last_of("/") + 1);
205 istringstream ss (dataBuffer);
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700206
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700207 if (last == "state")
208 {
209 FullState full;
210 ss >> full;
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700211 BOOST_FOREACH (LeafConstPtr leaf, full.getLeaves()) // order doesn't matter
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700212 {
213 NameInfoConstPtr info = leaf->getInfo ();
214 SeqNo seq = leaf->getSeq ();
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700215
216 bool inserted = false;
217 bool updated = false;
218 SeqNo oldSeq;
219 tie (inserted, updated, oldSeq) = m_state.update (info, seq);
Chaoyi Bian89ee2dc2012-03-09 14:06:01 -0800220
Alexander Afanasyevd4adce52012-03-13 13:59:39 -0700221 if (inserted || updated)
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700222 {
223 diffLog->update (info, seq);
Chaoyi Bian98135192012-03-27 18:34:11 -0700224 m_onUpdate (info->toString (), seq, oldSeq);
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700225 }
226 }
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700227 }
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700228 else
229 {
230 DiffState diff;
231 ss >> diff;
232 BOOST_FOREACH (LeafConstPtr leaf, diff.getLeaves().get<ordered>())
233 {
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700234 DiffLeafConstPtr diffLeaf = dynamic_pointer_cast<const DiffLeaf> (leaf);
235 BOOST_ASSERT (diffLeaf != 0);
236
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700237 NameInfoConstPtr info = diffLeaf->getInfo();
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700238 if (diffLeaf->getOperation() == UPDATE)
239 {
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700240 SeqNo seq = diffLeaf->getSeq();
Chaoyi Bian89ee2dc2012-03-09 14:06:01 -0800241
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700242 bool inserted = false;
243 bool updated = false;
244 SeqNo oldSeq;
245 tie (inserted, updated, oldSeq) = m_state.update (info, seq);
Chaoyi Bian89ee2dc2012-03-09 14:06:01 -0800246
Alexander Afanasyevd4adce52012-03-13 13:59:39 -0700247 if (inserted || updated)
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700248 {
249 diffLog->update (info, seq);
Chaoyi Bian98135192012-03-27 18:34:11 -0700250 m_onUpdate (info->toString (), seq, oldSeq);
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700251 }
252 }
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700253 else if (diffLeaf->getOperation() == REMOVE)
254 {
255 if (m_state.remove (info))
256 {
257 diffLog->remove (info);
258 m_onRemove (info->toString ());
259 }
260 }
261 else
262 {
263 BOOST_ASSERT (false); // just in case
264 }
265 }
266 }
267
Alexander Afanasyev235c6d72012-03-15 22:28:43 -0700268 insertToDiffLog (diffLog);
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700269 }
270 catch (Error::SyncXmlDecodingFailure &e)
271 {
Alexander Afanasyevd4cca472012-03-13 14:25:46 -0700272 diffLog.reset ();
273 // don't do anything
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700274 }
275
Alexander Afanasyevd4cca472012-03-13 14:25:46 -0700276 // if state has changed, then it is safe to express a new interest
Alexander Afanasyev750d1872012-03-12 15:33:56 -0700277 if (diffLog->getLeaves ().size () > 0)
278 {
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700279 m_scheduler.schedule (posix_time::seconds (0),
280 bind (&SyncLogic::sendSyncInterest, this),
281 REEXPRESSING_INTEREST);
Alexander Afanasyevd4cca472012-03-13 14:25:46 -0700282 }
283 else
284 {
285 // should not reexpress the same interest. Need at least wait for data lifetime
286 // Otherwise we will get immediate reply from the local daemon and there will be 100% utilization
287 m_scheduler.cancel (REEXPRESSING_INTEREST);
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700288 // m_scheduler.schedule (posix_time::seconds (0),
289 m_scheduler.schedule (posix_time::seconds (m_syncResponseFreshness) + posix_time::milliseconds (1),
Alexander Afanasyevd4cca472012-03-13 14:25:46 -0700290 bind (&SyncLogic::sendSyncInterest, this),
291 REEXPRESSING_INTEREST);
Alexander Afanasyev04fd8a82012-03-12 15:40:48 -0700292 }
Chaoyi Bian44fff0c2012-03-07 21:07:22 -0800293}
294
Alexander Afanasyevc1030192012-03-08 22:21:28 -0800295void
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700296SyncLogic::satisfyPendingSyncInterests (DiffStatePtr diffLog)
Chaoyi Bian44fff0c2012-03-07 21:07:22 -0800297{
Alexander Afanasyevc1030192012-03-08 22:21:28 -0800298 vector<string> pis = m_syncInterestTable.fetchAll ();
Alexander Afanasyevbf2b4362012-03-12 23:55:09 -0700299 if (pis.size () > 0)
300 {
Alexander Afanasyevf07ab352012-03-13 12:57:46 -0700301 stringstream ss;
Alexander Afanasyevbf2b4362012-03-12 23:55:09 -0700302 ss << *diffLog;
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700303 bool satisfiedOwnInterest = false;
304
Alexander Afanasyevf07ab352012-03-13 12:57:46 -0700305 for (vector<string>::iterator ii = pis.begin(); ii != pis.end(); ++ii)
306 {
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700307 _LOG_TRACE (">> D " << *ii);
Alexander Afanasyevf07ab352012-03-13 12:57:46 -0700308 m_ccnxHandle->publishData (*ii, ss.str(), m_syncResponseFreshness);
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700309
310 {
311 recursive_mutex::scoped_lock lock (m_stateMutex);
312 // _LOG_DEBUG (*ii << " == " << m_outstandingInterest << " = " << (*ii == m_outstandingInterest));
313 satisfiedOwnInterest = satisfiedOwnInterest || (*ii == m_outstandingInterest) || (*ii == (m_outstandingInterest + "/state"));
314 }
315 }
316
317 if (satisfiedOwnInterest)
318 {
319 _LOG_DEBUG ("Have satisfied our own interest. Scheduling interest reexpression");
320 // we need to reexpress interest only if we satisfied our own interest
321 m_scheduler.schedule (posix_time::milliseconds (0),
322 bind (&SyncLogic::sendSyncInterest, this),
323 REEXPRESSING_INTEREST);
Alexander Afanasyevf07ab352012-03-13 12:57:46 -0700324 }
325 }
Chaoyi Bian44fff0c2012-03-07 21:07:22 -0800326}
327
Alexander Afanasyevc1030192012-03-08 22:21:28 -0800328void
Alexander Afanasyev235c6d72012-03-15 22:28:43 -0700329SyncLogic::insertToDiffLog (DiffStatePtr diffLog)
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700330{
331 //cout << "Process Pending Interests" <<endl;
332 diffLog->setDigest (m_state.getDigest());
333 if (m_log.size () > 0)
334 {
335 m_log.get<sequenced> ().front ()->setNext (diffLog);
336 }
337 m_log.erase (m_state.getDigest()); // remove diff state with the same digest. next pointers are still valid
338 /// @todo Optimization
Alexander Afanasyev7df73332012-03-15 12:31:49 -0700339 m_log.get<sequenced> ().push_front (diffLog);
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700340 // _LOG_DEBUG (*diffLog->getDigest () << " " << m_log.size ());
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700341}
342
343void
Zhenkai Zhu0efa37b2012-03-12 13:54:12 -0700344SyncLogic::addLocalNames (const string &prefix, uint32_t session, uint32_t seq)
345{
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700346 DiffStatePtr diff;
347 {
348 //cout << "Add local names" <<endl;
349 recursive_mutex::scoped_lock lock (m_stateMutex);
350 NameInfoConstPtr info = StdNameInfo::FindOrCreate(prefix);
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700351
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700352 SeqNo seqN (session, seq);
353 m_state.update(info, seqN);
Zhenkai Zhu0efa37b2012-03-12 13:54:12 -0700354
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700355 _LOG_DEBUG ("addLocalNames (): new state " << *m_state.getDigest ());
356
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700357 diff = make_shared<DiffState>();
358 diff->update(info, seqN);
Alexander Afanasyev235c6d72012-03-15 22:28:43 -0700359 insertToDiffLog (diff);
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700360 }
361
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700362 // _LOG_DEBUG ("PIT size: " << m_syncInterestTable.size ());
363 satisfyPendingSyncInterests (diff);
Zhenkai Zhu0efa37b2012-03-12 13:54:12 -0700364}
365
366void
Alexander Afanasyevd91497c2012-03-12 15:39:30 -0700367SyncLogic::remove(const string &prefix)
368{
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700369 DiffStatePtr diff;
370 {
371 recursive_mutex::scoped_lock lock (m_stateMutex);
372 NameInfoConstPtr info = StdNameInfo::FindOrCreate(prefix);
373 m_state.remove(info);
Zhenkai Zhu0efa37b2012-03-12 13:54:12 -0700374
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700375 diff = make_shared<DiffState>();
376 diff->remove(info);
Zhenkai Zhu0efa37b2012-03-12 13:54:12 -0700377
Alexander Afanasyev235c6d72012-03-15 22:28:43 -0700378 insertToDiffLog (diff);
Alexander Afanasyev1b449c42012-03-13 20:24:07 -0700379 }
380
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700381 satisfyPendingSyncInterests (diff);
Zhenkai Zhu0efa37b2012-03-12 13:54:12 -0700382}
383
384void
Alexander Afanasyevc1030192012-03-08 22:21:28 -0800385SyncLogic::sendSyncInterest ()
Chaoyi Bian44fff0c2012-03-07 21:07:22 -0800386{
Alexander Afanasyev172d2b72012-03-08 23:43:39 -0800387 ostringstream os;
Chaoyi Bian89ee2dc2012-03-09 14:06:01 -0800388
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700389 {
390 // cout << "Sending Sync Interest" << endl;
391 recursive_mutex::scoped_lock lock (m_stateMutex);
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700392
Alexander Afanasyev860e6fe2012-03-15 17:30:31 -0700393 os << m_syncPrefix << "/" << *m_state.getDigest();
394
395 _LOG_TRACE (">> I " << os.str ());
396
397 m_outstandingInterest = os.str ();
398 }
399
Alexander Afanasyev172d2b72012-03-08 23:43:39 -0800400 m_ccnxHandle->sendInterest (os.str (),
401 bind (&SyncLogic::processSyncData, this, _1, _2));
Alexander Afanasyevbf2b4362012-03-12 23:55:09 -0700402
403 m_scheduler.cancel (REEXPRESSING_INTEREST);
404 m_scheduler.schedule (posix_time::seconds (4),
405 bind (&SyncLogic::sendSyncInterest, this),
406 REEXPRESSING_INTEREST);
Chaoyi Bian44fff0c2012-03-07 21:07:22 -0800407}
408
Alexander Afanasyevc1030192012-03-08 22:21:28 -0800409}