mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-24 23:19:29 -05:00
Finished off the basic Link Ranking system.
* added serialiser types. * finished streaming on p3ranking. * removed Bandwidth limitations from BinFile / BinMem. * added bytecount() to BinInterface. * moved the CacheTransfer creation to Startup. * added ranking to CacheStrapper & server tick() system. * Tweaked LinksDialog for final touches. * enabled downloads from Messages. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@335 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
925b1a780e
commit
2c69fd7eaf
@ -312,7 +312,10 @@ virtual int netstatus() = 0;
|
||||
virtual int isactive() = 0;
|
||||
virtual bool moretoread() = 0;
|
||||
virtual bool cansend() = 0;
|
||||
|
||||
/* if hashing data */
|
||||
virtual std::string gethash() = 0;
|
||||
virtual uint64_t bytecount() { return 0; }
|
||||
|
||||
/* used by pqistreamer to limit transfers */
|
||||
virtual bool bandwidthLimited() { return true; }
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "pqi/pqibin.h"
|
||||
|
||||
BinFileInterface::BinFileInterface(const char *fname, int flags)
|
||||
:bin_flags(flags), buf(NULL), hash(NULL)
|
||||
:bin_flags(flags), buf(NULL), hash(NULL), bcount(0)
|
||||
{
|
||||
/* if read + write - open r+ */
|
||||
if ((bin_flags & BIN_FLAGS_READABLE) &&
|
||||
@ -102,6 +102,7 @@ int BinFileInterface::senddata(void *data, int len)
|
||||
if (bin_flags & BIN_FLAGS_HASH_DATA)
|
||||
{
|
||||
hash->addData(data, len);
|
||||
bcount += len;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
@ -118,6 +119,7 @@ int BinFileInterface::readdata(void *data, int len)
|
||||
if (bin_flags & BIN_FLAGS_HASH_DATA)
|
||||
{
|
||||
hash->addData(data, len);
|
||||
bcount += len;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
@ -132,10 +134,19 @@ std::string BinFileInterface::gethash()
|
||||
return hashstr;
|
||||
}
|
||||
|
||||
uint64_t BinFileInterface::bytecount()
|
||||
{
|
||||
if (bin_flags & BIN_FLAGS_HASH_DATA)
|
||||
{
|
||||
return bcount;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
BinMemInterface::BinMemInterface(int defsize, int flags)
|
||||
:bin_flags(flags), buf(NULL), size(defsize),
|
||||
recvsize(0), readloc(0), hash(NULL)
|
||||
recvsize(0), readloc(0), hash(NULL), bcount(0)
|
||||
{
|
||||
buf = malloc(defsize);
|
||||
if (bin_flags & BIN_FLAGS_HASH_DATA)
|
||||
@ -174,6 +185,7 @@ int BinMemInterface::senddata(void *data, int len)
|
||||
if (bin_flags & BIN_FLAGS_HASH_DATA)
|
||||
{
|
||||
hash->addData(data, len);
|
||||
bcount += len;
|
||||
}
|
||||
recvsize += len;
|
||||
return len;
|
||||
@ -191,6 +203,7 @@ int BinMemInterface::readdata(void *data, int len)
|
||||
if (bin_flags & BIN_FLAGS_HASH_DATA)
|
||||
{
|
||||
hash->addData(data, len);
|
||||
bcount += len;
|
||||
}
|
||||
readloc += len;
|
||||
return len;
|
||||
@ -209,6 +222,16 @@ std::string BinMemInterface::gethash()
|
||||
}
|
||||
|
||||
|
||||
uint64_t BinMemInterface::bytecount()
|
||||
{
|
||||
if (bin_flags & BIN_FLAGS_HASH_DATA)
|
||||
{
|
||||
return bcount;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
@ -426,5 +449,3 @@ std::string NetBinDummy::gethash()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -57,13 +57,18 @@ virtual bool moretoread()
|
||||
|
||||
|
||||
virtual bool cansend() { return (bin_flags | BIN_FLAGS_WRITEABLE); }
|
||||
virtual bool bandwidthLimited() { return false; }
|
||||
|
||||
/* if HASHing is switched on */
|
||||
virtual std::string gethash();
|
||||
virtual uint64_t bytecount();
|
||||
|
||||
private:
|
||||
int bin_flags;
|
||||
FILE *buf;
|
||||
int size;
|
||||
pqihash *hash;
|
||||
uint64_t bcount;
|
||||
};
|
||||
|
||||
|
||||
@ -96,7 +101,10 @@ virtual bool moretoread()
|
||||
}
|
||||
|
||||
virtual bool cansend() { return (bin_flags | BIN_FLAGS_WRITEABLE); }
|
||||
virtual bool bandwidthLimited() { return false; }
|
||||
|
||||
virtual std::string gethash();
|
||||
virtual uint64_t bytecount();
|
||||
|
||||
private:
|
||||
int bin_flags;
|
||||
@ -105,6 +113,7 @@ virtual std::string gethash();
|
||||
int recvsize;
|
||||
int readloc;
|
||||
pqihash *hash;
|
||||
uint64_t bcount;
|
||||
};
|
||||
|
||||
|
||||
|
@ -36,6 +36,7 @@
|
||||
// and communicates with peer etc via the BinInterface.
|
||||
//
|
||||
// The interface does not handle connection, just communication.
|
||||
// possible bioflags: BIN_FLAGS_NO_CLOSE | BIN_FLAGS_NO_DELETE
|
||||
|
||||
class pqistreamer: public PQInterface
|
||||
{
|
||||
@ -75,7 +76,7 @@ void inReadBytes(int );
|
||||
RsSerialiser *rsSerialiser;
|
||||
// Binary Interface for IO, initialisated at startup.
|
||||
BinInterface *bio;
|
||||
unsigned int bio_flags; // only BIN_NO_CLOSE at the moment.
|
||||
unsigned int bio_flags; // BIN_FLAGS_NO_CLOSE | BIN_FLAGS_NO_DELETE
|
||||
|
||||
void *pkt_wpending; // storage for pending packet to write.
|
||||
int pkt_rpend_size; // size of pkt_rpending.
|
||||
|
@ -212,6 +212,9 @@ void RsServer::run()
|
||||
//std::cerr << "RsServer::run() CheckDHT()" << std::endl;
|
||||
//CheckNetworking();
|
||||
|
||||
|
||||
/* Tick slow services */
|
||||
mRanking->tick();
|
||||
}
|
||||
|
||||
// every 60 loops (> 1 min)
|
||||
|
@ -28,11 +28,15 @@
|
||||
//#include <getopt.h>
|
||||
|
||||
#include "dbase/cachestrapper.h"
|
||||
#include "server/ftfiler.h"
|
||||
#include "server/filedexserver.h"
|
||||
|
||||
#include "pqi/pqipersongrp.h"
|
||||
#include "pqi/pqisslpersongrp.h"
|
||||
#include "pqi/pqiloopback.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
#include "pqi/pqidebug.h"
|
||||
|
||||
#include "util/rsdir.h"
|
||||
|
||||
#include "upnp/upnphandler.h"
|
||||
@ -51,7 +55,6 @@
|
||||
// for blocking signals
|
||||
#include <signal.h>
|
||||
|
||||
#include "pqi/pqidebug.h"
|
||||
#include "rsserver/p3face.h"
|
||||
#include "rsserver/p3peers.h"
|
||||
#include "rsserver/p3rank.h"
|
||||
@ -472,7 +475,10 @@ int RsServer::StartupRetroShare(RsInit *config)
|
||||
mConnMgr = new p3ConnectMgr(mAuthMgr);
|
||||
p3UpnpMgr *mUpnpMgr = new upnphandler();
|
||||
p3DhtMgr *mDhtMgr = new OpenDHTMgr(ownId, mConnMgr);
|
||||
|
||||
CacheStrapper *mCacheStrapper = new CacheStrapper(ownId, queryPeriod);
|
||||
ftfiler *mCacheTransfer = new ftfiler(mCacheStrapper);
|
||||
|
||||
p3ConfigMgr *mConfigMgr = new p3ConfigMgr(config->basedir, "rs-v0.4.cfg", "rs-v0.4.sgn");
|
||||
|
||||
SecurityPolicy *none = secpolicy_create();
|
||||
@ -577,8 +583,12 @@ int RsServer::StartupRetroShare(RsInit *config)
|
||||
|
||||
pqih->load_config();
|
||||
|
||||
/* must be after server->setSearchInterface() */
|
||||
server->setFileCallback(ownId, mCacheStrapper, &(getNotify()));
|
||||
/* Must be after server->setSearchInterface()
|
||||
* and.
|
||||
* Must be before other Caches are added to the Strapper!
|
||||
* */
|
||||
|
||||
server->setFileCallback(ownId, mCacheStrapper, mCacheTransfer, &(getNotify()));
|
||||
|
||||
|
||||
|
||||
@ -608,7 +618,6 @@ int RsServer::StartupRetroShare(RsInit *config)
|
||||
msgSrv = new p3MsgService(mConnMgr);
|
||||
chatSrv = new p3ChatService(mConnMgr);
|
||||
p3GameLauncher *gameLauncher = new p3GameLauncher();
|
||||
p3Ranking *ranking = new p3Ranking(0, NULL, "", "", 3600 * 24 * 30);
|
||||
|
||||
pqih -> addService(ad);
|
||||
pqih -> addService(msgSrv);
|
||||
@ -618,9 +627,20 @@ int RsServer::StartupRetroShare(RsInit *config)
|
||||
/* so need to Monitor too! */
|
||||
mConnMgr->addMonitor(ad);
|
||||
|
||||
/* create Cache Services */
|
||||
std::string config_dir = config->basedir;
|
||||
std::string localcachedir = config_dir + "/cache/local";
|
||||
std::string remotecachedir = config_dir + "/cache/remote";
|
||||
|
||||
mRanking = new p3Ranking(RS_SERVICE_TYPE_RANK,
|
||||
mCacheTransfer, localcachedir, remotecachedir, 3600 * 24 * 30);
|
||||
|
||||
CachePair cp(mRanking, mRanking, CacheId(RS_SERVICE_TYPE_RANK, 0));
|
||||
mCacheStrapper -> addCachePair(cp);
|
||||
|
||||
/* setup the gui */
|
||||
rsGameLauncher = gameLauncher;
|
||||
rsRanks = new p3Rank(ranking);
|
||||
rsRanks = new p3Rank(mRanking);
|
||||
rsMsgs = new p3Msgs(mAuthMgr, msgSrv, chatSrv);
|
||||
|
||||
/* put a welcome message in! */
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "services/p3disc.h"
|
||||
#include "services/p3msgservice.h"
|
||||
#include "services/p3chatservice.h"
|
||||
#include "services/p3ranking.h"
|
||||
|
||||
/* The Main Interface Class - for controlling the server */
|
||||
|
||||
@ -271,6 +272,9 @@ int UpdateAllConfig();
|
||||
p3MsgService *msgSrv;
|
||||
p3ChatService *chatSrv;
|
||||
|
||||
/* caches (that need ticking) */
|
||||
p3Ranking *mRanking;
|
||||
|
||||
// Worker Data.....
|
||||
|
||||
};
|
||||
|
@ -10,7 +10,7 @@ include $(RS_TOP_DIR)/scripts/config.mk
|
||||
RSOBJ = rsserial.o rsbaseserial.o rstlvbase.o rstlvtypes.o
|
||||
RSOBJ += rstlvfileitem.o rstlvutil.o # TLV Objs
|
||||
RSOBJ += rsbaseitems.o rsconfigitems.o rsdiscitems.o # RsItems
|
||||
RSOBJ += rsmsgitems.o # RsItems
|
||||
RSOBJ += rsmsgitems.o rsrankitems.o # RsItems
|
||||
|
||||
TESTOBJ = tlvbase_test.o tlvbase_test2.o tlvfileitem_test.o
|
||||
TESTOBJ += tlvitems_test.o tlvstack_test.o tlvconfig_test.o
|
||||
|
244
libretroshare/src/serialiser/rsrankitems.cc
Normal file
244
libretroshare/src/serialiser/rsrankitems.cc
Normal file
@ -0,0 +1,244 @@
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsbaseitems.cc
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie.
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rsrankitems.h"
|
||||
#include "serialiser/rstlvbase.h"
|
||||
|
||||
#define RSSERIAL_DEBUG 1
|
||||
#include <iostream>
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
void RsRankMsg::clear()
|
||||
{
|
||||
rid.clear();
|
||||
timestamp = 0;
|
||||
title.clear();
|
||||
comment.clear();
|
||||
}
|
||||
|
||||
std::ostream &RsRankMsg::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsRankMsg", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
printIndent(out, int_Indent);
|
||||
out << "rid: " << rid << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "timestamp: " << timestamp << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
|
||||
std::string cnv_title(title.begin(), title.end());
|
||||
out << "msg: " << cnv_title << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
std::string cnv_comment(comment.begin(), comment.end());
|
||||
out << "comment: " << cnv_comment << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsRankMsg", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
void RsRankLinkMsg::clear()
|
||||
{
|
||||
rid.clear();
|
||||
timestamp = 0;
|
||||
title.clear();
|
||||
comment.clear();
|
||||
linktype = 0;
|
||||
link.clear();
|
||||
}
|
||||
|
||||
std::ostream &RsRankLinkMsg::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsRankLinkMsg", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
printIndent(out, int_Indent);
|
||||
out << "rid: " << rid << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "timestamp: " << timestamp << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
|
||||
std::string cnv_title(title.begin(), title.end());
|
||||
out << "msg: " << cnv_title << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
std::string cnv_comment(comment.begin(), comment.end());
|
||||
out << "comment: " << cnv_comment << std::endl;
|
||||
|
||||
printIndent(out, int_Indent);
|
||||
out << "linktype: " << linktype << std::endl;
|
||||
printIndent(out, int_Indent);
|
||||
std::string cnv_link(link.begin(), link.end());
|
||||
out << "link: " << cnv_link << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsRankLinkMsg", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsRankSerialiser::sizeLink(RsRankLinkMsg *item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += GetTlvStringSize(item->rid);
|
||||
s += 4; /* timestamp */
|
||||
s += GetTlvWideStringSize(item->title);
|
||||
s += GetTlvWideStringSize(item->comment);
|
||||
s += 4; /* linktype */
|
||||
s += GetTlvWideStringSize(item->link);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/* serialise the data to the buffer */
|
||||
bool RsRankSerialiser::serialiseLink(RsRankLinkMsg *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeLink(item);
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
|
||||
|
||||
std::cerr << "RsRankLinkSerialiser::serialiseLink() Header: " << ok << std::endl;
|
||||
std::cerr << "RsRankLinkSerialiser::serialiseLink() Size: " << tlvsize << std::endl;
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GENID, item->rid);
|
||||
std::cerr << "RsRankLinkSerialiser::serialiseLink() rid: " << ok << std::endl;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->timestamp);
|
||||
std::cerr << "RsRankLinkSerialiser::serialiseLink() timestamp: " << ok << std::endl;
|
||||
|
||||
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_TITLE, item->title);
|
||||
std::cerr << "RsRankLinkSerialiser::serialiseLink() Title: " << ok << std::endl;
|
||||
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_COMMENT, item->comment);
|
||||
std::cerr << "RsRankLinkSerialiser::serialiseLink() Comment: " << ok << std::endl;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->linktype);
|
||||
std::cerr << "RsRankLinkSerialiser::serialiseLink() linktype: " << ok << std::endl;
|
||||
|
||||
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_LINK, item->link);
|
||||
std::cerr << "RsRankLinkSerialiser::serialiseLink() Link: " << ok << std::endl;
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsRankLinkSerialiser::serialiseLink() Size Error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
RsRankLinkMsg *RsRankSerialiser::deserialiseLink(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_RANK != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_RANK_LINK != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < rssize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = rssize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsRankLinkMsg *item = new RsRankLinkMsg();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GENID, item->rid);
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->timestamp));
|
||||
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_TITLE, item->title);
|
||||
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_COMMENT, item->comment);
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->linktype));
|
||||
ok &= GetTlvWideString(data, rssize, &offset, TLV_TYPE_WSTR_LINK, item->link);
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
uint32_t RsRankSerialiser::size(RsItem *item)
|
||||
{
|
||||
return sizeLink((RsRankLinkMsg *) item);
|
||||
}
|
||||
|
||||
bool RsRankSerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
return serialiseLink((RsRankLinkMsg *) item, data, pktsize);
|
||||
}
|
||||
|
||||
RsItem *RsRankSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
{
|
||||
return deserialiseLink(data, pktsize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
108
libretroshare/src/serialiser/rsrankitems.h
Normal file
108
libretroshare/src/serialiser/rsrankitems.h
Normal file
@ -0,0 +1,108 @@
|
||||
#ifndef RS_RANK_ITEMS_H
|
||||
#define RS_RANK_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rsrankitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-2008 by Robert Fernie.
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
|
||||
const uint8_t RS_PKT_SUBTYPE_RANK_LINK = 0x02;
|
||||
const uint8_t RS_PKT_SUBTYPE_RANK_PHOTO = 0x03;
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
|
||||
class RsRankMsg: public RsItem
|
||||
{
|
||||
public:
|
||||
RsRankMsg(uint8_t subtype)
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_RANK,
|
||||
subtype) { return; }
|
||||
virtual ~RsRankMsg() { return; }
|
||||
virtual void clear();
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
std::string rid; /* Random Id */
|
||||
uint32_t timestamp;
|
||||
std::wstring title;
|
||||
std::wstring comment;
|
||||
};
|
||||
|
||||
|
||||
/* Flags */
|
||||
const uint32_t RS_LINK_TYPE_WEB = 0x0001;
|
||||
|
||||
class RsRankLinkMsg: public RsRankMsg
|
||||
{
|
||||
public:
|
||||
RsRankLinkMsg()
|
||||
:RsRankMsg(RS_PKT_SUBTYPE_RANK_LINK) { return; }
|
||||
virtual ~RsRankLinkMsg() { return; }
|
||||
virtual void clear();
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
/**** SAME as RsRankMsg ****
|
||||
std::string rid;
|
||||
uint32_t timestamp;
|
||||
std::wstring title;
|
||||
std::wstring comment;
|
||||
***************************/
|
||||
|
||||
/* Link specific Fields */
|
||||
uint32_t linktype; /* to be used later! */
|
||||
std::wstring link;
|
||||
};
|
||||
|
||||
class RsRankSerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsRankSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_RANK)
|
||||
{ return; }
|
||||
virtual ~RsRankSerialiser()
|
||||
{ return; }
|
||||
|
||||
virtual uint32_t size(RsItem *);
|
||||
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
virtual RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
|
||||
/* For RS_PKT_SUBTYPE_RANK_LINK */
|
||||
virtual uint32_t sizeLink(RsRankLinkMsg *);
|
||||
virtual bool serialiseLink (RsRankLinkMsg *item, void *data, uint32_t *size);
|
||||
virtual RsRankLinkMsg *deserialiseLink(void *data, uint32_t *size);
|
||||
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
#endif /* RS_RANK_ITEMS_H */
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <iosfwd>
|
||||
|
||||
|
||||
|
@ -39,17 +39,18 @@
|
||||
|
||||
/* These are Cache Only */
|
||||
const uint16_t RS_SERVICE_TYPE_FILE_INDEX = 0x0001;
|
||||
const uint16_t RS_SERVICE_TYPE_RANK = 0x0002;
|
||||
|
||||
/* These are Services only */
|
||||
const uint16_t RS_SERVICE_TYPE_DISC = 0x0011;
|
||||
const uint16_t RS_SERVICE_TYPE_CHAT = 0x0012;
|
||||
const uint16_t RS_SERVICE_TYPE_MSG = 0x0013;
|
||||
|
||||
|
||||
|
||||
/****************** BELOW ARE ONLY THEORETICAL (CAN BE CHANGED) *****/
|
||||
|
||||
const uint16_t RS_SERVICE_TYPE_STATUS = 0x0012;
|
||||
|
||||
const uint16_t RS_SERVICE_TYPE_CHAT = 0x0013;
|
||||
const uint16_t RS_SERVICE_TYPE_MSG = 0x0014;
|
||||
|
||||
const uint16_t RS_SERVICE_TYPE_CHANNEL_MSG = 0x0015;
|
||||
const uint16_t RS_SERVICE_TYPE_PROXY_MSG = 0x0016;
|
||||
|
@ -105,6 +105,8 @@ const uint16_t TLV_TYPE_STR_COMMENT = 0x0055;
|
||||
const uint16_t TLV_TYPE_STR_TITLE = 0x0056;
|
||||
const uint16_t TLV_TYPE_STR_MSG = 0x0057;
|
||||
const uint16_t TLV_TYPE_STR_SUBJECT = 0x0058;
|
||||
const uint16_t TLV_TYPE_STR_LINK = 0x0059;
|
||||
const uint16_t TLV_TYPE_STR_GENID = 0x005a;
|
||||
|
||||
/* Wide Chars (4 bytes per char) for internationalisation */
|
||||
const uint16_t TLV_TYPE_WSTR_PEERID = 0x0060;
|
||||
@ -116,6 +118,8 @@ const uint16_t TLV_TYPE_WSTR_COMMENT = 0x0065;
|
||||
const uint16_t TLV_TYPE_WSTR_TITLE = 0x0066;
|
||||
const uint16_t TLV_TYPE_WSTR_MSG = 0x0067;
|
||||
const uint16_t TLV_TYPE_WSTR_SUBJECT = 0x0068;
|
||||
const uint16_t TLV_TYPE_WSTR_LINK = 0x0069;
|
||||
const uint16_t TLV_TYPE_WSTR_GENID = 0x006a;
|
||||
|
||||
/* Hashs are always strings */
|
||||
const uint16_t TLV_TYPE_STR_HASH_SHA1 = 0x0070;
|
||||
|
@ -212,11 +212,10 @@ const std::string LOCAL_CACHE_FILE_KEY = "LCF_NAME";
|
||||
const std::string LOCAL_CACHE_HASH_KEY = "LCF_HASH";
|
||||
const std::string LOCAL_CACHE_SIZE_KEY = "LCF_SIZE";
|
||||
|
||||
void filedexserver::setFileCallback(std::string ownId, CacheStrapper *strapper, NotifyBase *cb)
|
||||
void filedexserver::setFileCallback(std::string ownId, CacheStrapper *strapper, ftfiler *ft, NotifyBase *cb)
|
||||
{
|
||||
mCacheStrapper = strapper;
|
||||
|
||||
ftFiler = new ftfiler(mCacheStrapper);
|
||||
ftFiler = ft;
|
||||
|
||||
/* setup FiStore/Monitor */
|
||||
std::string localcachedir = config_dir + "/cache/local";
|
||||
|
@ -155,7 +155,8 @@ int FileStoreTick();
|
||||
int FileCacheSave();
|
||||
|
||||
void initialiseFileStore();
|
||||
void setFileCallback(std::string ownId, CacheStrapper *cs, NotifyBase *cb);
|
||||
void setFileCallback(std::string ownId, CacheStrapper *strapper,
|
||||
ftfiler *ft, NotifyBase *cb);
|
||||
|
||||
int RequestDirDetails(std::string uid, std::string path, DirDetails &details);
|
||||
int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
|
||||
|
@ -23,7 +23,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "serialiser/rsrankitems.h"
|
||||
#include "services/p3ranking.h"
|
||||
|
||||
#include "pqi/pqibin.h"
|
||||
#include "pqi/p3authmgr.h"
|
||||
|
||||
@ -40,71 +42,155 @@ std::string generateRandomLinkId();
|
||||
|
||||
#define RANK_DEBUG 1
|
||||
|
||||
p3Ranking::p3Ranking(uint16_t subtype, CacheTransfer *cft,
|
||||
p3Ranking::p3Ranking(uint16_t type, CacheTransfer *cft,
|
||||
std::string sourcedir, std::string storedir,
|
||||
uint32_t storePeriod)
|
||||
:CacheSource(subtype, true, sourcedir),
|
||||
CacheStore(subtype, true, cft, storedir),
|
||||
:CacheSource(type, true, sourcedir),
|
||||
CacheStore(type, true, cft, storedir),
|
||||
mStorePeriod(storePeriod)
|
||||
{
|
||||
mOwnId = getAuthMgr()->OwnId();
|
||||
mViewPeriod = 60 * 60 * 24 * 30; /* one Month */
|
||||
mSortType = RS_RANK_ALG;
|
||||
|
||||
createDummyData();
|
||||
// createDummyData();
|
||||
return;
|
||||
}
|
||||
|
||||
bool p3Ranking::loadLocalCache(const CacheData &data)
|
||||
{
|
||||
|
||||
/* ignore Local Cache -> just use remote caches */
|
||||
return true;
|
||||
}
|
||||
|
||||
int p3Ranking::loadCache(const CacheData &data)
|
||||
{
|
||||
std::string filename = data.path + '/' + data.name;
|
||||
std::string hash = data.hash;
|
||||
//uint64_t size = data.size;
|
||||
std::string source = data.pid;
|
||||
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::loadCache()";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tSource: " << source;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tFilename: " << filename;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tHash: " << hash;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tSize: " << data.size;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
loadRankFile(filename, source);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void p3Ranking::loadRankFile(std::string filename, std::string src)
|
||||
{
|
||||
|
||||
#if 0
|
||||
/* create the serialiser to load info */
|
||||
pqistreamer *streamer = createStreamer(filename, src, BIN_FLAGS_READABLE);
|
||||
RsSerialiser *rsSerialiser = new RsSerialiser();
|
||||
rsSerialiser->addSerialType(new RsRankSerialiser());
|
||||
|
||||
uint32_t bioflags = BIN_FLAGS_HASH_DATA | BIN_FLAGS_READABLE;
|
||||
BinInterface *bio = new BinFileInterface(filename.c_str(), bioflags);
|
||||
pqistreamer *stream = new pqistreamer(rsSerialiser, src, bio, 0);
|
||||
|
||||
time_t now = time(NULL);
|
||||
time_t min = now - mStorePeriod;
|
||||
time_t max = now + RANK_MAX_FWD_OFFSET;
|
||||
|
||||
RsItem *item;
|
||||
RsRankMsg *newMsg;
|
||||
while(NULL != (item = streamer->GetItem()))
|
||||
{
|
||||
newMsg = (RsRankMsg *) item;
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::loadRankFile()";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tSource: " << src;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tFilename: " << filename;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* check timestamp */
|
||||
if ((newMsg->timestamp < min) || (newMsg->timestamp > max))
|
||||
RsItem *item;
|
||||
RsRankLinkMsg *newMsg;
|
||||
|
||||
stream->tick(); /* Tick to read! */
|
||||
while(NULL != (item = stream->GetItem()))
|
||||
{
|
||||
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::loadRankFile() Got Item:";
|
||||
std::cerr << std::endl;
|
||||
item->print(std::cerr, 10);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if (NULL == (newMsg = dynamic_cast<RsRankLinkMsg *>(item)))
|
||||
{
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::loadRankFile() Item not LinkMsg (deleting):";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
delete item;
|
||||
}
|
||||
/* check timestamp */
|
||||
else if (((time_t) newMsg->timestamp < min) ||
|
||||
((time_t) newMsg->timestamp > max))
|
||||
{
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::loadRankFile() Outside TimeRange (deleting):";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
/* if outside range -> remove */
|
||||
delete newMsg;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::loadRankFile() Loading Item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
addRankMsg(newMsg);
|
||||
}
|
||||
|
||||
stream->tick(); /* Tick to read! */
|
||||
}
|
||||
#endif
|
||||
|
||||
delete stream;
|
||||
}
|
||||
|
||||
|
||||
void p3Ranking::publishMsgs()
|
||||
{
|
||||
|
||||
#if 0
|
||||
/* create a serialiser */
|
||||
std::string file;
|
||||
pqistreamer *stream = createStreamer(file, mOwnId, BIN_FLAGS_NO_DELETE | BIN_FLAGS_HASH_DATA);
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::publishMsgs()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* determine filename */
|
||||
|
||||
std::string path = CacheSource::getCacheDir();
|
||||
std::ostringstream out;
|
||||
out << "rank-links-" << time(NULL) << ".rsrl";
|
||||
|
||||
std::string tmpname = out.str();
|
||||
std::string fname = path + "/" + tmpname;
|
||||
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::publishMsgs() Storing to: " << fname;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
RsSerialiser *rsSerialiser = new RsSerialiser();
|
||||
rsSerialiser->addSerialType(new RsRankSerialiser());
|
||||
|
||||
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);
|
||||
|
||||
/* iterate through list */
|
||||
std::map<std::string, RankGroup>::iterator it;
|
||||
@ -115,27 +201,77 @@ void p3Ranking::publishMsgs()
|
||||
/* write to serialiser */
|
||||
RsItem *item = it->second.comments[mOwnId];
|
||||
if (item)
|
||||
{
|
||||
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::publishMsgs() Storing Item:";
|
||||
std::cerr << std::endl;
|
||||
item->print(std::cerr, 10);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
stream->SendItem(item);
|
||||
stream->tick(); /* Tick to write! */
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::publishMsgs() Skipping Foreign item";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
stream->tick(); /* Tick for final write! */
|
||||
|
||||
/* flag as new info */
|
||||
CacheData data;
|
||||
data.pid = mOwnId;
|
||||
data.cid = CacheId(CacheSource::getCacheType(), 0);
|
||||
data.name = file;
|
||||
data.cid = CacheId(CacheSource::getCacheType(), 1);
|
||||
|
||||
refreshCache(data);
|
||||
data.path = path;
|
||||
data.name = tmpname;
|
||||
|
||||
data.hash = bio->gethash();
|
||||
data.size = bio->bytecount();
|
||||
data.recvd = time(NULL);
|
||||
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::publishMsgs() refreshing Cache";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tCache Path: " << data.path;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tCache Name: " << data.name;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tCache Hash: " << data.hash;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "\tCache Size: " << data.size;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
if (data.size > 0) /* don't refresh zero sized caches */
|
||||
{
|
||||
refreshCache(data);
|
||||
}
|
||||
|
||||
delete stream;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void p3Ranking::addRankMsg(RsRankMsg *msg)
|
||||
void p3Ranking::addRankMsg(RsRankLinkMsg *msg)
|
||||
{
|
||||
/* find msg */
|
||||
std::string id = msg->PeerId();
|
||||
std::string rid = msg->rid;
|
||||
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::addRankMsg() Item:";
|
||||
std::cerr << std::endl;
|
||||
msg->print(std::cerr, 10);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, RankGroup>::iterator it;
|
||||
it = mData.find(rid);
|
||||
if (it == mData.end())
|
||||
@ -154,22 +290,46 @@ void p3Ranking::addRankMsg(RsRankMsg *msg)
|
||||
}
|
||||
|
||||
/* check for old comment */
|
||||
std::map<std::string, RsRankMsg *>::iterator cit;
|
||||
std::map<std::string, RsRankLinkMsg *>::iterator cit;
|
||||
cit = (it->second).comments.find(id);
|
||||
if ((it->second).comments.end() != cit)
|
||||
|
||||
/* Check that it is different! */
|
||||
bool newComment = false;
|
||||
if ((it->second).comments.end() == cit)
|
||||
{
|
||||
(it->second).comments.erase(cit);
|
||||
newComment = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
RsRankLinkMsg *old = cit->second;
|
||||
if ((msg->timestamp != old->timestamp) ||
|
||||
(msg->comment != old->comment))
|
||||
{
|
||||
newComment = true;
|
||||
}
|
||||
}
|
||||
|
||||
(it->second).comments[id] = msg;
|
||||
|
||||
if (id == mOwnId)
|
||||
if (newComment)
|
||||
{
|
||||
it->second.ownTag = true;
|
||||
mRepublish = true;
|
||||
}
|
||||
/* clean up old */
|
||||
if ((it->second).comments.end() != cit)
|
||||
{
|
||||
delete (cit->second);
|
||||
(it->second).comments.erase(cit);
|
||||
}
|
||||
|
||||
reSortGroup(it->second);
|
||||
/* add in */
|
||||
(it->second).comments[id] = msg;
|
||||
|
||||
/* republish? */
|
||||
if (id == mOwnId)
|
||||
{
|
||||
it->second.ownTag = true;
|
||||
mRepublish = true;
|
||||
}
|
||||
|
||||
reSortGroup(it->second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -249,7 +409,7 @@ float p3Ranking::locked_calcRank(RankGroup &grp)
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, RsRankMsg *>::iterator it;
|
||||
std::map<std::string, RsRankLinkMsg *>::iterator it;
|
||||
for(it = grp.comments.begin(); it != grp.comments.end(); it++)
|
||||
{
|
||||
#ifdef RANK_DEBUG
|
||||
@ -271,7 +431,7 @@ float p3Ranking::locked_calcRank(RankGroup &grp)
|
||||
}
|
||||
|
||||
/* if Scoring is involved... drop old ones */
|
||||
if ((doScore) && (it->second->timestamp < minTime))
|
||||
if ((doScore) && ((time_t) it->second->timestamp < minTime))
|
||||
{
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "\tToo Old";
|
||||
@ -281,7 +441,7 @@ float p3Ranking::locked_calcRank(RankGroup &grp)
|
||||
}
|
||||
|
||||
time_t deltaT;
|
||||
if (it->second->timestamp > now)
|
||||
if ((time_t) it->second->timestamp > now)
|
||||
{
|
||||
deltaT = it->second->timestamp - now;
|
||||
}
|
||||
@ -350,7 +510,7 @@ float p3Ranking::locked_calcRank(RankGroup &grp)
|
||||
void p3Ranking::reSortGroup(RankGroup &grp)
|
||||
{
|
||||
std::string rid = grp.rid;
|
||||
float rank = grp.rank;
|
||||
//float rank = grp.rank;
|
||||
|
||||
/* remove from existings rankings */
|
||||
std::multimap<float, std::string>::iterator rit;
|
||||
@ -435,7 +595,7 @@ bool p3Ranking::getRankDetails(std::string rid, RsRankDetails &details)
|
||||
details.rank = (it->second).rank;
|
||||
details.ownTag = (it->second).ownTag;
|
||||
|
||||
std::map<std::string, RsRankMsg *>::iterator cit;
|
||||
std::map<std::string, RsRankLinkMsg *>::iterator cit;
|
||||
for(cit = (it->second).comments.begin();
|
||||
cit != (it->second).comments.end(); cit++)
|
||||
{
|
||||
@ -469,7 +629,7 @@ std::string p3Ranking::newRankMsg(std::wstring link, std::wstring title, std::ws
|
||||
/* generate an id */
|
||||
std::string rid = generateRandomLinkId();
|
||||
|
||||
RsRankMsg *msg = new RsRankMsg();
|
||||
RsRankLinkMsg *msg = new RsRankLinkMsg();
|
||||
|
||||
time_t now = time(NULL);
|
||||
|
||||
@ -477,9 +637,11 @@ std::string p3Ranking::newRankMsg(std::wstring link, std::wstring title, std::ws
|
||||
msg->rid = rid;
|
||||
msg->title = title;
|
||||
msg->timestamp = now;
|
||||
msg->link = link;
|
||||
msg->comment = comment;
|
||||
|
||||
msg->linktype = RS_LINK_TYPE_WEB;
|
||||
msg->link = link;
|
||||
|
||||
addRankMsg(msg);
|
||||
|
||||
return rid;
|
||||
@ -487,24 +649,72 @@ std::string p3Ranking::newRankMsg(std::wstring link, std::wstring title, std::ws
|
||||
|
||||
bool p3Ranking::updateComment(std::string rid, std::wstring comment)
|
||||
{
|
||||
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::updateComment() rid:" << rid;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<std::string, RankGroup>::iterator it;
|
||||
it = mData.find(rid);
|
||||
if (it == mData.end())
|
||||
{
|
||||
/* missing group -> fail */
|
||||
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::updateComment() Failed - noData";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
RsRankLinkMsg *msg = new RsRankLinkMsg();
|
||||
|
||||
time_t now = time(NULL);
|
||||
|
||||
msg->PeerId(mOwnId);
|
||||
msg->rid = rid;
|
||||
msg->timestamp = now;
|
||||
msg->title = (it->second).title;
|
||||
msg->comment = comment;
|
||||
|
||||
msg->linktype = RS_LINK_TYPE_WEB;
|
||||
msg->link = (it->second).link;
|
||||
|
||||
#ifdef RANK_DEBUG
|
||||
std::cerr << "p3Ranking::updateComment() Item:";
|
||||
std::cerr << std::endl;
|
||||
msg->print(std::cerr, 10);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
addRankMsg(msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
pqistreamer *createStreamer(std::string file, std::string src, uint32_t bioflags)
|
||||
pqistreamer *createStreamer(std::string file, std::string src, bool reading)
|
||||
{
|
||||
|
||||
#if 0
|
||||
RsSerialiser *rsSerialiser = new RsSerialiser();
|
||||
RsSerialType *serialType = new RsRankSerial(); /* TODO */
|
||||
rsSerialiser->addSerialType(new RsRankSerialiser());
|
||||
|
||||
rsSerialiser->addSerialType(serialType);
|
||||
uint32_t bioflags = BIN_FLAGS_HASH_DATA;
|
||||
if (reading)
|
||||
{
|
||||
bioflags |= BIN_FLAGS_READABLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
bioflags |= BIN_FLAGS_WRITEABLE;
|
||||
}
|
||||
|
||||
BinInterface *bio = BinFileInterface(file.c_str(), bioflags);
|
||||
pqistreamer *streamer = new pqistreamer(rsSerialiser, src, bio, 0);
|
||||
/* bin flags: READ | WRITE | HASH_DATA */
|
||||
BinInterface *bio = new BinFileInterface(file.c_str(), bioflags);
|
||||
/* streamer flags: NO_DELETE (yes) | NO_CLOSE (no) */
|
||||
pqistreamer *streamer = new pqistreamer(rsSerialiser, src, bio,
|
||||
BIN_FLAGS_NO_DELETE);
|
||||
|
||||
return streamer;
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::string generateRandomLinkId()
|
||||
@ -524,7 +734,7 @@ std::string generateRandomLinkId()
|
||||
|
||||
void p3Ranking::createDummyData()
|
||||
{
|
||||
RsRankMsg *msg = new RsRankMsg();
|
||||
RsRankLinkMsg *msg = new RsRankLinkMsg();
|
||||
|
||||
time_t now = time(NULL);
|
||||
|
||||
@ -537,7 +747,7 @@ void p3Ranking::createDummyData()
|
||||
|
||||
addRankMsg(msg);
|
||||
|
||||
msg = new RsRankMsg();
|
||||
msg = new RsRankLinkMsg();
|
||||
msg->PeerId(mOwnId);
|
||||
msg->rid = "0002";
|
||||
msg->title = L"Awesome Site!";
|
||||
@ -547,7 +757,7 @@ void p3Ranking::createDummyData()
|
||||
|
||||
addRankMsg(msg);
|
||||
|
||||
msg = new RsRankMsg();
|
||||
msg = new RsRankLinkMsg();
|
||||
msg->PeerId("ALTID");
|
||||
msg->rid = "0002";
|
||||
msg->title = L"Awesome Site!";
|
||||
@ -559,7 +769,7 @@ void p3Ranking::createDummyData()
|
||||
|
||||
addRankMsg(msg);
|
||||
|
||||
msg = new RsRankMsg();
|
||||
msg = new RsRankLinkMsg();
|
||||
msg->PeerId("ALTID2");
|
||||
msg->rid = "0002";
|
||||
msg->title = L"Awesome Site!";
|
||||
@ -572,7 +782,7 @@ void p3Ranking::createDummyData()
|
||||
|
||||
/***** Third one ****/
|
||||
|
||||
msg = new RsRankMsg();
|
||||
msg = new RsRankLinkMsg();
|
||||
msg->PeerId(mOwnId);
|
||||
msg->rid = "0003";
|
||||
msg->title = L"Weird Site!";
|
||||
@ -582,7 +792,7 @@ void p3Ranking::createDummyData()
|
||||
|
||||
addRankMsg(msg);
|
||||
|
||||
msg = new RsRankMsg();
|
||||
msg = new RsRankLinkMsg();
|
||||
msg->PeerId("ALTID");
|
||||
msg->rid = "0003";
|
||||
msg->title = L"Weird Site!";
|
||||
|
@ -41,38 +41,12 @@
|
||||
*
|
||||
* can be overloaded for specific types
|
||||
* (links, shares, photos etc)
|
||||
*
|
||||
* This is not generic yet!!!
|
||||
*/
|
||||
|
||||
class RsRankMsg: public RsItem
|
||||
{
|
||||
public:
|
||||
|
||||
//std::string peerId; /* From */
|
||||
std::string rid; /* Random Id */
|
||||
time_t timestamp;
|
||||
std::wstring link;
|
||||
std::wstring title;
|
||||
std::wstring comment;
|
||||
|
||||
RsRankMsg():RsItem(0) { return; }
|
||||
virtual void clear()
|
||||
{ return; }
|
||||
virtual std::ostream& print(std::ostream &out, uint16_t)
|
||||
{ return out; }
|
||||
|
||||
};
|
||||
|
||||
class RsRankSerial: public RsSerialType
|
||||
{
|
||||
public:
|
||||
|
||||
RsRankSerial()
|
||||
:RsSerialType(0,0,0)
|
||||
{ return; }
|
||||
|
||||
};
|
||||
|
||||
/* group these together */
|
||||
class RsRankMsg;
|
||||
class RsRankLinkMsg;
|
||||
|
||||
class RankGroup
|
||||
{
|
||||
@ -83,7 +57,7 @@ class RankGroup
|
||||
std::wstring title;
|
||||
float rank;
|
||||
bool ownTag;
|
||||
std::map<std::string, RsRankMsg *> comments;
|
||||
std::map<std::string, RsRankLinkMsg *> comments;
|
||||
};
|
||||
|
||||
|
||||
@ -91,7 +65,7 @@ class p3Ranking: public CacheSource, public CacheStore
|
||||
{
|
||||
public:
|
||||
|
||||
p3Ranking(uint16_t subtype, CacheTransfer *cft,
|
||||
p3Ranking(uint16_t type, CacheTransfer *cft,
|
||||
std::string sourcedir, std::string storedir,
|
||||
uint32_t storePeriod);
|
||||
|
||||
@ -129,12 +103,12 @@ virtual bool updateComment(std::string rid, std::wstring comment);
|
||||
void tick();
|
||||
|
||||
void loadRankFile(std::string filename, std::string src);
|
||||
void addRankMsg(RsRankMsg *msg);
|
||||
void addRankMsg(RsRankLinkMsg *msg);
|
||||
void publishMsgs();
|
||||
float locked_calcRank(RankGroup &grp); /* returns 0->100 */
|
||||
void reSortGroup(RankGroup &grp);
|
||||
void sortAllMsgs();
|
||||
pqistreamer *createStreamer(std::string file, std::string src, uint32_t bioflags);
|
||||
pqistreamer *createStreamer(std::string file, std::string src, bool reading);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -495,13 +495,38 @@ void LinksDialog::updateComments(std::string rid, std::string pid)
|
||||
ui.titleLineEdit->setText(QString::fromStdWString(detail.title));
|
||||
ui.linkLineEdit->setText(QString::fromStdWString(detail.link));
|
||||
|
||||
if (mLinkId != rid)
|
||||
if (mLinkId == rid)
|
||||
{
|
||||
/* clean comments */
|
||||
ui.linkTextEdit->setText("");
|
||||
/* leave comments */
|
||||
//ui.linkTextEdit->setText("");
|
||||
return;
|
||||
}
|
||||
|
||||
mLinkId = rid;
|
||||
|
||||
/* Add your text to the comment */
|
||||
std::string ownId = rsPeers->getOwnId();
|
||||
|
||||
for(cit = detail.comments.begin(); cit != detail.comments.end(); cit++)
|
||||
{
|
||||
if (cit->id == ownId)
|
||||
break;
|
||||
}
|
||||
|
||||
if (cit != detail.comments.end())
|
||||
{
|
||||
QString comment = QString::fromStdWString(cit->comment);
|
||||
ui.linkTextEdit->setText(comment);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.linkTextEdit->setText("");
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
for(cit = detail.comments.begin(); cit != detail.comments.end(); cit++)
|
||||
@ -584,6 +609,9 @@ void LinksDialog::addLinkComment( void )
|
||||
link.toStdWString(),
|
||||
title.toStdWString(),
|
||||
comment.toStdWString());
|
||||
|
||||
updateLinks();
|
||||
return;
|
||||
}
|
||||
|
||||
/* get existing details */
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "gui/toaster/MessageToaster.h"
|
||||
|
||||
|
||||
#include "rsiface/rsiface.h"
|
||||
#include "rsiface/rspeers.h"
|
||||
#include "rsiface/rsmsgs.h"
|
||||
#include <sstream>
|
||||
@ -260,7 +261,7 @@ void MessagesDialog::getallrecommended()
|
||||
for(fit = fnames.begin(), hit = hashes.begin(), sit = sizes.begin();
|
||||
fit != fnames.end(); fit++, hit++, sit++)
|
||||
{
|
||||
//rsicontrol -> FileRequest(*fit, *hit, *sit, "");
|
||||
rsicontrol -> FileRequest(*fit, *hit, *sit, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user