blob: a5650036c4120e0b183270c23065e7a1fb2636d3 [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
Chaoyi Bian11f294f2012-03-08 14:28:06 -080031SyncLogic::SyncLogic(string syncPrefix,
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080032 function<void (string, uint32_t, uint32_t)> fetch,
33 shared_ptr<CcnxWrapper> ccnxHandle)
34{
35 m_syncPrefix = syncPrefix;
36 m_fetch = fetch;
37 m_ccnxHandle = ccnxHandle;
38}
39
Chaoyi Bian11f294f2012-03-08 14:28:06 -080040SyncLogic::~SyncLogic()
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080041{
42
43}
44
Chaoyi Bian4194b742012-03-08 17:21:35 -080045void SyncLogic::processSyncData(string name, string dataBuffer)
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080046{
47
48}
49
Chaoyi Bian4194b742012-03-08 17:21:35 -080050void SyncLogic::addLocalNames(string prefix, uint32_t session, uint32_t seq)
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080051{
Chaoyi Bian4194b742012-03-08 17:21:35 -080052 NameInfoConstPtr info = StdNameInfo::FindOrCreate(prefix);
53 SeqNo seqN(session, seq);
54 m_state.update(info, seqN);
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080055}
56
Chaoyi Bian11f294f2012-03-08 14:28:06 -080057void SyncLogic::respondSyncInterest(string interest)
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080058{
Chaoyi Bian4194b742012-03-08 17:21:35 -080059 string hash = interest.substr(interest.find_last_of("/") + 1);
60
61 Digest digest;
62
63 digest << hash;
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080064
65}
66
Chaoyi Bian11f294f2012-03-08 14:28:06 -080067void SyncLogic::sendSyncInterest()
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080068{
Chaoyi Bian4194b742012-03-08 17:21:35 -080069 function<void (string, string)> f = bind(&SyncLogic::processSyncData, this, _1, _2);
70 stringstream os;
71 os << m_syncPrefix;
72 os << "/";
73 DigestConstPtr digest = m_state.getDigest();
74 os << digest;
75 string name;
76 os >> name;
77 m_ccnxHandle->sendInterest(name, f);
Chaoyi Bian44fff0c2012-03-07 21:07:22 -080078}
79
80}