mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-14 08:59:50 -05:00
Added Function to allow Services to get list of peers currently connected on a service.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7208 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
a9a1b054dd
commit
efe9503c3a
@ -630,6 +630,7 @@ void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId,
|
||||
std::cerr << std::endl;
|
||||
// removal
|
||||
changes[*it1] = false;
|
||||
filterChangeRemoved_locked(peerId, *it1);
|
||||
++it1;
|
||||
}
|
||||
else if (*it2 < *it1)
|
||||
@ -637,6 +638,7 @@ void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId,
|
||||
std::cerr << "Added Service: " << *it2;
|
||||
std::cerr << std::endl;
|
||||
// addition.
|
||||
filterChangeAdded_locked(peerId, *it2);
|
||||
changes[*it2] = true;
|
||||
++it2;
|
||||
}
|
||||
@ -654,6 +656,7 @@ void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId,
|
||||
std::cerr << std::endl;
|
||||
// removal
|
||||
changes[*it1] = false;
|
||||
filterChangeRemoved_locked(peerId, *it1);
|
||||
}
|
||||
|
||||
for(; it2 != eit2; it2++)
|
||||
@ -662,8 +665,11 @@ void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId,
|
||||
std::cerr << std::endl;
|
||||
// addition.
|
||||
changes[*it2] = true;
|
||||
filterChangeAdded_locked(peerId, *it2);
|
||||
}
|
||||
|
||||
// Can remove changes map... as only used below.
|
||||
#if 0
|
||||
// now we to store for later notifications.
|
||||
std::map<uint32_t, bool>::const_iterator cit;
|
||||
for(cit = changes.begin(); cit != changes.end(); cit++)
|
||||
@ -678,6 +684,8 @@ void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId,
|
||||
notes.mRemoved.insert(peerId);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -734,6 +742,83 @@ void p3ServiceControl::removePeer(const RsPeerId &peerId)
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/****************************************************************************/
|
||||
// need to provide list of connected peers per service.
|
||||
// these are collected here.
|
||||
|
||||
void p3ServiceControl::filterChangeRemoved_locked(const RsPeerId &peerId, uint32_t serviceId)
|
||||
{
|
||||
std::cerr << "p3ServiceControl::filterChangeRemoved_locked(" << peerId.toStdString();
|
||||
std::cerr << ", " << serviceId << ")";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::map<uint32_t, std::set<RsPeerId> >::iterator mit;
|
||||
|
||||
std::set<RsPeerId> &peerSet = mServicePeerMap[serviceId];
|
||||
std::set<RsPeerId>::iterator sit;
|
||||
|
||||
sit = peerSet.find(peerId);
|
||||
if (sit != peerSet.end())
|
||||
{
|
||||
peerSet.erase(sit);
|
||||
}
|
||||
else
|
||||
{
|
||||
// ERROR
|
||||
std::cerr << "p3ServiceControl::filterChangeRemoved_locked() ERROR NOT FOUND";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
|
||||
// Add to Notifications too.
|
||||
ServiceNotifications ¬es = mNotifications[serviceId];
|
||||
notes.mRemoved.insert(peerId);
|
||||
}
|
||||
|
||||
|
||||
void p3ServiceControl::filterChangeAdded_locked(const RsPeerId &peerId, uint32_t serviceId)
|
||||
{
|
||||
std::cerr << "p3ServiceControl::filterChangeAdded_locked(" << peerId.toStdString();
|
||||
std::cerr << ", " << serviceId << ")";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::map<uint32_t, std::set<RsPeerId> >::iterator mit;
|
||||
|
||||
std::set<RsPeerId> &peerSet = mServicePeerMap[serviceId];
|
||||
|
||||
// This bit is only for error checking.
|
||||
std::set<RsPeerId>::iterator sit = peerSet.find(peerId);
|
||||
if (sit != peerSet.end())
|
||||
{
|
||||
// ERROR.
|
||||
std::cerr << "p3ServiceControl::filterChangeAdded_locked() ERROR NOT FOUND";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
peerSet.insert(peerId);
|
||||
|
||||
// Add to Notifications too.
|
||||
ServiceNotifications ¬es = mNotifications[serviceId];
|
||||
notes.mAdded.insert(peerId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void p3ServiceControl::getPeersConnected(const uint32_t serviceId, std::set<RsPeerId> &peerSet)
|
||||
{
|
||||
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
|
||||
|
||||
std::map<uint32_t, std::set<RsPeerId> >::iterator mit;
|
||||
mit = mServicePeerMap.find(serviceId);
|
||||
if (mit != mServicePeerMap.end())
|
||||
{
|
||||
peerSet = mit->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
peerSet.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/****************************************************************************/
|
||||
@ -832,6 +917,8 @@ void p3ServiceControl::updatePeerDisconnect(const RsPeerId &peerId)
|
||||
// Update Peer status.
|
||||
void p3ServiceControl::updatePeerNew(const RsPeerId &peerId)
|
||||
{
|
||||
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
|
||||
|
||||
std::cerr << "p3ServiceControl::updatePeerNew(): " << peerId.toStdString();
|
||||
std::cerr << std::endl;
|
||||
|
||||
@ -845,6 +932,8 @@ void p3ServiceControl::updatePeerNew(const RsPeerId &peerId)
|
||||
|
||||
void p3ServiceControl::updatePeerRemoved(const RsPeerId &peerId)
|
||||
{
|
||||
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
|
||||
|
||||
std::cerr << "p3ServiceControl::updatePeerRemoved(): " << peerId.toStdString();
|
||||
std::cerr << std::endl;
|
||||
|
||||
|
@ -86,6 +86,9 @@ virtual bool getServicesProvided(const RsPeerId &peerId, RsPeerServiceInfo &info
|
||||
virtual bool getServicePermissions(uint32_t serviceId, RsServicePermissions &permissions);
|
||||
virtual bool updateServicePermissions(uint32_t serviceId, const RsServicePermissions &permissions);
|
||||
|
||||
// Get List of Peers using this Service.
|
||||
virtual void getPeersConnected(const uint32_t serviceId, std::set<RsPeerId> &peerSet);
|
||||
|
||||
/**
|
||||
* Registration for all Services.
|
||||
*/
|
||||
@ -127,24 +130,28 @@ private:
|
||||
void notifyServices();
|
||||
void notifyAboutFriends();
|
||||
|
||||
bool createDefaultPermissions_locked(uint32_t serviceId, std::string serviceName, bool defaultOn);
|
||||
void updatePeerConnect(const RsPeerId &peerId);
|
||||
void updatePeerDisconnect(const RsPeerId &peerId);
|
||||
void updatePeerNew(const RsPeerId &peerId);
|
||||
void updatePeerRemoved(const RsPeerId &peerId);
|
||||
|
||||
void removePeer(const RsPeerId &peerId);
|
||||
|
||||
|
||||
bool updateAllFilters();
|
||||
bool updateAllFilters_locked();
|
||||
bool updateFilterByPeer(const RsPeerId &peerId);
|
||||
bool updateFilterByPeer_locked(const RsPeerId &peerId);
|
||||
|
||||
void removePeer(const RsPeerId &peerId);
|
||||
|
||||
void recordFilterChanges_locked(const RsPeerId &peerId,
|
||||
void recordFilterChanges_locked(const RsPeerId &peerId,
|
||||
ServicePeerFilter &originalFilter, ServicePeerFilter &updatedFilter);
|
||||
|
||||
void updatePeerConnect(const RsPeerId &peerId);
|
||||
void updatePeerDisconnect(const RsPeerId &peerId);
|
||||
void updatePeerNew(const RsPeerId &peerId);
|
||||
void updatePeerRemoved(const RsPeerId &peerId);
|
||||
|
||||
// Called from recordFilterChanges.
|
||||
void filterChangeAdded_locked(const RsPeerId &peerId, uint32_t serviceId);
|
||||
void filterChangeRemoved_locked(const RsPeerId &peerId, uint32_t serviceId);
|
||||
|
||||
bool createDefaultPermissions_locked(uint32_t serviceId, std::string serviceName, bool defaultOn);
|
||||
bool peerHasPermissionForService_locked(const RsPeerId &peerId, uint32_t serviceId);
|
||||
|
||||
p3LinkMgr *mLinkMgr;
|
||||
@ -166,6 +173,9 @@ bool peerHasPermissionForService_locked(const RsPeerId &peerId, uint32_t service
|
||||
std::map<uint32_t, ServiceNotifications> mNotifications;
|
||||
std::list<pqiServicePeer> mFriendNotifications;
|
||||
|
||||
// Map of Connected Peers per Service.
|
||||
std::map<uint32_t, std::set<RsPeerId> > mServicePeerMap;
|
||||
|
||||
// Separate mutex here - must not hold both at the same time!
|
||||
RsMutex mMonitorMtx; /* below is protected */
|
||||
std::multimap<uint32_t, pqiServiceMonitor *> mMonitors;
|
||||
|
@ -111,6 +111,8 @@ virtual bool getServicesProvided(const RsPeerId &peerId, RsPeerServiceInfo &info
|
||||
virtual bool getServicePermissions(uint32_t serviceId, RsServicePermissions &permissions) = 0;
|
||||
virtual bool updateServicePermissions(uint32_t serviceId, const RsServicePermissions &permissions) = 0;
|
||||
|
||||
virtual void getPeersConnected(const uint32_t serviceId, std::set<RsPeerId> &peerSet) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user