mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-19 11:54:22 -04:00
added mechanism to allow services to document the names of their items, and improved bandwidth graph to show names for GXS services. Other services still need to supply their own names
This commit is contained in:
parent
f406b81238
commit
5f8bf03dfe
15 changed files with 280 additions and 81 deletions
|
@ -328,6 +328,23 @@ RsGxsNetService::RsGxsNetService(uint16_t servType, RsGeneralDataService *gds,
|
|||
mUpdateCounter = 0;
|
||||
}
|
||||
|
||||
void RsGxsNetService::getItemNames(std::map<uint8_t,std::string>& names) const
|
||||
{
|
||||
names.clear();
|
||||
|
||||
names[RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM ] = "Group Sync Request" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM ] = "Group Sync" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM ] = "Group Stats" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_GRP_ITEM ] = "Group Data" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_ENCRYPTED_DATA_ITEM ] = "Encrypted data" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_SESSION_KEY_ITEM ] = "Session Key" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM ] = "Message Sync" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM ] = "Message Sync Request" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_MSG_ITEM ] = "Message Data" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM ] = "Transaction" ;
|
||||
names[RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM ] = "Publish key" ;
|
||||
}
|
||||
|
||||
RsGxsNetService::~RsGxsNetService()
|
||||
{
|
||||
RS_STACK_MUTEX(mNxsMutex) ;
|
||||
|
|
|
@ -99,6 +99,7 @@ public:
|
|||
|
||||
virtual RsServiceInfo getServiceInfo() { return mServiceInfo; }
|
||||
|
||||
virtual void getItemNames(std::map<uint8_t,std::string>& names) const ;
|
||||
public:
|
||||
|
||||
|
||||
|
|
|
@ -29,7 +29,9 @@
|
|||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rsnxsitems.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
#include "pqi/pqiservice.h"
|
||||
|
||||
/*******************************/
|
||||
// #define SERVICECONTROL_DEBUG 1
|
||||
|
@ -138,7 +140,7 @@ public:
|
|||
std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl;
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= getRawUInt32(data, rssize, &offset, &item->mServiceId);
|
||||
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->mServiceName);
|
||||
|
@ -248,6 +250,13 @@ const RsPeerId& p3ServiceControl::getOwnId()
|
|||
return mOwnPeerId;
|
||||
}
|
||||
|
||||
bool p3ServiceControl::getServiceItemNames(uint32_t serviceId,std::map<uint8_t,std::string>& names)
|
||||
{
|
||||
if(mServiceServer != NULL)
|
||||
return mServiceServer->getServiceItemNames(serviceId,names) ;
|
||||
|
||||
return false ;
|
||||
}
|
||||
|
||||
/* Interface for Services */
|
||||
bool p3ServiceControl::registerService(const RsServiceInfo &info, bool defaultOn)
|
||||
|
@ -537,7 +546,7 @@ bool p3ServiceControl::updateServicePermissions(uint32_t serviceId, const RsServ
|
|||
{
|
||||
for(pit = onlinePeers.begin(); pit != onlinePeers.end(); ++pit)
|
||||
{
|
||||
if (it->second.peerHasPermission(*pit) !=
|
||||
if (it->second.peerHasPermission(*pit) !=
|
||||
permissions.peerHasPermission(*pit))
|
||||
{
|
||||
mUpdatedSet.insert(*pit);
|
||||
|
@ -597,7 +606,7 @@ bool p3ServiceControl::checkFilter(uint32_t serviceId, const RsPeerId &peerId)
|
|||
#endif
|
||||
|
||||
// must allow ServiceInfo through, or we have nothing!
|
||||
#define FULLID_SERVICEINFO ((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + ((RS_SERVICE_TYPE_SERVICEINFO) << 8))
|
||||
#define FULLID_SERVICEINFO ((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + ((RS_SERVICE_TYPE_SERVICEINFO) << 8))
|
||||
|
||||
//if (serviceId == RS_SERVICE_TYPE_SERVICEINFO)
|
||||
if (serviceId == FULLID_SERVICEINFO)
|
||||
|
@ -691,21 +700,21 @@ bool ServiceInfoCompatible(const RsServiceInfo &info1, const RsServiceInfo &info
|
|||
}
|
||||
|
||||
// ensure that info1 meets minimum requirements for info2
|
||||
if (!versionOkay(info1.mVersionMajor, info1.mVersionMinor,
|
||||
if (!versionOkay(info1.mVersionMajor, info1.mVersionMinor,
|
||||
info2.mMinVersionMajor, info2.mMinVersionMinor))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// ensure that info2 meets minimum requirements for info1
|
||||
if (!versionOkay(info2.mVersionMajor, info2.mVersionMinor,
|
||||
if (!versionOkay(info2.mVersionMajor, info2.mVersionMinor,
|
||||
info1.mMinVersionMajor, info1.mMinVersionMinor))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool p3ServiceControl::updateFilterByPeer(const RsPeerId &peerId)
|
||||
{
|
||||
|
@ -790,8 +799,8 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId)
|
|||
std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Empty ... Clearing";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
// empty, remove...
|
||||
|
||||
// empty, remove...
|
||||
recordFilterChanges_locked(peerId, originalFilter, peerFilter);
|
||||
if (fit != mPeerFilterMap.end())
|
||||
{
|
||||
|
@ -882,7 +891,7 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId)
|
|||
std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Empty(2) ... Clearing";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
if (fit != mPeerFilterMap.end())
|
||||
{
|
||||
mPeerFilterMap.erase(fit);
|
||||
|
@ -900,7 +909,7 @@ bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId)
|
|||
return true;
|
||||
}
|
||||
|
||||
void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId,
|
||||
void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId,
|
||||
ServicePeerFilter &originalFilter, ServicePeerFilter &updatedFilter)
|
||||
{
|
||||
#ifdef SERVICECONTROL_DEBUG
|
||||
|
@ -1202,7 +1211,7 @@ bool p3ServiceControl::loadList(std::list<RsItem *>& loadList)
|
|||
|
||||
if(item != NULL)
|
||||
mServicePermissionMap[item->mServiceId] = *item ;
|
||||
|
||||
|
||||
delete *it ;
|
||||
}
|
||||
|
||||
|
@ -1396,49 +1405,49 @@ void p3ServiceControl::notifyServices()
|
|||
std::cerr << "p3ServiceControl::notifyServices(): Noone Monitoring ... skipping";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
std::list<pqiServicePeer> peers;
|
||||
std::set<RsPeerId>::const_iterator pit;
|
||||
for(pit = it->second.mAdded.begin();
|
||||
for(pit = it->second.mAdded.begin();
|
||||
pit != it->second.mAdded.end(); ++pit)
|
||||
{
|
||||
pqiServicePeer peer;
|
||||
peer.id = *pit;
|
||||
peer.actions = RS_SERVICE_PEER_CONNECTED;
|
||||
|
||||
|
||||
peers.push_back(peer);
|
||||
|
||||
|
||||
#ifdef SERVICECONTROL_DEBUG
|
||||
std::cerr << "p3ServiceControl::notifyServices(): Peer: " << *pit << " CONNECTED";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
for(pit = it->second.mRemoved.begin();
|
||||
|
||||
for(pit = it->second.mRemoved.begin();
|
||||
pit != it->second.mRemoved.end(); ++pit)
|
||||
{
|
||||
pqiServicePeer peer;
|
||||
peer.id = *pit;
|
||||
peer.actions = RS_SERVICE_PEER_DISCONNECTED;
|
||||
|
||||
|
||||
peers.push_back(peer);
|
||||
|
||||
|
||||
#ifdef SERVICECONTROL_DEBUG
|
||||
std::cerr << "p3ServiceControl::notifyServices(): Peer: " << *pit << " DISCONNECTED";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
for(; sit != eit; ++sit)
|
||||
{
|
||||
#ifdef SERVICECONTROL_DEBUG
|
||||
std::cerr << "p3ServiceControl::notifyServices(): Sending to Monitoring Service";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
sit->second->statusChange(peers);
|
||||
}
|
||||
}
|
||||
|
@ -1500,17 +1509,17 @@ void RsServicePermissions::resetPermission(const RsPeerId& peerId)
|
|||
}
|
||||
|
||||
RsServiceInfo::RsServiceInfo(
|
||||
const uint16_t service_type,
|
||||
const std::string service_name,
|
||||
const uint16_t service_type,
|
||||
const std::string service_name,
|
||||
const uint16_t version_major,
|
||||
const uint16_t version_minor,
|
||||
const uint16_t min_version_major,
|
||||
const uint16_t min_version_minor)
|
||||
:mServiceName(service_name),
|
||||
mServiceType((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + (((uint32_t) service_type) << 8)),
|
||||
mVersionMajor(version_major),
|
||||
:mServiceName(service_name),
|
||||
mServiceType((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + (((uint32_t) service_type) << 8)),
|
||||
mVersionMajor(version_major),
|
||||
mVersionMinor(version_minor),
|
||||
mMinVersionMajor(min_version_major),
|
||||
mMinVersionMajor(min_version_major),
|
||||
mMinVersionMinor(min_version_minor)
|
||||
{
|
||||
return;
|
||||
|
@ -1518,7 +1527,7 @@ RsServiceInfo::RsServiceInfo(
|
|||
|
||||
|
||||
RsServiceInfo::RsServiceInfo()
|
||||
:mServiceName("unknown"),
|
||||
:mServiceName("unknown"),
|
||||
mServiceType(0),
|
||||
mVersionMajor(0),
|
||||
mVersionMinor(0),
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
#include "pqi/pqiservicemonitor.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
|
||||
class p3ServiceServer ;
|
||||
|
||||
class ServiceNotifications
|
||||
{
|
||||
public:
|
||||
|
@ -101,6 +103,9 @@ virtual bool updateServicePermissions(uint32_t serviceId, const RsServicePermiss
|
|||
virtual void getPeersConnected(const uint32_t serviceId, std::set<RsPeerId> &peerSet);
|
||||
virtual bool isPeerConnected(const uint32_t serviceId, const RsPeerId &peerId);
|
||||
|
||||
// Gets the list of items used by that service
|
||||
virtual bool getServiceItemNames(uint32_t serviceId,std::map<uint8_t,std::string>& names) ;
|
||||
|
||||
/**
|
||||
* Registration for all Services.
|
||||
*/
|
||||
|
@ -132,6 +137,8 @@ virtual bool updateServicesProvided(const RsPeerId &peerId, const RsPeerServiceI
|
|||
// pqiMonitor.
|
||||
virtual void statusChange(const std::list<pqipeer> &plist);
|
||||
|
||||
virtual void setServiceServer(p3ServiceServer *p) { mServiceServer = p ; }
|
||||
|
||||
protected:
|
||||
// configuration.
|
||||
virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
|
||||
|
@ -196,6 +203,7 @@ bool peerHasPermissionForService_locked(const RsPeerId &peerId, uint32_t service
|
|||
// Below here is saved in Configuration.
|
||||
std::map<uint32_t, RsServicePermissions> mServicePermissionMap;
|
||||
|
||||
p3ServiceServer *mServiceServer ;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -79,11 +79,26 @@ int p3ServiceServer::addService(pqiService *ts, bool defaultOn)
|
|||
services[info.mServiceType] = ts;
|
||||
|
||||
// This doesn't need to be in Mutex.
|
||||
mServiceControl->registerService(info, defaultOn);
|
||||
mServiceControl->registerService(info,defaultOn);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool p3ServiceServer::getServiceItemNames(uint32_t service_type,std::map<uint8_t,std::string>& names)
|
||||
{
|
||||
RsStackMutex stack(srvMtx); /********* LOCKED *********/
|
||||
|
||||
std::map<uint32_t, pqiService *>::iterator it=services.find(service_type) ;
|
||||
|
||||
if(it != services.end())
|
||||
{
|
||||
it->second->getItemNames(names) ;
|
||||
return true ;
|
||||
}
|
||||
else
|
||||
return false ;
|
||||
}
|
||||
|
||||
int p3ServiceServer::removeService(pqiService *ts)
|
||||
{
|
||||
RsStackMutex stack(srvMtx); /********* LOCKED *********/
|
||||
|
|
|
@ -60,24 +60,26 @@ class p3ServiceServerIface;
|
|||
|
||||
class pqiService
|
||||
{
|
||||
protected:
|
||||
protected:
|
||||
|
||||
pqiService() // our type of packets.
|
||||
:mServiceServer(NULL) { return; }
|
||||
:mServiceServer(NULL) { return; }
|
||||
|
||||
virtual ~pqiService() { return; }
|
||||
virtual ~pqiService() { return; }
|
||||
|
||||
public:
|
||||
void setServiceServer(p3ServiceServerIface *server);
|
||||
//
|
||||
virtual bool recv(RsRawItem *) = 0;
|
||||
virtual bool send(RsRawItem *item);
|
||||
public:
|
||||
void setServiceServer(p3ServiceServerIface *server);
|
||||
//
|
||||
virtual bool recv(RsRawItem *) = 0;
|
||||
virtual bool send(RsRawItem *item);
|
||||
|
||||
virtual RsServiceInfo getServiceInfo() = 0;
|
||||
virtual RsServiceInfo getServiceInfo() = 0;
|
||||
|
||||
virtual int tick() { return 0; }
|
||||
virtual int tick() { return 0; }
|
||||
|
||||
private:
|
||||
virtual void getItemNames(std::map<uint8_t,std::string>& names) const {} // This does nothing by default. Service should derive it in order to give info for the UI
|
||||
|
||||
private:
|
||||
p3ServiceServerIface *mServiceServer; // const, no need for mutex.
|
||||
};
|
||||
|
||||
|
@ -97,10 +99,10 @@ public:
|
|||
virtual ~p3ServiceServerIface() {}
|
||||
|
||||
|
||||
virtual bool recvItem(RsRawItem *) = 0;
|
||||
virtual bool sendItem(RsRawItem *) = 0;
|
||||
|
||||
virtual bool recvItem(RsRawItem *) = 0;
|
||||
virtual bool sendItem(RsRawItem *) = 0;
|
||||
|
||||
virtual bool getServiceItemNames(uint32_t service_type,std::map<uint8_t,std::string>& names) =0;
|
||||
};
|
||||
|
||||
class p3ServiceServer : public p3ServiceServerIface
|
||||
|
@ -108,13 +110,15 @@ class p3ServiceServer : public p3ServiceServerIface
|
|||
public:
|
||||
p3ServiceServer(pqiPublisher *pub, p3ServiceControl *ctrl);
|
||||
|
||||
int addService(pqiService *, bool defaultOn);
|
||||
int removeService(pqiService *);
|
||||
int addService(pqiService *, bool defaultOn);
|
||||
int removeService(pqiService *);
|
||||
|
||||
bool recvItem(RsRawItem *);
|
||||
bool sendItem(RsRawItem *);
|
||||
bool recvItem(RsRawItem *);
|
||||
bool sendItem(RsRawItem *);
|
||||
|
||||
int tick();
|
||||
bool getServiceItemNames(uint32_t service_type, std::map<uint8_t,std::string>& names) ;
|
||||
|
||||
int tick();
|
||||
public:
|
||||
|
||||
private:
|
||||
|
@ -122,7 +126,7 @@ private:
|
|||
pqiPublisher *mPublisher; // constant no need for mutex.
|
||||
p3ServiceControl *mServiceControl;
|
||||
|
||||
RsMutex srvMtx;
|
||||
RsMutex srvMtx;
|
||||
std::map<uint32_t, pqiService *> services;
|
||||
|
||||
};
|
||||
|
|
|
@ -109,6 +109,7 @@ virtual ~RsServiceControl() { return; }
|
|||
|
||||
virtual bool getOwnServices(RsPeerServiceInfo &info) = 0;
|
||||
virtual std::string getServiceName(uint32_t service_id) = 0;
|
||||
virtual bool getServiceItemNames(uint32_t service_id,std::map<uint8_t,std::string>& names) = 0;
|
||||
|
||||
virtual bool getServicesAllowed(const RsPeerId &peerId, RsPeerServiceInfo &info) = 0;
|
||||
virtual bool getServicesProvided(const RsPeerId &peerId, RsPeerServiceInfo &info) = 0;
|
||||
|
|
|
@ -1243,6 +1243,8 @@ int RsServer::StartupRetroShare()
|
|||
pqih = new pqisslpersongrp(serviceCtrl, flags, mPeerMgr);
|
||||
//pqih = new pqipersongrpDummy(none, flags);
|
||||
|
||||
serviceCtrl->setServiceServer(pqih) ;
|
||||
|
||||
/****** New Ft Server **** !!! */
|
||||
ftServer *ftserver = new ftServer(mPeerMgr, serviceCtrl);
|
||||
ftserver->setConfigDirectory(rsAccounts->PathAccountDirectory());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue