NLSR - (Hello Protocol + FIB Update)
diff --git a/src/utility/nlsr_logger.cpp b/src/utility/nlsr_logger.cpp
index 804ef98..82b6e75 100644
--- a/src/utility/nlsr_logger.cpp
+++ b/src/utility/nlsr_logger.cpp
@@ -3,57 +3,57 @@
namespace nlsr
{
- string
- NlsrLogger::getEpochTime()
- {
- std::stringstream ss;
- boost::posix_time::ptime time_t_epoch(boost::gregorian::date(1970,1,1));
- boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
- boost::posix_time::time_duration diff = now - time_t_epoch;
- ss<<diff.total_seconds()<<"."<<boost::format("%06i")%(diff.total_microseconds()
- %1000000);
- return ss.str();
- }
+ string
+ NlsrLogger::getEpochTime()
+ {
+ std::stringstream ss;
+ boost::posix_time::ptime time_t_epoch(boost::gregorian::date(1970,1,1));
+ boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
+ boost::posix_time::time_duration diff = now - time_t_epoch;
+ ss<<diff.total_seconds()<<"."<<boost::format("%06i")%(diff.total_microseconds()
+ %1000000);
+ return ss.str();
+ }
- string
- NlsrLogger::getUserHomeDirectory()
+ string
+ NlsrLogger::getUserHomeDirectory()
+ {
+ string homeDirPath(getpwuid(getuid())->pw_dir);
+ if( homeDirPath.empty() )
{
- string homeDirPath(getpwuid(getuid())->pw_dir);
- if( homeDirPath.empty() )
- {
- homeDirPath = getenv("HOME");
- }
- return homeDirPath;
+ homeDirPath = getenv("HOME");
}
+ return homeDirPath;
+ }
- void
- NlsrLogger::initNlsrLogger(std::string dirPath)
+ void
+ NlsrLogger::initNlsrLogger(std::string dirPath)
+ {
+ string logDirPath(dirPath);
+ if( dirPath.empty() )
{
- string logDirPath(dirPath);
- if( dirPath.empty() )
- {
- logDirPath=getUserHomeDirectory()+"/nlsrLog";
- }
- cout<<"Log Dir Path: "<< logDirPath<<endl;
- typedef sinks::synchronous_sink< sinks::text_file_backend > file_sink;
- shared_ptr< file_sink > sink(new file_sink(
- keywords::file_name = logDirPath
- +"/NLSR%Y%m%d%H%M%S_%3N.log",
- keywords::rotation_size = 128 * 1024 * 1024,
- keywords::time_based_rotation = sinks::file::rotation_at_time_point(12, 0, 0),
- keywords::auto_flush = true
- ));
- sink->locked_backend()->set_file_collector(sinks::file::make_collector(
- keywords::target = logDirPath,
- keywords::max_size = 16 * 1024 * 1024 * 1024,
- keywords::min_free_space = 128 * 1024 * 1024
- ));
- sink->set_formatter(
- expr::format("%1%: %2%")
- % getEpochTime()
- % expr::smessage
- );
- logging::core::get()->add_sink(sink);
+ logDirPath=getUserHomeDirectory()+"/nlsrLog";
}
+ cout<<"Log Dir Path: "<< logDirPath<<endl;
+ typedef sinks::synchronous_sink< sinks::text_file_backend > file_sink;
+ shared_ptr< file_sink > sink(new file_sink(
+ keywords::file_name = logDirPath
+ +"/NLSR%Y%m%d%H%M%S_%3N.log",
+ keywords::rotation_size = 16 * 1024 * 1024,
+ keywords::time_based_rotation = sinks::file::rotation_at_time_point(12, 0, 0),
+ keywords::auto_flush = true
+ ));
+ sink->locked_backend()->set_file_collector(sinks::file::make_collector(
+ keywords::target = logDirPath,
+ //keywords::max_size = 512 * 1024 * 1024,
+ keywords::min_free_space = 64 * 1024 * 1024
+ ));
+ sink->set_formatter(
+ expr::format("%1%: %2%")
+ % getEpochTime()
+ % expr::smessage
+ );
+ logging::core::get()->add_sink(sink);
+ }
}//namespace nlsr
diff --git a/src/utility/nlsr_logger.hpp b/src/utility/nlsr_logger.hpp
index 222ac52..129fe30 100644
--- a/src/utility/nlsr_logger.hpp
+++ b/src/utility/nlsr_logger.hpp
@@ -25,38 +25,38 @@
namespace nlsr
{
- namespace logging = boost::log;
- namespace attrs = boost::log::attributes;
- namespace src = boost::log::sources;
- namespace sinks = boost::log::sinks;
- namespace expr = boost::log::expressions;
- namespace keywords = boost::log::keywords;
+ namespace logging = boost::log;
+ namespace attrs = boost::log::attributes;
+ namespace src = boost::log::sources;
+ namespace sinks = boost::log::sinks;
+ namespace expr = boost::log::expressions;
+ namespace keywords = boost::log::keywords;
- using boost::shared_ptr;
- using namespace std;
+ using boost::shared_ptr;
+ using namespace std;
- class NlsrLogger
+ class NlsrLogger
+ {
+ public:
+ NlsrLogger()
{
- public:
- NlsrLogger()
- {
- }
+ }
- void initNlsrLogger(std::string dirPath);
+ void initNlsrLogger(std::string dirPath);
- src::logger& getLogger()
- {
- return mLogger;
- }
+ src::logger& getLogger()
+ {
+ return mLogger;
+ }
- private:
- string getEpochTime();
- string getUserHomeDirectory();
+ private:
+ string getEpochTime();
+ string getUserHomeDirectory();
- private:
- src::logger mLogger;
- };
+ private:
+ src::logger mLogger;
+ };
}//namespace nlsr
#endif
diff --git a/src/utility/nlsr_tokenizer.cpp b/src/utility/nlsr_tokenizer.cpp
index 809e395..35d6625 100644
--- a/src/utility/nlsr_tokenizer.cpp
+++ b/src/utility/nlsr_tokenizer.cpp
@@ -9,102 +9,102 @@
namespace nlsr
{
- using namespace std;
- using namespace boost;
+ using namespace std;
+ using namespace boost;
- void
- nlsrTokenizer::makeToken()
+ void
+ nlsrTokenizer::makeToken()
+ {
+ char_separator<char> sep(seps.c_str());
+ tokenizer< char_separator<char> >tokens(originalString, sep);
+ tokenizer< char_separator<char> >::iterator tok_iter = tokens.begin();
+ for ( ; tok_iter != tokens.end(); ++tok_iter)
{
- char_separator<char> sep(seps.c_str());
- tokenizer< char_separator<char> >tokens(originalString, sep);
- tokenizer< char_separator<char> >::iterator tok_iter = tokens.begin();
- for ( ; tok_iter != tokens.end(); ++tok_iter)
- {
- string oneToken(*tok_iter);
- trim(oneToken);
- if(!oneToken.empty())
- {
- insertToken(oneToken);
- }
- }
- firstToken=vTokenList[0];
- makeRestOfTheLine();
+ string oneToken(*tok_iter);
+ trim(oneToken);
+ if(!oneToken.empty())
+ {
+ insertToken(oneToken);
+ }
}
+ firstToken=vTokenList[0];
+ makeRestOfTheLine();
+ }
- void
- nlsrTokenizer::insertToken(const string& token)
- {
- tokenList.push_back(token);
- vTokenList.push_back(token);
- }
+ void
+ nlsrTokenizer::insertToken(const string& token)
+ {
+ tokenList.push_back(token);
+ vTokenList.push_back(token);
+ }
- int
- nlsrTokenizer::getTokenPosition(string& token)
+ int
+ nlsrTokenizer::getTokenPosition(string& token)
+ {
+ int pos=-1;
+ int i=0;
+ for(std::list<string>::iterator it=tokenList.begin();
+ it!=tokenList.end(); it++)
{
- int pos=-1;
- int i=0;
- for(std::list<string>::iterator it=tokenList.begin();
- it!=tokenList.end(); it++)
- {
- if( (*it) == token )
- {
- break;
- }
- i++;
- }
- if( i < tokenList.size() )
- {
- pos=i;
- }
- return pos;
+ if( (*it) == token )
+ {
+ break;
+ }
+ i++;
}
+ if( i < tokenList.size() )
+ {
+ pos=i;
+ }
+ return pos;
+ }
- string
- nlsrTokenizer::getTokenString(int from , int to)
+ string
+ nlsrTokenizer::getTokenString(int from , int to)
+ {
+ string returnString="";
+ if((from>=0 && to<tokenList.size()) &&
+ (to>=from && to <tokenList.size()))
{
- string returnString="";
- if((from>=0 && to<tokenList.size()) &&
- (to>=from && to <tokenList.size()))
- {
- for(int i=from; i<=to; i++)
- {
- returnString+=seps;
- returnString+=vTokenList[i];
- }
- }
- trim(returnString);
- return returnString;
+ for(int i=from; i<=to; i++)
+ {
+ returnString+=seps;
+ returnString+=vTokenList[i];
+ }
}
+ trim(returnString);
+ return returnString;
+ }
- string
- nlsrTokenizer::getTokenString(int from)
- {
- return getTokenString(from,tokenList.size()-1);
- }
+ string
+ nlsrTokenizer::getTokenString(int from)
+ {
+ return getTokenString(from,tokenList.size()-1);
+ }
- static bool
- tokenCompare(string& s1, string& s2)
- {
- return s1==s2;
- }
+ static bool
+ tokenCompare(string& s1, string& s2)
+ {
+ return s1==s2;
+ }
- void
- nlsrTokenizer::makeRestOfTheLine()
- {
- restOfTheLine=getTokenString(1);
- }
+ void
+ nlsrTokenizer::makeRestOfTheLine()
+ {
+ restOfTheLine=getTokenString(1);
+ }
- bool
- nlsrTokenizer::doesTokenExist(string token)
+ bool
+ nlsrTokenizer::doesTokenExist(string token)
+ {
+ std::list<string >::iterator it = std::find_if( tokenList.begin(),
+ tokenList.end(),
+ bind(&tokenCompare, _1 , token));
+ if( it != tokenList.end() )
{
- std::list<string >::iterator it = std::find_if( tokenList.begin(),
- tokenList.end(),
- bind(&tokenCompare, _1 , token));
- if( it != tokenList.end() )
- {
- return true;
- }
- return false;
+ return true;
}
+ return false;
+ }
}//namespace nlsr
diff --git a/src/utility/nlsr_tokenizer.hpp b/src/utility/nlsr_tokenizer.hpp
index 6cd97e0..4b84d8b 100644
--- a/src/utility/nlsr_tokenizer.hpp
+++ b/src/utility/nlsr_tokenizer.hpp
@@ -12,93 +12,93 @@
namespace nlsr
{
- using namespace std;
- using namespace boost;
+ using namespace std;
+ using namespace boost;
- class nlsrTokenizer
+ class nlsrTokenizer
+ {
+ public:
+ nlsrTokenizer(const string& inputString)
+ : firstToken()
+ , restOfTheLine()
+ , currentPosition(0)
{
- public:
- nlsrTokenizer(const string& inputString)
- : firstToken()
- , restOfTheLine()
- , currentPosition(0)
- {
- seps = " ";
- originalString = inputString;
- makeToken();
- }
+ seps = " ";
+ originalString = inputString;
+ makeToken();
+ }
- nlsrTokenizer(const string& inputString, const string& separator)
- : firstToken()
- , restOfTheLine()
- , currentPosition(0)
- {
- seps = separator;
- originalString = inputString;
- makeToken();
- }
+ nlsrTokenizer(const string& inputString, const string& separator)
+ : firstToken()
+ , restOfTheLine()
+ , currentPosition(0)
+ {
+ seps = separator;
+ originalString = inputString;
+ makeToken();
+ }
- string getFirstToken()
- {
- return firstToken;
- }
+ string getFirstToken()
+ {
+ return firstToken;
+ }
- string getRestOfLine()
- {
- return restOfTheLine;
- }
+ string getRestOfLine()
+ {
+ return restOfTheLine;
+ }
- void resetCurrentPosition(uint32_t cp=0)
- {
- if( cp >=0 && cp <= vTokenList.size() )
- {
- currentPosition=cp;
- }
- }
+ void resetCurrentPosition(uint32_t cp=0)
+ {
+ if( cp >=0 && cp <= vTokenList.size() )
+ {
+ currentPosition=cp;
+ }
+ }
- string getNextToken()
- {
- if(currentPosition >= 0 && currentPosition <= (vTokenList.size()-1))
- {
- return vTokenList[currentPosition++];
- }
- return "";
- }
+ string getNextToken()
+ {
+ if(currentPosition >= 0 && currentPosition <= (vTokenList.size()-1))
+ {
+ return vTokenList[currentPosition++];
+ }
+ return "";
+ }
- uint32_t getTokenNumber()
- {
- return tokenList.size();
- }
+ uint32_t getTokenNumber()
+ {
+ return tokenList.size();
+ }
- string getToken(int position)
- {
- if( position >=0 && position <vTokenList.size() )
- {
- return vTokenList[position];
- }
- return "";
- }
+ string getToken(int position)
+ {
+ if( position >=0 && position <vTokenList.size() )
+ {
+ return vTokenList[position];
+ }
+ return "";
+ }
- int getTokenPosition(string& token);
- string getTokenString(int from , int to);
- string getTokenString(int from);
- bool doesTokenExist(string token);
+ int getTokenPosition(string& token);
+ string getTokenString(int from , int to);
+ string getTokenString(int from);
+ bool doesTokenExist(string token);
- private:
+ private:
- void makeToken();
- void insertToken(const string& token);
- void makeRestOfTheLine();
+ void makeToken();
+ void insertToken(const string& token);
+ void makeRestOfTheLine();
- string seps;
- string originalString;
- string firstToken;
- string restOfTheLine;
- std::list<string> tokenList;
- std::vector<string> vTokenList;
- uint32_t currentPosition;
- };
+ string seps;
+ string originalString;
+ string firstToken;
+ string restOfTheLine;
+ std::list<string> tokenList;
+ std::vector<string> vTokenList;
+ uint32_t currentPosition;
+ };
}//namespace nlsr
#endif