2011-11-23 11:40:32 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/services p3banlist.cc
|
|
|
|
*
|
|
|
|
* Ban List Service for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2011-2011 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".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-03-28 23:57:44 -04:00
|
|
|
#include "pqi/p3servicecontrol.h"
|
2011-11-23 11:40:32 -05:00
|
|
|
#include "pqi/p3netmgr.h"
|
|
|
|
|
|
|
|
#include "util/rsnet.h"
|
|
|
|
|
|
|
|
#include "services/p3banlist.h"
|
|
|
|
#include "serialiser/rsbanlistitems.h"
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
/****
|
|
|
|
* #define DEBUG_BANLIST 1
|
|
|
|
****/
|
|
|
|
|
|
|
|
|
|
|
|
/* DEFINE INTERFACE POINTER! */
|
|
|
|
//RsBanList *rsBanList = NULL;
|
|
|
|
|
|
|
|
#define RSBANLIST_ENTRY_MAX_AGE (60 * 60 * 1) // 1 HOURS
|
|
|
|
#define RSBANLIST_SEND_PERIOD 600 // 10 Minutes.
|
|
|
|
|
|
|
|
#define RSBANLIST_SOURCE_SELF 0
|
|
|
|
#define RSBANLIST_SOURCE_FRIEND 1
|
|
|
|
#define RSBANLIST_SOURCE_FOF 2
|
|
|
|
|
|
|
|
|
|
|
|
/************ IMPLEMENTATION NOTES *********************************
|
|
|
|
*
|
|
|
|
* Get Bad Peers passed to us (from DHT mainly).
|
|
|
|
* we distribute and track the network list of bad peers.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2014-03-28 23:57:44 -04:00
|
|
|
p3BanList::p3BanList(p3ServiceControl *sc, p3NetMgr *nm)
|
|
|
|
:p3Service(), mBanMtx("p3BanList"), mServiceCtrl(sc), mNetMgr(nm)
|
2011-11-23 11:40:32 -05:00
|
|
|
{
|
|
|
|
addSerialType(new RsBanListSerialiser());
|
|
|
|
|
|
|
|
mSentListTime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-21 23:53:44 -04:00
|
|
|
const std::string BANLIST_APP_NAME = "banlist";
|
|
|
|
const uint16_t BANLIST_APP_MAJOR_VERSION = 1;
|
|
|
|
const uint16_t BANLIST_APP_MINOR_VERSION = 0;
|
|
|
|
const uint16_t BANLIST_MIN_MAJOR_VERSION = 1;
|
|
|
|
const uint16_t BANLIST_MIN_MINOR_VERSION = 0;
|
|
|
|
|
|
|
|
RsServiceInfo p3BanList::getServiceInfo()
|
|
|
|
{
|
|
|
|
return RsServiceInfo(RS_SERVICE_TYPE_BANLIST,
|
|
|
|
BANLIST_APP_NAME,
|
|
|
|
BANLIST_APP_MAJOR_VERSION,
|
|
|
|
BANLIST_APP_MINOR_VERSION,
|
|
|
|
BANLIST_MIN_MAJOR_VERSION,
|
|
|
|
BANLIST_MIN_MINOR_VERSION);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-11-23 11:40:32 -05:00
|
|
|
int p3BanList::tick()
|
|
|
|
{
|
|
|
|
processIncoming();
|
|
|
|
sendPackets();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int p3BanList::status()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***** Implementation ******/
|
|
|
|
|
|
|
|
bool p3BanList::processIncoming()
|
|
|
|
{
|
|
|
|
/* for each packet - pass to specific handler */
|
|
|
|
RsItem *item = NULL;
|
|
|
|
bool updated = false;
|
|
|
|
while(NULL != (item = recvItem()))
|
|
|
|
{
|
2011-11-24 19:58:01 -05:00
|
|
|
#ifdef DEBUG_BANLIST
|
|
|
|
std::cerr << "p3BanList::processingIncoming() Received Item:";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
item->print(std::cerr);
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2011-11-23 11:40:32 -05:00
|
|
|
switch(item->PacketSubType())
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case RS_PKT_SUBTYPE_BANLIST_ITEM:
|
|
|
|
{
|
2011-12-01 12:21:52 -05:00
|
|
|
// Order is important!.
|
|
|
|
updated = (recvBanItem((RsBanListItem *) item) || updated);
|
2011-11-23 11:40:32 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updated)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mBanMtx); /****** LOCKED MUTEX *******/
|
|
|
|
|
|
|
|
mBanSet.clear();
|
|
|
|
condenseBanSources_locked();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pass list to NetAssist */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool p3BanList::recvBanItem(RsBanListItem *item)
|
|
|
|
{
|
|
|
|
bool updated = false;
|
|
|
|
|
|
|
|
std::list<RsTlvBanListEntry>::const_iterator it;
|
2014-10-24 18:07:26 -04:00
|
|
|
//for(it = item->peerList.entries.begin(); it != item->peerList.entries.end(); ++it)
|
|
|
|
for(it = item->peerList.mList.begin(); it != item->peerList.mList.end(); ++it)
|
2011-11-23 11:40:32 -05:00
|
|
|
{
|
2011-12-01 12:21:52 -05:00
|
|
|
// Order is important!.
|
2013-09-13 10:35:19 -04:00
|
|
|
updated = (addBanEntry(item->PeerId(), it->addr.addr, it->level,
|
2011-12-01 12:21:52 -05:00
|
|
|
it->reason, it->age) || updated);
|
2011-11-23 11:40:32 -05:00
|
|
|
}
|
|
|
|
return updated;
|
|
|
|
}
|
|
|
|
|
2011-11-24 19:58:01 -05:00
|
|
|
/* overloaded from pqiNetAssistSharePeer */
|
2014-03-17 16:56:06 -04:00
|
|
|
void p3BanList::updatePeer(const RsPeerId& /*id*/, const struct sockaddr_storage &addr, int /*type*/, int /*reason*/, int age)
|
2011-11-24 19:58:01 -05:00
|
|
|
{
|
2014-03-28 23:57:44 -04:00
|
|
|
RsPeerId ownId = mServiceCtrl->getOwnId();
|
2011-11-24 19:58:01 -05:00
|
|
|
|
|
|
|
int int_reason = 0;
|
|
|
|
addBanEntry(ownId, addr, RSBANLIST_SOURCE_SELF, int_reason, age);
|
|
|
|
|
|
|
|
/* process */
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mBanMtx); /****** LOCKED MUTEX *******/
|
|
|
|
|
|
|
|
mBanSet.clear();
|
|
|
|
condenseBanSources_locked();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
bool p3BanList::addBanEntry(const RsPeerId &peerId, const struct sockaddr_storage &addr, int level, uint32_t reason, uint32_t age)
|
2011-11-23 11:40:32 -05:00
|
|
|
{
|
|
|
|
RsStackMutex stack(mBanMtx); /****** LOCKED MUTEX *******/
|
|
|
|
|
|
|
|
time_t now = time(NULL);
|
|
|
|
bool updated = false;
|
|
|
|
|
2011-11-24 19:58:01 -05:00
|
|
|
#ifdef DEBUG_BANLIST
|
|
|
|
std::cerr << "p3BanList::addBanEntry() Addr: " << rs_inet_ntoa(addr.sin_addr) << " Level: " << level;
|
|
|
|
std::cerr << " Reason: " << reason << " Age: " << age;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2011-12-01 12:21:52 -05:00
|
|
|
/* Only Accept it - if external address */
|
2013-09-13 10:35:19 -04:00
|
|
|
if (!sockaddr_storage_isExternalNet(addr))
|
2011-12-01 12:21:52 -05:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_BANLIST
|
2013-09-13 10:35:19 -04:00
|
|
|
std::cerr << "p3BanList::addBanEntry() Ignoring Non External Addr: " << sockaddr_storage_iptostring(addr);
|
2011-12-01 12:21:52 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
std::map<RsPeerId, BanList>::iterator it;
|
2011-11-23 11:40:32 -05:00
|
|
|
it = mBanSources.find(peerId);
|
|
|
|
if (it == mBanSources.end())
|
|
|
|
{
|
|
|
|
BanList bl;
|
|
|
|
bl.mPeerId = peerId;
|
2011-11-24 19:58:01 -05:00
|
|
|
bl.mLastUpdate = now;
|
2011-11-23 11:40:32 -05:00
|
|
|
mBanSources[peerId] = bl;
|
|
|
|
|
|
|
|
it = mBanSources.find(peerId);
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
|
2013-09-13 10:35:19 -04:00
|
|
|
// index is FAMILY + IP - the rest should be Zeros..
|
|
|
|
struct sockaddr_storage bannedaddr;
|
|
|
|
sockaddr_storage_clear(bannedaddr);
|
|
|
|
sockaddr_storage_copyip(bannedaddr, addr);
|
|
|
|
sockaddr_storage_setport(bannedaddr, 0);
|
|
|
|
|
|
|
|
std::map<struct sockaddr_storage, BanListPeer>::iterator mit;
|
|
|
|
mit = it->second.mBanPeers.find(bannedaddr);
|
2011-11-23 11:40:32 -05:00
|
|
|
if (mit == it->second.mBanPeers.end())
|
|
|
|
{
|
|
|
|
/* add in */
|
|
|
|
BanListPeer blp;
|
|
|
|
blp.addr = addr;
|
|
|
|
blp.reason = reason;
|
|
|
|
blp.level = level;
|
|
|
|
blp.mTs = now - age;
|
2011-11-24 19:58:01 -05:00
|
|
|
|
2013-09-13 10:35:19 -04:00
|
|
|
|
|
|
|
it->second.mBanPeers[bannedaddr] = blp;
|
2011-11-24 19:58:01 -05:00
|
|
|
it->second.mLastUpdate = now;
|
2011-11-23 11:40:32 -05:00
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* see if it needs an update */
|
|
|
|
if ((mit->second.reason != reason) ||
|
|
|
|
(mit->second.level != level) ||
|
2012-02-17 05:03:38 -05:00
|
|
|
(mit->second.mTs < (time_t) (now - age)))
|
2011-11-23 11:40:32 -05:00
|
|
|
{
|
|
|
|
/* update */
|
|
|
|
mit->second.addr = addr;
|
|
|
|
mit->second.reason = reason;
|
|
|
|
mit->second.level = level;
|
|
|
|
mit->second.mTs = now - age;
|
2011-11-24 19:58:01 -05:00
|
|
|
|
|
|
|
it->second.mLastUpdate = now;
|
2011-11-23 11:40:32 -05:00
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return updated;
|
|
|
|
}
|
|
|
|
|
2011-12-08 15:15:08 -05:00
|
|
|
/***
|
|
|
|
* EXTRA DEBUGGING.
|
|
|
|
* #define DEBUG_BANLIST_CONDENSE 1
|
|
|
|
***/
|
2011-11-23 11:40:32 -05:00
|
|
|
|
|
|
|
int p3BanList::condenseBanSources_locked()
|
|
|
|
{
|
|
|
|
time_t now = time(NULL);
|
2014-03-28 23:57:44 -04:00
|
|
|
RsPeerId ownId = mServiceCtrl->getOwnId();
|
2011-11-23 11:40:32 -05:00
|
|
|
|
2011-11-24 19:58:01 -05:00
|
|
|
#ifdef DEBUG_BANLIST
|
|
|
|
std::cerr << "p3BanList::condenseBanSources_locked()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
std::map<RsPeerId, BanList>::const_iterator it;
|
2014-10-24 18:07:26 -04:00
|
|
|
for(it = mBanSources.begin(); it != mBanSources.end(); ++it)
|
2011-11-23 11:40:32 -05:00
|
|
|
{
|
|
|
|
if (now - it->second.mLastUpdate > RSBANLIST_ENTRY_MAX_AGE)
|
|
|
|
{
|
2011-12-08 15:15:08 -05:00
|
|
|
#ifdef DEBUG_BANLIST_CONDENSE
|
2011-11-24 19:58:01 -05:00
|
|
|
std::cerr << "p3BanList::condenseBanSources_locked()";
|
|
|
|
std::cerr << " Ignoring Out-Of-Date peer: " << it->first;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2011-11-23 11:40:32 -05:00
|
|
|
continue;
|
|
|
|
}
|
2011-11-24 19:58:01 -05:00
|
|
|
|
2011-12-08 15:15:08 -05:00
|
|
|
#ifdef DEBUG_BANLIST_CONDENSE
|
2011-11-24 19:58:01 -05:00
|
|
|
std::cerr << "p3BanList::condenseBanSources_locked()";
|
|
|
|
std::cerr << " Condensing Info from peer: " << it->first;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2011-11-23 11:40:32 -05:00
|
|
|
|
2013-09-13 10:35:19 -04:00
|
|
|
std::map<struct sockaddr_storage, BanListPeer>::const_iterator lit;
|
2011-11-23 11:40:32 -05:00
|
|
|
for(lit = it->second.mBanPeers.begin();
|
2014-10-24 18:07:26 -04:00
|
|
|
lit != it->second.mBanPeers.end(); ++lit)
|
2011-11-23 11:40:32 -05:00
|
|
|
{
|
|
|
|
/* check timestamp */
|
|
|
|
if (now - lit->second.mTs > RSBANLIST_ENTRY_MAX_AGE)
|
|
|
|
{
|
2011-12-08 15:15:08 -05:00
|
|
|
#ifdef DEBUG_BANLIST_CONDENSE
|
2011-11-24 19:58:01 -05:00
|
|
|
std::cerr << "p3BanList::condenseBanSources_locked()";
|
|
|
|
std::cerr << " Ignoring Out-Of-Date Entry for: ";
|
2013-09-13 10:35:19 -04:00
|
|
|
std::cerr << sockaddr_storage_iptostring(lit->second.addr);
|
2011-11-24 19:58:01 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2011-11-23 11:40:32 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lvl = lit->second.level;
|
|
|
|
if (it->first != ownId)
|
|
|
|
{
|
|
|
|
/* as from someone else, increment level */
|
|
|
|
lvl++;
|
|
|
|
}
|
|
|
|
|
2013-09-13 10:35:19 -04:00
|
|
|
struct sockaddr_storage bannedaddr;
|
|
|
|
sockaddr_storage_clear(bannedaddr);
|
|
|
|
sockaddr_storage_copyip(bannedaddr, lit->second.addr);
|
|
|
|
sockaddr_storage_setport(bannedaddr, 0);
|
|
|
|
|
|
|
|
|
2011-11-23 11:40:32 -05:00
|
|
|
/* check if it exists in the Set already */
|
2013-09-13 10:35:19 -04:00
|
|
|
std::map<struct sockaddr_storage, BanListPeer>::iterator sit;
|
|
|
|
sit = mBanSet.find(bannedaddr);
|
2011-11-23 11:40:32 -05:00
|
|
|
if ((sit == mBanSet.end()) || (lvl < sit->second.level))
|
|
|
|
{
|
|
|
|
BanListPeer bp = lit->second;
|
|
|
|
bp.level = lvl;
|
2013-09-13 10:35:19 -04:00
|
|
|
sockaddr_storage_setport(bp.addr, 0);
|
|
|
|
mBanSet[bannedaddr] = bp;
|
2011-12-08 15:15:08 -05:00
|
|
|
#ifdef DEBUG_BANLIST_CONDENSE
|
2011-11-24 19:58:01 -05:00
|
|
|
std::cerr << "p3BanList::condenseBanSources_locked()";
|
|
|
|
std::cerr << " Added New Entry for: ";
|
2013-09-13 10:35:19 -04:00
|
|
|
std::cerr << sockaddr_storage_iptostring(bannedaddr);
|
2011-11-24 19:58:01 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2011-11-23 11:40:32 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-08 15:15:08 -05:00
|
|
|
#ifdef DEBUG_BANLIST_CONDENSE
|
2011-11-24 19:58:01 -05:00
|
|
|
std::cerr << "p3BanList::condenseBanSources_locked()";
|
|
|
|
std::cerr << " Merging Info for: ";
|
2013-09-13 10:35:19 -04:00
|
|
|
std::cerr << sockaddr_storage_iptostring(bannedaddr);
|
2011-11-24 19:58:01 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2011-11-23 11:40:32 -05:00
|
|
|
/* update if necessary */
|
|
|
|
if (lvl == sit->second.level)
|
|
|
|
{
|
|
|
|
sit->second.reason |= lit->second.reason;
|
|
|
|
if (sit->second.mTs < lit->second.mTs)
|
|
|
|
{
|
|
|
|
sit->second.mTs = lit->second.mTs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-24 19:58:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_BANLIST
|
|
|
|
std::cerr << "p3BanList::condenseBanSources_locked() Printing New Set:";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
printBanSet_locked(std::cerr);
|
2012-01-20 12:50:19 -05:00
|
|
|
#endif
|
2011-11-24 19:58:01 -05:00
|
|
|
|
2012-01-12 15:56:36 -05:00
|
|
|
return true ;
|
2011-11-23 11:40:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int p3BanList::sendPackets()
|
|
|
|
{
|
|
|
|
time_t now = time(NULL);
|
|
|
|
time_t pt;
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mBanMtx); /****** LOCKED MUTEX *******/
|
|
|
|
pt = mSentListTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (now - pt > RSBANLIST_SEND_PERIOD)
|
|
|
|
{
|
|
|
|
sendBanLists();
|
|
|
|
|
|
|
|
RsStackMutex stack(mBanMtx); /****** LOCKED MUTEX *******/
|
2011-11-24 19:58:01 -05:00
|
|
|
|
2012-01-20 12:50:19 -05:00
|
|
|
#ifdef DEBUG_BANLIST
|
2011-11-24 19:58:01 -05:00
|
|
|
std::cerr << "p3BanList::sendPackets() Regular Broadcast";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
printBanSources_locked(std::cerr);
|
|
|
|
printBanSet_locked(std::cerr);
|
2012-01-20 12:50:19 -05:00
|
|
|
#endif
|
2011-11-24 19:58:01 -05:00
|
|
|
|
2011-11-23 11:40:32 -05:00
|
|
|
mSentListTime = now;
|
|
|
|
}
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void p3BanList::sendBanLists()
|
|
|
|
{
|
|
|
|
|
|
|
|
/* we ping our peers */
|
|
|
|
/* who is online? */
|
2014-03-28 23:57:44 -04:00
|
|
|
std::set<RsPeerId> idList;
|
2011-11-23 11:40:32 -05:00
|
|
|
|
2014-03-28 23:57:44 -04:00
|
|
|
mServiceCtrl->getPeersConnected(getServiceInfo().mServiceType, idList);
|
2011-11-23 11:40:32 -05:00
|
|
|
|
|
|
|
#ifdef DEBUG_BANLIST
|
|
|
|
std::cerr << "p3BanList::sendBanList()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* prepare packets */
|
2014-03-28 23:57:44 -04:00
|
|
|
std::set<RsPeerId>::iterator it;
|
2014-10-24 18:07:26 -04:00
|
|
|
for(it = idList.begin(); it != idList.end(); ++it)
|
2011-11-23 11:40:32 -05:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_BANLIST
|
2015-05-11 14:26:59 -04:00
|
|
|
std::cerr << "p3BanList::sendBanList() To: " << *it;
|
2011-11-23 11:40:32 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
sendBanSet(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
int p3BanList::sendBanSet(const RsPeerId& peerid)
|
2011-11-23 11:40:32 -05:00
|
|
|
{
|
|
|
|
/* */
|
|
|
|
RsBanListItem *item = new RsBanListItem();
|
|
|
|
item->PeerId(peerid);
|
|
|
|
|
|
|
|
time_t now = time(NULL);
|
|
|
|
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mBanMtx); /****** LOCKED MUTEX *******/
|
2013-09-13 10:35:19 -04:00
|
|
|
std::map<struct sockaddr_storage, BanListPeer>::iterator it;
|
2014-10-24 18:07:26 -04:00
|
|
|
for(it = mBanSet.begin(); it != mBanSet.end(); ++it)
|
2011-11-23 11:40:32 -05:00
|
|
|
{
|
2012-02-02 19:59:41 -05:00
|
|
|
if (it->second.level >= RSBANLIST_SOURCE_FRIEND)
|
2011-11-23 11:40:32 -05:00
|
|
|
{
|
2012-02-02 19:59:41 -05:00
|
|
|
continue; // only share OWN for the moment.
|
2011-11-23 11:40:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
RsTlvBanListEntry bi;
|
2013-09-13 10:35:19 -04:00
|
|
|
bi.addr.addr = it->second.addr;
|
2011-11-23 11:40:32 -05:00
|
|
|
bi.reason = it->second.reason;
|
|
|
|
bi.level = it->second.level;
|
|
|
|
bi.age = now - it->second.mTs;
|
|
|
|
|
2014-03-29 11:34:37 -04:00
|
|
|
//item->peerList.entries.push_back(bi);
|
|
|
|
item->peerList.mList.push_back(bi);
|
2011-11-23 11:40:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sendItem(item);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-24 19:58:01 -05:00
|
|
|
int p3BanList::printBanSet_locked(std::ostream &out)
|
2011-11-23 11:40:32 -05:00
|
|
|
{
|
2011-11-24 19:58:01 -05:00
|
|
|
out << "p3BanList::printBanSet_locked()";
|
2011-11-23 11:40:32 -05:00
|
|
|
out << std::endl;
|
|
|
|
|
|
|
|
time_t now = time(NULL);
|
|
|
|
|
2013-09-13 10:35:19 -04:00
|
|
|
std::map<struct sockaddr_storage, BanListPeer>::iterator it;
|
2014-10-24 18:07:26 -04:00
|
|
|
for(it = mBanSet.begin(); it != mBanSet.end(); ++it)
|
2011-11-23 11:40:32 -05:00
|
|
|
{
|
2013-09-13 10:35:19 -04:00
|
|
|
out << "Ban: " << sockaddr_storage_iptostring(it->second.addr);
|
2011-11-23 11:40:32 -05:00
|
|
|
out << " Reason: " << it->second.reason;
|
|
|
|
out << " Level: " << it->second.level;
|
|
|
|
if (it->second.level > RSBANLIST_SOURCE_FRIEND)
|
|
|
|
{
|
|
|
|
out << " (unused)";
|
|
|
|
}
|
|
|
|
|
|
|
|
out << " Age: " << now - it->second.mTs;
|
|
|
|
out << std::endl;
|
|
|
|
}
|
2012-01-12 15:56:36 -05:00
|
|
|
return true ;
|
2011-11-23 11:40:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-11-24 19:58:01 -05:00
|
|
|
int p3BanList::printBanSources_locked(std::ostream &out)
|
2011-11-23 11:40:32 -05:00
|
|
|
{
|
|
|
|
time_t now = time(NULL);
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
std::map<RsPeerId, BanList>::const_iterator it;
|
2014-10-24 18:07:26 -04:00
|
|
|
for(it = mBanSources.begin(); it != mBanSources.end(); ++it)
|
2011-11-23 11:40:32 -05:00
|
|
|
{
|
|
|
|
out << "BanList from: " << it->first;
|
|
|
|
out << " LastUpdate: " << now - it->second.mLastUpdate;
|
|
|
|
out << std::endl;
|
|
|
|
|
2013-09-13 10:35:19 -04:00
|
|
|
std::map<struct sockaddr_storage, BanListPeer>::const_iterator lit;
|
2011-11-23 11:40:32 -05:00
|
|
|
for(lit = it->second.mBanPeers.begin();
|
2014-10-24 18:07:26 -04:00
|
|
|
lit != it->second.mBanPeers.end(); ++lit)
|
2011-11-23 11:40:32 -05:00
|
|
|
{
|
|
|
|
out << "\t";
|
2013-09-13 10:35:19 -04:00
|
|
|
out << "Ban: " << sockaddr_storage_iptostring(lit->second.addr);
|
2011-11-23 11:40:32 -05:00
|
|
|
out << " Reason: " << lit->second.reason;
|
|
|
|
out << " Level: " << lit->second.level;
|
|
|
|
out << " Age: " << now - lit->second.mTs;
|
|
|
|
out << std::endl;
|
|
|
|
}
|
|
|
|
}
|
2012-01-12 15:56:36 -05:00
|
|
|
return true ;
|
2011-11-23 11:40:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|