Zhenkai Zhu | 6cc2c81 | 2012-03-05 19:48:46 -0800 | [diff] [blame] | 1 | /* -*- 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 | |
| 26 | extern "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 Zhu | 774aa18 | 2012-03-05 19:54:38 -0800 | [diff] [blame] | 36 | #include <string> |
Zhenkai Zhu | 11a0ad4 | 2012-03-05 22:28:33 -0800 | [diff] [blame] | 37 | #include "sync-data-buffer.h" |
Zhenkai Zhu | 6cc2c81 | 2012-03-05 19:48:46 -0800 | [diff] [blame] | 38 | /** |
| 39 | * \defgroup sync SYNC protocol |
| 40 | * |
| 41 | * Implementation of SYNC protocol |
| 42 | */ |
| 43 | namespace Sync { |
Zhenkai Zhu | 6cc2c81 | 2012-03-05 19:48:46 -0800 | [diff] [blame] | 44 | |
| 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 | */ |
| 50 | class CcnxWrapper { |
| 51 | private: |
Zhenkai Zhu | 406f37a | 2012-03-05 20:23:20 -0800 | [diff] [blame] | 52 | 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 Zhu | 6cc2c81 | 2012-03-05 19:48:46 -0800 | [diff] [blame] | 57 | |
| 58 | private: |
| 59 | void createKeyLocator(); |
| 60 | void initKeyStore(); |
| 61 | const ccn_pkey *getPrivateKey(); |
| 62 | const unsigned char *getPublicKeyDigest(); |
| 63 | ssize_t getPublicKeyDigestLength(); |
| 64 | void ccnLoop(); |
| 65 | |
| 66 | public: |
| 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 Zhu | 4106406 | 2012-03-05 23:49:07 -0800 | [diff] [blame^] | 77 | int sendInterest(std::string strInterest, boost::function<void |
| 78 | (boost::shared_ptr<DataBuffer>)> processData); |
Zhenkai Zhu | 774aa18 | 2012-03-05 19:54:38 -0800 | [diff] [blame] | 79 | int sendInterestFilter(std::string prefix, boost::function<void (std::string)> |
Zhenkai Zhu | 6cc2c81 | 2012-03-05 19:48:46 -0800 | [diff] [blame] | 80 | processInterest); |
Zhenkai Zhu | 4106406 | 2012-03-05 23:49:07 -0800 | [diff] [blame^] | 81 | int publishData(std::string name, boost::shared_ptr<DataBuffer> dataBuffer); |
Zhenkai Zhu | 6cc2c81 | 2012-03-05 19:48:46 -0800 | [diff] [blame] | 82 | |
| 83 | }; |
| 84 | |
| 85 | } // Sync |
| 86 | |
| 87 | #endif // SYNC_STATE_H |