mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Improvements to the Bad Peer tracking in the DHT.
* Added Interfaces for sharing Bad Peers. * Added bdPeerQueue class for storing * added doInfoCallback() to inform libretroshare git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-dhtmods@4686 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
f01d06c806
commit
8d4a7ed4f0
@ -30,6 +30,9 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
/*****
|
||||||
|
* #define DEBUG_FRIENDLIST 1
|
||||||
|
****/
|
||||||
|
|
||||||
bdFriendEntry::bdFriendEntry()
|
bdFriendEntry::bdFriendEntry()
|
||||||
{
|
{
|
||||||
@ -139,10 +142,12 @@ bool bdFriendList::findPeerEntry(const bdNodeId *id, bdFriendEntry &entry)
|
|||||||
it = mPeers.find(*id);
|
it = mPeers.find(*id);
|
||||||
if (it == mPeers.end())
|
if (it == mPeers.end())
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_FRIENDLIST
|
||||||
std::cerr << "bdFriendList::getPeerEntry() Peer(";
|
std::cerr << "bdFriendList::getPeerEntry() Peer(";
|
||||||
bdStdPrintNodeId(std::cerr, id);
|
bdStdPrintNodeId(std::cerr, id);
|
||||||
std::cerr << ") is unknown!";
|
std::cerr << ") is unknown!";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -175,3 +180,37 @@ bool bdFriendList::print(std::ostream &out)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bdPeerQueue::bdPeerQueue()
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bdPeerQueue::queuePeer(const bdId *id, uint32_t flags)
|
||||||
|
{
|
||||||
|
bdFriendEntry entry;
|
||||||
|
entry.mPeerId = *id;
|
||||||
|
entry.mFlags = flags;
|
||||||
|
entry.mLastSeen = time(NULL);
|
||||||
|
|
||||||
|
mPeerQueue.push_back(entry);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bdPeerQueue::popPeer(bdId *id, uint32_t &flags)
|
||||||
|
{
|
||||||
|
if (mPeerQueue.size() > 0)
|
||||||
|
{
|
||||||
|
bdFriendEntry entry = mPeerQueue.front();
|
||||||
|
mPeerQueue.pop_front();
|
||||||
|
*id = entry.mPeerId;
|
||||||
|
flags = entry.mFlags;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,6 +84,20 @@ bool print(std::ostream &out);
|
|||||||
std::map<bdNodeId, bdFriendEntry> mPeers;
|
std::map<bdNodeId, bdFriendEntry> mPeers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class bdPeerQueue
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
bdPeerQueue();
|
||||||
|
|
||||||
|
bool queuePeer(const bdId *id, uint32_t flags);
|
||||||
|
bool popPeer(bdId *id, uint32_t &flags);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::list<bdFriendEntry> mPeerQueue;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -304,6 +304,8 @@ class bdQuerySummary
|
|||||||
#define BD_PROXY_CONNECTION_MID_POINT 2
|
#define BD_PROXY_CONNECTION_MID_POINT 2
|
||||||
#define BD_PROXY_CONNECTION_END_POINT 3
|
#define BD_PROXY_CONNECTION_END_POINT 3
|
||||||
|
|
||||||
|
#define BITDHT_INFO_CB_TYPE_BADPEER 1
|
||||||
|
|
||||||
class BitDhtCallback
|
class BitDhtCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -320,6 +322,9 @@ virtual int dhtValueCallback(const bdNodeId *id, std::string key, uint32_t statu
|
|||||||
virtual int dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId *destId,
|
virtual int dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId *destId,
|
||||||
uint32_t mode, uint32_t point, uint32_t param, uint32_t cbtype, uint32_t errcode) = 0; /* { return 0; } */
|
uint32_t mode, uint32_t point, uint32_t param, uint32_t cbtype, uint32_t errcode) = 0; /* { return 0; } */
|
||||||
|
|
||||||
|
// Generic Info callback - initially will be used to provide bad peers.
|
||||||
|
virtual int dhtInfoCallback(const bdId *id, uint32_t type, uint32_t flags, std::string info) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -327,6 +332,9 @@ class BitDhtInterface
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/* bad peer notification */
|
||||||
|
virtual void addBadPeer(const struct sockaddr_in &addr, uint32_t source, uint32_t reason, uint32_t age) = 0;
|
||||||
|
|
||||||
/* Friend Tracking */
|
/* Friend Tracking */
|
||||||
virtual void updateKnownPeer(const bdId *id, uint32_t type, uint32_t flags) = 0;
|
virtual void updateKnownPeer(const bdId *id, uint32_t type, uint32_t flags) = 0;
|
||||||
|
|
||||||
|
@ -158,6 +158,12 @@ bool bdNodeManager::setAttachMode(bool on)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Friend Tracking */
|
/* Friend Tracking */
|
||||||
|
void bdNodeManager::addBadPeer(const struct sockaddr_in &addr, uint32_t source, uint32_t reason, uint32_t age)
|
||||||
|
{
|
||||||
|
std::cerr << "bdNodeManager::addBadPeer() not implemented yet!";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
void bdNodeManager::updateKnownPeer(const bdId *id, uint32_t /* type */, uint32_t flags)
|
void bdNodeManager::updateKnownPeer(const bdId *id, uint32_t /* type */, uint32_t flags)
|
||||||
{
|
{
|
||||||
mFriendList.updatePeer(id, flags);
|
mFriendList.updatePeer(id, flags);
|
||||||
@ -624,6 +630,7 @@ int bdNodeManager::status()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
checkStatus();
|
checkStatus();
|
||||||
|
checkBadPeerStatus();
|
||||||
|
|
||||||
/* update the network numbers */
|
/* update the network numbers */
|
||||||
mNetworkSize = mNodeSpace.calcNetworkSize();
|
mNetworkSize = mNodeSpace.calcNetworkSize();
|
||||||
@ -927,6 +934,18 @@ bdNodeManager::checkPingStatus()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int bdNodeManager::checkBadPeerStatus()
|
||||||
|
{
|
||||||
|
bdId id;
|
||||||
|
uint32_t flags;
|
||||||
|
std::string nullstr;
|
||||||
|
|
||||||
|
while(mBadPeerQueue.popPeer(&id, flags))
|
||||||
|
{
|
||||||
|
doInfoCallback(&id, BITDHT_INFO_CB_TYPE_BADPEER, flags, nullstr);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int bdNodeManager::SearchOutOfDate()
|
int bdNodeManager::SearchOutOfDate()
|
||||||
{
|
{
|
||||||
@ -1141,6 +1160,23 @@ void bdNodeManager::doValueCallback(const bdNodeId *id, std::string key, uint32_
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void bdNodeManager::doInfoCallback(const bdId *id, uint32_t type, uint32_t flags, std::string info)
|
||||||
|
{
|
||||||
|
std::cerr << "bdNodeManager::doInfoCallback()";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
#ifdef DEBUG_MGR
|
||||||
|
#endif
|
||||||
|
/* search list */
|
||||||
|
std::list<BitDhtCallback *>::iterator it;
|
||||||
|
for(it = mCallbacks.begin(); it != mCallbacks.end(); it++)
|
||||||
|
{
|
||||||
|
(*it)->dhtInfoCallback(id, type, flags, info);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define BITDHT_IDENTITY_STRING_V1 "d1:"
|
#define BITDHT_IDENTITY_STRING_V1 "d1:"
|
||||||
#define BITDHT_IDENTITY_SIZE_V1 3
|
#define BITDHT_IDENTITY_SIZE_V1 3
|
||||||
#define BITDHT_PACKET_MIN_SIZE 4
|
#define BITDHT_PACKET_MIN_SIZE 4
|
||||||
|
@ -102,7 +102,10 @@ class bdNodeManager: public bdNode, public BitDhtInterface
|
|||||||
void iteration();
|
void iteration();
|
||||||
|
|
||||||
/***** Functions to Call down to bdNodeManager ****/
|
/***** Functions to Call down to bdNodeManager ****/
|
||||||
|
|
||||||
|
|
||||||
/* Friend Tracking */
|
/* Friend Tracking */
|
||||||
|
virtual void addBadPeer(const struct sockaddr_in &addr, uint32_t source, uint32_t reason, uint32_t age);
|
||||||
virtual void updateKnownPeer(const bdId *id, uint32_t type, uint32_t flags);
|
virtual void updateKnownPeer(const bdId *id, uint32_t type, uint32_t flags);
|
||||||
|
|
||||||
/* Request DHT Peer Lookup */
|
/* Request DHT Peer Lookup */
|
||||||
@ -152,10 +155,12 @@ int isBitDhtPacket(char *data, int size, struct sockaddr_in &from);
|
|||||||
void doNodeCallback(const bdId *id, uint32_t peerflags);
|
void doNodeCallback(const bdId *id, uint32_t peerflags);
|
||||||
void doPeerCallback(const bdId *id, uint32_t status);
|
void doPeerCallback(const bdId *id, uint32_t status);
|
||||||
void doValueCallback(const bdNodeId *id, std::string key, uint32_t status);
|
void doValueCallback(const bdNodeId *id, std::string key, uint32_t status);
|
||||||
|
void doInfoCallback(const bdId *id, uint32_t type, uint32_t flags, std::string info);
|
||||||
|
|
||||||
int status();
|
int status();
|
||||||
int checkStatus();
|
int checkStatus();
|
||||||
int checkPingStatus();
|
int checkPingStatus();
|
||||||
|
int checkBadPeerStatus();
|
||||||
int SearchOutOfDate();
|
int SearchOutOfDate();
|
||||||
void startQueries();
|
void startQueries();
|
||||||
|
|
||||||
|
@ -429,13 +429,15 @@ void bdNode::checkPotentialPeer(bdId *id, bdId *src)
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
#ifdef TEST_BAD_PEER
|
#ifdef TEST_BAD_PEER
|
||||||
std::cerr << "IN TEST MODE... so letting it through.";
|
std::cerr << "IN TEST MODE... Notifying, but letting it through.";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
|
|
||||||
|
mBadPeerQueue.queuePeer(id, 0);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
mFilterPeers->addBadPeer(id, 0);
|
mFilterPeers->addBadPeer(id, 0);
|
||||||
// Stores in queue for later callback and desemination around the network.
|
// Stores in queue for later callback and desemination around the network.
|
||||||
mBadPeerList->queuePeer(id, 0);
|
mBadPeerQueue.queuePeer(id, 0);
|
||||||
|
|
||||||
std::list<struct sockaddr_in> filteredIPs;
|
std::list<struct sockaddr_in> filteredIPs;
|
||||||
mFilterPeers->filteredIPs(filteredIPs);
|
mFilterPeers->filteredIPs(filteredIPs);
|
||||||
|
@ -244,6 +244,7 @@ void recvPkt(char *msg, int len, struct sockaddr_in addr);
|
|||||||
bdHashSpace mHashSpace;
|
bdHashSpace mHashSpace;
|
||||||
|
|
||||||
bdFriendList mFriendList;
|
bdFriendList mFriendList;
|
||||||
|
bdPeerQueue mBadPeerQueue;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -89,6 +89,14 @@ UdpBitDht::~UdpBitDht()
|
|||||||
|
|
||||||
/***** Functions to Call down to bdNodeManager ****/
|
/***** Functions to Call down to bdNodeManager ****/
|
||||||
/* Friend Tracking */
|
/* Friend Tracking */
|
||||||
|
void UdpBitDht::addBadPeer(const struct sockaddr_in &addr, uint32_t source, uint32_t reason, uint32_t age)
|
||||||
|
{
|
||||||
|
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
|
||||||
|
|
||||||
|
mBitDhtManager->addBadPeer(addr, source, reason, age);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void UdpBitDht::updateKnownPeer(const bdId *id, uint32_t type, uint32_t flags)
|
void UdpBitDht::updateKnownPeer(const bdId *id, uint32_t type, uint32_t flags)
|
||||||
{
|
{
|
||||||
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
|
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
|
||||||
|
@ -59,6 +59,7 @@ virtual ~UdpBitDht();
|
|||||||
/***** Functions to Call down to bdNodeManager ****/
|
/***** Functions to Call down to bdNodeManager ****/
|
||||||
|
|
||||||
/* Friend Tracking */
|
/* Friend Tracking */
|
||||||
|
virtual void addBadPeer(const struct sockaddr_in &addr, uint32_t source, uint32_t reason, uint32_t age);
|
||||||
virtual void updateKnownPeer(const bdId *id, uint32_t type, uint32_t flags);
|
virtual void updateKnownPeer(const bdId *id, uint32_t type, uint32_t flags);
|
||||||
|
|
||||||
/* Request DHT Peer Lookup */
|
/* Request DHT Peer Lookup */
|
||||||
|
Loading…
Reference in New Issue
Block a user