security: Integrate certificate exchanging into sync
Change-Id: I6ea284b0683d75013f6b72845d894eaed29e468c
diff --git a/src/sync-socket.h b/src/sync-socket.h
index f796fed..72df7ab 100644
--- a/src/sync-socket.h
+++ b/src/sync-socket.h
@@ -27,6 +27,7 @@
#include "sync-logic.h"
#include "sync-seq-no.h"
+#include "sync-validator.h"
#include <utility>
#include <map>
@@ -45,59 +46,78 @@
typedef ndn::function< void (const std::vector<MissingDataInfo> &, SyncSocket * ) > NewDataCallback;
typedef ndn::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 ndn::Name& syncPrefix,
- const ndn::Name& identity,
- ndn::shared_ptr<ndn::Validator> validator,
+ const ndn::Name& dataPrefix,
+ uint64_t dataSession,
+ const ndn::IdentityCertificate& myCertificate,
+ ndn::shared_ptr<ndn::SecRuleRelative> dataRule,
ndn::shared_ptr<ndn::Face> face,
NewDataCallback dataCallback,
RemoveCallback rmCallback);
~SyncSocket ();
- bool
- publishData(const ndn::Name &prefix, uint64_t session, const char *buf, size_t len, int freshness);
+ void
+ publishData(const uint8_t* buf, size_t len, int freshness, bool isCert = false);
void
remove (const ndn::Name &prefix)
- { m_syncLogic.remove(prefix); }
+ {
+ m_syncLogic.remove(prefix);
+ }
void
fetchData(const ndn::Name &prefix, const SeqNo &seq, const ndn::OnDataValidated& onValidated, int retry = 0);
std::string
getRootDigest()
- { return m_syncLogic.getRootDigest(); }
+ {
+ return m_syncLogic.getRootDigest();
+ }
uint64_t
- getNextSeq (const ndn::Name &prefix, uint64_t session);
+ getNextSeq (const ndn::Name &prefix, uint64_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;
+ }
SyncLogic &
getLogic ()
- { return m_syncLogic; }
+ {
+ 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 ();
+ void
+ addParticipant(const ndn::IdentityCertificate& introducee)
+ {
+ ndn::shared_ptr<const IntroCertificate> introCert = m_syncValidator->addParticipant(introducee);
+ }
+
+ // // 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
- publishDataInternal(ndn::shared_ptr<ndn::Data> data, const ndn::Name &prefix, uint64_t session);
+ publishDataInternal(ndn::shared_ptr<ndn::Data> data,
+ const ndn::Name &prefix,
+ uint64_t session,
+ bool isCert);
void
passCallback(const std::vector<MissingDataInfo> &v)
- { m_newDataCallback(v, this); }
+ {
+ m_newDataCallback(v, this);
+ }
void
onData(const ndn::Interest& interest, ndn::Data& data,
@@ -111,17 +131,26 @@
const ndn::OnDataValidationFailed& onValidationFailed);
void
- onDataValidationFailed(const ndn::shared_ptr<const ndn::Data>& data);
+ onDataValidated(const ndn::shared_ptr<const ndn::Data>& data,
+ size_t interestNameSize,
+ const ndn::OnDataValidated& onValidated);
+
+ void
+ onDataValidationFailed(const ndn::shared_ptr<const ndn::Data>& data,
+ const std::string& failureInfo);
private:
typedef std::map<ndn::Name, SeqNo> SequenceLog;
+
+ ndn::Name m_dataPrefix;
+ uint64_t m_dataSession;
NewDataCallback m_newDataCallback;
SequenceLog m_sequenceLog;
- ndn::Name m_identity;
- ndn::shared_ptr<ndn::Validator> m_validator;
- ndn::shared_ptr<ndn::KeyChain> m_keyChain;
+ ndn::IdentityCertificate m_myCertificate;
+ ndn::KeyChain m_keyChain;
ndn::shared_ptr<ndn::Face> m_face;
ndn::shared_ptr<boost::asio::io_service> m_ioService;
+ ndn::shared_ptr<SyncValidator> m_syncValidator;
SyncLogic m_syncLogic;
};