Merge branch 'master' into webui

This commit is contained in:
zeners 2016-01-03 23:54:56 +01:00
commit c7cbd257a5
2 changed files with 460 additions and 703 deletions

File diff suppressed because it is too large Load Diff

View File

@ -38,133 +38,121 @@
class ServiceNotifications class ServiceNotifications
{ {
public: public:
std::set<RsPeerId> mAdded; std::set<RsPeerId> mAdded;
std::set<RsPeerId> mRemoved; std::set<RsPeerId> mRemoved;
}; };
class ServicePeerFilter class ServicePeerFilter
{ {
public: public:
ServicePeerFilter() ServicePeerFilter() : mDenyAll(true), mAllowAll(false) {}
:mDenyAll(true), mAllowAll(false) {}
bool mDenyAll; bool mDenyAll;
bool mAllowAll; bool mAllowAll;
std::set<uint32_t> mAllowedServices; std::set<uint32_t> mAllowedServices;
}; };
std::ostream &operator<<(std::ostream &out, const ServicePeerFilter &filter); std::ostream &operator<<(std::ostream &out, const ServicePeerFilter &filter);
class ServiceControlSerialiser ; class ServiceControlSerialiser;
class p3ServiceControl: public RsServiceControl, public pqiMonitor, public p3Config class p3ServiceControl: public RsServiceControl, public pqiMonitor, public p3Config
{ {
public: public:
p3ServiceControl(p3LinkMgr *linkMgr);
/** /**
* checks and update all added configurations
* @see rsserver
*/ */
p3ServiceControl(p3LinkMgr *linkMgr); void tick();
/** /**
* checks and update all added configurations * provided so that services don't need linkMgr, and can get all info
* @see rsserver
*/
void tick();
/**
* provided so that services don't need linkMgr, and can get all info
* from ServiceControl. * from ServiceControl.
* @see rsserver * @see rsserver
*/ */
virtual const RsPeerId& getOwnId();
virtual const RsPeerId& getOwnId();
/** /**
* External Interface (RsServiceControl). * External Interface (RsServiceControl).
*/ */
virtual bool getOwnServices(RsPeerServiceInfo &info);
virtual bool getOwnServices(RsPeerServiceInfo &info);
// This is what is passed to peers, can be displayed by GUI too. // This is what is passed to peers, can be displayed by GUI too.
virtual bool getServicesAllowed(const RsPeerId &peerId, RsPeerServiceInfo &info); virtual bool getServicesAllowed(const RsPeerId &peerId, RsPeerServiceInfo &info);
// Information provided by peer. // Information provided by peer.
virtual bool getServicesProvided(const RsPeerId &peerId, RsPeerServiceInfo &info); virtual bool getServicesProvided(const RsPeerId &peerId, RsPeerServiceInfo &info);
// Main Permission Interface. // Main Permission Interface.
virtual bool getServicePermissions(uint32_t serviceId, RsServicePermissions &permissions); virtual bool getServicePermissions(uint32_t serviceId, RsServicePermissions &permissions);
virtual bool updateServicePermissions(uint32_t serviceId, const RsServicePermissions &permissions); virtual bool updateServicePermissions(uint32_t serviceId, const RsServicePermissions &permissions);
// Get List of Peers using this Service. // Get List of Peers using this Service.
virtual void getPeersConnected(const uint32_t serviceId, std::set<RsPeerId> &peerSet); virtual void getPeersConnected(const uint32_t serviceId, std::set<RsPeerId> &peerSet);
virtual bool isPeerConnected(const uint32_t serviceId, const RsPeerId &peerId); virtual bool isPeerConnected(const uint32_t serviceId, const RsPeerId &peerId);
/** /**
* Registration for all Services. * Registration for all Services.
*/ */
virtual bool registerService(const RsServiceInfo &info, bool defaultOn);
virtual bool deregisterService(uint32_t serviceId);
virtual bool registerService(const RsServiceInfo &info, bool defaultOn); virtual bool registerServiceMonitor(pqiServiceMonitor *monitor, uint32_t serviceId);
virtual bool deregisterService(uint32_t serviceId); virtual bool deregisterServiceMonitor(pqiServiceMonitor *monitor);
virtual bool registerServiceMonitor(pqiServiceMonitor *monitor, uint32_t serviceId);
virtual bool deregisterServiceMonitor(pqiServiceMonitor *monitor);
/**
*
*/
// Filter for services. // Filter for services.
virtual bool checkFilter(uint32_t serviceId, const RsPeerId &peerId); virtual bool checkFilter(uint32_t serviceId, const RsPeerId &peerId);
/** /*
* Interface for ServiceInfo service. * Interface for ServiceInfo service.
*/ */
// ServicesAllowed have changed for these peers. // ServicesAllowed have changed for these peers.
virtual void getServiceChanges(std::set<RsPeerId> &updateSet); virtual void getServiceChanges(std::set<RsPeerId> &updateSet);
// Input from peers. // Input from peers.
virtual bool updateServicesProvided(const RsPeerId &peerId, const RsPeerServiceInfo &info); virtual bool updateServicesProvided(const RsPeerId &peerId, const RsPeerServiceInfo &info);
// pqiMonitor. // pqiMonitor.
virtual void statusChange(const std::list<pqipeer> &plist); virtual void statusChange(const std::list<pqipeer> &plist);
protected: protected:
// configuration. // configuration.
virtual bool saveList(bool &cleanup, std::list<RsItem *>&); virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
virtual bool loadList(std::list<RsItem *>& load); virtual bool loadList(std::list<RsItem *>& load);
virtual RsSerialiser *setupSerialiser() ; virtual RsSerialiser *setupSerialiser() ;
private: private:
void notifyServices();
void notifyAboutFriends();
void notifyServices(); void updatePeerConnect(const RsPeerId &peerId);
void notifyAboutFriends(); void updatePeerDisconnect(const RsPeerId &peerId);
void updatePeerNew(const RsPeerId &peerId);
void updatePeerRemoved(const RsPeerId &peerId);
void updatePeerConnect(const RsPeerId &peerId); void removePeer(const RsPeerId &peerId);
void updatePeerDisconnect(const RsPeerId &peerId);
void updatePeerNew(const RsPeerId &peerId);
void updatePeerRemoved(const RsPeerId &peerId);
void removePeer(const RsPeerId &peerId);
bool updateAllFilters(); bool updateAllFilters();
bool updateAllFilters_locked(); bool updateAllFilters_locked();
bool updateFilterByPeer(const RsPeerId &peerId); bool updateFilterByPeer(const RsPeerId &peerId);
bool updateFilterByPeer_locked(const RsPeerId &peerId); bool updateFilterByPeer_locked(const RsPeerId &peerId);
void recordFilterChanges_locked(const RsPeerId &peerId, void recordFilterChanges_locked(const RsPeerId &peerId,
ServicePeerFilter &originalFilter, ServicePeerFilter &updatedFilter); ServicePeerFilter &originalFilter,
ServicePeerFilter &updatedFilter);
// Called from recordFilterChanges. // Called from recordFilterChanges.
void filterChangeAdded_locked(const RsPeerId &peerId, uint32_t serviceId); void filterChangeAdded_locked(const RsPeerId &peerId, uint32_t serviceId);
void filterChangeRemoved_locked(const RsPeerId &peerId, uint32_t serviceId); void filterChangeRemoved_locked(const RsPeerId &peerId, uint32_t serviceId);
bool createDefaultPermissions_locked(uint32_t serviceId, std::string serviceName, bool defaultOn); bool createDefaultPermissions_locked(uint32_t serviceId, std::string serviceName, bool defaultOn);
bool peerHasPermissionForService_locked(const RsPeerId &peerId, uint32_t serviceId); bool peerHasPermissionForService_locked(const RsPeerId &peerId, uint32_t serviceId);
p3LinkMgr *mLinkMgr; p3LinkMgr *mLinkMgr;
const RsPeerId mOwnPeerId; // const from constructor const RsPeerId mOwnPeerId; // const from constructor
@ -176,25 +164,22 @@ bool peerHasPermissionForService_locked(const RsPeerId &peerId, uint32_t service
// From registration / deregistration. // From registration / deregistration.
std::map<uint32_t, RsServiceInfo> mOwnServices; std::map<uint32_t, RsServiceInfo> mOwnServices;
// From peers. // From peers.
std::map<RsPeerId, RsPeerServiceInfo> mServicesProvided; std::map<RsPeerId, RsPeerServiceInfo> mServicesProvided;
// derived from all the others. // derived from all the others.
std::map<RsPeerId, ServicePeerFilter> mPeerFilterMap; std::map<RsPeerId, ServicePeerFilter> mPeerFilterMap;
std::map<uint32_t, ServiceNotifications> mNotifications; std::map<uint32_t, ServiceNotifications> mNotifications;
std::list<pqiServicePeer> mFriendNotifications; std::list<pqiServicePeer> mFriendNotifications;
// Map of Connected Peers per Service. // Map of Connected Peers per Service.
std::map<uint32_t, std::set<RsPeerId> > mServicePeerMap; std::map<uint32_t, std::set<RsPeerId> > mServicePeerMap;
// Separate mutex here - must not hold both at the same time! // Separate mutex here - must not hold both at the same time!
RsMutex mMonitorMtx; /* below is protected */ RsMutex mMonitorMtx; /* below is protected */
std::multimap<uint32_t, pqiServiceMonitor *> mMonitors; std::multimap<uint32_t, pqiServiceMonitor *> mMonitors;
ServiceControlSerialiser *mSerialiser ;
// Below here is saved in Configuration.
std::map<uint32_t, RsServicePermissions> mServicePermissionMap;
// Below here is saved in Configuration.
std::map<uint32_t, RsServicePermissions> mServicePermissionMap;
}; };