use protobuf instead of tinyxml
diff --git a/include/sync-logic.h b/include/sync-logic.h
index 551cb06..5e32918 100644
--- a/include/sync-logic.h
+++ b/include/sync-logic.h
@@ -101,7 +101,7 @@
* @param name the data name
* @param dataBuffer the sync data
*/
- void respondSyncData (const std::string &name, const std::string &dataBuffer);
+ void respondSyncData (const std::string &name, const char *wireData, size_t len);
/**
* @brief remove a participant's subtree from the sync tree
@@ -133,7 +133,7 @@
void
processSyncData (const std::string &name,
- DigestConstPtr digest, const std::string &dataBuffer);
+ DigestConstPtr digest, const char *wireData, size_t len);
void
processSyncRecoveryInterest (const std::string &name,
diff --git a/include/sync-state.h b/include/sync-state.h
index c96160e..84c2400 100644
--- a/include/sync-state.h
+++ b/include/sync-state.h
@@ -93,7 +93,7 @@
* @returns SyncStateMsg msg
*/
SyncStateMsg &
-operator >> (SyncStateMsg &issm, const State &state);
+operator >> (SyncStateMsg &issm, State &state);
namespace Error {
/**
diff --git a/model/sync-logic.cc b/model/sync-logic.cc
index 943126b..b72a061 100644
--- a/model/sync-logic.cc
+++ b/model/sync-logic.cc
@@ -29,6 +29,7 @@
#include "sync-diff-leaf.h"
#include "sync-full-leaf.h"
#include "sync-log.h"
+#include "sync-state.h"
#include <boost/make_shared.hpp>
#include <boost/foreach.hpp>
@@ -278,10 +279,10 @@
DiffState diff;
SyncStateMsg msg;
- if (!msg.parseFromArray(wireData, len) || !msg.IsInitialized())
+ if (!msg.ParseFromArray(wireData, len) || !msg.IsInitialized())
{
//Throw
- BOOST_THROW_EXCEPTION (SyncStateMsgDecodingFailure () << info_str ("Can not decode data"));
+ BOOST_THROW_EXCEPTION (Error::SyncStateMsgDecodingFailure () );
}
msg >> diff;
@@ -526,11 +527,12 @@
// sending
SyncStateMsg ssm;
ssm << (*state);
- char *wireData = new char[ssm.size()];
- ssm.SerializedToArray(wireData, ssm.size());
+ int size = ssm.ByteSize();
+ char *wireData = new char[size];
+ ssm.SerializeToArray(wireData, size);
m_ccnxHandle->publishRawData (name,
wireData,
- ssm.size(),
+ size,
m_syncResponseFreshness); // in NS-3 it doesn't have any effect... yet
delete wireData;
diff --git a/model/sync-state.cc b/model/sync-state.cc
index 45a7ab7..137e8b0 100644
--- a/model/sync-state.cc
+++ b/model/sync-state.cc
@@ -74,9 +74,9 @@
{
BOOST_FOREACH (shared_ptr<const Leaf> leaf, state.getLeaves ().get<ordered> ())
{
- SyncState *oss = ossm->add_ss();
+ SyncState *oss = ossm.add_ss();
shared_ptr<const DiffLeaf> diffLeaf = dynamic_pointer_cast<const DiffLeaf> (leaf);
- if (diffLeaf != 0 && diffLeaf->getOperation != UPDATE)
+ if (diffLeaf != 0 && diffLeaf->getOperation() != UPDATE)
{
oss->set_type(SyncState::DELETE);
}
@@ -91,10 +91,9 @@
if (diffLeaf == 0 || (diffLeaf != 0 && diffLeaf->getOperation () == UPDATE))
{
- SyncState::SeqNo seqNo;
- seqNo->set_session(leaf->getSeq()->getSession());
- seqNo->set_seq(leaf->getSeq()->getSeq());
- oss->set_seqNo(seqNo);
+ SyncState::SeqNo *seqNo = oss->mutable_seqno();
+ seqNo->set_session(leaf->getSeq().getSession());
+ seqNo->set_seq(leaf->getSeq().getSeq());
}
}
return ossm;
@@ -150,7 +149,7 @@
*/
SyncStateMsg &
-operator >> (SyncStateMsg &issm, const State &state)
+operator >> (SyncStateMsg &issm, State &state)
{
int n = issm.ss_size();
for (int i = 0; i < n; i++)
@@ -159,10 +158,10 @@
NameInfoConstPtr info = StdNameInfo::FindOrCreate (ss.name());
if (ss.type() == SyncState::UPDATE)
{
- state.update(info, SeqNo(
- lexical_cast<uint32_t> (ss.seqNo().session()),
- lexical_cast<uint32_t> (ss.seqNo().seq()),
- ));
+ uint32_t session = lexical_cast<uint32_t>(ss.seqno().session());
+ uint32_t seq = lexical_cast<uint32_t>(ss.seqno().seq());
+ SeqNo seqNo(session, seq);
+ state.update(info, seqNo);
}
else
{
diff --git a/proto/sync-state.proto b/sync-state.proto
similarity index 91%
rename from proto/sync-state.proto
rename to sync-state.proto
index 71bd1e7..18892fb 100644
--- a/proto/sync-state.proto
+++ b/sync-state.proto
@@ -15,7 +15,7 @@
required uint32 seq = 1;
required uint32 session = 2;
}
- optional SeqNo seqNo = 3;
+ optional SeqNo seqno = 3;
}
message SyncStateMsg
diff --git a/test/test_state.cc b/test/test_state.cc.outdated
similarity index 100%
rename from test/test_state.cc
rename to test/test_state.cc.outdated
diff --git a/waf-tools/protobuf.py b/waf-tools/protobuf.py
new file mode 100644
index 0000000..71d8bdf
--- /dev/null
+++ b/waf-tools/protobuf.py
@@ -0,0 +1,76 @@
+#! /usr/bin/env python
+# encoding: utf-8
+
+'''
+
+When using this tool, the wscript will look like:
+
+ def options(opt):
+ opt.tool_options('protobuf', tooldir=["waf-tools"])
+
+ def configure(conf):
+ conf.load('compiler_cxx protobuf')
+
+ def build(bld):
+ bld(source='main.cpp', target='app', use='PROTOBUF')
+
+Options are generated, in order to specify the location of protobuf includes/libraries.
+
+
+'''
+import sys
+import re
+from waflib import Utils,Logs,Errors
+from waflib.Configure import conf
+PROTOBUF_DIR=['/usr','/usr/local','/opt/local','/sw']
+PROTOBUF_VERSION_FILE='google/protobuf/stubs/common.h'
+PROTOBUF_VERSION_CODE='''
+#include <iostream>
+#include <google/protobuf/stubs/common.h>
+int main() { std::cout << GOOGLE_PROTOBUF_VERSION ;}
+'''
+
+def options(opt):
+ opt.add_option('--protobuf',type='string',default='',dest='protobuf_dir',help='''path to where protobuf is installed, e.g. /usr/local''')
+@conf
+def __protobuf_get_version_file(self,dir):
+ try:
+ return self.root.find_dir(dir).find_node('%s/%s' % ('include', PROTOBUF_VERSION_FILE))
+ except:
+ return None
+@conf
+def protobuf_get_version(self,dir):
+ val=self.check_cxx(fragment=PROTOBUF_VERSION_CODE,includes=['%s/%s' % (dir, 'include')], execute=True, define_ret = True, mandatory=True)
+ return val
+@conf
+def protobuf_get_root(self,*k,**kw):
+ root=k and k[0]or kw.get('path',None)
+ # Logs.pprint ('RED', ' %s' %root)
+ if root and self.__protobuf_get_version_file(root):
+ return root
+ for dir in PROTOBUF_DIR:
+ if self.__protobuf_get_version_file(dir):
+ return dir
+ if root:
+ self.fatal('Protobuf not found in %s'%root)
+ else:
+ self.fatal('Protobuf not found, please provide a --protobuf argument (see help)')
+@conf
+def check_protobuf(self,*k,**kw):
+ if not self.env['CXX']:
+ self.fatal('load a c++ compiler first, conf.load("compiler_cxx")')
+
+ var=kw.get('uselib_store','PROTOBUF')
+ self.start_msg('Checking Protocol Buffer')
+ root = self.protobuf_get_root(*k,**kw);
+ self.env.PROTOBUF_VERSION=self.protobuf_get_version(root)
+
+ self.env['INCLUDES_%s'%var]= '%s/%s' % (root, "include");
+ self.env['LIB_%s'%var] = "protobuf"
+ self.env['LIBPATH_%s'%var] = '%s/%s' % (root, "lib")
+
+ self.end_msg(self.env.PROTOBUF_VERSION)
+ if Logs.verbose:
+ Logs.pprint('CYAN',' Protocol Buffer include : %s'%self.env['INCLUDES_%s'%var])
+ Logs.pprint('CYAN',' Protocol Buffer lib : %s'%self.env['LIB_%s'%var])
+ Logs.pprint('CYAN',' Protocol Buffer libpath : %s'%self.env['LIBPATH_%s'%var])
diff --git a/waf-tools/tinyxml.py b/waf-tools/tinyxml.py
deleted file mode 100644
index 3908b38..0000000
--- a/waf-tools/tinyxml.py
+++ /dev/null
@@ -1,76 +0,0 @@
-#! /usr/bin/env python
-# encoding: utf-8
-
-'''
-
-When using this tool, the wscript will look like:
-
- def options(opt):
- opt.tool_options('tinyxml', tooldir=["waf-tools"])
-
- def configure(conf):
- conf.load('compiler_cxx tiny')
-
- def build(bld):
- bld(source='main.cpp', target='app', use='TINYXML')
-
-Options are generated, in order to specify the location of tinyxml includes/libraries.
-
-
-'''
-import sys
-import re
-from waflib import Utils,Logs,Errors
-from waflib.Configure import conf
-TINYXML_DIR=['/usr','/usr/local','/opt/local','/sw']
-TINYXML_VERSION_FILE='tinyxml.h'
-TINYXML_VERSION_CODE='''
-#include <iostream>
-#include <tinyxml.h>
-int main() { std::cout << TIXML_MAJOR_VERSION << "." << TIXML_MINOR_VERSION << "." << TIXML_PATCH_VERSION; }
-'''
-
-def options(opt):
- opt.add_option('--tinyxml',type='string',default='',dest='tinyxml_dir',help='''path to where TinyXML is installed, e.g. /usr/local''')
-@conf
-def __tinyxml_get_version_file(self,dir):
- try:
- return self.root.find_dir(dir).find_node('%s/%s' % ('include', TINYXML_VERSION_FILE))
- except:
- return None
-@conf
-def tinyxml_get_version(self,dir):
- val=self.check_cxx(fragment=TINYXML_VERSION_CODE,includes=['%s/%s' % (dir, 'include')], execute=True, define_ret = True, mandatory=True)
- return val
-@conf
-def tinyxml_get_root(self,*k,**kw):
- root=k and k[0]or kw.get('path',None)
- # Logs.pprint ('RED', ' %s' %root)
- if root and self.__tinyxml_get_version_file(root):
- return root
- for dir in TINYXML_DIR:
- if self.__tinyxml_get_version_file(dir):
- return dir
- if root:
- self.fatal('TinyXML not found in %s'%root)
- else:
- self.fatal('TinyXML not found, please provide a --tinyxml argument (see help)')
-@conf
-def check_tinyxml(self,*k,**kw):
- if not self.env['CXX']:
- self.fatal('load a c++ compiler first, conf.load("compiler_cxx")')
-
- var=kw.get('uselib_store','TINYXML')
- self.start_msg('Checking TinyXML')
- root = self.tinyxml_get_root(*k,**kw);
- self.env.TINYXML_VERSION=self.tinyxml_get_version(root)
-
- self.env['INCLUDES_%s'%var]= '%s/%s' % (root, "include");
- self.env['LIB_%s'%var] = "tinyxml"
- self.env['LIBPATH_%s'%var] = '%s/%s' % (root, "lib")
-
- self.end_msg(self.env.TINYXML_VERSION)
- if Logs.verbose:
- Logs.pprint('CYAN',' TinyXML include : %s'%self.env['INCLUDES_%s'%var])
- Logs.pprint('CYAN',' TinyXML lib : %s'%self.env['LIB_%s'%var])
- Logs.pprint('CYAN',' TinyXML libpath : %s'%self.env['LIBPATH_%s'%var])
diff --git a/wscript b/wscript
index df97940..c87bf89 100644
--- a/wscript
+++ b/wscript
@@ -13,7 +13,7 @@
opt.load('compiler_cxx')
opt.load('boost')
opt.load('doxygen')
- opt.load('ccnx tinyxml ns3', tooldir=["waf-tools"])
+ opt.load('ccnx protobuf ns3', tooldir=["waf-tools"])
def configure(conf):
conf.load("compiler_cxx")
@@ -61,10 +61,18 @@
except:
pass
- conf.load('tinyxml')
- conf.check_tinyxml ()
+ conf.load('protobuf')
+ conf.check_protobuf (path=conf.options.protobuf_dir)
+
+def pre(bld):
+ bld.exec_command('protoc --cpp_out=. sync-state.proto')
+ bld.exec_command('mv sync-state.pb.h include/')
+ bld.exec_command('mv sync-state.pb.cc model/')
+
def build (bld):
+ bld.add_pre_fun(pre)
+
if bld.get_define ("NS3_MODULE"):
sync_ns3 = bld.shlib (
target = "sync-ns3",
@@ -91,8 +99,9 @@
'model/sync-seq-no.cc',
'model/sync-state.cc',
'model/sync-std-name-info.cc',
+ 'model/sync-state.pb.cc',
],
- use = 'BOOST BOOST_IOSTREAMS SSL TINYXML ' + ' '.join (['ns3_'+dep for dep in ['core', 'network', 'internet', 'NDNabstraction']]).upper (),
+ use = 'BOOST BOOST_IOSTREAMS SSL PROTOBUF ' + ' '.join (['ns3_'+dep for dep in ['core', 'network', 'internet', 'NDNabstraction']]).upper (),
includes = ['include', 'include/ns3', 'helper'],
)
@@ -139,8 +148,9 @@
'model/sync-seq-no.cc',
'model/sync-state.cc',
'model/sync-std-name-info.cc',
+ 'model/sync-state.pb.cc',
],
- use = 'BOOST BOOST_IOSTREAMS BOOST_THREAD SSL TINYXML CCNX',
+ use = 'BOOST BOOST_IOSTREAMS BOOST_THREAD SSL PROTOBUF CCNX',
includes = ['include', 'helper'],
)