mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
- added more debug info to p3LinkMgr
- added check for banned IP from DHT at connection time - added regular removal of banned IPs from friend IP lists - increased time of banned IP storage to 1 week (previously 6 hours) - added save for banned IPs to keep them after restart (in bdfilter.cc) to file bdfilter.txt (can be manually updated) - changed mFiltered into a std::map for increased search efficiency - added secondary check of cert ID at connection time.-This line, and those below, will be ignored-- M libretroshare/src/pqi/p3netmgr.cc M libretroshare/src/pqi/pqimonitor.h M libretroshare/src/pqi/p3peermgr.cc M libretroshare/src/pqi/p3linkmgr.h M libretroshare/src/pqi/pqissllistener.cc M libretroshare/src/pqi/p3peermgr.h M libretroshare/src/pqi/p3linkmgr.cc M libretroshare/src/pqi/pqiperson.cc M libretroshare/src/pqi/pqissl.cc M libretroshare/src/rsserver/rsinit.cc M libretroshare/src/dht/p3bitdht_relay.cc M libretroshare/src/dht/p3bitdht.cc M libretroshare/src/dht/p3bitdht.h M libretroshare/src/retroshare/rsdht.h M libbitdht/src/udp/udpbitdht.h M libbitdht/src/udp/udpbitdht.cc M libbitdht/src/bitdht/bdmanager.cc M libbitdht/src/bitdht/bdmanager.h M libbitdht/src/bitdht/bdnode.h M libbitdht/src/bitdht/bdfilter.h M libbitdht/src/bitdht/bdfilter.cc M libbitdht/src/bitdht/bdnode.cc M libbitdht/src/bitdht/bdstore.h git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8289 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
e9b9dce9f5
commit
5b2ba1e81c
23 changed files with 442 additions and 200 deletions
|
@ -26,6 +26,7 @@
|
|||
|
||||
|
||||
#include "bitdht/bdfilter.h"
|
||||
#include "util/bdfile.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@ -35,39 +36,110 @@
|
|||
/**
|
||||
* #define DEBUG_FILTER 1
|
||||
**/
|
||||
#define BDFILTER_ENTRY_DROP_PERIOD (7 * 24 * 3600)
|
||||
|
||||
#define BDFILTER_ENTRY_DROP_PERIOD (6 * 3600)
|
||||
|
||||
|
||||
bdFilter::bdFilter(const bdNodeId *ownId, std::list<bdFilteredPeer> &startList,
|
||||
uint32_t filterFlags, bdDhtFunctions *fns)
|
||||
bdFilter::bdFilter(const std::string &fname, const bdNodeId *ownid, uint32_t filterFlags, bdDhtFunctions *fns)
|
||||
{
|
||||
/* */
|
||||
mOwnId = *ownId;
|
||||
mFns = fns;
|
||||
mOwnId = *ownid;
|
||||
mFns = fns;
|
||||
mFilename = fname ;
|
||||
|
||||
std::list<bdFilteredPeer>::iterator it;
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
for(it = startList.begin(); it != startList.end(); it++)
|
||||
{
|
||||
mFiltered.push_back(*it);
|
||||
}
|
||||
loadBannedIpFile() ;
|
||||
|
||||
mFilterFlags = filterFlags;
|
||||
mFilterFlags = filterFlags;
|
||||
}
|
||||
|
||||
bool bdFilter::filtered(std::list<bdFilteredPeer> &answer)
|
||||
void bdFilter::writeBannedIpFile()
|
||||
{
|
||||
answer = mFiltered;
|
||||
return (answer.size() > 0);
|
||||
std::string filetmp = mFilename + ".tmp" ;
|
||||
|
||||
FILE *fd = fopen(filetmp.c_str(), "w");
|
||||
|
||||
if (!fd)
|
||||
{
|
||||
std::cerr << "(EE) bdFilter::writeBannedIpFile() FAILED to Open File " << mFilename << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
for( std::map<uint32_t,bdFilteredPeer>::iterator it=mFiltered.begin();it!=mFiltered.end();++it)
|
||||
{
|
||||
fprintf(fd, "%s %d %ld %ld\n", bdnet_inet_ntoa(it->second.mAddr.sin_addr).c_str(), it->second.mFilterFlags, it->second.mFilterTS, it->second.mLastSeen) ;
|
||||
#ifdef DEBUG_FILTER
|
||||
fprintf(stderr, "Storing Peer Address: %s \n", bdnet_inet_ntoa(it->second.mAddr.sin_addr).c_str()) ;
|
||||
#endif
|
||||
|
||||
}
|
||||
fclose(fd);
|
||||
|
||||
if(!bdFile::renameFile(filetmp,mFilename))
|
||||
std::cerr << "Could not rename file !!" << std::endl;
|
||||
#ifdef DEBUG_FILTER
|
||||
else
|
||||
std::cerr << "Successfully renamed file " << filetmp << " to " << mFilename << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
void bdFilter::loadBannedIpFile()
|
||||
{
|
||||
char line[10240];
|
||||
char addr_str[10240];
|
||||
|
||||
struct sockaddr_in addr;
|
||||
addr.sin_family = PF_INET;
|
||||
unsigned short port;
|
||||
|
||||
FILE *fd = fopen(mFilename.c_str(),"r") ;
|
||||
|
||||
if(fd == NULL)
|
||||
{
|
||||
std::cerr << "(EE) Cannot load filter file " << mFilename << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
while(line == fgets(line, 10240, fd))
|
||||
{
|
||||
uint32_t filter_flags ;
|
||||
unsigned long long int filter_ts ;
|
||||
unsigned long long int last_seen ;
|
||||
|
||||
if (4 == sscanf(line, "%s %u %llu %llu", addr_str, &filter_flags,&filter_ts,&last_seen))
|
||||
{
|
||||
if (bdnet_inet_aton(addr_str, &(addr.sin_addr)))
|
||||
{
|
||||
addr.sin_port = 0;
|
||||
|
||||
bdFilteredPeer peer;
|
||||
|
||||
peer.mAddr = addr;
|
||||
peer.mFilterTS = filter_ts;
|
||||
peer.mLastSeen = last_seen;
|
||||
|
||||
mFiltered[addr.sin_addr.s_addr] = peer ;
|
||||
#ifdef DEBUG_FILTER
|
||||
std::cerr << "Loaded filtered IP: " << std::string(addr_str) << " last seen: " << last_seen << ", TS=" << filter_ts << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
//bool bdFilter::filtered(std::list<bdFilteredPeer> &answer)
|
||||
//{
|
||||
// answer = mFiltered;
|
||||
// return (answer.size() > 0);
|
||||
//}
|
||||
|
||||
bool bdFilter::filteredIPs(std::list<struct sockaddr_in> &answer)
|
||||
{
|
||||
std::list<bdFilteredPeer>::iterator it;
|
||||
std::map<uint32_t,bdFilteredPeer>::iterator it;
|
||||
for(it = mFiltered.begin(); it != mFiltered.end(); it++)
|
||||
{
|
||||
answer.push_back(it->mAddr);
|
||||
answer.push_back(it->second.mAddr);
|
||||
}
|
||||
return (answer.size() > 0);
|
||||
}
|
||||
|
@ -85,7 +157,8 @@ int bdFilter::checkPeer(const bdId *id, uint32_t mode)
|
|||
|
||||
if (add)
|
||||
{
|
||||
bool isNew = addPeerToFilter(id, flags);
|
||||
bool isNew = addPeerToFilter(id->addr, flags);
|
||||
|
||||
if (isNew)
|
||||
{
|
||||
return 1;
|
||||
|
@ -95,59 +168,68 @@ int bdFilter::checkPeer(const bdId *id, uint32_t mode)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int bdFilter::addPeerToFilter(const bdId *id, uint32_t flags)
|
||||
int bdFilter::addPeerToFilter(const struct sockaddr_in& addr, uint32_t flags)
|
||||
{
|
||||
std::list<bdFilteredPeer>::iterator it;
|
||||
bool found = false;
|
||||
for(it = mFiltered.begin(); it != mFiltered.end(); it++)
|
||||
std::map<uint32_t,bdFilteredPeer>::iterator it = mFiltered.find(addr.sin_addr.s_addr) ;
|
||||
|
||||
if(it != mFiltered.end())
|
||||
{
|
||||
if (id->addr.sin_addr.s_addr == it->mAddr.sin_addr.s_addr)
|
||||
{
|
||||
found = true;
|
||||
it->mLastSeen = time(NULL);
|
||||
it->mFilterFlags |= flags;
|
||||
break;
|
||||
}
|
||||
}
|
||||
it->second.mLastSeen = time(NULL);
|
||||
it->second.mFilterFlags |= flags;
|
||||
}
|
||||
else
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
bdFilteredPeer fp;
|
||||
|
||||
if (!found)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
bdFilteredPeer fp;
|
||||
fp.mAddr = addr;
|
||||
fp.mAddr.sin_port = 0;
|
||||
fp.mFilterFlags = flags;
|
||||
fp.mFilterTS = now;
|
||||
fp.mLastSeen = now;
|
||||
|
||||
fp.mAddr = id->addr;
|
||||
fp.mAddr.sin_port = 0;
|
||||
fp.mFilterFlags = flags;
|
||||
fp.mFilterTS = now;
|
||||
fp.mLastSeen = now;
|
||||
uint32_t saddr = addr.sin_addr.s_addr;
|
||||
|
||||
mFiltered.push_back(fp);
|
||||
mFiltered[saddr] = fp;
|
||||
|
||||
uint32_t saddr = id->addr.sin_addr.s_addr;
|
||||
mIpsBanned.insert(saddr);
|
||||
std::cerr << "Adding New Banned Ip Address: " << bdnet_inet_ntoa(addr.sin_addr);
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
writeBannedIpFile() ;
|
||||
|
||||
std::cerr << "Adding New Banned Ip Address: " << bdnet_inet_ntoa(id->addr.sin_addr);
|
||||
std::cerr << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// void bdFilter::loadFilteredPeers(const std::list<bdFilteredPeer>& peers)
|
||||
// {
|
||||
// for(std::list<bdFilteredPeer>::iterator it = peers.begin(); it != peers.end();++it)
|
||||
// {
|
||||
// #ifdef DEBUG_FILTER
|
||||
// std::cerr << "Loading filtered peer " << inet_ntoa(it->mAddr.sin_addr) << " Flags: " << it->mFilterFlags << " FilterTS: "
|
||||
// << now - it->mFilterTS << " LastSeen: " << now - it->mLastSeen << std::endl;
|
||||
// #endif
|
||||
// uint32_t saddr = it->mAddr.sin_addr.s_addr;
|
||||
// mFiltered[saddr] = *it ;
|
||||
// }
|
||||
// }
|
||||
// void bdFilter::getFilteredPeers(std::list<bdFilteredPeer>& peers)
|
||||
// {
|
||||
// for(std::map<uint32_t,bdFilteredPeer>::iterator it = mFiltered.begin(); it != mFiltered.end();++it)
|
||||
// peers.push_back(it->second) ;
|
||||
// }
|
||||
/* fast check if the addr is in the structure */
|
||||
int bdFilter::addrOkay(struct sockaddr_in *addr)
|
||||
{
|
||||
std::set<uint32_t>::const_iterator it = mIpsBanned.find(addr->sin_addr.s_addr);
|
||||
if (it == mIpsBanned.end())
|
||||
{
|
||||
return 1; // Address is Okay!
|
||||
}
|
||||
std::map<uint32_t,bdFilteredPeer>::const_iterator it = mFiltered.find(addr->sin_addr.s_addr);
|
||||
|
||||
if (it == mFiltered.end())
|
||||
return 1; // Address is Okay!
|
||||
|
||||
#ifdef DEBUG_FILTER
|
||||
std::cerr << "Detected Packet From Banned Ip Address: " << inet_ntoa(addr->sin_addr);
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "Detected Packet From Banned Ip Address: " << inet_ntoa(addr->sin_addr);
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -184,55 +266,41 @@ bool bdFilter::isOwnIdWithoutBitDhtFlags(const bdId *id, uint32_t peerFlags)
|
|||
bool bdFilter::cleanupFilter()
|
||||
{
|
||||
#ifdef DEBUG_FILTER
|
||||
std::cerr << "bdFilter::cleanupFilter() Current BanList" << std::endl;
|
||||
struct in_addr inaddr;
|
||||
|
||||
std::set<uint32_t>::iterator sit;
|
||||
for(sit = mIpsBanned.begin(); sit != mIpsBanned.end(); sit++)
|
||||
{
|
||||
inaddr.s_addr = *sit;
|
||||
std::cerr << "\tBanned: " << inet_ntoa(inaddr) << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
mIpsBanned.clear();
|
||||
|
||||
#ifdef DEBUG_FILTER
|
||||
std::cerr << "Filter List:" << std::endl;
|
||||
std::cerr << "bdFilter: Checking current filter List:" << std::endl;
|
||||
#endif
|
||||
|
||||
time_t now = time(NULL);
|
||||
time_t dropTime = now - BDFILTER_ENTRY_DROP_PERIOD;
|
||||
|
||||
std::list<bdFilteredPeer>::iterator it;
|
||||
for(it = mFiltered.begin(); it != mFiltered.end();)
|
||||
{
|
||||
for(std::map<uint32_t,bdFilteredPeer>::iterator it = mFiltered.begin(); it != mFiltered.end();)
|
||||
{
|
||||
#ifdef DEBUG_FILTER
|
||||
std::cerr << "\t" << inet_ntoa(it->mAddr.sin_addr);
|
||||
std::cerr << " Flags: " << it->mFilterFlags;
|
||||
std::cerr << " FilterTS: " << now - it->mFilterTS;
|
||||
std::cerr << " LastSeen: " << now - it->mLastSeen;
|
||||
std::cerr << "\t" << bdnet_inet_ntoa(it->second.mAddr.sin_addr);
|
||||
std::cerr << " Flags: " << it->second.mFilterFlags;
|
||||
std::cerr << " FilterTS: " << now - it->second.mFilterTS;
|
||||
std::cerr << " LastSeen: " << now - it->second.mLastSeen;
|
||||
#endif
|
||||
|
||||
if (it->mLastSeen < dropTime)
|
||||
{
|
||||
/* remove from filter */
|
||||
if (it->second.mLastSeen < dropTime)
|
||||
{
|
||||
/* remove from filter */
|
||||
#ifdef DEBUG_FILTER
|
||||
std::cerr << " OLD DROPPING" << std::endl;
|
||||
std::cerr << " OLD DROPPING" << std::endl;
|
||||
#endif
|
||||
it = mFiltered.erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG_FILTER
|
||||
std::cerr << " OK" << std::endl;
|
||||
#endif
|
||||
uint32_t saddr = it->mAddr.sin_addr.s_addr;
|
||||
mIpsBanned.insert(saddr);
|
||||
std::map<uint32_t,bdFilteredPeer>::iterator tmp(it) ;
|
||||
++tmp ;
|
||||
|
||||
it++;
|
||||
}
|
||||
}
|
||||
mFiltered.erase(it);
|
||||
it = tmp ;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG_FILTER
|
||||
std::cerr << " OK" << std::endl;
|
||||
#endif
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -50,21 +50,26 @@ class bdFilteredPeer
|
|||
class bdFilter
|
||||
{
|
||||
public:
|
||||
bdFilter(const bdNodeId *ownid, std::list<bdFilteredPeer> &initialFilters,
|
||||
uint32_t filterFlags, bdDhtFunctions *fns);
|
||||
bdFilter(const std::string& fname,const bdNodeId *ownid, uint32_t filterFlags, bdDhtFunctions *fns);
|
||||
|
||||
// get the answer.
|
||||
bool filtered(std::list<bdFilteredPeer> &answer);
|
||||
//bool filtered(std::list<bdFilteredPeer> &answer);
|
||||
bool filteredIPs(std::list<struct sockaddr_in> &answer);
|
||||
|
||||
void loadFilteredPeers(const std::list<bdFilteredPeer>& peers) ;
|
||||
void getFilteredPeers(std::list<bdFilteredPeer> &peers);
|
||||
|
||||
int checkPeer(const bdId *id, uint32_t peerFlags);
|
||||
|
||||
int addrOkay(struct sockaddr_in *addr);
|
||||
int addPeerToFilter(const bdId *id, uint32_t flags);
|
||||
int addPeerToFilter(const struct sockaddr_in &addr, uint32_t flags);
|
||||
|
||||
bool cleanupFilter();
|
||||
|
||||
private:
|
||||
void loadBannedIpFile() ;
|
||||
void writeBannedIpFile() ;
|
||||
|
||||
private:
|
||||
|
||||
bool isOwnIdWithoutBitDhtFlags(const bdId *id, uint32_t peerFlags);
|
||||
|
||||
|
@ -72,11 +77,9 @@ bool isOwnIdWithoutBitDhtFlags(const bdId *id, uint32_t peerFlags);
|
|||
bdNodeId mOwnId;
|
||||
uint32_t mFilterFlags;
|
||||
|
||||
std::list<bdFilteredPeer> mFiltered;
|
||||
bdDhtFunctions *mFns;
|
||||
|
||||
// = addr.sin_addr.s_addr (uint32_t) stored in network order.
|
||||
std::set<uint32_t> mIpsBanned;
|
||||
std::map<uint32_t,bdFilteredPeer> mFiltered;
|
||||
bdDhtFunctions *mFns;
|
||||
std::string mFilename ;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -68,8 +68,8 @@
|
|||
#define QUERY_UPDATE_PERIOD 8 // under refresh period - so it'll happen at the MAX_REFRESH_PERIOD
|
||||
|
||||
|
||||
bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, bdDhtFunctions *fns)
|
||||
:bdNode(id, dhtVersion, bootfile, fns)
|
||||
bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, const std::string& filterfile,bdDhtFunctions *fns)
|
||||
:bdNode(id, dhtVersion, bootfile, filterfile, fns)
|
||||
{
|
||||
mMode = BITDHT_MGR_STATE_OFF;
|
||||
mFns = fns;
|
||||
|
@ -394,7 +394,7 @@ void bdNodeManager::iteration()
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
mFilterPeers->cleanupFilter();
|
||||
mFilterPeers.cleanupFilter();
|
||||
|
||||
|
||||
#ifdef DEBUG_MGR
|
||||
|
|
|
@ -96,7 +96,7 @@ class bdQueryPeer
|
|||
class bdNodeManager: public bdNode, public BitDhtInterface
|
||||
{
|
||||
public:
|
||||
bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, bdDhtFunctions *fns);
|
||||
bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, const std::string &filterfile, bdDhtFunctions *fns);
|
||||
|
||||
|
||||
void iteration();
|
||||
|
@ -152,7 +152,8 @@ virtual void callbackConnect(bdId *srcId, bdId *proxyId, bdId *destId,
|
|||
int mode, int point, int param, int cbtype, int errcode);
|
||||
|
||||
int isBitDhtPacket(char *data, int size, struct sockaddr_in &from);
|
||||
private:
|
||||
|
||||
private:
|
||||
|
||||
|
||||
void doNodeCallback(const bdId *id, uint32_t peerflags);
|
||||
|
|
|
@ -70,12 +70,14 @@
|
|||
|
||||
#define HISTORY_PERIOD 60
|
||||
|
||||
bdNode::bdNode(bdNodeId *ownId, std::string dhtVersion, std::string bootfile, bdDhtFunctions *fns)
|
||||
:mNodeSpace(ownId, fns), mQueryMgr(NULL), mConnMgr(NULL),
|
||||
mFilterPeers(NULL), mOwnId(*ownId), mDhtVersion(dhtVersion), mStore(bootfile, fns), mFns(fns),
|
||||
mFriendList(ownId), mHistory(HISTORY_PERIOD)
|
||||
bdNode::bdNode(bdNodeId *ownId, std::string dhtVersion, const std::string& bootfile, const std::string& filterfile, bdDhtFunctions *fns)
|
||||
:mNodeSpace(ownId, fns),
|
||||
mFilterPeers(filterfile,ownId, BITDHT_FILTER_REASON_OWNID, fns),
|
||||
mQueryMgr(NULL),
|
||||
mConnMgr(NULL),
|
||||
mOwnId(*ownId), mDhtVersion(dhtVersion), mStore(bootfile, fns), mFns(fns),
|
||||
mFriendList(ownId), mHistory(HISTORY_PERIOD)
|
||||
{
|
||||
|
||||
init(); /* (uses this pointers) stuff it - do it here! */
|
||||
}
|
||||
|
||||
|
@ -84,9 +86,6 @@ void bdNode::init()
|
|||
mQueryMgr = new bdQueryManager(&mNodeSpace, mFns, this);
|
||||
mConnMgr = new bdConnectManager(&mOwnId, &mNodeSpace, mQueryMgr, mFns, this);
|
||||
|
||||
std::list<bdFilteredPeer> emptyList;
|
||||
mFilterPeers = new bdFilter(&mOwnId, emptyList, BITDHT_FILTER_REASON_OWNID, mFns);
|
||||
|
||||
//setNodeOptions(BITDHT_OPTIONS_MAINTAIN_UNSTABLE_PORT);
|
||||
setNodeOptions(0);
|
||||
|
||||
|
@ -94,7 +93,15 @@ void bdNode::init()
|
|||
setNodeDhtMode(BITDHT_MODE_TRAFFIC_DEFAULT);
|
||||
|
||||
}
|
||||
|
||||
//void bdNode::getFilteredPeers(std::list<bdFilteredPeer>& peers)
|
||||
//{
|
||||
// mFilterPeers.getFilteredPeers(peers) ;
|
||||
//}
|
||||
//
|
||||
//void bdNode::loadFilteredPeers(const std::list<bdFilteredPeer>& peers)
|
||||
//{
|
||||
// mFilterPeers.loadFilteredPeers(peers) ;
|
||||
//}
|
||||
/* Unfortunately I've ended up with 2 calls down through the heirarchy...
|
||||
* not ideal - must clean this up one day.
|
||||
*/
|
||||
|
@ -249,7 +256,12 @@ void bdNode::shutdownNode()
|
|||
/* Crappy initial store... use bdspace as answer */
|
||||
void bdNode::updateStore()
|
||||
{
|
||||
mStore.writeStore();
|
||||
mStore.writeStore();
|
||||
}
|
||||
|
||||
bool bdNode::addressBanned(const sockaddr_in& raddr)
|
||||
{
|
||||
return !mFilterPeers.addrOkay(const_cast<sockaddr_in*>(&raddr)) ;
|
||||
}
|
||||
|
||||
void bdNode::printState()
|
||||
|
@ -481,7 +493,7 @@ void bdNode::checkPotentialPeer(bdId *id, bdId *src)
|
|||
/* Check BadPeer Filters for Potential Peers too */
|
||||
|
||||
/* first check the filters */
|
||||
if (!mFilterPeers->addrOkay(&(id->addr)))
|
||||
if (!mFilterPeers.addrOkay(&(id->addr)))
|
||||
{
|
||||
std::cerr << "bdNode::checkPotentialPeer(";
|
||||
mFns->bdPrintId(std::cerr, id);
|
||||
|
@ -509,10 +521,10 @@ void bdNode::checkPotentialPeer(bdId *id, bdId *src)
|
|||
// Stores in queue for later callback and desemination around the network.
|
||||
mBadPeerQueue.queuePeer(id, 0);
|
||||
|
||||
mFilterPeers->addPeerToFilter(id, 0);
|
||||
mFilterPeers.addPeerToFilter(id->addr, 0);
|
||||
|
||||
std::list<struct sockaddr_in> filteredIPs;
|
||||
mFilterPeers->filteredIPs(filteredIPs);
|
||||
mFilterPeers.filteredIPs(filteredIPs);
|
||||
mStore.filterIpList(filteredIPs);
|
||||
|
||||
return;
|
||||
|
@ -542,8 +554,6 @@ void bdNode::addPotentialPeer(bdId *id, bdId * /*src*/)
|
|||
mPotentialPeers.push_back(*id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// virtual so manager can do callback.
|
||||
// peer flags defined in bdiface.h
|
||||
void bdNode::addPeer(const bdId *id, uint32_t peerflags)
|
||||
|
@ -556,7 +566,7 @@ void bdNode::addPeer(const bdId *id, uint32_t peerflags)
|
|||
#endif
|
||||
|
||||
/* first check the filters */
|
||||
if (mFilterPeers->checkPeer(id, peerflags))
|
||||
if (mFilterPeers.checkPeer(id, peerflags))
|
||||
{
|
||||
std::cerr << "bdNode::addPeer(";
|
||||
mFns->bdPrintId(std::cerr, id);
|
||||
|
@ -565,7 +575,7 @@ void bdNode::addPeer(const bdId *id, uint32_t peerflags)
|
|||
std::cerr << std::endl;
|
||||
|
||||
std::list<struct sockaddr_in> filteredIPs;
|
||||
mFilterPeers->filteredIPs(filteredIPs);
|
||||
mFilterPeers.filteredIPs(filteredIPs);
|
||||
mStore.filterIpList(filteredIPs);
|
||||
|
||||
mBadPeerQueue.queuePeer(id, peerflags);
|
||||
|
@ -597,10 +607,10 @@ void bdNode::addPeer(const bdId *id, uint32_t peerflags)
|
|||
// Stores in queue for later callback and desemination around the network.
|
||||
mBadPeerQueue.queuePeer(id, peerflags);
|
||||
|
||||
mFilterPeers->addPeerToFilter(id, peerflags);
|
||||
mFilterPeers.addPeerToFilter(id->addr, peerflags);
|
||||
|
||||
std::list<struct sockaddr_in> filteredIPs;
|
||||
mFilterPeers->filteredIPs(filteredIPs);
|
||||
mFilterPeers.filteredIPs(filteredIPs);
|
||||
mStore.filterIpList(filteredIPs);
|
||||
|
||||
// DO WE EXPLICITLY NEED TO DO THIS, OR WILL THEY JUST BE DROPPED?
|
||||
|
@ -826,7 +836,7 @@ int bdNode::outgoingMsg(struct sockaddr_in *addr, char *msg, int *len)
|
|||
void bdNode::incomingMsg(struct sockaddr_in *addr, char *msg, int len)
|
||||
{
|
||||
/* check against the filter */
|
||||
if (mFilterPeers->addrOkay(addr))
|
||||
if (mFilterPeers.addrOkay(addr))
|
||||
{
|
||||
bdNodeNetMsg *bdmsg = new bdNodeNetMsg(msg, len, addr);
|
||||
mIncomingMsgs.push_back(bdmsg);
|
||||
|
@ -1133,7 +1143,7 @@ void bdNode::sendPkt(char *msg, int len, struct sockaddr_in addr)
|
|||
// len, inet_ntoa(addr.sin_addr), htons(addr.sin_port));
|
||||
|
||||
/* filter outgoing packets */
|
||||
if (mFilterPeers->addrOkay(&addr))
|
||||
if (mFilterPeers.addrOkay(&addr))
|
||||
{
|
||||
bdNodeNetMsg *bdmsg = new bdNodeNetMsg(msg, len, &addr);
|
||||
//bdmsg->print(std::cerr);
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "bitdht/bdobj.h"
|
||||
#include "bitdht/bdhash.h"
|
||||
#include "bitdht/bdhistory.h"
|
||||
#include "bitdht/bdfilter.h"
|
||||
|
||||
#include "bitdht/bdconnection.h"
|
||||
#include "bitdht/bdaccount.h"
|
||||
|
@ -83,6 +84,8 @@ output -> call back to Udp().
|
|||
|
||||
*********/
|
||||
|
||||
class bdFilteredPeer ;
|
||||
|
||||
class bdNodeNetMsg
|
||||
{
|
||||
|
||||
|
@ -118,7 +121,7 @@ class bdNode: public bdNodePublisher
|
|||
{
|
||||
public:
|
||||
|
||||
bdNode(bdNodeId *id, std::string dhtVersion, std::string bootfile,
|
||||
bdNode(bdNodeId *id, std::string dhtVersion, const std::string& bootfile, const std::string& filterfile,
|
||||
bdDhtFunctions *fns);
|
||||
|
||||
void init(); /* sets up the self referential classes (mQueryMgr & mConnMgr) */
|
||||
|
@ -145,6 +148,10 @@ class bdNode: public bdNodePublisher
|
|||
void processRemoteQuery();
|
||||
void updateStore();
|
||||
|
||||
bool addressBanned(const sockaddr_in &raddr) ;
|
||||
void getFilteredPeers(std::list<bdFilteredPeer> &peers);
|
||||
void loadFilteredPeers(const std::list<bdFilteredPeer> &peers);
|
||||
|
||||
/* simplified outgoing msg functions (for the managers) */
|
||||
virtual void send_ping(bdId *id); /* message out */
|
||||
virtual void send_query(bdId *id, bdNodeId *targetNodeId, bool localnet); /* message out */
|
||||
|
@ -163,8 +170,9 @@ void incomingMsg(struct sockaddr_in *addr, char *msg, int len);
|
|||
void dropRelayServers();
|
||||
void pingRelayServers();
|
||||
|
||||
// Below is internal Management of incoming / outgoing messages.
|
||||
private:
|
||||
// Below is internal Management of incoming / outgoing messages.
|
||||
|
||||
private:
|
||||
|
||||
/* internal interaction with network */
|
||||
void sendPkt(char *msg, int len, struct sockaddr_in addr);
|
||||
|
@ -235,10 +243,10 @@ void recvPkt(char *msg, int len, struct sockaddr_in addr);
|
|||
protected:
|
||||
|
||||
bdSpace mNodeSpace;
|
||||
bdFilter mFilterPeers;
|
||||
|
||||
bdQueryManager *mQueryMgr;
|
||||
bdConnectManager *mConnMgr;
|
||||
bdFilter *mFilterPeers;
|
||||
|
||||
bdNodeId mOwnId;
|
||||
bdId mLikelyOwnId; // Try to workout own id address.
|
||||
|
|
|
@ -33,24 +33,24 @@
|
|||
|
||||
class bdStore
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
bdStore(std::string file, bdDhtFunctions *fns);
|
||||
bdStore(std::string file, bdDhtFunctions *fns);
|
||||
|
||||
int reloadFromStore(); /* for restarts */
|
||||
int filterIpList(const std::list<struct sockaddr_in> &filteredIPs);
|
||||
int clear();
|
||||
int reloadFromStore(); /* for restarts */
|
||||
int filterIpList(const std::list<struct sockaddr_in> &filteredIPs);
|
||||
int clear();
|
||||
|
||||
int getPeer(bdPeer *peer);
|
||||
void addStore(bdPeer *peer);
|
||||
void writeStore(std::string file);
|
||||
void writeStore();
|
||||
int getPeer(bdPeer *peer);
|
||||
void addStore(bdPeer *peer);
|
||||
void writeStore(std::string file);
|
||||
void writeStore();
|
||||
|
||||
private:
|
||||
std::string mStoreFile;
|
||||
std::list<bdPeer> store;
|
||||
int mIndex;
|
||||
bdDhtFunctions *mFns;
|
||||
protected:
|
||||
std::string mStoreFile;
|
||||
std::list<bdPeer> store;
|
||||
int mIndex;
|
||||
bdDhtFunctions *mFns;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
|
||||
/*************************************/
|
||||
|
||||
UdpBitDht::UdpBitDht(UdpPublisher *pub, bdNodeId *id, std::string appVersion, std::string bootstrapfile, bdDhtFunctions *fns)
|
||||
UdpBitDht::UdpBitDht(UdpPublisher *pub, bdNodeId *id, std::string appVersion, std::string bootstrapfile, const std::string& filteredipfile, bdDhtFunctions *fns)
|
||||
:UdpSubReceiver(pub), dhtMtx(true), mFns(fns)
|
||||
{
|
||||
std::string usedVersion;
|
||||
|
@ -76,7 +76,7 @@ UdpBitDht::UdpBitDht(UdpPublisher *pub, bdNodeId *id, std::string appVersion, st
|
|||
|
||||
/* setup nodeManager */
|
||||
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
|
||||
mBitDhtManager = new bdNodeManager(id, usedVersion, bootstrapfile, fns);
|
||||
mBitDhtManager = new bdNodeManager(id, usedVersion, bootstrapfile, filteredipfile, fns);
|
||||
}
|
||||
|
||||
|
||||
|
@ -209,7 +209,12 @@ int UdpBitDht::getDhtQueryStatus(const bdNodeId *id, bdQuerySummary &query)
|
|||
{
|
||||
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
|
||||
|
||||
return mBitDhtManager->getDhtQueryStatus(id, query);
|
||||
return mBitDhtManager->getDhtQueryStatus(id, query);
|
||||
}
|
||||
|
||||
bool UdpBitDht::isAddressBanned(const sockaddr_in &raddr)
|
||||
{
|
||||
return mBitDhtManager->addressBanned(raddr) ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ class UdpBitDht: public UdpSubReceiver, public bdThread, public BitDhtInterface
|
|||
{
|
||||
public:
|
||||
|
||||
UdpBitDht(UdpPublisher *pub, bdNodeId *id, std::string dhtVersion, std::string bootstrapfile, bdDhtFunctions *fns);
|
||||
UdpBitDht(UdpPublisher *pub, bdNodeId *id, std::string dhtVersion, std::string bootstrapfile, const std::string& filteredipfile,bdDhtFunctions *fns);
|
||||
virtual ~UdpBitDht();
|
||||
|
||||
|
||||
|
@ -87,6 +87,8 @@ virtual int getDhtBucket(const int idx, bdBucket &bucket);
|
|||
virtual int getDhtQueries(std::map<bdNodeId, bdQueryStatus> &queries);
|
||||
virtual int getDhtQueryStatus(const bdNodeId *id, bdQuerySummary &query);
|
||||
|
||||
virtual bool isAddressBanned(const sockaddr_in &raddr) ;
|
||||
|
||||
/* stats and Dht state */
|
||||
virtual int startDht();
|
||||
virtual int stopDht();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue