Added ServiceControl + ServiceInfo. Basics are working, but still a lot to do!

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7196 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2014-03-22 03:53:44 +00:00
parent a4b54e1021
commit 83a78bcaee
71 changed files with 3168 additions and 209 deletions

View File

@ -64,8 +64,8 @@ static const time_t FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD = 5 ; // low priorit
/* Setup */
ftServer::ftServer(p3PeerMgr *pm, p3LinkMgr *lm)
: p3Service(RS_SERVICE_TYPE_FILE_TRANSFER),
mPeerMgr(pm),
: p3Service(),
mPeerMgr(pm),
mLinkMgr(lm),
mCacheStrapper(NULL),
mFiStore(NULL), mFiMon(NULL),
@ -77,6 +77,23 @@ ftServer::ftServer(p3PeerMgr *pm, p3LinkMgr *lm)
addSerialType(new RsFileTransferSerialiser()) ;
}
const std::string FILE_TRANSFER_APP_NAME = "ft";
const uint16_t FILE_TRANSFER_APP_MAJOR_VERSION = 1;
const uint16_t FILE_TRANSFER_APP_MINOR_VERSION = 0;
const uint16_t FILE_TRANSFER_MIN_MAJOR_VERSION = 1;
const uint16_t FILE_TRANSFER_MIN_MINOR_VERSION = 0;
RsServiceInfo ftServer::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_TYPE_FILE_TRANSFER,
FILE_TRANSFER_APP_NAME,
FILE_TRANSFER_APP_MAJOR_VERSION,
FILE_TRANSFER_APP_MINOR_VERSION,
FILE_TRANSFER_MIN_MAJOR_VERSION,
FILE_TRANSFER_MIN_MINOR_VERSION);
}
void ftServer::setConfigDirectory(std::string path)
{
mConfigPath = path;

View File

@ -84,6 +84,7 @@ class ftServer: public p3Service, public RsFiles, public ftDataSend, public RsTu
/***************************************************************/
ftServer(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr);
virtual RsServiceInfo getServiceInfo();
/* Assign important variables */
void setConfigDirectory(std::string path);

View File

@ -133,6 +133,11 @@ public:
virtual ~RsGenExchange();
// Convention that this is implemented here.
// and passes to network service.
virtual RsServiceInfo getServiceInfo() = 0;
/** S: Observer implementation **/
/*!

View File

@ -41,11 +41,14 @@
const uint32_t RsGxsNetService::FRAGMENT_SIZE = 150000;
RsGxsNetService::RsGxsNetService(uint16_t servType, RsGeneralDataService *gds,
RsNxsNetMgr *netMgr, RsNxsObserver *nxsObs, RsGixsReputation* reputations, RsGcxs* circles, bool grpAutoSync)
: p3Config(servType), p3ThreadedService(servType),
RsNxsNetMgr *netMgr, RsNxsObserver *nxsObs,
const RsServiceInfo serviceInfo,
RsGixsReputation* reputations, RsGcxs* circles, bool grpAutoSync)
: p3Config(servType), p3ThreadedService(),
mTransactionTimeOut(TRANSAC_TIMEOUT), mServType(servType), mDataStore(gds), mTransactionN(0),
mObserver(nxsObs), mNxsMutex("RsGxsNetService"), mNetMgr(netMgr), mSYNC_PERIOD(SYNC_PERIOD),
mSyncTs(0), mReputations(reputations), mCircles(circles), mGrpAutoSync(grpAutoSync), mGrpServerUpdateItem(NULL)
mSyncTs(0), mReputations(reputations), mCircles(circles), mGrpAutoSync(grpAutoSync), mGrpServerUpdateItem(NULL),
mServiceInfo(serviceInfo)
{
addSerialType(new RsNxsSerialiser(mServType));

View File

@ -73,11 +73,16 @@ public:
* @param nxsObs observer will be notified whenever new messages/grps
* arrive
*/
RsGxsNetService(uint16_t servType, RsGeneralDataService* gds, RsNxsNetMgr* netMgr,
RsNxsObserver* nxsObs = NULL, RsGixsReputation* repuations = NULL, RsGcxs* circles = NULL, bool grpAutoSync = true);
RsGxsNetService(uint16_t servType, RsGeneralDataService *gds,
RsNxsNetMgr *netMgr,
RsNxsObserver *nxsObs, // used to be = NULL.
const RsServiceInfo serviceInfo,
RsGixsReputation* reputations = NULL, RsGcxs* circles = NULL, bool grpAutoSync = true);
virtual ~RsGxsNetService();
virtual RsServiceInfo getServiceInfo() { return mServiceInfo; }
public:
@ -452,6 +457,7 @@ private:
ClientGrpMap mClientGrpUpdateMap;
RsGxsServerGrpUpdateItem* mGrpServerUpdateItem;
RsServiceInfo mServiceInfo;
};
#endif // RSGXSNETSERVICE_H

View File

@ -119,7 +119,8 @@ PUBLIC_HEADERS = retroshare/rsdisc.h \
retroshare/rstypes.h \
retroshare/rsdht.h \
retroshare/rsrtt.h \
retroshare/rsconfig.h
retroshare/rsconfig.h \
retroshare/rsservicecontrol.h \
HEADERS += plugins/pluginmanager.h \
@ -383,7 +384,8 @@ HEADERS += pqi/authssl.h \
pqi/pqithreadstreamer.h \
pqi/pqiqosstreamer.h \
pqi/sslfns.h \
pqi/pqinetstatebox.h
pqi/pqinetstatebox.h \
pqi/p3servicecontrol.h \
# pqi/p3dhtmgr.h \
@ -410,7 +412,9 @@ HEADERS += serialiser/rsbaseserial.h \
serialiser/rstlvkeys.h \
serialiser/rstlvkvwide.h \
serialiser/rstlvtypes.h \
serialiser/rstlvgenericparam.h \
serialiser/rstlvgenericmap.h \
serialiser/rstlvgenericmap.inl \
serialiser/rstlvmaps.h \
serialiser/rstlvutil.h \
serialiser/rstlvbanlist.h \
@ -420,7 +424,8 @@ HEADERS += serialiser/rsbaseserial.h \
serialiser/rsheartbeatitems.h \
serialiser/rsrttitems.h \
serialiser/rsgxsrecognitems.h \
serialiser/rsgxsupdateitems.h
serialiser/rsgxsupdateitems.h \
serialiser/rsserviceinfoitems.h \
HEADERS += services/p3chatservice.h \
services/p3msgservice.h \
@ -431,6 +436,7 @@ HEADERS += services/p3chatservice.h \
services/p3discovery2.h \
services/p3heartbeat.h \
services/p3rtt.h \
services/p3serviceinfo.cc \
HEADERS += turtle/p3turtle.h \
turtle/rsturtleitem.h \
@ -509,7 +515,8 @@ SOURCES += pqi/authgpg.cc \
pqi/pqithreadstreamer.cc \
pqi/pqiqosstreamer.cc \
pqi/sslfns.cc \
pqi/pqinetstatebox.cc
pqi/pqinetstatebox.cc \
pqi/p3servicecontrol.cc \
# pqi/p3dhtmgr.cc \
@ -545,7 +552,7 @@ SOURCES += serialiser/rsbaseserial.cc \
serialiser/rstlvkeys.cc \
serialiser/rstlvkvwide.cc \
serialiser/rstlvtypes.cc \
serialiser/rstlvgenericmap.cc \
serialiser/rstlvgenericparam.cc \
serialiser/rstlvutil.cc \
serialiser/rstlvbanlist.cc \
serialiser/rsbanlistitems.cc \
@ -554,7 +561,8 @@ SOURCES += serialiser/rsbaseserial.cc \
serialiser/rsheartbeatitems.cc \
serialiser/rsrttitems.cc \
serialiser/rsgxsrecognitems.cc \
serialiser/rsgxsupdateitems.cc
serialiser/rsgxsupdateitems.cc \
serialiser/rsserviceinfoitems.cc \
SOURCES += services/p3chatservice.cc \
services/p3msgservice.cc \
@ -565,6 +573,7 @@ SOURCES += services/p3chatservice.cc \
services/p3discovery2.cc \
services/p3heartbeat.cc \
services/p3rtt.cc \
services/p3serviceinfo.cc \
SOURCES += turtle/p3turtle.cc \
turtle/rsturtleitem.cc

View File

@ -410,7 +410,7 @@ void RsPluginManager::registerClientServices(p3ServiceServer *pqih)
for(uint32_t i=0;i<_plugins.size();++i)
if(_plugins[i].plugin != NULL && _plugins[i].plugin->rs_pqi_service() != NULL)
{
pqih->addService(_plugins[i].plugin->rs_pqi_service()) ;
pqih->addService(_plugins[i].plugin->rs_pqi_service(), true) ;
std::cerr << " Added pqi service for plugin " << _plugins[i].plugin->getPluginName() << std::endl;
}
}
@ -534,7 +534,7 @@ RsCacheService::RsCacheService(uint16_t service_type,uint32_t config_type,uint32
}
RsPQIService::RsPQIService(uint16_t service_type,uint32_t config_type,uint32_t /*tick_delay_in_seconds*/, RsPluginHandler* /*pgHandler*/)
: p3Service(service_type),p3Config(config_type)
: p3Service(),p3Config(config_type)
{
}

View File

