blob: 20e541103863fa0b8e7259a2c08c2283452a3d0c [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 Bian44fff0c2012-03-07 21:07:22 -080024
25using namespace std;
26using namespace boost;
27
28namespace Sync
29{
30
Alexander Afanasyevc1030192012-03-08 22:21:28 -080031SyncLogic::SyncLogic (const string &syncPrefix,
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080032 LogicCallback fetch,
Alexander Afanasyevc1030192012-03-08 22:21:28 -080033 CcnxWrapperPtr ccnxHandle)
34 : m_syncPrefix (syncPrefix)
35 , m_fetch (fetch)
36 , m_ccnxHandle (ccnxHandle)
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080037{
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080038}
39
Alexander Afanasyevc1030192012-03-08 22:21:28 -080040SyncLogic::~SyncLogic ()
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080041{
42
43}
44
Alexander Afanasyevc1030192012-03-08 22:21:28 -080045void
46SyncLogic::processSyncData (const string &name, const string &dataBuffer)
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080047{
48
49}
50
Alexander Afanasyevc1030192012-03-08 22:21:28 -080051void
52SyncLogic::addLocalNames (const string &prefix, uint32_t session, uint32_t seq)
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080053{
Chaoyi Bian4194b742012-03-08 17:21:35 -080054 NameInfoConstPtr info = StdNameInfo::FindOrCreate(prefix);
55 SeqNo seqN(session, seq);
56 m_state.update(info, seqN);
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080057}
58
Alexander Afanasyevc1030192012-03-08 22:21:28 -080059void
60SyncLogic::respondSyncInterest (const string &interest)
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080061{
Chaoyi Bian4194b742012-03-08 17:21:35 -080062 string hash = interest.substr(interest.find_last_of("/") + 1);
63
64 Digest digest;
65
66 digest << hash;
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080067
68}
69
Alexander Afanasyevc1030192012-03-08 22:21:28 -080070void
71SyncLogic::sendSyncInterest ()
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080072{
Alexander Afanasyev172d2b72012-03-08 23:43:39 -080073 ostringstream os;
74 os << m_syncPrefix << "/" << m_state.getDigest();
75
76 m_ccnxHandle->sendInterest (os.str (),
77 bind (&SyncLogic::processSyncData, this, _1, _2));
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080078}
79
Alexander Afanasyevc1030192012-03-08 22:21:28 -080080}