Adapt sync to use new ndn.cxx api
This commit is contained in:
1 parent
f46eac58f5
commit
43e71613e1
23 files changed
+1468
-54
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+2
-1
@@ -11,7 +11,8 @@ log4j.appender.A1.target=System.err
|
||||
#log4j.appender.A1.layout.ConversionPattern=%d{hh:mm:ss,SSS} %-14t %-14c %m%n
|
||||
log4j.appender.A1.layout.ConversionPattern=%d{ss,SSS} %-12c %m%n
|
||||
|
||||
log4j.logger.SyncLogic = DEBUG
|
||||
log4j.logger.SyncLogic = TRACE
|
||||
log4j.logger.SyncPolicyManager = DEBUG
|
||||
#log4j.logger.SyncInterestTable = TRACE
|
||||
#log4j.logger.AppDataFetch = TRACE
|
||||
log4j.logger.Test = TRACE
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
/* -*- Mode: C32++; 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: Yingdi Yu <yingdi@cs.ucla.edu>
|
||||
*/
|
||||
|
||||
#include "sync-socket.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace ndn;
|
||||
|
||||
namespace Sync {
|
||||
|
||||
SyncSocket::SyncSocket (const string &syncPrefix,
|
||||
Ptr<SyncPolicyManager> syncPolicyManager,
|
||||
NewDataCallback dataCallback,
|
||||
RemoveCallback rmCallback )
|
||||
: m_newDataCallback(dataCallback)
|
||||
, m_syncPolicyManager(syncPolicyManager)
|
||||
, m_syncLogic (syncPrefix,
|
||||
syncPolicyManager,
|
||||
bind(&SyncSocket::passCallback, this, _1),
|
||||
rmCallback)
|
||||
{
|
||||
Ptr<security::Keychain> keychain = Ptr<security::Keychain>(new security::Keychain(Ptr<security::IdentityManager>::Create(), m_syncPolicyManager, NULL));
|
||||
m_handler = Ptr<Wrapper>(new Wrapper(keychain));
|
||||
}
|
||||
|
||||
SyncSocket::~SyncSocket()
|
||||
{}
|
||||
|
||||
bool
|
||||
SyncSocket::publishData(const std::string &prefix, uint32_t session, const char *buf, size_t len, int freshness)
|
||||
{
|
||||
uint32_t sequence = getNextSeq(prefix, session);
|
||||
ostringstream contentNameWithSeqno;
|
||||
contentNameWithSeqno << prefix << "/" << session << "/" << sequence;
|
||||
|
||||
Name dataName(contentNameWithSeqno.str ());
|
||||
Blob blob(buf, len);
|
||||
Name signingIdentity = m_syncPolicyManager->inferSigningIdentity(dataName);
|
||||
|
||||
m_handler->publishDataByIdentity (dataName,
|
||||
blob,
|
||||
signingIdentity,
|
||||
freshness);
|
||||
|
||||
SeqNo s(session, sequence + 1);
|
||||
m_sequenceLog[prefix] = s;
|
||||
m_syncLogic.addLocalNames (prefix, session, sequence);
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
SyncSocket::fetchData(const string &prefix, const SeqNo &seq, const DataCallback& callback, int retry)
|
||||
{
|
||||
ostringstream interestName;
|
||||
interestName << prefix << "/" << seq.getSession() << "/" << seq.getSeq();
|
||||
//std::cout << "Socket " << this << " Send Interest <" << interestName.str() << "> for raw data " << endl;
|
||||
|
||||
|
||||
Ptr<ndn::Interest> interestPtr = Ptr<ndn::Interest>(new ndn::Interest(interestName.str()));
|
||||
Ptr<Closure> closure = Ptr<Closure> (new Closure(callback,
|
||||
boost::bind(&SyncSocket::onChatDataTimeout,
|
||||
this,
|
||||
_1,
|
||||
_2,
|
||||
retry),
|
||||
boost::bind(&SyncSocket::onChatDataUnverified,
|
||||
this,
|
||||
_1)));
|
||||
m_handler->sendInterest(interestPtr, closure);
|
||||
}
|
||||
|
||||
void
|
||||
SyncSocket::onChatDataTimeout(Ptr<Closure> closure, Ptr<ndn::Interest> interest, int retry)
|
||||
{
|
||||
if(retry > 0)
|
||||
{
|
||||
Ptr<Closure> newClosure = Ptr<Closure>(new Closure(closure->m_dataCallback,
|
||||
boost::bind(&SyncSocket::onChatDataTimeout,
|
||||
this,
|
||||
_1,
|
||||
_2,
|
||||
retry - 1),
|
||||
closure->m_unverifiedCallback,
|
||||
closure->m_stepCount)
|
||||
);
|
||||
m_handler->sendInterest(interest, newClosure);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SyncSocket::onChatDataUnverified(Ptr<Data> data)
|
||||
{}
|
||||
|
||||
|
||||
uint32_t
|
||||
SyncSocket::getNextSeq (const string &prefix, uint32_t session)
|
||||
{
|
||||
SequenceLog::iterator i = m_sequenceLog.find (prefix);
|
||||
|
||||
if (i != m_sequenceLog.end ())
|
||||
{
|
||||
SeqNo s = i->second;
|
||||
if (s.getSession() == session)
|
||||
return s.getSeq();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}//Sync
|
||||
@@ -0,0 +1,111 @@
|
||||
/* -*- 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: Yingdi Yu <yingdi@cs.ucla.edu>
|
||||
*/
|
||||
|
||||
#ifndef SYNC_SOCKET_H
|
||||
#define SYNC_SOCKET_H
|
||||
|
||||
#include "sync-logic.h"
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include "sync-seq-no.h"
|
||||
#include <ndn.cxx/wrapper/wrapper.h>
|
||||
#include <utility>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
namespace Sync {
|
||||
|
||||
/**
|
||||
* \ingroup sync
|
||||
* @brief A simple interface to interact with client code
|
||||
*/
|
||||
class SyncSocket
|
||||
{
|
||||
public:
|
||||
typedef boost::function< void (const std::vector<MissingDataInfo> &, SyncSocket * ) > NewDataCallback;
|
||||
typedef boost::function< void ( const std::string &/*prefix*/ ) > RemoveCallback;
|
||||
/**
|
||||
* @brief the constructor for SyncAppSocket; the parameter syncPrefix
|
||||
* should be passed to the constructor of m_syncAppWrapper; the other
|
||||
* parameter should be passed to the constructor of m_fetcher; furthermore,
|
||||
* the fetch function of m_fetcher should be a second paramter passed to
|
||||
* the constructor of m_syncAppWrapper, so that m_syncAppWrapper can tell
|
||||
* m_fetcher to fetch the actual app data after it learns the names
|
||||
*
|
||||
* @param syncPrefix the name prefix for Sync Interest
|
||||
* @param dataCallback the callback to process data
|
||||
*/
|
||||
SyncSocket (const std::string &syncPrefix,
|
||||
ndn::Ptr<SyncPolicyManager> syncPolicyManager,
|
||||
NewDataCallback dataCallback,
|
||||
RemoveCallback rmCallback);
|
||||
|
||||
~SyncSocket ();
|
||||
|
||||
bool
|
||||
publishData(const std::string &prefix, uint32_t session, const char *buf, size_t len, int freshness);
|
||||
|
||||
void
|
||||
remove (const std::string &prefix)
|
||||
{ m_syncLogic.remove(prefix); }
|
||||
|
||||
void
|
||||
fetchData(const std::string &prefix, const SeqNo &seq, const ndn::DataCallback& callback, int retry = 0);
|
||||
|
||||
std::string
|
||||
getRootDigest()
|
||||
{ return m_syncLogic.getRootDigest(); }
|
||||
|
||||
uint32_t
|
||||
getNextSeq (const std::string &prefix, uint32_t session);
|
||||
|
||||
SyncLogic &
|
||||
getLogic ()
|
||||
{ return m_syncLogic; }
|
||||
|
||||
// make this a static function so we don't have to create socket instance without
|
||||
// knowing the local prefix. it's a wrong place for this function anyway
|
||||
static std::string
|
||||
GetLocalPrefix ();
|
||||
|
||||
private:
|
||||
void
|
||||
passCallback(const std::vector<MissingDataInfo> &v)
|
||||
{ m_newDataCallback(v, this); }
|
||||
|
||||
void
|
||||
onChatDataTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, int retry);
|
||||
|
||||
void
|
||||
onChatDataUnverified(ndn::Ptr<ndn::Data> data);
|
||||
|
||||
private:
|
||||
typedef boost::unordered_map<std::string, SeqNo> SequenceLog;
|
||||
NewDataCallback m_newDataCallback;
|
||||
SequenceLog m_sequenceLog;
|
||||
ndn::Ptr<SyncPolicyManager> m_syncPolicyManager;
|
||||
ndn::Ptr<ndn::Wrapper> m_handler;
|
||||
SyncLogic m_syncLogic;
|
||||
};
|
||||
|
||||
} // Sync
|
||||
|
||||
#endif // SYNC_SOCKET_H
|
||||
@@ -0,0 +1,50 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
|
||||
/*
|
||||
* Copyright (c) 2013, Regents of the University of California
|
||||
* Yingdi Yu
|
||||
*
|
||||
* BSD license, See the LICENSE file for more information
|
||||
*
|
||||
* Author: Yingdi Yu <yingdi@cs.ucla.edu>
|
||||
*/
|
||||
|
||||
#include "specific-policy-rule.h"
|
||||
#include <ndn.cxx/fields/signature-sha256-with-rsa.h>
|
||||
|
||||
using namespace ndn;
|
||||
using namespace std;
|
||||
using namespace ndn::security;
|
||||
|
||||
|
||||
SpecificPolicyRule::SpecificPolicyRule(Ptr<Regex> dataRegex,
|
||||
Ptr<Regex> signerRegex)
|
||||
: PolicyRule(PolicyRule::IDENTITY_POLICY, true)
|
||||
, m_dataRegex(dataRegex)
|
||||
, m_signerRegex(signerRegex)
|
||||
{}
|
||||
|
||||
SpecificPolicyRule::SpecificPolicyRule(const SpecificPolicyRule& rule)
|
||||
: PolicyRule(PolicyRule::IDENTITY_POLICY, true)
|
||||
, m_dataRegex(rule.m_dataRegex)
|
||||
, m_signerRegex(rule.m_signerRegex)
|
||||
{}
|
||||
|
||||
bool
|
||||
SpecificPolicyRule::matchDataName(const Data & data)
|
||||
{ return m_dataRegex->match(data.getName()); }
|
||||
|
||||
bool
|
||||
SpecificPolicyRule::matchSignerName(const Data & data)
|
||||
{
|
||||
Ptr<const signature::Sha256WithRsa> sigPtr = DynamicCast<const signature::Sha256WithRsa> (data.getSignature());
|
||||
Name signerName = sigPtr->getKeyLocator ().getKeyName ();
|
||||
return m_signerRegex->match(signerName);
|
||||
}
|
||||
|
||||
bool
|
||||
SpecificPolicyRule::satisfy(const Data & data)
|
||||
{ return (matchDataName(data) && matchSignerName(data)) ? true : false ; }
|
||||
|
||||
bool
|
||||
SpecificPolicyRule::satisfy(const Name & dataName, const Name & signerName)
|
||||
{ return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName)); }
|
||||
@@ -0,0 +1,46 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
|
||||
/*
|
||||
* Copyright (c) 2013, Regents of the University of California
|
||||
* Yingdi Yu
|
||||
*
|
||||
* BSD license, See the LICENSE file for more information
|
||||
*
|
||||
* Author: Yingdi Yu <yingdi@cs.ucla.edu>
|
||||
*/
|
||||
|
||||
#ifndef SPECIFIC_POLICY_RULE_H
|
||||
#define SPECIFIC_POLICY_RULE_H
|
||||
|
||||
#include <ndn.cxx/security/policy/policy-rule.h>
|
||||
#include <ndn.cxx/regex/regex.h>
|
||||
|
||||
class SpecificPolicyRule : public ndn::security::PolicyRule
|
||||
{
|
||||
|
||||
public:
|
||||
SpecificPolicyRule(ndn::Ptr<ndn::Regex> dataRegex,
|
||||
ndn::Ptr<ndn::Regex> signerRegex);
|
||||
|
||||
SpecificPolicyRule(const SpecificPolicyRule& rule);
|
||||
|
||||
virtual
|
||||
~SpecificPolicyRule() {};
|
||||
|
||||
bool
|
||||
matchDataName(const ndn::Data & data);
|
||||
|
||||
bool
|
||||
matchSignerName(const ndn::Data & data);
|
||||
|
||||
bool
|
||||
satisfy(const ndn::Data & data);
|
||||
|
||||
bool
|
||||
satisfy(const ndn::Name & dataName, const ndn::Name & signerName);
|
||||
|
||||
private:
|
||||
ndn::Ptr<ndn::Regex> m_dataRegex;
|
||||
ndn::Ptr<ndn::Regex> m_signerRegex;
|
||||
};
|
||||
|
||||
#endif //CHAT_POLICY_RULE_H
|
||||
@@ -0,0 +1,213 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
|
||||
/*
|
||||
* Copyright (c) 2013, Regents of the University of California
|
||||
* Yingdi Yu
|
||||
*
|
||||
* BSD license, See the LICENSE file for more information
|
||||
*
|
||||
* Author: Yingdi Yu <yingdi@cs.ucla.edu>
|
||||
*/
|
||||
|
||||
#include "sync-intro-certificate.h"
|
||||
#include <ndn.cxx/security/exception.h>
|
||||
|
||||
using namespace ndn;
|
||||
using namespace ndn::security;
|
||||
using namespace std;
|
||||
|
||||
SyncIntroCertificate::SyncIntroCertificate ()
|
||||
: Certificate()
|
||||
{}
|
||||
|
||||
SyncIntroCertificate::SyncIntroCertificate (const Name& nameSpace,
|
||||
const Name& keyName,
|
||||
const Name& signerName,
|
||||
const Time& notBefore,
|
||||
const Time& notAfter,
|
||||
const Publickey& key,
|
||||
const IntroType& introType)
|
||||
: m_keyName(keyName)
|
||||
, m_introType(introType)
|
||||
{
|
||||
Name certificateName = nameSpace;
|
||||
certificateName.append("WOT").append(keyName).append("INTRO-CERT").append(signerName);
|
||||
switch(introType)
|
||||
{
|
||||
case PRODUCER:
|
||||
certificateName.append("PRODUCER");
|
||||
break;
|
||||
case INTRODUCER:
|
||||
certificateName.append("INTRODUCER");
|
||||
break;
|
||||
default:
|
||||
throw SecException("Wrong Introduction Type!");
|
||||
}
|
||||
certificateName.appendVersion();
|
||||
|
||||
setName(certificateName);
|
||||
setNotBefore(notBefore);
|
||||
setNotAfter(notAfter);
|
||||
setPublicKeyInfo(key);
|
||||
addSubjectDescription(CertificateSubDescrypt("2.5.4.41", keyName.toUri()));
|
||||
}
|
||||
|
||||
SyncIntroCertificate::SyncIntroCertificate (const Name& nameSpace,
|
||||
const IdentityCertificate& identityCertificate,
|
||||
const Name& signerName,
|
||||
const IntroType& introType)
|
||||
: m_introType(introType)
|
||||
{
|
||||
m_keyName = identityCertificate.getPublicKeyName();
|
||||
|
||||
Name certificateName = nameSpace;
|
||||
certificateName.append("WOT").append(m_keyName).append("INTRO-CERT").append(signerName);
|
||||
switch(introType)
|
||||
{
|
||||
case PRODUCER:
|
||||
certificateName.append("PRODUCER");
|
||||
break;
|
||||
case INTRODUCER:
|
||||
certificateName.append("INTRODUCER");
|
||||
break;
|
||||
default:
|
||||
throw SecException("Wrong Introduction Type!");
|
||||
}
|
||||
certificateName.appendVersion();
|
||||
|
||||
setName(certificateName);
|
||||
setNotBefore(identityCertificate.getNotBefore());
|
||||
setNotAfter(identityCertificate.getNotAfter());
|
||||
setPublicKeyInfo(identityCertificate.getPublicKeyInfo());
|
||||
addSubjectDescription(CertificateSubDescrypt("2.5.4.41", m_keyName.toUri()));
|
||||
}
|
||||
|
||||
SyncIntroCertificate::SyncIntroCertificate (const Data& data)
|
||||
: Certificate(data)
|
||||
{
|
||||
Name certificateName = getName();
|
||||
int i = 0;
|
||||
int keyNameStart = 0;
|
||||
int keyNameEnd = 0;
|
||||
for(; i < certificateName.size(); i++)
|
||||
{
|
||||
if(certificateName.get(i).toUri() == string("WOT"))
|
||||
{
|
||||
keyNameStart = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(i >= certificateName.size())
|
||||
throw SecException("Wrong SyncIntroCertificate Name!");
|
||||
|
||||
for(; i< certificateName.size(); i++)
|
||||
{
|
||||
if(certificateName.get(i).toUri() == string("INTRO-CERT"))
|
||||
{
|
||||
keyNameEnd = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(i >= certificateName.size())
|
||||
throw SecException("Wrong SyncIntroCertificate Name!");
|
||||
|
||||
m_keyName = certificateName.getSubName(keyNameStart, keyNameEnd);
|
||||
|
||||
string typeComponent = certificateName.get(certificateName.size() - 2).toUri();
|
||||
if(typeComponent == string("PRODUCER"))
|
||||
m_introType = PRODUCER;
|
||||
else if(typeComponent == string("INTRODUCER"))
|
||||
m_introType = INTRODUCER;
|
||||
else
|
||||
throw SecException("Wrong SyncIntroCertificate Name!");
|
||||
}
|
||||
|
||||
SyncIntroCertificate::SyncIntroCertificate (const SyncIntroCertificate& chronosIntroCertificate)
|
||||
: Certificate(chronosIntroCertificate)
|
||||
, m_keyName(chronosIntroCertificate.m_keyName)
|
||||
, m_introType(chronosIntroCertificate.m_introType)
|
||||
{}
|
||||
|
||||
Data &
|
||||
SyncIntroCertificate::setName (const Name& certificateName)
|
||||
{
|
||||
int i = 0;
|
||||
int keyNameStart = 0;
|
||||
int keyNameEnd = 0;
|
||||
for(; i < certificateName.size(); i++)
|
||||
{
|
||||
if(certificateName.get(i).toUri() == string("WOT"))
|
||||
{
|
||||
keyNameStart = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(i >= certificateName.size())
|
||||
throw SecException("Wrong SyncIntroCertificate Name!");
|
||||
|
||||
for(; i< certificateName.size(); i++)
|
||||
{
|
||||
if(certificateName.get(i).toUri() == string("INTRO-CERT"))
|
||||
{
|
||||
keyNameEnd = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(i >= certificateName.size())
|
||||
throw SecException("Wrong SyncIntroCertificate Name!");
|
||||
|
||||
m_keyName = certificateName.getSubName(keyNameStart, keyNameEnd);
|
||||
|
||||
string typeComponent = certificateName.get(certificateName.size() - 2).toUri();
|
||||
if(typeComponent == string("PRODUCER"))
|
||||
m_introType = PRODUCER;
|
||||
else if(typeComponent == string("INTRODUCER"))
|
||||
m_introType = INTRODUCER;
|
||||
else
|
||||
throw SecException("Wrong SyncIntroCertificate Name!");
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool
|
||||
SyncIntroCertificate::isSyncIntroCertificate(const Certificate& certificate)
|
||||
{
|
||||
const Name& certificateName = certificate.getName();
|
||||
string introType = certificateName.get(certificateName.size() - 2).toUri();
|
||||
if(introType != string("PRODUCER") && introType != string("INTRODUCER"))
|
||||
return false;
|
||||
|
||||
int i = 0;
|
||||
bool findWot = false;
|
||||
bool findIntroCert = false;
|
||||
for(; i < certificateName.size(); i++)
|
||||
{
|
||||
if(certificateName.get(i).toUri() == string("WOT"))
|
||||
{
|
||||
findWot = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!findWot)
|
||||
return false;
|
||||
|
||||
for(; i < certificateName.size(); i++)
|
||||
{
|
||||
if(certificateName.get(i).toUri() == string("INTRO-CERT"))
|
||||
{
|
||||
findIntroCert = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!findIntroCert)
|
||||
return false;
|
||||
|
||||
if(i < certificateName.size() - 2)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
|
||||
/*
|
||||
* Copyright (c) 2013, Regents of the University of California
|
||||
* Yingdi Yu
|
||||
*
|
||||
* BSD license, See the LICENSE file for more information
|
||||
*
|
||||
* Author: Yingdi Yu <yingdi@cs.ucla.edu>
|
||||
*/
|
||||
|
||||
#ifndef SYNC_INTRO_CERTIFICATE_H
|
||||
#define SYNC_INTRO_CERTIFICATE_H
|
||||
|
||||
#include <ndn.cxx/security/certificate/certificate.h>
|
||||
#include <ndn.cxx/security/certificate/identity-certificate.h>
|
||||
|
||||
class SyncIntroCertificate : public ndn::security::Certificate
|
||||
{
|
||||
public:
|
||||
enum IntroType{
|
||||
PRODUCER,
|
||||
INTRODUCER
|
||||
};
|
||||
|
||||
public:
|
||||
SyncIntroCertificate ();
|
||||
|
||||
SyncIntroCertificate (const ndn::Name& nameSpace,
|
||||
const ndn::Name& keyName,
|
||||
const ndn::Name& signerName,
|
||||
const ndn::Time& notBefore,
|
||||
const ndn::Time& notAfter,
|
||||
const ndn::security::Publickey& key,
|
||||
const IntroType& introType = PRODUCER);
|
||||
|
||||
SyncIntroCertificate (const ndn::Name& nameSpace,
|
||||
const ndn::security::IdentityCertificate& identityCertificate,
|
||||
const ndn::Name& signerName,
|
||||
const IntroType& introType);
|
||||
|
||||
SyncIntroCertificate (const ndn::Data& data);
|
||||
|
||||
SyncIntroCertificate (const SyncIntroCertificate& chronosIntroCertificate);
|
||||
|
||||
|
||||
virtual
|
||||
~SyncIntroCertificate ()
|
||||
{}
|
||||
|
||||
ndn::Data &
|
||||
setName (const ndn::Name& name);
|
||||
|
||||
inline virtual ndn::Name
|
||||
getPublicKeyName () const
|
||||
{ return m_keyName; }
|
||||
|
||||
inline IntroType
|
||||
getIntroType()
|
||||
{ return m_introType; }
|
||||
|
||||
static bool
|
||||
isSyncIntroCertificate(const ndn::security::Certificate& certificate);
|
||||
|
||||
protected:
|
||||
ndn::Name m_keyName;
|
||||
IntroType m_introType;
|
||||
};
|
||||
|
||||
#endif
|
||||
+104
-38
@@ -38,6 +38,7 @@
|
||||
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
using namespace ndn;
|
||||
|
||||
INIT_LOGGER ("SyncLogic");
|
||||
|
||||
@@ -57,31 +58,36 @@ INIT_LOGGER ("SyncLogic");
|
||||
namespace Sync
|
||||
{
|
||||
|
||||
SyncLogic::SyncLogic (const std::string &syncPrefix,
|
||||
LogicUpdateCallback onUpdate,
|
||||
LogicRemoveCallback onRemove)
|
||||
: m_state (new FullState)
|
||||
, m_syncInterestTable (TIME_SECONDS (m_syncInterestReexpress))
|
||||
, m_syncPrefix (syncPrefix)
|
||||
, m_onUpdate (onUpdate)
|
||||
, m_onRemove (onRemove)
|
||||
, m_perBranch (false)
|
||||
, m_ccnxHandle(new CcnxWrapper ())
|
||||
SyncLogic::SyncLogic (const Name& syncPrefix,
|
||||
Ptr<SyncPolicyManager> syncPolicyManager,
|
||||
LogicUpdateCallback onUpdate,
|
||||
LogicRemoveCallback onRemove)
|
||||
: m_state (new FullState)
|
||||
, m_syncInterestTable (TIME_SECONDS (m_syncInterestReexpress))
|
||||
, m_syncPrefix (syncPrefix)
|
||||
, m_onUpdate (onUpdate)
|
||||
, m_onRemove (onRemove)
|
||||
, m_perBranch (false)
|
||||
, m_policyManager(syncPolicyManager)
|
||||
#ifndef NS3_MODULE
|
||||
, m_randomGenerator (static_cast<unsigned int> (std::time (0)))
|
||||
, m_rangeUniformRandom (m_randomGenerator, uniform_int<> (200,1000))
|
||||
, m_reexpressionJitter (m_randomGenerator, uniform_int<> (100,500))
|
||||
, m_randomGenerator (static_cast<unsigned int> (std::time (0)))
|
||||
, m_rangeUniformRandom (m_randomGenerator, uniform_int<> (200,1000))
|
||||
, m_reexpressionJitter (m_randomGenerator, uniform_int<> (100,500))
|
||||
#else
|
||||
, m_rangeUniformRandom (200,1000)
|
||||
, m_reexpressionJitter (10,500)
|
||||
, m_rangeUniformRandom (200,1000)
|
||||
, m_reexpressionJitter (10,500)
|
||||
#endif
|
||||
, m_recoveryRetransmissionInterval (m_defaultRecoveryRetransmitInterval)
|
||||
, m_recoveryRetransmissionInterval (m_defaultRecoveryRetransmitInterval)
|
||||
{
|
||||
#ifndef NS3_MODULE
|
||||
// In NS3 module these functions are moved to StartApplication method
|
||||
|
||||
m_ccnxHandle->setInterestFilter (m_syncPrefix,
|
||||
bind (&SyncLogic::respondSyncInterest, this, _1));
|
||||
|
||||
Ptr<security::Keychain> keychain = Ptr<security::Keychain>(new security::Keychain(Ptr<security::IdentityManager>::Create(),
|
||||
m_policyManager,
|
||||
NULL));
|
||||
m_handler = Ptr<Wrapper>(new Wrapper(keychain));
|
||||
m_handler->setInterestFilter (m_syncPrefix,
|
||||
bind (&SyncLogic::respondSyncInterest, this, _1));
|
||||
|
||||
m_scheduler.schedule (TIME_SECONDS (0), // no need to add jitter
|
||||
bind (&SyncLogic::sendSyncInterest, this),
|
||||
@@ -89,14 +95,15 @@ SyncLogic::SyncLogic (const std::string &syncPrefix,
|
||||
#endif
|
||||
}
|
||||
|
||||
SyncLogic::SyncLogic (const std::string &syncPrefix,
|
||||
SyncLogic::SyncLogic (const Name& syncPrefix,
|
||||
Ptr<SyncPolicyManager> syncPolicyManager,
|
||||
LogicPerBranchCallback onUpdateBranch)
|
||||
: m_state (new FullState)
|
||||
, m_syncInterestTable (TIME_SECONDS (m_syncInterestReexpress))
|
||||
, m_syncPrefix (syncPrefix)
|
||||
, m_onUpdateBranch (onUpdateBranch)
|
||||
, m_perBranch(true)
|
||||
, m_ccnxHandle(new CcnxWrapper())
|
||||
, m_policyManager(syncPolicyManager)
|
||||
#ifndef NS3_MODULE
|
||||
, m_randomGenerator (static_cast<unsigned int> (std::time (0)))
|
||||
, m_rangeUniformRandom (m_randomGenerator, uniform_int<> (200,1000))
|
||||
@@ -109,8 +116,13 @@ SyncLogic::SyncLogic (const std::string &syncPrefix,
|
||||
{
|
||||
#ifndef NS3_MODULE
|
||||
// In NS3 module these functions are moved to StartApplication method
|
||||
|
||||
Ptr<security::Keychain> keychain = Ptr<security::Keychain>(new security::Keychain(Ptr<security::IdentityManager>::Create(),
|
||||
m_policyManager,
|
||||
NULL));
|
||||
m_handler = Ptr<Wrapper>(new Wrapper(keychain));
|
||||
|
||||
m_ccnxHandle->setInterestFilter (m_syncPrefix,
|
||||
m_handler->setInterestFilter (m_syncPrefix,
|
||||
bind (&SyncLogic::respondSyncInterest, this, _1));
|
||||
|
||||
m_scheduler.schedule (TIME_SECONDS (0), // no need to add jitter
|
||||
@@ -121,7 +133,7 @@ SyncLogic::SyncLogic (const std::string &syncPrefix,
|
||||
|
||||
SyncLogic::~SyncLogic ()
|
||||
{
|
||||
m_ccnxHandle->clearInterestFilter (m_syncPrefix);
|
||||
m_handler->clearInterestFilter (Name(m_syncPrefix));
|
||||
}
|
||||
|
||||
#ifdef NS3_MODULE
|
||||
@@ -152,7 +164,7 @@ SyncLogic::StopApplication ()
|
||||
void
|
||||
SyncLogic::stop()
|
||||
{
|
||||
m_ccnxHandle->clearInterestFilter (m_syncPrefix);
|
||||
m_handler->clearInterestFilter (Name(m_syncPrefix));
|
||||
m_scheduler.cancel (REEXPRESSING_INTEREST);
|
||||
m_scheduler.cancel (DELAYED_INTEREST_PROCESSING);
|
||||
}
|
||||
@@ -166,9 +178,9 @@ SyncLogic::stop()
|
||||
boost::tuple<DigestConstPtr, std::string>
|
||||
SyncLogic::convertNameToDigestAndType (const std::string &name)
|
||||
{
|
||||
BOOST_ASSERT (name.find (m_syncPrefix) == 0);
|
||||
BOOST_ASSERT (name.find (m_syncPrefix.toUri()) == 0);
|
||||
|
||||
string hash = name.substr (m_syncPrefix.size (), name.size ()-m_syncPrefix.size ());
|
||||
string hash = name.substr (m_syncPrefix.toUri().size (), name.size ()-m_syncPrefix.toUri().size ());
|
||||
if (hash[0] == '/')
|
||||
hash = hash.substr (1, hash.size ()-1);
|
||||
string interestType = "normal";
|
||||
@@ -190,8 +202,10 @@ SyncLogic::convertNameToDigestAndType (const std::string &name)
|
||||
}
|
||||
|
||||
void
|
||||
SyncLogic::respondSyncInterest (const string &name)
|
||||
SyncLogic::respondSyncInterest (ndn::Ptr<ndn::Interest> interest)
|
||||
{
|
||||
_LOG_DEBUG("respondSyncInterest: " << interest->getName().toUri());
|
||||
string name = interest->getName().toUri();
|
||||
try
|
||||
{
|
||||
_LOG_TRACE ("<< I " << name);
|
||||
@@ -218,8 +232,12 @@ SyncLogic::respondSyncInterest (const string &name)
|
||||
}
|
||||
|
||||
void
|
||||
SyncLogic::respondSyncData (const std::string &name, const char *wireData, size_t len)
|
||||
SyncLogic::respondSyncData (Ptr<Data> data)
|
||||
{
|
||||
string name = data->getName().toUri();
|
||||
const char *wireData = data->content().buf();
|
||||
size_t len = data->content().size();
|
||||
|
||||
try
|
||||
{
|
||||
_LOG_TRACE ("<< D " << name);
|
||||
@@ -247,10 +265,32 @@ SyncLogic::respondSyncData (const std::string &name, const char *wireData, size_
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SyncLogic::onSyncDataTimeout(Ptr<Closure> closure, Ptr<ndn::Interest> interest, int retry)
|
||||
{
|
||||
if(retry > 0)
|
||||
{
|
||||
Ptr<Closure> newClosure = Ptr<Closure>(new Closure(closure->m_dataCallback,
|
||||
boost::bind(&SyncLogic::onSyncDataTimeout,
|
||||
this,
|
||||
_1,
|
||||
_2,
|
||||
retry - 1),
|
||||
closure->m_unverifiedCallback,
|
||||
closure->m_stepCount)
|
||||
);
|
||||
m_handler->sendInterest(interest, newClosure);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SyncLogic::onSyncDataUnverified()
|
||||
{}
|
||||
|
||||
void
|
||||
SyncLogic::processSyncInterest (const std::string &name, DigestConstPtr digest, bool timedProcessing/*=false*/)
|
||||
{
|
||||
_LOG_DEBUG("processSyncInterest");
|
||||
DigestConstPtr rootDigest;
|
||||
{
|
||||
recursive_mutex::scoped_lock lock (m_stateMutex);
|
||||
@@ -435,7 +475,7 @@ SyncLogic::processSyncData (const std::string &name, DigestConstPtr digest, cons
|
||||
void
|
||||
SyncLogic::processSyncRecoveryInterest (const std::string &name, DigestConstPtr digest)
|
||||
{
|
||||
|
||||
_LOG_DEBUG("processSyncRecoveryInterest");
|
||||
DiffStateContainer::iterator stateInDiffLog = m_log.find (digest);
|
||||
|
||||
if (stateInDiffLog == m_log.end ())
|
||||
@@ -564,6 +604,7 @@ SyncLogic::remove(const string &prefix)
|
||||
void
|
||||
SyncLogic::sendSyncInterest ()
|
||||
{
|
||||
_LOG_DEBUG("sendSyncInterest");
|
||||
ostringstream os;
|
||||
|
||||
{
|
||||
@@ -574,13 +615,25 @@ SyncLogic::sendSyncInterest ()
|
||||
_LOG_TRACE (">> I " << os.str ());
|
||||
}
|
||||
|
||||
_LOG_DEBUG("sendSyncInterest: " << os.str());
|
||||
|
||||
m_scheduler.cancel (REEXPRESSING_INTEREST);
|
||||
m_scheduler.schedule (TIME_SECONDS_WITH_JITTER (m_syncInterestReexpress),
|
||||
bind (&SyncLogic::sendSyncInterest, this),
|
||||
REEXPRESSING_INTEREST);
|
||||
|
||||
m_ccnxHandle->sendInterest (os.str (),
|
||||
bind (&SyncLogic::respondSyncData, this, _1, _2, _3));
|
||||
|
||||
Ptr<ndn::Interest> interestPtr = Ptr<ndn::Interest>(new ndn::Interest(os.str()));
|
||||
Ptr<Closure> closure = Ptr<Closure> (new Closure(boost::bind(&SyncLogic::respondSyncData,
|
||||
this,
|
||||
_1),
|
||||
boost::bind(&SyncLogic::onSyncDataTimeout,
|
||||
this,
|
||||
_1,
|
||||
_2,
|
||||
0),
|
||||
boost::bind(&SyncLogic::onSyncDataUnverified,
|
||||
this)));
|
||||
m_handler->sendInterest(interestPtr, closure);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -601,8 +654,18 @@ SyncLogic::sendSyncRecoveryInterests (DigestConstPtr digest)
|
||||
REEXPRESSING_RECOVERY_INTEREST);
|
||||
}
|
||||
|
||||
m_ccnxHandle->sendInterest (os.str (),
|
||||
bind (&SyncLogic::respondSyncData, this, _1, _2, _3));
|
||||
Ptr<ndn::Interest> interestPtr = Ptr<ndn::Interest>(new ndn::Interest(os.str()));
|
||||
Ptr<Closure> closure = Ptr<Closure> (new Closure(boost::bind(&SyncLogic::respondSyncData,
|
||||
this,
|
||||
_1),
|
||||
boost::bind(&SyncLogic::onSyncDataTimeout,
|
||||
this,
|
||||
_1,
|
||||
_2,
|
||||
0),
|
||||
boost::bind(&SyncLogic::onSyncDataUnverified,
|
||||
this)));
|
||||
m_handler->sendInterest (interestPtr, closure);
|
||||
}
|
||||
|
||||
|
||||
@@ -623,10 +686,13 @@ SyncLogic::sendSyncData (const std::string &name, DigestConstPtr digest, SyncSta
|
||||
int size = ssm.ByteSize();
|
||||
char *wireData = new char[size];
|
||||
ssm.SerializeToArray(wireData, size);
|
||||
m_ccnxHandle->publishRawData (name,
|
||||
wireData,
|
||||
size,
|
||||
m_syncResponseFreshness); // in NS-3 it doesn't have any effect... yet
|
||||
Blob blob(wireData, size);
|
||||
Name dataName(name);
|
||||
Name signingIdentity = m_policyManager->inferSigningIdentity(dataName);
|
||||
m_handler->publishDataByIdentity (dataName,
|
||||
blob,
|
||||
signingIdentity,
|
||||
m_syncResponseFreshness); // in NS-3 it doesn't have any effect... yet
|
||||
delete []wireData;
|
||||
|
||||
// checking if our own interest got satisfied
|
||||
|
||||
+17
-7
@@ -29,12 +29,13 @@
|
||||
#include <memory>
|
||||
#include <map>
|
||||
|
||||
#include "ccnx/sync-ccnx-wrapper.h"
|
||||
#include <ndn.cxx/wrapper/wrapper.h>
|
||||
#include "sync-interest-table.h"
|
||||
#include "sync-diff-state.h"
|
||||
#include "sync-full-state.h"
|
||||
#include "sync-std-name-info.h"
|
||||
#include "sync-scheduler.h"
|
||||
#include "sync-policy-manager.h"
|
||||
|
||||
#include "sync-diff-state-container.h"
|
||||
|
||||
@@ -82,11 +83,13 @@ public:
|
||||
* @param ccnxHandle ccnx handle
|
||||
* the app data when new remote names are learned
|
||||
*/
|
||||
SyncLogic (const std::string &syncPrefix,
|
||||
SyncLogic (const ndn::Name& syncPrefix,
|
||||
ndn::Ptr<SyncPolicyManager> syncPolicyManager,
|
||||
LogicUpdateCallback onUpdate,
|
||||
LogicRemoveCallback onRemove);
|
||||
|
||||
SyncLogic (const std::string &syncPrefix,
|
||||
SyncLogic (const ndn::Name& syncPrefix,
|
||||
ndn::Ptr<SyncPolicyManager> syncPolicyManager,
|
||||
LogicPerBranchCallback onUpdateBranch);
|
||||
|
||||
~SyncLogic ();
|
||||
@@ -100,14 +103,14 @@ public:
|
||||
* @brief respond to the Sync Interest; a lot of logic needs to go in here
|
||||
* @param interest the Sync Interest in string format
|
||||
*/
|
||||
void respondSyncInterest (const std::string &interest);
|
||||
void respondSyncInterest (ndn::Ptr<ndn::Interest>);
|
||||
|
||||
/**
|
||||
* @brief process the fetched sync data
|
||||
* @param name the data name
|
||||
* @param dataBuffer the sync data
|
||||
*/
|
||||
void respondSyncData (const std::string &name, const char *wireData, size_t len);
|
||||
void respondSyncData (ndn::Ptr<ndn::Data> data);
|
||||
|
||||
/**
|
||||
* @brief remove a participant's subtree from the sync tree
|
||||
@@ -141,6 +144,12 @@ private:
|
||||
void
|
||||
delayedChecksLoop ();
|
||||
|
||||
void
|
||||
onSyncDataTimeout(ndn::Ptr<ndn::Closure> closure, ndn::Ptr<ndn::Interest> interest, int retry);
|
||||
|
||||
void
|
||||
onSyncDataUnverified();
|
||||
|
||||
void
|
||||
processSyncInterest (const std::string &name,
|
||||
DigestConstPtr digest, bool timedProcessing=false);
|
||||
@@ -187,12 +196,13 @@ private:
|
||||
std::string m_outstandingInterestName;
|
||||
SyncInterestTable m_syncInterestTable;
|
||||
|
||||
std::string m_syncPrefix;
|
||||
ndn::Name m_syncPrefix;
|
||||
LogicUpdateCallback m_onUpdate;
|
||||
LogicRemoveCallback m_onRemove;
|
||||
LogicPerBranchCallback m_onUpdateBranch;
|
||||
bool m_perBranch;
|
||||
CcnxWrapperPtr m_ccnxHandle;
|
||||
ndn::Ptr<SyncPolicyManager> m_policyManager;
|
||||
ndn::Ptr<ndn::Wrapper> m_handler;
|
||||
|
||||
Scheduler m_scheduler;
|
||||
|
||||
|
||||
@@ -0,0 +1,341 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
|
||||
/*
|
||||
* Copyright (c) 2013, Regents of the University of California
|
||||
* Yingdi Yu
|
||||
*
|
||||
* BSD license, See the LICENSE file for more information
|
||||
*
|
||||
* Author: Yingdi Yu <yingdi@cs.ucla.edu>
|
||||
*/
|
||||
|
||||
#include "sync-policy-manager.h"
|
||||
|
||||
#include "sync-intro-certificate.h"
|
||||
#include "sync-logging.h"
|
||||
|
||||
using namespace ndn;
|
||||
using namespace ndn::security;
|
||||
using namespace std;
|
||||
|
||||
INIT_LOGGER("SyncPolicyManager");
|
||||
|
||||
SyncPolicyManager::SyncPolicyManager(const Name& signingIdentity,
|
||||
const Name& signingCertificateName,
|
||||
const Name& syncPrefix,
|
||||
int stepLimit)
|
||||
: m_signingIdentity(signingIdentity)
|
||||
, m_signingCertificateName(signingCertificateName.getPrefix(signingCertificateName.size()-1))
|
||||
, m_syncPrefix(syncPrefix)
|
||||
, m_stepLimit(stepLimit)
|
||||
{
|
||||
Name wotPrefix = syncPrefix;
|
||||
wotPrefix.append("WOT");
|
||||
m_syncPrefixRegex = Regex::fromName(syncPrefix);
|
||||
m_wotPrefixRegex = Regex::fromName(wotPrefix);
|
||||
m_chatDataPolicy = Ptr<IdentityPolicyRule>(new IdentityPolicyRule("^[^<FH>]*<FH>([^<chronos>]*)<chronos><>",
|
||||
"^(<>*)<KEY><DSK-.*><ID-CERT><>$",
|
||||
"==", "\\1", "\\1", true));
|
||||
}
|
||||
|
||||
SyncPolicyManager::~SyncPolicyManager()
|
||||
{}
|
||||
|
||||
bool
|
||||
SyncPolicyManager::skipVerifyAndTrust (const Data& data)
|
||||
{ return false; }
|
||||
|
||||
bool
|
||||
SyncPolicyManager::requireVerify (const Data& data)
|
||||
{ return true; }
|
||||
|
||||
Ptr<ValidationRequest>
|
||||
SyncPolicyManager::checkVerificationPolicy(Ptr<Data> data,
|
||||
const int& stepCount,
|
||||
const DataCallback& verifiedCallback,
|
||||
const UnverifiedCallback& unverifiedCallback)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
_LOG_DEBUG("checkVerificationPolicy");
|
||||
verifiedCallback(data);
|
||||
return NULL;
|
||||
#else
|
||||
//TODO:
|
||||
if(stepCount > m_stepLimit)
|
||||
{
|
||||
unverifiedCallback(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Ptr<const signature::Sha256WithRsa> sha256sig = DynamicCast<const signature::Sha256WithRsa> (data->getSignature());
|
||||
if(KeyLocator::KEYNAME != sha256sig->getKeyLocator().getType())
|
||||
{
|
||||
unverifiedCallback(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const Name& keyLocatorName = sha256sig->getKeyLocator().getKeyName();
|
||||
|
||||
// if data is intro cert
|
||||
if(m_wotPrefixRegex->match(data->getName()))
|
||||
{
|
||||
Name keyName = IdentityCertificate::certificateNameToPublicKeyName(keyLocatorName);
|
||||
map<Name, Publickey>::const_iterator it = m_trustedIntroducers.find(keyName);
|
||||
if(m_trustedIntroducers.end() != it)
|
||||
{
|
||||
if(verifySignature(*data, it->second))
|
||||
verifiedCallback(data);
|
||||
else
|
||||
unverifiedCallback(data);
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
return prepareRequest(keyName, true, data, stepCount, verifiedCallback, unverifiedCallback);
|
||||
}
|
||||
|
||||
// if data is sync data or chat data
|
||||
if(m_syncPrefixRegex->match(data->getName()) || m_chatDataPolicy->satisfy(*data))
|
||||
{
|
||||
Name keyName = IdentityCertificate::certificateNameToPublicKeyName(keyLocatorName);
|
||||
|
||||
map<Name, Publickey>::const_iterator it = m_trustedIntroducers.find(keyName);
|
||||
if(m_trustedIntroducers.end() != it)
|
||||
{
|
||||
if(verifySignature(*data, it->second))
|
||||
verifiedCallback(data);
|
||||
else
|
||||
unverifiedCallback(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
it = m_trustedProducers.find(keyName);
|
||||
if(m_trustedProducers.end() != it)
|
||||
{
|
||||
if(verifySignature(*data, it->second))
|
||||
verifiedCallback(data);
|
||||
else
|
||||
unverifiedCallback(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return prepareRequest(keyName, false, data, stepCount, verifiedCallback, unverifiedCallback);
|
||||
}
|
||||
|
||||
unverifiedCallback(data);
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
SyncPolicyManager::checkSigningPolicy(const Name& dataName,
|
||||
const Name& certificateName)
|
||||
{
|
||||
|
||||
#ifdef _DEBUG
|
||||
_LOG_DEBUG("checkSigningPolicy");
|
||||
return true;
|
||||
#else
|
||||
return (m_syncPrefixRegex->match(dataName) && certificateName == m_signingCertificateName) ? true : false;
|
||||
#endif
|
||||
}
|
||||
|
||||
Name
|
||||
SyncPolicyManager::inferSigningIdentity(const ndn::Name& dataName)
|
||||
{ return m_signingIdentity; }
|
||||
|
||||
void
|
||||
SyncPolicyManager::addTrustAnchor(const IdentityCertificate& identityCertificate, bool isIntroducer)
|
||||
{
|
||||
if(isIntroducer)
|
||||
m_trustedIntroducers.insert(pair <Name, Publickey > (identityCertificate.getPublicKeyName(), identityCertificate.getPublicKeyInfo()));
|
||||
else
|
||||
m_trustedProducers.insert(pair <Name, Publickey > (identityCertificate.getPublicKeyName(), identityCertificate.getPublicKeyInfo()));
|
||||
}
|
||||
|
||||
void
|
||||
SyncPolicyManager::addChatDataRule(const Name& prefix,
|
||||
const IdentityCertificate& identityCertificate,
|
||||
bool isIntroducer)
|
||||
{
|
||||
// Name dataPrefix = prefix;
|
||||
// dataPrefix.append("chronos").append(m_syncPrefix.get(-1));
|
||||
// Ptr<Regex> dataRegex = Regex::fromName(prefix);
|
||||
// Name certName = identityCertificate.getName();
|
||||
// Name signerName = certName.getPrefix(certName.size()-1);
|
||||
// Ptr<Regex> signerRegex = Regex::fromName(signerName, true);
|
||||
|
||||
// SpecificPolicyRule rule(dataRegex, signerRegex);
|
||||
// map<Name, SpecificPolicyRule>::iterator it = m_chatDataRules.find(dataPrefix);
|
||||
// if(it != m_chatDataRules.end())
|
||||
// it->second = rule;
|
||||
// else
|
||||
// m_chatDataRules.insert(pair <Name, SpecificPolicyRule > (dataPrefix, rule));
|
||||
|
||||
addTrustAnchor(identityCertificate, isIntroducer);
|
||||
}
|
||||
|
||||
|
||||
Ptr<const vector<Name> >
|
||||
SyncPolicyManager::getAllIntroducerName()
|
||||
{
|
||||
Ptr<vector<Name> > nameList = Ptr<vector<Name> >(new vector<Name>);
|
||||
|
||||
map<Name, Publickey>::iterator it = m_trustedIntroducers.begin();
|
||||
for(; it != m_trustedIntroducers.end(); it++)
|
||||
nameList->push_back(it->first);
|
||||
|
||||
return nameList;
|
||||
}
|
||||
|
||||
Ptr<ValidationRequest>
|
||||
SyncPolicyManager::prepareRequest(const Name& keyName,
|
||||
bool forIntroducer,
|
||||
Ptr<Data> data,
|
||||
const int & stepCount,
|
||||
const DataCallback& verifiedCallback,
|
||||
const UnverifiedCallback& unverifiedCallback)
|
||||
{
|
||||
Ptr<Name> interestPrefixName = Ptr<Name>(new Name(m_syncPrefix));
|
||||
interestPrefixName->append("WOT").append(keyName).append("INTRO-CERT");
|
||||
|
||||
Ptr<const std::vector<ndn::Name> > nameList = getAllIntroducerName();
|
||||
|
||||
Name interestName = *interestPrefixName;
|
||||
interestName.append(nameList->at(0));
|
||||
|
||||
if(forIntroducer)
|
||||
interestName.append("INTRODUCER");
|
||||
|
||||
Ptr<Interest> interest = Ptr<Interest>(new Interest(interestName));
|
||||
interest->setChildSelector(Interest::CHILD_RIGHT);
|
||||
|
||||
DataCallback requestedCertVerifiedCallback = boost::bind(&SyncPolicyManager::onIntroCertVerified,
|
||||
this,
|
||||
_1,
|
||||
forIntroducer,
|
||||
data,
|
||||
verifiedCallback,
|
||||
unverifiedCallback);
|
||||
|
||||
UnverifiedCallback requestedCertUnverifiedCallback = boost::bind(&SyncPolicyManager::onIntroCertUnverified,
|
||||
this,
|
||||
_1,
|
||||
interestPrefixName,
|
||||
forIntroducer,
|
||||
nameList,
|
||||
1,
|
||||
data,
|
||||
verifiedCallback,
|
||||
unverifiedCallback);
|
||||
|
||||
|
||||
Ptr<ValidationRequest> nextStep = Ptr<ValidationRequest>(new ValidationRequest(interest,
|
||||
requestedCertVerifiedCallback,
|
||||
requestedCertUnverifiedCallback,
|
||||
1,
|
||||
m_stepLimit-1)
|
||||
);
|
||||
return nextStep;
|
||||
}
|
||||
|
||||
void
|
||||
SyncPolicyManager::onIntroCertVerified(Ptr<Data> introCertificateData,
|
||||
bool forIntroducer,
|
||||
Ptr<Data> originalData,
|
||||
const DataCallback& verifiedCallback,
|
||||
const UnverifiedCallback& unverifiedCallback)
|
||||
{
|
||||
Ptr<SyncIntroCertificate> introCertificate = Ptr<SyncIntroCertificate>(new SyncIntroCertificate(*introCertificateData));
|
||||
if(forIntroducer)
|
||||
m_trustedIntroducers.insert(pair <Name, Publickey > (introCertificate->getPublicKeyName(), introCertificate->getPublicKeyInfo()));
|
||||
else
|
||||
m_trustedProducers.insert(pair <Name, Publickey > (introCertificate->getPublicKeyName(), introCertificate->getPublicKeyInfo()));
|
||||
|
||||
if(verifySignature(*originalData, introCertificate->getPublicKeyInfo()))
|
||||
verifiedCallback(originalData);
|
||||
else
|
||||
unverifiedCallback(originalData);
|
||||
}
|
||||
|
||||
void
|
||||
SyncPolicyManager::onIntroCertUnverified(Ptr<Data> introCertificateData,
|
||||
Ptr<Name> interestPrefixName,
|
||||
bool forIntroducer,
|
||||
Ptr<const std::vector<ndn::Name> > introNameList,
|
||||
const int& nextIntroducerIndex,
|
||||
Ptr<Data> originalData,
|
||||
const DataCallback& verifiedCallback,
|
||||
const UnverifiedCallback& unverifiedCallback)
|
||||
{
|
||||
Name interestName = *interestPrefixName;
|
||||
if(nextIntroducerIndex < introNameList->size())
|
||||
interestName.append(introNameList->at(nextIntroducerIndex));
|
||||
else
|
||||
unverifiedCallback(originalData);
|
||||
|
||||
if(forIntroducer)
|
||||
interestName.append("INTRODUCER");
|
||||
|
||||
Ptr<Interest> interest = Ptr<Interest>(new Interest(interestName));
|
||||
interest->setChildSelector(Interest::CHILD_RIGHT);
|
||||
|
||||
DataCallback requestedCertVerifiedCallback = boost::bind(&SyncPolicyManager::onIntroCertVerified,
|
||||
this,
|
||||
_1,
|
||||
forIntroducer,
|
||||
originalData,
|
||||
verifiedCallback,
|
||||
unverifiedCallback);
|
||||
|
||||
UnverifiedCallback requestedCertUnverifiedCallback = boost::bind(&SyncPolicyManager::onIntroCertUnverified,
|
||||
this,
|
||||
_1,
|
||||
interestPrefixName,
|
||||
forIntroducer,
|
||||
introNameList,
|
||||
nextIntroducerIndex + 1,
|
||||
originalData,
|
||||
verifiedCallback,
|
||||
unverifiedCallback);
|
||||
|
||||
TimeoutCallback requestedCertTimeoutCallback = boost::bind(&SyncPolicyManager::onIntroCertTimeOut,
|
||||
this,
|
||||
_1,
|
||||
_2,
|
||||
1,
|
||||
requestedCertUnverifiedCallback,
|
||||
originalData);
|
||||
|
||||
Ptr<Closure> closure = Ptr<Closure> (new Closure(requestedCertVerifiedCallback,
|
||||
requestedCertTimeoutCallback,
|
||||
requestedCertUnverifiedCallback,
|
||||
m_stepLimit-1)
|
||||
);
|
||||
|
||||
m_handler->sendInterest(interest, closure);
|
||||
}
|
||||
|
||||
void
|
||||
SyncPolicyManager::onIntroCertTimeOut(Ptr<Closure> closure,
|
||||
Ptr<Interest> interest,
|
||||
int retry,
|
||||
const UnverifiedCallback& unverifiedCallback,
|
||||
Ptr<Data> data)
|
||||
{
|
||||
if(retry > 0)
|
||||
{
|
||||
Ptr<Closure> newClosure = Ptr<Closure>(new Closure(closure->m_dataCallback,
|
||||
boost::bind(&SyncPolicyManager::onIntroCertTimeOut,
|
||||
this,
|
||||
_1,
|
||||
_2,
|
||||
retry - 1,
|
||||
unverifiedCallback,
|
||||
data),
|
||||
closure->m_unverifiedCallback,
|
||||
closure->m_stepCount)
|
||||
);
|
||||
m_handler->sendInterest(interest, newClosure);
|
||||
}
|
||||
else
|
||||
unverifiedCallback(data);
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
|
||||
/*
|
||||
* Copyright (c) 2013, Regents of the University of California
|
||||
* Yingdi Yu
|
||||
*
|
||||
* BSD license, See the LICENSE file for more information
|
||||
*
|
||||
* Author: Yingdi Yu <yingdi@cs.ucla.edu>
|
||||
*/
|
||||
|
||||
#ifndef SYNC_POLICY_MANAGER_H
|
||||
#define SYNC_POLICY_MANAGER_H
|
||||
|
||||
#include <ndn.cxx/security/policy/policy-manager.h>
|
||||
#include <ndn.cxx/security/policy/identity-policy-rule.h>
|
||||
#include <ndn.cxx/security/certificate/identity-certificate.h>
|
||||
#include <ndn.cxx/regex/regex.h>
|
||||
#include <ndn.cxx/wrapper/wrapper.h>
|
||||
#include "specific-policy-rule.h"
|
||||
|
||||
|
||||
class SyncPolicyManager : public ndn::security::PolicyManager
|
||||
{
|
||||
public:
|
||||
SyncPolicyManager(const ndn::Name& signingIdentity,
|
||||
const ndn::Name& signingCertificateName,
|
||||
const ndn::Name& syncPrefix,
|
||||
int m_stepLimit = 3);
|
||||
|
||||
virtual
|
||||
~SyncPolicyManager();
|
||||
|
||||
bool
|
||||
skipVerifyAndTrust (const ndn::Data& data);
|
||||
|
||||
bool
|
||||
requireVerify (const ndn::Data& data);
|
||||
|
||||
ndn::Ptr<ndn::security::ValidationRequest>
|
||||
checkVerificationPolicy(ndn::Ptr<ndn::Data> data,
|
||||
const int& stepCount,
|
||||
const ndn::DataCallback& verifiedCallback,
|
||||
const ndn::UnverifiedCallback& unverifiedCallback);
|
||||
|
||||
bool
|
||||
checkSigningPolicy(const ndn::Name& dataName,
|
||||
const ndn::Name& certificateName);
|
||||
|
||||
ndn::Name
|
||||
inferSigningIdentity(const ndn::Name& dataName);
|
||||
|
||||
void
|
||||
addTrustAnchor(const ndn::security::IdentityCertificate& identityCertificate, bool isIntroducer);
|
||||
|
||||
void
|
||||
addChatDataRule(const ndn::Name& prefix,
|
||||
const ndn::security::IdentityCertificate& identityCertificate,
|
||||
bool isIntroducer);
|
||||
|
||||
inline void
|
||||
setWrapper(ndn::Wrapper* handler)
|
||||
{ m_handler = handler; }
|
||||
|
||||
private:
|
||||
ndn::Ptr<ndn::security::ValidationRequest>
|
||||
prepareIntroducerRequest(const ndn::Name& keyName,
|
||||
ndn::Ptr<ndn::Data> data,
|
||||
const int & stepCount,
|
||||
const ndn::DataCallback& verifiedCallback,
|
||||
const ndn::UnverifiedCallback& unverifiedCallback);
|
||||
|
||||
ndn::Ptr<const std::vector<ndn::Name> >
|
||||
getAllIntroducerName();
|
||||
|
||||
ndn::Ptr<ndn::security::ValidationRequest>
|
||||
prepareRequest(const ndn::Name& keyName,
|
||||
bool forIntroducer,
|
||||
ndn::Ptr<ndn::Data> data,
|
||||
const int & stepCount,
|
||||
const ndn::DataCallback& verifiedCallback,
|
||||
const ndn::UnverifiedCallback& unverifiedCallback);
|
||||
|
||||
void
|
||||
onIntroCertVerified(ndn::Ptr<ndn::Data> introCertificateData,
|
||||
bool forIntroducer,
|
||||
ndn::Ptr<ndn::Data> originalData,
|
||||
const ndn::DataCallback& verifiedCallback,
|
||||
const ndn::UnverifiedCallback& unverifiedCallback);
|
||||
|
||||
void
|
||||
onIntroCertUnverified(ndn::Ptr<ndn::Data> introCertificateData,
|
||||
ndn::Ptr<ndn::Name> interestPrefixName,
|
||||
bool forIntroducer,
|
||||
ndn::Ptr<const std::vector<ndn::Name> > introNameList,
|
||||
const int& nextIntroducerIndex,
|
||||
ndn::Ptr<ndn::Data> originalData,
|
||||
const ndn::DataCallback& verifiedCallback,
|
||||
const ndn::UnverifiedCallback& unverifiedCallback);
|
||||
|
||||
void
|
||||
onIntroCertTimeOut(ndn::Ptr<ndn::Closure> closure,
|
||||
ndn::Ptr<ndn::Interest> interest,
|
||||
int retry,
|
||||
const ndn::UnverifiedCallback& unverifiedCallback,
|
||||
ndn::Ptr<ndn::Data> data);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
ndn::Name m_signingIdentity;
|
||||
ndn::Name m_signingCertificateName;
|
||||
ndn::Name m_syncPrefix;
|
||||
int m_stepLimit;
|
||||
ndn::Ptr<ndn::Regex> m_syncPrefixRegex;
|
||||
ndn::Ptr<ndn::Regex> m_wotPrefixRegex;
|
||||
ndn::Ptr<ndn::security::IdentityPolicyRule> m_chatDataPolicy;
|
||||
std::map<ndn::Name, ndn::security::Publickey> m_trustedIntroducers;
|
||||
std::map<ndn::Name, ndn::security::Publickey> m_trustedProducers;
|
||||
std::map<ndn::Name, SpecificPolicyRule> m_chatDataRules;
|
||||
|
||||
ndn::Wrapper* m_handler;
|
||||
};
|
||||
|
||||
#endif
|
||||
File renamed without changes.
@@ -0,0 +1,248 @@
|
||||
/* -*- 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>
|
||||
*/
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/output_test_stream.hpp>
|
||||
using boost::test_tools::output_test_stream;
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
#include "sync-logging.h"
|
||||
|
||||
#include "ccnx/sync-socket.h"
|
||||
|
||||
extern "C" {
|
||||
#include <unistd.h>
|
||||
}
|
||||
|
||||
using namespace Sync;
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
|
||||
INIT_LOGGER ("Test.AppSocket");
|
||||
|
||||
#define PRINT
|
||||
//std::cout << "Line: " << __LINE__ << std::endl;
|
||||
|
||||
class TestSocketApp {
|
||||
public:
|
||||
map<string, string> data;
|
||||
void set(ndn::Ptr<ndn::Data> dataPacket) {
|
||||
// _LOG_FUNCTION (this << ", " << str1);
|
||||
string str1(dataPacket->getName().toUri());
|
||||
string str2(dataPacket->content().buf(), dataPacket->content().size());
|
||||
data.insert(make_pair(str1, str2));
|
||||
// cout << str1 << ", " << str2 << endl;
|
||||
}
|
||||
|
||||
void set(string str1, const char * buf, int len) {
|
||||
string str2(buf, len);
|
||||
data.insert(make_pair(str1, str2));
|
||||
}
|
||||
|
||||
void setNum(ndn::Ptr<ndn::Data> dataPacket) {
|
||||
int n = dataPacket->content().size() / 4;
|
||||
int *numbers = new int [n];
|
||||
memcpy(numbers, dataPacket->content().buf(), dataPacket->content().size());
|
||||
for (int i = 0; i < n; i++) {
|
||||
sum += numbers[i];
|
||||
}
|
||||
delete numbers;
|
||||
|
||||
}
|
||||
|
||||
void setNum(string str1, const char * buf, int len) {
|
||||
int n = len / 4;
|
||||
int *numbers = new int [n];
|
||||
memcpy(numbers, buf, len);
|
||||
for (int i = 0; i < n; i++) {
|
||||
sum += numbers[i];
|
||||
}
|
||||
delete numbers;
|
||||
}
|
||||
|
||||
int sum;
|
||||
|
||||
void fetchAll(const vector<MissingDataInfo> &v, SyncSocket *socket) {
|
||||
int n = v.size();
|
||||
|
||||
PRINT
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
for(SeqNo s = v[i].low; s <= v[i].high; ++s) {
|
||||
//PRINT
|
||||
socket->fetchData(v[i].prefix, s, bind(&TestSocketApp::set, this, _1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void fetchNumbers(const vector<MissingDataInfo> &v, SyncSocket *socket) {
|
||||
int n = v.size();
|
||||
|
||||
PRINT
|
||||
|
||||
std::cout << "In fetchNumbers. size of v is: " << n << std::endl;
|
||||
for (int i = 0; i < n; i++) {
|
||||
std::cout << "In fetchNumbers. v[i].low is (" <<v[i].low.getSession() <<", " << v[i].low.getSeq() << ") v[i].high is ("<<v[i].high.getSession() <<", " <<v[i].high.getSeq()<<")" << std::endl;
|
||||
for(SeqNo s = v[i].low; s <= v[i].high; ++s) {
|
||||
PRINT
|
||||
socket->fetchData(v[i].prefix, s, bind(&TestSocketApp::setNum, this, _1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pass(const string &prefix) {
|
||||
}
|
||||
|
||||
string toString(){
|
||||
map<string, string>::iterator it = data.begin();
|
||||
string str = "\n";
|
||||
for (; it != data.end(); ++it){
|
||||
str += "<";
|
||||
str += it->first;
|
||||
str += "|";
|
||||
str += it->second;
|
||||
str += ">";
|
||||
str += "\n";
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE (AppSocketTest)
|
||||
{
|
||||
INIT_LOGGERS ();
|
||||
|
||||
TestSocketApp a1, a2, a3;
|
||||
|
||||
string syncPrefix("/let/us/sync");
|
||||
string p1("/irl.cs.ucla.edu"), p2("/yakshi.org"), p3("/google.com");
|
||||
|
||||
ndn::Ptr<SyncPolicyManager> policyManager1 = ndn::Ptr<SyncPolicyManager>(new SyncPolicyManager(ndn::Name("/ndn/ucla.edu/alice"), ndn::Name("/ndn/ucla.edu/alice/KEY/dsk-1382934202/ID-CERT/%FD%FF%FF%FF%FF%DEk%C0%0B"), ndn::Name(syncPrefix)));
|
||||
|
||||
_LOG_DEBUG ("s1");
|
||||
SyncSocket s1 (syncPrefix, policyManager1, bind(&TestSocketApp::fetchAll, &a1, _1, _2), bind(&TestSocketApp::pass, &a1, _1));
|
||||
this_thread::sleep (posix_time::milliseconds (50));
|
||||
_LOG_DEBUG ("s2");
|
||||
SyncSocket s2 (syncPrefix, policyManager1, bind(&TestSocketApp::fetchAll, &a2, _1, _2), bind(&TestSocketApp::pass, &a2, _1));
|
||||
this_thread::sleep (posix_time::milliseconds (50));
|
||||
SyncSocket s3 (syncPrefix, policyManager1, bind(&TestSocketApp::fetchAll, &a3, _1, _2), bind(&TestSocketApp::pass, &a3, _1));
|
||||
this_thread::sleep (posix_time::milliseconds (50));
|
||||
|
||||
// single source
|
||||
string data0 = "Very funny Scotty, now beam down my clothes";
|
||||
_LOG_DEBUG ("s1 publish");
|
||||
s1.publishData (p1, 0, data0.c_str(), data0.size(), 10);
|
||||
this_thread::sleep (posix_time::milliseconds (1000));
|
||||
|
||||
// from code logic, we won't be fetching our own data
|
||||
a1.set(p1 + "/0/0", data0.c_str(), data0.size());
|
||||
BOOST_CHECK_EQUAL(a1.toString(), a2.toString());
|
||||
BOOST_CHECK_EQUAL(a2.toString(), a3.toString());
|
||||
|
||||
// single source, multiple data at once
|
||||
string data1 = "Yes, give me that ketchup";
|
||||
string data2 = "Don't look conspicuous, it draws fire";
|
||||
|
||||
_LOG_DEBUG ("s1 publish");
|
||||
s1.publishData (p1, 0, data1.c_str(), data1.size(), 10);
|
||||
_LOG_DEBUG ("s1 publish");
|
||||
s1.publishData (p1, 0, data2.c_str(), data2.size(), 10);
|
||||
this_thread::sleep (posix_time::milliseconds (1000));
|
||||
|
||||
// from code logic, we won't be fetching our own data
|
||||
a1.set(p1 + "/0/1", data1.c_str(), data1.size());
|
||||
a1.set(p1 + "/0/2", data2.c_str(), data2.size());
|
||||
BOOST_CHECK_EQUAL(a1.toString(), a2.toString());
|
||||
BOOST_CHECK_EQUAL(a2.toString(), a3.toString());
|
||||
|
||||
// another single source
|
||||
string data3 = "You surf the Internet, I surf the real world";
|
||||
string data4 = "I got a fortune cookie once that said 'You like Chinese food'";
|
||||
string data5 = "Real men wear pink. Why? Because their wives make them";
|
||||
_LOG_DEBUG ("s3 publish");
|
||||
s3.publishData(p3, 0, data3.c_str(), data3.size(), 10);
|
||||
this_thread::sleep (posix_time::milliseconds (200));
|
||||
|
||||
// another single source, multiple data at once
|
||||
s2.publishData(p2, 0, data4.c_str(), data4.size(), 10);
|
||||
s2.publishData(p2, 0, data5.c_str(), data5.size(), 10);
|
||||
this_thread::sleep (posix_time::milliseconds (1000));
|
||||
|
||||
// from code logic, we won't be fetching our own data
|
||||
a3.set(p3 + "/0/0", data3.c_str(), data3.size());
|
||||
a2.set(p2 + "/0/0", data4.c_str(), data4.size());
|
||||
a2.set(p2 + "/0/1", data5.c_str(), data5.size());
|
||||
BOOST_CHECK_EQUAL(a1.toString(), a2.toString());
|
||||
BOOST_CHECK_EQUAL(a2.toString(), a3.toString());
|
||||
|
||||
// not sure weither this is simultanous data generation from multiple sources
|
||||
_LOG_DEBUG ("Simultaneous publishing");
|
||||
string data6 = "Shakespeare says: 'Prose before hos.'";
|
||||
string data7 = "Pick good people, talent never wears out";
|
||||
s1.publishData(p1, 0, data6.c_str(), data6.size(), 10);
|
||||
// this_thread::sleep (posix_time::milliseconds (1000));
|
||||
s2.publishData(p2, 0, data7.c_str(), data7.size(), 10);
|
||||
this_thread::sleep (posix_time::milliseconds (1500));
|
||||
|
||||
// from code logic, we won't be fetching our own data
|
||||
a1.set(p1 + "/0/3", data6.c_str(), data6.size());
|
||||
a2.set(p2 + "/0/2", data7.c_str(), data7.size());
|
||||
// a1.set(p1 + "/0/1", data6);
|
||||
// a2.set(p2 + "/0/0", data7);
|
||||
BOOST_CHECK_EQUAL(a1.toString(), a2.toString());
|
||||
BOOST_CHECK_EQUAL(a2.toString(), a3.toString());
|
||||
|
||||
_LOG_DEBUG("Begin new test");
|
||||
std::cout << "Begin new Test " << std::endl;
|
||||
string syncRawPrefix = "/this/is/the/prefix";
|
||||
ndn::Ptr<SyncPolicyManager> policyManager2 = ndn::Ptr<SyncPolicyManager>(new SyncPolicyManager(ndn::Name("/ndn/ucla.edu/alice"), ndn::Name("/ndn/ucla.edu/alice/KEY/dsk-1382934202/ID-CERT/%FD%FF%FF%FF%FF%DEk%C0%0B"), ndn::Name(syncRawPrefix)));
|
||||
|
||||
a1.sum = 0;
|
||||
a2.sum = 0;
|
||||
SyncSocket s4 (syncRawPrefix, policyManager2, bind(&TestSocketApp::fetchNumbers, &a1, _1, _2), bind(&TestSocketApp::pass, &a1, _1));
|
||||
SyncSocket s5 (syncRawPrefix, policyManager2, bind(&TestSocketApp::fetchNumbers, &a2, _1, _2), bind(&TestSocketApp::pass, &a2, _1));
|
||||
|
||||
int num[5] = {0, 1, 2, 3, 4};
|
||||
|
||||
string p4 = "/xiaonei.com";
|
||||
string p5 = "/mitbbs.com";
|
||||
|
||||
s4.publishData(p4, 0,(const char *) num, sizeof(num), 10);
|
||||
a1.setNum(p4, (const char *) num, sizeof (num));
|
||||
|
||||
this_thread::sleep (posix_time::milliseconds (1000));
|
||||
BOOST_CHECK(a1.sum == a2.sum && a1.sum == 10);
|
||||
|
||||
int newNum[5] = {9, 7, 2, 1, 1};
|
||||
|
||||
s5.publishData(p5, 0,(const char *) newNum, sizeof(newNum), 10);
|
||||
a2.setNum(p5, (const char *)newNum, sizeof (newNum));
|
||||
this_thread::sleep (posix_time::milliseconds (1000));
|
||||
BOOST_CHECK_EQUAL(a1.sum, a2.sum);
|
||||
BOOST_CHECK_EQUAL(a1.sum, 30);
|
||||
|
||||
_LOG_DEBUG ("Finish");
|
||||
}
|
||||
@@ -27,7 +27,8 @@ using boost::test_tools::output_test_stream;
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
#include "ccnx/sync-ccnx-wrapper.h"
|
||||
// #include <ndn.cxx/wrapper/wrapper.h>
|
||||
#include "sync-policy-manager.h"
|
||||
#include "sync-logic.h"
|
||||
#include "sync-seq-no.h"
|
||||
|
||||
@@ -75,7 +76,9 @@ BOOST_AUTO_TEST_CASE (SyncLogicTest)
|
||||
{
|
||||
Handler h1 ("1");
|
||||
|
||||
SyncLogic l1 ("/bcast", bind (&Handler::wrapper, &h1, _1), bind (&Handler::onRemove, &h1, _1));
|
||||
ndn::Ptr<SyncPolicyManager> policyManager1 = ndn::Ptr<SyncPolicyManager>(new SyncPolicyManager(ndn::Name("/ndn/ucla.edu/alice"), ndn::Name("/ndn/ucla.edu/alice/KEY/dsk-1382934202/ID-CERT/%FD%FF%FF%FF%FF%DEk%C0%0B"), ndn::Name("/bcast")));
|
||||
|
||||
SyncLogic l1 (ndn::Name("/bcast"), policyManager1, bind (&Handler::wrapper, &h1, _1), bind (&Handler::onRemove, &h1, _1));
|
||||
|
||||
std::string oldDigest = l1.getRootDigest();
|
||||
|
||||
@@ -86,7 +89,10 @@ BOOST_AUTO_TEST_CASE (SyncLogicTest)
|
||||
BOOST_CHECK_EQUAL (h1.m_map.size (), 0);
|
||||
|
||||
Handler h2 ("2");
|
||||
SyncLogic l2 ("/bcast", bind (&Handler::wrapper, &h2, _1), bind (&Handler::onRemove, &h2, _1));
|
||||
|
||||
ndn::Ptr<SyncPolicyManager> policyManager2 = ndn::Ptr<SyncPolicyManager>(new SyncPolicyManager(ndn::Name("/ndn/ucla.edu/bob"), ndn::Name("/ndn/ucla.edu/bob/KEY/dsk-1382934206/ID-CERT/%FD%FF%FF%FF%FF%DEl%0BC"), ndn::Name("/bcast")));
|
||||
|
||||
SyncLogic l2 (ndn::Name("/bcast"), policyManager2, bind (&Handler::wrapper, &h2, _1), bind (&Handler::onRemove, &h2, _1));
|
||||
|
||||
sleep (1);
|
||||
BOOST_CHECK_EQUAL (h1.m_map.size (), 0);
|
||||
|
||||
@@ -7,7 +7,7 @@ from waflib import Configure, Build, Logs
|
||||
|
||||
def options(opt):
|
||||
opt.load('compiler_c compiler_cxx boost doxygen gnu_dirs protoc')
|
||||
opt.load('ndnx', tooldir=["waf-tools"])
|
||||
# opt.load('ndnx', tooldir=["waf-tools"])
|
||||
|
||||
syncopt = opt.add_option_group ("ChronoSync Options")
|
||||
|
||||
@@ -17,7 +17,7 @@ def options(opt):
|
||||
|
||||
def configure(conf):
|
||||
conf.load('compiler_c compiler_cxx gnu_dirs boost')
|
||||
conf.load('ndnx')
|
||||
# conf.load('ndnx')
|
||||
|
||||
if conf.options.debug:
|
||||
conf.define ('_DEBUG', 1)
|
||||
@@ -32,8 +32,11 @@ def configure(conf):
|
||||
else:
|
||||
conf.add_supported_cxxflags (cxxflags = ['-O3', '-g'])
|
||||
|
||||
conf.check_ndnx ()
|
||||
conf.check_openssl ()
|
||||
# conf.check_ndnx ()
|
||||
|
||||
conf.check_cfg(package='libndn.cxx', args=['--cflags', '--libs'], uselib_store='NDNCXX', mandatory=True)
|
||||
conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='OPENSSL', mandatory=True)
|
||||
# conf.check_openssl ()
|
||||
|
||||
conf.check_boost(lib='system iostreams test thread')
|
||||
|
||||
@@ -55,7 +58,7 @@ def build (bld):
|
||||
target="ChronoSync",
|
||||
features=['cxx', 'cxxshlib'],
|
||||
source = bld.path.ant_glob (['src/**/*.cc', 'src/**/*.proto']),
|
||||
use = 'BOOST BOOST_IOSTREAMS BOOST_THREAD SSL NDNX',
|
||||
use = 'BOOST BOOST_IOSTREAMS BOOST_THREAD SSL NDNCXX OPENSSL',
|
||||
includes = ['src'],
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user