@ -0,0 +1,920 @@
/*
* libretroshare/src/pqi: p3servicecontrol.cc
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2014 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.1 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".
*
*/
#include "p3servicecontrol.h"
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
RsServiceControl *rsServiceControl = NULL;
p3ServiceControl::p3ServiceControl(uint32_t configId)
:RsServiceControl(), /* p3Config(configId), pqiMonitor(), */
mCtrlMtx("p3ServiceControl")
{
}
/* Interface for Services */
bool p3ServiceControl::registerService(const RsServiceInfo &info, bool defaultOn)
{
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
std::map<uint32_t, RsServiceInfo>::iterator it;
it = mOwnServices.find(info.mServiceType);
if (it != mOwnServices.end())
{
std::cerr << "p3ServiceControl::registerService() ERROR Duplicate Service ID";
std::cerr << std::endl;
return false;
}
/* sanity check ServiceInfo */
mOwnServices[info.mServiceType] = info;
std::cerr << "p3ServiceControl::registerService() Registered ServiceID: " << info.mServiceType;
std::cerr << std::endl;
std::cerr << "p3ServiceControl::registerService() ServiceName: " << info.mServiceName;
std::cerr << std::endl;
/* create default permissions for this service
* this will be overwritten by configuration (if it exists).
*/
createDefaultPermissions_locked(info.mServiceType, info.mServiceName, defaultOn);
return true;
}
bool p3ServiceControl::deregisterService(uint32_t serviceId)
{
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
std::map<uint32_t, RsServiceInfo>::iterator it;
it = mOwnServices.find(serviceId);
if (it == mOwnServices.end())
{
std::cerr << "p3ServiceControl::deregisterService() ERROR No matching Service ID";
std::cerr << std::endl;
return false;
}
std::cerr << "p3ServiceControl::deregisterService() Removed ServiceID: " << serviceId;
std::cerr << std::endl;
mOwnServices.erase(it);
return true;
}
/* Interface for Services */
bool p3ServiceControl::registerServiceMonitor(pqiServiceMonitor *monitor, uint32_t serviceId)
{
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
std::cerr << "p3ServiceControl::registerServiceMonitor() for ServiceId: ";
std::cerr << serviceId;
std::cerr << std::endl;
mMonitors.insert(std::make_pair(serviceId, monitor));
return true;
}
bool p3ServiceControl::deregisterServiceMonitor(pqiServiceMonitor *monitor)
{
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
std::cerr << "p3ServiceControl::deregisterServiceMonitor()";
std::cerr << std::endl;
std::multimap<uint32_t, pqiServiceMonitor *>::iterator it;
for(it = mMonitors.begin(); it != mMonitors.end(); )
{
if (it->second == monitor)
{
mMonitors.erase(it++);
}
else
{
++it;
}
}
return true;
}
/* Interface to p3ServiceInfo */
void p3ServiceControl::getServiceChanges(std::set<RsPeerId> &updateSet)
{
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
std::cerr << "p3ServiceControl::getServiceChanges()";
std::cerr << std::endl;
std::set<RsPeerId>::iterator it;
for (it = mUpdatedSet.begin(); it != mUpdatedSet.end(); it++)
{
updateSet.insert(*it);
}
mUpdatedSet.clear();
}
bool p3ServiceControl::getServicesAllowed(const RsPeerId &peerId, RsPeerServiceInfo &info)
{
std::cerr << "p3ServiceControl::getServicesAllowed(" << peerId.toStdString() << ")";
std::cerr << std::endl;
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
info.mPeerId = peerId;
// For each registered Service.. check if peer has permissions.
std::map<uint32_t, RsServiceInfo>::iterator it;
for(it = mOwnServices.begin(); it != mOwnServices.end(); it++)
{
if (peerHasPermissionForService_locked(peerId, it->first))
{
info.mServiceList[it->first] = it->second;
}
}
return true;
}
bool p3ServiceControl::peerHasPermissionForService_locked(const RsPeerId &peerId, uint32_t serviceId)
{
std::cerr << "p3ServiceControl::peerHasPermissionForService_locked()";
std::cerr << std::endl;
std::map<uint32_t, RsServicePermissions>::iterator it;
it = mServicePermissionMap.find(serviceId);
if (it == mServicePermissionMap.end())
{
return false;
}
return it->second.peerHasPermission(peerId);
}
// This is used by both RsServiceControl and p3ServiceInfo.
bool p3ServiceControl::getServicesProvided(const RsPeerId &peerId, RsPeerServiceInfo &info)
{
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
std::cerr << "p3ServiceControl::getServicesProvided()";
std::cerr << std::endl;
std::map<RsPeerId, RsPeerServiceInfo>::iterator it;
it = mServicesProvided.find(peerId);
if (it == mServicesProvided.end())
{
return false;
}
info = it->second;
return true;
}
bool p3ServiceControl::updateServicesProvided(const RsPeerId &peerId, const RsPeerServiceInfo &info)
{
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
std::cerr << "p3ServiceControl::updateServicesProvided() from: " << peerId.toStdString();
std::cerr << std::endl;
std::cerr << info;
std::cerr << std::endl;
mServicesProvided[peerId] = info;
updateFilterByPeer_locked(peerId);
return true;
}
/* External Interface to RsServiceControl */
bool p3ServiceControl::getServicePermissions(uint32_t serviceId, RsServicePermissions &permissions)
{
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
std::cerr << "p3ServiceControl::getServicePermissions()";
std::cerr << std::endl;
std::map<uint32_t, RsServicePermissions>::iterator it;
it = mServicePermissionMap.find(serviceId);
if (it == mServicePermissionMap.end())
{
return false;
}
permissions = it->second;
return true;
}
bool p3ServiceControl::createDefaultPermissions_locked(uint32_t serviceId, std::string serviceName, bool defaultOn)
{
std::map<uint32_t, RsServicePermissions>::iterator it;
it = mServicePermissionMap.find(serviceId);
if (it == mServicePermissionMap.end())
{
RsServicePermissions perms;
perms.mServiceId = serviceId;
perms.mServiceName = serviceName;
perms.mDefaultAllowed = defaultOn;
mServicePermissionMap[serviceId] = perms;
return true;
}
return false;
}
bool p3ServiceControl::updateServicePermissions(uint32_t serviceId, const RsServicePermissions &permissions)
{
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
std::cerr << "p3ServiceControl::updateServicePermissions()";
std::cerr << std::endl;
std::map<uint32_t, RsServicePermissions>::iterator it;
it = mServicePermissionMap.find(serviceId);
/* here we have to check which peers - permissions have changed for,
* and flag for updates.
*
* This is far more complex.
* need to check if versions are compatible and peers are providing service.
*/
#if 0
std::list<std::string> onlinePeers;
std::list<std::string>::const_iterator pit;
if (it != mServicePermissionMap.end())
{
for(pit = onlinePeers.begin(); pit != onlinePeers.end(); pit++)
{
if (it->second.peerHasPermission(*pit) !=
permissions.peerHasPermission(*pit))
{
mUpdatedSet.insert(*pit);
}
}
}
else
{
// ERROR!
it = mServicePermissionMap.find[serviceId];
for(pit = onlinePeers.begin(); pit != onlinePeers.end(); pit++)
{
mUpdatedSet.insert(*pit);
}
}
#endif
it->second = permissions;
it->second.mServiceId = serviceId; // just to make sure!
return true;
}
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
// This is the basic system...
// which will be a little slow (2x maps).
//
// Potential improvement is to push the RsPeerFilter
// to the pqiStreamer, (when items have been sorted by peers already!).
// but we will do this later.
bool p3ServiceControl::checkFilter(uint32_t serviceId, const RsPeerId &peerId)
{
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
std::cerr << "p3ServiceControl::checkFilter() ";
std::cerr << " ServiceId: " << serviceId;
std::map<uint32_t, RsServiceInfo>::iterator it;
it = mOwnServices.find(serviceId);
if (it != mOwnServices.end())
{
std::cerr << " ServiceName: " << it->second.mServiceName;
}
else
{
std::cerr << " ServiceName: Unknown! ";
}
std::cerr << " PeerId: " << peerId.toStdString();
std::cerr << std::endl;
// must allow ServiceInfo through, or we have nothing!
#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)
{
std::cerr << "p3ServiceControl::checkFilter() Allowed SERVICEINFO";
std::cerr << std::endl;
return true;
}
std::map<RsPeerId, ServicePeerFilter>::const_iterator pit;
pit = mPeerFilterMap.find(peerId);
if (pit == mPeerFilterMap.end())
{
std::cerr << "p3ServiceControl::checkFilter() Denied No PeerId";
std::cerr << std::endl;
return false;
}
if (pit->second.mDenyAll)
{
std::cerr << "p3ServiceControl::checkFilter() Denied Peer.DenyAll";
std::cerr << std::endl;
return false;
}
if (pit->second.mAllowAll)
{
std::cerr << "p3ServiceControl::checkFilter() Allowed Peer.AllowAll";
std::cerr << std::endl;
return true;
}
std::set<uint32_t>::const_iterator sit;
sit = pit->second.mAllowedServices.find(serviceId);
if (sit == pit->second.mAllowedServices.end())
{
std::cerr << "p3ServiceControl::checkFilter() Denied !Peer.find(serviceId)";
std::cerr << std::endl;
return false;
}
std::cerr << "p3ServiceControl::checkFilter() Allowed Peer.find(serviceId)";
std::cerr << std::endl;
return true;
}
bool versionOkay(uint16_t version_major, uint16_t version_minor,
uint16_t min_version_major, uint16_t min_version_minor)
{
if (version_major > min_version_major)
{
return true;
}
if (version_major == min_version_major)
{
return (version_minor >= min_version_minor);
}
return false;
}
bool servicesCompatible(const RsServiceInfo &info1, const RsServiceInfo &info2)
{
// Id, or Name mismatch.
if ((info1.mServiceType != info2.mServiceType) ||
(info1.mServiceName != info2.mServiceName))
{
std::cerr << "servicesCompatible: Type/Name mismatch";
std::cerr << std::endl;
std::cerr << "Info1 ID: " << info1.mServiceType;
std::cerr << " " << info1.mServiceName;
std::cerr << std::endl;
std::cerr << "Info2 ID: " << info2.mServiceType;
std::cerr << " " << info2.mServiceName;
std::cerr << std::endl;
return false;
}
// ensure that info1 meets minimum requirements for info2
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,
info1.mMinVersionMajor, info1.mMinVersionMinor))
{
return false;
}
return true;
}
bool p3ServiceControl::updateFilterByPeer(const RsPeerId &peerId)
{
std::cerr << "p3ServiceControl::updateFilterByPeer()";
std::cerr << std::endl;
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
return updateFilterByPeer_locked(peerId);
}
bool p3ServiceControl::updateAllFilters()
{
std::cerr << "p3ServiceControl::updateAllFilters()";
std::cerr << std::endl;
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
// Create a peerSet from ServicesProvided + PeerFilters.
// This will completely refresh the Filters.
std::set<RsPeerId> peerSet;
std::set<RsPeerId>::const_iterator pit;
std::map<RsPeerId, RsPeerServiceInfo>::const_iterator it;
for(it = mServicesProvided.begin(); it != mServicesProvided.end(); it++)
{
peerSet.insert(it->first);
}
std::map<RsPeerId, ServicePeerFilter>::const_iterator fit;
for(fit = mPeerFilterMap.begin(); fit != mPeerFilterMap.end(); fit++)
{
peerSet.insert(fit->first);
}
for(pit = peerSet.begin(); pit != peerSet.end(); pit++)
{
updateFilterByPeer_locked(*pit);
}
return true;
}
// create filter. (the easy way).
bool p3ServiceControl::updateFilterByPeer_locked(const RsPeerId &peerId)
{
std::cerr << "p3ServiceControl::updateFilterByPeer_locked() : " << peerId.toStdString();
std::cerr << std::endl;
ServicePeerFilter originalFilter;
ServicePeerFilter peerFilter;
std::map<RsPeerId, ServicePeerFilter>::iterator fit;
fit = mPeerFilterMap.find(peerId);
if (fit != mPeerFilterMap.end())
{
originalFilter = fit->second;
}
std::map<RsPeerId, RsPeerServiceInfo>::iterator it;
it = mServicesProvided.find(peerId);
if (it == mServicesProvided.end())
{
std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Empty ... Clearing";
std::cerr << std::endl;
// empty, remove...
recordFilterChanges_locked(peerId, originalFilter, peerFilter);
if (fit != mPeerFilterMap.end())
{
std::cerr << std::endl;
mPeerFilterMap.erase(fit);
}
return true;
}
// For each registered Service.. check if services compatible.
// then check for permissions.
// similar maps, can iterate through in parallel.
std::map<uint32_t, RsServiceInfo>::const_iterator oit = mOwnServices.begin();
std::map<uint32_t, RsServiceInfo>::const_iterator eoit = mOwnServices.end();
std::map<uint32_t, RsServiceInfo>::const_iterator tit = it->second.mServiceList.begin();
std::map<uint32_t, RsServiceInfo>::const_iterator etit = it->second.mServiceList.end();
std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Comparing lists";
std::cerr << std::endl;
while((oit != eoit) && (tit != etit))
{
if (oit->first == tit->first)
{
std::cerr << "\tChecking Matching Service ID: " << oit->first;
std::cerr << std::endl;
/* match of service IDs */
/* check if compatible */
if (servicesCompatible(oit->second, tit->second))
{
if (peerHasPermissionForService_locked(peerId, oit->first))
{
std::cerr << "\t\tMatched Service ID: " << oit->first;
std::cerr << std::endl;
peerFilter.mAllowedServices.insert(oit->first);
}
}
oit++;
tit++;
}
else
{
if (oit->first < tit->first)
{
std::cerr << "\tSkipping Only Own Service ID: " << oit->first;
std::cerr << std::endl;
oit++;
}
else
{
std::cerr << "\tSkipping Only Peer Service ID: " << tit->first;
std::cerr << std::endl;
tit++;
}
}
}
// small optimisations.
if (peerFilter.mAllowedServices.empty())
{
peerFilter.mDenyAll = true;
}
else
{
peerFilter.mDenyAll = false;
if (peerFilter.mAllowedServices.size() == mOwnServices.size())
{
peerFilter.mAllowAll = true;
}
}
// update or remove.
if (peerFilter.mDenyAll)
{
std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Empty(2) ... Clearing";
std::cerr << std::endl;
if (fit != mPeerFilterMap.end())
{
mPeerFilterMap.erase(fit);
}
}
else
{
std::cerr << "p3ServiceControl::updateFilterByPeer_locked() Installing PeerFilter";
std::cerr << std::endl;
mPeerFilterMap[peerId] = peerFilter;
}
recordFilterChanges_locked(peerId, originalFilter, peerFilter);
return true;
}
void p3ServiceControl::recordFilterChanges_locked(const RsPeerId &peerId,
ServicePeerFilter &originalFilter, ServicePeerFilter &updatedFilter)
{
std::cerr << "p3ServiceControl::recordFilterChanges_locked()";
std::cerr << std::endl;
std::cerr << "PeerId: " << peerId.toStdString();
std::cerr << std::endl;
std::cerr << "OriginalFilter: " << originalFilter;
std::cerr << std::endl;
std::cerr << "UpdatedFilter: " << updatedFilter;
std::cerr << std::endl;
/* find differences */
std::map<uint32_t, bool> changes;
std::set<uint32_t>::const_iterator it1, it2, eit1, eit2;
it1 = originalFilter.mAllowedServices.begin();
eit1 = originalFilter.mAllowedServices.end();
it2 = updatedFilter.mAllowedServices.begin();
eit2 = updatedFilter.mAllowedServices.end();
while((it1 != eit1) && (it2 != eit2))
{
if (*it1 < *it2)
{
std::cerr << "Removed Service: " << *it1;
std::cerr << std::endl;
// removal
changes[*it1] = false;
++it1;
}
else if (*it2 < *it1)
{
std::cerr << "Added Service: " << *it2;
std::cerr << std::endl;
// addition.
changes[*it2] = true;
++it2;
}
else
{
++it1;
++it2;
}
}
// Handle the unfinished Set.
for(; it1 != eit1; it1++)
{
std::cerr << "Removed Service: " << *it1;
std::cerr << std::endl;
// removal
changes[*it1] = false;
}
for(; it2 != eit2; it2++)
{
std::cerr << "Added Service: " << *it2;
std::cerr << std::endl;
// addition.
changes[*it2] = true;
}
// now we to store for later notifications.
std::map<uint32_t, bool>::const_iterator cit;
for(cit = changes.begin(); cit != changes.end(); cit++)
{
ServiceNotifications &notes = mNotifications[cit->first];
if (cit->second)
{
notes.mAdded.insert(peerId);
}
else
{
notes.mRemoved.insert(peerId);
}
}
}
// when they go offline, etc.
void p3ServiceControl::removePeer(const RsPeerId &peerId)
{
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
std::cerr << "p3ServiceControl::removePeer()";
std::cerr << std::endl;
ServicePeerFilter originalFilter;
bool hadFilter = false;
{
std::map<RsPeerId, ServicePeerFilter>::iterator fit;
fit = mPeerFilterMap.find(peerId);
if (fit != mPeerFilterMap.end())
{
hadFilter = true;
originalFilter = fit->second;
mPeerFilterMap.erase(fit);
}
}
{
std::map<RsPeerId, RsPeerServiceInfo>::iterator sit;
sit = mServicesProvided.find(peerId);
if (sit != mServicesProvided.end())
{
mServicesProvided.erase(sit);
}
}
if (hadFilter)
{
ServicePeerFilter emptyFilter;
recordFilterChanges_locked(peerId, originalFilter, emptyFilter);
}
}
/****************************************************************************/
/****************************************************************************/
void p3ServiceControl::tick()
{
std::cerr << "p3ServiceControl::tick()";
std::cerr << std::endl;
}
// configuration.
bool p3ServiceControl::saveList(bool &cleanup, std::list<RsItem *> &saveList)
{
std::cerr << "p3ServiceControl::saveList()";
std::cerr << std::endl;
return true;
}
bool p3ServiceControl::loadList(std::list<RsItem *>& loadList)
{
std::cerr << "p3ServiceControl::loadList()";
std::cerr << std::endl;
return true;
}
/****************************************************************************/
/****************************************************************************/
// pqiMonitor.
void p3ServiceControl::statusChange(const std::list<pqipeer> &plist)
{
std::cerr << "p3ServiceControl::statusChange()";
std::cerr << std::endl;
std::list<pqipeer>::const_iterator pit;
for(pit = plist.begin(); pit != plist.end(); pit++)
{
if (pit->state & RS_PEER_S_FRIEND)
{
if (pit->actions & RS_PEER_CONNECTED)
{
updatePeerConnect(pit->id);
}
else if (pit->actions & RS_PEER_DISCONNECTED)
{
updatePeerDisconnect(pit->id);
}
}
}
return;
}
// Update Peer status.
void p3ServiceControl::updatePeerConnect(const RsPeerId &peerId)
{
std::cerr << "p3ServiceControl::updatePeerConnect(): " << peerId.toStdString();
std::cerr << std::endl;
return;
}
void p3ServiceControl::updatePeerDisconnect(const RsPeerId &peerId)
{
std::cerr << "p3ServiceControl::updatePeerDisconnect(): " << peerId.toStdString();
std::cerr << std::endl;
removePeer(peerId);
return;
}
/****************************************************************************/
/****************************************************************************/
void p3ServiceControl::notifyServices()
{
RsStackMutex stack(mCtrlMtx); /***** LOCK STACK MUTEX ****/
std::map<uint32_t, ServiceNotifications>::const_iterator it;
std::multimap<uint32_t, pqiServiceMonitor *>::const_iterator sit, eit;
for(it = mNotifications.begin(); it != mNotifications.end(); it++)
{
sit = mMonitors.lower_bound(it->first);
eit = mMonitors.upper_bound(it->first);
if (sit == eit)
{
/* nothing to notify - skip */
continue;
}
std::list<pqiServicePeer> peers;
std::set<RsPeerId>::const_iterator pit;
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);
}
for(pit = it->second.mRemoved.begin();
pit != it->second.mRemoved.end(); pit++)
{
pqiServicePeer peer;
peer.id = *pit;
peer.actions = RS_SERVICE_PEER_REMOVED;
peers.push_back(peer);
}
for(; sit != eit; sit++)
{
sit->second->statusChange(peers);
}
}
mNotifications.clear();
}
/****************************************************************************/
/****************************************************************************/
RsServicePermissions::RsServicePermissions()
:mServiceId(0), mServiceName(), mDefaultAllowed(false)
{
return;
}
bool RsServicePermissions::peerHasPermission(const RsPeerId &peerId) const
{
std::cerr << "RsServicePermissions::peerHasPermission()";
std::cerr << std::endl;
std::set<RsPeerId>::const_iterator it;
if (mDefaultAllowed)
{
it = mPeersDenied.find(peerId);
return (it == mPeersDenied.end());
}
else
{
it = mPeersAllowed.find(peerId);
return (it != mPeersAllowed.end());
}
}
RsServiceInfo::RsServiceInfo(
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),
mVersionMinor(version_minor),
mMinVersionMajor(min_version_major),
mMinVersionMinor(min_version_minor)
{
return;
}
RsServiceInfo::RsServiceInfo()
:mServiceName("unknown"),
mServiceType(0),
mVersionMajor(0),
mVersionMinor(0),
mMinVersionMajor(0),
mMinVersionMinor(0)
{
return;
}
std::ostream &operator<<(std::ostream &out, const RsPeerServiceInfo &info)
{
out << "RsPeerServiceInfo(" << info.mPeerId << ")";
out << std::endl;
std::map<uint32_t, RsServiceInfo>::const_iterator it;
for(it = info.mServiceList.begin(); it != info.mServiceList.end(); it++)
{
out << "\t Service:" << it->first << " : ";
out << it->second;
out << std::endl;
}
return out;
}
std::ostream &operator<<(std::ostream &out, const RsServiceInfo &info)
{
out << "RsServiceInfo(" << info.mServiceType << "): " << info.mServiceName;
out << " Version(" << info.mVersionMajor << "," << info.mVersionMinor << ")";
out << " MinVersion(" << info.mMinVersionMajor << "," << info.mMinVersionMinor << ")";
return out;
}
std::ostream &operator<<(std::ostream &out, const ServicePeerFilter &filter)
{
out << "ServicePeerFilter DenyAll: " << filter.mDenyAll;
out << " AllowAll: " << filter.mAllowAll;
out << " Matched Services: ";
std::set<uint32_t>::const_iterator it;
for(it = filter.mAllowedServices.begin(); it != filter.mAllowedServices.end(); it++)
{
out << *it << " ";
}
out << std::endl;
return out;
}

