blob: eaa86cf4c362642b20f05ca8529b83caf1367a4c [file] [log] [blame]
Zhenkai Zhu6cc2c812012-03-05 19:48:46 -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 */
22
23#ifndef SYNC_STATE_H
24#define SYNC_STATE_H
25
26extern "C" {
27#include <ccn/ccn.h>
28#include <ccn/charbuf.h>
29#include <ccn/keystore.h>
30#include <ccn/uri.h>
31#include <ccn/bloom.h>
32}
33
34#include <boost/thread.hpp>
35#include <boost/shared_ptr.hpp>
Zhenkai Zhu774aa182012-03-05 19:54:38 -080036#include <string>
Zhenkai Zhu11a0ad42012-03-05 22:28:33 -080037#include "sync-data-buffer.h"
Zhenkai Zhu6cc2c812012-03-05 19:48:46 -080038/**
39 * \defgroup sync SYNC protocol
40 *
41 * Implementation of SYNC protocol
42 */
43namespace Sync {
Zhenkai Zhu6cc2c812012-03-05 19:48:46 -080044
45/**
46 * \ingroup sync
47 * @brief A wrapper for ccnx library; clients of this code do not need to deal
48 * with ccnx library
49 */
50class CcnxWrapper {
51private:
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080052 ccn* m_handle;
53 ccn_keystore *m_keyStore;
54 ccn_charbuf *m_keyLoactor;
55 boost::mutex m_mutex;
56 boost::shared_ptr<boos::thread> m_thread;
Zhenkai Zhu6cc2c812012-03-05 19:48:46 -080057
58private:
59 void createKeyLocator();
60 void initKeyStore();
61 const ccn_pkey *getPrivateKey();
62 const unsigned char *getPublicKeyDigest();
63 ssize_t getPublicKeyDigestLength();
64 void ccnLoop();
65
66public:
67
68
69 CcnxWrapper();
70 ~CcnxWrapper();
71 /**
72 * @brief send Interest
73 *
74 * @param strInterest the Interest name
75 * @param callback the callback function to deal with the returned data
76 */
Zhenkai Zhu41064062012-03-05 23:49:07 -080077 int sendInterest(std::string strInterest, boost::function<void
78 (boost::shared_ptr<DataBuffer>)> processData);
Zhenkai Zhu774aa182012-03-05 19:54:38 -080079 int sendInterestFilter(std::string prefix, boost::function<void (std::string)>
Zhenkai Zhu6cc2c812012-03-05 19:48:46 -080080 processInterest);
Zhenkai Zhu8d935c82012-03-06 10:44:12 -080081 int publishData(std::string name, boost::shared_ptr<DataBuffer> dataBuffer,
82 int freshness);
Zhenkai Zhu6cc2c812012-03-05 19:48:46 -080083
84};
85
86} // Sync
87
88#endif // SYNC_STATE_H