mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-03-19 05:26:07 -04:00
almost done with load/save of BanLists. Changed the item format to include masked_bytes, and changed subitem types. Also disabled code from rsgxsreputationitems.cc wich was a copy of the code from rsbanlistitems.cc
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8316 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
4ebc87b9c2
commit
20a2d42038
@ -1420,10 +1420,10 @@ void RsGenExchange::notifyNewGroups(std::vector<RsNxsGrp *> &groups)
|
||||
// TODO: move this to nxs layer to save bandwidth
|
||||
if(received == mReceivedGrps.end())
|
||||
{
|
||||
//#ifdef GEN_EXCH_DEBUG
|
||||
#ifdef GEN_EXCH_DEBUG
|
||||
std::cerr << "RsGenExchange::notifyNewGroups() Received GrpId: " << grp->grpId;
|
||||
std::cerr << std::endl;
|
||||
//#endif
|
||||
#endif
|
||||
|
||||
GxsPendingItem<RsNxsGrp*, RsGxsGroupId> gpsi(grp, grp->grpId);
|
||||
mReceivedGrps.push_back(gpsi);
|
||||
|
@ -40,11 +40,15 @@ extern RsBanList *rsBanList ;
|
||||
#define RSBANLIST_REASON_DHT 2
|
||||
#define RSBANLIST_REASON_AUTO_RANGE 3
|
||||
|
||||
class RsTlvBanListEntry ;
|
||||
|
||||
class BanListPeer
|
||||
{
|
||||
public:
|
||||
BanListPeer() ;
|
||||
|
||||
void toRsTlvBanListEntry(RsTlvBanListEntry& e) const ;
|
||||
void fromRsTlvBanListEntry(const RsTlvBanListEntry& e) ;
|
||||
|
||||
struct sockaddr_storage addr;
|
||||
uint8_t masked_bytes ; // 0 = []/32. 1=[]/24, 2=[]/16
|
||||
|
@ -64,6 +64,15 @@ uint32_t RsBanListSerialiser::sizeList(RsBanListItem *item)
|
||||
return s;
|
||||
}
|
||||
|
||||
uint32_t RsBanListSerialiser::sizeListConfig(RsBanListConfigItem *item)
|
||||
{
|
||||
uint32_t s = 8; /* header */
|
||||
s += item->banned_peers.TlvSize();
|
||||
s += 8 ; // update time
|
||||
s += item->peerId.serial_size() ;
|
||||
|
||||
return s;
|
||||
}
|
||||
/* serialise the data to the buffer */
|
||||
bool RsBanListSerialiser::serialiseList(RsBanListItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
@ -100,8 +109,95 @@ bool RsBanListSerialiser::serialiseList(RsBanListItem *item, void *data, uin
|
||||
|
||||
return ok;
|
||||
}
|
||||
/* serialise the data to the buffer */
|
||||
bool RsBanListSerialiser::serialiseListConfig(RsBanListConfigItem *item, void *data, uint32_t *pktsize)
|
||||
{
|
||||
uint32_t tlvsize = sizeListConfig(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);
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsBanListSerialiser::serialiseRoute() Header: " << ok << std::endl;
|
||||
std::cerr << "RsBanListSerialiser::serialiseRoute() Size: " << tlvsize << std::endl;
|
||||
#endif
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= item->peerId.serialise(data, tlvsize, offset);
|
||||
ok &= setRawTimeT(data, tlvsize, &offset,item->update_time);
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->banned_peers.SetTlv(data, tlvsize, &offset);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsBanListSerialiser::serialiseRoute() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
RsBanListItem *RsBanListSerialiser::deserialiseList(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
uint32_t tlvsize = getRsItemSize(data);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_BANLIST != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_BANLIST_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
if (*pktsize < tlvsize) /* check size */
|
||||
return NULL; /* not enough data */
|
||||
|
||||
/* set the packet length */
|
||||
*pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsBanListItem *item = new RsBanListItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->peerList.GetTlv(data, tlvsize, &offset);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
/* error */
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
delete item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
RsBanListConfigItem *RsBanListSerialiser::deserialiseListConfig(void *data, uint32_t *pktsize)
|
||||
{
|
||||
/* get the type and size */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
@ -112,7 +208,7 @@ RsBanListItem *RsBanListSerialiser::deserialiseList(void *data, uint32_t *pktsiz
|
||||
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
|
||||
(RS_SERVICE_TYPE_BANLIST != getRsItemService(rstype)) ||
|
||||
(RS_PKT_SUBTYPE_BANLIST_ITEM != getRsItemSubType(rstype)))
|
||||
(RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM != getRsItemSubType(rstype)))
|
||||
{
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
@ -126,14 +222,17 @@ RsBanListItem *RsBanListSerialiser::deserialiseList(void *data, uint32_t *pktsiz
|
||||
bool ok = true;
|
||||
|
||||
/* ready to load */
|
||||
RsBanListItem *item = new RsBanListItem();
|
||||
RsBanListConfigItem *item = new RsBanListConfigItem();
|
||||
item->clear();
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->peerList.GetTlv(data, tlvsize, &offset);
|
||||
ok &= item->peerId.deserialise(data, tlvsize, offset);
|
||||
ok &= getRawTimeT(data, tlvsize, &offset,item->update_time);
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= item->banned_peers.GetTlv(data, tlvsize, &offset);
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
@ -156,23 +255,34 @@ RsBanListItem *RsBanListSerialiser::deserialiseList(void *data, uint32_t *pktsiz
|
||||
uint32_t RsBanListSerialiser::size(RsItem *i)
|
||||
{
|
||||
RsBanListItem *dri;
|
||||
RsBanListConfigItem *drc;
|
||||
|
||||
if (NULL != (dri = dynamic_cast<RsBanListItem *>(i)))
|
||||
{
|
||||
return sizeList(dri);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (NULL != (drc = dynamic_cast<RsBanListConfigItem *>(i)))
|
||||
{
|
||||
return sizeListConfig(drc);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsBanListSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
|
||||
{
|
||||
RsBanListItem *dri;
|
||||
RsBanListConfigItem *drc;
|
||||
|
||||
if (NULL != (dri = dynamic_cast<RsBanListItem *>(i)))
|
||||
if (NULL != (dri = dynamic_cast<RsBanListItem *>(i)))
|
||||
{
|
||||
return serialiseList(dri, data, pktsize);
|
||||
}
|
||||
return false;
|
||||
if (NULL != (drc = dynamic_cast<RsBanListConfigItem *>(i)))
|
||||
{
|
||||
return serialiseListConfig(drc, data, pktsize);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RsItem *RsBanListSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
@ -191,10 +301,28 @@ RsItem *RsBanListSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
case RS_PKT_SUBTYPE_BANLIST_ITEM:
|
||||
return deserialiseList(data, pktsize);
|
||||
break;
|
||||
default:
|
||||
case RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM:
|
||||
return deserialiseListConfig(data, pktsize);
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RsBanListConfigItem::clear()
|
||||
{
|
||||
banned_peers.TlvClear() ;
|
||||
}
|
||||
|
||||
std::ostream &RsBanListConfigItem::print(std::ostream &out, uint16_t indent)
|
||||
{
|
||||
printRsItemBase(out, "RsBanListConfigItem", indent);
|
||||
uint16_t int_Indent = indent + 2;
|
||||
banned_peers.print(out, int_Indent);
|
||||
|
||||
printRsItemEnd(out, "RsBanListConfigItem", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
@ -32,7 +32,9 @@
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvbanlist.h"
|
||||
|
||||
#define RS_PKT_SUBTYPE_BANLIST_ITEM 0x01
|
||||
#define RS_PKT_SUBTYPE_BANLIST_ITEM_deprecated 0x01
|
||||
#define RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM 0x02
|
||||
#define RS_PKT_SUBTYPE_BANLIST_ITEM 0x03
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
@ -47,33 +49,51 @@ class RsBanListItem: public RsItem
|
||||
return;
|
||||
}
|
||||
|
||||
virtual ~RsBanListItem();
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
virtual ~RsBanListItem();
|
||||
virtual void clear();
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsTlvBanList peerList;
|
||||
|
||||
};
|
||||
|
||||
class RsBanListConfigItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsBanListConfigItem()
|
||||
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BANLIST, RS_PKT_SUBTYPE_BANLIST_CONFIG_ITEM) {}
|
||||
|
||||
virtual ~RsBanListConfigItem(){}
|
||||
virtual void clear();
|
||||
|
||||
std::ostream &print(std::ostream &out, uint16_t indent = 0);
|
||||
|
||||
RsPeerId peerId ;
|
||||
time_t update_time ;
|
||||
RsTlvBanList banned_peers;
|
||||
};
|
||||
|
||||
class RsBanListSerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsBanListSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BANLIST)
|
||||
{ return; }
|
||||
virtual ~RsBanListSerialiser()
|
||||
{ return; }
|
||||
|
||||
virtual uint32_t size(RsItem *);
|
||||
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
virtual RsItem * deserialise(void *data, uint32_t *size);
|
||||
public:
|
||||
RsBanListSerialiser()
|
||||
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_BANLIST)
|
||||
{ return; }
|
||||
virtual ~RsBanListSerialiser()
|
||||
{ return; }
|
||||
|
||||
private:
|
||||
virtual uint32_t size(RsItem *);
|
||||
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
|
||||
virtual RsItem * deserialise(void *data, uint32_t *size);
|
||||
|
||||
virtual uint32_t sizeList(RsBanListItem *);
|
||||
virtual bool serialiseList (RsBanListItem *item, void *data, uint32_t *size);
|
||||
virtual RsBanListItem *deserialiseList(void *data, uint32_t *size);
|
||||
private:
|
||||
|
||||
virtual uint32_t sizeList(RsBanListItem *);
|
||||
virtual bool serialiseList (RsBanListItem *item, void *data, uint32_t *size);
|
||||
virtual RsBanListItem *deserialiseList(void *data, uint32_t *size);
|
||||
|
||||
virtual uint32_t sizeListConfig(RsBanListConfigItem *);
|
||||
virtual bool serialiseListConfig (RsBanListConfigItem *item, void *data, uint32_t *size);
|
||||
virtual RsBanListConfigItem *deserialiseListConfig(void *data, uint32_t *size);
|
||||
|
||||
|
||||
};
|
||||
|
@ -35,6 +35,7 @@
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef SUSPENDED
|
||||
RsBanListItem::~RsBanListItem()
|
||||
{
|
||||
return;
|
||||
@ -197,6 +198,7 @@ RsItem *RsBanListSerialiser::deserialise(void *data, uint32_t *pktsize)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
|
@ -54,6 +54,7 @@ uint32_t RsTlvBanListEntry::TlvSize() const
|
||||
s += 4; // level;
|
||||
s += 4; // reason;
|
||||
s += 4; // age;
|
||||
s += 1; // masked_bytes;
|
||||
|
||||
return s;
|
||||
|
||||
@ -79,7 +80,9 @@ bool RsTlvBanListEntry::SetTlv(void *data, uint32_t size, uint32_t *offset) con
|
||||
ok &= setRawUInt32(data, tlvend, offset, level);
|
||||
ok &= setRawUInt32(data, tlvend, offset, reason);
|
||||
ok &= setRawUInt32(data, tlvend, offset, age);
|
||||
return ok;
|
||||
ok &= setRawUInt8(data, tlvend, offset, masked_bytes);
|
||||
|
||||
return ok;
|
||||
|
||||
}
|
||||
|
||||
@ -110,7 +113,11 @@ bool RsTlvBanListEntry::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
||||
ok &= addr.GetTlv(data, tlvend, offset);
|
||||
ok &= getRawUInt32(data, tlvend, offset, &(level));
|
||||
ok &= getRawUInt32(data, tlvend, offset, &(reason));
|
||||
ok &= getRawUInt32(data, tlvend, offset, &(age));
|
||||
ok &= getRawUInt32(data, tlvend, offset, &(age));
|
||||
|
||||
uint8_t tmp ;
|
||||
ok &= getRawUInt8(data, tlvend, offset, &(tmp));
|
||||
masked_bytes = tmp ;
|
||||
|
||||
/***************************************************************************
|
||||
* NB: extra components could be added (for future expansion of the type).
|
||||
@ -153,8 +160,13 @@ std::ostream &RsTlvBanListEntry::print(std::ostream &out, uint16_t indent) const
|
||||
out << "age:" << age;
|
||||
out << std::endl;
|
||||
|
||||
printEnd(out, "RsTlvBanListEntry", indent);
|
||||
return out;
|
||||
printIndent(out, int_Indent);
|
||||
out << "masked bytes:" << masked_bytes;
|
||||
out << std::endl;
|
||||
|
||||
printEnd(out, "RsTlvBanListEntry", indent);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -54,7 +54,6 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
|
||||
uint8_t masked_bytes ;
|
||||
};
|
||||
|
||||
|
||||
typedef t_RsTlvList<RsTlvBanListEntry,TLV_TYPE_BAN_LIST> RsTlvBanList;
|
||||
|
||||
|
||||
|
@ -25,11 +25,13 @@
|
||||
|
||||
#include "pqi/p3servicecontrol.h"
|
||||
#include "pqi/p3netmgr.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
|
||||
#include "util/rsnet.h"
|
||||
|
||||
#include "services/p3banlist.h"
|
||||
#include "serialiser/rsbanlistitems.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "retroshare/rsdht.h"
|
||||
|
||||
#include <sys/time.h>
|
||||
@ -129,6 +131,27 @@ BanListPeer::BanListPeer()
|
||||
mTs=0;
|
||||
}
|
||||
|
||||
void BanListPeer::toRsTlvBanListEntry(RsTlvBanListEntry &e) const
|
||||
{
|
||||
e.addr.addr = addr;
|
||||
e.level = level;
|
||||
e.reason = reason;
|
||||
e.masked_bytes = masked_bytes;
|
||||
e.age = time(NULL) - mTs;
|
||||
}
|
||||
|
||||
void BanListPeer::fromRsTlvBanListEntry(const RsTlvBanListEntry &e)
|
||||
{
|
||||
addr = e.addr.addr;
|
||||
masked_bytes = e.masked_bytes; // 0 = []/32. 1=[]/24, 2=[]/16
|
||||
reason = e.reason; // User, DHT
|
||||
level = e.level; // LOCAL, FRIEND, FoF.
|
||||
state = true; // true=>active, false=>just stored but inactive
|
||||
connect_attempts = 0; // recorded by the BanList service
|
||||
mTs = time(NULL) - e.age;
|
||||
comment.clear() ; //
|
||||
}
|
||||
|
||||
static sockaddr_storage makeBitsRange(const sockaddr_storage& addr,int masked_bytes)
|
||||
{
|
||||
sockaddr_storage s ;
|
||||
@ -166,8 +189,9 @@ void p3BanList::autoFigureOutBanRanges()
|
||||
|
||||
if(!mAutoRangeIps)
|
||||
return ;
|
||||
|
||||
#ifdef DEBUG_BANLIST
|
||||
std::cerr << "Automatically figuring out IP ranges from banned IPs." << std::endl;
|
||||
#endif
|
||||
|
||||
std::map<sockaddr_storage,ZeroedInt> range_map ;
|
||||
|
||||
@ -178,11 +202,15 @@ void p3BanList::autoFigureOutBanRanges()
|
||||
|
||||
for(std::map<sockaddr_storage,ZeroedInt>::const_iterator it=range_map.begin();it!=range_map.end();++it)
|
||||
{
|
||||
#ifdef DEBUG_BANLIST
|
||||
std::cerr << "Ban range: " << sockaddr_storage_iptostring(it->first) << " : " << it->second.n << std::endl;
|
||||
#endif
|
||||
|
||||
if(it->second.n >= mAutoRangeLimit)
|
||||
{
|
||||
#ifdef DEBUG_BANLIST
|
||||
std::cerr << " --> creating new ban range." << std::endl;
|
||||
#endif
|
||||
BanListPeer& peer(mBanRanges[it->first]) ;
|
||||
|
||||
if(peer.reason == RSBANLIST_REASON_USER)
|
||||
@ -212,32 +240,42 @@ bool p3BanList::isAddressAccepted(const sockaddr_storage &addr)
|
||||
sockaddr_storage addr_24 = makeBitsRange(addr,1) ;
|
||||
sockaddr_storage addr_16 = makeBitsRange(addr,2) ;
|
||||
|
||||
#ifdef DEBUG_BANLIST
|
||||
std::cerr << "p3BanList::isAddressAccepted() testing " << sockaddr_storage_iptostring(addr) << " and range " << sockaddr_storage_iptostring(addr_24) ;
|
||||
#endif
|
||||
|
||||
std::map<sockaddr_storage,BanListPeer>::iterator it ;
|
||||
|
||||
if((it=mBanRanges.find(addr_16)) != mBanRanges.end())
|
||||
{
|
||||
++it->second.connect_attempts;
|
||||
#ifdef DEBUG_BANLIST
|
||||
std::cerr << " returning false. attempts=" << it->second.connect_attempts << std::endl;
|
||||
#endif
|
||||
return false ;
|
||||
}
|
||||
|
||||
if((it=mBanRanges.find(addr_24)) != mBanRanges.end())
|
||||
{
|
||||
++it->second.connect_attempts;
|
||||
#ifdef DEBUG_BANLIST
|
||||
std::cerr << " returning false. attempts=" << it->second.connect_attempts << std::endl;
|
||||
#endif
|
||||
return false ;
|
||||
}
|
||||
|
||||
if((it=mBanSet.find(addr)) != mBanSet.end())
|
||||
{
|
||||
++it->second.connect_attempts;
|
||||
#ifdef DEBUG_BANLIST
|
||||
std::cerr << " returning false. attempts=" << it->second.connect_attempts << std::endl;
|
||||
#endif
|
||||
return false ;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_BANLIST
|
||||
std::cerr << " returning true " << std::endl;
|
||||
#endif
|
||||
return true ;
|
||||
}
|
||||
|
||||
@ -313,12 +351,16 @@ void p3BanList::getDhtInfo()
|
||||
|
||||
rsDht->getListOfBannedIps(filtered_peers) ;
|
||||
|
||||
#ifdef DEBUG_BANLIST
|
||||
std::cerr << "p3BanList::getDhtInfo() Got list of banned IPs." << std::endl;
|
||||
#endif
|
||||
RsPeerId ownId = mServiceCtrl->getOwnId();
|
||||
|
||||
for(std::list<RsDhtFilteredPeer>::const_iterator it(filtered_peers.begin());it!=filtered_peers.end();++it)
|
||||
{
|
||||
#ifdef DEBUG_BANLIST
|
||||
std::cerr << " filtered peer: " << rs_inet_ntoa((*it).mAddr.sin_addr) << std::endl;
|
||||
#endif
|
||||
|
||||
int int_reason = RSBANLIST_REASON_DHT ;
|
||||
int time_stamp = (*it).mLastSeen ;
|
||||
@ -386,8 +428,8 @@ bool p3BanList::recvBanItem(RsBanListItem *item)
|
||||
bool updated = false;
|
||||
|
||||
time_t now = time(NULL) ;
|
||||
std::list<RsTlvBanListEntry>::const_iterator it;
|
||||
//for(it = item->peerList.entries.begin(); it != item->peerList.entries.end(); ++it)
|
||||
std::list<RsTlvBanListEntry>::const_iterator it;
|
||||
|
||||
for(it = item->peerList.mList.begin(); it != item->peerList.mList.end(); ++it)
|
||||
{
|
||||
// Order is important!.
|
||||
@ -413,6 +455,108 @@ void p3BanList::updatePeer(const RsPeerId& /*id*/, const struct sockaddr_storage
|
||||
}
|
||||
}
|
||||
|
||||
RsSerialiser *p3BanList::setupSerialiser()
|
||||
{
|
||||
RsSerialiser *rss = new RsSerialiser ;
|
||||
|
||||
rss->addSerialType(new RsBanListSerialiser()) ;
|
||||
rss->addSerialType(new RsGeneralConfigSerialiser());
|
||||
|
||||
return rss ;
|
||||
}
|
||||
|
||||
bool p3BanList::saveList(bool &cleanup, std::list<RsItem*>& itemlist)
|
||||
{
|
||||
RsStackMutex stack(mBanMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
cleanup = true ;
|
||||
|
||||
for(std::map<RsPeerId,BanList>::const_iterator it(mBanSources.begin());it!=mBanSources.end();++it)
|
||||
{
|
||||
RsBanListConfigItem *item = new RsBanListConfigItem ;
|
||||
|
||||
item->peerId = it->second.mPeerId ;
|
||||
item->update_time = it->second.mLastUpdate ;
|
||||
item->banned_peers.TlvClear() ;
|
||||
|
||||
for(std::map<sockaddr_storage,BanListPeer>::const_iterator it2 = it->second.mBanPeers.begin();it2!=it->second.mBanPeers.end();++it2)
|
||||
{
|
||||
RsTlvBanListEntry e ;
|
||||
it2->second.toRsTlvBanListEntry(e) ;
|
||||
|
||||
item->banned_peers.mList.push_back(e) ;
|
||||
}
|
||||
|
||||
itemlist.push_back(item) ;
|
||||
}
|
||||
|
||||
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
||||
|
||||
RsTlvKeyValue kv;
|
||||
|
||||
kv.key = "IP_FILTERING_ENABLED";
|
||||
kv.value = mIPFilteringEnabled?"TRUE":"FALSE" ;
|
||||
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
kv.key = "IP_FILTERING_AUTORANGE_IPS";
|
||||
kv.value = mAutoRangeIps?"TRUE":"FALSE" ;
|
||||
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
kv.key = "IP_FILTERING_FRIEND_GATHERING_ENABLED";
|
||||
kv.value = mIPFriendGatheringEnabled?"TRUE":"FALSE" ;
|
||||
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
kv.key = "IP_FILTERING_DHT_GATHERING_ENABLED";
|
||||
kv.value = mIPDHTGatheringEnabled?"TRUE":"FALSE" ;
|
||||
vitem->tlvkvs.pairs.push_back(kv) ;
|
||||
|
||||
itemlist.push_back(vitem) ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool p3BanList::loadList(std::list<RsItem*>& load)
|
||||
{
|
||||
RsStackMutex stack(mBanMtx); /****** LOCKED MUTEX *******/
|
||||
|
||||
for(std::list<RsItem*>::const_iterator it(load.begin());it!=load.end();++it)
|
||||
{
|
||||
RsConfigKeyValueSet *vitem = dynamic_cast<RsConfigKeyValueSet*>( *it ) ;
|
||||
|
||||
if(vitem != NULL)
|
||||
for(std::list<RsTlvKeyValue>::const_iterator it2(vitem->tlvkvs.pairs.begin());it2!=vitem->tlvkvs.pairs.end();++it2)
|
||||
{
|
||||
if(it2->key == "IP_FILTERING_ENABLED") mIPFilteringEnabled = (it2->value=="TRUE") ;
|
||||
if(it2->key == "IP_FILTERING_AUTORANGE_IPS") mAutoRangeIps = (it2->value=="TRUE") ;
|
||||
if(it2->key == "IP_FILTERING_FRIEND_GATHERING_ENABLED") mIPFriendGatheringEnabled = (it2->value=="TRUE") ;
|
||||
if(it2->key == "IP_FILTERING_DHT_GATHERING_ENABLED") mIPDHTGatheringEnabled = (it2->value=="TRUE") ;
|
||||
}
|
||||
|
||||
RsBanListConfigItem *citem = dynamic_cast<RsBanListConfigItem*>( *it ) ;
|
||||
|
||||
if(citem != NULL)
|
||||
{
|
||||
BanList& bl(mBanSources[citem->peerId]) ;
|
||||
|
||||
bl.mPeerId = citem->peerId ;
|
||||
bl.mLastUpdate = citem->update_time ;
|
||||
|
||||
bl.mBanPeers.clear() ;
|
||||
|
||||
for(std::list<RsTlvBanListEntry>::const_iterator it2(citem->banned_peers.mList.begin());it2!=citem->banned_peers.mList.end();++it2)
|
||||
{
|
||||
BanListPeer blp ;
|
||||
blp.fromRsTlvBanListEntry(*it2) ;
|
||||
|
||||
bl.mBanPeers[blp.addr] = blp ;
|
||||
}
|
||||
}
|
||||
|
||||
delete *it ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool p3BanList::addBanEntry(const RsPeerId &peerId, const struct sockaddr_storage &addr,
|
||||
int level, uint32_t reason, time_t time_stamp,uint8_t masked_bytes)
|
||||
@ -506,7 +650,7 @@ int p3BanList::condenseBanSources_locked()
|
||||
{
|
||||
mBanSet.clear();
|
||||
|
||||
time_t now = time(NULL);
|
||||
// time_t now = time(NULL);
|
||||
RsPeerId ownId = mServiceCtrl->getOwnId();
|
||||
|
||||
#ifdef DEBUG_BANLIST
|
||||
@ -670,35 +814,29 @@ void p3BanList::sendBanLists()
|
||||
|
||||
int p3BanList::sendBanSet(const RsPeerId& peerid)
|
||||
{
|
||||
/* */
|
||||
RsBanListItem *item = new RsBanListItem();
|
||||
item->PeerId(peerid);
|
||||
|
||||
time_t now = time(NULL);
|
||||
/* */
|
||||
RsBanListItem *item = new RsBanListItem();
|
||||
item->PeerId(peerid);
|
||||
|
||||
{
|
||||
RsStackMutex stack(mBanMtx); /****** LOCKED MUTEX *******/
|
||||
std::map<struct sockaddr_storage, BanListPeer>::iterator it;
|
||||
for(it = mBanSet.begin(); it != mBanSet.end(); ++it)
|
||||
{
|
||||
//time_t now = time(NULL);
|
||||
|
||||
{
|
||||
RsStackMutex stack(mBanMtx); /****** LOCKED MUTEX *******/
|
||||
std::map<struct sockaddr_storage, BanListPeer>::iterator it;
|
||||
for(it = mBanSet.begin(); it != mBanSet.end(); ++it)
|
||||
{
|
||||
if (it->second.level >= RSBANLIST_ORIGIN_FRIEND)
|
||||
{
|
||||
continue; // only share OWN for the moment.
|
||||
}
|
||||
|
||||
RsTlvBanListEntry bi;
|
||||
bi.addr.addr = it->second.addr;
|
||||
bi.reason = it->second.reason;
|
||||
bi.level = it->second.level;
|
||||
bi.age = now - it->second.mTs;
|
||||
|
||||
//item->peerList.entries.push_back(bi);
|
||||
item->peerList.mList.push_back(bi);
|
||||
}
|
||||
}
|
||||
continue; // only share OWN for the moment.
|
||||
|
||||
sendItem(item);
|
||||
return 1;
|
||||
RsTlvBanListEntry bi;
|
||||
it->second.toRsTlvBanListEntry(bi) ;
|
||||
|
||||
item->peerList.mList.push_back(bi);
|
||||
}
|
||||
}
|
||||
|
||||
sendItem(item);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,7 +53,7 @@ class BanList
|
||||
* Exchange list of Banned IP addresses with peers.
|
||||
*/
|
||||
|
||||
class p3BanList: public RsBanList, public p3Service, public pqiNetAssistPeerShare /* , public p3Config, public pqiMonitor */
|
||||
class p3BanList: public RsBanList, public p3Service, public pqiNetAssistPeerShare, public p3Config /*, public pqiMonitor */
|
||||
{
|
||||
public:
|
||||
p3BanList(p3ServiceControl *sc, p3NetMgr *nm);
|
||||
@ -85,6 +85,11 @@ public:
|
||||
|
||||
virtual void updatePeer(const RsPeerId& id, const struct sockaddr_storage &addr, int type, int reason, int time_stamp);
|
||||
|
||||
/*********************** p3config ******************************/
|
||||
virtual RsSerialiser *setupSerialiser();
|
||||
virtual bool saveList(bool &cleanup, std::list<RsItem *>& itemlist);
|
||||
virtual bool loadList(std::list<RsItem *>& load);
|
||||
|
||||
/***** overloaded from p3Service *****/
|
||||
/*!
|
||||
* This retrieves all chat msg items and also (important!)
|
||||
@ -103,7 +108,7 @@ public:
|
||||
bool recvBanItem(RsBanListItem *item);
|
||||
bool addBanEntry(const RsPeerId &peerId, const struct sockaddr_storage &addr, int level, uint32_t reason, time_t time_stamp, uint8_t masked_bytes);
|
||||
void sendBanLists();
|
||||
int sendBanSet(const RsPeerId& peerid);
|
||||
int sendBanSet(const RsPeerId& peerid);
|
||||
|
||||
|
||||
/*!
|
||||
|
Loading…
x
Reference in New Issue
Block a user