View File

@ -0,0 +1,163 @@
/*
* libretroshare/src/pqi: p3servicecontrol.h
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2014 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.1 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 P3_SERVICE_CONTROL_HEADER
#define P3_SERVICE_CONTROL_HEADER
#include <string>
#include <map>
#include "retroshare/rsservicecontrol.h"
#include "pqi/p3cfgmgr.h"
#include "pqi/pqimonitor.h"
#include "pqi/pqiservicemonitor.h"
class ServiceNotifications
{
public:
std::set<RsPeerId> mAdded;
std::set<RsPeerId> mRemoved;
};
class ServicePeerFilter
{
public:
ServicePeerFilter()
:mDenyAll(true), mAllowAll(false) {}
bool mDenyAll;
bool mAllowAll;
std::set<uint32_t> mAllowedServices;
};
std::ostream &operator<<(std::ostream &out, const ServicePeerFilter &filter);
class p3ServiceControl: public RsServiceControl /* , public p3Config, public pqiMonitor */
{
public:
/**
*/
p3ServiceControl(uint32_t configId);
/**
* checks and update all added configurations
* @see rsserver
*/
void tick();
/**
* External Interface (RsServiceControl).
*/
// This is what is passed to peers, can be displayed by GUI too.
virtual bool getServicesAllowed(const RsPeerId &peerId, RsPeerServiceInfo &info);
// Information provided by peer.
virtual bool getServicesProvided(const RsPeerId &peerId, RsPeerServiceInfo &info);
// Main Permission Interface.
virtual bool getServicePermissions(uint32_t serviceId, RsServicePermissions &permissions);
virtual bool updateServicePermissions(uint32_t serviceId, const RsServicePermissions &permissions);
/**
* Registration for all Services.
*/
virtual bool registerService(const RsServiceInfo &info, bool defaultOn);
virtual bool deregisterService(uint32_t serviceId);
virtual bool registerServiceMonitor(pqiServiceMonitor *monitor, uint32_t serviceId);
virtual bool deregisterServiceMonitor(pqiServiceMonitor *monitor);
/**
*
*/
// Filter for services.
virtual bool checkFilter(uint32_t serviceId, const RsPeerId &peerId);
/**
* Interface for ServiceInfo service.
*/
// ServicesAllowed have changed for these peers.
virtual void getServiceChanges(std::set<RsPeerId> &updateSet);
// Input from peers.
virtual bool updateServicesProvided(const RsPeerId &peerId, const RsPeerServiceInfo &info);
// pqiMonitor.
virtual void statusChange(const std::list<pqipeer> &plist);
protected:
// configuration.
virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
virtual bool loadList(std::list<RsItem *>& load);
private:
void notifyServices();
bool createDefaultPermissions_locked(uint32_t serviceId, std::string serviceName, bool defaultOn);
bool updateAllFilters();
bool updateFilterByPeer(const RsPeerId &peerId);
bool updateFilterByPeer_locked(const RsPeerId &peerId);
void removePeer(const RsPeerId &peerId);
void recordFilterChanges_locked(const RsPeerId &peerId,
ServicePeerFilter &originalFilter, ServicePeerFilter &updatedFilter);
void updatePeerConnect(const RsPeerId &peerId);
void updatePeerDisconnect(const RsPeerId &peerId);
bool peerHasPermissionForService_locked(const RsPeerId &peerId, uint32_t serviceId);
RsMutex mCtrlMtx; /* below is protected */
std::set<RsPeerId> mUpdatedSet;
// From registration / deregistration.
std::map<uint32_t, RsServiceInfo> mOwnServices;
// From peers.
std::map<RsPeerId, RsPeerServiceInfo> mServicesProvided;
// derived from all the others.
std::map<RsPeerId, ServicePeerFilter> mPeerFilterMap;
// Below here is saved in Configuration.
std::map<uint32_t, RsServicePermissions> mServicePermissionMap;
std::multimap<uint32_t, pqiServiceMonitor *> mMonitors;
std::map<uint32_t, ServiceNotifications> mNotifications;
};
#endif // P3_SERVICE_CONTROL_HEADER

View File

@ -300,6 +300,12 @@ int pqihandler::SendRsRawItem(RsRawItem *ns)
// system that is completely biased and slow...
// someone please fix.
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// THIS CODE SHOULD BE ABLE TO BE REMOVED!
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
int pqihandler::locked_GetItems()
{
std::map<RsPeerId, SearchModule *>::iterator it;
@ -319,6 +325,11 @@ int pqihandler::locked_GetItems()
// if yes... attempt to read.
while((item = (mod -> pqi) -> GetItem()) != NULL)
{
std::cerr << "pqihandler::locked_GetItems() pqi->GetItem()";
std::cerr << " should never happen anymore!";
std::cerr << std::endl;
#ifdef RSITEM_DEBUG
std::string out;
rs_sprintf(out, "pqihandler::GetItems() Incoming Item from: %p\n", mod -> pqi);
@ -407,6 +418,13 @@ RsRawItem *pqihandler::GetRsRawItem()
return NULL;
}
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// ABOVE CODE SHOULD BE ABLE TO BE REMOVED!
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
static const float MIN_RATE = 0.01; // 10 B/s
// NEW extern fn to extract rates.

View File

@ -83,6 +83,10 @@ int pqipersongrp::tickServiceRecv()
while(NULL != (pqi = GetRsRawItem()))
{
std::cerr << "pqipersongrp::tickServiceRecv() GetRsRawItem()";
std::cerr << " should never happen anymore!";
std::cerr << std::endl;
++i;
pqioutput(PQL_DEBUG_BASIC, pqipersongrpzone,
"pqipersongrp::tickServiceRecv() Incoming TunnelItem");
@ -130,8 +134,8 @@ int pqipersongrp::tickServiceSend()
// init
pqipersongrp::pqipersongrp(SecurityPolicy *glob, unsigned long flags)
:pqihandler(glob), p3ServiceServer(this), pqil(NULL), initFlags(flags)
pqipersongrp::pqipersongrp(p3ServiceControl *ctrl, SecurityPolicy *glob, unsigned long flags)
:pqihandler(glob), p3ServiceServer(this, ctrl), pqil(NULL), initFlags(flags)
{
}

View File

@ -50,7 +50,7 @@ class RsPeerCryptoParams ;
class pqipersongrp: public pqihandler, public pqiMonitor, public p3ServiceServer, public pqiNetListener
{
public:
pqipersongrp(SecurityPolicy *, unsigned long flags);
pqipersongrp(p3ServiceControl *ctrl, SecurityPolicy *, unsigned long flags);
/*************************** Setup *************************/
/* pqilistener */
@ -129,8 +129,8 @@ virtual int checkOutgoingRsItem(RsItem *item, int global)
class pqipersongrpDummy: public pqipersongrp
{
public:
pqipersongrpDummy(SecurityPolicy *pol, unsigned long flags)
:pqipersongrp(pol, flags) { return; }
pqipersongrpDummy(p3ServiceControl *ctrl, SecurityPolicy *pol, unsigned long flags)
:pqipersongrp(ctrl, pol, flags) { return; }
protected:

View File

@ -44,7 +44,7 @@ bool pqiService::send(RsRawItem *item)
}
p3ServiceServer::p3ServiceServer(pqiPublisher *pub) : mPublisher(pub), srvMtx("p3ServiceServer")
p3ServiceServer::p3ServiceServer(pqiPublisher *pub, p3ServiceControl *ctrl) : mPublisher(pub), mServiceControl(ctrl), srvMtx("p3ServiceServer")
{
RsStackMutex stack(srvMtx); /********* LOCKED *********/
@ -56,7 +56,7 @@ p3ServiceServer::p3ServiceServer(pqiPublisher *pub) : mPublisher(pub), srvMtx("p
return;
}
int p3ServiceServer::addService(pqiService *ts)
int p3ServiceServer::addService(pqiService *ts, bool defaultOn)
{
RsStackMutex stack(srvMtx); /********* LOCKED *********/
@ -65,18 +65,21 @@ int p3ServiceServer::addService(pqiService *ts)
"p3ServiceServer::addService()");
#endif
RsServiceInfo info = ts->getServiceInfo();
std::map<uint32_t, pqiService *>::iterator it;
it = services.find(ts -> getType());
it = services.find(info.mServiceType);
if (it != services.end())
{
std::cerr << "p3ServiceServer::addService(): Service already added with id " << ts->getType() << "!" << std::endl;
std::cerr << "p3ServiceServer::addService(): Service already added with id " << info.mServiceType << "!" << std::endl;
// it exists already!
return -1;
}
ts->setServiceServer(this);
services[ts -> getType()] = ts;
services[info.mServiceType] = ts;
// This doesn't need to be in Mutex.
mServiceControl->registerService(info, defaultOn);
return 1;
}
@ -97,6 +100,16 @@ bool p3ServiceServer::recvItem(RsRawItem *item)
}
#endif
// Packet Filtering.
// This doesn't need to be in Mutex.
if (!mServiceControl->checkFilter(item->PacketId() & 0xffffff00, item->PeerId()))
{
std::cerr << "p3ServiceServer::recvItem() Fails Filtering";
delete item;
return false;
}
std::map<uint32_t, pqiService *>::iterator it;
it = services.find(item -> PacketId() & 0xffffff00);
if (it == services.end())
@ -133,8 +146,20 @@ bool p3ServiceServer::sendItem(RsRawItem *item)
item -> print_string(out);
std::cerr << std::endl;
#endif
if (!item)
{
std::cerr << "p3ServiceServer::sendItem() Caught Null item";
std::cerr << std::endl;
return false;
}
/* any filtering ??? */
// Packet Filtering.
if (!mServiceControl->checkFilter(item->PacketId() & 0xffffff00, item->PeerId()))
{
std::cerr << "p3ServiceServer::sendItem() Fails Filtering";
delete item;
return false;
}
mPublisher->sendItem(item);
return true;

View File

@ -31,6 +31,9 @@
#include "pqi/pqi_base.h"
#include "util/rsthreads.h"
#include "retroshare/rsservicecontrol.h"
#include "pqi/p3servicecontrol.h"
// PQI Service, is a generic lower layer on which services can run on.
//
// these packets get passed through the
@ -59,8 +62,8 @@ class pqiService
{
protected:
pqiService(uint32_t t) // our type of packets.
:type(t), mServiceServer(NULL) { return; }
pqiService() // our type of packets.
:mServiceServer(NULL) { return; }
virtual ~pqiService() { return; }
@ -70,29 +73,28 @@ void setServiceServer(p3ServiceServer *server);
virtual bool recv(RsRawItem *) = 0;
virtual bool send(RsRawItem *item);
uint32_t getType() { return type; }
virtual RsServiceInfo getServiceInfo() = 0;
virtual int tick() { return 0; }
private:
uint32_t type;
p3ServiceServer *mServiceServer; // const, no need for mutex.
};
#include <map>
/* We are pushing the packets back through p3ServiceServer2,
/* We are pushing the packets back through p3ServiceServer,
* so that we can filter services at this level later...
* if we decide not to do this, pqiService2 can call through
* if we decide not to do this, pqiService can call through
* to the base level pqiPublisher instead.
*/
class p3ServiceServer
{
public:
p3ServiceServer(pqiPublisher *pub);
p3ServiceServer(pqiPublisher *pub, p3ServiceControl *ctrl);
int addService(pqiService *);
int addService(pqiService *, bool defaultOn);
bool recvItem(RsRawItem *);
bool sendItem(RsRawItem *);
@ -102,9 +104,10 @@ int tick();
private:
pqiPublisher *mPublisher; // constant no need for mutex.
p3ServiceControl *mServiceControl;
RsMutex srvMtx;
std::map<uint32_t, pqiService *> services;
std::map<uint32_t, pqiService *> services;
};

View File

@ -0,0 +1,64 @@
/*
* libretroshare/src/pqi: pqiservicemonitor.h
*
* 3P/PQI network interface for RetroShare.
*
* Copyright 2014 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.1 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 PQI_SERVICE_MONITOR_H
#define PQI_SERVICE_MONITOR_H
#include <inttypes.h>
#include <string>
#include <list>
#include <retroshare/rstypes.h>
/* ACTIONS */
const uint32_t RS_SERVICE_PEER_NEW = 0x0001; /* new Peer */
const uint32_t RS_SERVICE_PEER_CONNECTED = 0x0002; /* service connected */
const uint32_t RS_SERVICE_PEER_DISCONNECTED = 0x0010;
const uint32_t RS_SERVICE_PEER_REMOVED = 0x0020;
class pqiServicePeer
{
public:
RsPeerId id;
uint32_t actions;
};
class pqiServiceMonitor
{
public:
pqiServiceMonitor() { return; }
virtual ~pqiServiceMonitor() { return; }
/*!
* this serves as a call back function for server which has
* a handle on the subclass and updates this subclass on the
* action of peer's of the client (state and action information)
*
*@param plist contains list of states and actions of the client's peers
*/
virtual void statusChange(const std::list<pqiServicePeer> &plist) = 0;
};
#endif // PQI_SERVICE_MONITOR_H

View File

@ -37,8 +37,8 @@ class pqissl ;
class pqisslpersongrp: public pqipersongrp
{
public:
pqisslpersongrp(SecurityPolicy *pol, unsigned long flags, p3PeerMgr *pm)
:pqipersongrp(pol, flags), mPeerMgr(pm) { return; }
pqisslpersongrp(p3ServiceControl *ctrl, SecurityPolicy *pol, unsigned long flags, p3PeerMgr *pm)
:pqipersongrp(ctrl, pol, flags), mPeerMgr(pm) { return; }
protected:

View File

@ -0,0 +1,110 @@
#ifndef RETROSHARE_SERVICE_CONTROL_GUI_INTERFACE_H
#define RETROSHARE_SERVICE_CONTROL_GUI_INTERFACE_H
/*
* libretroshare/src/rsiface: rsservicecontrol.h
*
* RetroShare C++ Interface.
*
* Copyright 2014 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.1 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".
*
*/
#include <inttypes.h>
#include <string>
#include <list>
#include <map>
#include <set>
#include <retroshare/rstypes.h>
/* The Main Interface Class - for information about your Peers */
class RsServiceControl;
extern RsServiceControl *rsServiceControl;
class RsServiceInfo
{
public:
RsServiceInfo();
RsServiceInfo(
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);
std::string mServiceName;
uint32_t mServiceType;
// current version, we running.
uint16_t mVersionMajor;
uint16_t mVersionMinor;
// minimum version can communicate with.
uint16_t mMinVersionMajor;
uint16_t mMinVersionMinor;
};
/* this is what is transmitted to peers */
class RsPeerServiceInfo
{
public:
RsPeerServiceInfo()
:mPeerId(), mServiceList() { return; }
RsPeerId mPeerId;
std::map<uint32_t, RsServiceInfo> mServiceList;
};
std::ostream &operator<<(std::ostream &out, const RsPeerServiceInfo &info);
std::ostream &operator<<(std::ostream &out, const RsServiceInfo &info);
class RsServicePermissions
{
public:
RsServicePermissions();
bool peerHasPermission(const RsPeerId &peerId) const;
uint32_t mServiceId;
std::string mServiceName;
bool mDefaultAllowed;
// note only one of these is checked.
// if DefaultAllowed = true, then only PeersDenied is checked.
// if DefaultAllowed = false, then only PeersAllowed is checked.
std::set<RsPeerId> mPeersAllowed;
std::set<RsPeerId> mPeersDenied;
};
class RsServiceControl
{
public:
RsServiceControl() { return; }
virtual ~RsServiceControl() { return; }
virtual bool getServicesAllowed(const RsPeerId &peerId, RsPeerServiceInfo &info) = 0;
virtual bool getServicesProvided(const RsPeerId &peerId, RsPeerServiceInfo &info) = 0;
virtual bool getServicePermissions(uint32_t serviceId, RsServicePermissions &permissions) = 0;
virtual bool updateServicePermissions(uint32_t serviceId, const RsServicePermissions &permissions) = 0;
};
#endif

View File

@ -867,6 +867,7 @@ RsGRouter *rsGRouter = NULL ;
#endif
#endif
#include "services/p3serviceinfo.h"
#include "services/p3heartbeat.h"
#include "services/p3discovery2.h"
#include "services/p3msgservice.h"
@ -1221,9 +1222,10 @@ int RsServer::StartupRetroShare()
/**************************** BITDHT ***********************************/
p3ServiceControl *serviceCtrl = new p3ServiceControl(0);
SecurityPolicy *none = secpolicy_create();
pqih = new pqisslpersongrp(none, flags, mPeerMgr);
pqih = new pqisslpersongrp(serviceCtrl, none, flags, mPeerMgr);
//pqih = new pqipersongrpDummy(none, flags);
/****** New Ft Server **** !!! */
@ -1293,6 +1295,7 @@ int RsServer::StartupRetroShare()
mPluginsManager->loadPlugins(programatically_inserted_plugins) ;
/* create Services */
p3ServiceInfo *serviceInfo = new p3ServiceInfo(serviceCtrl);
mDisc = new p3discovery2(mPeerMgr, mLinkMgr, mNetMgr);
mHeart = new p3heartbeat(mLinkMgr, pqih);
msgSrv = new p3MsgService(mLinkMgr);
@ -1302,13 +1305,13 @@ int RsServer::StartupRetroShare()
#ifdef GROUTER
p3GRouter *gr = new p3GRouter(mLinkMgr) ;
rsGRouter = gr ;
pqih->addService(gr) ;
pqih->addService(gr, true) ;
#endif
p3turtle *tr = new p3turtle(mLinkMgr) ;
rsTurtle = tr ;
pqih -> addService(tr);
pqih -> addService(ftserver);
pqih -> addService(tr, true);
pqih -> addService(ftserver, true);
rsDisc = mDisc;
rsMsgs = new p3Msgs(msgSrv, chatSrv);
@ -1322,11 +1325,12 @@ int RsServer::StartupRetroShare()
#endif
msgSrv->connectToTurtleRouter(tr) ;
pqih -> addService(mHeart);
pqih -> addService(mDisc);
pqih -> addService(msgSrv);
pqih -> addService(chatSrv);
pqih ->addService(mStatusSrv);
pqih -> addService(serviceInfo, true);
pqih -> addService(mHeart, true);
pqih -> addService(mDisc, true);
pqih -> addService(msgSrv, true);
pqih -> addService(chatSrv, true);
pqih ->addService(mStatusSrv, true);
// set interfaces for plugins
@ -1400,15 +1404,14 @@ int RsServer::StartupRetroShare()
// create GXS ID service
RsGxsNetService* gxsid_ns = new RsGxsNetService(
RS_SERVICE_GXSV2_TYPE_GXSID, gxsid_ds, nxsMgr,
mGxsIdService, mGxsIdService, mGxsCircles,
true); // don't synchronise group automatic (need explicit group request)
mGxsIdService, mGxsIdService->getServiceInfo(),
mGxsIdService, mGxsCircles,
false); // don't synchronise group automatic (need explicit group request)
mGxsIdService->setNes(gxsid_ns);
/**** GxsCircle service ****/
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
gxscircles_ds->resetDataStore();
#endif
@ -1419,7 +1422,8 @@ int RsServer::StartupRetroShare()
// create GXS Circle service
RsGxsNetService* gxscircles_ns = new RsGxsNetService(
RS_SERVICE_GXSV2_TYPE_GXSCIRCLE, gxscircles_ds, nxsMgr,
mGxsCircles, mGxsIdService, mGxsCircles);
mGxsCircles, mGxsCircles->getServiceInfo(),
mGxsIdService, mGxsCircles);
/**** Photo service ****/
@ -1435,14 +1439,17 @@ int RsServer::StartupRetroShare()
// create GXS photo service
RsGxsNetService* photo_ns = new RsGxsNetService(
RS_SERVICE_GXSV2_TYPE_PHOTO, photo_ds, nxsMgr, mPhoto, mGxsIdService, mGxsCircles);
RS_SERVICE_GXSV2_TYPE_PHOTO, photo_ds, nxsMgr,
mPhoto, mPhoto->getServiceInfo(),
mGxsIdService, mGxsCircles);
/**** Posted GXS service ****/
RsGeneralDataService* posted_ds = new RsDataService(currGxsDir + "/", "posted_db",
RS_SERVICE_GXSV2_TYPE_POSTED, NULL, RsInitConfig::gxs_passwd);
RS_SERVICE_GXSV2_TYPE_POSTED,
NULL, RsInitConfig::gxs_passwd);
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
posted_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
@ -1452,16 +1459,16 @@ int RsServer::StartupRetroShare()
// create GXS photo service
RsGxsNetService* posted_ns = new RsGxsNetService(
RS_SERVICE_GXSV2_TYPE_POSTED, posted_ds, nxsMgr, mPosted, mGxsIdService, mGxsCircles);
RS_SERVICE_GXSV2_TYPE_POSTED, posted_ds, nxsMgr,
mPosted, mPosted->getServiceInfo(),
mGxsIdService, mGxsCircles);
/**** Wiki GXS service ****/
RsGeneralDataService* wiki_ds = new RsDataService(currGxsDir + "/", "wiki_db",
RS_SERVICE_GXSV2_TYPE_WIKI,
NULL, RsInitConfig::gxs_passwd);
RS_SERVICE_GXSV2_TYPE_WIKI,
NULL, RsInitConfig::gxs_passwd);
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
wiki_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
@ -1471,14 +1478,17 @@ int RsServer::StartupRetroShare()
// create GXS photo service
RsGxsNetService* wiki_ns = new RsGxsNetService(
RS_SERVICE_GXSV2_TYPE_WIKI, wiki_ds, nxsMgr, mWiki, mGxsIdService, mGxsCircles);
RS_SERVICE_GXSV2_TYPE_WIKI, wiki_ds, nxsMgr,
mWiki, mWiki->getServiceInfo(),
mGxsIdService, mGxsCircles);
/**** Wire GXS service ****/
RsGeneralDataService* wire_ds = new RsDataService(currGxsDir + "/", "wire_db",
RS_SERVICE_GXSV2_TYPE_WIRE, NULL, RsInitConfig::gxs_passwd);
RS_SERVICE_GXSV2_TYPE_WIRE,
NULL, RsInitConfig::gxs_passwd);
#ifndef GXS_DEV_TESTNET // NO RESET, OR DUMMYDATA for TESTNET
wire_ds->resetDataStore(); //TODO: remove, new service data per RS session, for testing
@ -1488,7 +1498,9 @@ int RsServer::StartupRetroShare()
// create GXS photo service
RsGxsNetService* wire_ns = new RsGxsNetService(
RS_SERVICE_GXSV2_TYPE_WIRE, wire_ds, nxsMgr, mWire, mGxsIdService, mGxsCircles);
RS_SERVICE_GXSV2_TYPE_WIRE, wire_ds, nxsMgr,
mWire, mWire->getServiceInfo(),
mGxsIdService, mGxsCircles);
/**** Forum GXS service ****/
@ -1505,7 +1517,8 @@ int RsServer::StartupRetroShare()
// create GXS photo service
RsGxsNetService* gxsforums_ns = new RsGxsNetService(
RS_SERVICE_GXSV2_TYPE_FORUMS, gxsforums_ds, nxsMgr,
mGxsForums, mGxsIdService, mGxsCircles);
mGxsForums, mGxsForums->getServiceInfo(),
mGxsIdService, mGxsCircles);
/**** Channel GXS service ****/
@ -1522,16 +1535,17 @@ int RsServer::StartupRetroShare()
// create GXS photo service
RsGxsNetService* gxschannels_ns = new RsGxsNetService(
RS_SERVICE_GXSV2_TYPE_CHANNELS, gxschannels_ds, nxsMgr,
mGxsChannels, mGxsIdService, mGxsCircles);
mGxsChannels, mGxsChannels->getServiceInfo(),
mGxsIdService, mGxsCircles);
// now add to p3service
pqih->addService(gxsid_ns);
pqih->addService(gxscircles_ns);
pqih->addService(photo_ns);
pqih->addService(posted_ns);
pqih->addService(wiki_ns);
pqih->addService(gxsforums_ns);
pqih->addService(gxschannels_ns);
pqih->addService(gxsid_ns, true);
pqih->addService(gxscircles_ns, true);
pqih->addService(photo_ns, true);
pqih->addService(posted_ns, true);
pqih->addService(wiki_ns, true);
pqih->addService(gxsforums_ns, true);
pqih->addService(gxschannels_ns, true);
// remove pword from memory
RsInitConfig::gxs_passwd = "";
@ -1541,21 +1555,21 @@ int RsServer::StartupRetroShare()
#ifdef RS_RTT
p3rtt *mRtt = new p3rtt(mLinkMgr);
pqih -> addService(mRtt);
pqih -> addService(mRtt, true);
rsRtt = mRtt;
#endif
// new services to test.
p3BanList *mBanList = new p3BanList(mLinkMgr, mNetMgr);
pqih -> addService(mBanList);
pqih -> addService(mBanList, true);
mBitDht->setupPeerSharer(mBanList);
p3BandwidthControl *mBwCtrl = new p3BandwidthControl(pqih);
pqih -> addService(mBwCtrl);
pqih -> addService(mBwCtrl, true);
#ifdef SERVICES_DSDV
p3Dsdv *mDsdv = new p3Dsdv(mLinkMgr);
pqih -> addService(mDsdv);
pqih -> addService(mDsdv, true);
rsDsdv = mDsdv;
mDsdv->addTestService();
#endif
@ -1589,6 +1603,7 @@ int RsServer::StartupRetroShare()
/**************************************************************************/
/* need to Monitor too! */
mLinkMgr->addMonitor(serviceInfo);
mLinkMgr->addMonitor(pqih);
mLinkMgr->addMonitor(mCacheStrapper);
mLinkMgr->addMonitor(mDisc);

