blob: fb552a22071371873f5b40ade4e936516a0a4eed [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:
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080049 unsigned char *m_buffer;
50 size_t m_len;
Zhenkai Zhu6cc2c812012-03-05 19:48:46 -080051public:
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:
Zhenkai Zhu406f37a2012-03-05 20:23:20 -080067 ccn* m_handle;
68 ccn_keystore *m_keyStore;
69 ccn_charbuf *m_keyLoactor;
70 boost::mutex m_mutex;
71 boost::shared_ptr<boos::thread> m_thread;
Zhenkai Zhu6cc2c812012-03-05 19:48:46 -080072
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