blob: 11d08785d25e7b522abc3ea2208bd6584b18c7ba [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 Zhu6cc2c812012-03-05 19:48:46 -080037/**
38 * \defgroup sync SYNC protocol
39 *
40 * Implementation of SYNC protocol
41 */
42namespace Sync {
43/**
44 * \ingroup sync
45 * @brief Data wrapper with size
46 */
47 class DataBuffer {
48private:
49 unsigned char *buffer;
50 size_t len;
51public:
52 DataBuffer(const unsigned char *buffer, size_t len);
53 DataBuffer(const DataBuffer &dataBuffer);
54 DataBuffer &operator=(const DataBuffer &dataBuffer);
55 ~DataBuffer();
56 size_t length() {return len;}
57 const unsigned char *buffer() { return const_cast<const unsigned char *> (buffer); }
58};
59
60/**
61 * \ingroup sync
62 * @brief A wrapper for ccnx library; clients of this code do not need to deal
63 * with ccnx library
64 */
65class CcnxWrapper {
66private:
67 ccn* handle;
68 ccn_keystore *keyStore;
69 ccn_charbuf *keyLoactor;
70 boost::mutex mutex;
71 boost::shared_ptr<boos::thread> thread;
72
73private:
74 void createKeyLocator();
75 void initKeyStore();
76 const ccn_pkey *getPrivateKey();
77 const unsigned char *getPublicKeyDigest();
78 ssize_t getPublicKeyDigestLength();
79 void ccnLoop();
80
81public:
82
83
84 CcnxWrapper();
85 ~CcnxWrapper();
86 /**
87 * @brief send Interest
88 *
89 * @param strInterest the Interest name
90 * @param callback the callback function to deal with the returned data
91 */
Zhenkai Zhu774aa182012-03-05 19:54:38 -080092 int sendInterest(std::string strInterest, boost::function<void (DataBuffer &)> processData);
93 int sendInterestFilter(std::string prefix, boost::function<void (std::string)>
Zhenkai Zhu6cc2c812012-03-05 19:48:46 -080094 processInterest);
Zhenkai Zhu774aa182012-03-05 19:54:38 -080095 int publishData(std::string name, DataBuffer &dataBuffer);
Zhenkai Zhu6cc2c812012-03-05 19:48:46 -080096
97};
98
99} // Sync
100
101#endif // SYNC_STATE_H