View File

@ -109,3 +109,7 @@ const uint8_t QOS_PRIORITY_RS_DSDV_DATA = 2 ;
const uint8_t QOS_PRIORITY_RS_GXS_NET = 3 ;
// GXS Reputation.
const uint8_t QOS_PRIORITY_RS_GXSREPUTATION_ITEM = 2;
// Service Info / Control.
const uint8_t QOS_PRIORITY_RS_SERVICE_INFO_ITEM = 7;

View File

@ -215,6 +215,12 @@ bool setRawUFloat32(void *data,uint32_t size,uint32_t *offset,float f)
return setRawUInt32(data, size, offset, n);
}
uint32_t getRawStringSize(const std::string &outStr)
{
return outStr.length() + 4;
}
bool getRawString(void *data, uint32_t size, uint32_t *offset, std::string &outStr)
{
uint32_t len = 0;

View File

@ -63,6 +63,7 @@ bool setRawUInt64(void *data, uint32_t size, uint32_t *offset, uint64_t in);
bool getRawUFloat32(void *data, uint32_t size, uint32_t *offset, float& out);
bool setRawUFloat32(void *data, uint32_t size, uint32_t *offset, float in);
uint32_t getRawStringSize(const std::string &outStr);
bool getRawString(void *data, uint32_t size, uint32_t *offset, std::string &outStr);
bool setRawString(void *data, uint32_t size, uint32_t *offset, const std::string &inStr);

View File

@ -52,6 +52,8 @@ const uint16_t RS_SERVICE_TYPE_FILE_TRANSFER = 0x0017;
/* BanList Still Testing at the moment - Service Only */
const uint16_t RS_SERVICE_TYPE_BANLIST = 0x0101;
const uint16_t RS_SERVICE_TYPE_SERVICEINFO = 0x0201;
/* Caches based on p3distrib (Cache Only)
* Unfortunately, noone changed the DUMMY IDS... so we are stuck with them!
*/

View File

@ -0,0 +1,445 @@
/*
* libretroshare/src/serialiser: rsserviceinfoitems.cc
*
* RetroShare Serialiser.
*
* Copyright 2014 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.1 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".
*
*/
#include "serialiser/rsbaseserial.h"
#include "serialiser/rsserviceinfoitems.h"
/***
#define RSSERIAL_DEBUG 1
***/
#include <iostream>
/*************************************************************************/
/***** RsServiceInfo ****/
template<>
std::ostream &RsTlvParamRef<RsServiceInfo>::print(std::ostream &out, uint16_t indent)
{
out << "RsServiceInfo: " << mParam.mServiceType << " name " << mParam.mServiceName;
out << std::endl;
out << "Version(" << mParam.mVersionMajor << "," << mParam.mVersionMinor << ")";
out << " MinVersion(" << mParam.mMinVersionMajor << "," << mParam.mMinVersionMinor << ")";
out << std::endl;
return out;
}
template<>
uint32_t RsTlvParamRef<RsServiceInfo>::TlvSize()
{
uint32_t s = TLV_HEADER_SIZE; /* header + 4 for size */
s += getRawStringSize(mParam.mServiceName);
s += 4; // type.
s += 4; // version.
s += 4; // min version.
return s;
}
template<>
void RsTlvParamRef<RsServiceInfo>::TlvClear()
{
mParam = RsServiceInfo();
mParam.mServiceName.clear();
}
template<>
bool RsTlvParamRef<RsServiceInfo>::SetTlv(void *data, uint32_t size, uint32_t *offset)
{
/* must check sizes */
uint32_t tlvsize = TlvSize();
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend)
{
return false; /* not enough space */
}
bool ok = true;
ok &= SetTlvBase(data, tlvend, offset, mParamType, tlvsize);
ok &= setRawString(data, tlvend, offset, mParam.mServiceName);
ok &= setRawUInt32(data, tlvend, offset, mParam.mServiceType);
ok &= setRawUInt16(data, tlvend, offset, mParam.mVersionMajor);
ok &= setRawUInt16(data, tlvend, offset, mParam.mVersionMinor);
ok &= setRawUInt16(data, tlvend, offset, mParam.mMinVersionMajor);
ok &= setRawUInt16(data, tlvend, offset, mParam.mMinVersionMinor);
if (!ok)
{
std::cerr << "RsTlvParamRef<RsServiceInfo>::SetTlv() Failed";
std::cerr << std::endl;
}
return ok;
}
template<>
bool RsTlvParamRef<RsServiceInfo>::GetTlv(void *data, uint32_t size, uint32_t *offset)
{
if (size < *offset + TLV_HEADER_SIZE)
return false;
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend) /* check size */
{
return false; /* not enough space */
}
if (tlvtype != mParamType) /* check type */
{
return false;
}
bool ok = true;
/* ready to load */
TlvClear();
/* skip the header */
(*offset) += TLV_HEADER_SIZE;
ok &= getRawString(data, tlvend, offset, mParam.mServiceName);
ok &= getRawUInt32(data, tlvend, offset, &(mParam.mServiceType));
ok &= getRawUInt16(data, tlvend, offset, &(mParam.mVersionMajor));
ok &= getRawUInt16(data, tlvend, offset, &(mParam.mVersionMinor));
ok &= getRawUInt16(data, tlvend, offset, &(mParam.mMinVersionMajor));
ok &= getRawUInt16(data, tlvend, offset, &(mParam.mMinVersionMinor));
return ok;
}
template class RsTlvParamRef<RsServiceInfo>;
/*************************************************************************/
RsServiceInfoListItem::~RsServiceInfoListItem()
{
return;
}
void RsServiceInfoListItem::clear()
{
mServiceInfo.clear();
}
std::ostream &RsServiceInfoListItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsServiceInfoListItem", indent);
uint16_t int_Indent = indent + 2;
RsTlvServiceInfoMapRef map(mServiceInfo);
map.print(out, int_Indent);
out << std::endl;
printRsItemEnd(out, "RsServiceInfoListItem", indent);
return out;
}
uint32_t RsServiceInfoSerialiser::sizeInfo(RsServiceInfoListItem *item)
{
uint32_t s = 8; /* header */
RsTlvServiceInfoMapRef map(item->mServiceInfo);
s += map.TlvSize();
return s;
}
/* serialise the data to the buffer */
bool RsServiceInfoSerialiser::serialiseInfo(RsServiceInfoListItem *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeInfo(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsServiceInfoSerialiser::serialiseInfo() Header: " << ok << std::endl;
std::cerr << "RsServiceInfoSerialiser::serialiseInfo() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
RsTlvServiceInfoMapRef map(item->mServiceInfo);
ok &= map.SetTlv(data, tlvsize, &offset);
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsServiceInfoSerialiser::serialiseInfo() Size Error! " << std::endl;
#endif
}
return ok;
}
RsServiceInfoListItem *RsServiceInfoSerialiser::deserialiseInfo(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t tlvsize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_SERVICEINFO != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_SERVICELIST_ITEM != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < tlvsize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = tlvsize;
bool ok = true;
/* ready to load */
RsServiceInfoListItem *item = new RsServiceInfoListItem();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
RsTlvServiceInfoMapRef map(item->mServiceInfo);
ok &= map.GetTlv(data, tlvsize, &offset);
if (offset != tlvsize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
/*************************************************************************/
/*************************************************************************/
RsServiceInfoPermissionsItem::~RsServiceInfoPermissionsItem()
{
return;
}
void RsServiceInfoPermissionsItem::clear()
{
allowedBw = 0;
}
std::ostream &RsServiceInfoPermissionsItem::print(std::ostream &out, uint16_t indent)
{
printRsItemBase(out, "RsServiceInfoPermissionsItem", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
out << "AllowedBw: " << allowedBw;
out << std::endl;
printRsItemEnd(out, "RsServiceInfoPermissionsItem", indent);
return out;
}
uint32_t RsServiceInfoSerialiser::sizePermissions(RsServiceInfoPermissionsItem * /*item*/)
{
uint32_t s = 8; /* header */
s += GetTlvUInt32Size();
return s;
}
/* serialise the data to the buffer */
bool RsServiceInfoSerialiser::serialisePermissions(RsServiceInfoPermissionsItem *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizePermissions(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG
std::cerr << "RsServiceInfoSerialiser::serialisePermissions() Header: " << ok << std::endl;
std::cerr << "RsServiceInfoSerialiser::serialisePermissions() Size: " << tlvsize << std::endl;
#endif
/* skip the header */
offset += 8;
/* add mandatory parts first */
ok &= SetTlvUInt32(data, tlvsize, &offset, TLV_TYPE_UINT32_BW, item->allowedBw);
if (offset != tlvsize)
{
ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsServiceInfoSerialiser::serialisePermissions() Size Error! " << std::endl;
#endif
}
return ok;
}
RsServiceInfoPermissionsItem *RsServiceInfoSerialiser::deserialisePermissions(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t tlvsize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_SERVICEINFO != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < tlvsize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = tlvsize;
bool ok = true;
/* ready to load */
RsServiceInfoPermissionsItem *item = new RsServiceInfoPermissionsItem();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
ok &= GetTlvUInt32(data, tlvsize, &offset, TLV_TYPE_UINT32_BW, &(item->allowedBw));
if (offset != tlvsize)
{
/* error */
delete item;
return NULL;
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
/*************************************************************************/
uint32_t RsServiceInfoSerialiser::size(RsItem *i)
{
RsServiceInfoListItem *sli;
RsServiceInfoPermissionsItem *spi;
if (NULL != (sli = dynamic_cast<RsServiceInfoListItem *>(i)))
{
return sizeInfo(sli);
}
if (NULL != (spi = dynamic_cast<RsServiceInfoPermissionsItem *>(i)))
{
return sizePermissions(spi);
}
return 0;
}
bool RsServiceInfoSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
{
RsServiceInfoListItem *sli;
RsServiceInfoPermissionsItem *spi;
if (NULL != (sli = dynamic_cast<RsServiceInfoListItem *>(i)))
{
return serialiseInfo(sli, data, pktsize);
}
if (NULL != (spi = dynamic_cast<RsServiceInfoPermissionsItem *>(i)))
{
return serialisePermissions(spi, data, pktsize);
}
return false;
}
RsItem *RsServiceInfoSerialiser::deserialise(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_SERVICEINFO != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_SERVICELIST_ITEM:
return deserialiseInfo(data, pktsize);
break;
case RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM:
return deserialisePermissions(data, pktsize);
break;
default:
return NULL;
break;
}
}
/*************************************************************************/

View File

@ -0,0 +1,133 @@
#ifndef RS_SERVICE_INFO_ITEMS_H
#define RS_SERVICE_INFO_ITEMS_H
/*
* libretroshare/src/serialiser: rsserviceinfoitems.h
*
* RetroShare Serialiser.
*
* Copyright 2012 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.1 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".
*
*/
// Provides serialiser for p3ServiceControl & p3ServiceInfo.
#include <map>
#include "serialiser/rsserviceids.h"
#include "serialiser/rsserial.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rstlvgenericmap.h"
#include "retroshare/rsservicecontrol.h"
#define RS_PKT_SUBTYPE_SERVICELIST_ITEM 0x01
#define RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM 0x02
/**************************************************************************/
#define SERVICE_INFO_MAP 0x01
#define SERVICE_INFO_KEY 0x01
#define SERVICE_ID 0x01
#define SERVICE_INFO 0x01
class RsTlvServiceInfoMapRef: public RsTlvGenericMapRef<uint32_t, RsServiceInfo>
{
public:
RsTlvServiceInfoMapRef(std::map<uint32_t, RsServiceInfo> &refmap)
:RsTlvGenericMapRef<uint32_t, RsServiceInfo>(
SERVICE_INFO_MAP,
SERVICE_INFO_KEY,
SERVICE_ID,
SERVICE_INFO,
refmap)
{
return;
}
};
class RsServiceInfoListItem: public RsItem
{
public:
RsServiceInfoListItem()
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_SERVICEINFO,
RS_PKT_SUBTYPE_SERVICELIST_ITEM)
{
setPriorityLevel(QOS_PRIORITY_RS_SERVICE_INFO_ITEM);
return;
}
virtual ~RsServiceInfoListItem();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
std::map<uint32_t, RsServiceInfo> mServiceInfo;
};
class RsServiceInfoPermissionsItem: public RsItem
{
public:
RsServiceInfoPermissionsItem()
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_SERVICEINFO,
RS_PKT_SUBTYPE_SERVICEPERMISSIONS_ITEM)
{
setPriorityLevel(QOS_PRIORITY_RS_SERVICE_INFO_ITEM);
return;
}
virtual ~RsServiceInfoPermissionsItem();
virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
uint32_t allowedBw; // Units are bytes/sec => 4Gb/s;
};
class RsServiceInfoSerialiser: public RsSerialType
{
public:
RsServiceInfoSerialiser()
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_SERVICEINFO)
{ return; }
virtual ~RsServiceInfoSerialiser()
{ return; }
virtual uint32_t size(RsItem *);
virtual bool serialise (RsItem *item, void *data, uint32_t *size);
virtual RsItem * deserialise(void *data, uint32_t *size);
private:
virtual uint32_t sizeInfo(RsServiceInfoListItem *);
virtual bool serialiseInfo(RsServiceInfoListItem *item, void *data, uint32_t *size);
virtual RsServiceInfoListItem *deserialiseInfo(void *data, uint32_t *size);
virtual uint32_t sizePermissions(RsServiceInfoPermissionsItem *);
virtual bool serialisePermissions(RsServiceInfoPermissionsItem *item, void *data, uint32_t *size);
virtual RsServiceInfoPermissionsItem *deserialisePermissions(void *data, uint32_t *size);
};
/**************************************************************************/
#endif /* RS_SERVICE_INFO_ITEMS_H */

View File

@ -259,6 +259,98 @@ bool GetTlvUInt32(void *data, uint32_t size, uint32_t *offset,
return ok;
}
// UInt16
bool SetTlvUInt16(void *data, uint32_t size, uint32_t *offset, uint16_t type,
uint16_t out)
{
if (!data)
return false;
uint32_t tlvsize = GetTlvUInt16Size(); /* this will always be 8 bytes */
uint32_t tlvend = *offset + tlvsize; /* where the data will extend to */
if (size < tlvend)
{
#ifdef TLV_BASE_DEBUG
std::cerr << "SetTlvUInt16() FAILED - not enough space. (or earlier)" << std::endl;
std::cerr << "SetTlvUInt16() size: " << size << std::endl;
std::cerr << "SetTlvUInt16() tlvsize: " << tlvsize << std::endl;
std::cerr << "SetTlvUInt16() tlvend: " << tlvend << std::endl;
#endif
return false;
}
bool ok = true;
/* Now use the function we got to set the TlvHeader */
/* function shifts offset to the new start for the next data */
ok &= SetTlvBase(data, tlvend, offset, type, tlvsize);
#ifdef TLV_BASE_DEBUG
if (!ok)
{
std::cerr << "SetTlvUInt16() SetTlvBase FAILED (or earlier)" << std::endl;
}
#endif
/* now set the UInt16 ( in rsbaseserial.h???) */
ok &= setRawUInt16(data, tlvend, offset, out);
#ifdef TLV_BASE_DEBUG
if (!ok)
{
std::cerr << "SetTlvUInt16() setRawUInt16 FAILED (or earlier)" << std::endl;
}
#endif
return ok;
}
bool GetTlvUInt16(void *data, uint32_t size, uint32_t *offset,
uint16_t type, uint16_t *in)
{
if (!data)
return false;
if (size < *offset + TLV_HEADER_SIZE)
return false;
/* extract the type and size */
void *tlvstart = right_shift_void_pointer(data, *offset);
uint16_t tlvtype = GetTlvType(tlvstart);
uint32_t tlvsize = GetTlvSize(tlvstart);
/* check that there is size */
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend)
{
#ifdef TLV_BASE_DEBUG
std::cerr << "GetTlvUInt16() FAILED - not enough space." << std::endl;
std::cerr << "GetTlvUInt16() size: " << size << std::endl;
std::cerr << "GetTlvUInt16() tlvsize: " << tlvsize << std::endl;
std::cerr << "GetTlvUInt16() tlvend: " << tlvend << std::endl;
#endif
return false;
}
if (type != tlvtype)
{
#ifdef TLV_BASE_DEBUG
std::cerr << "GetTlvUInt16() FAILED - Type mismatch" << std::endl;
std::cerr << "GetTlvUInt16() type: " << type << std::endl;
std::cerr << "GetTlvUInt16() tlvtype: " << tlvtype << std::endl;
#endif
return false;
}
*offset += TLV_HEADER_SIZE; /* step past header */
bool ok = true;
ok &= getRawUInt16(data, tlvend, offset, in);
return ok;
}
uint32_t GetTlvUInt64Size() {
return TLV_HEADER_SIZE + 8;

View File

@ -32,28 +32,7 @@
#include <stdlib.h>
#include <stdint.h>
/**** TLV *****
* Generic Parameters / Maps.
*/
template<class T>
class RsTlvParamRef: public RsTlvItem
{
public:
RsTlvParamRef(uint16_t param_type, T &p): mParamType(param_type), mParam(p) {}
virtual ~RsTlvParamRef() { return; }
virtual uint32_t TlvSize();
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
virtual std::ostream &print(std::ostream &out, uint16_t indent);
uint16_t mParamType;
T &mParam;
};
#include "serialiser/rstlvgenericparam.h"
/*********************************** RsTlvGenericPairRef ***********************************/
@ -107,5 +86,7 @@ virtual std::ostream &print(std::ostream &out, uint16_t indent);
};
#include "rstlvgenericmap.inl"
#endif

View File

@ -1,6 +1,6 @@
/*
* libretroshare/src/serialiser: rstlvgenericmap.cc
* libretroshare/src/serialiser: rstlvgenericmap.inl
*
* RetroShare Serialiser.
*
@ -36,89 +36,6 @@
#define TLV_DEBUG 1
/* generic print */
template<class T>
std::ostream & RsTlvParamRef<T>::print(std::ostream &out, uint16_t indent)
{
printIndent(out, indent);
out << "Type: " << mParamType << "Param: " << mParam;
return out;
}
template<>
uint32_t RsTlvParamRef<uint32_t>::TlvSize()
{
return GetTlvUInt32Size();
}
template<>
void RsTlvParamRef<uint32_t>::TlvClear()
{
mParam = 0;
}
template<>
bool RsTlvParamRef<uint32_t>::SetTlv(void *data, uint32_t size, uint32_t *offset)
{
return SetTlvUInt32(data, size, offset, mParamType, mParam);
}
template<>
bool RsTlvParamRef<uint32_t>::GetTlv(void *data, uint32_t size, uint32_t *offset)
{
return GetTlvUInt32(data, size, offset, mParamType, &mParam);
}
#if 0
template<>
std::ostream & RsTlvParamRef<uint32_t>::print(std::ostream &out, uint16_t indent)
{
printIndent(out, indent);
out << mParam;
return out;
}
#endif
/***** std::string ****/
template<>
uint32_t RsTlvParamRef<std::string>::TlvSize()
{
return GetTlvStringSize(mParam);
}
template<>
void RsTlvParamRef<std::string>::TlvClear()
{
mParam.clear();
}
template<>
bool RsTlvParamRef<std::string>::SetTlv(void *data, uint32_t size, uint32_t *offset)
{
return SetTlvString(data, size, offset, mParamType, mParam);
}
template<>
bool RsTlvParamRef<std::string>::GetTlv(void *data, uint32_t size, uint32_t *offset)
{
return GetTlvString(data, size, offset, mParamType, mParam);
}
#if 0
template<>
std::ostream & RsTlvParamRef<std::string>::print(std::ostream &out, uint16_t indent)
{
printIndent(out, indent);
out << "Type: " << mParamType << "Param: " << mParam;
return out;
}
#endif
// declare likely combinations.
template class RsTlvParamRef<uint32_t>;
template class RsTlvParamRef<std::string>;
/*********************************** RsTlvGenericPairRef ***********************************/
template<class K, class V>
@ -163,6 +80,16 @@ bool RsTlvGenericPairRef<K, V>::SetTlv(void *data, uint32_t size, uint32_t *off
ok &= key.SetTlv(data, tlvend, offset);
ok &= value.SetTlv(data, tlvend, offset);
if (!ok)
{
std::cerr << "RsTlvGenericPairRef<>::SetTlv() Failed";
std::cerr << std::endl;
}
else
{
std::cerr << "RsTlvGenericPairRef<>::SetTlv() Ok";
std::cerr << std::endl;
}
return ok;
}
@ -187,6 +114,9 @@ bool RsTlvGenericPairRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *off
/* ready to load */
TlvClear();
/* skip the header */
(*offset) += TLV_HEADER_SIZE;
RsTlvParamRef<K> key(mKeyType, mKey);
RsTlvParamRef<V> value(mValueType, mValue);
ok &= key.GetTlv(data, tlvend, offset);
@ -213,7 +143,7 @@ bool RsTlvGenericPairRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *off
template<class K, class V>
std::ostream &RsTlvGenericPairRef<K, V>::print(std::ostream &out, uint16_t indent)
{
printBase(out, "RsTlvGenericPairRef", indent);
//printBase(out, "RsTlvGenericPairRef", indent);
uint16_t int_Indent = indent + 2;
RsTlvParamRef<K> key(mKeyType, mKey);
@ -229,7 +159,7 @@ std::ostream &RsTlvGenericPairRef<K, V>::print(std::ostream &out, uint16_t inden
value.print(out, 0);
out << std::endl;
printEnd(out, "RsTlvGenericPairRef", indent);
//printEnd(out, "RsTlvGenericPairRef", indent);
return out;
}
@ -285,6 +215,12 @@ bool RsTlvGenericMapRef<K, V>::SetTlv(void *data, uint32_t size, uint32_t *offs
ok &= pair.SetTlv(data, size, offset);
}
if (!ok)
{
std::cerr << "RsTlvGenericMapRef<>::SetTlv() Failed";
std::cerr << std::endl;
}
return ok;
}
@ -322,7 +258,7 @@ bool RsTlvGenericMapRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *offs
{
K k;
V v;
RsTlvGenericPairRef<const K, V> pair(mPairType, mKeyType, mValueType, k, v);
RsTlvGenericPairRef<K, V> pair(mPairType, mKeyType, mValueType, k, v);
ok &= pair.GetTlv(data, size, offset);
if (ok)
{
@ -360,7 +296,7 @@ bool RsTlvGenericMapRef<K, V>::GetTlv(void *data, uint32_t size, uint32_t *offs
template<class K, class V>
std::ostream &RsTlvGenericMapRef<K, V>::print(std::ostream &out, uint16_t indent)
{
printBase(out, "RsTlvGenericMapRef", indent);
//printBase(out, "RsTlvGenericMapRef", indent);
uint16_t int_Indent = indent + 2;
printIndent(out, int_Indent);
@ -373,15 +309,15 @@ std::ostream &RsTlvGenericMapRef<K, V>::print(std::ostream &out, uint16_t indent
pair.print(out, int_Indent);
}
printEnd(out, "RsTlvGenericMapRef", indent);
//printEnd(out, "RsTlvGenericMapRef", indent);
return out;
}
// declare likely combinations.
template class RsTlvGenericMapRef<uint32_t, uint32_t>;
template class RsTlvGenericMapRef<uint32_t, std::string>;
template class RsTlvGenericMapRef<std::string, uint32_t>;
template class RsTlvGenericMapRef<std::string, std::string>;
//template class RsTlvGenericMapRef<uint32_t, uint32_t>;
//template class RsTlvGenericMapRef<uint32_t, std::string>;
//template class RsTlvGenericMapRef<std::string, uint32_t>;
//template class RsTlvGenericMapRef<std::string, std::string>;

View File

@ -0,0 +1,235 @@
/*
* libretroshare/src/serialiser: rstlvgenericparam.cc
*
* RetroShare Serialiser.
*
* Copyright 2014 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.1 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".
*
*/
#include "rstlvbase.h"
#include "rstlvtypes.h"
#include "rstlvgenericmap.h"
#include "rsbaseserial.h"
#include "util/rsprint.h"
#include <ostream>
#include <sstream>
#include <iomanip>
#include <iostream>
#define TLV_DEBUG 1
/* generic print */
template<class T>
std::ostream & RsTlvParamRef<T>::print(std::ostream &out, uint16_t indent)
{
printIndent(out, indent);
out << "Type: " << mParamType << " Param: " << mParam;
return out;
}
/***** uint16_t ****/
template<>
uint32_t RsTlvParamRef<uint16_t>::TlvSize()
{
return GetTlvUInt16Size();
}
template<>
void RsTlvParamRef<uint16_t>::TlvClear()
{
mParam = 0;
}
template<>
bool RsTlvParamRef<uint16_t>::SetTlv(void *data, uint32_t size, uint32_t *offset)
{
uint16_t param = mParam;
return SetTlvUInt16(data, size, offset, mParamType, mParam);
}
template<>
bool RsTlvParamRef<uint16_t>::GetTlv(void *data, uint32_t size, uint32_t *offset)
{
uint16_t param;
bool retval = GetTlvUInt16(data, size, offset, mParamType, &param);
mParam = param;
return retval;
}
template<>
std::ostream & RsTlvParamRef<uint16_t>::print(std::ostream &out, uint16_t indent)
{
printIndent(out, indent);
out << "Type: " << mParamType << "Param: " << mParam;
return out;
}
/***** const uint16_t ****/
template<>
uint32_t RsTlvParamRef<const uint16_t>::TlvSize()
{
return GetTlvUInt16Size();
}
template<>
void RsTlvParamRef<const uint16_t>::TlvClear()
{
//mParam = 0;
}
template<>
bool RsTlvParamRef<const uint16_t>::SetTlv(void *data, uint32_t size, uint32_t *offset)
{
return SetTlvUInt16(data, size, offset, mParamType, mParam);
}
template<>
bool RsTlvParamRef<const uint16_t>::GetTlv(void *data, uint32_t size, uint32_t *offset)
{
return false; //GetTlvUInt16(data, size, offset, mParamType, &mParam);
}
template<>
std::ostream & RsTlvParamRef<const uint16_t>::print(std::ostream &out, uint16_t indent)
{
printIndent(out, indent);
out << "Type: " << mParamType << "Param: " << mParam;
return out;
}
/***** uint32_t ****/
template<>
uint32_t RsTlvParamRef<uint32_t>::TlvSize()
{
return GetTlvUInt32Size();
}
template<>
void RsTlvParamRef<uint32_t>::TlvClear()
{
mParam = 0;
}
template<>
bool RsTlvParamRef<uint32_t>::SetTlv(void *data, uint32_t size, uint32_t *offset)
{
return SetTlvUInt32(data, size, offset, mParamType, mParam);
}
template<>
bool RsTlvParamRef<uint32_t>::GetTlv(void *data, uint32_t size, uint32_t *offset)
{
return GetTlvUInt32(data, size, offset, mParamType, &mParam);
}
template<>
std::ostream & RsTlvParamRef<uint32_t>::print(std::ostream &out, uint16_t indent)
{
printIndent(out, indent);
out << "Type: " << mParamType << "Param: " << mParam;
return out;
}
/***** const uint32_t ****/
template<>
uint32_t RsTlvParamRef<const uint32_t>::TlvSize()
{
return GetTlvUInt32Size();
}
template<>
void RsTlvParamRef<const uint32_t>::TlvClear()
{
//mParam = 0;
}
template<>
bool RsTlvParamRef<const uint32_t>::SetTlv(void *data, uint32_t size, uint32_t *offset)
{
return SetTlvUInt32(data, size, offset, mParamType, mParam);
}
template<>
bool RsTlvParamRef<const uint32_t>::GetTlv(void *data, uint32_t size, uint32_t *offset)
{
return false;
//GetTlvUInt32(data, size, offset, mParamType, &mParam);
}
template<>
std::ostream & RsTlvParamRef<const uint32_t>::print(std::ostream &out, uint16_t indent)
{
printIndent(out, indent);
out << "Type: " << mParamType << "Param: " << mParam;
return out;
}
/***** std::string ****/
template<>
uint32_t RsTlvParamRef<std::string>::TlvSize()
{
return GetTlvStringSize(mParam);
}
template<>
void RsTlvParamRef<std::string>::TlvClear()
{
mParam.clear();
}
template<>
bool RsTlvParamRef<std::string>::SetTlv(void *data, uint32_t size, uint32_t *offset)
{
return SetTlvString(data, size, offset, mParamType, mParam);
}
template<>
bool RsTlvParamRef<std::string>::GetTlv(void *data, uint32_t size, uint32_t *offset)
{
return GetTlvString(data, size, offset, mParamType, mParam);
}
template<>
std::ostream & RsTlvParamRef<std::string>::print(std::ostream &out, uint16_t indent)
{
printIndent(out, indent);
out << "Type: " << mParamType << "Param: " << mParam;
return out;
}
// declare likely combinations.
//template class RsTlvParamRef<uint16_t>;
//template class RsTlvParamRef<uint32_t>;
//template class RsTlvParamRef<std::string>;
//template class RsTlvParamRef<const uint16_t>;
//template class RsTlvParamRef<const uint32_t>;
//template class RsTlvParamRef<const std::string>;

View File

@ -0,0 +1,59 @@
#ifndef RS_TLV_GENERIC_PARAM_H
#define RS_TLV_GENERIC_PARAM_H
/*
* libretroshare/src/serialiser: rstlvgenericparam.h
*
* RetroShare Serialiser.
*
* Copyright 2014 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.1 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".
*
*/
#include "serialiser/rstlvtypes.h"
#include <map>
#include <stdlib.h>
#include <stdint.h>
/**** TLV *****
* Generic Parameters / Maps.
*/
template<class T>
class RsTlvParamRef: public RsTlvItem
{
public:
RsTlvParamRef(uint16_t param_type, T &p): mParamType(param_type), mParam(p) {}
virtual ~RsTlvParamRef() { return; }
virtual uint32_t TlvSize();
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset); /* serialise */
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset); /* deserialise */
virtual std::ostream &print(std::ostream &out, uint16_t indent);
uint16_t mParamType;
T &mParam;
};
#endif

View File

@ -64,6 +64,7 @@ std::ostream &printEnd(std::ostream &out, std::string clsName, uint16_t indent);
std::ostream &printIndent(std::ostream &out, uint16_t indent);
//! GENERIC Binary Data TLV
/*! Use to serialise and deserialise binary data, usually included in other compound tlvs
*/

View File

@ -58,7 +58,7 @@
p3BanList::p3BanList(p3LinkMgr *lm, p3NetMgr *nm)
:p3Service(RS_SERVICE_TYPE_BANLIST), mBanMtx("p3BanList"), mLinkMgr(lm), mNetMgr(nm)
:p3Service(), mBanMtx("p3BanList"), mLinkMgr(lm), mNetMgr(nm)
{
addSerialType(new RsBanListSerialiser());
@ -66,6 +66,24 @@ p3BanList::p3BanList(p3LinkMgr *lm, p3NetMgr *nm)
}
const std::string BANLIST_APP_NAME = "banlist";
const uint16_t BANLIST_APP_MAJOR_VERSION = 1;
const uint16_t BANLIST_APP_MINOR_VERSION = 0;
const uint16_t BANLIST_MIN_MAJOR_VERSION = 1;
const uint16_t BANLIST_MIN_MINOR_VERSION = 0;
RsServiceInfo p3BanList::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_TYPE_BANLIST,
BANLIST_APP_NAME,
BANLIST_APP_MAJOR_VERSION,
BANLIST_APP_MINOR_VERSION,
BANLIST_MIN_MAJOR_VERSION,
BANLIST_MIN_MINOR_VERSION);
}
int p3BanList::tick()
{
processIncoming();

View File

@ -69,6 +69,7 @@ class p3BanList: /* public RsBanList, */ public p3Service, public pqiNetAssistPe
{
public:
p3BanList(p3LinkMgr *lm, p3NetMgr *nm);
virtual RsServiceInfo getServiceInfo();
/***** overloaded from RsBanList *****/

View File

@ -46,7 +46,7 @@ p3BandwidthControl *rsBandwidthControl;
p3BandwidthControl::p3BandwidthControl(pqipersongrp *pg)
:p3Service(RS_SERVICE_TYPE_BWCTRL), mPg(pg), mBwMtx("p3BwCtrl")
:p3Service(), mPg(pg), mBwMtx("p3BwCtrl")
{
addSerialType(new RsBwCtrlSerialiser());
@ -54,6 +54,24 @@ p3BandwidthControl::p3BandwidthControl(pqipersongrp *pg)
}
const std::string BANDWIDTH_CTRL_APP_NAME = "bandwidth_ctrl";
const uint16_t BANDWIDTH_CTRL_APP_MAJOR_VERSION = 1;
const uint16_t BANDWIDTH_CTRL_APP_MINOR_VERSION = 0;
const uint16_t BANDWIDTH_CTRL_MIN_MAJOR_VERSION = 1;
const uint16_t BANDWIDTH_CTRL_MIN_MINOR_VERSION = 0;
RsServiceInfo p3BandwidthControl::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_TYPE_BWCTRL,
BANDWIDTH_CTRL_APP_NAME,
BANDWIDTH_CTRL_APP_MAJOR_VERSION,
BANDWIDTH_CTRL_APP_MINOR_VERSION,
BANDWIDTH_CTRL_MIN_MAJOR_VERSION,
BANDWIDTH_CTRL_MIN_MINOR_VERSION);
}
int p3BandwidthControl::tick()
{
processIncoming();

View File

@ -73,6 +73,7 @@ class p3BandwidthControl: public p3Service, public pqiMonitor
{
public:
p3BandwidthControl(pqipersongrp *pg);
virtual RsServiceInfo getServiceInfo();
/***** overloaded from RsBanList *****/

View File

@ -76,7 +76,7 @@ static const uint32_t MAX_MESSAGES_PER_SECONDS_NUMBER = 5 ; // max number o
static const uint32_t MAX_MESSAGES_PER_SECONDS_PERIOD = 10 ; // duration window for max number of messages before messages get dropped.
p3ChatService::p3ChatService(p3LinkMgr *lm, p3HistoryMgr *historyMgr)
:p3Service(RS_SERVICE_TYPE_CHAT), p3Config(CONFIG_TYPE_CHAT), mChatMtx("p3ChatService"), mLinkMgr(lm) , mHistoryMgr(historyMgr)
:p3Service(), p3Config(CONFIG_TYPE_CHAT), mChatMtx("p3ChatService"), mLinkMgr(lm) , mHistoryMgr(historyMgr)
{
_serializer = new RsChatSerialiser() ;
_own_avatar = NULL ;
@ -91,6 +91,23 @@ p3ChatService::p3ChatService(p3LinkMgr *lm, p3HistoryMgr *historyMgr)
addSerialType(_serializer) ;
}
const std::string CHAT_APP_NAME = "chat";
const uint16_t CHAT_APP_MAJOR_VERSION = 1;
const uint16_t CHAT_APP_MINOR_VERSION = 0;
const uint16_t CHAT_MIN_MAJOR_VERSION = 1;
const uint16_t CHAT_MIN_MINOR_VERSION = 0;
RsServiceInfo p3ChatService::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_TYPE_CHAT,
CHAT_APP_NAME,
CHAT_APP_MAJOR_VERSION,
CHAT_APP_MINOR_VERSION,
CHAT_MIN_MAJOR_VERSION,
CHAT_MIN_MINOR_VERSION);
}
void p3ChatService::connectToTurtleRouter(p3turtle *tr)
{
mTurtle = tr ;

View File

@ -55,6 +55,8 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
public:
p3ChatService(p3LinkMgr *cm, p3HistoryMgr *historyMgr);
virtual RsServiceInfo getServiceInfo();
/***** overloaded from p3Service *****/
/*!
* This retrieves all chat msg items and also (important!)

View File

@ -85,7 +85,7 @@ void DiscPgpInfo::mergeFriendList(const std::list<PGPID> &friends)
p3discovery2::p3discovery2(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr *netMgr)
:p3Service(RS_SERVICE_TYPE_DISC), mPeerMgr(peerMgr), mLinkMgr(linkMgr), mNetMgr(netMgr),
:p3Service(), mPeerMgr(peerMgr), mLinkMgr(linkMgr), mNetMgr(netMgr),
mDiscMtx("p3discovery2")
{
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
@ -105,6 +105,28 @@ p3discovery2::p3discovery2(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr *net
return;
}
const std::string DISCOVERY_APP_NAME = "disc";
const uint16_t DISCOVERY_APP_MAJOR_VERSION = 1;
const uint16_t DISCOVERY_APP_MINOR_VERSION = 0;
const uint16_t DISCOVERY_MIN_MAJOR_VERSION = 1;
const uint16_t DISCOVERY_MIN_MINOR_VERSION = 0;
RsServiceInfo p3discovery2::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_TYPE_DISC,
DISCOVERY_APP_NAME,
DISCOVERY_APP_MAJOR_VERSION,
DISCOVERY_APP_MINOR_VERSION,
DISCOVERY_MIN_MAJOR_VERSION,
DISCOVERY_MIN_MINOR_VERSION);
}
p3discovery2::~p3discovery2()
{
return;

View File

@ -81,6 +81,8 @@ class p3discovery2: public RsDisc, public p3Service, public pqiMonitor, public A
p3discovery2(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr *netMgr);
virtual ~p3discovery2();
virtual RsServiceInfo getServiceInfo();
/************* from pqiMonitor *******************/
virtual void statusChange(const std::list<pqipeer> &plist);
/************* from pqiMonitor *******************/

View File

@ -64,7 +64,7 @@ RsDsdv *rsDsdv = NULL;
****/
p3Dsdv::p3Dsdv(p3LinkMgr *lm)
:p3Service(RS_SERVICE_TYPE_DSDV), /* p3Config(CONFIG_TYPE_DSDV), */ mDsdvMtx("p3Dsdv"), mLinkMgr(lm)
:p3Service(), /* p3Config(CONFIG_TYPE_DSDV), */ mDsdvMtx("p3Dsdv"), mLinkMgr(lm)
{
addSerialType(new RsDsdvSerialiser());
@ -72,6 +72,24 @@ p3Dsdv::p3Dsdv(p3LinkMgr *lm)
mSentIncrementTime = 0;
}
const std::string DSDV_APP_NAME = "dsdv";
const uint16_t DSDV_APP_MAJOR_VERSION = 1;
const uint16_t DSDV_APP_MINOR_VERSION = 0;
const uint16_t DSDV_MIN_MAJOR_VERSION = 1;
const uint16_t DSDV_MIN_MINOR_VERSION = 0;
RsServiceInfo p3Dsdv::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_TYPE_DSDV,
DSDV_APP_NAME,
DSDV_APP_MAJOR_VERSION,
DSDV_APP_MINOR_VERSION,
DSDV_MIN_MAJOR_VERSION,
DSDV_MIN_MINOR_VERSION);
}
int p3Dsdv::tick()
{
processIncoming();

View File

@ -53,6 +53,7 @@ class p3Dsdv: public RsDsdv, public p3Service /* , public p3Config */, public pq
{
public:
p3Dsdv(p3LinkMgr *cm);
virtual RsServiceInfo getServiceInfo();
/*** internal librs interface ****/

View File

@ -78,6 +78,24 @@ p3GxsChannels::p3GxsChannels(RsGeneralDataService *gds, RsNetworkExchangeService
}
const std::string GXS_CHANNELS_APP_NAME = "gxschannels";
const uint16_t GXS_CHANNELS_APP_MAJOR_VERSION = 1;
const uint16_t GXS_CHANNELS_APP_MINOR_VERSION = 0;
const uint16_t GXS_CHANNELS_MIN_MAJOR_VERSION = 1;
const uint16_t GXS_CHANNELS_MIN_MINOR_VERSION = 0;
RsServiceInfo p3GxsChannels::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_CHANNELS,
GXS_CHANNELS_APP_NAME,
GXS_CHANNELS_APP_MAJOR_VERSION,
GXS_CHANNELS_APP_MINOR_VERSION,
GXS_CHANNELS_MIN_MAJOR_VERSION,
GXS_CHANNELS_MIN_MINOR_VERSION);
}
uint32_t p3GxsChannels::channelsAuthenPolicy()
{
uint32_t policy = 0;

View File

@ -60,6 +60,7 @@ class p3GxsChannels: public RsGenExchange, public RsGxsChannels,
public:
p3GxsChannels(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs);
virtual RsServiceInfo getServiceInfo();
virtual void service_tick();

View File

@ -130,6 +130,24 @@ p3GxsCircles::p3GxsCircles(RsGeneralDataService *gds, RsNetworkExchangeService *
}
const std::string GXS_CIRCLES_APP_NAME = "gxscircle";
const uint16_t GXS_CIRCLES_APP_MAJOR_VERSION = 1;
const uint16_t GXS_CIRCLES_APP_MINOR_VERSION = 0;
const uint16_t GXS_CIRCLES_MIN_MAJOR_VERSION = 1;
const uint16_t GXS_CIRCLES_MIN_MINOR_VERSION = 0;
RsServiceInfo p3GxsCircles::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_GXSCIRCLE,
GXS_CIRCLES_APP_NAME,
GXS_CIRCLES_APP_MAJOR_VERSION,
GXS_CIRCLES_APP_MINOR_VERSION,
GXS_CIRCLES_MIN_MAJOR_VERSION,
GXS_CIRCLES_MIN_MINOR_VERSION);
}
uint32_t p3GxsCircles::circleAuthenPolicy()
{

View File

@ -135,6 +135,8 @@ class p3GxsCircles: public RsGxsCircleExchange, public RsGxsCircles,
p3GxsCircles(RsGeneralDataService* gds, RsNetworkExchangeService* nes,
p3IdService *identities);
virtual RsServiceInfo getServiceInfo();
/*********** External Interface ***************/
virtual bool getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails &details);

