| /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| /* |
| * Copyright (c) 2012 University of California, Los Angeles |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License version 2 as |
| * published by the Free Software Foundation; |
| * |
| * This program is distributed in the hope that it will be useful, |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| * GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License |
| * along with this program; if not, write to the Free Software |
| * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| * |
| * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| * 卞超轶 Chaoyi Bian <bcy@pku.edu.cn> |
| * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| */ |
| |
| #ifndef SYNC_STATE_H |
| #define SYNC_STATE_H |
| |
| extern "C" { |
| #include <ccn/ccn.h> |
| #include <ccn/charbuf.h> |
| #include <ccn/keystore.h> |
| #include <ccn/uri.h> |
| #include <ccn/bloom.h> |
| } |
| |
| #include <boost/thread.hpp> |
| #include <boost/shared_ptr.hpp> |
| /** |
| * \defgroup sync SYNC protocol |
| * |
| * Implementation of SYNC protocol |
| */ |
| namespace Sync { |
| /** |
| * \ingroup sync |
| * @brief Data wrapper with size |
| */ |
| class DataBuffer { |
| private: |
| unsigned char *buffer; |
| size_t len; |
| public: |
| DataBuffer(const unsigned char *buffer, size_t len); |
| DataBuffer(const DataBuffer &dataBuffer); |
| DataBuffer &operator=(const DataBuffer &dataBuffer); |
| ~DataBuffer(); |
| size_t length() {return len;} |
| const unsigned char *buffer() { return const_cast<const unsigned char *> (buffer); } |
| }; |
| |
| /** |
| * \ingroup sync |
| * @brief A wrapper for ccnx library; clients of this code do not need to deal |
| * with ccnx library |
| */ |
| class CcnxWrapper { |
| private: |
| ccn* handle; |
| ccn_keystore *keyStore; |
| ccn_charbuf *keyLoactor; |
| boost::mutex mutex; |
| boost::shared_ptr<boos::thread> thread; |
| |
| private: |
| void createKeyLocator(); |
| void initKeyStore(); |
| const ccn_pkey *getPrivateKey(); |
| const unsigned char *getPublicKeyDigest(); |
| ssize_t getPublicKeyDigestLength(); |
| void ccnLoop(); |
| |
| public: |
| |
| |
| CcnxWrapper(); |
| ~CcnxWrapper(); |
| /** |
| * @brief send Interest |
| * |
| * @param strInterest the Interest name |
| * @param callback the callback function to deal with the returned data |
| */ |
| int sendInterest(string strInterest, boost::function<void (DataBuffer &)> processData); |
| int sendInterestFilter(string prefix, boost::function<void (string)> |
| processInterest); |
| int publishData(string name, DataBuffer &dataBuffer); |
| |
| }; |
| |
| } // Sync |
| |
| #endif // SYNC_STATE_H |