mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-17 13:24:15 -05:00
commit
96e73b301c
@ -2822,6 +2822,11 @@ void RsGenExchange::processRecvdMessages()
|
||||
mNetService->rejectMessage(*it) ;
|
||||
}
|
||||
|
||||
bool RsGenExchange::acceptNewGroup(const RsGxsGrpMetaData *grpMeta)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void RsGenExchange::processRecvdGroups()
|
||||
{
|
||||
RS_STACK_MUTEX(mGenMtx) ;
|
||||
@ -2847,12 +2852,12 @@ void RsGenExchange::processRecvdGroups()
|
||||
RsGxsGrpMetaData* meta = new RsGxsGrpMetaData();
|
||||
bool deserialOk = false;
|
||||
|
||||
if(grp->meta.bin_len != 0)
|
||||
if(grp->meta.bin_len != 0)
|
||||
deserialOk = meta->deserialise(grp->meta.bin_data, grp->meta.bin_len);
|
||||
|
||||
bool erase = true;
|
||||
|
||||
if(deserialOk)
|
||||
if(deserialOk && acceptNewGroup(meta))
|
||||
{
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << " processing validation for group " << meta->mGroupId << ", attempts number " << gpsi.mAttempts << std::endl;
|
||||
@ -2932,8 +2937,10 @@ void RsGenExchange::processRecvdGroups()
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "(EE) deserialise error in group meta data" << std::endl;
|
||||
delete grp;
|
||||
if(!deserialOk)
|
||||
std::cerr << "(EE) deserialise error in group meta data" << std::endl;
|
||||
|
||||
delete grp;
|
||||
delete meta;
|
||||
erase = true;
|
||||
}
|
||||
|
@ -259,6 +259,16 @@ public:
|
||||
*/
|
||||
virtual void receiveChanges(std::vector<RsGxsNotify*>& changes);
|
||||
|
||||
/*!
|
||||
* \brief acceptNewGroup
|
||||
* Early checks if the group can be accepted. This is mainly used to check wether the group is banned for some reasons.
|
||||
* Returns true unless derived in GXS services.
|
||||
*
|
||||
* \param grpMeta Group metadata to check
|
||||
* \return
|
||||
*/
|
||||
virtual bool acceptNewGroup(const RsGxsGrpMetaData *grpMeta) ;
|
||||
|
||||
bool subscribeToGroup(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe);
|
||||
|
||||
/*!
|
||||
|
@ -266,7 +266,7 @@ static const uint32_t RS_NXS_ITEM_ENCRYPTION_STATUS_GXS_KEY_MISSING = 0x05 ;
|
||||
|| defined(NXS_NET_DEBUG_4) || defined(NXS_NET_DEBUG_5) || defined(NXS_NET_DEBUG_6) || defined(NXS_NET_DEBUG_7)
|
||||
|
||||
static const RsPeerId peer_to_print = RsPeerId(std::string("")) ;
|
||||
static const RsGxsGroupId group_id_to_print = RsGxsGroupId(std::string("30501fac090b65f5b9def169598b53ed" )) ; // use this to allow to this group id only, or "" for all IDs
|
||||
static const RsGxsGroupId group_id_to_print = RsGxsGroupId(std::string("")) ; // use this to allow to this group id only, or "" for all IDs
|
||||
static const uint32_t service_to_print = 0x211 ; // use this to allow to this service id only, or 0 for all services
|
||||
// warning. Numbers should be SERVICE IDS (see serialiser/rsserviceids.h. E.g. 0x0215 for forums)
|
||||
|
||||
|
@ -50,12 +50,13 @@ public:
|
||||
};
|
||||
|
||||
virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) =0;
|
||||
virtual bool getReputationInfo(const RsGxsId& id,const RsPgpId& owner_id,ReputationInfo& info) =0 ;
|
||||
virtual bool getReputationInfo(const RsGxsId& id, const RsPgpId &ownerNode, ReputationInfo& info) =0;
|
||||
|
||||
// parameters
|
||||
|
||||
virtual void setNodeAutoBanThreshold(uint32_t n) =0;
|
||||
virtual uint32_t nodeAutoBanThreshold() =0;
|
||||
// virtual void setNodeAutoBanThreshold(uint32_t n) =0;
|
||||
// virtual uint32_t nodeAutoBanThreshold() =0;
|
||||
|
||||
virtual void setNodeAutoPositiveOpinionForContacts(bool b) =0;
|
||||
virtual bool nodeAutoPositiveOpinionForContacts() =0;
|
||||
virtual float nodeAutoBanIdentitiesLimit() =0;
|
||||
@ -64,7 +65,10 @@ public:
|
||||
// This one is a proxy designed to allow fast checking of a GXS id.
|
||||
// it basically returns true if assessment is not ASSESSMENT_OK
|
||||
|
||||
virtual bool isIdentityBanned(const RsGxsId& id,const RsPgpId& owner_node) =0;
|
||||
virtual bool isIdentityBanned(const RsGxsId& id) =0;
|
||||
|
||||
virtual bool isNodeBanned(const RsPgpId& id) =0;
|
||||
virtual void banNode(const RsPgpId& id,bool b) =0;
|
||||
};
|
||||
|
||||
// To access reputations from anywhere
|
||||
|
@ -74,6 +74,11 @@ void RsGxsReputationUpdateItem::clear()
|
||||
mOpinions.clear() ;
|
||||
}
|
||||
|
||||
void RsGxsReputationBannedNodeSetItem::clear()
|
||||
{
|
||||
mKnownIdentities.TlvClear();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
@ -82,10 +87,10 @@ std::ostream& RsGxsReputationConfigItem::print(std::ostream &out, uint16_t inden
|
||||
{
|
||||
printRsItemBase(out, "RsReputationConfigItem", indent);
|
||||
|
||||
out << "mPeerId: " << mPeerId << std::endl;
|
||||
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
|
||||
out << "last query : " << time(NULL) - mLastQuery << " secs ago." << std::endl;
|
||||
|
||||
out << "mPeerId: " << mPeerId << std::endl;
|
||||
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
|
||||
out << "last query : " << time(NULL) - mLastQuery << " secs ago." << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsReputationConfigItem", indent);
|
||||
return out;
|
||||
}
|
||||
@ -94,14 +99,15 @@ std::ostream& RsGxsReputationSetItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsReputationSetItem", indent);
|
||||
|
||||
out << "GxsId: " << mGxsId << std::endl;
|
||||
out << "mOwnOpinion: " << mOwnOpinion << std::endl;
|
||||
out << "mOwnOpinionTS : " << time(NULL) - mOwnOpinionTS << " secs ago." << std::endl;
|
||||
out << "GxsId: " << mGxsId << std::endl;
|
||||
out << "Owner: " << mOwnerNodeId << std::endl;
|
||||
out << "mOwnOpinion: " << mOwnOpinion << std::endl;
|
||||
out << "mOwnOpinionTS : " << time(NULL) - mOwnOpinionTS << " secs ago." << std::endl;
|
||||
out << "Opinions from neighbors: " << std::endl;
|
||||
|
||||
|
||||
for(std::map<RsPeerId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
|
||||
out << " " << it->first << ": " << it->second << std::endl;
|
||||
|
||||
out << " " << it->first << ": " << it->second << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsReputationSetItem", indent);
|
||||
return out;
|
||||
}
|
||||
@ -109,12 +115,12 @@ std::ostream& RsGxsReputationUpdateItem::print(std::ostream &out, uint16_t inden
|
||||
{
|
||||
printRsItemBase(out, "RsReputationUpdateItem", indent);
|
||||
|
||||
out << "from: " << PeerId() << std::endl;
|
||||
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
|
||||
|
||||
out << "from: " << PeerId() << std::endl;
|
||||
out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl;
|
||||
|
||||
for(std::map<RsGxsId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
|
||||
out << " " << it->first << ": " << it->second << std::endl;
|
||||
|
||||
out << " " << it->first << ": " << it->second << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsReputationUpdateItem", indent);
|
||||
return out;
|
||||
}
|
||||
@ -122,8 +128,19 @@ std::ostream& RsGxsReputationRequestItem::print(std::ostream &out, uint16_t inde
|
||||
{
|
||||
printRsItemBase(out, "RsReputationRequestItem", indent);
|
||||
|
||||
out << "last update: " << time(NULL) - mLastUpdate << " secs ago." << std::endl;
|
||||
|
||||
out << "last update: " << time(NULL) - mLastUpdate << " secs ago." << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsReputationRequestItem", indent);
|
||||
return out;
|
||||
}
|
||||
std::ostream& RsGxsReputationBannedNodeSetItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsReputationBannedNodeSetItem", indent);
|
||||
|
||||
out << "last update: " << time(NULL) - mLastActivityTS << " secs ago." << std::endl;
|
||||
out << "PGP id: " << mPgpId << std::endl;
|
||||
out << "Known ids: " << mKnownIdentities.ids.size() << std::endl;
|
||||
|
||||
printRsItemEnd(out, "RsReputationRequestItem", indent);
|
||||
return out;
|
||||
}
|
||||
@ -134,26 +151,38 @@ uint32_t RsGxsReputationConfigItem::serial_size() const
|
||||
uint32_t s = 8; /* header */
|
||||
|
||||
s += mPeerId.serial_size() ; // PeerId
|
||||
s += 4 ; // mLatestUpdate
|
||||
s += 4 ; // mLastQuery
|
||||
s += 4 ; // mLatestUpdate
|
||||
s += 4 ; // mLastQuery
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsGxsReputationSetItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
|
||||
s += mGxsId.serial_size() ;
|
||||
uint32_t s = 8; /* header */
|
||||
|
||||
s += mGxsId.serial_size() ;
|
||||
s += 4 ; // mOwnOpinion
|
||||
s += 4 ; // mOwnOpinionTS
|
||||
s += 4 ; // mIdentityFlags
|
||||
|
||||
s += mOwnerNodeId.serial_size() ;
|
||||
|
||||
s += 4 ; // mOpinions.size()
|
||||
|
||||
|
||||
s += (4+RsPeerId::serial_size()) * mOpinions.size() ;
|
||||
|
||||
return s ;
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsGxsReputationBannedNodeSetItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
|
||||
s += RsPgpId::serial_size() ; // mPgpId
|
||||
s += 4 ; // mLastActivityTS;
|
||||
s += mKnownIdentities.TlvSize(); // mKnownIdentities
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
uint32_t RsGxsReputationUpdateItem::serial_size() const
|
||||
@ -216,8 +245,10 @@ bool RsGxsReputationSetItem::serialise(void *data, uint32_t& pktsize) const
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinion);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinionTS);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mIdentityFlags) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size());
|
||||
|
||||
ok &= mOwnerNodeId.serialise(data,tlvsize,offset) ;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size());
|
||||
|
||||
for(std::map<RsPeerId,uint32_t>::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it)
|
||||
{
|
||||
ok &= it->first.serialise(data,tlvsize,offset) ;
|
||||
@ -232,6 +263,29 @@ bool RsGxsReputationSetItem::serialise(void *data, uint32_t& pktsize) const
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool RsGxsReputationBannedNodeSetItem::serialise(void *data, uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize ;
|
||||
uint32_t offset=0;
|
||||
|
||||
if(!serialise_header(data,pktsize,tlvsize,offset))
|
||||
return false ;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
ok &= mPgpId.serialise(data, tlvsize, offset) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, mLastActivityTS);
|
||||
ok &= mKnownIdentities.SetTlv(data, tlvsize, &offset) ;
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "RsGxsReputationSetItem::serialisedata() size error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
bool RsGxsReputationUpdateItem::serialise(void *data, uint32_t& pktsize) const
|
||||
{
|
||||
uint32_t tlvsize ;
|
||||
@ -304,7 +358,28 @@ RsGxsReputationConfigItem *RsGxsReputationSerialiser::deserialiseReputationConfi
|
||||
|
||||
return item;
|
||||
}
|
||||
RsGxsReputationBannedNodeSetItem *RsGxsReputationSerialiser::deserialiseReputationBannedNodeSetItem(void *data,uint32_t size)
|
||||
{
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
bool ok = true ;
|
||||
|
||||
RsGxsReputationBannedNodeSetItem *item = new RsGxsReputationBannedNodeSetItem() ;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->mPgpId.deserialise(data, size, offset) ;
|
||||
ok &= getRawUInt32(data, size, &offset, &item->mLastActivityTS);
|
||||
ok &= item->mKnownIdentities.GetTlv(data,size,&offset) ;
|
||||
|
||||
if (offset != rssize || !ok)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
||||
delete item;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem_deprecated(void *data,uint32_t tlvsize)
|
||||
{
|
||||
uint32_t offset = 8; // skip the header
|
||||
@ -315,30 +390,32 @@ RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem_
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->mGxsId.deserialise(data, tlvsize, offset) ;
|
||||
|
||||
item->mOwnerNodeId.clear(); // clears up, for backward compat.
|
||||
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion);
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS);
|
||||
|
||||
item->mIdentityFlags = REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE; // special value that means please update me.
|
||||
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags);
|
||||
|
||||
uint32_t S ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &S);
|
||||
|
||||
|
||||
for(uint32_t i = 0; ok && (i < S); ++i)
|
||||
{
|
||||
RsPeerId pid ;
|
||||
uint32_t op ;
|
||||
|
||||
ok &= pid.deserialise(data, tlvsize, offset) ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &op);
|
||||
|
||||
|
||||
ok &= pid.deserialise(data, tlvsize, offset) ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &op);
|
||||
|
||||
if(ok)
|
||||
item->mOpinions[pid] = op ;
|
||||
item->mOpinions[pid] = op ;
|
||||
}
|
||||
|
||||
if (offset != rssize || !ok)
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
||||
delete item;
|
||||
delete item;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
@ -357,7 +434,8 @@ RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem(
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion);
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS);
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags);
|
||||
|
||||
ok &= item->mOwnerNodeId.deserialise(data, tlvsize, offset) ;
|
||||
|
||||
uint32_t S ;
|
||||
ok &= getRawUInt32(data, tlvsize, &offset, &S);
|
||||
|
||||
@ -455,12 +533,13 @@ RsItem *RsGxsReputationSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM : return deserialiseReputationSetItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated: return deserialiseReputationSetItem_deprecated(data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM : return deserialiseReputationUpdateItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM : return deserialiseReputationRequestItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM : return deserialiseReputationConfigItem (data, *pktsize);
|
||||
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM : return deserialiseReputationSetItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated : return deserialiseReputationSetItem_deprecated(data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM: return deserialiseReputationBannedNodeSetItem(data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM : return deserialiseReputationUpdateItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM : return deserialiseReputationRequestItem (data, *pktsize);
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM : return deserialiseReputationConfigItem (data, *pktsize);
|
||||
|
||||
default:
|
||||
std::cerr << "RsGxsReputationSerialiser::deserialise(): unknown item subtype " << std::hex<< rstype << std::dec << std::endl;
|
||||
return NULL;
|
||||
|
@ -30,13 +30,16 @@
|
||||
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvidset.h"
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM 0x01
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated 0x02
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM 0x03
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM 0x04
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM 0x05
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM 0x01
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated2 0x02
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM 0x03
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM 0x04
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated 0x05
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM 0x06
|
||||
#define RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM 0x07
|
||||
|
||||
/**************************************************************************/
|
||||
class RsReputationItem: public RsItem
|
||||
@ -68,31 +71,71 @@ public:
|
||||
virtual void clear() {}
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
virtual bool serialise(void *data,uint32_t& size) const ;
|
||||
virtual bool serialise(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
|
||||
RsPeerId mPeerId;
|
||||
uint32_t mLatestUpdate; // timestamp they returned.
|
||||
uint32_t mLastQuery; // when we sent out.
|
||||
uint32_t mLastQuery; // when we sent out.
|
||||
};
|
||||
|
||||
// This class should disappear. Deprecated since Aug 1, 2016. The class definition is actually not needed,
|
||||
// that is why it's commented out. Kept here in order to explains how the deserialisation works.
|
||||
//
|
||||
// class RsGxsReputationSetItem_deprecated: public RsReputationItem
|
||||
// {
|
||||
// public:
|
||||
// RsGxsReputationSetItem_deprecated() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated) {}
|
||||
//
|
||||
// virtual ~RsGxsReputationSetItem_deprecated() {}
|
||||
// virtual void clear() {}
|
||||
// std::ostream &print(std::ostream &out, uint16_t indent = 0) { return out;}
|
||||
//
|
||||
// virtual bool serialise(void *data,uint32_t& size) const { std::cerr << "(EE) serialise attempt for a deprecated reputation item. This should not happen" << std::endl; return false ; }
|
||||
// virtual uint32_t serial_size() const ;
|
||||
//
|
||||
// RsGxsId mGxsId;
|
||||
// uint32_t mOwnOpinion;
|
||||
// uint32_t mOwnOpinionTS;
|
||||
// uint32_t mIdentityFlags;
|
||||
// std::map<RsPeerId, uint32_t> mOpinions; // RsPeerId -> Opinion.
|
||||
// };
|
||||
|
||||
class RsGxsReputationSetItem: public RsReputationItem
|
||||
{
|
||||
public:
|
||||
RsGxsReputationSetItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM) {}
|
||||
RsGxsReputationSetItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM) {}
|
||||
|
||||
virtual ~RsGxsReputationSetItem() {}
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
virtual bool serialise(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
|
||||
RsGxsId mGxsId;
|
||||
uint32_t mOwnOpinion;
|
||||
uint32_t mOwnOpinionTS;
|
||||
uint32_t mIdentityFlags ;
|
||||
std::map<RsPeerId, uint32_t> mOpinions; // RsPeerId -> Opinion.
|
||||
virtual bool serialise(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
|
||||
RsGxsId mGxsId;
|
||||
uint32_t mOwnOpinion;
|
||||
uint32_t mOwnOpinionTS;
|
||||
uint32_t mIdentityFlags ;
|
||||
RsPgpId mOwnerNodeId;
|
||||
std::map<RsPeerId, uint32_t> mOpinions; // RsPeerId -> Opinion.
|
||||
};
|
||||
|
||||
class RsGxsReputationBannedNodeSetItem: public RsReputationItem
|
||||
{
|
||||
public:
|
||||
RsGxsReputationBannedNodeSetItem() :RsReputationItem(RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM) {}
|
||||
|
||||
virtual ~RsGxsReputationBannedNodeSetItem() {}
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
virtual bool serialise(void *data,uint32_t& size) const ;
|
||||
virtual uint32_t serial_size() const ;
|
||||
|
||||
RsPgpId mPgpId ;
|
||||
uint32_t mLastActivityTS ;
|
||||
RsTlvGxsIdSet mKnownIdentities ;
|
||||
};
|
||||
|
||||
class RsGxsReputationUpdateItem: public RsReputationItem
|
||||
@ -145,11 +188,12 @@ public:
|
||||
virtual RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
private:
|
||||
static RsGxsReputationConfigItem *deserialiseReputationConfigItem (void *data, uint32_t size);
|
||||
static RsGxsReputationSetItem *deserialiseReputationSetItem (void *data, uint32_t size);
|
||||
static RsGxsReputationSetItem *deserialiseReputationSetItem_deprecated (void *data, uint32_t size);
|
||||
static RsGxsReputationUpdateItem *deserialiseReputationUpdateItem (void *data, uint32_t size);
|
||||
static RsGxsReputationRequestItem *deserialiseReputationRequestItem (void *data, uint32_t size);
|
||||
static RsGxsReputationConfigItem *deserialiseReputationConfigItem (void *data, uint32_t size);
|
||||
static RsGxsReputationSetItem *deserialiseReputationSetItem (void *data, uint32_t size);
|
||||
static RsGxsReputationSetItem *deserialiseReputationSetItem_deprecated (void *data, uint32_t size);
|
||||
static RsGxsReputationUpdateItem *deserialiseReputationUpdateItem (void *data, uint32_t size);
|
||||
static RsGxsReputationRequestItem *deserialiseReputationRequestItem (void *data, uint32_t size);
|
||||
static RsGxsReputationBannedNodeSetItem *deserialiseReputationBannedNodeSetItem (void *data, uint32_t size);
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
|
@ -139,6 +139,7 @@ static const uint32_t PGP_AUTO_BAN_THRESHOLD_DEFAULT = 2 ; // above t
|
||||
static const uint32_t IDENTITY_FLAGS_UPDATE_DELAY = 100 ; //
|
||||
static const uint32_t BANNED_NODES_UPDATE_DELAY = 313 ; // update approx every 5 mins. Chosen to not be a multiple of IDENTITY_FLAGS_UPDATE_DELAY
|
||||
static const uint32_t REPUTATION_INFO_KEEP_DELAY = 86400*35; // remove old reputation info 5 days after last usage limit, in case the ID would come back..
|
||||
static const uint32_t BANNED_NODES_INACTIVITY_KEEP = 86400*60; // remove all info about banned nodes after 2 months of inactivity
|
||||
|
||||
p3GxsReputation::p3GxsReputation(p3LinkMgr *lm)
|
||||
:p3Service(), p3Config(),
|
||||
@ -146,7 +147,7 @@ p3GxsReputation::p3GxsReputation(p3LinkMgr *lm)
|
||||
{
|
||||
addSerialType(new RsGxsReputationSerialiser());
|
||||
|
||||
mPgpAutoBanThreshold = PGP_AUTO_BAN_THRESHOLD_DEFAULT ;
|
||||
//mPgpAutoBanThreshold = PGP_AUTO_BAN_THRESHOLD_DEFAULT ;
|
||||
mRequestTime = 0;
|
||||
mStoreTime = 0;
|
||||
mReputationsUpdated = false;
|
||||
@ -154,6 +155,7 @@ p3GxsReputation::p3GxsReputation(p3LinkMgr *lm)
|
||||
mLastIdentityFlagsUpdate = time(NULL) - 3;
|
||||
mAverageActiveFriends = 0 ;
|
||||
mLastBannedNodesUpdate = 0 ;
|
||||
mBannedNodesProxyNeedsUpdate = false;
|
||||
|
||||
mAutoBanIdentitiesLimit = REPUTATION_ASSESSMENT_THRESHOLD_X1;
|
||||
mAutoSetPositiveOptionToContacts = true; // default
|
||||
@ -200,9 +202,15 @@ int p3GxsReputation::tick()
|
||||
if(now > BANNED_NODES_UPDATE_DELAY+mLastBannedNodesUpdate) // 613 is not a multiple of 100, to avoid piling up work
|
||||
{
|
||||
updateIdentityFlags() ; // needed before updateBannedNodesList!
|
||||
updateBannedNodesList();
|
||||
updateBannedNodesProxy();
|
||||
mLastBannedNodesUpdate = now ;
|
||||
}
|
||||
|
||||
if(mBannedNodesProxyNeedsUpdate)
|
||||
{
|
||||
updateBannedNodesProxy();
|
||||
mBannedNodesProxyNeedsUpdate = false ;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_REPUTATION
|
||||
static time_t last_debug_print = time(NULL) ;
|
||||
@ -216,21 +224,21 @@ int p3GxsReputation::tick()
|
||||
return 0;
|
||||
}
|
||||
|
||||
void p3GxsReputation::setNodeAutoBanThreshold(uint32_t n)
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
if(n != mPgpAutoBanThreshold)
|
||||
{
|
||||
mLastBannedNodesUpdate = 0 ;
|
||||
mPgpAutoBanThreshold = n ;
|
||||
IndicateConfigChanged() ;
|
||||
}
|
||||
}
|
||||
uint32_t p3GxsReputation::nodeAutoBanThreshold()
|
||||
{
|
||||
return mPgpAutoBanThreshold ;
|
||||
}
|
||||
// void p3GxsReputation::setNodeAutoBanThreshold(uint32_t n)
|
||||
// {
|
||||
// RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
//
|
||||
// if(n != mPgpAutoBanThreshold)
|
||||
// {
|
||||
// mLastBannedNodesUpdate = 0 ;
|
||||
// mPgpAutoBanThreshold = n ;
|
||||
// IndicateConfigChanged() ;
|
||||
// }
|
||||
// }
|
||||
// uint32_t p3GxsReputation::nodeAutoBanThreshold()
|
||||
// {
|
||||
// return mPgpAutoBanThreshold ;
|
||||
// }
|
||||
|
||||
void p3GxsReputation::setNodeAutoPositiveOpinionForContacts(bool b)
|
||||
{
|
||||
@ -284,33 +292,21 @@ class ZeroInitCnt
|
||||
operator uint32_t() const { return cnt ; }
|
||||
};
|
||||
|
||||
void p3GxsReputation::updateBannedNodesList()
|
||||
void p3GxsReputation::updateBannedNodesProxy()
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << "Updating PGP ban list based on signed GxsIds to ban" << std::endl;
|
||||
#endif
|
||||
std::map<RsGxsId, Reputation> tmpreps ;
|
||||
//#ifdef DEBUG_REPUTATION
|
||||
// std::cerr << "Updating PGP ban list based on signed GxsIds to ban. Ban threshold = " << mPgpAutoBanThreshold << std::endl;
|
||||
//#endif
|
||||
// This function keeps the Banned GXS id proxy up to date.
|
||||
//
|
||||
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
tmpreps = mReputations ;
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
std::map<RsPgpId,ZeroInitCnt> pgp_ids_to_ban ;
|
||||
mPerNodeBannedIdsProxy.clear();
|
||||
|
||||
for( std::map<RsGxsId, Reputation>::iterator rit = tmpreps.begin();rit!=tmpreps.end();++rit)
|
||||
if((rit->second.mIdentityFlags & REPUTATION_IDENTITY_FLAG_PGP_LINKED) && !rit->second.mOwnerNode.isNull() && rit->second.mOwnOpinion == p3GxsReputation::OPINION_NEGATIVE)
|
||||
++pgp_ids_to_ban[rit->second.mOwnerNode] ;
|
||||
|
||||
mBannedPgpIds.clear() ;
|
||||
|
||||
if(mPgpAutoBanThreshold > 0)
|
||||
for(std::map<RsPgpId,ZeroInitCnt>::const_iterator it(pgp_ids_to_ban.begin());it!=pgp_ids_to_ban.end();++it)
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << "PGP Id: " << it->first << ". Ban count=" << it->second << " - " << (( it->second >= mPgpAutoBanThreshold)?"Banned!":"OK" ) << std::endl;
|
||||
#endif
|
||||
if(it->second >= mPgpAutoBanThreshold)
|
||||
mBannedPgpIds.insert(it->first) ;
|
||||
}
|
||||
for( std::map<RsPgpId, BannedNodeInfo>::iterator rit = mBannedPgpIds.begin();rit!=mBannedPgpIds.end();++rit)
|
||||
for(std::set<RsGxsId>::const_iterator it(rit->second.known_identities.begin());it!=rit->second.known_identities.end();++it)
|
||||
mPerNodeBannedIdsProxy.insert(*it) ;
|
||||
}
|
||||
|
||||
void p3GxsReputation::updateIdentityFlags()
|
||||
@ -326,7 +322,7 @@ void p3GxsReputation::updateIdentityFlags()
|
||||
#endif
|
||||
|
||||
for( std::map<RsGxsId, Reputation>::iterator rit = mReputations.begin();rit!=mReputations.end();++rit)
|
||||
if(rit->second.mIdentityFlags & REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE)
|
||||
if( (rit->second.mIdentityFlags & REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE) && (mPerNodeBannedIdsProxy.find(rit->first) == mPerNodeBannedIdsProxy.end()))
|
||||
to_update.push_back(rit->first) ;
|
||||
}
|
||||
|
||||
@ -387,9 +383,9 @@ void p3GxsReputation::cleanup()
|
||||
#endif
|
||||
std::cerr << "p3GxsReputation::cleanup() " << std::endl;
|
||||
|
||||
// remove optionions about identities that do not exist anymore. That will in particular avoid asking p3idservice about deleted
|
||||
// identities, which would cause an excess of hits to the database.
|
||||
// We do it in two steps to avoid a deadlock when calling rsIdentity from here.
|
||||
// Remove opinions about identities that do not exist anymore. That will in particular avoid asking p3idservice about deleted
|
||||
// identities, which would cause an excess of hits to the database. We do it in two steps to avoid a deadlock when calling rsIdentity from here.
|
||||
// Also, neutral opinions for banned PGP linked nodes are kept, so as to be able to not request them again.
|
||||
|
||||
bool updated = false ;
|
||||
time_t now = time(NULL) ;
|
||||
@ -400,15 +396,15 @@ void p3GxsReputation::cleanup()
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
for(std::map<RsGxsId,Reputation>::iterator it(mReputations.begin());it!=mReputations.end();)
|
||||
if(it->second.mOpinions.empty() && it->second.mOwnOpinion == RsReputations::OPINION_NEUTRAL)
|
||||
if(it->second.mOpinions.empty() && it->second.mOwnOpinion == RsReputations::OPINION_NEUTRAL && (it->second.mOwnerNode.isNull()))
|
||||
{
|
||||
std::map<RsGxsId,Reputation>::iterator tmp(it) ;
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << " ID " << it->first << ": own is neutral and no opinions from friends => remove entry" << std::endl;
|
||||
#endif
|
||||
std::map<RsGxsId,Reputation>::iterator tmp(it) ;
|
||||
++tmp ;
|
||||
mReputations.erase(it) ;
|
||||
it = tmp ;
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << " ID " << it->first << ": own is neutral and no opinions from friends => remove entry" << std::endl;
|
||||
#endif
|
||||
updated = true ;
|
||||
}
|
||||
else
|
||||
@ -424,12 +420,31 @@ void p3GxsReputation::cleanup()
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << " Identity " << *it << " has a last usage TS of " << now - rsIdentity->getLastUsageTS(*it) << " secs ago: deleting it." << std::endl;
|
||||
#endif
|
||||
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
mReputations.erase(*it) ;
|
||||
updated = true ;
|
||||
}
|
||||
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
for(std::map<RsPgpId,BannedNodeInfo>::iterator it(mBannedPgpIds.begin());it!=mBannedPgpIds.end();)
|
||||
if(it->second.last_activity_TS + BANNED_NODES_INACTIVITY_KEEP < now)
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << " Removing all info about banned node " << it->first << " by lack of activity." << std::endl;
|
||||
#endif
|
||||
std::map<RsPgpId,BannedNodeInfo>::iterator tmp(it ) ;
|
||||
++tmp ;
|
||||
mBannedPgpIds.erase(it) ;
|
||||
it = tmp ;
|
||||
|
||||
updated = true ;
|
||||
}
|
||||
else
|
||||
++it ;
|
||||
}
|
||||
|
||||
if(updated)
|
||||
IndicateConfigChanged() ;
|
||||
}
|
||||
@ -493,8 +508,8 @@ bool p3GxsReputation::processIncoming()
|
||||
switch(item->PacketSubType())
|
||||
{
|
||||
default:
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM:
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM:
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM:
|
||||
case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM:
|
||||
std::cerr << "p3GxsReputation::processingIncoming() Unknown Item";
|
||||
std::cerr << std::endl;
|
||||
itemOk = false;
|
||||
@ -762,37 +777,63 @@ bool p3GxsReputation::updateLatestUpdate(RsPeerId peerid,time_t latest_update)
|
||||
* Opinion
|
||||
****/
|
||||
|
||||
bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& owner_id, RsReputations::ReputationInfo& info)
|
||||
bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& ownerNode, RsReputations::ReputationInfo& info)
|
||||
{
|
||||
if(gxsid.isNull())
|
||||
return false ;
|
||||
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
#ifdef DEBUG_REPUTATION
|
||||
#ifdef DEBUG_REPUTATION2
|
||||
std::cerr << "getReputationInfo() for " << gxsid << std::endl;
|
||||
#endif
|
||||
std::map<RsGxsId,Reputation>::const_iterator it = mReputations.find(gxsid) ;
|
||||
std::map<RsGxsId,Reputation>::iterator it = mReputations.find(gxsid) ;
|
||||
RsPgpId owner_id ;
|
||||
|
||||
if(it == mReputations.end())
|
||||
{
|
||||
info.mOwnOpinion = RsReputations::OPINION_NEUTRAL ;
|
||||
info.mOverallReputationScore = RsReputations::REPUTATION_THRESHOLD_DEFAULT ;
|
||||
info.mFriendAverage = REPUTATION_THRESHOLD_DEFAULT ;
|
||||
info.mFriendAverage = REPUTATION_THRESHOLD_DEFAULT ;
|
||||
|
||||
owner_id = ownerNode ;
|
||||
}
|
||||
else
|
||||
{
|
||||
const Reputation& rep(it->second) ;
|
||||
Reputation& rep(it->second) ;
|
||||
|
||||
info.mOwnOpinion = RsReputations::Opinion(rep.mOwnOpinion) ;
|
||||
info.mOverallReputationScore = rep.mReputation ;
|
||||
info.mFriendAverage = rep.mFriendAverage ;
|
||||
|
||||
if(rep.mOwnerNode.isNull())
|
||||
rep.mOwnerNode = ownerNode ;
|
||||
|
||||
owner_id = rep.mOwnerNode ;
|
||||
}
|
||||
|
||||
if(!owner_id.isNull() && (mBannedPgpIds.find(owner_id) != mBannedPgpIds.end()))
|
||||
std::map<RsPgpId,BannedNodeInfo>::iterator it2 ;
|
||||
|
||||
if(!owner_id.isNull() && (it2 = mBannedPgpIds.find(owner_id))!=mBannedPgpIds.end())
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << "p3GxsReputations: identity " << gxsid << " is banned because owner node ID " << owner_id << " is banned." << std::endl;
|
||||
if(it2->second.known_identities.find(gxsid) == it2->second.known_identities.end())
|
||||
{
|
||||
it2->second.known_identities.insert(gxsid) ;
|
||||
it2->second.last_activity_TS = now ;
|
||||
mBannedNodesProxyNeedsUpdate = true ;
|
||||
}
|
||||
|
||||
info.mAssessment = RsReputations::ASSESSMENT_BAD ;
|
||||
#ifdef DEBUG_REPUTATION2
|
||||
std::cerr << "p3GxsReputations: identity " << gxsid << " is banned because owner node ID " << owner_id << " is banned (found in banned nodes list)." << std::endl;
|
||||
#endif
|
||||
}
|
||||
else if(mPerNodeBannedIdsProxy.find(gxsid) != mPerNodeBannedIdsProxy.end())
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION2
|
||||
std::cerr << "p3GxsReputations: identity " << gxsid << " is banned because owner node ID " << owner_id << " is banned (found in proxy)." << std::endl;
|
||||
#endif
|
||||
info.mAssessment = RsReputations::ASSESSMENT_BAD ;
|
||||
}
|
||||
@ -801,18 +842,46 @@ bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& own
|
||||
else
|
||||
info.mAssessment = RsReputations::ASSESSMENT_OK ;
|
||||
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << " information present. OwnOp = " << info.mOwnOpinion << ", overall score=" << info.mAssessment << std::endl;
|
||||
#ifdef DEBUG_REPUTATION2
|
||||
std::cerr << " information present. OwnOp = " << info.mOwnOpinion << ", owner node=" << owner_id << ", overall score=" << info.mAssessment << std::endl;
|
||||
#endif
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool p3GxsReputation::isIdentityBanned(const RsGxsId &id,const RsPgpId& owner_node)
|
||||
void p3GxsReputation::banNode(const RsPgpId& id,bool b)
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
if(b)
|
||||
{
|
||||
if(mBannedPgpIds.find(id) == mBannedPgpIds.end())
|
||||
{
|
||||
mBannedPgpIds[id] = BannedNodeInfo() ;
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(mBannedPgpIds.find(id) != mBannedPgpIds.end())
|
||||
{
|
||||
mBannedPgpIds.erase(id) ;
|
||||
IndicateConfigChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
bool p3GxsReputation::isNodeBanned(const RsPgpId& id)
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
return mBannedPgpIds.find(id) != mBannedPgpIds.end();
|
||||
}
|
||||
|
||||
bool p3GxsReputation::isIdentityBanned(const RsGxsId &id)
|
||||
{
|
||||
RsReputations::ReputationInfo info ;
|
||||
|
||||
if(!getReputationInfo(id,owner_node,info))
|
||||
if(!getReputationInfo(id,RsPgpId(),info))
|
||||
return false ;
|
||||
|
||||
#ifdef DEBUG_REPUTATION
|
||||
@ -931,6 +1000,7 @@ bool p3GxsReputation::saveList(bool& cleanup, std::list<RsItem*> &savelist)
|
||||
item->mOwnOpinion = rit->second.mOwnOpinion;
|
||||
item->mOwnOpinionTS = rit->second.mOwnOpinionTs;
|
||||
item->mIdentityFlags = rit->second.mIdentityFlags;
|
||||
item->mOwnerNodeId = rit->second.mOwnerNode;
|
||||
|
||||
std::map<RsPeerId, RsReputations::Opinion>::iterator oit;
|
||||
for(oit = rit->second.mOpinions.begin(); oit != rit->second.mOpinions.end(); ++oit)
|
||||
@ -942,12 +1012,23 @@ bool p3GxsReputation::saveList(bool& cleanup, std::list<RsItem*> &savelist)
|
||||
savelist.push_back(item);
|
||||
count++;
|
||||
}
|
||||
|
||||
for(std::map<RsPgpId,BannedNodeInfo>::const_iterator it(mBannedPgpIds.begin());it!=mBannedPgpIds.end();++it)
|
||||
{
|
||||
RsGxsReputationBannedNodeSetItem *item = new RsGxsReputationBannedNodeSetItem();
|
||||
|
||||
item->mPgpId = it->first ;
|
||||
item->mLastActivityTS = it->second.last_activity_TS;
|
||||
item->mKnownIdentities.ids = it->second.known_identities;
|
||||
|
||||
savelist.push_back(item) ;
|
||||
}
|
||||
|
||||
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
||||
RsTlvKeyValue kv;
|
||||
kv.key = "AUTO_BAN_NODES_THRESHOLD" ;
|
||||
rs_sprintf(kv.value, "%d", mPgpAutoBanThreshold);
|
||||
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
// kv.key = "AUTO_BAN_NODES_THRESHOLD" ;
|
||||
// rs_sprintf(kv.value, "%d", mPgpAutoBanThreshold);
|
||||
// vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
kv.key = "AUTO_BAN_IDENTITIES_THRESHOLD" ;
|
||||
rs_sprintf(kv.value, "%f", mAutoBanIdentitiesLimit);
|
||||
@ -970,7 +1051,7 @@ void p3GxsReputation::saveDone()
|
||||
bool p3GxsReputation::loadList(std::list<RsItem *>& loadList)
|
||||
{
|
||||
#ifdef DEBUG_REPUTATION
|
||||
std::cerr << "p3GxsReputation::saveList()" << std::endl;
|
||||
std::cerr << "p3GxsReputation::loadList()" << std::endl;
|
||||
#endif
|
||||
std::list<RsItem *>::iterator it;
|
||||
std::set<RsPeerId> peerSet;
|
||||
@ -989,28 +1070,39 @@ bool p3GxsReputation::loadList(std::list<RsItem *>& loadList)
|
||||
config.mLatestUpdate = item->mLatestUpdate;
|
||||
config.mLastQuery = 0;
|
||||
|
||||
peerSet.insert(peerId);
|
||||
peerSet.insert(peerId);
|
||||
}
|
||||
|
||||
RsGxsReputationSetItem *set = dynamic_cast<RsGxsReputationSetItem *>(*it);
|
||||
|
||||
if (set)
|
||||
loadReputationSet(set, peerSet);
|
||||
|
||||
|
||||
RsGxsReputationBannedNodeSetItem *itm2 = dynamic_cast<RsGxsReputationBannedNodeSetItem*>(*it) ;
|
||||
|
||||
if(itm2 != NULL)
|
||||
{
|
||||
BannedNodeInfo& info(mBannedPgpIds[itm2->mPgpId]) ;
|
||||
info.last_activity_TS = itm2->mLastActivityTS ;
|
||||
info.known_identities = itm2->mKnownIdentities.ids ;
|
||||
}
|
||||
|
||||
RsConfigKeyValueSet *vitem = dynamic_cast<RsConfigKeyValueSet *>(*it);
|
||||
|
||||
if(vitem)
|
||||
for(std::list<RsTlvKeyValue>::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit)
|
||||
{
|
||||
if(kit->key == "AUTO_BAN_NODES_THRESHOLD")
|
||||
{
|
||||
int val ;
|
||||
if (sscanf(kit->value.c_str(), "%d", &val) == 1)
|
||||
{
|
||||
mPgpAutoBanThreshold = val ;
|
||||
std::cerr << "Setting AutoBanNode threshold to " << val << std::endl ;
|
||||
mLastBannedNodesUpdate = 0 ; // force update
|
||||
}
|
||||
};
|
||||
// if(kit->key == "AUTO_BAN_NODES_THRESHOLD")
|
||||
// {
|
||||
// int val ;
|
||||
// if (sscanf(kit->value.c_str(), "%d", &val) == 1)
|
||||
// {
|
||||
// mPgpAutoBanThreshold = val ;
|
||||
// std::cerr << "Setting AutoBanNode threshold to " << val << std::endl ;
|
||||
// mLastBannedNodesUpdate = 0 ; // force update
|
||||
// }
|
||||
// };
|
||||
if(kit->key == "AUTO_BAN_IDENTITIES_THRESHOLD")
|
||||
{
|
||||
float val ;
|
||||
@ -1033,52 +1125,62 @@ bool p3GxsReputation::loadList(std::list<RsItem *>& loadList)
|
||||
delete (*it);
|
||||
}
|
||||
|
||||
updateBannedNodesProxy();
|
||||
loadList.clear() ;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3GxsReputation::loadReputationSet(RsGxsReputationSetItem *item, const std::set<RsPeerId> &peerSet)
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
{
|
||||
RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
std::map<RsGxsId, Reputation>::iterator rit;
|
||||
std::map<RsGxsId, Reputation>::iterator rit;
|
||||
|
||||
if(item->mGxsId.isNull()) // just a protection against potential errors having put 00000 into ids.
|
||||
if(item->mGxsId.isNull()) // just a protection against potential errors having put 00000 into ids.
|
||||
return false ;
|
||||
|
||||
/* find matching Reputation */
|
||||
RsGxsId gxsId(item->mGxsId);
|
||||
rit = mReputations.find(gxsId);
|
||||
if (rit != mReputations.end())
|
||||
{
|
||||
std::cerr << "ERROR";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
Reputation &reputation = mReputations[gxsId];
|
||||
/* find matching Reputation */
|
||||
RsGxsId gxsId(item->mGxsId);
|
||||
rit = mReputations.find(gxsId);
|
||||
if (rit != mReputations.end())
|
||||
{
|
||||
std::cerr << "ERROR";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
// install opinions.
|
||||
std::map<RsPeerId, uint32_t>::const_iterator oit;
|
||||
for(oit = item->mOpinions.begin(); oit != item->mOpinions.end(); ++oit)
|
||||
{
|
||||
// expensive ... but necessary.
|
||||
RsPeerId peerId(oit->first);
|
||||
if (peerSet.end() != peerSet.find(peerId))
|
||||
reputation.mOpinions[peerId] = safe_convert_uint32t_to_opinion(oit->second);
|
||||
}
|
||||
Reputation &reputation = mReputations[gxsId];
|
||||
|
||||
reputation.mOwnOpinion = item->mOwnOpinion;
|
||||
reputation.mOwnOpinionTs = item->mOwnOpinionTS;
|
||||
// install opinions.
|
||||
std::map<RsPeerId, uint32_t>::const_iterator oit;
|
||||
for(oit = item->mOpinions.begin(); oit != item->mOpinions.end(); ++oit)
|
||||
{
|
||||
// expensive ... but necessary.
|
||||
RsPeerId peerId(oit->first);
|
||||
if (peerSet.end() != peerSet.find(peerId))
|
||||
reputation.mOpinions[peerId] = safe_convert_uint32t_to_opinion(oit->second);
|
||||
}
|
||||
|
||||
// if dropping entries has changed the score -> must update.
|
||||
|
||||
//float old_reputation = reputation.mReputation ;
|
||||
//mUpdatedReputations.insert(gxsId) ;
|
||||
|
||||
reputation.updateReputation() ;
|
||||
reputation.mOwnOpinion = item->mOwnOpinion;
|
||||
reputation.mOwnOpinionTs = item->mOwnOpinionTS;
|
||||
reputation.mOwnerNode = item->mOwnerNodeId;
|
||||
reputation.mIdentityFlags = item->mIdentityFlags | REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE;
|
||||
|
||||
mUpdated.insert(std::make_pair(reputation.mOwnOpinionTs, gxsId));
|
||||
return true;
|
||||
// if dropping entries has changed the score -> must update.
|
||||
|
||||
//float old_reputation = reputation.mReputation ;
|
||||
//mUpdatedReputations.insert(gxsId) ;
|
||||
|
||||
reputation.updateReputation() ;
|
||||
|
||||
mUpdated.insert(std::make_pair(reputation.mOwnOpinionTs, gxsId));
|
||||
}
|
||||
#ifdef DEBUG_REPUTATION
|
||||
RsReputations::ReputationInfo info ;
|
||||
getReputationInfo(item->mGxsId,item->mOwnerNodeId,info) ;
|
||||
std::cerr << item->mGxsId << " : own: " << info.mOwnOpinion << ", owner node: " << item->mOwnerNodeId << ", assessment: " << ((info.mAssessment==ASSESSMENT_BAD)?"BAD":"OK") << std::endl;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -1258,16 +1360,33 @@ void p3GxsReputation::debug_print()
|
||||
{
|
||||
std::cerr << "Reputations database: " << std::endl;
|
||||
std::cerr << " Average number of peers: " << mAverageActiveFriends << std::endl;
|
||||
|
||||
std::cerr << " GXS ID data: " << std::endl;
|
||||
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
|
||||
for(std::map<RsGxsId,Reputation>::const_iterator it(mReputations.begin());it!=mReputations.end();++it)
|
||||
{
|
||||
std::cerr << " ID=" << it->first << ", own: " << it->second.mOwnOpinion << ", Friend average: " << it->second.mFriendAverage << ", global_score: " << it->second.mReputation
|
||||
<< ", last own update: " << now - it->second.mOwnOpinionTs << " secs ago." << std::endl;
|
||||
|
||||
for(std::map<RsPeerId,RsReputations::Opinion>::const_iterator it2(it->second.mOpinions.begin());it2!=it->second.mOpinions.end();++it2)
|
||||
std::cerr << " " << it->first << ": own: " << it->second.mOwnOpinion << ", Friend average: " << it->second.mFriendAverage << ", global_score: " << it->second.mReputation
|
||||
<< ", last own update: " << now - it->second.mOwnOpinionTs << " secs ago." << std::endl;
|
||||
#ifdef DEBUG_REPUTATION2
|
||||
for(std::map<RsPeerId,RsReputations::Opinion>::const_iterator it2(it->second.mOpinions.begin());it2!=it->second.mOpinions.end();++it2)
|
||||
std::cerr << " " << it2->first << ": " << it2->second << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::cerr << " Banned RS nodes by ID: " << std::endl;
|
||||
|
||||
for(std::map<RsPgpId,BannedNodeInfo>::const_iterator it(mBannedPgpIds.begin());it!=mBannedPgpIds.end();++it)
|
||||
{
|
||||
std::cerr << " Node " << it->first << ", last activity: " << now - it->second.last_activity_TS << " secs ago." << std::endl;
|
||||
|
||||
for(std::set<RsGxsId>::const_iterator it2(it->second.known_identities.begin());it2!=it->second.known_identities.end();++it2)
|
||||
std::cerr << " " << *it2 << std::endl;
|
||||
}
|
||||
|
||||
std::cerr << " Per node Banned GXSIds proxy: " << std::endl;
|
||||
|
||||
for(std::set<RsGxsId>::const_iterator it(mPerNodeBannedIdsProxy.begin());it!=mPerNodeBannedIdsProxy.end();++it)
|
||||
std::cerr << " " << *it << std::endl;
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,12 @@ public:
|
||||
time_t mLastQuery;
|
||||
};
|
||||
|
||||
struct BannedNodeInfo
|
||||
{
|
||||
time_t last_activity_TS ; // updated everytime a node or one of its former identities is required
|
||||
std::set<RsGxsId> known_identities ; // list of known identities from this node. This is kept for a while, and useful in order to avoid re-asking these keys.
|
||||
};
|
||||
|
||||
class Reputation
|
||||
{
|
||||
public:
|
||||
@ -77,7 +83,7 @@ public:
|
||||
float mFriendAverage ;
|
||||
float mReputation;
|
||||
|
||||
RsPgpId mOwnerNode;
|
||||
RsPgpId mOwnerNode;
|
||||
|
||||
uint32_t mIdentityFlags;
|
||||
};
|
||||
@ -97,11 +103,15 @@ public:
|
||||
|
||||
/***** Interface for RsReputations *****/
|
||||
virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) ;
|
||||
virtual bool getReputationInfo(const RsGxsId& id, const RsPgpId &owner_id, ReputationInfo& info) ;
|
||||
virtual bool isIdentityBanned(const RsGxsId& id, const RsPgpId &owner_node) ;
|
||||
virtual bool getReputationInfo(const RsGxsId& id, const RsPgpId &ownerNode, ReputationInfo& info) ;
|
||||
virtual bool isIdentityBanned(const RsGxsId& id) ;
|
||||
|
||||
virtual bool isNodeBanned(const RsPgpId& id);
|
||||
virtual void banNode(const RsPgpId& id,bool b) ;
|
||||
|
||||
//virtual void setNodeAutoBanThreshold(uint32_t n) ;
|
||||
//virtual uint32_t nodeAutoBanThreshold() ;
|
||||
|
||||
virtual void setNodeAutoBanThreshold(uint32_t n) ;
|
||||
virtual uint32_t nodeAutoBanThreshold() ;
|
||||
virtual void setNodeAutoPositiveOpinionForContacts(bool b) ;
|
||||
virtual bool nodeAutoPositiveOpinionForContacts() ;
|
||||
virtual float nodeAutoBanIdentitiesLimit() ;
|
||||
@ -129,7 +139,8 @@ private:
|
||||
bool RecvReputations(RsGxsReputationUpdateItem *item);
|
||||
bool updateLatestUpdate(RsPeerId peerid, time_t latest_update);
|
||||
void updateActiveFriends() ;
|
||||
void updateBannedNodesList();
|
||||
|
||||
void updateBannedNodesProxy();
|
||||
|
||||
// internal update of data. Takes care of cleaning empty boxes.
|
||||
void locked_updateOpinion(const RsPeerId &from, const RsGxsId &about, RsReputations::Opinion op);
|
||||
@ -167,8 +178,10 @@ private:
|
||||
std::set<RsGxsId> mUpdatedReputations;
|
||||
|
||||
// PGP Ids auto-banned. This is updated regularly.
|
||||
std::set<RsPgpId> mBannedPgpIds ;
|
||||
uint32_t mPgpAutoBanThreshold ;
|
||||
std::map<RsPgpId,BannedNodeInfo> mBannedPgpIds ;
|
||||
std::set<RsGxsId> mPerNodeBannedIdsProxy ;
|
||||
//uint32_t mPgpAutoBanThreshold ;
|
||||
bool mBannedNodesProxyNeedsUpdate ;
|
||||
};
|
||||
|
||||
#endif //SERVICE_RSGXSREPUTATION_HEADER
|
||||
|
@ -51,16 +51,16 @@
|
||||
* #define GXSID_GEN_DUMMY_DATA 1
|
||||
****/
|
||||
|
||||
#define ID_REQUEST_LIST 0x0001
|
||||
#define ID_REQUEST_IDENTITY 0x0002
|
||||
#define ID_REQUEST_LIST 0x0001
|
||||
#define ID_REQUEST_IDENTITY 0x0002
|
||||
#define ID_REQUEST_REPUTATION 0x0003
|
||||
#define ID_REQUEST_OPINION 0x0004
|
||||
#define ID_REQUEST_OPINION 0x0004
|
||||
|
||||
#define GXSID_MAX_CACHE_SIZE 5000
|
||||
|
||||
// unused keys are deleted according to some heuristic that should favor known keys, signed keys etc.
|
||||
|
||||
static const time_t MAX_KEEP_KEYS_BANNED = 2 * 86400 ; // get rid of banned ids after 2 days. That gives a chance to un-ban someone before he gets kicked out
|
||||
static const time_t MAX_KEEP_KEYS_BANNED = 2 * 86400 ; // get rid of banned ids after 1 days. That gives a chance to un-ban someone before he gets definitely kicked out
|
||||
static const time_t MAX_KEEP_KEYS_DEFAULT = 5 * 86400 ; // default for unsigned identities: 5 days
|
||||
static const time_t MAX_KEEP_KEYS_SIGNED = 8 * 86400 ; // signed identities by unknown key
|
||||
static const time_t MAX_KEEP_KEYS_SIGNED_KNOWN = 30 * 86400 ; // signed identities by known node keys
|
||||
@ -264,10 +264,10 @@ time_t p3IdService::locked_getLastUsageTS(const RsGxsId& gxs_id)
|
||||
}
|
||||
void p3IdService::timeStampKey(const RsGxsId& gxs_id)
|
||||
{
|
||||
if(isBanned(gxs_id))
|
||||
if(rsReputations->isIdentityBanned(gxs_id) )
|
||||
{
|
||||
std::cerr << "(II) p3IdService:timeStampKey(): refusing to time stamp key " << gxs_id << " because it is banned." << std::endl;
|
||||
return;
|
||||
return ;
|
||||
}
|
||||
|
||||
RS_STACK_MUTEX(mIdMtx) ;
|
||||
@ -324,7 +324,7 @@ public:
|
||||
time_t now = time(NULL);
|
||||
const RsGxsId& gxs_id = entry.details.mId ;
|
||||
|
||||
bool is_id_banned = rsReputations->isIdentityBanned(gxs_id,entry.details.mPgpId) ;
|
||||
bool is_id_banned = rsReputations->isIdentityBanned(gxs_id) ;
|
||||
bool is_own_id = (bool)(entry.details.mFlags & RS_IDENTITY_FLAGS_IS_OWN_ID) ;
|
||||
bool is_known_id = (bool)(entry.details.mFlags & RS_IDENTITY_FLAGS_PGP_KNOWN) ;
|
||||
bool is_signed_id = (bool)(entry.details.mFlags & RS_IDENTITY_FLAGS_PGP_LINKED) ;
|
||||
@ -430,6 +430,15 @@ void p3IdService::service_tick()
|
||||
return;
|
||||
}
|
||||
|
||||
bool p3IdService::acceptNewGroup(const RsGxsGrpMetaData *grpMeta)
|
||||
{
|
||||
bool res = !rsReputations->isIdentityBanned(RsGxsId(grpMeta->mGroupId)) ;
|
||||
|
||||
std::cerr << "p3IdService::acceptNewGroup: ID=" << grpMeta->mGroupId << ": " << (res?"ACCEPTED":"DENIED") << std::endl;
|
||||
|
||||
return res ;
|
||||
}
|
||||
|
||||
void p3IdService::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||
{
|
||||
#ifdef DEBUG_IDS
|
||||
@ -440,11 +449,11 @@ void p3IdService::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||
/* iterate through and grab any new messages */
|
||||
std::list<RsGxsGroupId> unprocessedGroups;
|
||||
|
||||
std::vector<RsGxsNotify *>::iterator it;
|
||||
for(it = changes.begin(); it != changes.end(); ++it)
|
||||
for(uint32_t i = 0;i<changes.size();++i)
|
||||
{
|
||||
RsGxsGroupChange *groupChange = dynamic_cast<RsGxsGroupChange *>(*it);
|
||||
RsGxsMsgChange *msgChange = dynamic_cast<RsGxsMsgChange *>(*it);
|
||||
RsGxsGroupChange *groupChange = dynamic_cast<RsGxsGroupChange *>(changes[i]);
|
||||
RsGxsMsgChange *msgChange = dynamic_cast<RsGxsMsgChange *>(changes[i]);
|
||||
|
||||
if (msgChange && !msgChange->metaChange())
|
||||
{
|
||||
#ifdef DEBUG_IDS
|
||||
@ -470,23 +479,34 @@ void p3IdService::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||
std::cerr << "p3IdService::notifyChanges() Found Group Change Notification";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
std::list<RsGxsGroupId> &groupList = groupChange->mGrpIdList;
|
||||
std::list<RsGxsGroupId>::iterator git;
|
||||
for(git = groupList.begin(); git != groupList.end(); ++git)
|
||||
|
||||
for(git = groupList.begin(); git != groupList.end();)
|
||||
{
|
||||
#ifdef DEBUG_IDS
|
||||
std::cerr << "p3IdService::notifyChanges() Auto Subscribe to Incoming Groups: " << *git;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
if(!rsReputations->isIdentityBanned(RsGxsId(*git)))
|
||||
{
|
||||
uint32_t token;
|
||||
RsGenExchange::subscribeToGroup(token, *git, true);
|
||||
|
||||
uint32_t token;
|
||||
RsGenExchange::subscribeToGroup(token, *git, true);
|
||||
// also time_stamp the key that this group represents
|
||||
|
||||
// also time_stamp the key that this group represents
|
||||
timeStampKey(RsGxsId(*git)) ;
|
||||
|
||||
std::cerr << "(II) time-stamping new received GXS ID " << *git << std::endl;
|
||||
timeStampKey(RsGxsId(*git)) ;
|
||||
++git;
|
||||
}
|
||||
else
|
||||
git = groupList.erase(git) ;
|
||||
}
|
||||
|
||||
if(groupList.empty())
|
||||
{
|
||||
delete changes[i] ;
|
||||
changes[i] = NULL ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -525,6 +545,12 @@ bool p3IdService::getIdDetails(const RsGxsId &id, RsIdentityDetails &details)
|
||||
|
||||
if (mKeyCache.fetch(id, data))
|
||||
{
|
||||
// This step is needed, because p3GxsReputation does not know all identities, and might not have any data for
|
||||
// the ones in the contact list. So we change them on demand.
|
||||
|
||||
if(mContacts.find(id) != mContacts.end() && rsReputations->nodeAutoPositiveOpinionForContacts())
|
||||
rsReputations->setOwnOpinion(id,RsReputations::OPINION_POSITIVE) ;
|
||||
|
||||
details = data.details;
|
||||
details.mLastUsageTS = locked_getLastUsageTS(id) ;
|
||||
|
||||
@ -739,6 +765,25 @@ bool p3IdService::requestKey(const RsGxsId &id, const std::list<RsPeerId>& peers
|
||||
return true;
|
||||
else
|
||||
{
|
||||
// Normally we should call getIdDetails(), but since the key is not known, we need to digg a possibly old information
|
||||
// from the reputation system, which keeps its own list of banned keys. Of course, the owner ID is not known at this point.
|
||||
|
||||
std::cerr << "p3IdService::requesting key " << id <<std::endl;
|
||||
|
||||
RsReputations::ReputationInfo info ;
|
||||
rsReputations->getReputationInfo(id,RsPgpId(),info) ;
|
||||
|
||||
if(info.mAssessment == RsReputations::ASSESSMENT_BAD)
|
||||
{
|
||||
std::cerr << "(II) not requesting Key " << id << " because it has been banned." << std::endl;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
|
||||
mIdsNotPresent.erase(id) ;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<RsGxsId,std::list<RsPeerId> >::iterator rit = mIdsNotPresent.find(id) ;
|
||||
|
@ -317,7 +317,10 @@ protected:
|
||||
/** Overloaded to add PgpIdHash to Group Definition **/
|
||||
virtual ServiceCreate_Return service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet);
|
||||
|
||||
// Overloaded from GxsTokenQueue for Request callbacks.
|
||||
// Overloads RsGxsGenExchange
|
||||
virtual bool acceptNewGroup(const RsGxsGrpMetaData *grpMeta) ;
|
||||
|
||||
// Overloaded from GxsTokenQueue for Request callbacks.
|
||||
virtual void handleResponse(uint32_t token, uint32_t req_type);
|
||||
|
||||
// Overloaded from RsTickEvent.
|
||||
|
@ -333,6 +333,7 @@ IdDialog::IdDialog(QWidget *parent) :
|
||||
|
||||
//connect(ui->treeWidget_membership, SIGNAL(itemSelectionChanged()), this, SLOT(circle_selected()));
|
||||
connect(ui->treeWidget_membership, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(CircleListCustomPopupMenu(QPoint)));
|
||||
connect(ui->autoBanIdentities_CB, SIGNAL(toggled(bool)), this, SLOT(toggleAutoBanIdentities(bool)));
|
||||
|
||||
|
||||
/* Setup TokenQueue */
|
||||
@ -349,6 +350,17 @@ IdDialog::IdDialog(QWidget *parent) :
|
||||
tmer->start(10000) ; // update every 10 secs.
|
||||
}
|
||||
|
||||
void IdDialog::toggleAutoBanIdentities(bool b)
|
||||
{
|
||||
RsPgpId id(ui->lineEdit_GpgId->text().left(16).toStdString());
|
||||
|
||||
if(!id.isNull())
|
||||
{
|
||||
rsReputations->banNode(id,b) ;
|
||||
requestIdList();
|
||||
}
|
||||
}
|
||||
|
||||
void IdDialog::updateCirclesDisplay()
|
||||
{
|
||||
if(RsAutoUpdatePage::eventsLocked())
|
||||
@ -1676,6 +1688,8 @@ void IdDialog::insertIdDetails(uint32_t token)
|
||||
else
|
||||
ui->lineEdit_GpgId->setText(QString::fromStdString(data.mPgpId.toStdString()) + tr(" [unverified]"));
|
||||
|
||||
ui->autoBanIdentities_CB->setVisible(!data.mPgpId.isNull()) ;
|
||||
|
||||
time_t now = time(NULL) ;
|
||||
ui->lineEdit_LastUsed->setText(getHumanReadableDuration(now - data.mLastUsageTS)) ;
|
||||
ui->headerTextLabel_Person->setText(QString::fromUtf8(data.mMeta.mGroupName.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE));
|
||||
@ -1769,6 +1783,8 @@ void IdDialog::insertIdDetails(uint32_t token)
|
||||
ui->inviteButton->setEnabled(true);
|
||||
}
|
||||
|
||||
ui->autoBanIdentities_CB->setChecked(rsReputations->isNodeBanned(data.mPgpId));
|
||||
|
||||
/* now fill in the reputation information */
|
||||
|
||||
#ifdef SUSPENDED
|
||||
|
@ -77,6 +77,7 @@ private slots:
|
||||
void createExternalCircle();
|
||||
void showEditExistingCircle();
|
||||
void updateCirclesDisplay();
|
||||
void toggleAutoBanIdentities(bool b);
|
||||
|
||||
void acceptCircleSubscription() ;
|
||||
void cancelCircleSubscription() ;
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
<height>872</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@ -117,7 +117,7 @@
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../images.qrc">
|
||||
<iconset resource="../icons.qrc">
|
||||
<normaloff>:/icons/help_64.png</normaloff>:/icons/help_64.png</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
@ -278,7 +278,7 @@
|
||||
<string>Reputation</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignLeading|AlignVCenter</set>
|
||||
<set>AlignLeft|AlignVCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
@ -534,6 +534,13 @@
|
||||
<string>Reputation</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="reputationGroupBoxVLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="autoBanIdentities_CB">
|
||||
<property name="text">
|
||||
<string>Auto-Ban all identities from this node</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="reputationGLayout">
|
||||
<property name="leftMargin">
|
||||
@ -806,8 +813,8 @@ p, li { white-space: pre-wrap; }
|
||||
<tabstop>idTreeWidget</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../images.qrc"/>
|
||||
<include location="../icons.qrc"/>
|
||||
<include location="../images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -37,11 +37,6 @@ PeoplePage::~PeoplePage()
|
||||
/** Saves the changes on this page */
|
||||
bool PeoplePage::save(QString &/*errmsg*/)
|
||||
{
|
||||
if(!ui.identityBan_CB->isChecked())
|
||||
rsReputations->setNodeAutoBanThreshold(0) ;
|
||||
else
|
||||
rsReputations->setNodeAutoBanThreshold(ui.identityBanThreshold_SB->value()) ;
|
||||
|
||||
if(ui.autoPositiveOpinion_CB->isChecked())
|
||||
rsReputations->setNodeAutoPositiveOpinionForContacts(true) ;
|
||||
else
|
||||
@ -55,12 +50,9 @@ bool PeoplePage::save(QString &/*errmsg*/)
|
||||
/** Loads the settings for this page */
|
||||
void PeoplePage::load()
|
||||
{
|
||||
uint32_t ban_limit = rsReputations->nodeAutoBanThreshold() ;
|
||||
bool auto_positive_contacts = rsReputations->nodeAutoPositiveOpinionForContacts() ;
|
||||
float node_auto_ban_identities_limit = rsReputations->nodeAutoBanIdentitiesLimit();
|
||||
|
||||
ui.identityBan_CB->setChecked(ban_limit > 0) ;
|
||||
ui.identityBanThreshold_SB->setValue(ban_limit) ;
|
||||
ui.autoPositiveOpinion_CB->setChecked(auto_positive_contacts);
|
||||
ui.autoBanIdentitiesLimit_SB->setValue(node_auto_ban_identities_limit);
|
||||
}
|
||||
|
@ -17,50 +17,6 @@
|
||||
<string>Identities handling</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="identityBan_CB">
|
||||
<property name="text">
|
||||
<string>ban all identities of a node when more than</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="identityBanThreshold_SB">
|
||||
<property name="maximum">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>2</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string> of them have a negative opinion</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="autoPositiveOpinion_CB">
|
||||
<property name="toolTip">
|
||||
|
Loading…
x
Reference in New Issue
Block a user