2008-05-08 20:27:28 -04:00
/*
* libretroshare / src / services : p3Qblog . cc
*
* RetroShare C + + Interface .
*
* Copyright 2007 - 2008 by Chris Evi - Parker
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation .
*
* This library 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
* Library General Public License for more details .
*
* You should have received a copy of the GNU Library General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307
* USA .
*
* Please report all bugs and problems to " retroshare@lunamutt.com " .
*
*/
2008-06-04 06:59:24 -04:00
# include "serialiser/rsqblogitems.h"
2008-09-21 16:30:34 -04:00
# include "p3Qblog.h"
2008-05-08 20:27:28 -04:00
# include <utility>
# include <ctime>
2008-06-04 06:59:24 -04:00
# include <iomanip>
# include "pqi/pqibin.h"
# include "pqi/p3authmgr.h"
2008-05-08 20:27:28 -04:00
2008-09-21 16:30:34 -04:00
const uint32_t BLOG_MAX_FWD_OFFSET = ( 60 * 60 * 24 * 2 ) ; /* 2 Days */
2008-06-04 06:59:24 -04:00
const uint32_t FRIEND_QBLOG_REPOST_PERIOD = 60 ; /* every minute for testing */
2008-09-21 16:30:34 -04:00
# define QBLOG_DEBUG 1
p3Qblog : : p3Qblog ( p3ConnectMgr * connMgr ,
2008-06-04 06:59:24 -04:00
uint16_t type , CacheStrapper * cs , CacheTransfer * cft ,
2008-09-21 16:30:34 -04:00
std : : string sourcedir , std : : string storedir ,
2008-06-04 06:59:24 -04:00
uint32_t storePeriod )
2008-09-21 16:30:34 -04:00
: CacheSource ( type , true , cs , sourcedir ) ,
CacheStore ( type , true , cs , cft , storedir ) ,
mConnMgr ( connMgr ) ,
2008-06-19 17:34:13 -04:00
mStorePeriod ( storePeriod ) , mPostsUpdated ( false ) , mProfileUpdated ( false )
2008-05-10 17:33:07 -04:00
{
2008-09-21 16:30:34 -04:00
{
2008-06-04 06:59:24 -04:00
RsStackMutex stack ( mBlogMtx ) ;
mOwnId = mConnMgr - > getOwnId ( ) ; // get your own usr Id
loadDummy ( ) ; // load dummy data
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
# ifdef QBLOG_DEBUG
/*if(!ok)
std : : cerr < < " initialization failed: could not retrieve friend list " ; */
# endif
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
}
2008-09-21 16:30:34 -04:00
2008-05-10 17:33:07 -04:00
return ;
}
2008-06-19 17:34:13 -04:00
std : : ostream & operator < < ( std : : ostream & out , const std : : wstring wstr )
{
std : : string str ( wstr . begin ( ) , wstr . end ( ) ) ;
out < < str ;
2008-09-21 16:30:34 -04:00
2008-06-19 17:34:13 -04:00
return out ;
}
2008-06-04 06:59:24 -04:00
bool p3Qblog : : loadLocalCache ( const CacheData & data )
2008-05-10 17:33:07 -04:00
{
2008-06-04 06:59:24 -04:00
std : : string filename = data . path + ' / ' + data . name ;
std : : string hash = data . hash ;
std : : string source = data . pid ;
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
# ifdef QBLOG_DEBUG
std : : cerr < < " p3Ranking::loadLocalCache() " ;
std : : cerr < < std : : endl ;
std : : cerr < < " \t Source: " < < source ;
std : : cerr < < std : : endl ;
std : : cerr < < " \t Filename: " < < filename ;
std : : cerr < < std : : endl ;
std : : cerr < < " \t Hash: " < < hash ;
std : : cerr < < std : : endl ;
std : : cerr < < " \t Size: " < < data . size ;
std : : cerr < < std : : endl ;
# endif
loadBlogFile ( filename , source ) ;
2008-09-21 16:30:34 -04:00
2008-06-06 19:38:37 -04:00
{
RsStackMutex stack ( mBlogMtx ) ;
2008-06-19 17:34:13 -04:00
mPostsUpdated = true ; // there is nothing to tick/repost (i.e. comes from cache)
2008-06-06 19:38:37 -04:00
}
2008-06-04 06:59:24 -04:00
if ( data . size > 0 ) /* don't refresh zero sized caches */
{
refreshCache ( data ) ;
}
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
return true ;
2008-05-10 17:33:07 -04:00
}
2008-05-08 20:27:28 -04:00
2008-06-04 06:59:24 -04:00
int p3Qblog : : loadCache ( const CacheData & data )
2008-05-08 20:27:28 -04:00
{
2008-06-04 06:59:24 -04:00
std : : string filename = data . path + ' / ' + data . name ;
std : : string hash = data . hash ;
std : : string source = data . pid ;
# ifdef QBLOG_DEBUG
std : : cerr < < " p3Qblog::loadCache() " ;
std : : cerr < < std : : endl ;
std : : cerr < < " \t Source: " < < source ;
std : : cerr < < std : : endl ;
std : : cerr < < " \t Filename: " < < filename ;
std : : cerr < < std : : endl ;
std : : cerr < < " \t Hash: " < < hash ;
std : : cerr < < std : : endl ;
std : : cerr < < " \t Size: " < < data . size ;
std : : cerr < < std : : endl ;
# endif
loadBlogFile ( filename , source ) ;
CacheStore : : lockData ( ) ; /***** LOCK ****/
2008-09-21 16:30:34 -04:00
locked_storeCacheEntry ( data ) ;
2008-06-04 06:59:24 -04:00
CacheStore : : unlockData ( ) ; /***** UNLOCK ****/
return 1 ;
2008-05-08 20:27:28 -04:00
}
2008-06-04 06:59:24 -04:00
bool p3Qblog : : loadBlogFile ( std : : string filename , std : : string src )
2008-05-08 20:27:28 -04:00
{
2008-06-04 06:59:24 -04:00
/* create the serialiser to load info */
RsSerialiser * rsSerialiser = new RsSerialiser ( ) ;
2008-06-19 17:34:13 -04:00
rsSerialiser - > addSerialType ( new RsQblogMsgSerialiser ( ) ) ;
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
uint32_t bioflags = BIN_FLAGS_HASH_DATA | BIN_FLAGS_READABLE ;
2008-09-21 16:30:34 -04:00
BinInterface * bio = new BinFileInterface ( filename . c_str ( ) , bioflags ) ;
2008-06-04 06:59:24 -04:00
pqistreamer * stream = new pqistreamer ( rsSerialiser , src , bio , 0 ) ;
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
# ifdef QBLOG_DEBUG
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
std : : cerr < < " p3Qblog::loadBlogFile() " ;
std : : cerr < < std : : endl ;
std : : cerr < < " \t Source: " < < src ;
std : : cerr < < std : : endl ;
std : : cerr < < " \t Filename: " < < filename ;
std : : cerr < < std : : endl ;
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
# endif
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
/* will load file info to these items */
RsItem * item ;
2008-06-19 17:34:13 -04:00
RsQblogMsg * newBlog ;
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
stream - > tick ( ) ; // tick to read
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
time_t now = time ( NULL ) ;
time_t min , max ;
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
{ /********** STACK LOCKED MTX ******/
RsStackMutex stack ( mBlogMtx ) ;
min = now - mStorePeriod ;
2008-09-21 16:30:34 -04:00
max = now + BLOG_MAX_FWD_OFFSET ;
2008-06-04 06:59:24 -04:00
} /********** STACK LOCKED MTX ******/
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
while ( NULL ! = ( item = stream - > GetItem ( ) ) )
{
# ifdef QBLOG_DEBUG
std : : cerr < < " p3Qblog::loadBlogFile() Got Item: " ;
std : : cerr < < std : : endl ;
item - > print ( std : : cerr , 10 ) ;
std : : cerr < < std : : endl ;
# endif
2008-09-21 16:30:34 -04:00
2008-06-19 17:34:13 -04:00
if ( NULL = = ( newBlog = dynamic_cast < RsQblogMsg * > ( item ) ) )
2008-06-04 06:59:24 -04:00
{
# ifdef QBLOG_DEBUG
std : : cerr < < " p3Qblog::loadBlogFile() Item not Blog (deleting): " ;
std : : cerr < < std : : endl ;
# endif
delete item ;
}
2008-09-21 16:30:34 -04:00
/* check timestamp: delete if here longer than store period or more than two days */
else if ( ( ( time_t ) newBlog - > sendTime < min ) | |
2008-07-02 09:19:59 -04:00
( ( time_t ) newBlog - > sendTime > max ) )
2008-06-04 06:59:24 -04:00
{
# ifdef QBLOG_DEBUG
std : : cerr < < " p3Qblog::loadBlogFile() Outside TimeRange (deleting): " ;
std : : cerr < < std : : endl ;
# endif
/* if outside time range remove */
delete newBlog ;
}
else
{
# ifdef QBLOG_DEBUG
std : : cerr < < " p3Qblog::loadBlogFile() Loading Item " ;
std : : cerr < < std : : endl ;
# endif
addBlog ( newBlog ) ; // add received blog to list
}
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
stream - > tick ( ) ; // tick to read
}
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
delete stream ; // stream finished with/return resource
return true ;
2008-05-08 20:27:28 -04:00
}
2008-06-19 17:34:13 -04:00
bool p3Qblog : : addBlog ( RsQblogMsg * newBlog )
2008-05-08 20:27:28 -04:00
{
2008-06-06 19:38:37 -04:00
# ifdef QBLOG_DEBUG
std : : cerr < < " p3Ranking::addBlog() Item: " ;
std : : cerr < < std : : endl ;
newBlog - > print ( std : : cerr , 10 ) ; // check whats in the blog item
std : : cerr < < std : : endl ;
# endif
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
{
RsStackMutex Stack ( mBlogMtx ) ;
2008-09-21 16:30:34 -04:00
2008-07-02 09:19:59 -04:00
mUsrBlogSet [ newBlog - > PeerId ( ) ] . insert ( std : : make_pair ( newBlog - > sendTime , newBlog - > message ) ) ;
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
# ifdef QBLOG_DEBUG
std : : cerr < < " p3Qblog::addBlog() " ;
std : : cerr < < std : : endl ;
2008-06-19 17:34:13 -04:00
std : : cerr < < " \t peerId " < < newBlog - > PeerId ( ) ;
2008-06-04 06:59:24 -04:00
std : : cerr < < std : : endl ;
2008-07-02 09:19:59 -04:00
std : : cerr < < " \t mUsrBlogSet: time " < < newBlog - > sendTime ;
2008-06-04 06:59:24 -04:00
std : : cerr < < std : : endl ;
2008-07-02 09:19:59 -04:00
std : : cerr < < " \t mUsrBlogSet: blog " < < newBlog - > message ;
2008-06-04 06:59:24 -04:00
std : : cerr < < std : : endl ;
2008-09-21 16:30:34 -04:00
# endif
mPostsUpdated = false ; // need to figure how this should work/ where this should be placed
}
2008-05-08 20:27:28 -04:00
return true ;
}
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
bool p3Qblog : : postBlogs ( void )
{
# ifdef QBLOG_DEBUG
std : : cerr < < " p3Qblog::postBlogs() " ;
std : : cerr < < std : : endl ;
# endif
std : : string path = CacheSource : : getCacheDir ( ) ;
std : : ostringstream out ;
uint16_t subid = 1 ;
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
out < < " qblogs- " < < time ( NULL ) < < " .rsqb " ; // create blog file name based on time posted
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
/* determine filename */
std : : string tmpname = out . str ( ) ;
std : : string fname = path + " / " + tmpname ;
2008-09-21 16:30:34 -04:00
# ifdef QBLOG_DEBUG
std : : cerr < < " p3Qblog::postBlogs() Storing to: " < < fname ;
2008-06-04 06:59:24 -04:00
std : : cerr < < std : : endl ;
# endif
RsSerialiser * rsSerialiser = new RsSerialiser ( ) ;
2008-06-19 17:34:13 -04:00
rsSerialiser - > addSerialType ( new RsQblogMsgSerialiser ( ) ) ;
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
uint32_t bioflags = BIN_FLAGS_HASH_DATA | BIN_FLAGS_WRITEABLE ;
BinInterface * bio = new BinFileInterface ( fname . c_str ( ) , bioflags ) ;
pqistreamer * stream = new pqistreamer ( rsSerialiser , mOwnId , bio ,
BIN_FLAGS_NO_DELETE ) ;
2008-09-21 16:30:34 -04:00
{
2008-06-04 06:59:24 -04:00
RsStackMutex stack ( mBlogMtx ) ; /********** STACK LOCKED MTX ******/
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
/* iterate through list */
2008-09-21 16:30:34 -04:00
std : : list < RsQblogMsg * > : : iterator it ;
2008-06-19 17:34:13 -04:00
for ( it = mBlogs . begin ( ) ; it ! = mBlogs . end ( ) ; it + + )
2008-06-04 06:59:24 -04:00
{
/* only post own blogs */
2008-06-19 17:34:13 -04:00
if ( mOwnId = = ( * it ) - > PeerId ( ) )
2008-06-04 06:59:24 -04:00
{
/*write to serialiser*/
RsItem * item = * it ;
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
# ifdef QBLOG_DEBUG
std : : cerr < < " p3Qblog::postBlogs() Storing Item: " ;
std : : cerr < < std : : endl ;
item - > print ( std : : cerr , 10 ) ;
std : : cerr < < std : : endl ;
# endif
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
stream - > SendItem ( item ) ;
stream - > tick ( ) ; /* tick to write */
}
else /* if blogs belong to a friend */
{
# ifdef QBLOG_DEBUG
std : : cerr < < " p3Ranking::postBlogs() Skipping friend blog items: " ;
std : : cerr < < std : : endl ;
# endif
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
continue ;
2008-09-21 16:30:34 -04:00
}
2008-06-04 06:59:24 -04:00
}
}
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
stream - > tick ( ) ; /* Tick for final write! */
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
/* flag as new info */
CacheData data ;
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
{ /********** STACK LOCKED MTX ******/
2008-09-21 16:30:34 -04:00
RsStackMutex stack ( mBlogMtx ) ;
2008-06-04 06:59:24 -04:00
data . pid = mOwnId ;
} /********** STACK LOCKED MTX ******/
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
data . cid = CacheId ( CacheSource : : getCacheType ( ) , subid ) ;
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
data . path = path ;
data . name = tmpname ;
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
data . hash = bio - > gethash ( ) ;
data . size = bio - > bytecount ( ) ;
data . recvd = time ( NULL ) ;
2008-09-21 16:30:34 -04:00
# ifdef QBLOG_DEBUG
2008-06-04 06:59:24 -04:00
std : : cerr < < " p3Ranking::postBlogs() refreshing Cache " ;
std : : cerr < < std : : endl ;
std : : cerr < < " \t Cache Path: " < < data . path ;
std : : cerr < < std : : endl ;
std : : cerr < < " \t Cache Name: " < < data . name ;
std : : cerr < < std : : endl ;
std : : cerr < < " \t Cache Hash: " < < data . hash ;
std : : cerr < < std : : endl ;
std : : cerr < < " \t Cache Size: " < < data . size ;
std : : cerr < < std : : endl ;
# endif
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
if ( data . size > 0 ) /* don't refresh zero sized caches */
{
refreshCache ( data ) ;
}
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
delete stream ;
2008-09-21 16:30:34 -04:00
return true ;
2008-06-04 06:59:24 -04:00
}
2008-09-21 16:30:34 -04:00
2008-05-08 20:27:28 -04:00
2008-06-04 06:59:24 -04:00
p3Qblog : : ~ p3Qblog ( )
{
return ;
}
2008-05-08 20:27:28 -04:00
2008-09-21 16:30:34 -04:00
bool p3Qblog : : getBlogs ( std : : map < std : : string , std : : multimap < long int , std : : wstring > > & blogs )
2008-05-08 20:27:28 -04:00
{
{
2008-06-04 06:59:24 -04:00
RsStackMutex stack ( mBlogMtx ) ;
2008-05-08 20:27:28 -04:00
2008-06-04 06:59:24 -04:00
if ( mUsrBlogSet . empty ( ) ) // return error blogs are empty
{
std : : cerr < < " usr blog set empty! " < < std : : endl ;
return false ;
}
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
blogs = mUsrBlogSet ;
2008-09-21 16:30:34 -04:00
# ifdef QBLOG_DEBUG
2008-06-04 06:59:24 -04:00
std : : cerr < < " p3Qblog::getBlogs() number of blogs: " < < mUsrBlogSet . size ( ) ;
std : : cerr < < std : : endl ;
# endif
2008-05-08 20:27:28 -04:00
}
2008-09-21 16:30:34 -04:00
return true ;
2008-05-08 20:27:28 -04:00
}
2008-09-21 16:30:34 -04:00
2008-06-19 17:34:13 -04:00
bool p3Qblog : : sendBlog ( const std : : wstring & msg )
2008-05-08 20:27:28 -04:00
{
2008-06-04 06:59:24 -04:00
time_t blogTimeStamp ;
2008-09-21 16:30:34 -04:00
{
2008-06-04 06:59:24 -04:00
RsStackMutex stack ( mBlogMtx ) ;
mUsrBlogSet [ mOwnId ] . insert ( std : : make_pair ( blogTimeStamp , msg ) ) ;
2008-09-21 16:30:34 -04:00
2008-06-19 17:34:13 -04:00
RsQblogMsg * blog = new RsQblogMsg ( ) ;
blog - > clear ( ) ;
2008-09-21 16:30:34 -04:00
2008-07-02 09:19:59 -04:00
blog - > sendTime = blogTimeStamp ;
blog - > message = msg ;
2008-06-19 17:34:13 -04:00
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
# ifdef QBLOG_DEBUG
std : : cerr < < " p3Qblog::sendBlogFile() " ;
std : : cerr < < std : : endl ;
2008-07-02 09:19:59 -04:00
std : : cerr < < " \t blogItem->sendTime " < < blog - > sendTime ;
2008-06-04 06:59:24 -04:00
std : : cerr < < std : : endl ;
2008-07-02 09:19:59 -04:00
std : : cerr < < " \t blogItem->message " < < blog - > message ;
2008-06-04 06:59:24 -04:00
std : : cerr < < std : : endl ;
# endif
2008-05-08 20:27:28 -04:00
2008-09-21 16:30:34 -04:00
mBlogs . push_back ( blog ) ;
}
2008-06-19 17:34:13 -04:00
return true ;
}
2008-05-08 20:27:28 -04:00
void p3Qblog : : loadDummy ( void )
{
2008-06-04 06:59:24 -04:00
std : : list < std : : string > peers ;
2008-06-19 17:34:13 -04:00
std : : wstring cnv_wstr ;
2008-06-04 06:59:24 -04:00
mConnMgr - > getFriendList ( peers ) ; // retrieve peers list from core
if ( peers . empty ( ) )
{
2008-07-09 05:55:09 -04:00
//for(int i = 0; i < 50; i++)
// std::cerr << "nothing in peer list!!!" << std::endl;
2008-06-04 06:59:24 -04:00
}
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
srand ( 60 ) ;
long int now = time ( NULL ) ; // the present time
2008-06-19 17:34:13 -04:00
std : : multimap < long int , std : : wstring > emptySet ; // time/blog map
2008-09-21 16:30:34 -04:00
2008-06-19 17:34:13 -04:00
//std::string statusSet[5] = { "great", "rubbish", "ecstatic", "save me", "emo depression"};
//std::string songs[5] = { "broken spleen", "niobium", "ewe (a sheep)", "velvet stuff", "chun li kicks"};
2008-06-04 06:59:24 -04:00
2008-09-21 16:30:34 -04:00
/* the usr dummy usr blogs */
2008-06-04 06:59:24 -04:00
std : : string B1 = " I think we should eat more cheese " ;
std : : string B2 = " today was so cool, i got attacked by fifty ninja while buying a loaf so i used my paper bag to suffocate each of them to death at hyper speed " ;
std : : string B3 = " Nuthins up " ;
std : : string B4 = " stop bothering me " ;
std : : string B5 = " I'm really a boring person and having nothin interesting to say " ;
std : : string blogs [ 5 ] = { B1 , B2 , B3 , B4 , B5 } ;
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
/* fill up maps: first usrblogset with empty blogs */
2008-09-21 16:30:34 -04:00
std : : list < std : : string > : : iterator it ;
2008-06-19 17:34:13 -04:00
mUsrBlogSet . insert ( std : : make_pair ( mOwnId , emptySet ) ) ;
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
for ( it = peers . begin ( ) ; it ! = peers . end ( ) ; it + + )
{
mUsrBlogSet . insert ( std : : make_pair ( * it , emptySet ) ) ;
}
/* now fill up blog map */
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
for ( int i = 0 ; i < 50 ; i + + )
{
std : : list < std : : string > : : iterator it = peers . begin ( ) ;
long int timeStamp ;
timeStamp = now + rand ( ) % 2134223 ;
2008-06-19 17:34:13 -04:00
int b = rand ( ) % 5 ;
cnv_wstr . assign ( blogs [ b ] . begin ( ) , blogs [ b ] . end ( ) ) ;
mUsrBlogSet [ mOwnId ] . insert ( std : : make_pair ( timeStamp , cnv_wstr ) ) ; // store a random blog
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
for ( ; it ! = peers . end ( ) ; it + + )
{
timeStamp = now + rand ( ) % 2134223 ; // a random time for each blog
2008-06-19 17:34:13 -04:00
int c = rand ( ) % 5 ;
cnv_wstr . assign ( blogs [ c ] . begin ( ) , blogs [ c ] . end ( ) ) ;
mUsrBlogSet [ * it ] . insert ( std : : make_pair ( timeStamp , cnv_wstr ) ) ; // store a random blog
2008-06-04 06:59:24 -04:00
}
}
2008-09-21 16:30:34 -04:00
2008-06-04 06:59:24 -04:00
return ;
2008-09-21 16:30:34 -04:00
}
2008-05-08 20:27:28 -04:00
2008-06-04 06:59:24 -04:00
bool p3Qblog : : sort ( void )
{
// TODO sorts blog maps in time order
return true ;
}
2008-06-06 19:38:37 -04:00
void p3Qblog : : tick ( )
{
2008-06-19 17:34:13 -04:00
bool postUpdated = false ; // so stack mutex is not enabled during postblog call
2008-09-21 16:30:34 -04:00
2008-06-06 19:38:37 -04:00
{
RsStackMutex stack ( mBlogMtx ) ;
2008-06-19 17:34:13 -04:00
postUpdated = mPostsUpdated ;
2008-06-06 19:38:37 -04:00
}
2008-09-21 16:30:34 -04:00
2008-06-19 17:34:13 -04:00
if ( ! postUpdated )
2008-06-06 19:38:37 -04:00
{
if ( ! postBlogs ( ) )
std : : cerr < < " p3Qblog::tick(): " < < " tick failed! " ;
2008-07-06 12:38:52 -04:00
/* drbob: added to stop infinite qblog output */
RsStackMutex stack ( mBlogMtx ) ;
mPostsUpdated = true ;
2008-06-06 19:38:37 -04:00
}
2008-06-19 17:34:13 -04:00
}