View File

@ -61,6 +61,24 @@ p3GxsForums::p3GxsForums(RsGeneralDataService *gds, RsNetworkExchangeService *ne
}
const std::string GXS_FORUMS_APP_NAME = "gxsforums";
const uint16_t GXS_FORUMS_APP_MAJOR_VERSION = 1;
const uint16_t GXS_FORUMS_APP_MINOR_VERSION = 0;
const uint16_t GXS_FORUMS_MIN_MAJOR_VERSION = 1;
const uint16_t GXS_FORUMS_MIN_MINOR_VERSION = 0;
RsServiceInfo p3GxsForums::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_FORUMS,
GXS_FORUMS_APP_NAME,
GXS_FORUMS_APP_MAJOR_VERSION,
GXS_FORUMS_APP_MINOR_VERSION,
GXS_FORUMS_MIN_MAJOR_VERSION,
GXS_FORUMS_MIN_MINOR_VERSION);
}
uint32_t p3GxsForums::forumsAuthenPolicy()
{
uint32_t policy = 0;

View File

@ -46,6 +46,8 @@ class p3GxsForums: public RsGenExchange, public RsGxsForums,
p3GxsForums(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs);
virtual RsServiceInfo getServiceInfo();
virtual void service_tick();
protected:

View File

@ -123,7 +123,7 @@ uint32_t ConvertToSerialised(int32_t value, bool limit)
p3GxsReputation::p3GxsReputation(p3LinkMgr *lm)
:p3Service(RS_SERVICE_GXSV2_TYPE_REPUTATION), p3Config(CONFIG_TYPE_GXS_REPUTATION),
:p3Service(), p3Config(CONFIG_TYPE_GXS_REPUTATION),
mReputationMtx("p3GxsReputation"), mLinkMgr(lm)
{
addSerialType(new RsGxsReputationSerialiser());
@ -134,6 +134,24 @@ p3GxsReputation::p3GxsReputation(p3LinkMgr *lm)
}
const std::string GXS_REPUTATION_APP_NAME = "gxsreputation";
const uint16_t GXS_REPUTATION_APP_MAJOR_VERSION = 1;
const uint16_t GXS_REPUTATION_APP_MINOR_VERSION = 0;
const uint16_t GXS_REPUTATION_MIN_MAJOR_VERSION = 1;
const uint16_t GXS_REPUTATION_MIN_MINOR_VERSION = 0;
RsServiceInfo p3GxsReputation::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_REPUTATION,
GXS_REPUTATION_APP_NAME,
GXS_REPUTATION_APP_MAJOR_VERSION,
GXS_REPUTATION_APP_MINOR_VERSION,
GXS_REPUTATION_MIN_MAJOR_VERSION,
GXS_REPUTATION_MIN_MINOR_VERSION);
}
int p3GxsReputation::tick()
{
processIncoming();

View File

@ -84,6 +84,7 @@ class p3GxsReputation: public p3Service, public p3Config /* , public pqiMonitor
{
public:
p3GxsReputation(p3LinkMgr *lm);
virtual RsServiceInfo getServiceInfo();
/***** Interface for p3idservice *****/

View File

@ -32,7 +32,7 @@
p3heartbeat::p3heartbeat(p3LinkMgr *linkMgr, pqipersongrp *pqipg)
:p3Service(RS_SERVICE_TYPE_HEARTBEAT), mLinkMgr(linkMgr), mPqiPersonGrp(pqipg),
:p3Service(), mLinkMgr(linkMgr), mPqiPersonGrp(pqipg),
mHeartMtx("p3heartbeat")
{
RsStackMutex stack(mHeartMtx); /********** STACK LOCKED MTX ******/
@ -55,6 +55,24 @@ p3heartbeat::~p3heartbeat()
}
const std::string HEARTBEAT_APP_NAME = "heartbeat";
const uint16_t HEARTBEAT_APP_MAJOR_VERSION = 1;
const uint16_t HEARTBEAT_APP_MINOR_VERSION = 0;
const uint16_t HEARTBEAT_MIN_MAJOR_VERSION = 1;
const uint16_t HEARTBEAT_MIN_MINOR_VERSION = 0;
RsServiceInfo p3heartbeat::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_TYPE_HEARTBEAT,
HEARTBEAT_APP_NAME,
HEARTBEAT_APP_MAJOR_VERSION,
HEARTBEAT_APP_MINOR_VERSION,
HEARTBEAT_MIN_MAJOR_VERSION,
HEARTBEAT_MIN_MINOR_VERSION);
}
int p3heartbeat::tick()
{
//send a heartbeat to all connected peers

View File

@ -40,6 +40,8 @@ class p3heartbeat: public p3Service
p3heartbeat(p3LinkMgr *linkMgr, pqipersongrp *pqipg);
virtual ~p3heartbeat();
virtual RsServiceInfo getServiceInfo();
int tick();
private:

View File

@ -165,6 +165,24 @@ p3IdService::p3IdService(RsGeneralDataService *gds, RsNetworkExchangeService *ne
loadRecognKeys();
}
const std::string GXSID_APP_NAME = "gxsid";
const uint16_t GXSID_APP_MAJOR_VERSION = 1;
const uint16_t GXSID_APP_MINOR_VERSION = 0;
const uint16_t GXSID_MIN_MAJOR_VERSION = 1;
const uint16_t GXSID_MIN_MINOR_VERSION = 0;
RsServiceInfo p3IdService::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_GXSID,
GXSID_APP_NAME,
GXSID_APP_MAJOR_VERSION,
GXSID_APP_MINOR_VERSION,
GXSID_MIN_MAJOR_VERSION,
GXSID_MIN_MINOR_VERSION);
}
void p3IdService::setNes(RsNetworkExchangeService *nes)
{
RsStackMutex stack(mIdMtx);

View File

@ -216,6 +216,8 @@ class p3IdService: public RsGxsIdExchange, public RsIdentity,
{
public:
p3IdService(RsGeneralDataService* gds, RsNetworkExchangeService* nes);
virtual RsServiceInfo getServiceInfo();
static uint32_t idAuthenPolicy();
virtual void service_tick(); // needed for background processing.

View File

@ -76,7 +76,7 @@ static const uint8_t ENCRYPTED_MSG_PROTOCOL_VERSION_01 = 0x37 ;
p3MsgService::p3MsgService(p3LinkMgr *lm)
:p3Service(RS_SERVICE_TYPE_MSG), p3Config(CONFIG_TYPE_MSGS),
:p3Service(), p3Config(CONFIG_TYPE_MSGS),
mLinkMgr(lm), mMsgMtx("p3MsgService"), mMsgUniqueId(time(NULL))
{
_serialiser = new RsMsgSerialiser();
@ -108,6 +108,23 @@ p3MsgService::p3MsgService(p3LinkMgr *lm)
#endif
}
const std::string MSG_APP_NAME = "msg";
const uint16_t MSG_APP_MAJOR_VERSION = 1;
const uint16_t MSG_APP_MINOR_VERSION = 0;
const uint16_t MSG_MIN_MAJOR_VERSION = 1;
const uint16_t MSG_MIN_MINOR_VERSION = 0;
RsServiceInfo p3MsgService::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_TYPE_MSG,
MSG_APP_NAME,
MSG_APP_MAJOR_VERSION,
MSG_APP_MINOR_VERSION,
MSG_MIN_MAJOR_VERSION,
MSG_MIN_MINOR_VERSION);
}
uint32_t p3MsgService::getNewUniqueMsgId()
{
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/

View File

@ -60,6 +60,7 @@ class p3MsgService: public p3Service, public p3Config, public pqiMonitor, public
{
public:
p3MsgService(p3LinkMgr *lm);
virtual RsServiceInfo getServiceInfo();
/* External Interface */
bool getMessageSummaries(std::list<MsgInfoSummary> &msgList);

View File

@ -92,6 +92,23 @@ p3PhotoService::p3PhotoService(RsGeneralDataService* gds, RsNetworkExchangeServi
{
}
const std::string GXS_PHOTO_APP_NAME = "gxsphoto";
const uint16_t GXS_PHOTO_APP_MAJOR_VERSION = 1;
const uint16_t GXS_PHOTO_APP_MINOR_VERSION = 0;
const uint16_t GXS_PHOTO_MIN_MAJOR_VERSION = 1;
const uint16_t GXS_PHOTO_MIN_MINOR_VERSION = 0;
RsServiceInfo p3PhotoService::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_PHOTO,
GXS_PHOTO_APP_NAME,
GXS_PHOTO_APP_MAJOR_VERSION,
GXS_PHOTO_APP_MINOR_VERSION,
GXS_PHOTO_MIN_MAJOR_VERSION,
GXS_PHOTO_MIN_MINOR_VERSION);
}
uint32_t p3PhotoService::photoAuthenPolicy()
{

View File

@ -34,6 +34,7 @@ class p3PhotoService : public RsPhoto, public RsGenExchange
public:
p3PhotoService(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs);
virtual RsServiceInfo getServiceInfo();
static uint32_t photoAuthenPolicy();

View File

@ -46,6 +46,24 @@ p3Posted::p3Posted(RsGeneralDataService *gds, RsNetworkExchangeService *nes, RsG
}
const std::string GXS_POSTED_APP_NAME = "gxsposted";
const uint16_t GXS_POSTED_APP_MAJOR_VERSION = 1;
const uint16_t GXS_POSTED_APP_MINOR_VERSION = 0;
const uint16_t GXS_POSTED_MIN_MAJOR_VERSION = 1;
const uint16_t GXS_POSTED_MIN_MINOR_VERSION = 0;
RsServiceInfo p3Posted::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_POSTED,
GXS_POSTED_APP_NAME,
GXS_POSTED_APP_MAJOR_VERSION,
GXS_POSTED_APP_MINOR_VERSION,
GXS_POSTED_MIN_MAJOR_VERSION,
GXS_POSTED_MIN_MINOR_VERSION);
}
bool p3Posted::getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups)
{
std::vector<RsGxsGrpItem*> grpData;

View File

@ -45,6 +45,7 @@ class p3Posted: public p3PostBase, public RsPosted
public:
p3Posted(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs);
virtual RsServiceInfo getServiceInfo();
protected:

View File

@ -117,7 +117,7 @@ static double convert64bitsToTs(uint64_t bits)
p3rtt::p3rtt(p3LinkMgr *lm)
:p3FastService(RS_SERVICE_TYPE_RTT), mRttMtx("p3rtt"), mLinkMgr(lm)
:p3FastService(), mRttMtx("p3rtt"), mLinkMgr(lm)
{
addSerialType(new RsRttSerialiser());
@ -127,6 +127,24 @@ p3rtt::p3rtt(p3LinkMgr *lm)
}
const std::string RTT_APP_NAME = "rtt";
const uint16_t RTT_APP_MAJOR_VERSION = 1;
const uint16_t RTT_APP_MINOR_VERSION = 0;
const uint16_t RTT_MIN_MAJOR_VERSION = 1;
const uint16_t RTT_MIN_MINOR_VERSION = 0;
RsServiceInfo p3rtt::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_TYPE_RTT,
RTT_APP_NAME,
RTT_APP_MAJOR_VERSION,
RTT_APP_MINOR_VERSION,
RTT_MIN_MAJOR_VERSION,
RTT_MIN_MINOR_VERSION);
}
int p3rtt::tick()
{
sendPackets();

View File

@ -64,6 +64,7 @@ class p3rtt: public RsRtt, public p3FastService
{
public:
p3rtt(p3LinkMgr *cm);
virtual RsServiceInfo getServiceInfo();
/***** overloaded from rsRtt *****/

View File

@ -53,12 +53,16 @@ std::string generateRandomServiceId();
//TODO : encryption and upload / download rate implementation
// p3FastService(uint16_t type)
// :pqiService((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + (((uint32_t) type) << 8)),
class p3FastService: public pqiService
{
protected:
p3FastService(uint16_t type)
:pqiService((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + (((uint32_t) type) << 8)),
p3FastService()
:pqiService(),
srvMtx("p3FastService"), rsSerialiser(NULL)
{
rsSerialiser = new RsSerialiser();
@ -95,8 +99,8 @@ class p3Service: public p3FastService
{
protected:
p3Service(uint16_t type)
:p3FastService(type)
p3Service()
:p3FastService()
{
return;
}
@ -127,8 +131,8 @@ class nullService: public pqiService
{
protected:
nullService(uint16_t type)
:pqiService((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + (((uint32_t) type) << 8))
nullService()
:pqiService()
{
return;
}
@ -157,8 +161,8 @@ class p3ThreadedService: public p3Service, public RsThread
{
protected:
p3ThreadedService(uint16_t type)
:p3Service(type) { return; }
p3ThreadedService()
:p3Service() { return; }
public:

View File

@ -0,0 +1,254 @@
/*
* libretroshare/src/services p3serviceinfo.cc
*
* ServiceInfo Service for RetroShare.
*
* Copyright 2014 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.1 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".
*
*/
#include "pqi/p3linkmgr.h"
#include "pqi/p3netmgr.h"
#include "util/rsnet.h"
#include "services/p3serviceinfo.h"
#include "serialiser/rsbanlistitems.h"
#include <sys/time.h>
/****
* #define DEBUG_INFO 1
****/
/************ IMPLEMENTATION NOTES *********************************
*
* Send Info to peers about services we are providing.
*/
p3ServiceInfo::p3ServiceInfo(p3ServiceControl *serviceControl)
:p3Service(), mInfoMtx("p3ServiceInfo"),
mServiceControl(serviceControl)
{
addSerialType(new RsServiceInfoSerialiser());
}
const std::string SERVICE_INFO_APP_NAME = "serviceinfo";
const uint16_t SERVICE_INFO_APP_MAJOR_VERSION = 1;
const uint16_t SERVICE_INFO_APP_MINOR_VERSION = 0;
const uint16_t SERVICE_INFO_MIN_MAJOR_VERSION = 1;
const uint16_t SERVICE_INFO_MIN_MINOR_VERSION = 0;
RsServiceInfo p3ServiceInfo::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_TYPE_SERVICEINFO,
SERVICE_INFO_APP_NAME,
SERVICE_INFO_APP_MAJOR_VERSION,
SERVICE_INFO_APP_MINOR_VERSION,
SERVICE_INFO_MIN_MAJOR_VERSION,
SERVICE_INFO_MIN_MINOR_VERSION);
}
int p3ServiceInfo::tick()
{
processIncoming();
sendPackets();
return 0;
}
int p3ServiceInfo::status()
{
return 1;
}
/***** Implementation ******/
bool p3ServiceInfo::processIncoming()
{
/* for each packet - pass to specific handler */
RsItem *item = NULL;
while(NULL != (item = recvItem()))
{
#ifdef DEBUG_INFO
std::cerr << "p3ServiceInfo::processingIncoming() Received Item:";
std::cerr << std::endl;
item->print(std::cerr);
std::cerr << std::endl;
#endif
switch(item->PacketSubType())
{
default:
break;
case RS_PKT_SUBTYPE_SERVICELIST_ITEM:
{
// Order is important!.
RsServiceInfoListItem *listItem = dynamic_cast<RsServiceInfoListItem *>(item);
if (listItem)
{
recvServiceInfoList(listItem);
}
else
{
// error.
std::cerr << "p3ServiceInfo::processingIncoming() Error with Received Item:";
std::cerr << std::endl;
item->print(std::cerr);
std::cerr << std::endl;
}
}
break;
}
/* clean up */
delete item;
}
return true ;
}
bool convertServiceInfoToItem(
const RsPeerServiceInfo &info,
RsServiceInfoListItem *item)
{
item->mServiceInfo = info.mServiceList;
item->PeerId(info.mPeerId);
return true;
}
bool convertServiceItemToInfo(
const RsServiceInfoListItem *item,
RsPeerServiceInfo &info)
{
info.mServiceList = item->mServiceInfo;
info.mPeerId = item->PeerId();
return true;
}
bool p3ServiceInfo::recvServiceInfoList(RsServiceInfoListItem *item)
{
RsPeerId peerId = item->PeerId();
std::cerr << "p3ServiceInfo::recvServiceInfoList() from: " << peerId.toStdString();
std::cerr << std::endl;
RsPeerServiceInfo info;
if (convertServiceItemToInfo(item, info))
{
#ifdef DEBUG_INFO
std::cerr << "p3ServiceInfo::recvServiceInfoList() Info: ";
std::cerr << std::endl;
std::cerr << info;
std::cerr << std::endl;
#endif
/* update service control */
mServiceControl->updateServicesProvided(peerId, info);
return true;
}
return false;
}
bool p3ServiceInfo::sendPackets()
{
std::set<RsPeerId> updateSet;
{
RsStackMutex stack(mInfoMtx); /****** LOCKED MUTEX *******/
updateSet = mPeersToUpdate;
mPeersToUpdate.clear();
}
mServiceControl->getServiceChanges(updateSet);
RsStackMutex stack(mInfoMtx); /****** LOCKED MUTEX *******/
std::set<RsPeerId>::iterator it;
for(it = updateSet.begin(); it != updateSet.end(); it++)
{
sendServiceInfoList(*it);
}
return (!updateSet.empty());
}
int p3ServiceInfo::sendServiceInfoList(const RsPeerId &peerId)
{
std::cerr << "p3ServiceInfo::sendServiceInfoList() to " << peerId.toStdString();
std::cerr << std::endl;
RsServiceInfoListItem *item = new RsServiceInfoListItem();
RsPeerServiceInfo info;
bool sent = false;
if (mServiceControl->getServicesAllowed(peerId, info))
{
std::cerr << "p3ServiceInfo::sendServiceInfoList() Info: ";
std::cerr << std::endl;
std::cerr << info;
std::cerr << std::endl;
if (convertServiceInfoToItem(info, item))
{
item->PeerId(peerId);
sent = true;
sendItem(item);
}
}
if (!sent)
{
delete item;
}
return sent;
}
void p3ServiceInfo::statusChange(const std::list<pqipeer> &plist)
{
std::cerr << "p3ServiceInfo::statusChange()";
std::cerr << std::endl;
std::list<pqipeer>::const_iterator it;
for (it = plist.begin(); it != plist.end(); it++)
{
if (it->state & RS_PEER_S_FRIEND)
{
if (it->actions & RS_PEER_CONNECTED)
{
std::cerr << "p3ServiceInfo::statusChange()";
std::cerr << "Peer: " << it->id;
std::cerr << " Connected";
std::cerr << std::endl;
RsStackMutex stack(mInfoMtx); /****** LOCKED MUTEX *******/
mPeersToUpdate.insert(it->id);
}
}
}
}

View File

@ -0,0 +1,75 @@
/*
* libretroshare/src/services/p3serviceinfo.h
*
* Exchange list of Service Information.
*
* Copyright 2014 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.1 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_RSSERVICEINFO_HEADER
#define SERVICE_RSSERVICEINFO_HEADER
#include <string>
#include <list>
#include <map>
#include "pqi/p3servicecontrol.h"
#include "pqi/pqimonitor.h"
#include "services/p3service.h"
#include "serialiser/rsserviceinfoitems.h"
//!The ServiceInfo service.
/**
*
* Exchange list of Available Services with peers.
*/
class p3ServiceInfo: public p3Service, public pqiMonitor
{
public:
p3ServiceInfo(p3ServiceControl *serviceControl);
virtual RsServiceInfo getServiceInfo();
virtual int tick();
virtual int status();
/*************** pqiMonitor callback ***********************/
virtual void statusChange(const std::list<pqipeer> &plist);
private:
bool sendPackets();
bool processIncoming();
bool recvServiceInfoList(RsServiceInfoListItem *item);
int sendServiceInfoList(const RsPeerId &peerid);
private:
RsMutex mInfoMtx;
std::set<RsPeerId> mPeersToUpdate;
p3ServiceControl *mServiceControl;
};
#endif // SERVICE_RSSERVICEINFO_HEADER

View File

@ -48,7 +48,7 @@ std::ostream& operator<<(std::ostream& out, const StatusInfo& si)
RsStatus *rsStatus = NULL;
p3StatusService::p3StatusService(p3LinkMgr *cm)
:p3Service(RS_SERVICE_TYPE_STATUS), p3Config(CONFIG_TYPE_STATUS), mLinkMgr(cm), mStatusMtx("p3StatusService")
:p3Service(), p3Config(CONFIG_TYPE_STATUS), mLinkMgr(cm), mStatusMtx("p3StatusService")
{
addSerialType(new RsStatusSerialiser());
@ -58,6 +58,24 @@ p3StatusService::~p3StatusService()
{
}
const std::string STATUS_APP_NAME = "status";
const uint16_t STATUS_APP_MAJOR_VERSION = 1;
const uint16_t STATUS_APP_MINOR_VERSION = 0;
const uint16_t STATUS_MIN_MAJOR_VERSION = 1;
const uint16_t STATUS_MIN_MINOR_VERSION = 0;
RsServiceInfo p3StatusService::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_TYPE_STATUS,
STATUS_APP_NAME,
STATUS_APP_MAJOR_VERSION,
STATUS_APP_MINOR_VERSION,
STATUS_MIN_MAJOR_VERSION,
STATUS_MIN_MINOR_VERSION);
}
bool p3StatusService::getOwnStatus(StatusInfo& statusInfo)
{
#ifdef STATUS_DEBUG

View File

@ -51,6 +51,8 @@ class p3StatusService: public p3Service, public p3Config, public pqiMonitor
p3StatusService(p3LinkMgr *lm);
virtual ~p3StatusService();
virtual RsServiceInfo getServiceInfo();
/***** overloaded from p3Service *****/
virtual int tick();
virtual int status();

View File

@ -56,6 +56,24 @@ p3Wiki::p3Wiki(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs
}
const std::string GXS_WIKI_APP_NAME = "gxswiki";
const uint16_t GXS_WIKI_APP_MAJOR_VERSION = 1;
const uint16_t GXS_WIKI_APP_MINOR_VERSION = 0;
const uint16_t GXS_WIKI_MIN_MAJOR_VERSION = 1;
const uint16_t GXS_WIKI_MIN_MINOR_VERSION = 0;
RsServiceInfo p3Wiki::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_WIKI,
GXS_WIKI_APP_NAME,
GXS_WIKI_APP_MAJOR_VERSION,
GXS_WIKI_APP_MINOR_VERSION,
GXS_WIKI_MIN_MAJOR_VERSION,
GXS_WIKI_MIN_MINOR_VERSION);
}
uint32_t p3Wiki::wikiAuthenPolicy()
{
uint32_t policy = 0;

View File

@ -45,6 +45,7 @@ class p3Wiki: public RsGenExchange, public RsWiki,
{
public:
p3Wiki(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs *gixs);
virtual RsServiceInfo getServiceInfo();
static uint32_t wikiAuthenPolicy();
protected:

View File

@ -43,6 +43,24 @@ p3Wire::p3Wire(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs
}
const std::string WIRE_APP_NAME = "gxswire";
const uint16_t WIRE_APP_MAJOR_VERSION = 1;
const uint16_t WIRE_APP_MINOR_VERSION = 0;
const uint16_t WIRE_MIN_MAJOR_VERSION = 1;
const uint16_t WIRE_MIN_MINOR_VERSION = 0;
RsServiceInfo p3Wire::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_GXSV2_TYPE_WIRE,
WIRE_APP_NAME,
WIRE_APP_MAJOR_VERSION,
WIRE_APP_MINOR_VERSION,
WIRE_MIN_MAJOR_VERSION,
WIRE_MIN_MINOR_VERSION);
}
uint32_t p3Wire::wireAuthenPolicy()
{
uint32_t policy = 0;

View File

@ -43,6 +43,7 @@ class p3Wire: public RsGenExchange, public RsWire
{
public:
p3Wire(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs *gixs);
virtual RsServiceInfo getServiceInfo();
static uint32_t wireAuthenPolicy();
protected:

View File

@ -99,7 +99,7 @@ static const int MAX_TR_FORWARD_PER_SEC_LOWER_LIMIT = 10 ;
static const int DISTANCE_SQUEEZING_POWER = 8 ;
p3turtle::p3turtle(p3LinkMgr *lm)
:p3Service(RS_SERVICE_TYPE_TURTLE), p3Config(CONFIG_TYPE_TURTLE), mLinkMgr(lm), mTurtleMtx("p3turtle")
:p3Service(), p3Config(CONFIG_TYPE_TURTLE), mLinkMgr(lm), mTurtleMtx("p3turtle")
{
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
@ -120,6 +120,23 @@ p3turtle::p3turtle(p3LinkMgr *lm)
_max_tr_up_rate = MAX_TR_FORWARD_PER_SEC ;
}
const std::string TURTLE_APP_NAME = "turtle";
const uint16_t TURTLE_APP_MAJOR_VERSION = 1;
const uint16_t TURTLE_APP_MINOR_VERSION = 0;
const uint16_t TURTLE_MIN_MAJOR_VERSION = 1;
const uint16_t TURTLE_MIN_MINOR_VERSION = 0;
RsServiceInfo p3turtle::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_TYPE_TURTLE,
TURTLE_APP_NAME,
TURTLE_APP_MAJOR_VERSION,
TURTLE_APP_MINOR_VERSION,
TURTLE_MIN_MAJOR_VERSION,
TURTLE_MIN_MINOR_VERSION);
}
void p3turtle::setEnabled(bool b)
{
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/

View File

@ -217,6 +217,7 @@ class p3turtle: public p3Service, public RsTurtle, public p3Config
{
public:
p3turtle(p3LinkMgr *lm) ;
virtual RsServiceInfo getServiceInfo();
// Enables/disable the service. Still ticks, but does nothing. Default is true.
//