2011-11-23 16:40:32 +00:00
|
|
|
/*
|
|
|
|
* libretroshare/src/services/p3banlist.h
|
|
|
|
*
|
|
|
|
* Exchange list of Peers for Banning / Whitelisting.
|
|
|
|
*
|
|
|
|
* Copyright 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".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SERVICE_RSBANLIST_HEADER
|
|
|
|
#define SERVICE_RSBANLIST_HEADER
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "serialiser/rsbanlistitems.h"
|
|
|
|
#include "services/p3service.h"
|
|
|
|
//#include "retroshare/rsbanlist.h"
|
|
|
|
|
2014-03-29 03:57:44 +00:00
|
|
|
class p3ServiceControl;
|
2011-11-23 16:40:32 +00:00
|
|
|
class p3NetMgr;
|
|
|
|
|
|
|
|
class BanListPeer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2013-09-13 14:35:19 +00:00
|
|
|
struct sockaddr_storage addr;
|
2011-11-23 16:40:32 +00:00
|
|
|
uint32_t reason; // Dup Self, Dup Friend
|
|
|
|
int level; // LOCAL, FRIEND, FoF.
|
|
|
|
time_t mTs;
|
|
|
|
};
|
|
|
|
|
|
|
|
class BanList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-03-17 20:56:06 +00:00
|
|
|
RsPeerId mPeerId; /* from */
|
2011-11-23 16:40:32 +00:00
|
|
|
time_t mLastUpdate;
|
2013-09-13 14:35:19 +00:00
|
|
|
std::map<struct sockaddr_storage, BanListPeer> mBanPeers;
|
2011-11-23 16:40:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//!The RS BanList service.
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Exchange list of Banned IP addresses with peers.
|
|
|
|
*/
|
|
|
|
|
2011-11-25 00:58:01 +00:00
|
|
|
class p3BanList: /* public RsBanList, */ public p3Service, public pqiNetAssistPeerShare /* , public p3Config, public pqiMonitor */
|
2011-11-23 16:40:32 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-03-29 03:57:44 +00:00
|
|
|
p3BanList(p3ServiceControl *sc, p3NetMgr *nm);
|
2014-03-22 03:53:44 +00:00
|
|
|
virtual RsServiceInfo getServiceInfo();
|
2011-11-23 16:40:32 +00:00
|
|
|
|
|
|
|
/***** overloaded from RsBanList *****/
|
|
|
|
|
2011-11-25 00:58:01 +00:00
|
|
|
/***** overloaded from pqiNetAssistPeerShare *****/
|
|
|
|
|
2014-03-17 20:56:06 +00:00
|
|
|
virtual void updatePeer(const RsPeerId& id, const struct sockaddr_storage &addr, int type, int reason, int age);
|
2011-11-25 00:58:01 +00:00
|
|
|
|
|
|
|
|
2011-11-23 16:40:32 +00:00
|
|
|
/***** overloaded from p3Service *****/
|
|
|
|
/*!
|
|
|
|
* This retrieves all chat msg items and also (important!)
|
|
|
|
* processes chat-status items that are in service item queue. chat msg item requests are also processed and not returned
|
|
|
|
* (important! also) notifications sent to notify base on receipt avatar, immediate status and custom status
|
|
|
|
* : notifyCustomState, notifyChatStatus, notifyPeerHasNewAvatar
|
|
|
|
* @see NotifyBase
|
|
|
|
|
|
|
|
*/
|
|
|
|
virtual int tick();
|
|
|
|
virtual int status();
|
|
|
|
|
|
|
|
int sendPackets();
|
|
|
|
bool processIncoming();
|
|
|
|
|
|
|
|
bool recvBanItem(RsBanListItem *item);
|
2014-03-17 20:56:06 +00:00
|
|
|
bool addBanEntry(const RsPeerId &peerId, const struct sockaddr_storage &addr,
|
2012-02-17 10:03:38 +00:00
|
|
|
int level, uint32_t reason, uint32_t age);
|
2011-11-23 16:40:32 +00:00
|
|
|
void sendBanLists();
|
2014-03-17 20:56:06 +00:00
|
|
|
int sendBanSet(const RsPeerId& peerid);
|
2011-11-23 16:40:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Interface stuff.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*************** pqiMonitor callback ***********************/
|
|
|
|
//virtual void statusChange(const std::list<pqipeer> &plist);
|
|
|
|
|
|
|
|
|
|
|
|
/************* from p3Config *******************/
|
|
|
|
//virtual RsSerialiser *setupSerialiser() ;
|
|
|
|
//virtual bool saveList(bool& cleanup, std::list<RsItem*>&) ;
|
|
|
|
//virtual void saveDone();
|
|
|
|
//virtual bool loadList(std::list<RsItem*>& load) ;
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
RsMutex mBanMtx;
|
|
|
|
|
|
|
|
int condenseBanSources_locked();
|
2011-11-25 00:58:01 +00:00
|
|
|
int printBanSources_locked(std::ostream &out);
|
|
|
|
int printBanSet_locked(std::ostream &out);
|
2011-11-23 16:40:32 +00:00
|
|
|
|
|
|
|
time_t mSentListTime;
|
2014-03-17 20:56:06 +00:00
|
|
|
std::map<RsPeerId, BanList> mBanSources;
|
2013-09-13 14:35:19 +00:00
|
|
|
std::map<struct sockaddr_storage, BanListPeer> mBanSet;
|
2011-11-23 16:40:32 +00:00
|
|
|
|
2014-03-29 03:57:44 +00:00
|
|
|
p3ServiceControl *mServiceCtrl;
|
2011-11-23 16:40:32 +00:00
|
|
|
p3NetMgr *mNetMgr;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SERVICE_RSBANLIST_HEADER
|
|
|
|
|